From f6e27bfefed6a8aaa0abb935de9f20640b80ece9 Mon Sep 17 00:00:00 2001 From: 0x434b Date: Wed, 20 Nov 2024 09:21:52 +0400 Subject: [PATCH] fix: properly forward seed to AFL++ if requested fix: remove nightly requirement --- README.md | 2 +- src/afl_cmd_gen.rs | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dc4931b..f415352 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Currently, this tool should work on all \*NIX flavor operating-systems. ### Prerequisites -- [Rust (nightly) toolchain](https://www.rust-lang.org/tools/install) 🦀 +- [Rust toolchain v1.78.0+](https://www.rust-lang.org/tools/install) 🦀 - [AFLPlusPlus](https://github.com/AFLplusplus/AFLplusplus) - [pgrep](https://man7.org/linux/man-pages/man1/pgrep.1.html) - [TMUX](https://github.com/tmux/tmux) || [screen](https://www.gnu.org/software/screen/) (Optional) diff --git a/src/afl_cmd_gen.rs b/src/afl_cmd_gen.rs index 082bd39..6e8a599 100644 --- a/src/afl_cmd_gen.rs +++ b/src/afl_cmd_gen.rs @@ -93,7 +93,8 @@ impl AFLCmdGenerator { /// Generates AFL commands based on the configuration pub fn run(&self) -> Result> { - let mut rng = StdRng::seed_from_u64(Xorshift64::new(self.seed.unwrap_or(0)).next()); + let seed = Xorshift64::new(self.seed.unwrap_or(0)).next(); + let mut rng = StdRng::seed_from_u64(seed); let afl_envs = AFLEnv::new(self.runners as usize, self.use_afl_defaults, &mut rng); let mut cmds = self.create_initial_cmds(&afl_envs)?; @@ -108,6 +109,10 @@ impl AFLCmdGenerator { Self::apply_strategies(&mut cmds, &mut rng, is_using_custom_mutator); } + if self.seed.is_some() { + self.apply_afl_seed(&mut cmds, seed); + } + self.apply_directory(&mut cmds); self.apply_dictionary(&mut cmds)?; self.apply_sanitizer_or_target_binary(&mut cmds); @@ -262,6 +267,12 @@ impl AFLCmdGenerator { } } } + + fn apply_afl_seed(&self, cmds: &mut [AflCmd], seed: u64) { + for cmd in cmds { + cmd.add_flag(format!("-s {seed}")); + } + } } #[cfg(test)] @@ -536,8 +547,8 @@ mod tests { None, None, false, - true, // Use AFL defaults - Some(42), + true, + None, ); let cmds_with_defaults = generator_with_defaults.run().unwrap(); @@ -545,4 +556,14 @@ mod tests { // Commands with defaults should be simpler assert!(cmds_with_defaults[0].to_string().len() < cmds_no_defaults[0].to_string().len()); } + + #[test] + fn test_afl_relay_seed() { + let (_temp_dir, generator) = setup_test_generator(); + let cmds = generator.run().unwrap(); + let expected_seed = Xorshift64::new(generator.seed.unwrap()).next(); + + assert!(cmds[0].to_string().contains("-s")); + assert!(cmds[0].to_string().contains(&format!("{}", expected_seed))); + } }