2016-03-26 17:19:14 +00:00
|
|
|
# I Can Haz Fuzz?
|
|
|
|
|
2016-05-07 20:09:13 +00:00
|
|
|
LibFuzzer
|
|
|
|
=========
|
|
|
|
|
2016-10-28 18:52:50 +00:00
|
|
|
Or, how to fuzz OpenSSL with [libfuzzer](http://llvm.org/docs/LibFuzzer.html).
|
2016-03-26 17:19:14 +00:00
|
|
|
|
|
|
|
Starting from a vanilla+OpenSSH server Ubuntu install.
|
|
|
|
|
|
|
|
Use Chrome's handy recent build of clang. Older versions may also work.
|
|
|
|
|
|
|
|
$ sudo apt-get install git
|
|
|
|
$ mkdir git-work
|
|
|
|
$ git clone https://chromium.googlesource.com/chromium/src/tools/clang
|
|
|
|
$ clang/scripts/update.py
|
|
|
|
|
|
|
|
You may want to git pull and re-run the update from time to time.
|
|
|
|
|
|
|
|
Update your path:
|
|
|
|
|
|
|
|
$ PATH=~/third_party/llvm-build/Release+Asserts/bin/:$PATH
|
|
|
|
|
|
|
|
Get and build libFuzzer (there is a git mirror at
|
|
|
|
https://github.com/llvm-mirror/llvm/tree/master/lib/Fuzzer if you prefer):
|
|
|
|
|
|
|
|
$ cd
|
|
|
|
$ sudo apt-get install subversion
|
|
|
|
$ mkdir svn-work
|
|
|
|
$ cd svn-work
|
|
|
|
$ svn co http://llvm.org/svn/llvm-project/llvm/trunk/lib/Fuzzer
|
|
|
|
$ cd Fuzzer
|
|
|
|
$ clang++ -c -g -O2 -std=c++11 *.cpp
|
|
|
|
$ ar r libFuzzer.a *.o
|
|
|
|
$ ranlib libFuzzer.a
|
|
|
|
|
|
|
|
Configure for fuzzing:
|
|
|
|
|
2016-05-07 20:09:13 +00:00
|
|
|
$ CC=clang ./config enable-fuzz-libfuzzer \
|
|
|
|
--with-fuzzer-include=../../svn-work/Fuzzer \
|
|
|
|
--with-fuzzer-lib=../../svn-work/Fuzzer/libFuzzer \
|
2016-11-19 16:20:34 +00:00
|
|
|
-DPEDANTIC enable-asan enable-ubsan no-shared \
|
2016-12-02 18:26:31 +00:00
|
|
|
-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
|
|
|
|
-fsanitize-coverage=edge,indirect-calls,8bit-counters
|
2016-03-26 17:19:14 +00:00
|
|
|
$ sudo apt-get install make
|
|
|
|
$ LDCMD=clang++ make -j
|
2016-07-04 00:00:47 +00:00
|
|
|
$ fuzz/helper.py $FUZZER
|
2016-03-26 17:19:14 +00:00
|
|
|
|
2016-07-04 00:00:47 +00:00
|
|
|
Where $FUZZER is one of the executables in `fuzz/`.
|
2016-03-26 17:19:14 +00:00
|
|
|
|
|
|
|
If you get a crash, you should find a corresponding input file in
|
2016-07-04 00:00:47 +00:00
|
|
|
`fuzz/corpora/$FUZZER-crash/`. You can reproduce the crash with
|
2016-03-26 17:19:14 +00:00
|
|
|
|
2016-07-04 00:00:47 +00:00
|
|
|
$ fuzz/$FUZZER <crashfile>
|
2016-05-07 20:09:13 +00:00
|
|
|
|
|
|
|
AFL
|
|
|
|
===
|
|
|
|
|
|
|
|
Configure for fuzzing:
|
|
|
|
|
|
|
|
$ sudo apt-get install afl-clang
|
|
|
|
$ CC=afl-clang-fast ./config enable-fuzz-afl no-shared
|
|
|
|
$ make
|
|
|
|
|
|
|
|
Run one of the fuzzers:
|
|
|
|
|
2016-07-04 00:00:47 +00:00
|
|
|
$ afl-fuzz -i fuzz/corpora/$FUZZER -o fuzz/corpora/$FUZZER/out fuzz/$FUZZER
|
2016-05-07 20:09:13 +00:00
|
|
|
|
2016-07-04 00:00:47 +00:00
|
|
|
Where $FUZZER is one of the executables in `fuzz/`.
|