From 2ed7ec6a51e15f440870b053bf379c2bca37e811 Mon Sep 17 00:00:00 2001 From: CyberSecurityUP Date: Wed, 2 Dec 2026 14:44:32 -0300 Subject: [PATCH] fix: reactive seeds target from prose recon; add --no-reactive off switch - add_recon always seeds the target asset and extracts in-scope URLs / subdomains from free text, so a prose recon answer no longer leaves the graph empty (which made the planner quiesce with 0 findings) - --no-reactive / NEUROSPLOIT_NO_REACTIVE=1 and unchecking the web toggle now actually disable reactive and fall back to the phased pipeline --- neurosploit-rs/app/src/main.rs | 9 +- .../crates/harness/src/dual_build.rs | 108 +++++++++++++++++- web/server.js | 1 + 3 files changed, 111 insertions(+), 7 deletions(-) diff --git a/neurosploit-rs/app/src/main.rs b/neurosploit-rs/app/src/main.rs index fd16363..22729e6 100644 --- a/neurosploit-rs/app/src/main.rs +++ b/neurosploit-rs/app/src/main.rs @@ -205,6 +205,10 @@ struct Cli { /// never auto-enabled. #[arg(long = "no-auto-config", global = true)] no_auto_config: bool, + /// Disable the reactive engine and use the phased pipeline. Overrides the + /// auto-config default (same as NEUROSPLOIT_NO_REACTIVE=1). + #[arg(long = "no-reactive", global = true)] + no_reactive: bool, } /// Flags shared by the infrastructure-style engagements (network · ad · cloud). @@ -1169,6 +1173,9 @@ async fn main() -> anyhow::Result<()> { if cli.no_auto_config { std::env::set_var("NEUROSPLOIT_NO_AUTO", "1"); } + if cli.no_reactive { + std::env::set_var("NEUROSPLOIT_NO_REACTIVE", "1"); + } // Auto-configuration (early env): enable tools/economy when detected. harness::autoconfig::apply_early(); let base = ensure_agents(&find_base()).await; @@ -1569,7 +1576,7 @@ async fn main() -> anyhow::Result<()> { if !models.is_empty() { cfg.models = models; } - cfg.reactive = reactive; + cfg.reactive = reactive && !cli.no_reactive; cfg.mcp_profile = mcp_profile; cfg.autonomy = autonomy; cfg.stealth = cli.stealth; diff --git a/neurosploit-rs/crates/harness/src/dual_build.rs b/neurosploit-rs/crates/harness/src/dual_build.rs index aed5f69..32b079b 100644 --- a/neurosploit-rs/crates/harness/src/dual_build.rs +++ b/neurosploit-rs/crates/harness/src/dual_build.rs @@ -41,15 +41,22 @@ fn clip(s: &str, n: usize) -> String { s.trim().chars().take(n).collect() } /// Add recon-discovered assets. Returns how many assets were new. pub fn add_recon(dg: &mut DualGraph, target: &str, recon: &str, in_scope: &dyn Fn(&str) -> bool) -> usize { - let (Some(s), Some(e)) = (recon.find('{'), recon.rfind('}')) else { return 0 }; - if e <= s { return 0; } - let Ok(v) = serde_json::from_str::(&recon[s..=e]) else { return 0 }; let thost = host_of(target); - let mut added = 0usize; - + if thost.is_empty() { + return 0; + } let kind = if is_ip(&thost) { AssetKind::IpAddress } else { AssetKind::Domain }; - added += dg.assets.upsert(kind, &thost, BTreeMap::new(), "target") as usize; + // Always seed the target. Recon is best-effort: even when the model answers + // in prose (no JSON), the planner still needs a root asset to schedule. + let mut added = dg.assets.upsert(kind, &thost, BTreeMap::new(), "target") as usize; let root_id = dg.assets.find(kind, &thost).map(|a| a.id.clone()); + added += add_recon_text(dg, recon, &thost, &root_id, in_scope); + + let (Some(s), Some(e)) = (recon.find('{'), recon.rfind('}')) else { return added }; + if e <= s { + return added; + } + let Ok(v) = serde_json::from_str::(&recon[s..=e]) else { return added }; for key in ["hosts", "subdomains"] { for raw in strings(&v, key) { @@ -81,6 +88,77 @@ pub fn add_recon(dg: &mut DualGraph, target: &str, recon: &str, in_scope: &dyn F added } +/// Pull URLs and in-scope subdomains out of free-text recon (models often reply +/// in prose instead of the requested JSON). Never invents assets: only absolute +/// URLs whose host is in scope and subdomains of the target. +fn add_recon_text( + dg: &mut DualGraph, + recon: &str, + thost: &str, + root_id: &Option, + in_scope: &dyn Fn(&str) -> bool, +) -> usize { + let mut added = 0usize; + let mut seen = std::collections::BTreeSet::new(); + for raw in recon.split(|c: char| { + c.is_whitespace() || matches!(c, '"' | '\'' | ',' | '(' | ')' | '[' | ']' | '<' | '>' | '`') + }) { + let tok = raw.trim().trim_end_matches(['.', ';', ':', ')', ']', '}', '"', '\'']); + if tok.is_empty() || tok.len() > 300 || !seen.insert(tok.to_string()) { + continue; + } + if added >= MAX_NEW_ASSETS { + break; + } + if tok.starts_with("http://") || tok.starts_with("https://") { + if !in_scope(tok) { + continue; + } + added += dg + .assets + .upsert(AssetKind::Endpoint, tok, BTreeMap::new(), "recon-text") as usize; + if let (Some(root), Some(ep)) = ( + root_id, + dg.assets.find(AssetKind::Endpoint, tok).map(|a| a.id.clone()), + ) { + dg.assets.relate(&ep, root, AssetRelation::HostedOn); + } + } else if looks_like_host(tok) { + let host = tok.trim_start_matches("*.").to_lowercase(); + if host == thost || !host.ends_with(&format!(".{thost}")) { + continue; + } + if !in_scope(&format!("https://{host}")) { + continue; + } + added += dg + .assets + .upsert(AssetKind::Subdomain, &host, BTreeMap::new(), "recon-text") as usize; + if let (Some(root), Some(sub)) = ( + root_id, + dg.assets.find(AssetKind::Subdomain, &host).map(|a| a.id.clone()), + ) { + dg.assets.relate(root, &sub, AssetRelation::ParentOf); + } + } + } + added +} + +fn looks_like_host(s: &str) -> bool { + if s.is_empty() || s.len() > 253 || s.contains('/') || !s.contains('.') { + return false; + } + if !s + .chars() + .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '-' | '_')) + { + return false; + } + let tld = s.rsplit('.').next().unwrap_or(""); + tld.len() >= 2 && tld.chars().any(|c| c.is_ascii_alphabetic()) +} + /// Record findings as intent -> finding with anchors. Returns (new, updated). pub fn add_findings(dg: &mut DualGraph, target: &str, findings: &[Finding], in_scope: &dyn Fn(&str) -> bool) -> (usize, usize) { // One root goal per target. @@ -165,6 +243,24 @@ mod tests { assert!(dg.assets.edges.iter().any(|e| e.kind == AssetRelation::ParentOf)); } + #[test] + fn prose_recon_still_seeds_target_and_endpoints() { + let mut dg = DualGraph::default(); + let any = |_u: &str| true; + let n = add_recon( + &mut dg, + "http://127.0.0.1:8765/", + "Found http://127.0.0.1:8765/login then api.t.com", + &any, + ); + assert!(n >= 1); + assert!(dg.assets.find(AssetKind::IpAddress, "127.0.0.1").is_some()); + assert!(dg + .assets + .find(AssetKind::Endpoint, "http://127.0.0.1:8765/login") + .is_some()); + } + #[test] fn findings_become_intent_finding_with_anchors_and_dedupe() { let mut dg = DualGraph::default(); diff --git a/web/server.js b/web/server.js index cc15d57..8a4af93 100644 --- a/web/server.js +++ b/web/server.js @@ -665,6 +665,7 @@ function autoOptOutEnv(body) { if (body.revalidatePoc === false) env.NEUROSPLOIT_NO_REVALIDATE = '1'; if (body.evasion === false) env.NEUROSPLOIT_NO_EVASION = '1'; if (body.sandbox === 'host') env.NEUROSPLOIT_NO_SANDBOX = '1'; + if (body.reactive === false) env.NEUROSPLOIT_NO_REACTIVE = '1'; return env; }