-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuzzmethod_singleoption.c
122 lines (107 loc) · 2.62 KB
/
fuzzmethod_singleoption.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* $Id */
#include "ifuzz.h"
#define FUZZES_PER_OPTION 5
extern pid_t child;
void
fuzzmethod_singleoption (char *fullpath,struct singleoption_args *singleoption_args)
{
pid_t pid;
int status;
char option;
char option_string[3];
char *args[4];
FILE *fp;
for (option = 0x20; option < 0x7f; option++)
{
int thorough = 0;
sprintf (option_string, "-%c", option);
while (thorough++ < FUZZES_PER_OPTION)
{
rfree ();
args[0] = fullpath;
args[1] = option_string;
args[2] = get_random_string ();
args[3] = NULL;
if ((pid = fork ()) != 0)
{
child = pid;
signal (SIGALRM, &handle_alarm);
alarm (TIME_TO_DIE);
waitpid (pid, &status, 0);
alarm (0);
if (WIFSIGNALED (status))
{
switch (WTERMSIG (status))
{
/*
** since we are only logging the signals, we might as well catch anything
** even remotely interesting
*/
case SIGBUS:
case SIGILL:
case SIGSEGV:
case SIGTRAP:
case SIGFPE:
case SIGUSR1:
case SIGUSR2:
fprintf (stderr, "%s | CRASH SIGNAL #%d (%s)\n",
fullpath, WTERMSIG (status), option_string);
if (!
(fp =
open_c_file (fullpath, pid, WTERMSIG (status))))
{
fprintf (stderr,
"have you ever heard of chmod? no access to dump dir you douchebag.\n");
exit (-1);
}
print_c_basic_header (fp);
print_c_comment_open (fp);
print_text (fp, asciitime ());
print_text (fp, "Single option: ");
print_text (fp, option_string);
print_c_comment_close (fp);
print_c_array_to_file (fp, args, "args");
print_c_array_to_file (fp, environ, "envp");
print_c_execve_call (fp, fullpath, "args", "envp");
print_c_basic_header_close (fp);
fclose (fp);
break;
default:
break;
}
}
}
else
{
/* do the actual fuzz */
execle (fullpath, fullpath, option_string, get_random_string (),
NULL, environ);
perror ("execle");
}
}
}
rfree ();
return; /* unreached */
}
/* should only be called once even when fuzzing multiple programs */
void
parse_singleoption (int argc, char *argv[], struct singleoption_args *singleoption_args)
{
int c;
opterr = 0;
printf ("initializing single option options\n");
while ((c = getopt (argc, argv, "s")) != -1)
{
switch (c)
{
case 's':
singleoption_args->silent = 1;
break;
default:
printf("Error in arguments\n");
usage();
break;
}
}
return;
}