Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly forward seed to AFL++ if requested #59

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 24 additions & 3 deletions src/afl_cmd_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ impl AFLCmdGenerator {

/// Generates AFL commands based on the configuration
pub fn run(&self) -> Result<Vec<AflCmd>> {
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)?;
Expand All @@ -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);
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -536,13 +547,23 @@ mod tests {
None,
None,
false,
true, // Use AFL defaults
Some(42),
true,
None,
);

let cmds_with_defaults = generator_with_defaults.run().unwrap();

// 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)));
}
}