forked from electricworry/fuzzing-helloworld
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
406 lines (368 loc) · 12.9 KB
/
Copy pathMakefile
File metadata and controls
406 lines (368 loc) · 12.9 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
WORKSPACE = /workspaces/helloworld
AFL_HOME = $(WORKSPACE)/extern/AFLplusplus
AFL_FUZZ = $(AFL_HOME)/afl-fuzz
HONGGFUZZ = $(WORKSPACE)/extern/honggfuzz/honggfuzz
HFUZZ_CC = $(WORKSPACE)/extern/honggfuzz/hfuzz_cc/hfuzz-pcguard-clang
LIBAFL_FUZZ = $(WORKSPACE)/extern/LibAFL/fuzzers/forkserver/libafl-fuzz/target/release/libafl-fuzz
AFL_CC = $(AFL_HOME)/afl-cc
LAFL_QL = $(WORKSPACE)/libafl_qemu/target/debug/qemu_launcher
CLANG = /usr/bin/clang
CORPUS = $(WORKSPACE)/corpus
OUTPUT = $(WORKSPACE)/output
SRC_VULN_PROG_DIR = $(WORKSPACE)/src/vuln_prog
SRC_VULN_PROG_HOOK_DIR = $(WORKSPACE)/src/vuln_prog_persistent_hook
TARGET_PROG = $(WORKSPACE)/targets/vuln_prog
TARGET_PROG_PERSIST_HOOK = $(WORKSPACE)/targets/vuln_prog_persistent_hook.so
TARGET_PROG_SLOWINIT = $(WORKSPACE)/targets/vuln_prog_slowinit
TARGET_PROG_ASAN = $(WORKSPACE)/targets/vuln_prog_asan
TARGET_PROG_HONGGFUZZ = $(WORKSPACE)/targets/vuln_prog_honggfuzz
TARGET_PROG_HARDEN = $(WORKSPACE)/targets/vuln_prog_harden
SRC_VULN_PROG_SLOWINIT = $(WORKSPACE)/src/vuln_prog_slowinit
SRC_VULN_PROG_PERSIST_DIR = $(WORKSPACE)/src/vuln_prog_persist
TARGET_PROG_PERSIST_ASAN = $(WORKSPACE)/targets/vuln_prog_persist_asan
SRC_VULN_PROG_SHMEM_DIR = $(WORKSPACE)/src/vuln_prog_shmem
TARGET_PROG_SHMEM_ASAN = $(WORKSPACE)/targets/vuln_prog_shmem_asan
SRC_VULN_LIB_DIR = $(WORKSPACE)/src/vuln_lib
SRC_VULN_LIB_HARNESS = $(WORKSPACE)/src/vuln_lib_harness/harness.c
SRC_VULN_LIB_HARNESS_LF = $(WORKSPACE)/src/vuln_lib_harness/libfuzzer_target.c
TARGET_LIB_DIR = $(WORKSPACE)/targets/lib
TARGET_LIB_STATIC_BIN = $(WORKSPACE)/targets/vuln_lib_static_bin
TARGET_LIB_STATIC_LF_BIN = $(WORKSPACE)/targets/vuln_lib_libfuzzer_static
TARGET_LIB_DYNAMIC_BIN = $(WORKSPACE)/targets/vuln_lib_dynamic_bin
##
## Source-code programs
##
# AFL++ source-code program w/ ASAN + CMPLOG - using file inputs
.PHONY: fuzz_01_afl_asan_file
fuzz_01_afl_asan_file: $(TARGET_PROG_ASAN) $(AFL_FUZZ)
AFL_PIZZA_MODE=1 \
$(AFL_FUZZ) \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c $<.cmplog \
-- \
$< @@
$(TARGET_PROG_ASAN): $(AFL_CC)
cd $(SRC_VULN_PROG_DIR) && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_USE_ASAN=1 && \
mv imgRead $@ && \
./configure CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 && \
mv imgRead $@.cmplog
# libafl-fuzz source-code program w/ ASAN + CMPLOG (incomplete port of afl++ to Rust/LibAFL)
.PHONY: fuzz_01_libaflfuzz_asan_file
fuzz_01_libaflfuzz_asan_file: $(TARGET_PROG_ASAN) $(LIBAFL_FUZZ)
cd tmp && \
AFL_CORES=0-15 \
$(LIBAFL_FUZZ) \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c $<.cmplog \
$<
# Honggfuzz source-code program w/ ASAN - using file inputs
.PHONY: fuzz_01_honggfuzz_file
fuzz_01_honggfuzz_file: $(TARGET_PROG_HONGGFUZZ) $(HONGGFUZZ)
cd tmp && $(HONGGFUZZ) \
-i $(CORPUS) \
-z \
-- \
$< ___FILE___
$(TARGET_PROG_HONGGFUZZ): $(HFUZZ_CC)
cd $(SRC_VULN_PROG_DIR) && \
autoreconf -i && \
./configure CC=$(HFUZZ_CC) HFUZZ_CC_ASAN=1 HFUZZ_CC_UBSAN=1 CFLAGS="-fno-omit-frame-pointer" && \
make clean && \
make HFUZZ_CC_ASAN=1 HFUZZ_CC_UBSAN=1 && \
mv imgRead $@
# Honggfuzz source-code program w/ ASAN - using stdin
.PHONY: fuzz_01_honggfuzz_stdin
fuzz_01_honggfuzz_stdin: $(TARGET_PROG_HONGGFUZZ) $(HONGGFUZZ)
cd tmp && $(HONGGFUZZ) \
-i $(CORPUS) \
-z \
-s \
-- \
$<
# AFL++ source-code program w/ ASAN + CMPLOG - using stdin
.PHONY: fuzz_02_afl_asan_stdin
fuzz_02_afl_asan_stdin: $(TARGET_PROG_ASAN)
$(AFL_FUZZ) \
-i $(CORPUS) \
-o output/$@ \
-c $<.cmplog \
-- \
$<
# AFL++ source-code program with hardening/CMPLOG - using file inputs
.PHONY: fuzz_03_afl_harden
fuzz_03_afl_harden: $(TARGET_PROG_HARDEN)
$(AFL_FUZZ) \
-i $(CORPUS) \
-o output/$@ -P exploit \
-c $<.cmplog \
-- \
$< @@
$(TARGET_PROG_HARDEN): $(AFL_CC)
cd $(SRC_VULN_PROG_DIR) && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_HARDEN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_HARDEN=1 && \
mv imgRead $@ && \
./configure CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_HARDEN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_LLVM_CMPLOG=1 AFL_HARDEN=1 && \
mv imgRead $@.cmplog
# Deferred fork-server + persistent mode to defeat slow initialisation.
# Must use file input; STDIN won't work.
.PHONY: fuzz_04_afl_asan_persist
fuzz_04_afl_asan_persist: $(TARGET_PROG_PERSIST_ASAN)
$(AFL_FUZZ) \
-i $(CORPUS) \
-o output/$@ \
-c $<.cmplog \
-- \
$< @@
$(TARGET_PROG_PERSIST_ASAN): $(AFL_CC)
cd $(SRC_VULN_PROG_PERSIST_DIR) && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_USE_ASAN=1 && \
mv imgRead $@ && \
./configure CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 && \
mv imgRead $@.cmplog
# Add shared memory fuzzing.
# File/STDIN input options are ignored.
.PHONY: fuzz_05_afl_asan_shmem
fuzz_05_afl_asan_shmem: $(TARGET_PROG_SHMEM_ASAN)
$(AFL_FUZZ) \
-i $(CORPUS) \
-o output/$@ \
-c $<.cmplog \
-- \
$<
$(TARGET_PROG_SHMEM_ASAN): $(AFL_CC)
cd $(SRC_VULN_PROG_SHMEM_DIR) && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_USE_ASAN=1 && \
mv imgRead $@ && \
./configure CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" && \
make clean && \
make AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 && \
mv imgRead $@.cmplog
##
## Source-code libraries
##
# AFL++ source-code library (static) w/ CMPLOG - ASAN not supported on static builds
.PHONY: fuzz_06_afl_harden
fuzz_06_afl_harden: $(TARGET_LIB_STATIC_BIN)
$(AFL_FUZZ) \
-i $(CORPUS) \
-o output/$@ \
-c $<.cmplog \
-- \
$<
$(TARGET_LIB_STATIC_BIN): $(SRC_VULN_LIB_HARNESS) $(AFL_CC)
cd $(SRC_VULN_LIB_DIR) && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_HARDEN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" --prefix=$(shell dirname $<)/libs && \
make clean && \
make AFL_HARDEN=1 && \
make install
cd $(shell dirname $<) && \
make CC=$(AFL_CC) AFL_HARDEN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" clean vuln_lib_static_harness && \
mv vuln_lib_static_harness $@
cd $(SRC_VULN_LIB_DIR) && \
./configure CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_HARDEN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" --prefix=$(shell dirname $<)/libs && \
make clean && \
make AFL_LLVM_CMPLOG=1 AFL_HARDEN=1 && \
make install
cd $(shell dirname $<) && \
make CC=$(AFL_CC) AFL_HARDEN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" clean vuln_lib_static_harness && \
mv vuln_lib_static_harness $@.cmplog
# LibFuzzer source-code library (dynamic) w/ ASAN
# For cmdline options see: https://llvm.org/docs/LibFuzzer.html
.PHONY: fuzz_07_libfuzzer
fuzz_07_libfuzzer: $(TARGET_LIB_STATIC_LF_BIN)
cd tmp && \
LD_LIBRARY_PATH=$(TARGET_LIB_DIR) $(TARGET_LIB_STATIC_LF_BIN) $(CORPUS)
$(TARGET_LIB_STATIC_LF_BIN): $(SRC_VULN_LIB_HARNESS_LF) $(CLANG) $(TARGET_LIB_DIR)
cd $(SRC_VULN_LIB_DIR) && \
autoreconf -i && \
./configure CC=$(CLANG) CFLAGS="-g -O1 -fsanitize=fuzzer-no-link,address,undefined -fno-omit-frame-pointer" --prefix=$(shell dirname $<)/libs && \
make clean && \
make && \
make install
cd $(shell dirname $<) && \
make CC=$(CLANG) CFLAGS="-g -O1 -fsanitize=fuzzer,address,undefined -fno-omit-frame-pointer" clean vuln_lib_libfuzzer_dynamic_harness && \
mv vuln_lib_libfuzzer_dynamic_harness $@ && \
cp libs/lib/libimgread.so.0 $(TARGET_LIB_DIR)
# AFL++ source-code library (dynamic) - w/ ASAN + CMPLOG
.PHONY: fuzz_07_afl_asan
fuzz_07_afl_asan: $(TARGET_LIB_DYNAMIC_BIN)
AFL_TARGET_ENV=LD_LIBRARY_PATH=$(TARGET_LIB_DIR) \
$(AFL_FUZZ) \
-i $(CORPUS) \
-o output/$@ \
-c $<.cmplog \
-- \
$<
$(TARGET_LIB_DYNAMIC_BIN): $(SRC_VULN_LIB_HARNESS) $(AFL_CC) $(TARGET_LIB_DIR)
cd $(SRC_VULN_LIB_DIR) && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" --prefix=$(shell dirname $<)/libs && \
make clean && \
make AFL_USE_ASAN=1 && \
make install
cd $(shell dirname $<) && \
make CC=$(AFL_CC) AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" vuln_lib_dynamic_harness && \
mv vuln_lib_dynamic_harness $@ && \
cp libs/lib/libimgread.so.0 $(TARGET_LIB_DIR)
cd $(SRC_VULN_LIB_DIR) && \
sed -r -i 's/(libimgread)/\1_cmplog/g' configure.ac && \
sed -r -i 's/(libimgread)/\1_cmplog/g' Makefile.am && \
autoreconf -i && \
./configure CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" --prefix=$(shell dirname $<)/libs && \
make clean && \
make AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 && \
make install && \
git checkout configure.ac Makefile.am
cd $(shell dirname $<) && \
make CC=$(AFL_CC) AFL_LLVM_CMPLOG=1 AFL_USE_ASAN=1 CFLAGS="-fno-omit-frame-pointer -fsanitize=undefined" vuln_lib_dynamic_harness.cmplog && \
mv vuln_lib_dynamic_harness.cmplog $@.cmplog && \
cp libs/lib/libimgread_cmplog.so.0 $(TARGET_LIB_DIR)
##
## Binary-only simulations
##
# GCC compiled program - AFL++ QEMU mode - using file inputs
.PHONY: fuzz_11_afl_qemu_file
fuzz_11_afl_qemu_file: $(TARGET_PROG_SLOWINIT) $(AFL_FUZZ)
AFL_QEMU_PERSISTENT_MEM=1 \
$(AFL_FUZZ) \
-Q \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c 0 \
-- \
$< @@
$(TARGET_PROG_SLOWINIT):
cd $(SRC_VULN_PROG_SLOWINIT) && \
autoreconf -i && \
./configure CFLAGS="-O2" && \
make clean && \
make && \
mv imgRead $@
# GCC compiled program - AFL++ QEMU mode - stdin
.PHONY: fuzz_11_afl_qemu_stdin
fuzz_11_afl_qemu_stdin: $(TARGET_PROG_SLOWINIT) $(AFL_FUZZ)
AFL_QEMU_PERSISTENT_MEM=1 \
$(AFL_FUZZ) \
-Q \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c 0 \
-- \
$<
# GCC compiled program - AFL++ QEMU mode - deferred; see docs/afl_qemu_deferred.md
.PHONY: fuzz_11_afl_qemu_defer
fuzz_11_afl_qemu_defer: $(TARGET_PROG_SLOWINIT) $(AFL_FUZZ)
AFL_QEMU_PERSISTENT_MEM=1 \
AFL_ENTRYPOINT=$(shell printf "%#x\n" $$((0x4000000000 + 0x11fd))) \
$(AFL_FUZZ) \
-Q \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c 0 \
-- \
$< @@
# GCC compiled program - AFL++ QEMU mode - persistent; see docs/afl_qemu_persistent.md
.PHONY: fuzz_11_afl_qemu_persist
fuzz_11_afl_qemu_persist: $(TARGET_PROG_SLOWINIT) $(AFL_FUZZ)
AFL_QEMU_PERSISTENT_MEM=1 \
AFL_QEMU_PERSISTENT_EXITS=1 \
AFL_QEMU_PERSISTENT_GPR=1 \
AFL_QEMU_PERSISTENT_CNT=10000 \
AFL_ENTRYPOINT=$(shell printf "%#x\n" $$((0x4000000000 + 0x11fd))) \
AFL_QEMU_PERSISTENT_ADDR=$(shell printf "%#x\n" $$(( 0x4000000000 + 0x11fd ))) \
AFL_QEMU_PERSISTENT_RET=$(shell printf "%#x\n" $$(( 0x4000000000 + 0x11e4 ))) \
$(AFL_FUZZ) \
-Q \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c 0 \
-- \
$< @@
# GCC compiled program - AFL++ QEMU mode - in-memory; see docs/afl_qemu_persistent.md
.PHONY: fuzz_11_afl_qemu_persist_hook
fuzz_11_afl_qemu_persist_hook: $(TARGET_PROG_SLOWINIT) $(AFL_FUZZ) $(TARGET_PROG_PERSIST_HOOK)
dd if=/dev/zero of=tmp/dummy bs=1k count=4
AFL_QEMU_PERSISTENT_MEM=1 \
AFL_QEMU_PERSISTENT_EXITS=1 \
AFL_QEMU_PERSISTENT_GPR=1 \
AFL_QEMU_PERSISTENT_CNT=10000 \
AFL_ENTRYPOINT=$(shell printf "%#x\n" $$(( 0x4000000000 + 0x11df ))) \
AFL_QEMU_PERSISTENT_ADDR=$(shell printf "%#x\n" $$(( 0x4000000000 + 0x11df ))) \
AFL_QEMU_PERSISTENT_RET=$(shell printf "%#x\n" $$(( 0x4000000000 + 0x11e4 ))) \
AFL_QEMU_PERSISTENT_HOOK=$(TARGET_PROG_PERSIST_HOOK) \
$(AFL_FUZZ) \
-Q \
-i $(CORPUS) \
-o $(OUTPUT)/$@ \
-c 0 \
-- \
$< tmp/dummy
$(TARGET_PROG_PERSIST_HOOK): $(SRC_VULN_PROG_HOOK_DIR)
cd $(SRC_VULN_PROG_HOOK_DIR) && \
make all && \
cp read_into_rdi.so $@
# GCC compiled program - LibAFL's qemu_launcher example
# 5.256M exec/s
.PHONY: fuzz_11_libafl_qemu_launcher
fuzz_11_libafl_qemu_launcher: $(TARGET_PROG_SLOWINIT) $(LAFL_QL)
dd if=/dev/zero of=tmp/dummy bs=1k count=4
ulimit -c 0
RUST_LOG=info \
$(LAFL_QL) \
--input $(CORPUS) \
--output $(OUTPUT)/$@ \
--log tmp/qemu_launcher.log \
--cores 0 \
-v \
--include 0x0-0xffffffffffffffff \
--entrypoint $(shell printf "%#x\n" $$(( 0x0000555555556000 + 0x11dc ))) \
--exitpoint $(shell printf "%#x\n" $$(( 0x0000555555556000 + 0x11e1 ))) \
-- \
$< tmp/dummy
.PHONY: clean
clean:
rm -rf tmp/* tmp/.cur_input_* targets/* output/* core *.core crash-* .cur_input_*
$(TARGET_LIB_DIR):
mkdir -p $@
$(AFL_CC) $(AFL_FUZZ):
cd extern/AFLplusplus && \
make distrib
$(LIBAFL_FUZZ):
cd $(LIBAFL_FUZZ)/../../.. && \
cargo build --release
$(HFUZZ_CC) $(HONGGFUZZ):
cd $(HONGGFUZZ)/.. && \
make
$(LAFL_QL):
cd libafl_qemu && \
PROFILE=dev ARCH=x86_64 just build
.PHONY: libafl-qemu-run
libafl-qemu-run:
cd libafl_qemu && \
cargo make run
.PHONY: clean
libafl:
cd extern/LibAFL && \
cargo build --release