-
Notifications
You must be signed in to change notification settings - Fork 4
/
05-deploy.sh
executable file
·185 lines (154 loc) · 4.73 KB
/
05-deploy.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
#!/usr/bin/bash
function usage() {
cat << HEREDOC
Usage: $0 [-b blocklist.txt] [-t timeout] [-v qemu|vbox|all] revision
positional arguments:
revision revision (int) of current fuzzing compaign
optional arguments:
-b, blocklist.txt absolute pathname of the blocked fuzz target
-t, timeout number of seconds we want to run, 86400 by default
-v, qemu|vbox|all virtual machine manager we want to fuzz, all by default
-h show this help message and exit
HEREDOC
exit 1
}
blocklist=$(pwd)/videzzo_tool/blocklist.txt
timeout=86400
vmm='all'
while getopts ":b:t:v:" o; do
case "${o}" in
b)
blocklist=${OPTARG}
;;
t)
timeout=${OPTARG}
;;
v)
vmm=${OPTARG}
((vmm == 'vbox' || vmm == 'qemu' || vmm == 'all')) || usage
;;
*)
usage
;;
esac
done
revision=${@:$OPTIND:1}
if [ -z ${revision} ]; then
usage
fi
echo "[+] === We are going to deploy ViDeZZo. ==="
if [ ! -f "$(pwd)/videzzo.c" ]; then
echo "[+] We are not in the root directory. Exit."
exit 1
fi
if [ ${vmm} = "all" ]; then
make qemu
make vbox
elif [ ${vmm} = "qemu" ]; then
make qemu
elif [ ${vmm} = "vbox" ]; then
make vbox
fi
echo "[+] Load blocklist.txt ..."
__blocklist=()
while IFS= read -r pattern; do
if [ -z "${pattern}" ]; then
continue
elif [ "${pattern:0:1}" = "#" ]; then
continue
else
echo " - ${pattern}"
__blocklist+=("${pattern}")
fi
done < ${blocklist}
function is_blocked() {
filename=$1
echo " - ${filename}"
for pattern in ${__blocklist[@]}; do
case ${filename} in
${pattern}) echo " ~ ${pattern} matched"; return 1 ;;
esac
done
return 0
}
number_of_qemu_fuzz_target=0
number_of_vbox_fuzz_target=0
number_of_fuzz_target=0
qemu_fuzz_target=()
vbox_fuzz_target=()
function count_qemu() {
dir=videzzo_qemu/out-san
for target in ${dir}/*; do
fuzz_target=$(basename ${target})
is_blocked ${fuzz_target}
if [ $? == 0 ]; then
number_of_qemu_fuzz_target=$((number_of_qemu_fuzz_target+1))
qemu_fuzz_target+=("${fuzz_target}")
fi
done
}
function count_vbox() {
dir=videzzo_vbox/out-san
for target in ${dir}/*; do
fuzz_target=$(basename ${target})
is_blocked ${fuzz_target}
if [ $? == 0 ]; then
number_of_vbox_fuzz_target=$((number_of_vbox_fuzz_target+1))
vbox_fuzz_target+=("${fuzz_target}")
fi
done
}
echo "[+] Traverse fuzz targets"
if [ ${vmm} = "all" ]; then
count_qemu
count_vbox
elif [ ${vmm} = "qemu" ]; then
count_qemu
elif [ ${vmm} = "vbox" ]; then
count_vbox
fi
number_of_fuzz_target=$(expr ${number_of_qemu_fuzz_target} + ${number_of_vbox_fuzz_target})
echo "[+] Detect resources"
processors=$(expr $(nproc) - 2)
echo " - ${processors} processors" # 10
echo " - ${timeout} seconds" # 3600
echo " - ${number_of_qemu_fuzz_target} qemu targets"
echo " - ${number_of_vbox_fuzz_target} vbox targets"
echo " - ${number_of_fuzz_target} in total" # 108
echo "[+] Calculate average timeout for each fuzz target"
__batches=$(expr \( ${number_of_fuzz_target} + ${processors} - 1 \) / ${processors}) # 11
echo " - ${__batches} batches"
__timeout=$(expr \( ${timeout} + ${__batches} - 1 \) / ${__batches}) # 360
echo " - ${__timeout} seconds"
gen_cmds=/tmp/videzzo_deploy_cmds.sh
# libfuzzer_args="-fork=1 -ignore_crashes=1 -print_final_stats=1 -max_total_time=${__timeout} -detect_leaks=0 -use_value_profile=1"
libfuzzer_args="-print_final_stats=1 -max_total_time=${__timeout} -detect_leaks=0 -use_value_profile=1"
function gen_qemu_cmds() {
batch=${revision}
dir=videzzo_qemu/out-san
for fuzz_target in ${qemu_fuzz_target[@]}; do
cmd="cd ${dir} && cpulimit -l 100 -f -- ./${fuzz_target} ${libfuzzer_args} >${fuzz_target}-${batch}.log 2>&1 && cd \$OLDPWD"
echo ${cmd} >> ${gen_cmds}
done
}
vbox_env="export VBOX_LOG_DEST=\"nofile stdout\" && export VBOX_LOG=\"+gui.e.l.f\""
function gen_vbox_cmds() {
batch=${revision}
dir=videzzo_vbox/out-san
for fuzz_target in ${vbox_fuzz_target[@]}; do
cmd="cd ${dir} && ${vbox_env} && cpulimit -l 100 -f -- ./${fuzz_target} ${libfuzzer_args} >${fuzz_target}-${batch}.log 2>&1 && cd \$OLDPWD"
echo ${cmd} >> ${gen_cmds}
done
}
echo "[+] Generate deploy commands"
rm -f ${gen_cmds}
if [ ${vmm} = "all" ]; then
gen_qemu_cmds
gen_vbox_cmds
elif [ ${vmm} = "qemu" ]; then
gen_qemu_cmds
elif [ ${vmm} = "vbox" ]; then
gen_vbox_cmds
fi
echo "[+] Will run ${gen_cmds}"
parallel -j${processors} --bar < ${gen_cmds}