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

Add Intel PT tracing support #2471

Merged
merged 184 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
d934297
WIP: IntelPT qemu systemmode
Marcondiro Aug 2, 2024
ac158be
use perf-event-open-sys instead of bindgen
Marcondiro Aug 5, 2024
3cf251b
intelPT Add enable and disable tracing, add test
Marcondiro Aug 6, 2024
916e876
Use static_assertions crate
Marcondiro Aug 7, 2024
1cd9a33
Fix volatiles, finish test
Marcondiro Aug 7, 2024
d0b0a57
Add Intel PT availability check
Marcondiro Aug 8, 2024
b3418f5
Use LibAFL errors in Result
Marcondiro Aug 9, 2024
296526a
Improve filtering
Marcondiro Aug 12, 2024
ff3d73f
Add KVM pt_mode check
Marcondiro Aug 12, 2024
a5dba76
move static_assertions use
Marcondiro Aug 12, 2024
1fadf19
Check for perf_event_open support
Marcondiro Aug 13, 2024
de0aca1
Add (empty) IntelPT module
Marcondiro Aug 13, 2024
2e3b9a3
Add IntelPTModule POC
Marcondiro Aug 16, 2024
e2558f3
partial ideas to implement intel pt
rmalmain Aug 16, 2024
183286f
forgot smth
rmalmain Aug 16, 2024
9131b66
trace decoding draft
Marcondiro Aug 18, 2024
ddb148a
add libipt decoder
Marcondiro Aug 19, 2024
3d3d20d
use cpuid instead of reading /proc/cpuinfo
Marcondiro Aug 20, 2024
53dcd52
investigating nondeterministic behaviour
Marcondiro Aug 21, 2024
c4e4be2
intel_pt module add thread creation hook
Marcondiro Aug 22, 2024
5b37bca
Fully identify deps versions
Marcondiro Aug 22, 2024
ba75de5
Move mem image to module, output to file for debug
Marcondiro Aug 23, 2024
87a3d8f
fixup! Use static_assertions crate
Marcondiro Sep 4, 2024
8007a0c
Exclude host kernel from traces
Marcondiro Sep 5, 2024
904372b
Bump libipt-rs
Marcondiro Sep 6, 2024
009d766
Callback to get memory as an alterantive to image
Marcondiro Sep 9, 2024
ce0e43a
WIP Add bootloader fuzzer example
Marcondiro Sep 12, 2024
0549a6a
Split availability check: add availability_with_qemu
Marcondiro Sep 13, 2024
bb3ada6
Move IntelPT to observer
Marcondiro Sep 16, 2024
9f15910
Improve test docs
Marcondiro Sep 16, 2024
9727f62
Clippy happy now
Marcondiro Sep 16, 2024
d83170a
Taplo happy now
Marcondiro Sep 16, 2024
445f266
Add IntelPTObserver boilerplate
Marcondiro Sep 16, 2024
c99fb1a
Hook instead of Observer
Marcondiro Sep 17, 2024
a4e9c80
Clippy & Taplo
Marcondiro Sep 17, 2024
a5ef701
Add psb_freq setting
Marcondiro Sep 18, 2024
f2e61a9
Extremely bad and dirty babyfuzzer stealing
Marcondiro Sep 19, 2024
9b78014
Use thread local cell instead of mutex
Marcondiro Sep 20, 2024
9d5304c
Try a trace diff based naive feedback
Marcondiro Sep 20, 2024
203ec9e
fix perf aux buffer wrap handling
Marcondiro Sep 23, 2024
c4f61c7
Use f64 for feedback score
Marcondiro Sep 23, 2024
92930bb
Fix clippy for cargo test
Marcondiro Sep 23, 2024
8efbe9f
Add config format tests
Marcondiro Sep 23, 2024
a38f3cc
WIP intelpt babyfuzzer with fork
Marcondiro Sep 24, 2024
254a1ec
Fix not wrapped tail offset in split buffer
Marcondiro Sep 25, 2024
0eed21a
Baby PT with raw traces diff working
Marcondiro Sep 25, 2024
6fa66cb
Cache nr_filters
Marcondiro Sep 25, 2024
6b827f9
Use Lazy_lock for perf_type
Marcondiro Sep 26, 2024
e36a48d
Add baby_fuzzer_intel_pt
Marcondiro Sep 26, 2024
64cdd67
restore baby fuzzer
Marcondiro Sep 27, 2024
1f42f7e
baby_fuzzer with block decoder
Marcondiro Oct 2, 2024
700e069
instruction decoder instead of block
Marcondiro Oct 2, 2024
2fed4d3
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 2, 2024
58960a2
Fix after upstream merge
Marcondiro Oct 2, 2024
3dae097
OwnedRefMut instead of Cow
Marcondiro Oct 3, 2024
6f26985
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 3, 2024
9066186
Read mem directly instead of going through files
Marcondiro Oct 3, 2024
00b78fc
Fix cache lifetime and tail update
Marcondiro Oct 10, 2024
903af72
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 10, 2024
e3cb6bc
clippy
Marcondiro Oct 10, 2024
67594ae
Taplo
Marcondiro Oct 10, 2024
7f3f33f
Compile caps only on linux
Marcondiro Oct 10, 2024
bb2d0b8
clippy
Marcondiro Oct 10, 2024
babf373
Fail compilation on unsupported OSes
Marcondiro Oct 10, 2024
afa4f47
Add baby_fuzzer_intel_pt to CI
Marcondiro Oct 10, 2024
a975c29
Cleanup
Marcondiro Oct 10, 2024
63365d6
Move intel pt + linux check
Marcondiro Oct 10, 2024
f066f4c
fix baby pt
Marcondiro Oct 10, 2024
9318d37
rollback forkexecutor
Marcondiro Oct 10, 2024
d6e9926
Remove unused dep
Marcondiro Oct 10, 2024
b85ce25
Cleanup
Marcondiro Oct 10, 2024
3349ea2
Lints
Marcondiro Oct 11, 2024
e062420
Compute an edge id instead of using only block ip
Marcondiro Oct 11, 2024
cffc7f5
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 11, 2024
6b0f8b8
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 14, 2024
4aeecd0
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 14, 2024
33720bf
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 16, 2024
d973ff2
Binary only intelPT POC
Marcondiro Oct 17, 2024
76c1cfc
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 17, 2024
a3f89d1
put linux specific code behind target_os=linux
Marcondiro Oct 17, 2024
91e44d8
Clippy & Taplo
Marcondiro Oct 17, 2024
504ede7
fix CI
Marcondiro Oct 17, 2024
e6ee853
Disable relocation
Marcondiro Oct 18, 2024
873b081
No unwrap in decode
Marcondiro Oct 18, 2024
4e110bd
No expect in decode
Marcondiro Oct 18, 2024
6e9212f
Better logging, smaller aux buffer
Marcondiro Oct 18, 2024
7a39033
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 21, 2024
a23350d
add IntelPTBuilder
Marcondiro Oct 21, 2024
e3f2e65
some lints
Marcondiro Oct 21, 2024
0f7cc2c
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 21, 2024
a13a549
Add exclude_hv config
Marcondiro Oct 22, 2024
8e4d6e8
Per CPU tracing and inheritance
Marcondiro Oct 22, 2024
1cd5f31
Parametrize buffer size
Marcondiro Oct 22, 2024
98ba48d
Try not to break commandExecutor API pt.1
Marcondiro Oct 23, 2024
30b99f5
Try not to break commandExecutor API pt.2
Marcondiro Oct 23, 2024
f3e7213
Try not to break commandExecutor API pt.3
Marcondiro Oct 23, 2024
7c3a70b
fix baby PT
Marcondiro Oct 23, 2024
569ca34
Support on_crash & on_timeout callbacks for libafl_qemu modules (#2620)
rmalmain Oct 21, 2024
9f7ce7a
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 24, 2024
585aad3
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 24, 2024
b10fb50
Move common code to bolts
Marcondiro Oct 24, 2024
c6f2e29
Cleanup
Marcondiro Oct 24, 2024
574be81
Revert changes to backtrace_baby_fuzzers/command_executor
Marcondiro Oct 25, 2024
bf30230
Move intel_pt in one file
Marcondiro Oct 25, 2024
5f1186b
Use workspace deps
Marcondiro Oct 25, 2024
b892233
add nr_addr_filter fallback
Marcondiro Oct 25, 2024
b77e74a
Cleaning
Marcondiro Oct 25, 2024
f5b995b
Improve decode
Marcondiro Oct 25, 2024
7738446
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 25, 2024
f129abd
Clippy
Marcondiro Oct 25, 2024
c8205cf
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 25, 2024
3a95359
Improve errors and docs
Marcondiro Oct 25, 2024
04c79de
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 25, 2024
6fba90c
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 28, 2024
3215824
Impl from<PtError> for libafl::Error
Marcondiro Oct 28, 2024
37a562e
Merge hooks
Marcondiro Oct 28, 2024
455390c
Docs
Marcondiro Oct 28, 2024
b847f18
Clean command executor
Marcondiro Oct 28, 2024
4625993
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 28, 2024
a3daeab
fix baby PT
Marcondiro Oct 28, 2024
dc79ae4
fix baby PT warnings
Marcondiro Oct 29, 2024
1590d50
decoder fills the map with no vec alloc
Marcondiro Oct 29, 2024
e4c1f3d
WIP command executor intel PT
Marcondiro Oct 29, 2024
79c90d3
filter_map() instead of filter().map()
Marcondiro Oct 29, 2024
a960741
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 29, 2024
02535c5
fix docs
Marcondiro Oct 29, 2024
e05d371
fix windows?
Marcondiro Oct 29, 2024
ad5101f
Baby lints
Marcondiro Oct 29, 2024
83db743
Small cleanings
Marcondiro Oct 29, 2024
38fb8b1
Use personality to disable ASLR at runtime
Marcondiro Oct 29, 2024
b0a5581
Fix nix dep
Marcondiro Oct 29, 2024
e6e3e07
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 30, 2024
ae93181
Use prc-maps in babyfuzzer
Marcondiro Oct 30, 2024
046fc46
working ET_DYN elf
Marcondiro Oct 30, 2024
70a010b
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 30, 2024
5bc19f9
Cleanup Cargo.toml
Marcondiro Oct 30, 2024
c096f44
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 31, 2024
3e9367f
Clean command executor
Marcondiro Oct 31, 2024
c88cc04
introduce PtraceCommandConfigurator
Marcondiro Oct 31, 2024
4d8f9b9
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Oct 31, 2024
d66b353
Fix clippy & taplo
Marcondiro Oct 31, 2024
31b5201
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Nov 4, 2024
ee838ae
input via stdin
Marcondiro Nov 4, 2024
fca2d37
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Nov 4, 2024
20f4428
Merge remote-tracking branch 'upstream/main' into intel_pt
Marcondiro Nov 4, 2024
fe46a15
libipt as workspace dep
Marcondiro Nov 4, 2024
d91271e
Check kernel version
Marcondiro Nov 5, 2024
90be012
support Arg input location
Marcondiro Nov 5, 2024
ce817ed
Reorder stuff
Marcondiro Nov 5, 2024
6175889
File input
Marcondiro Nov 6, 2024
bb8ea41
timeout support for PtraceExec
Marcondiro Nov 6, 2024
59ae760
Lints
Marcondiro Nov 6, 2024
4a66bc2
Move out method not needing self form IntelPT
Marcondiro Nov 6, 2024
9191e0e
unimplemented
Marcondiro Nov 6, 2024
f9c500b
Lints
Marcondiro Nov 6, 2024
5a0041d
Move intel_pt_baby_fuzzer
Marcondiro Nov 7, 2024
808417a
Move intel_pt_command_executor
Marcondiro Nov 7, 2024
dfb11c8
Document the need for smp_rmb
Marcondiro Nov 7, 2024
14f642f
Better comment
Marcondiro Nov 7, 2024
c0f5699
Readme and Makefile.toml instead of build.rs
Marcondiro Nov 7, 2024
b4430ea
Move out from libafl_bolts to libafl_intelpt
Marcondiro Nov 7, 2024
d21afe8
Fix hooks
Marcondiro Nov 7, 2024
3cecf4b
(Almost) fix intel_pt command exec
Marcondiro Nov 7, 2024
11b7a3c
fix intel_pt command exec debug
Marcondiro Nov 8, 2024
5a8642a
Fix baby_fuzzer
Marcondiro Nov 8, 2024
a6deb79
&raw over addr_of!
Marcondiro Nov 8, 2024
40b5084
cfg(target_os = "linux")
Marcondiro Nov 8, 2024
92f37cf
bolts Cargo.toml leftover
Marcondiro Nov 8, 2024
71fd726
minimum wage README.md
Marcondiro Nov 8, 2024
d31133f
extract join_split_trace from decode
Marcondiro Nov 8, 2024
9c17590
extract decode_block from decode
Marcondiro Nov 8, 2024
8cad188
add 1 to `previous_block_ip` to avoid that all the recursive basic bl…
Marcondiro Nov 8, 2024
8972400
More generic hook
Marcondiro Nov 8, 2024
08eb14d
fix windows
Marcondiro Nov 9, 2024
88a960f
Merge branch 'main' into intel_pt
domenukk Nov 9, 2024
21ed10c
Merge branch 'main' into intel_pt
Marcondiro Nov 10, 2024
dc0a2ca
Merge branch 'main' into intel_pt
Marcondiro Nov 11, 2024
ccc793e
Update CI, fmt
Marcondiro Nov 12, 2024
b38b9d5
No bitbybit
Marcondiro Nov 12, 2024
89cf7a3
Fix docker?
Marcondiro Nov 12, 2024
6499c03
Fix Apple silicon?
Marcondiro Nov 12, 2024
14add06
Merge branch 'main' into intel_pt
Marcondiro Nov 12, 2024
59971d4
Use old libipt from crates.io
Marcondiro Nov 12, 2024
6600cb5
Merge branch 'main' into intel_pt
Marcondiro Nov 12, 2024
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: 2 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ jobs:
- ./fuzzers/binary_only/frida_windows_gdiplus
- ./fuzzers/binary_only/frida_libpng
- ./fuzzers/binary_only/fuzzbench_qemu
- ./fuzzers/binary_only/intel_pt_baby_fuzzer
- ./fuzzers/binary_only/intel_pt_command_executor
- ./fuzzers/binary_only/tinyinst_simple

# Forkserver
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-prepare/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runs:
steps:
- name: Install and cache deps
shell: bash
run: sudo apt-get update && sudo apt-get install -y curl lsb-release wget software-properties-common gnupg ninja-build shellcheck pax-utils nasm libsqlite3-dev libc6-dev libgtk-3-dev gcc g++ gcc-arm-none-eabi gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libslirp-dev libz3-dev build-essential
run: sudo apt-get update && sudo apt-get install -y curl lsb-release wget software-properties-common gnupg ninja-build shellcheck pax-utils nasm libsqlite3-dev libc6-dev libgtk-3-dev gcc g++ gcc-arm-none-eabi gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libslirp-dev libz3-dev build-essential cmake
- uses: dtolnay/rust-toolchain@stable
- name: Add stable clippy
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"libafl_concolic/symcc_libafl",
"libafl_derive",
"libafl_frida",
"libafl_intelpt",
"libafl_libfuzzer",
"libafl_nyx",
"libafl_targets",
Expand Down Expand Up @@ -48,6 +49,7 @@ exclude = [

[workspace.package]
version = "0.13.2"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
ahash = { version = "0.8.11", default-features = false } # The hash function already used in hashbrown
Expand All @@ -59,6 +61,7 @@ cmake = "0.1.51"
document-features = "0.2.10"
hashbrown = { version = "0.14.5", default-features = false } # A faster hashmap, nostd compatible
libc = "0.2.159" # For (*nix) libc
libipt = "0.1.4"
log = "0.4.22"
meminterval = "0.4.1"
mimalloc = { version = "0.1.43", default-features = false }
Expand All @@ -76,6 +79,7 @@ serde = { version = "1.0.210", default-features = false } # serialization lib
serial_test = { version = "3.1.1", default-features = false }
serde_json = { version = "1.0.128", default-features = false }
serde_yaml = { version = "0.9.34" } # For parsing the injections yaml file
static_assertions = "1.1.0"
strum = "0.26.3"
strum_macros = "0.26.4"
toml = "0.8.19" # For parsing the injections toml file
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ COPY libafl_frida/Cargo.toml libafl_frida/build.rs libafl_frida/
COPY scripts/dummy.rs libafl_frida/src/lib.rs
COPY libafl_frida/src/gettls.c libafl_frida/src/gettls.c

COPY libafl_intelpt/Cargo.toml libafl_intelpt/README.md libafl_intelpt/
COPY scripts/dummy.rs libafl_intelpt/src/lib.rs

COPY libafl_qemu/Cargo.toml libafl_qemu/build.rs libafl_qemu/build_linux.rs libafl_qemu/
COPY scripts/dummy.rs libafl_qemu/src/lib.rs

Expand Down Expand Up @@ -144,6 +147,8 @@ COPY libafl_libfuzzer/src libafl_libfuzzer/src
COPY libafl_libfuzzer/runtime libafl_libfuzzer/runtime
COPY libafl_libfuzzer/build.rs libafl_libfuzzer/build.rs
RUN touch libafl_libfuzzer/src/lib.rs
COPY libafl_intelpt/src libafl_intelpt/src
RUN touch libafl_intelpt/src/lib.rs
RUN cargo build && cargo build --release

# Copy fuzzers over
Expand Down
19 changes: 19 additions & 0 deletions fuzzers/binary_only/intel_pt_baby_fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "intel_pt_baby_fuzzer"
version = "0.13.2"
authors = [
"Andrea Fioraldi <[email protected]>",
"Dominik Maier <[email protected]>",
"Marco Cavenati <[email protected]>",
]
edition = "2021"

[features]
tui = []

[dependencies]
libafl = { path = "../../../libafl/", default-features = false, features = [
"intel_pt",
] }
libafl_bolts = { path = "../../../libafl_bolts" }
proc-maps = "0.4.0"
15 changes: 15 additions & 0 deletions fuzzers/binary_only/intel_pt_baby_fuzzer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Baby fuzzer with Intel PT tracing

This is a minimalistic example about how to create a libafl based fuzzer with Intel PT tracing.

It runs on a single core until a crash occurs and then exits.

The tested program is a simple Rust function without any instrumentation.

After building this example with `cargo build`, you need to give to the executable the necessary capabilities with
`sudo setcap cap_ipc_lock,cap_sys_ptrace,cap_sys_admin,cap_syslog=ep ./target/debug/intel_pt_baby_fuzzer`.

You can run this example using `cargo run`, and you can enable the TUI feature by building and running with
`--features tui`.

This fuzzer is compatible with Linux hosts only having an Intel PT compatible CPU.
153 changes: 153 additions & 0 deletions fuzzers/binary_only/intel_pt_baby_fuzzer/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
use std::{hint::black_box, num::NonZero, path::PathBuf, process, time::Duration};

#[cfg(feature = "tui")]
use libafl::monitors::tui::TuiMonitor;
#[cfg(not(feature = "tui"))]
use libafl::monitors::SimpleMonitor;
use libafl::{
corpus::{InMemoryCorpus, OnDiskCorpus},
events::SimpleEventManager,
executors::{
hooks::intel_pt::{IntelPTHook, Section},
inprocess::GenericInProcessExecutor,
ExitKind,
},
feedbacks::{CrashFeedback, MaxMapFeedback},
fuzzer::{Fuzzer, StdFuzzer},
generators::RandPrintablesGenerator,
inputs::{BytesInput, HasTargetBytes},
mutators::{havoc_mutations::havoc_mutations, scheduled::StdScheduledMutator},
observers::StdMapObserver,
schedulers::QueueScheduler,
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice};
use proc_maps::get_process_maps;

// Coverage map
const MAP_SIZE: usize = 4096;
static mut MAP: [u8; MAP_SIZE] = [0; MAP_SIZE];
#[allow(static_mut_refs)]
static mut MAP_PTR: *mut u8 = unsafe { MAP.as_mut_ptr() };

pub fn main() {
// The closure that we want to fuzz
let mut harness = |input: &BytesInput| {
let target = input.target_bytes();
let buf = target.as_slice();
if !buf.is_empty() && buf[0] == b'a' {
let _do_something = black_box(0);
if buf.len() > 1 && buf[1] == b'b' {
let _do_something = black_box(0);
if buf.len() > 2 && buf[2] == b'c' {
panic!("Artificial bug triggered =)");
}
}
}
ExitKind::Ok
};

// Create an observation channel using the map
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", MAP_PTR, MAP_SIZE) };

// Feedback to rate the interestingness of an input
let mut feedback = MaxMapFeedback::new(&observer);

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

// create a State from scratch
let mut state = StdState::new(
// RNG
StdRand::with_seed(current_nanos()),
// Corpus that will be evolved, we keep it in memory for performance
InMemoryCorpus::new(),
// Corpus in which we store solutions (crashes in this example),
// on disk so the user can get them after stopping the fuzzer
OnDiskCorpus::new(PathBuf::from("./crashes")).unwrap(),
// States of the feedbacks.
// The feedbacks can report the data that should persist in the State.
&mut feedback,
// Same for objective feedbacks
&mut objective,
)
.unwrap();

// The Monitor trait define how the fuzzer stats are displayed to the user
#[cfg(not(feature = "tui"))]
let mon = SimpleMonitor::new(|s| println!("{s}"));
#[cfg(feature = "tui")]
let mon = TuiMonitor::builder()
.title("Baby Fuzzer Intel PT")
.enhanced_graphics(false)
.build();

// The event manager handle the various events generated during the fuzzing loop
// such as the notification of the addition of a new item to the corpus
let mut mgr = SimpleEventManager::new(mon);

// A queue policy to get testcases from the corpus
let scheduler = QueueScheduler::new();

// A fuzzer with feedbacks and a corpus scheduler
let mut fuzzer = StdFuzzer::new(scheduler, feedback, objective);

// Get the memory map of the current process
let my_pid = i32::try_from(process::id()).unwrap();
let process_maps = get_process_maps(my_pid).unwrap();
let sections = process_maps
.iter()
.filter_map(|pm| {
if pm.is_exec() && pm.filename().is_some() {
Some(Section {
file_path: pm.filename().unwrap().to_string_lossy().to_string(),
file_offset: pm.offset as u64,
size: pm.size() as u64,
virtual_address: pm.start() as u64,
})
} else {
None
}
})
.collect::<Vec<_>>();

// Intel PT hook that will handle the setup of Intel PT for each execution and fill the map
let pt_hook = unsafe {
IntelPTHook::builder()
.map_ptr(MAP_PTR)
.map_len(MAP_SIZE)
.image(&sections)
}
.build();

type PTInProcessExecutor<'a, H, OT, S, T> =
GenericInProcessExecutor<H, &'a mut H, (IntelPTHook<T>, ()), OT, S>;
// Create the executor for an in-process function with just one observer
let mut executor = PTInProcessExecutor::with_timeout_generic(
tuple_list!(pt_hook),
&mut harness,
tuple_list!(observer),
&mut fuzzer,
&mut state,
&mut mgr,
Duration::from_millis(5000),
)
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(NonZero::new(32).unwrap());

// Generate 8 initial inputs
state
.generate_initial_inputs(&mut fuzzer, &mut executor, &mut generator, &mut mgr, 8)
.expect("Failed to generate the initial corpus");

// Set up a mutational stage with a basic bytes mutator
let mutator = StdScheduledMutator::new(havoc_mutations());
let mut stages = tuple_list!(StdMutationalStage::new(mutator));

fuzzer
.fuzz_loop(&mut stages, &mut executor, &mut state, &mut mgr)
.expect("Error in the fuzzing loop");
}
14 changes: 14 additions & 0 deletions fuzzers/binary_only/intel_pt_command_executor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "intel_pt_command_executor"
version = "0.1.0"
authors = ["Marco Cavenati <[email protected]>"]
edition = "2021"

[dependencies]
env_logger = "0.11.5"
libafl = { path = "../../../libafl", default-features = false, features = [
"intel_pt",
] }
libafl_bolts = { path = "../../../libafl_bolts" }
libafl_intelpt = { path = "../../../libafl_intelpt" }
log = { version = "0.4.22", features = ["release_max_level_info"] }
33 changes: 33 additions & 0 deletions fuzzers/binary_only/intel_pt_command_executor/Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[env.development]
PROFILE_DIR = "debug"

[env.release]
PROFILE_DIR = "release"

[tasks.build_target]
command = "rustc"
args = [
"src/target_program.rs",
"--out-dir",
"${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/${PROFILE_DIR}",
"-O",
]

[tasks.build_fuzzer]
command = "cargo"
args = ["build", "--profile", "${CARGO_MAKE_CARGO_PROFILE}"]

[tasks.build]
dependencies = ["build_fuzzer", "build_target"]

[tasks.setcap]
script = "sudo setcap cap_ipc_lock,cap_sys_ptrace,cap_sys_admin,cap_syslog=ep ${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/${PROFILE_DIR}/${CARGO_MAKE_CRATE_NAME}"
dependencies = ["build_fuzzer"]

[tasks.run]
command = "cargo"
args = ["run", "--profile", "${CARGO_MAKE_CARGO_PROFILE}"]
dependencies = ["build", "setcap"]

[tasks.default]
alias = "run"
21 changes: 21 additions & 0 deletions fuzzers/binary_only/intel_pt_command_executor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Linux Binary-Only Fuzzer with Intel PT Tracing

This fuzzer is designed to target a Linux binary (without requiring source code instrumentation) and leverages Intel
Processor Trace (PT) to compute code coverage.

## Prerequisites

- A Linux host with an Intel Processor Trace (PT) compatible CPU
- `cargo-make` installed
- Sudo access to grant necessary capabilities to the fuzzer

## How to Run the Fuzzer

To compile and run the fuzzer (and the target program) execute the following command:
```sh
cargo make
```

> **Note**: This command may prompt you for your password to assign capabilities required for Intel PT. If you'd prefer
> not to run it with elevated permissions, you can review and execute the commands from `Makefile.toml`
> individually.
Loading
Loading