-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz.sh
executable file
·52 lines (46 loc) · 1.89 KB
/
fuzz.sh
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
#!/bin/sh
die() { echo "Error $1"; exit 100; }
AFL_DIR=`echo ./afl/afl-2*`
AFL_FUZZ=`which afl-fuzz 2>/dev/null || echo $AFL_DIR/afl-fuzz`;
AFL_WHATSUP=`which afl-whatsup 2>/dev/null || echo $AFL_DIR/afl-whatsup`;
[ -f "$AFL_FUZZ" ] || die "missing afl-fuzz -- did you run ./setup.sh ?"
[ -f "$AFL_WHATSUP" ] || die "missing afl-whatsup -- did you run ./setup.sh ?"
OUTPUT_DIR="./findings";
[ "x" = "x$JOBS" ] && which nproc 2>/dev/null >/dev/null && JOBS=`nproc --all`;
[ "x" = "x$JOBS" ] && which grep 2>/dev/null >/dev/null && [ -f /proc/cpuinfo ] && \
JOBS=`grep -c ^processor /proc/cpuinfo`;
[ "x" = "x$JOBS" ] && die 'can'\''t determine number of processors, try `JOBS=2 ./fuzz`';
i=0; while [ "x$i" != "x$JOBS" ]; do
## Safety
[ "x$i" = "x64" ] && die "JOBS doesn't seem to be a number between 0 and 64";
i=$(expr $i + 1);
done
CJDNS_DIR=`echo ./cjdns/build_*`;
INPUT_DIR="$CJDNS_DIR/fuzz_inputs/";
[ -e $OUTPUT_DIR ] && INPUT_DIR="-" && echo "Continuing existing fuzz job";
[ -d ./logs ] || mkdir ./logs || die "could not create log directory";
MS=-M
i=0; while [ "x$i" != "x$JOBS" ]; do
echo "-------------------------------------------------------"
echo "Launching cjdnsfuzz-$i";
echo;
echo '' >./logs/cjdnsfuzz-$i.log
$AFL_FUZZ -i $INPUT_DIR -o $OUTPUT_DIR $MS "cjdnsfuzz-$i" -- \
$CJDNS_DIR/test_testcjdroute_c fuzz --quiet --stderr-to errout.txt --inittests \
2>>./logs/cjdnsfuzz-$i.log >>./logs/cjdnsfuzz-$i.log &
AFL_PID=$!;
tail -f ./logs/cjdnsfuzz-$i.log &
TAIL_PID=$!;
# If we get ^C during the process, we still want to kill the tail process...
( sleep 5 ; kill $TAIL_PID 2>/dev/null ) &
sleep 5;
kill $TAIL_PID 2>/dev/null
kill -0 $AFL_PID || break;
echo;
echo -e "Launched cjdnsfuzz-$i as pid $AFL_PID";
echo;
echo $AFL_PID >> ./fuzzpids
i=$(expr $i + 1);
MS=-S
done
$AFL_WHATSUP -s $OUTPUT_DIR;