Fuzzing stdio-wrapped knotd with AFL
- Ensure Clang
- Ensure AFL 1.83b+ or install a fresh one
curl -O -L http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz
tar -xzf afl-latest.tgz
cd afl-*/
make
make -C llvm_mode
sudo make install
- Compile Knot DNS with
afl-clang
compilerCC=afl-clang-fast ./configure --disable-shared --disable-utilities --disable-documentation
- (Add
--with-sanitizer=address
for ASAN) make
- Try running
knotd_stdio
cd tests-fuzz
make check-compile
mkdir -p /tmp/knotd-fuzz/rundir /tmp/knotd-fuzz/storage
./knotd_stdio -c ./knotd_wrap/knot_stdio.conf
- (Consider adding zones or modules to the configuration)
- Prepare an initial corpus
- Checkout the dns-fuzzing repository
git clone https://github.com/CZ-NIC/dns-fuzzing in
- (Add more custom test cases to
in/packet/
)
- Checkout the dns-fuzzing repository
- Minimize the tested corpus with
afl-cmin
and simple packet parser (doesn't work with ASAN!)afl-cmin -i in/packet/ -o min -- ./fuzz_packet
- Run the fuzzer
AFL_PERSISTENT=1 afl-fuzz -m 1000M -i min -o out -- ./knotd_stdio -c knotd_wrap/knot_stdio.conf
- (Add
AFL_USE_ASAN=1
and use-m none
if compiled with ASAN) - (Consider parallel fuzzing, see
afl-fuzz -h
)
NOTE: Sanitizer utilization is a bit problematical with AFL, see [notes_for_asan.txt] (https://github.com/mirrorer/afl/blob/master/docs/notes_for_asan.txt).
Fuzzing with libFuzzer (requires Clang 6.0+)
- Ensure Clang with
-fsanitize=fuzzer
support (e.g. LLVM) - Configure with
- Compile Knot DNS:
make
- Create and check the fuzzing binaries
cd tests-fuzz
make check
- Download the corpora
git submodule init
git submodule update --recursive --remote
- (Optional) add more test cases
./fuzz_packet -merge=1 fuzz_packet.in <DIR_WITH_NEW_PACKET_TEST_CASES>
./fuzz_zscanner -merge=1 fuzz_zscanner.in <DIR_WITH_NEW_ZSCANNER_TEST_CASES>
- Run the fuzzer
- (Set proper symbolizer if necessary
export ASAN_SYMBOLIZER_PATH=$(readlink -f `which llvm-symbolizer-6.0`)
for ASAN orexport UBSAN_SYMBOLIZER_PATH=$(readlink -f `which llvm-symbolizer-6.0`)
for UBSAN) ./fuzz_packet fuzz_packet.in
or./fuzz_zscanner fuzz_zscanner.in
- (Add parallel fuzzing
-jobs=<CPUS>
- (Set proper symbolizer if necessary