* Implemented -f/--fuzzing (fuzzing mode).
This commit is contained in:
parent
b4fbf4c088
commit
5e6b423865
22
doc/zzuf.1
22
doc/zzuf.1
@ -4,11 +4,11 @@ zzuf \- multiple purpose fuzzer
|
|||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
\fBzzuf\fR [\fB\-AcdimnqSvx\fR] [\fB\-s\fR \fIseed\fR|\fB\-s\fR \fIstart:stop\fR] [\fB\-r\fR \fIratio\fR|\fB\-r\fR \fImin:max\fR]
|
\fBzzuf\fR [\fB\-AcdimnqSvx\fR] [\fB\-s\fR \fIseed\fR|\fB\-s\fR \fIstart:stop\fR] [\fB\-r\fR \fIratio\fR|\fB\-r\fR \fImin:max\fR]
|
||||||
.br
|
.br
|
||||||
[\fB\-D\fR \fIdelay\fR] [\fB\-F\fR \fIforks\fR] [\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR] [\fB\-T\fR \fIseconds\fR]
|
[\fB\-f\fR \fIfuzzing\fR] [\fB\-D\fR \fIdelay\fR] [\fB\-F\fR \fIforks\fR] [\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR]
|
||||||
.br
|
.br
|
||||||
[\fB\-M\fR \fImegabytes\fR] [\fB\-b\fR \fIranges\fR] [\fB\-P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR]
|
[\fB\-T\fR \fIseconds\fR] [\fB\-M\fR \fImegabytes\fR] [\fB\-P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR]
|
||||||
.br
|
.br
|
||||||
[\fB\-I\fR \fIinclude\fR] [\fB\-E\fR \fIexclude\fR] [\fIPROGRAM\fR [\fB\-\-\fR] [\fIARGS\fR]...]
|
[\fB\-b\fR \fIranges\fR] [\fB\-I\fR \fIinclude\fR] [\fB\-E\fR \fIexclude\fR] [\fIPROGRAM\fR [\fB\-\-\fR] [\fIARGS\fR]...]
|
||||||
.br
|
.br
|
||||||
\fBzzuf \-h\fR | \fB\-\-help\fR
|
\fBzzuf \-h\fR | \fB\-\-help\fR
|
||||||
.br
|
.br
|
||||||
@ -98,6 +98,22 @@ and do not want it to fuzz files in the \fB/etc\fR directory.
|
|||||||
Multiple \fB\-E\fR flags can be specified, in which case files matching any one
|
Multiple \fB\-E\fR flags can be specified, in which case files matching any one
|
||||||
of the regular expressions will be ignored.
|
of the regular expressions will be ignored.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-f\fR, \fB\-\-fuzzing\fR=\fImode\fR
|
||||||
|
Select how the input is fuzzed. Valid values for \fImode\fR are:
|
||||||
|
.RS
|
||||||
|
.TP
|
||||||
|
\fBxor\fR
|
||||||
|
randomly set and unset bits
|
||||||
|
.TP
|
||||||
|
\fBset\fR
|
||||||
|
only set bits
|
||||||
|
.TP
|
||||||
|
\fBunset\fR
|
||||||
|
only unset bits
|
||||||
|
.RE
|
||||||
|
.IP
|
||||||
|
The default value for \fImode\fR is \fBxor\fR.
|
||||||
|
.TP
|
||||||
\fB\-F\fR, \fB\-\-max\-forks\fR=\fIforks\fR
|
\fB\-F\fR, \fB\-\-max\-forks\fR=\fIforks\fR
|
||||||
Specify the number of simultaneous children that can be run.
|
Specify the number of simultaneous children that can be run.
|
||||||
|
|
||||||
|
|||||||
37
src/fuzz.c
37
src/fuzz.c
@ -36,6 +36,13 @@
|
|||||||
#define MAGIC1 0x33ea84f7
|
#define MAGIC1 0x33ea84f7
|
||||||
#define MAGIC2 0x783bc31f
|
#define MAGIC2 0x783bc31f
|
||||||
|
|
||||||
|
/* Fuzzing mode */
|
||||||
|
static enum fuzzing
|
||||||
|
{
|
||||||
|
FUZZING_XOR = 0, FUZZING_SET, FUZZING_UNSET
|
||||||
|
}
|
||||||
|
fuzzing;
|
||||||
|
|
||||||
/* Per-offset byte protection */
|
/* Per-offset byte protection */
|
||||||
static unsigned int *ranges = NULL;
|
static unsigned int *ranges = NULL;
|
||||||
static unsigned int ranges_static[512];
|
static unsigned int ranges_static[512];
|
||||||
@ -47,6 +54,16 @@ static int refuse[256];
|
|||||||
/* Local prototypes */
|
/* Local prototypes */
|
||||||
static void readchars(int *, char const *);
|
static void readchars(int *, char const *);
|
||||||
|
|
||||||
|
extern void _zz_fuzzing(char const *mode)
|
||||||
|
{
|
||||||
|
if(!strcmp(mode, "xor"))
|
||||||
|
fuzzing = FUZZING_XOR;
|
||||||
|
else if(!strcmp(mode, "set"))
|
||||||
|
fuzzing = FUZZING_SET;
|
||||||
|
else if(!strcmp(mode, "unset"))
|
||||||
|
fuzzing = FUZZING_UNSET;
|
||||||
|
}
|
||||||
|
|
||||||
void _zz_bytes(char const *list)
|
void _zz_bytes(char const *list)
|
||||||
{
|
{
|
||||||
char const *parser;
|
char const *parser;
|
||||||
@ -143,7 +160,7 @@ void _zz_fuzz(int fd, volatile uint8_t *buf, uint64_t len)
|
|||||||
for(j = start; j < stop; j++)
|
for(j = start; j < stop; j++)
|
||||||
{
|
{
|
||||||
unsigned int *r;
|
unsigned int *r;
|
||||||
uint8_t byte;
|
uint8_t byte, fuzzbyte;
|
||||||
|
|
||||||
if(!ranges)
|
if(!ranges)
|
||||||
goto range_ok;
|
goto range_ok;
|
||||||
@ -160,7 +177,23 @@ void _zz_fuzz(int fd, volatile uint8_t *buf, uint64_t len)
|
|||||||
if(protect[byte])
|
if(protect[byte])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
byte ^= fuzz->data[j % CHUNKBYTES];
|
fuzzbyte = fuzz->data[j % CHUNKBYTES];
|
||||||
|
|
||||||
|
if(!fuzzbyte)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
switch(fuzzing)
|
||||||
|
{
|
||||||
|
case FUZZING_XOR:
|
||||||
|
byte ^= fuzzbyte;
|
||||||
|
break;
|
||||||
|
case FUZZING_SET:
|
||||||
|
byte |= fuzzbyte;
|
||||||
|
break;
|
||||||
|
case FUZZING_UNSET:
|
||||||
|
byte &= ~fuzzbyte;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(refuse[byte])
|
if(refuse[byte])
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
* fuzz.h: fuzz functions
|
* fuzz.h: fuzz functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
extern void _zz_fuzzing(char const *);
|
||||||
extern void _zz_bytes(char const *);
|
extern void _zz_bytes(char const *);
|
||||||
extern void _zz_protect(char const *);
|
extern void _zz_protect(char const *);
|
||||||
extern void _zz_refuse(char const *);
|
extern void _zz_refuse(char const *);
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
void _zz_opts_init(struct opts *opts)
|
void _zz_opts_init(struct opts *opts)
|
||||||
{
|
{
|
||||||
opts->bytes = opts->protect = opts->refuse = NULL;
|
opts->fuzzing = opts->bytes = opts->protect = opts->refuse = NULL;
|
||||||
opts->seed = DEFAULT_SEED;
|
opts->seed = DEFAULT_SEED;
|
||||||
opts->endseed = DEFAULT_SEED + 1;
|
opts->endseed = DEFAULT_SEED + 1;
|
||||||
opts->minratio = opts->maxratio = DEFAULT_RATIO;
|
opts->minratio = opts->maxratio = DEFAULT_RATIO;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ struct opts
|
|||||||
{
|
{
|
||||||
char **oldargv;
|
char **oldargv;
|
||||||
char **newargv;
|
char **newargv;
|
||||||
char *bytes, *protect, *refuse;
|
char *fuzzing, *bytes, *protect, *refuse;
|
||||||
uint32_t seed;
|
uint32_t seed;
|
||||||
uint32_t endseed;
|
uint32_t endseed;
|
||||||
double minratio;
|
double minratio;
|
||||||
|
|||||||
22
src/zzuf.c
22
src/zzuf.c
@ -130,9 +130,9 @@ int main(int argc, char *argv[])
|
|||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
# if defined HAVE_REGEX_H
|
# if defined HAVE_REGEX_H
|
||||||
# define OPTSTR "Ab:B:cC:dD:E:F:iI:mM:nP:qr:R:s:ST:vxhV"
|
# define OPTSTR "Ab:B:cC:dD:E:f:F:iI:mM:nP:qr:R:s:ST:vxhV"
|
||||||
# else
|
# else
|
||||||
# define OPTSTR "Ab:B:C:dD:F:imM:nP:qr:R:s:ST:vxhV"
|
# define OPTSTR "Ab:B:C:dD:f:F:imM:nP:qr:R:s:ST:vxhV"
|
||||||
# endif
|
# endif
|
||||||
# if defined HAVE_GETOPT_LONG
|
# if defined HAVE_GETOPT_LONG
|
||||||
# define MOREINFO "Try `%s --help' for more information.\n"
|
# define MOREINFO "Try `%s --help' for more information.\n"
|
||||||
@ -152,6 +152,7 @@ int main(int argc, char *argv[])
|
|||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
{ "exclude", 1, NULL, 'E' },
|
{ "exclude", 1, NULL, 'E' },
|
||||||
#endif
|
#endif
|
||||||
|
{ "fuzzing", 1, NULL, 'f' },
|
||||||
{ "max-forks", 1, NULL, 'F' },
|
{ "max-forks", 1, NULL, 'F' },
|
||||||
{ "stdin", 0, NULL, 'i' },
|
{ "stdin", 0, NULL, 'i' },
|
||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
@ -219,6 +220,9 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case 'f': /* --fuzzing */
|
||||||
|
opts->fuzzing = optarg;
|
||||||
|
break;
|
||||||
case 'F': /* --max-forks */
|
case 'F': /* --max-forks */
|
||||||
opts->maxchild = atoi(optarg) > 1 ? atoi(optarg) : 1;
|
opts->maxchild = atoi(optarg) > 1 ? atoi(optarg) : 1;
|
||||||
break;
|
break;
|
||||||
@ -343,6 +347,8 @@ int main(int argc, char *argv[])
|
|||||||
setenv("ZZUF_EXCLUDE", exclude, 1);
|
setenv("ZZUF_EXCLUDE", exclude, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(opts->fuzzing)
|
||||||
|
setenv("ZZUF_FUZZING", opts->fuzzing, 1);
|
||||||
if(opts->bytes)
|
if(opts->bytes)
|
||||||
setenv("ZZUF_BYTES", opts->bytes, 1);
|
setenv("ZZUF_BYTES", opts->bytes, 1);
|
||||||
if(opts->protect)
|
if(opts->protect)
|
||||||
@ -393,6 +399,8 @@ static void loop_stdin(struct opts *opts)
|
|||||||
if(opts->md5)
|
if(opts->md5)
|
||||||
ctx = _zz_md5_init();
|
ctx = _zz_md5_init();
|
||||||
|
|
||||||
|
if(opts->fuzzing)
|
||||||
|
_zz_fuzzing(opts->fuzzing);
|
||||||
if(opts->bytes)
|
if(opts->bytes)
|
||||||
_zz_bytes(opts->bytes);
|
_zz_bytes(opts->bytes);
|
||||||
if(opts->protect)
|
if(opts->protect)
|
||||||
@ -1048,12 +1056,12 @@ static void usage(void)
|
|||||||
#else
|
#else
|
||||||
printf("Usage: zzuf [-AdimnqSvx] [-s seed|-s start:stop] [-r ratio|-r min:max]\n");
|
printf("Usage: zzuf [-AdimnqSvx] [-s seed|-s start:stop] [-r ratio|-r min:max]\n");
|
||||||
#endif
|
#endif
|
||||||
printf(" [-D delay] [-F forks] [-C crashes] [-B bytes] [-T seconds]\n");
|
printf(" [-f fuzzing] [-D delay] [-F forks] [-C crashes] [-B bytes]\n");
|
||||||
printf(" [-M bytes] [-b ranges] [-P protect] [-R refuse]\n");
|
printf(" [-T seconds] [-M bytes] [-b ranges] [-P protect] [-R refuse]\n");
|
||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
printf(" [-I include] [-E exclude] [PROGRAM [--] [ARGS]...]\n");
|
printf(" [-I include] [-E exclude] [PROGRAM [--] [ARGS]...]\n");
|
||||||
#else
|
#else
|
||||||
printf(" [PROGRAM [--] [ARGS]...]\n");
|
printf(" [PROGRAM [--] [ARGS]...]\n");
|
||||||
#endif
|
#endif
|
||||||
# if defined HAVE_GETOPT_LONG
|
# if defined HAVE_GETOPT_LONG
|
||||||
printf(" zzuf -h | --help\n");
|
printf(" zzuf -h | --help\n");
|
||||||
@ -1078,6 +1086,7 @@ static void usage(void)
|
|||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
printf(" -E, --exclude <regex> do not fuzz files matching <regex>\n");
|
printf(" -E, --exclude <regex> do not fuzz files matching <regex>\n");
|
||||||
#endif
|
#endif
|
||||||
|
printf(" -f, --fuzzing <mode> use fuzzing mode <mode> ([xor] set unset)\n");
|
||||||
printf(" -F, --max-forks <n> number of concurrent children (default 1)\n");
|
printf(" -F, --max-forks <n> number of concurrent children (default 1)\n");
|
||||||
printf(" -i, --stdin fuzz standard input\n");
|
printf(" -i, --stdin fuzz standard input\n");
|
||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
@ -1114,6 +1123,7 @@ static void usage(void)
|
|||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
printf(" -E <regex> do not fuzz files matching <regex>\n");
|
printf(" -E <regex> do not fuzz files matching <regex>\n");
|
||||||
#endif
|
#endif
|
||||||
|
printf(" -f <mode> use fuzzing mode <mode>\n");
|
||||||
printf(" -F <n> number of concurrent forks (default 1)\n");
|
printf(" -F <n> number of concurrent forks (default 1)\n");
|
||||||
printf(" -i fuzz standard input\n");
|
printf(" -i fuzz standard input\n");
|
||||||
#if defined HAVE_REGEX_H
|
#if defined HAVE_REGEX_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user