-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin_fuzz.c
49 lines (40 loc) · 1.2 KB
/
bin_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
48
49
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#define MAX_INPUT_SIZE 1024
int main(int argc, char *argv[])
{
if (argc < 3) {
printf("Usage: %s <target_elf_binary> <target_input_txt_file>\n", argv[0]);
return 1;
}
char *target_elf_binary = argv[1];
char *target_input_txt_file = argv[2];
// Generate test cases using radamsa fuzzer
char cmd[MAX_INPUT_SIZE];
snprintf(cmd, MAX_INPUT_SIZE, "radamsa %s -o test_case.txt", target_input_txt_file);
system(cmd);
// Execute the target binary with the generated test cases
FILE *fp = fopen("test_case.txt", "r");
if (fp == NULL) {
printf("Error: Failed to open test_case.txt\n");
return 1;
}
char input[MAX_INPUT_SIZE];
while (fgets(input, MAX_INPUT_SIZE, fp) != NULL) {
// Remove trailing newline
input[strcspn(input, "\n")] = 0;
// Execute the target binary
pid_t pid = fork();
if (pid == 0) {
execl(target_elf_binary, target_elf_binary, input, NULL);
} else {
int status;
waitpid(pid, &status, 0);
}
}
fclose(fp);
return 0;
}