-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauto-fuzz.sh
executable file
·196 lines (165 loc) · 4.53 KB
/
auto-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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
FUZZ_ROOT="/root/xFuzz"
BENCH_ROOT="$FUZZ_ROOT/benchmarks/script"
MULTI_BENCHS="aubio bottleneck jansi jep jna libsmbios msgpack-python one-nio Pillow pycryptodome pycurl simplejson tink ultrajson zstd-jni"
SINGLE_BENCHS="bind9 civetweb cyclonedds e2fsprogs igraph apache-commons javaparser json-sanitizer jsoup zxing bleach pygments pyyaml sqlalchemy urllib3"
FUZZERS="polyfuzz atheris jazzer honggfuzz nsa-polyfuzz"
FUZZER_NAME=$1
IsOk=$(echo $FUZZERS | grep "$FUZZER_NAME")
if [ "$IsOk" == "" ] || [ "$FUZZER_NAME" == "" ]; then
echo "@@@[Warning]please specify the fuzzer[$FUZZERS]:"
exit 0
fi
BENCH_NAME=$2
IsOk=$(echo "$MULTI_BENCHS $SINGLE_BENCHS" | grep "$BENCH_NAME")
if [ "$IsOk" == "" ] || [ "$BENCH_NAME" == "" ]; then
echo "@@@[Warning]None support benchmakrs:"
echo "@@@[Multi-language Benchmarks]: $MULTI_BENCHS"
echo "@@@[Single-language Benchmarks]: $SINGLE_BENCHS"
exit 0
fi
DRIVER_NAME=$3
export FUZZ_WORKING_DIR=""
###############################################################
# init environment
###############################################################
function initEnv ()
{
__conda_setup="$('/root/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/root/anaconda3/etc/profile.d/conda.sh" ]; then
. "/root/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/root/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
export LLVM_PATH=/root/tools/llvm11
export CLANG_PATH=$LLVM_PATH/build/bin
export PATH=$PATH:$CLANG_PATH
export AFLPP=/root/xFuzz/AFLplusplus
export PATH=$PATH:$AFLPP
}
###############################################################
# arg1: fuzzer name
# arg2: benchmark name
###############################################################
function getWorkingDir ()
{
fuzzer=$1
bench=$2
if [ "$fuzzer" == "polyfuzz" ] || [ "$fuzzer" == "nsa-polyfuzz" ]; then
IsOk=$(echo $MULTI_BENCHS | grep "$BENCH_NAME")
if [ "$IsOk" != "" ]; then
export FUZZ_WORKING_DIR="$BENCH_ROOT/multi-benches"
return
fi
IsOk=$(echo $SINGLE_BENCHS | grep "$BENCH_NAME")
if [ "$IsOk" != "" ]; then
echo "result here is $IsOk"
export FUZZ_WORKING_DIR="$BENCH_ROOT/single-benches/c $BENCH_ROOT/single-benches/python $BENCH_ROOT/single-benches/java"
return
fi
elif [ "$fuzzer" == "atheris" ]; then
IsOk=$(echo $MULTI_BENCHS | grep "$BENCH_NAME")
if [ "$IsOk" != "" ]; then
export FUZZ_WORKING_DIR="$BENCH_ROOT/baselines/atheris"
return
fi
elif [ "$fuzzer" == "jazzer" ]; then
IsOk=$(echo $MULTI_BENCHS | grep "$BENCH_NAME")
if [ "$IsOk" != "" ]; then
export FUZZ_WORKING_DIR="$BENCH_ROOT/baselines/jazzer"
return
fi
elif [ "$fuzzer" == "honggfuzz" ]; then
IsOk=$(echo $MULTI_BENCHS | grep "$BENCH_NAME")
if [ "$IsOk" != "" ]; then
export FUZZ_WORKING_DIR="$BENCH_ROOT/baselines/honggfuzz"
return
fi
fi
echo "@@@[Warning]$fuzzer do not support $BENCH_NAME"
exit 0
}
###############################################################
# arg1: benchmark name
# arg2: benchmark dir
###############################################################
function buildBenchmark ()
{
bname=$1
benchmark=$2
if [ ! -d "$bname" ]; then
echo "[buildBenchmark]$bname not exist........."
return 1
fi
cd $bname
# 1. build the benchmark
. build.sh
cd $benchmark
# 2. build the driver if necessary
cd $bname/drivers
if [ -f "build.sh" ]; then
. build.sh
fi
return 0
}
###############################################################
# arg1: driver name
###############################################################
function runFuzzing ()
{
driver=$1
if [ ! -d "$driver" ]; then
if [ -f "docker.cfg" ]; then
driver=$(cat docker.in)
else
driver_list=`ls`
for dr in $driver_list
do
if [ -d "$dr" ]; then
driver=$dr
break
fi
done
fi
if [ ! -d "$driver" ]; then
echo "@@@[Warning]get driver fail..."
exit 0
fi
fi
cd $driver
is_baseline=$(echo $FUZZ_WORKING_DIR | grep "baseline")
if [ "$is_baseline" == "" ]; then
if [ "$fuzzer" == "nsa-polyfuzz" ]; then
export AFL_TRACE_DU_SHUTDOWN=1
fi
./ple_entry.sh
else
./run-fuzzer.sh
fi
}
# 0. init env
initEnv
# 1. build the fuzzer
cd $FUZZ_ROOT
env
. build.sh
cd -
# 2. get working directory
getWorkingDir $FUZZER_NAME $BENCH_NAME
# 3. build the benchmark
for benchmark in $FUZZ_WORKING_DIR
do
cd $benchmark
buildBenchmark $BENCH_NAME $benchmark
if [ "$?" != "0" ]; then
continue
fi
cd $benchmark/$BENCH_NAME/drivers
# 3. run the fuzzing
runFuzzing $DRIVER_NAME
done