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 đŸ‘‡

feat(lisdex): M7.5 - the ordering is structural now, and the hazard it guards against never fired

CarterPerez-dev70b89a58788c
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/config.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/config.rs
index 08a1f230..1bbd0f6f 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/config.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-core/src/config.rs
@@ -7,6 +7,7 @@ pub const DEFAULT_CAMPAIGN_DURATION_SECS: u64 = 3600;
pub const DEFAULT_PARALLEL_JOBS: usize = 1;
pub const DEFAULT_TRIALS: usize = 30;
pub const DEFAULT_REPRODUCE_TIMEOUT_MS: u64 = 10_000;
+pub const DEFAULT_MINIMIZE_EXEC_TIMEOUT_MS: u64 = 1_000;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum LlmTier {
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/lib.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/lib.rs
index e53a0171..60a59c87 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/lib.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/lib.rs
@@ -1,6 +1,7 @@
// ©AngelaMos | 2026
// lib.rs
+pub mod minimize;
pub mod runner;
pub mod stats;
pub mod symbolize;
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/minimize.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/minimize.rs
new file mode 100644
index 00000000..f3f2be4f
--- /dev/null
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex-fuzz/src/minimize.rs
@@ -0,0 +1,258 @@
+// ©AngelaMos | 2026
+// minimize.rs
+
+use std::path::Path;
+use std::process::{Command, Stdio};
+use std::time::Duration;
+
+use lisdex_core::report::SanitizerReport;
+
+use crate::runner::{self, RunnerError};
+
+pub const AFL_TMIN_BIN: &str = "afl-tmin";
+
+const ARG_INPUT: &str = "-i";
+const ARG_OUTPUT: &str = "-o";
+const ARG_MEMORY: &str = "-m";
+const ARG_TIMEOUT: &str = "-t";
+const ARG_EDGES_ONLY: &str = "-e";
+const ARG_SEPARATOR: &str = "--";
+const MEM_LIMIT_UNLIMITED: &str = "none";
+const ENV_TMIN_EXACT: &str = "AFL_TMIN_EXACT";
+const ENV_SKIP_CPUFREQ: &str = "AFL_SKIP_CPUFREQ";
+const ENV_NO_AFFINITY: &str = "AFL_NO_AFFINITY";
+const ENV_ENABLED: &str = "1";
+
+#[derive(Debug, thiserror::Error)]
+pub enum MinimizeError {
+ #[error("io error: {0}")]
+ Io(#[from] std::io::Error),
+ #[error("could not reproduce the crash to establish its identity: {0}")]
+ Runner(#[from] RunnerError),
+ #[error("{AFL_TMIN_BIN} exited with {status} and produced no usable output")]
+ TminFailed { status: String },
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum Outcome {
+ Minimized {
+ key: String,
+ bytes_before: u64,
+ bytes_after: u64,
+ },
+ RejectedForIdentity {
+ expected: String,
+ produced: Option<String>,
+ },
+ RefusedUnkeyed,
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct TminInvocation<'a> {
+ pub target: &'a Path,
+ pub input: &'a Path,
+ pub output: &'a Path,
+ pub timeout: Duration,
+}
+
+#[must_use]
+pub fn verdict(
+ expected: Option<&str>,
+ produced: Option<&str>,
+ bytes_before: u64,
+ bytes_after: u64,
+) -> Outcome {
+ let Some(expected) = expected else {
+ return Outcome::RefusedUnkeyed;
+ };
+ match produced {
+ Some(produced) if produced == expected => Outcome::Minimized {
+ key: expected.to_owned(),
+ bytes_before,
+ bytes_after,
+ },
+ produced => Outcome::RejectedForIdentity {
+ expected: expected.to_owned(),
+ produced: produced.map(str::to_owned),
+ },
+ }
+}
+
+#[must_use]
+pub fn tmin_command(invocation: TminInvocation<'_>) -> Command {
+ let mut command = Command::new(AFL_TMIN_BIN);
+ command
+ .arg(ARG_INPUT)
+ .arg(invocation.input)
+ .arg(ARG_OUTPUT)
+ .arg(invocation.output)
+ .arg(ARG_MEMORY)
+ .arg(MEM_LIMIT_UNLIMITED)
+ .arg(ARG_TIMEOUT)
+ .arg(invocation.timeout.as_millis().to_string())
+ .arg(ARG_EDGES_ONLY)
+ .env(ENV_TMIN_EXACT, ENV_ENABLED)
+ .env(ENV_SKIP_CPUFREQ, ENV_ENABLED)
+ .env(ENV_NO_AFFINITY, ENV_ENABLED)
+ .arg(ARG_SEPARATOR)
+ .arg(invocation.target)
+ .stdout(Stdio::null())
+ .stderr(Stdio::null());
+ command
+}
+
+pub fn identity(
+ target: &Path,
+ input: &Path,
+ timeout: Duration,
+) -> Result<Option<String>, RunnerError> {
+ let reproduction = runner::reproduce(target, input, timeout)?;
+ Ok(SanitizerReport::parse(&reproduction.output).and_then(|report| report.stack_hash()))
+}
+
+pub fn minimize(
+ invocation: TminInvocation<'_>,
+ reproduce_timeout: Duration,
+) -> Result<Outcome, MinimizeError> {
+ let expected = identity(invocation.target, invocation.input, reproduce_timeout)?;
+ if expected.is_none() {
+ return Ok(Outcome::RefusedUnkeyed);
+ }
+
+ let status = tmin_command(invocation).status()?;
+ if !status.success() || !invocation.output.exists() {
+ return Err(MinimizeError::TminFailed {
+ status: status.to_string(),
+ });
+ }
+
+ let bytes_before = std::fs::metadata(invocation.input)?.len();
+ let bytes_after = std::fs::metadata(invocation.output)?.len();
+ let produced = identity(invocation.target, invocation.output, reproduce_timeout)?;
+
+ let outcome = verdict(
+ expected.as_deref(),
+ produced.as_deref(),
+ bytes_before,
+ bytes_after,
+ );
+ if matches!(outcome, Outcome::RejectedForIdentity { .. }) {
+ std::fs::remove_file(invocation.output)?;
+ }
+ Ok(outcome)
+}
+
+#[cfg(test)]
+mod tests {
+ use std::ffi::OsStr;
+ use std::path::PathBuf;
+
+ use super::*;
+
+ const KEY: &str = "5cb9f19ccde1a943";
+ const OTHER_KEY: &str = "80722b352fbccbd5";
+ const BEFORE: u64 = 4096;
+ const AFTER: u64 = 128;
+
+ fn invocation() -> TminInvocation<'static> {
+ TminInvocation {
+ target: Path::new("/out/afl/harness"),
+ input: Path::new("/findings/crashes/id:000000"),
+ output: Path::new("/tmp/min"),
+ timeout: Duration::from_secs(5),
+ }
+ }
+
+ #[test]
+ fn a_minimized_input_that_keeps_its_key_is_accepted() {
+ assert_eq!(
+ verdict(Some(KEY), Some(KEY), BEFORE, AFTER),
+ Outcome::Minimized {
+ key: KEY.to_owned(),
+ bytes_before: BEFORE,
+ bytes_after: AFTER,
+ }
+ );
+ }
+
+ #[test]
+ fn a_minimized_input_that_proves_a_different_bug_is_rejected() {
+ assert_eq!(
+ verdict(Some(KEY), Some(OTHER_KEY), BEFORE, AFTER),
+ Outcome::RejectedForIdentity {
+ expected: KEY.to_owned(),
+ produced: Some(OTHER_KEY.to_owned()),
+ },
+ "afl-tmin accepts ANY crash unless AFL_TMIN_EXACT is set, and even then it compares its own coverage bitmap rather than the symbolized stack lisdex publishes; a smaller input that crashes elsewhere is not a reproducer for this bug"
+ );
+ }
+
+ #[test]
+ fn a_minimized_input_that_stops_crashing_identifiably_is_rejected() {
+ assert_eq!(
+ verdict(Some(KEY), None, BEFORE, AFTER),
+ Outcome::RejectedForIdentity {
+ expected: KEY.to_owned(),
+ produced: None,
+ }
+ );
+ }
+
+ #[test]
+ fn a_crash_with_no_key_is_refused_rather_than_minimized_blind() {
+ assert_eq!(
+ verdict(None, Some(KEY), BEFORE, AFTER),
+ Outcome::RefusedUnkeyed,
+ "with no identity to preserve there is nothing to verify preservation against, so the reduction cannot be shown to be sound"
+ );
+ assert_eq!(verdict(None, None, BEFORE, AFTER), Outcome::RefusedUnkeyed);
+ }
+
+ #[test]
+ fn the_invocation_asks_for_exact_identity_and_edges_only() {
+ let command = tmin_command(invocation());
+ let args: Vec<&OsStr> = command.get_args().collect();
+ assert!(
+ args.contains(&OsStr::new(ARG_EDGES_ONLY)),
+ "-e is upstream's own paired recommendation for AFL_TMIN_EXACT"
+ );
+ let exact = command
+ .get_envs()
+ .find(|(key, _)| *key == OsStr::new(ENV_TMIN_EXACT))
+ .map(|(_, value)| value);
+ assert_eq!(
+ exact,
+ Some(Some(OsStr::new(ENV_ENABLED))),
+ "without AFL_TMIN_EXACT afl-tmin returns 1 on the first crash it sees without ever comparing traces, so it will happily walk a PoC from one bug to another"
+ );
+ }
+
+ #[test]
+ fn the_invocation_lifts_the_memory_limit_for_a_sanitizer_build() {
+ let command = tmin_command(invocation());
+ let args: Vec<String> = command
+ .get_args()
+ .map(|a| a.to_string_lossy().into_owned())
+ .collect();
+ let at = args.iter().position(|a| a == ARG_MEMORY).unwrap();
+ assert_eq!(
+ args[at + 1],
+ MEM_LIMIT_UNLIMITED,
+ "an ASAN build reserves terabytes of address space and dies instantly under afl-tmin's default limit"
+ );
+ }
+
+ #[test]
+ fn the_target_comes_after_the_separator() {
+ let command = tmin_command(invocation());
+ let args: Vec<String> = command
+ .get_args()
+ .map(|a| a.to_string_lossy().into_owned())
+ .collect();
+ let at = args.iter().position(|a| a == ARG_SEPARATOR).unwrap();
+ assert_eq!(
+ args[at + 1],
+ PathBuf::from("/out/afl/harness").to_string_lossy()
+ );
+ }
+}
diff --git a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
index 22ed76e4..554563d5 100644
--- a/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
+++ b/PROJECTS/advanced/zero-day-vulnerability-scanner/crates/lisdex/src/main.rs
@@ -13,11 +13,14 @@ use lisdex_build::ladder::{self, BuildOptions};
use lisdex_build::layout::{BuildLayout, VARIANT_AFL, VARIANT_BENCH};
use lisdex_build::verify::Requirements;
use lisdex_core::campaign::{Campaign, CampaignId, CampaignStatus};
-use lisdex_core::config::LlmTier;
+use lisdex_core::config::{
+ DEFAULT_MINIMIZE_EXEC_TIMEOUT_MS, DEFAULT_REPRODUCE_TIMEOUT_MS, LlmTier,
+};
use lisdex_core::crash::Crash;
use lisdex_core::dedup;
use lisdex_core::report::SanitizerReport;
use lisdex_core::store::Store;
+use lisdex_fuzz::minimize::{self, Outcome, TminInvocation};
use lisdex_fuzz::runner::{self, AflOptions};
use lisdex_harness::coverage::EdgeSet;
use lisdex_harness::emit;
@@ -36,6 +39,8 @@ const UNCLASSIFIED_SEVERITY: &str = "UNCLASSIFIED";
const NO_STACK_HASH: &str = "none";
const UNKEYED_MARKER: &str = "unkeyed";
const STACK_HASH_SHORT_LEN: usize = 16;
+const ORIGINAL_SUFFIX: &str = ".orig";
+const MINIMIZED_SUFFIX: &str = ".min";
const DISPLAYED_FRAMES: usize = 6;
const SOURCES_DIR: &str = "sources";
const BUILDS_DIR: &str = "builds";
@@ -81,6 +86,10 @@ enum Command {
Verify(VerifyArgs),
#[command(about = "list the crashes persisted for a campaign")]
Crashes(CrashesArgs),
+ #[command(
+ about = "minimize one reproducer per distinct bug, rejecting any that changes identity"
+ )]
+ Minimize(MinimizeArgs),
#[command(about = "report which LLM booster tier is configured and whether it answers")]
Llm(LlmArgs),
}
@@ -185,6 +194,21 @@ struct CrashesArgs {
campaign: i64,
}
+#[derive(clap::Args)]
+struct MinimizeArgs {
+ #[arg(long, help = "sqlite database written by a previous campaign")]
+ db: PathBuf,
+ #[arg(long, help = "campaign id whose crashes to minimize")]
+ campaign: i64,
+ #[arg(long, help = "the instrumented harness the campaign ran against")]
+ target: PathBuf,
+ #[arg(
+ long,
+ help = "directory to write one verified reproducer per distinct bug"
+ )]
+ out: PathBuf,
+}
+
#[derive(clap::Args)]
struct OracleArgs {
#[arg(
@@ -368,6 +392,7 @@ fn dispatch() -> Result<(), Box<dyn Error>> {
Command::Harness(args) => harness(args),
Command::Verify(args) => verify(args),
Command::Crashes(args) => crashes(args),
+ Command::Minimize(args) => minimize_campaign(args),
Command::Llm(args) => llm(args),
}
}
@@ -1247,6 +1272,66 @@ fn short_hash(hash: Option<&str>) -> String {
}
}
+fn minimize_campaign(args: &MinimizeArgs) -> Result<(), Box<dyn Error>> {
+ let store = Store::open(&args.db)?;
+ let campaign_id = CampaignId(args.campaign);
+ store
+ .get_campaign(campaign_id)?
+ .ok_or("no such campaign in store")?;
+
+ let crashes = store.crashes_for_campaign(campaign_id)?;
+ let grouping = dedup::group_crashes(&crashes);
+ std::fs::create_dir_all(&args.out)?;
+
+ println!("distinct_bugs {}", grouping.keyed_bugs());
+ println!("unkeyed_crashes {}", grouping.unkeyed_crashes());
+
+ let reproduce_timeout = Duration::from_millis(DEFAULT_REPRODUCE_TIMEOUT_MS);
+ let exec_timeout = Duration::from_millis(DEFAULT_MINIMIZE_EXEC_TIMEOUT_MS);
+
+ for group in grouping.groups() {
+ let Some(crash) = group.representative() else {
+ continue;
+ };
+ let stem = short_hash(crash.stack_hash());
+ let original = args.out.join(format!("{stem}{ORIGINAL_SUFFIX}"));
+ let minimized = args.out.join(format!("{stem}{MINIMIZED_SUFFIX}"));
+ std::fs::write(&original, crash.input())?;
+
+ let outcome = minimize::minimize(
+ TminInvocation {
+ target: &args.target,
+ input: &original,
+ output: &minimized,
+ timeout: exec_timeout,
+ },
+ reproduce_timeout,
+ );
+ match outcome {
+ Ok(Outcome::Minimized {
+ bytes_before,
+ bytes_after,
+ ..
+ }) => println!(
+ " {stem} x{} {bytes_before} -> {bytes_after} bytes, identity verified",
+ group.len()
+ ),
+ Ok(Outcome::RejectedForIdentity { produced, .. }) => println!(
+ " {stem} x{} NOT minimized: the reduced input proves {}, so only the original is a reproducer",
+ group.len(),
+ produced.as_deref().unwrap_or(NO_STACK_HASH)
+ ),
+ Ok(Outcome::RefusedUnkeyed) => println!(
+ " {stem} x{} NOT minimized: no dedup key, so identity cannot be shown to survive",
+ group.len()
+ ),
+ Err(err) => println!(" {stem} x{} NOT minimized: {err}", group.len()),
+ }
+ }
+
+ Ok(())
+}
+
fn crashes(args: &CrashesArgs) -> Result<(), Box<dyn Error>> {
let store = Store::open(&args.db)?;
let campaign_id = CampaignId(args.campaign);