Skip to content

Commit

Permalink
all
Browse files Browse the repository at this point in the history
  • Loading branch information
tokatoka committed May 2, 2023
1 parent bfeee85 commit d6c5316
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 49 deletions.
8 changes: 4 additions & 4 deletions cmplog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libafl::{
tuples::{tuple_list, Merge},
AsSlice,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down Expand Up @@ -66,19 +66,19 @@ pub fn libafl_main() {
Arg::new("out")
.short('o')
.long("output")
.help("The directory to place finds in ('corpus')")
.help("The directory to place finds in ('corpus')"),
)
.arg(
Arg::new("in")
.short('i')
.long("input")
.help("The directory to read initial inputs from ('seeds')")
.help("The directory to read initial inputs from ('seeds')"),
)
.arg(
Arg::new("tokens")
.short('x')
.long("tokens")
.help("A file to read tokens from, to be used during fuzzing")
.help("A file to read tokens from, to be used during fuzzing"),
)
.arg(
Arg::new("timeout")
Expand Down
2 changes: 1 addition & 1 deletion coe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libafl::{
tuples::{tuple_list, Merge},
AsSlice,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
2 changes: 1 addition & 1 deletion generic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libafl::{
tuples::{tuple_list, Merge},
AsSlice,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
2 changes: 1 addition & 1 deletion naive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libafl::{
tuples::{tuple_list, Merge},
AsSlice,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
2 changes: 1 addition & 1 deletion naive_ctx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libafl::{
tuples::{tuple_list, Merge},
AsSlice,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
2 changes: 1 addition & 1 deletion nautilus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use libafl::{
shmem::{ShMemProvider, StdShMemProvider},
tuples::tuple_list,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
2 changes: 1 addition & 1 deletion nautilus_mopt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use libafl::{
shmem::{ShMemProvider, StdShMemProvider},
tuples::tuple_list,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
2 changes: 1 addition & 1 deletion rand_scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use libafl::{
tuples::{tuple_list, Merge},
AsSlice,
},
corpus::{InMemoryOnDiskCorpus, Corpus, OnDiskCorpus},
corpus::{Corpus, InMemoryOnDiskCorpus, OnDiskCorpus},
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
Expand Down
4 changes: 2 additions & 2 deletions weighted/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ libafl = { path = "../LibAFL/libafl/" }
libafl_targets = { path = "../LibAFL/libafl_targets/", features = ["sancov_pcguard_hitcounts", "libfuzzer"] }
# TODO Include it only when building cc
libafl_cc = { path = "../LibAFL/libafl_cc/" }
clap = { version = "3.0", features = ["default"] }
nix = "0.23"
clap = { version = "4.0", features = ["default"] }
nix = "0.26"
mimalloc = { version = "*", default-features = false }

[lib]
Expand Down
67 changes: 31 additions & 36 deletions weighted/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use mimalloc::MiMalloc;
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

use clap::{App, Arg};
use clap::{Arg, Command};
use core::time::Duration;
#[cfg(unix)]
use nix::{self, unistd::dup};
Expand All @@ -30,20 +30,18 @@ use libafl::{
events::SimpleRestartingEventManager,
executors::{inprocess::InProcessExecutor, ExitKind, TimeoutExecutor},
feedback_or,
feedbacks::{CrashFeedback, MapFeedbackState, MaxMapFeedback, TimeFeedback},
feedbacks::{CrashFeedback, MaxMapFeedback, TimeFeedback},
fuzzer::{Fuzzer, StdFuzzer},
inputs::{BytesInput, HasTargetBytes},
monitors::SimpleMonitor,
mutators::{scheduled::havoc_mutations, tokens_mutations, StdScheduledMutator, Tokens},
observers::{HitcountsMapObserver, StdMapObserver, TimeObserver},
schedulers::{
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, StdWeightedScheduler,
},
observers::{HitcountsMapObserver, TimeObserver},
schedulers::{IndexesLenTimeMinimizerScheduler, StdWeightedScheduler},
stages::power::StdPowerMutationalStage,
state::{HasCorpus, HasMetadata, StdState},
Error,
};
use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, EDGES_MAP, MAX_EDGES_NUM};
use libafl_targets::{libfuzzer_initialize, libfuzzer_test_one_input, std_edges_map_observer};

#[cfg(target_os = "linux")]
use libafl_targets::autotokens;
Expand All @@ -55,30 +53,27 @@ pub fn libafl_main() {
// Needed only on no_std
//RegistryBuilder::register::<Tokens>();

let res = match App::new(env!("CARGO_PKG_NAME"))
let res = match Command::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.author("AFLplusplus team")
.about("LibAFL-based fuzzer for Fuzzbench")
.arg(
Arg::new("out")
.short('o')
.long("output")
.help("The directory to place finds in ('corpus')")
.takes_value(true),
.help("The directory to place finds in ('corpus')"),
)
.arg(
Arg::new("in")
.short('i')
.long("input")
.help("The directory to read initial inputs from ('seeds')")
.takes_value(true),
.help("The directory to read initial inputs from ('seeds')"),
)
.arg(
Arg::new("tokens")
.short('x')
.long("tokens")
.help("A file to read tokens from, to be used during fuzzing")
.takes_value(true),
.help("A file to read tokens from, to be used during fuzzing"),
)
.arg(
Arg::new("timeout")
Expand All @@ -87,7 +82,7 @@ pub fn libafl_main() {
.help("Timeout for each individual execution, in milliseconds")
.default_value("1200"),
)
.arg(Arg::new("remaining").multiple_values(true))
.arg(Arg::new("remaining"))
.try_get_matches()
{
Ok(res) => res,
Expand All @@ -97,7 +92,7 @@ pub fn libafl_main() {
env::current_exe()
.unwrap_or_else(|_| "fuzzer".into())
.to_string_lossy(),
err.info,
err,
);
return;
}
Expand All @@ -108,8 +103,8 @@ pub fn libafl_main() {
env::current_dir().unwrap().to_string_lossy().to_string()
);

if let Some(filenames) = res.values_of("remaining") {
let filenames: Vec<&str> = filenames.collect();
if let Some(filenames) = res.get_many::<String>("remaining") {
let filenames: Vec<&str> = filenames.map(String::as_str).collect();
if !filenames.is_empty() {
run_testcases(&filenames);
return;
Expand All @@ -118,7 +113,7 @@ pub fn libafl_main() {

// For fuzzbench, crashes and finds are inside the same `corpus` directory, in the "queue" and "crashes" subdir.
let mut out_dir = PathBuf::from(
res.value_of("out")
res.get_one::<String>("out")
.expect("The --output parameter is missing")
.to_string(),
);
Expand All @@ -134,7 +129,7 @@ pub fn libafl_main() {
out_dir.push("queue");

let in_dir = PathBuf::from(
res.value_of("in")
res.get_one::<String>("in")
.expect("The --input parameter is missing")
.to_string(),
);
Expand All @@ -143,10 +138,10 @@ pub fn libafl_main() {
return;
}

let tokens = res.value_of("tokens").map(PathBuf::from);
let tokens = res.get_one::<String>("tokens").map(PathBuf::from);

let timeout = Duration::from_millis(
res.value_of("timeout")
res.get_one::<String>("timeout")
.unwrap()
.to_string()
.parse()
Expand Down Expand Up @@ -223,26 +218,22 @@ fn fuzz(

// Create an observation channel using the coverage map
// We don't use the hitcounts (see the Cargo.toml, we use pcguard_edges)
let edges = unsafe { &mut EDGES_MAP[0..MAX_EDGES_NUM] };
let edges_observer = HitcountsMapObserver::new(StdMapObserver::new("edges", edges));
let edges_observer = HitcountsMapObserver::new(unsafe { std_edges_map_observer("edges") });

// Create an observation channel to keep track of the execution time
let time_observer = TimeObserver::new("time");

// The state of the edges feedback.
let feedback_state = MapFeedbackState::with_observer(&edges_observer);

// Feedback to rate the interestingness of an input
// This one is composed by two Feedbacks in OR
let feedback = feedback_or!(
let mut feedback = feedback_or!(
// New maximization map feedback linked to the edges observer and the feedback state
MaxMapFeedback::new_tracking(&feedback_state, &edges_observer, true, false),
MaxMapFeedback::tracking(&edges_observer, true, false),
// Time feedback, this one does not need a feedback state
TimeFeedback::new_with_observer(&time_observer)
TimeFeedback::with_observer(&time_observer)
);

// A feedback to choose if an input is a solution or not
let objective = CrashFeedback::new();
let mut objective = CrashFeedback::new();

// If not restarting, create a State from scratch
let mut state = state.unwrap_or_else(|| {
Expand All @@ -256,8 +247,10 @@ fn fuzz(
OnDiskCorpus::new(objective_dir).unwrap(),
// States of the feedbacks.
// They are the data related to the feedbacks that you want to persist in the State.
tuple_list!(feedback_state),
&mut feedback,
&mut objective,
)
.unwrap()
});

println!("Let's fuzz :)");
Expand All @@ -271,11 +264,13 @@ fn fuzz(

let mutator = StdScheduledMutator::new(havoc_mutations().merge(tokens_mutations()));

let power =
StdPowerMutationalStage::new(&mut state, mutator, &edges_observer, PowerSchedule::RAND);
let power = StdPowerMutationalStage::new(mutator);

// A minimization+queue policy to get testcasess from the corpus
let scheduler = IndexesLenTimeMinimizerScheduler::new(StdWeightedScheduler::new());
let scheduler = IndexesLenTimeMinimizerScheduler::new(StdWeightedScheduler::new(
&mut state,
&edges_observer,
));

// A fuzzer with feedbacks and a corpus scheduler
let mut fuzzer = StdFuzzer::new(scheduler, feedback, objective);
Expand Down Expand Up @@ -304,7 +299,7 @@ fn fuzz(
let mut stages = tuple_list!(power);

// Read tokens
if state.metadata().get::<Tokens>().is_none() {
if state.metadata_map().get::<Tokens>().is_none() {
let mut toks = Tokens::default();
if let Some(tokenfile) = tokenfile {
toks.add_from_file(tokenfile)?;
Expand Down

0 comments on commit d6c5316

Please sign in to comment.