-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafl-fuzz.c
47 lines (40 loc) · 890 Bytes
/
afl-fuzz.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "debug.h"
int main(int argc, char *argv[]){
int pid;
int status;
int out_fd;
char *target_path = "./target";
char *fuzz = "Hello,World!";
char *out_file = "./.cur_input";
// afl: setup_stdio_file()
// make .cur_input
FILE *fp;
fp = fopen(out_file, "w");
fclose(fp);
out_fd = open(out_file, O_RDWR | O_CREAT, 0600);
unlink(out_file);
// afl: write_to_testcase()
lseek(out_fd, 0, SEEK_SET); // 先頭
write(out_fd, fuzz, strlen(fuzz));
lseek(out_fd, 0, SEEK_SET); // 先頭
// afl: run_target()
pid = fork();
if(pid < 0) {
printf("fork error\n");
return 1;
}
else if(pid == 0) {
printf("child process\n");
setsid();
dup2(out_fd, 0);
close(out_fd);
execv(target_path, argv);
exit(0);
}
else {
printf("parent process\n");
wait(&status);
printf("child process exit\n");
}
return 0;
}