From bc0ee6ca276e121296ba401fc001d94c73f7d80b Mon Sep 17 00:00:00 2001 From: Joas A Santos <34966120+CyberSecurityUP@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:09:47 -0300 Subject: [PATCH] test(skills): drive the catalogue through several rounds, not one call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every test written for the exploration work so far checks a single call to route. That proves a round can be selected; it does not prove the loop advances, which is the thing the loop exists for and the thing that was broken three separate ways this week. Add a walk that drives the catalogue on disk the way exploration_loop does: start at round 1, route, record what ran, feed findings back, go again under the same budget and gates. On a typical web recon it reaches three rounds — round 1 no capabilities yet, recon-driven: sqli_error, idor, jwt_manipulation round 2 the SQLi minted admin_access, credential, internal_host, so sqli_union and sqli_blind arrive by declared chain while cloud_iam_privesc and container_escape arrive by capability alone round 3 privilege_escalation chains to exposed_admin_panel and account_takeover_chain; ssrf and auth_bypass by capability Three tests: that it runs more than one round and no round repeats the one before it, that rounds finding nothing wind the loop down rather than paying for skills on stale recon, and that max_rounds holds under a productive run. The findings are synthetic, so this proves the machinery advances and stops where told. It does not show the selections pay off against a real target — that still needs an engagement with API keys and something to point at. Co-Authored-By: Claude Opus 5 --- neurosploit-rs/crates/harness/src/skill.rs | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/neurosploit-rs/crates/harness/src/skill.rs b/neurosploit-rs/crates/harness/src/skill.rs index b7a48ee..c187f4c 100644 --- a/neurosploit-rs/crates/harness/src/skill.rs +++ b/neurosploit-rs/crates/harness/src/skill.rs @@ -1819,3 +1819,130 @@ mod overmint_tests { ); } } + +#[cfg(test)] +mod loop_progression_tests { + use super::*; + + fn repo_root() -> std::path::PathBuf { + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .ancestors().nth(3).unwrap().to_path_buf() + } + + fn finding(agent: &str, title: &str, impact: &str, evidence: &str) -> crate::types::Finding { + let mut f = crate::types::Finding::default(); + f.agent = agent.into(); + f.id = format!("{agent}-f"); + f.severity = "High".into(); + f.title = title.into(); + f.impact = impact.into(); + f.evidence = evidence.into(); + f + } + + /// Drive the real catalogue through the loop the way `exploration_loop` + /// does: start at round 1, route, record what ran, feed back findings, go + /// again under the same budget and gates. + /// + /// Every test so far has checked a single call to `route`. This checks the + /// thing the loop is for — that it keeps going, picks something different + /// each round, and stops where it is told. The findings are synthetic, so + /// this proves the machinery advances, not that the selections pay off. + fn walk(mode: &str, recon: &str, produce: impl Fn(u32, &[ScoredSkill]) -> Vec) + -> Vec> + { + let catalog = load_catalog(&repo_root()); + let budget = ExplorationBudget { + max_rounds: 3, max_skills_per_round: 5, max_total_skills: 20, + }; + + let mut skills_ran: HashSet = HashSet::new(); + let mut findings: Vec = Vec::new(); + let mut explored = 0usize; + let mut rounds: Vec> = Vec::new(); + let mut round = 1u32; + + loop { + let caps = capabilities_from(&findings); + let picked = next_round( + &catalog, &findings, &skills_ran, explored, &caps, mode, recon, round, &budget, + ); + if picked.is_empty() { + break; + } + rounds.push(picked.iter().map(|s| s.skill.name.clone()).collect()); + + findings.extend(produce(round, &picked)); + for s in &picked { + skills_ran.insert(s.skill.name.clone()); + explored += 1; + } + round += 1; + } + rounds + } + + #[test] + fn the_loop_runs_several_rounds_and_does_not_repeat_itself() { + let rounds = walk( + "web", + "nginx php mysql wordpress /api/users?id=1 jwt bearer eyJ upload .map", + |round, picked| { + // Each round yields one finding from its highest-scoring skill, + // phrased as an achievement so it mints capabilities. + vec![finding( + &picked[0].skill.name, + &format!("Round {round}: exploitation confirmed"), + "Recovered credentials for an application account", + "dumped admin:hunter2 from the users table; backend at 10.0.4.12", + )] + }, + ); + + assert!( + rounds.len() >= 2, + "the loop stopped after {} round(s): {rounds:?}", + rounds.len(), + ); + + // A round that reruns the previous round's picks is not progress. + for w in rounds.windows(2) { + let (a, b) = (&w[0], &w[1]); + assert!( + b.iter().any(|s| !a.contains(s)), + "a round repeated the one before it: {a:?} then {b:?}", + ); + } + } + + /// A round that finds nothing mints no capabilities, so the loop should + /// wind down rather than keep paying for skills on the same stale recon. + #[test] + fn rounds_that_find_nothing_do_not_keep_the_loop_alive_forever() { + let rounds = walk("web", "nginx php mysql /login", |_round, _picked| Vec::new()); + assert!( + rounds.len() <= 3, + "ran {} rounds on findings that never appeared: {rounds:?}", + rounds.len(), + ); + } + + /// max_rounds is the ceiling whatever the findings do. + #[test] + fn the_round_ceiling_holds_under_a_productive_run() { + let rounds = walk( + "host", + "445 smb 389 ldap kerberos 88 domain controller windows", + |round, picked| { + vec![finding( + &picked[0].skill.name, + &format!("Round {round}: domain foothold"), + "Obtained administrative access", + "recovered DOMAIN\\svc_sql:Summer2024; dumped NTDS.dit; host 10.10.1.7", + )] + }, + ); + assert!(rounds.len() <= 3, "exceeded max_rounds: {} rounds", rounds.len()); + } +} +