Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can β€” learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company πŸ‘‡

fix(lisdex): leak gate must run with LSAN on, plus a persistent-mode detector

CarterPerez-dev6c3a7b4f50b3
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs
index 59697e2c..995edb8b 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-harness/src/compile.rs
@@ -10,7 +10,10 @@ pub const SHOWMAP: &str = "afl-showmap";
pub const DEFAULT_DRIVER: &str = "/usr/local/lib/afl/libAFLDriver.a";
pub const ASAN_OPTIONS: &str = "ASAN_OPTIONS";
pub const ASAN_OPTIONS_VALUE: &str = "detect_leaks=0";
+pub const ASAN_OPTIONS_LEAKS: &str = "detect_leaks=1";
pub const SHOWMAP_TIMEOUT_MS: u64 = 5000;
+pub const TARGET_MODE_KEY: &str = "target_mode";
+pub const REQUIRED_TARGET_MODES: &[&str] = &["persistent", "shmem_testcase", "deferred"];
#[derive(Debug, Clone)]
pub struct BuildSpec {
@@ -87,11 +90,33 @@ pub fn showmap_command(binary: &Path, seed: &Path, map: &Path) -> CommandSpec {
.path_arg(seed)
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum LeakCheck {
+ Enforce,
+ Ignore,
+}
+
#[must_use]
-pub fn exercise_command(binary: &Path, seed: &Path) -> CommandSpec {
- CommandSpec::new(binary.display().to_string())
- .env(ASAN_OPTIONS, ASAN_OPTIONS_VALUE)
- .path_arg(seed)
+pub fn exercise_command(binary: &Path, seed: &Path, leaks: LeakCheck) -> CommandSpec {
+ let command = CommandSpec::new(binary.display().to_string());
+ let command = match leaks {
+ LeakCheck::Enforce => command.env(ASAN_OPTIONS, ASAN_OPTIONS_LEAKS),
+ LeakCheck::Ignore => command.env(ASAN_OPTIONS, ASAN_OPTIONS_VALUE),
+ };
+ command.path_arg(seed)
+}
+
+#[must_use]
+pub fn drives_persistent_mode(fuzzer_stats: &str) -> bool {
+ fuzzer_stats
+ .lines()
+ .filter_map(|line| line.split_once(':'))
+ .any(|(key, value)| {
+ key.trim() == TARGET_MODE_KEY
+ && REQUIRED_TARGET_MODES
+ .iter()
+ .all(|mode| value.split_whitespace().any(|token| token == *mode))
+ })
}
#[cfg(test)]
@@ -173,14 +198,49 @@ mod tests {
#[test]
fn a_direct_exercise_runs_the_binary_on_the_seed() {
- let command = exercise_command(Path::new("/w/h.bin"), Path::new("/seeds/a.png"));
+ let command = exercise_command(
+ Path::new("/w/h.bin"),
+ Path::new("/seeds/a.png"),
+ LeakCheck::Enforce,
+ );
assert_eq!(command.program, "/w/h.bin");
assert_eq!(command.command_line(), "/w/h.bin /seeds/a.png");
}
#[test]
- fn a_direct_exercise_also_silences_leak_detection() {
- let command = exercise_command(Path::new("/w/h.bin"), Path::new("/seeds/a.png"));
+ fn the_leak_gate_turns_leak_detection_on() {
+ let command = exercise_command(
+ Path::new("/w/h.bin"),
+ Path::new("/seeds/a.png"),
+ LeakCheck::Enforce,
+ );
+ assert_eq!(command.env_value(ASAN_OPTIONS), Some(ASAN_OPTIONS_LEAKS));
+ }
+
+ #[test]
+ fn a_campaign_run_leaves_leak_detection_off() {
+ let command = exercise_command(
+ Path::new("/w/h.bin"),
+ Path::new("/seeds/a.png"),
+ LeakCheck::Ignore,
+ );
assert_eq!(command.env_value(ASAN_OPTIONS), Some(ASAN_OPTIONS_VALUE));
}
+
+ #[test]
+ fn persistent_mode_is_recognised_from_fuzzer_stats() {
+ let stats = "execs_done : 12\ntarget_mode : persistent shmem_testcase deferred\n";
+ assert!(drives_persistent_mode(stats));
+ }
+
+ #[test]
+ fn a_shadowed_main_is_caught_by_the_target_mode_check() {
+ let stats = "execs_done : 12\ntarget_mode : shmem_testcase default\n";
+ assert!(!drives_persistent_mode(stats));
+ }
+
+ #[test]
+ fn a_missing_target_mode_line_is_not_persistent() {
+ assert!(!drives_persistent_mode("execs_done : 12\n"));
+ }
}