Skip to content

Commit d991395

Browse files
vj-27Vimal Josephdomenukks1341marcograss
authored
Launcher (#48)
* launcher in linux * silence stdout and stderr linux * arg parser and other changes * retry instead of sleep * no_std fixes * reordered includes * launcher for windows and kill clients when broker returns * cargo fmt * started launcher api cleanup * use closures instead of functions * small change * reordered launcher params * fixed clippy warnings * fixed no_std * moved launcher example to own folder * docu * cleanup launcher * more docs * Fix merge issues * Rework the launcher code to provide a cleaner API * Open file before spawning clients * launcher: fix merge issue, sleep for a different amount for each core * fixed no_std * Tcp Broker to Broker Communication (#66) * initial b2b implementation * no_std and clippy fixes * b2b testcase added * more correct testcases * fixed b2b * typo * fixed unused warning * some clippy warning ignored * using clippy.sh * Update README.md * fixed clippy run in workflow * fixing clippy::match-same-arms * make clippy less pedantic * fixed some minor typos in the book * launcher: use s1341's fork of core_affinity * Build warning fix proposal, mostly about reference to packed fields. (#79) * Observers refactor (#84) * new observer structure with HasExecHooks * adapt libafl_frida to new observers * docstrings * Composing feedback (#85) * composing feedbacks as logic operations and bump to 0.2 * adapt fuzzers and libafl_frida * fix windows build * fixed clippy warnings * Frida suppress instrumentation locations option (#87) * Implement frida option * Format * add append/discard_metadata for and/or/not feedback (#86) * add append/discard_metadata for and/or/not feedback * fix * Call append_metadata on crash (#88) * Call append_metadata on crash * Formatting * Reachability example (#65) * add reachability observer/feedback * add fuzzer exmaple * fmt * remove reachabilityobserver, use stdmapobserver instead * update diff.patch * update README * fix the clippy warning * Squashed commit of the following: commit f20524e Author: Andrea Fioraldi <[email protected]> Date: Tue May 4 16:00:39 2021 +0200 Composing feedback (#85) * composing feedbacks as logic operations and bump to 0.2 * adapt fuzzers and libafl_frida * fix windows build commit e06efaa Author: Andrea Fioraldi <[email protected]> Date: Tue May 4 13:54:46 2021 +0200 Observers refactor (#84) * new observer structure with HasExecHooks * adapt libafl_frida to new observers * docstrings commit 17c6fcd Merge: 08a2d43 a78a4b7 Author: Andrea Fioraldi <[email protected]> Date: Mon May 3 11:16:49 2021 +0200 Merge branch 'main' into dev commit 08a2d43 Author: David CARLIER <[email protected]> Date: Mon May 3 10:15:28 2021 +0100 Build warning fix proposal, mostly about reference to packed fields. (#79) commit 88fe8fa Merge: d5d46ad d2e7719 Author: Andrea Fioraldi <[email protected]> Date: Mon May 3 11:05:42 2021 +0200 Merge pull request #80 from marcograss/book-typos fixed some minor typos in the book commit a78a4b7 Author: s1341 <[email protected]> Date: Mon May 3 10:34:15 2021 +0300 frida-asan: Un-inline report funclet to reduce code bloat (#81) * frida-asan: Outline report funclet to reduce code bloat * fmt commit d2e7719 Author: Marco Grassi <[email protected]> Date: Sun May 2 21:58:33 2021 +0800 fixed some minor typos in the book commit d5d46ad Author: Dominik Maier <[email protected]> Date: Sat May 1 23:09:10 2021 +0200 make clippy less pedantic commit 52d25e9 Author: Dominik Maier <[email protected]> Date: Sat May 1 22:23:59 2021 +0200 fixing clippy::match-same-arms commit cd66f88 Author: Dominik Maier <[email protected]> Date: Sat May 1 14:02:07 2021 +0200 fixed clippy run in workflow commit ddcf086 Author: Dominik Maier <[email protected]> Date: Sat May 1 13:53:29 2021 +0200 Update README.md commit c715f1f Author: Dominik Maier <[email protected]> Date: Sat May 1 13:48:38 2021 +0200 using clippy.sh commit 9374b26 Author: Dominik Maier <[email protected]> Date: Sat May 1 13:47:44 2021 +0200 some clippy warning ignored commit b9e75c0 Author: Dominik Maier <[email protected]> Date: Sat May 1 13:24:02 2021 +0200 Tcp Broker to Broker Communication (#66) * initial b2b implementation * no_std and clippy fixes * b2b testcase added * more correct testcases * fixed b2b * typo * fixed unused warning * feedbacks now return a boolean value * use feedback_or, and modify Cargo.toml * fix diff between dev and this branch * fmt Co-authored-by: Dominik Maier <[email protected]> * clippy fixes * clippy fixes * clippy fixes, x86_64 warnings * more docs * Observers lifetime (#89) * introduce MatchName and alow lifetimes in observers * adapt fuzzers to observers with lifetime * introduce type_eq when on nightly * fix no_std * fmt * Better docu (#90) * more docs * more docs: * more docu * more docu * finished docs * cleaned up markup * must_use tags added * more docs * more docu, less clippy * more fixes * Clippy fixes (#92) * more docs * more docs: * more docu * more docu * finished docs * cleaned up markup * must_use tags added * more docs * swapped if/else, as per clippy * more docu, less clippy * more fixes * Fix merge issues * Get rid of unneeded prints * Fix merge errors * added b2b to restarting interface * Setting SO_REUSEPORT * added b2b to launcher api * more windows launcher * Fix merge errors * Add b2b support to frida_libpng * make frida_libpng bind to a public address * Convert launcher into a builder LauncherBuilder * formatting * Convert setup_restarting_mgr to a builder RestartingMgrBuilder; leave setup_restarting_mgr_std as is, so that fuzzers work * RcShmem should be locked via a mutex * Wait at least 1 second between broker and first client, to avoid race * update frida_libpng README for cross-compiling to android (#100) Co-authored-by: Ariel Zentner <[email protected]> * Fixed build for Windows * no_std fixes * reverted aa6773d & windows fixes * added pipes, moving to remove race conditions for rc shmem * fix unix build * fixed clippy: * fixed no_std once more * renamed b2b to remote_broker_addr * you get a pre_fork, and you get a post_fork, forks for everyone * switched to typed_builder * Fix merge isseu * Fix frida fuzzer with new Launcher builder * Introspection (#97) * Rework to put `ClientPerfStats` in `State` and pass that along. Still need to work on getting granular information from `Feedback` and `Observer` * Add perf_stats feature to libafl/Cargo.toml * Update feedbacks to have with_perf * Remove unneeeded print statement * cargo fmt all the things * use local llvmint vs cpu specific asm for reading cycle counter * Remove debug testing code * Stats timeout to 3 seconds * Inline smallish functions for ClientPerfStats * Remove .libs/llvmint and have the correct conditional compilation of link_llvm_intrinsics on the perf_stats feature * pub(crate) the NUM_FEEDBACK and NUM_STAGES consts * Tcp Broker to Broker Communication (#66) * initial b2b implementation * no_std and clippy fixes * b2b testcase added * more correct testcases * fixed b2b * typo * fixed unused warning * clippy fixes * fallback to systemtime on non-x86 * make clippy more strict * small fixes * bump 0.2.1 * readme Co-authored-by: ctfhacker <[email protected]> Co-authored-by: Dominik Maier <[email protected]> * typos (please review) * merged clippy.sh * utils * Add asan cores option (#102) * added asan-cores option for frida fuzzer When asan is enabled (via LIBBAFL_FRIDA_OPTIONS enable-asan), you can filter exactly which of the cores asan should run on with the asan-cores variable. * add is_some check instead of !None Co-authored-by: Ariel Zentner <[email protected]> * moved utils to bolts * fixed typo * no_std fixes * unix fixes * fixed unix no_std build * fix llmp.rs * adapt libfuzzer_libpng_launcher * added all fuzzers to ci * fmt, improved ci * tests crate not ready for prime time * clippy fixes * make ci script executable * trying to fix example fuzzers * working libfuzzer_libpng_laucnher * frida_libpng builds * clippy * bump version * fix no_std * fix dep version * clippy fixes * more fies * clippy++ * warn again * clearer readme Co-authored-by: Vimal Joseph <[email protected]> Co-authored-by: Dominik Maier <[email protected]> Co-authored-by: s1341 <[email protected]> Co-authored-by: Marco Grassi <[email protected]> Co-authored-by: s1341 <[email protected]> Co-authored-by: Andrea Fioraldi <[email protected]> Co-authored-by: David CARLIER <[email protected]> Co-authored-by: Toka <[email protected]> Co-authored-by: r-e-l-z <[email protected]> Co-authored-by: Ariel Zentner <[email protected]> Co-authored-by: ctfhacker <[email protected]> Co-authored-by: hexcoder <[email protected]>
1 parent b519363 commit d991395

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2068
-694
lines changed

.github/workflows/build_and_test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ jobs:
6060
run: cargo test --all-features --doc
6161
- name: Run clippy
6262
run: ./clippy.sh
63+
- name: Build fuzzers
64+
run: ./build_all_fuzzers.sh
6365
windows:
6466
runs-on: windows-latest
6567
steps:

build_all_fuzzers.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
# TODO: This should be rewritten in rust, a Makefile, or some platform-independent language
4+
5+
cd fuzzers
6+
7+
for fuzzer in *;
8+
do
9+
echo "[+] Checking fmt, clippy, and building $fuzzer"
10+
cd $fuzzer \
11+
&& cargo fmt --all -- --check \
12+
&& ../../clippy.sh --no-clean \
13+
&& cargo build \
14+
&& cd .. \
15+
|| exit 1
16+
done

clippy.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/bin/sh
22
# Clippy checks
3-
cargo clean -p libafl
3+
if [ "$1" != "--no-clean" ]; then
4+
# Usually, we want to clean, since clippy won't work otherwise.
5+
echo "[+] Cleaning up previous builds..."
6+
cargo clean -p libafl
7+
fi
48
RUST_BACKTRACE=full cargo clippy --all --all-features --tests -- \
59
-D clippy::pedantic \
6-
-W clippy::similar-names \
710
-W clippy::unused_self \
811
-W clippy::too_many_lines \
912
-W clippy::option_if_let_else \
1013
-W clippy::must-use-candidate \
1114
-W clippy::if-not-else \
15+
-W clippy::similar-names \
1216
-A clippy::type_repetition_in_bounds \
1317
-A clippy::missing-errors-doc \
1418
-A clippy::cast-possible-truncation \

docs/src/baby_fuzzer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ Now you can prepend the following `use` directives to your main.rs and compile i
156156
```rust
157157
use std::path::PathBuf;
158158
use libafl::{
159+
bolts::{current_nanos, rands::StdRand},
159160
corpus::{InMemoryCorpus, OnDiskCorpus, QueueCorpusScheduler},
160161
events::SimpleEventManager,
161162
executors::{inprocess::InProcessExecutor, ExitKind},
162163
generators::RandPrintablesGenerator,
163164
state::State,
164165
stats::SimpleStats,
165-
utils::{current_nanos, StdRand},
166166
};
167167
```
168168

fuzzers/baby_fuzzer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "baby_fuzzer"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Andrea Fioraldi <[email protected]>", "Dominik Maier <[email protected]>"]
55
edition = "2018"
66

fuzzers/baby_fuzzer/src/main.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
use libafl::{
4-
bolts::tuples::tuple_list,
4+
bolts::{current_nanos, rands::StdRand, tuples::tuple_list},
55
corpus::{InMemoryCorpus, OnDiskCorpus, QueueCorpusScheduler},
66
events::SimpleEventManager,
77
executors::{inprocess::InProcessExecutor, ExitKind},
@@ -13,25 +13,26 @@ use libafl::{
1313
stages::mutational::StdMutationalStage,
1414
state::StdState,
1515
stats::SimpleStats,
16-
utils::{current_nanos, StdRand},
1716
};
1817

19-
// Coverage map with explicit assignments due to the lack of instrumentation
18+
/// Coverage map with explicit assignments due to the lack of instrumentation
2019
static mut SIGNALS: [u8; 16] = [0; 16];
2120

21+
/// Assign a signal to the signals map
2222
fn signals_set(idx: usize) {
2323
unsafe { SIGNALS[idx] = 1 };
2424
}
2525

26+
#[allow(clippy::similar_names)]
2627
pub fn main() {
2728
// The closure that we want to fuzz
2829
let mut harness = |buf: &[u8]| {
2930
signals_set(0);
30-
if buf.len() > 0 && buf[0] == 'a' as u8 {
31+
if !buf.is_empty() && buf[0] == b'a' {
3132
signals_set(1);
32-
if buf.len() > 1 && buf[1] == 'b' as u8 {
33+
if buf.len() > 1 && buf[1] == b'b' {
3334
signals_set(2);
34-
if buf.len() > 2 && buf[2] == 'c' as u8 {
35+
if buf.len() > 2 && buf[2] == b'c' {
3536
panic!("=)");
3637
}
3738
}
@@ -86,21 +87,21 @@ pub fn main() {
8687
&mut state,
8788
&mut mgr,
8889
)
89-
.expect("Failed to create the Executor".into());
90+
.expect("Failed to create the Executor");
9091

9192
// Generator of printable bytearrays of max size 32
9293
let mut generator = RandPrintablesGenerator::new(32);
9394

9495
// Generate 8 initial inputs
9596
state
9697
.generate_initial_inputs(&mut fuzzer, &mut executor, &mut generator, &mut mgr, 8)
97-
.expect("Failed to generate the initial corpus".into());
98+
.expect("Failed to generate the initial corpus");
9899

99100
// Setup a mutational stage with a basic bytes mutator
100101
let mutator = StdScheduledMutator::new(havoc_mutations());
101102
let mut stages = tuple_list!(StdMutationalStage::new(mutator));
102103

103104
fuzzer
104105
.fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
105-
.expect("Error in the fuzzing loop".into());
106+
.expect("Error in the fuzzing loop");
106107
}

fuzzers/frida_libpng/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "frida_libpng"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Andrea Fioraldi <[email protected]>", "Dominik Maier <[email protected]>"]
55
edition = "2018"
66
build = "build.rs"
@@ -21,17 +21,18 @@ num_cpus = "1.0"
2121
which = "4.1"
2222

2323
[target.'cfg(unix)'.dependencies]
24-
libafl = { path = "../../libafl/", features = [ "std", "llmp_compression" ] } #, "llmp_small_maps", "llmp_debug"]}
24+
libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public" ] } #, "llmp_small_maps", "llmp_debug"]}
25+
libafl_frida = { path = "../../libafl_frida" }
2526
capstone = "0.8.0"
26-
frida-gum = { version = "0.4", git = "https://github.com/s1341/frida-rust", features = [ "auto-download", "event-sink", "invocation-listener"] }
27+
frida-gum = { version = "0.4.1", git = "https://github.com/frida/frida-rust", features = [ "auto-download", "event-sink", "invocation-listener"] }
2728
#frida-gum = { version = "0.4", path = "../../../frida-rust/frida-gum", features = [ "auto-download", "event-sink", "invocation-listener"] }
28-
libafl_frida = { path = "../../libafl_frida", version = "0.2.0" }
2929
lazy_static = "1.4.0"
3030
libc = "0.2"
3131
libloading = "0.7.0"
3232
num-traits = "0.2.14"
3333
rangemap = "0.1.10"
3434
seahash = "4.1.0"
35+
clap = "2.33"
3536
serde = "1.0"
3637

3738
backtrace = "0.3"

fuzzers/frida_libpng/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ This will call (the build.rs)[./build.rs], which in turn downloads a libpng arch
1111
Then, it will link (the fuzzer)[./src/fuzzer.rs] against (the C++ harness)[./harness.cc] and the instrumented `libpng`.
1212
Afterwards, the fuzzer will be ready to run, from `../../target/examples/libfuzzer_libpng`.
1313

14+
### Build For Android
15+
When building for android using a cross-compiler, make sure you have a _standalone toolchain_, and then add the following:
16+
1. In the ~/.cargo/config file add a target with the correct cross-compiler toolchain name (in this case aarch64-linux-android, but names may vary)
17+
`[target.aarch64-linux-android]`
18+
`linker="aarch64-linux-android-clang"`
19+
2. add path to installed toolchain to PATH env variable.
20+
3. define CLANG_PATH and add target to the build command line:
21+
`CLANG_PATH=<path to installed toolchain>/bin/aarch64-linux-android-clang cargo -v build --release --target=aarch64-linux-android`
22+
1423
## Run
1524

1625
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.

fuzzers/frida_libpng/build.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ const LIBPNG_URL: &str =
1212
"https://deac-fra.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.xz";
1313

1414
fn build_dep_check(tools: &[&str]) {
15-
for tool in tools.into_iter() {
15+
for tool in tools {
1616
println!("Checking for build tool {}...", tool);
1717

18-
match which(tool) {
19-
Ok(path) => println!("Found build tool {}", path.to_str().unwrap()),
20-
Err(_) => {
21-
println!("ERROR: missing build tool {}", tool);
22-
exit(1);
23-
}
18+
if let Ok(path) = which(tool) {
19+
println!("Found build tool {}", path.to_str().unwrap())
20+
} else {
21+
println!("ERROR: missing build tool {}", tool);
22+
exit(1);
2423
};
2524
}
2625
}
@@ -35,7 +34,7 @@ fn main() {
3534
let cwd = env::current_dir().unwrap().to_string_lossy().to_string();
3635
let out_dir = out_dir.to_string_lossy().to_string();
3736
let out_dir_path = Path::new(&out_dir);
38-
std::fs::create_dir_all(&out_dir).expect(&format!("Failed to create {}", &out_dir));
37+
std::fs::create_dir_all(&out_dir).unwrap_or_else(|_| panic!("Failed to create {}", &out_dir));
3938

4039
println!("cargo:rerun-if-changed=build.rs");
4140
println!("cargo:rerun-if-changed=../libfuzzer_runtime/rt.c",);

0 commit comments

Comments
 (0)