From 022c12568b0fed98073f2371655e231bd49e5a07 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Mon, 12 Apr 2021 12:16:45 +0200 Subject: [PATCH] QoL improvements --- .gitignore | 3 ++ fuzzers/libfuzzer_libpng/README.md | 34 ++++++++++++------- .../src/bin/{cc.rs => libafl_cc.rs} | 2 ++ .../src/bin/{cxx.rs => libafl_cxx.rs} | 2 ++ libafl_cc/src/lib.rs | 8 ++++- 5 files changed, 36 insertions(+), 13 deletions(-) rename fuzzers/libfuzzer_libpng/src/bin/{cc.rs => libafl_cc.rs} (93%) rename fuzzers/libfuzzer_libpng/src/bin/{cxx.rs => libafl_cxx.rs} (94%) diff --git a/.gitignore b/.gitignore index 0c466bba6e..3727f15757 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ perf.data.old .vscode test.dict + +# Ignore all built fuzzers +fuzzer_* \ No newline at end of file diff --git a/fuzzers/libfuzzer_libpng/README.md b/fuzzers/libfuzzer_libpng/README.md index 9d33d2f724..8d88900306 100644 --- a/fuzzers/libfuzzer_libpng/README.md +++ b/fuzzers/libfuzzer_libpng/README.md @@ -6,36 +6,46 @@ It has been tested on Linux. ## Build -To build this example, run `cargo build --release`. -This will build the library with the fuzzer (src/lib.rs) with the libfuzzer compatibility layer and the SanitizerCoverage runtime functions for coverage feedback. -In addition, it will build also two C and C++ compiler wrappers (bin/c(c/xx).rs) that you must use to compile the target. - -Then download libpng from https://deac-fra.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.xz and unpack the archive. - -Now compile it with: +To build this example, run +```bash +cargo build --release ``` + +This will build the library with the fuzzer (src/lib.rs) with the libfuzzer compatibility layer and the SanitizerCoverage runtime functions for coverage feedback. +In addition, it will also build two C and C++ compiler wrappers (bin/libafl_c(libafl_c/xx).rs) that you must use to compile the target. + +Then download libpng, and unpack the archive: +```bash +wget https://deac-fra.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.xz +tar -xvf libpng-1.6.37.tar.xz +``` + +Now compile libpng, using the libafl_cc compiler wrapper: + +```bash cd libpng-1.6.37 ./configure -make CC=/path/to/libfuzzer_libpng/target/release/cc -j `nproc` +make CC=../target/release/libafl_cc CXX=../target/release/libafl_cxx -j `nproc` ``` You can find the static lib at `libpng-1.6.37/.libs/libpng16.a`. -Now, we have to build the libfuzzer harness and link all togheter to create our fuzzer binary. +Now, we have to build the libfuzzer harness and link all together to create our fuzzer binary. ``` -/path/to/libfuzzer_libpng/target/debug/cxx /path/to/libfuzzer_libpng/harness.cc libpng-1.6.37/.libs/libpng16.a -I libpng-1.6.37/ -o fuzzer -lz -lm +cd .. +./target/release/libafl_cxx ./harness.cc libpng-1.6.37/.libs/libpng16.a -I libpng-1.6.37/ -o fuzzer_libpng -lz -lm ``` -Afterwards, the fuzzer will be ready to run simply executing `./fuzzer`. +Afterwards, the fuzzer will be ready to run. ## Run The first time you run the binary, the broker will open a tcp port (currently on port `1337`), waiting for fuzzer clients to connect. This port is local and only used for the initial handshake. All further communication happens via shared map, to be independent of the kernel. Currently you must run the clients from the libfuzzer_libpng directory for them to be able to access the PNG corpus. ``` -cargo run --release --example libfuzzer_libpng +./fuzzer_libpng [libafl/src/bolts/llmp.rs:407] "We're the broker" = "We\'re the broker" Doing broker things. Run this tool again to start fuzzing in a client. diff --git a/fuzzers/libfuzzer_libpng/src/bin/cc.rs b/fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs similarity index 93% rename from fuzzers/libfuzzer_libpng/src/bin/cc.rs rename to fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs index ad5b05c084..dc65a9a57b 100644 --- a/fuzzers/libfuzzer_libpng/src/bin/cc.rs +++ b/fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs @@ -27,5 +27,7 @@ fn main() { .add_link_arg("-lAdvapi32".into()) .unwrap(); cc.run().unwrap(); + } else { + panic!("LibAFL CC: No Arguments given"); } } diff --git a/fuzzers/libfuzzer_libpng/src/bin/cxx.rs b/fuzzers/libfuzzer_libpng/src/bin/libafl_cxx.rs similarity index 94% rename from fuzzers/libfuzzer_libpng/src/bin/cxx.rs rename to fuzzers/libfuzzer_libpng/src/bin/libafl_cxx.rs index 842c915ba2..2183682d96 100644 --- a/fuzzers/libfuzzer_libpng/src/bin/cxx.rs +++ b/fuzzers/libfuzzer_libpng/src/bin/libafl_cxx.rs @@ -28,5 +28,7 @@ fn main() { .add_link_arg("-lAdvapi32".into()) .unwrap(); cc.run().unwrap(); + } else { + panic!("LibAFL CC: No Arguments given"); } } diff --git a/libafl_cc/src/lib.rs b/libafl_cc/src/lib.rs index c26675aceb..87fcb27117 100644 --- a/libafl_cc/src/lib.rs +++ b/libafl_cc/src/lib.rs @@ -90,7 +90,13 @@ impl CompilerWrapper for ClangWrapper { let mut new_args = vec![]; if args.is_empty() { return Err(Error::InvalidArguments( - "The number of arguments cannot be 0".into(), + "The number of arguments cannot be 0".to_string(), + )); + } + + if args.len() == 1 { + return Err(Error::InvalidArguments( + "LibAFL Compiler wrapper - no commands specified. Use me as compiler.".to_string(), )); }