Skip to content

Commit

Permalink
Add basic config for text/binary inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed Jan 31, 2024
1 parent 1793f05 commit e2f0f7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,7 @@ impl Fuzz {
2..=3 => "-Pexplore",
_ => "-Pexploit",
};
/* wait for afl crate update
let mutation_option = match job_num / 2 {
0 => "-abinary",
_ => "-adefault",
};
*/
let input_format = format!("-a{}", self.config.input_format());
let log_destination = || match job_num {
0 => File::create(format!("{}/logs/afl.log", self.output_target()))
.unwrap()
Expand Down Expand Up @@ -357,12 +352,12 @@ impl Fuzz {
&format!("-g{}", self.min_length),
&format!("-G{}", self.max_length),
&use_shared_corpus,
// &format!("-V{}", self.minimization_timeout + SECONDS_TO_WAIT_AFTER_KILL, &use_initial_corpus_dir),
&use_initial_corpus_dir,
old_queue_cycling,
cmplog_options,
mopt_mutator,
mutation_option,
&input_format,
&timeout_option_afl,
&dictionary_option,
&self.afl_flags.clone().unwrap_or_default(),
Expand All @@ -381,8 +376,8 @@ impl Fuzz {
.env("AFL_NO_WARN_INSTABILITY", "1")
.env("AFL_FUZZER_STATS_UPDATE_INTERVAL", "10")
.env("AFL_IMPORT_FIRST", "1")
.env(final_sync, "1") // upcoming in v4.09c
.env("AFL_IGNORE_SEED_PROBLEMS", "1") // upcoming in v4.09c
.env(final_sync, "1")
.env("AFL_IGNORE_SEED_PROBLEMS", "1")
.stdout(log_destination())
.stderr(log_destination())
.spawn()?,
Expand Down Expand Up @@ -775,6 +770,30 @@ impl Fuzz {
}
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
pub enum FuzzingConfig {
Generic,
Binary,
Text,
Blockchain,
}

impl FuzzingConfig {
fn input_format(&self) -> &str {
match self {
Self::Text => "text",
_ => "binary",
}
}
}

use std::fmt;
impl fmt::Display for FuzzingConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

pub fn kill_subprocesses_recursively(pid: &str) -> Result<(), anyhow::Error> {
let subprocesses = process::Command::new("pgrep")
.arg(&format!("-P{pid}"))
Expand Down
5 changes: 5 additions & 0 deletions src/bin/cargo-ziggy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod plot;
mod run;
mod triage;

#[cfg(feature = "cli")]
use crate::fuzz::FuzzingConfig;
#[cfg(feature = "cli")]
use anyhow::{anyhow, Context, Result};
#[cfg(feature = "cli")]
Expand Down Expand Up @@ -152,6 +154,9 @@ pub struct Fuzz {
/// Pass flags to AFL++ directly
#[clap(short, long)]
afl_flags: Option<String>,

#[clap(short = 'C', long, default_value = "generic")]
config: FuzzingConfig,
}

#[derive(Args)]
Expand Down

0 comments on commit e2f0f7e

Please sign in to comment.