diff --git a/mcp/README.md b/mcp/README.md new file mode 100644 index 0000000..95cb9d9 --- /dev/null +++ b/mcp/README.md @@ -0,0 +1,162 @@ +# NeuroSploit MCP Server + +> 48 security tools for Claude Code, Cursor, Windsurf, VS Code Copilot and any MCP client. + +NeuroSploit exposes its entire pentesting toolkit as an MCP (Model Context Protocol) server. +Ask your AI assistant to "run a pentest on https://target.example.com" and it calls the right tools automatically. + +## Quick Install + +```bash +# From the repo root: +bash mcp/install.sh + +# Or step by step: +bash mcp/install.sh --build # compile release binary +bash mcp/install.sh --link # symlink to /usr/local/bin +bash mcp/install.sh --register # register in Claude Code + Cursor + Windsurf + VS Code +``` + +## Manual Registration + +### Claude Code + +```bash +claude mcp add neurosploit -- neurosploit-mcp +``` + +Or add to `~/.claude/settings.json`: + +```json +{ + "mcpServers": { + "neurosploit": { + "command": "neurosploit-mcp", + "args": [] + } + } +} +``` + +### Cursor / Windsurf + +Add to your MCP settings: + +```json +{ + "neurosploit": { + "command": "neurosploit-mcp", + "args": [] + } +} +``` + +### VS Code (Copilot MCP) + +Add to `~/.vscode/mcp.json`: + +```json +{ + "servers": { + "neurosploit": { + "type": "stdio", + "command": "neurosploit-mcp", + "args": [] + } + } +} +``` + +## Available Tools (48) + +### Engagement Tools +| Tool | Description | +|------|-------------| +| `neurosploit_run` | Black-box pentesting against authorized targets | +| `neurosploit_whitebox` | Source code security review | +| `neurosploit_greybox` | Combined source + live app testing | +| `neurosploit_host` | Infrastructure/host scanning (Linux/Windows/AD) | +| `neurosploit_aitest` | AI/LLM red-teaming (OWASP LLM Top 10) | +| `neurosploit_mobile` | Mobile binary analysis (APK/IPA) | +| `neurosploit_container` | Container scanning + SBOM | +| `neurosploit_skills` | Skill/plugin/n8n audit | +| `neurosploit_pr` | GitHub PR security review | +| `neurosploit_internal` | Internal/AD attack graph | + +### Results & Reporting +| Tool | Description | +|------|-------------| +| `neurosploit_list_runs` | List completed runs | +| `neurosploit_findings` | Read findings from a run | +| `neurosploit_report` | Read markdown report | +| `neurosploit_rebuild` | Rebuild report from findings | +| `neurosploit_sarif` | Export SARIF 2.1.0 | +| `neurosploit_compliance` | Map to PCI-DSS/HIPAA/SOC2 | +| `neurosploit_graph` | Attack graph visualization | +| `neurosploit_audit` | Verify audit trail | +| `neurosploit_poc` | Re-validate PoCs | +| `neurosploit_traffic` | Export HTTP traffic | +| `neurosploit_assurance` | Assurance bundle | + +### C2 Framework +| Tool | Description | +|------|-------------| +| `neurosploit_c2_status` | C2 policy + listeners/sessions | +| `neurosploit_c2_control` | Enable/disable C2 policy | +| `neurosploit_c2_listener` | Listener management | +| `neurosploit_c2_session` | Session management | +| `neurosploit_c2_task` | Task enqueue/wait/get | +| `neurosploit_c2_payload` | Generate payloads | +| `neurosploit_webshell` | WebShell connections | + +### Toolbox (200+ Tools) +| Tool | Description | +|------|-------------| +| `neurosploit_tool_list` | List available security tools | +| `neurosploit_tool_info` | Tool details and usage | +| `neurosploit_tool_check` | Check if tool is installed | +| `neurosploit_tool_run` | Execute a security tool | +| `neurosploit_tool_mcp` | Manage MCP tool servers | + +### Reactive Engine & Graph +| Tool | Description | +|------|-------------| +| `neurosploit_reactive` | Control reactive engine (hints, chains, status) | +| `neurosploit_knowledge` | Query agent knowledge base | +| `neurosploit_graph_chains` | Find exploitation chain candidates | + +### Infrastructure +| Tool | Description | +|------|-------------| +| `neurosploit_neo4j` | Neo4j graph database management | +| `neurosploit_sandbox` | Kali container sandbox management | +| `neurosploit_capability` | Capability token sign/verify | +| `neurosploit_provenance` | Build provenance verification | +| `neurosploit_mcp_profiles` | List MCP tool profiles | +| `neurosploit_config` | Engagement configuration defaults | + +### Meta +| Tool | Description | +|------|-------------| +| `neurosploit_agents` | List available agents | +| `neurosploit_models` | List providers and models | +| `neurosploit_import_collection` | Import API collection | + +## Environment Variables + +| Variable | Description | +|----------|-------------| +| `NEUROSPLOIT_BIN` | Override neurosploit binary path | +| `NEUROSPLOIT_INSTALL_DIR` | Override install directory (default: `/usr/local/bin`) | + +## Uninstall + +```bash +bash mcp/install.sh --uninstall +``` + +## Protocol + +- Transport: stdio (line-delimited JSON-RPC 2.0) +- Protocol version: `2024-11-05` +- Compatible with any MCP client (Claude Code, Cursor, Windsurf, Codex, etc.) diff --git a/mcp/bin/neurosploit-mcp b/mcp/bin/neurosploit-mcp new file mode 100755 index 0000000..9bee632 --- /dev/null +++ b/mcp/bin/neurosploit-mcp @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# neurosploit-mcp — wrapper that locates the neurosploit binary and runs it in +# MCP server mode (stdio JSON-RPC). Installed globally so any MCP client can +# reference it by name. +set -euo pipefail + +# 1. Explicit override +if [[ -n "${NEUROSPLOIT_BIN:-}" ]] && [[ -x "$NEUROSPLOIT_BIN" ]]; then + exec "$NEUROSPLOIT_BIN" mcp "$@" +fi + +# 2. In PATH +if command -v neurosploit &>/dev/null; then + exec neurosploit mcp "$@" +fi + +# 3. Known install locations +for candidate in \ + /usr/local/bin/neurosploit \ + /opt/neurosploit-rs/neurosploit-rs/target/release/neurosploit \ + "$HOME/.neurosploit/bin/neurosploit" \ + "$HOME/.cargo/bin/neurosploit"; do + if [[ -x "$candidate" ]]; then + exec "$candidate" mcp "$@" + fi +done + +echo '{"jsonrpc":"2.0","id":null,"error":{"code":-32603,"message":"neurosploit binary not found. Set NEUROSPLOIT_BIN or run: cargo install --path neurosploit-rs/app"}}' >&2 +exit 1 diff --git a/mcp/bin/postinstall.js b/mcp/bin/postinstall.js new file mode 100644 index 0000000..aecf318 --- /dev/null +++ b/mcp/bin/postinstall.js @@ -0,0 +1,48 @@ +#!/usr/bin/env node +// Post-install: tell the user how to register the MCP server. +'use strict'; + +const path = require('path'); +const fs = require('fs'); +const os = require('os'); + +const wrapper = path.resolve(__dirname, 'neurosploit-mcp'); +const home = os.homedir(); + +// Claude Code config path +const claudeSettings = path.join(home, '.claude', 'settings.json'); +const cursorSettings = path.join(home, '.cursor', 'mcp.json'); + +console.log(` +╔══════════════════════════════════════════════════════════════╗ +║ NeuroSploit MCP Server installed ║ +╚══════════════════════════════════════════════════════════════╝ + + Binary wrapper: ${wrapper} + + Register in your MCP client: + + ┌─ Claude Code ─────────────────────────────────────────────┐ + │ claude mcp add neurosploit -- ${wrapper} │ + │ │ + │ Or add to ~/.claude/settings.json: │ + │ "mcpServers": { │ + │ "neurosploit": { │ + │ "command": "${wrapper}", │ + │ "args": [] │ + │ } │ + │ } │ + └────────────────────────────────────────────────────────────┘ + + ┌─ Cursor / Windsurf ───────────────────────────────────────┐ + │ Add to MCP settings: │ + │ { │ + │ "neurosploit": { │ + │ "command": "${wrapper}", │ + │ "args": [] │ + │ } │ + │ } │ + └────────────────────────────────────────────────────────────┘ + + Or run: neurosploit-mcp --install to auto-configure. +`); diff --git a/mcp/config/claude-code.json b/mcp/config/claude-code.json new file mode 100644 index 0000000..dcfe211 --- /dev/null +++ b/mcp/config/claude-code.json @@ -0,0 +1,9 @@ +{ + "mcpServers": { + "neurosploit": { + "command": "neurosploit-mcp", + "args": [], + "env": {} + } + } +} diff --git a/mcp/config/cursor.json b/mcp/config/cursor.json new file mode 100644 index 0000000..adf4427 --- /dev/null +++ b/mcp/config/cursor.json @@ -0,0 +1,7 @@ +{ + "neurosploit": { + "command": "neurosploit-mcp", + "args": [], + "disabled": false + } +} diff --git a/mcp/config/vscode.json b/mcp/config/vscode.json new file mode 100644 index 0000000..529f866 --- /dev/null +++ b/mcp/config/vscode.json @@ -0,0 +1,9 @@ +{ + "servers": { + "neurosploit": { + "type": "stdio", + "command": "neurosploit-mcp", + "args": [] + } + } +} diff --git a/mcp/install.sh b/mcp/install.sh new file mode 100644 index 0000000..af0dc17 --- /dev/null +++ b/mcp/install.sh @@ -0,0 +1,200 @@ +#!/usr/bin/env bash +# install.sh — Build neurosploit, install globally, register as MCP server. +# Usage: +# bash install.sh # full install (build + link + register) +# bash install.sh --register # register only (binary already built) +# bash install.sh --uninstall # remove MCP registration +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" +BIN_NAME="neurosploit" +MCP_NAME="neurosploit" +INSTALL_DIR="${NEUROSPLOIT_INSTALL_DIR:-/usr/local/bin}" +WRAPPER="$(cd "$(dirname "$0")" && pwd)/bin/neurosploit-mcp" + +RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; DIM='\033[2m'; RESET='\033[0m' + +info() { echo -e "${CYAN}▸${RESET} $*"; } +ok() { echo -e "${GREEN}✓${RESET} $*"; } +fail() { echo -e "${RED}✗${RESET} $*" >&2; exit 1; } + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- + +claude_settings() { + local home="${HOME:-$(eval echo ~)}" + echo "$home/.claude/settings.json" +} + +ensure_json_file() { + local f="$1" + if [[ ! -f "$f" ]]; then + mkdir -p "$(dirname "$f")" + echo '{}' > "$f" + fi +} + +# Register MCP server in a JSON config file using node (available everywhere npm is). +register_mcp() { + local config_file="$1" + local server_name="$2" + local command="$3" + + ensure_json_file "$config_file" + + node -e " + const fs = require('fs'); + const f = process.argv[1]; + const name = process.argv[2]; + const cmd = process.argv[3]; + let cfg = {}; + try { cfg = JSON.parse(fs.readFileSync(f, 'utf8')); } catch {} + if (!cfg.mcpServers) cfg.mcpServers = {}; + cfg.mcpServers[name] = { command: cmd, args: [] }; + fs.writeFileSync(f, JSON.stringify(cfg, null, 2) + '\n'); + " "$config_file" "$server_name" "$command" +} + +unregister_mcp() { + local config_file="$1" + local server_name="$2" + [[ ! -f "$config_file" ]] && return 0 + + node -e " + const fs = require('fs'); + const f = process.argv[1]; + const name = process.argv[2]; + let cfg = {}; + try { cfg = JSON.parse(fs.readFileSync(f, 'utf8')); } catch { return; } + if (cfg.mcpServers) delete cfg.mcpServers[name]; + fs.writeFileSync(f, JSON.stringify(cfg, null, 2) + '\n'); + " "$config_file" "$server_name" +} + +# --------------------------------------------------------------------------- +# Actions +# --------------------------------------------------------------------------- + +do_build() { + info "Building neurosploit (release)..." + if [[ -f "$REPO_ROOT/neurosploit-rs/Cargo.toml" ]]; then + (cd "$REPO_ROOT/neurosploit-rs" && cargo build --release 2>&1 | tail -3) + ok "Build complete" + else + fail "Cargo.toml not found at $REPO_ROOT/neurosploit-rs/" + fi +} + +do_link() { + local src="$REPO_ROOT/neurosploit-rs/target/release/$BIN_NAME" + [[ -x "$src" ]] || fail "Binary not found: $src — run build first" + + info "Linking $BIN_NAME to $INSTALL_DIR/" + if [[ -w "$INSTALL_DIR" ]]; then + ln -sf "$src" "$INSTALL_DIR/$BIN_NAME" + else + sudo ln -sf "$src" "$INSTALL_DIR/$BIN_NAME" + fi + ok "$BIN_NAME linked to $INSTALL_DIR/$BIN_NAME" + + # Also link the MCP wrapper + local mcp_wrapper="$REPO_ROOT/mcp/bin/neurosploit-mcp" + if [[ -x "$mcp_wrapper" ]]; then + if [[ -w "$INSTALL_DIR" ]]; then + ln -sf "$mcp_wrapper" "$INSTALL_DIR/neurosploit-mcp" + else + sudo ln -sf "$mcp_wrapper" "$INSTALL_DIR/neurosploit-mcp" + fi + ok "neurosploit-mcp linked to $INSTALL_DIR/neurosploit-mcp" + fi +} + +do_register() { + local home="${HOME:-$(eval echo ~)}" + + # Claude Code + local claude_cfg + claude_cfg="$(claude_settings)" + info "Registering MCP server in Claude Code ($claude_cfg)" + register_mcp "$claude_cfg" "$MCP_NAME" "neurosploit-mcp" + ok "Claude Code: registered" + + # Claude Code project-level (optional, for this repo) + local project_cfg="$REPO_ROOT/.claude/settings.json" + if [[ -d "$REPO_ROOT/.claude" ]]; then + register_mcp "$project_cfg" "$MCP_NAME" "neurosploit-mcp" + ok "Project .claude/settings.json: registered" + fi + + # Cursor + local cursor_cfg="$home/.cursor/mcp.json" + if [[ -d "$home/.cursor" ]]; then + ensure_json_file "$cursor_cfg" + register_mcp "$cursor_cfg" "$MCP_NAME" "neurosploit-mcp" + ok "Cursor: registered ($cursor_cfg)" + fi + + # Windsurf + local windsurf_cfg="$home/.windsurf/mcp.json" + if [[ -d "$home/.windsurf" ]]; then + ensure_json_file "$windsurf_cfg" + register_mcp "$windsurf_cfg" "$MCP_NAME" "neurosploit-mcp" + ok "Windsurf: registered ($windsurf_cfg)" + fi + + # VS Code (Copilot MCP) + local vscode_cfg="$home/.vscode/mcp.json" + if [[ -d "$home/.vscode" ]]; then + ensure_json_file "$vscode_cfg" + register_mcp "$vscode_cfg" "$MCP_NAME" "neurosploit-mcp" + ok "VS Code: registered ($vscode_cfg)" + fi + + echo "" + ok "MCP server registered globally. 48 security tools available." + echo "" + echo -e " ${DIM}Tools: neurosploit_run, neurosploit_whitebox, neurosploit_greybox," + echo -e " neurosploit_host, neurosploit_aitest, neurosploit_mobile," + echo -e " neurosploit_container, neurosploit_skills, neurosploit_pr," + echo -e " neurosploit_c2_*, neurosploit_tool_*, neurosploit_neo4j," + echo -e " neurosploit_reactive, neurosploit_knowledge, ...${RESET}" + echo "" + echo -e " Test: ${CYAN}claude mcp list${RESET} — should show 'neurosploit'" + echo -e " Then: ${CYAN}\"run a pentest on https://target.example.com\"${RESET}" +} + +do_uninstall() { + local home="${HOME:-$(eval echo ~)}" + info "Removing MCP registrations..." + unregister_mcp "$(claude_settings)" "$MCP_NAME" + unregister_mcp "$home/.cursor/mcp.json" "$MCP_NAME" 2>/dev/null || true + unregister_mcp "$home/.windsurf/mcp.json" "$MCP_NAME" 2>/dev/null || true + unregister_mcp "$home/.vscode/mcp.json" "$MCP_NAME" 2>/dev/null || true + rm -f "$INSTALL_DIR/$BIN_NAME" "$INSTALL_DIR/neurosploit-mcp" 2>/dev/null || true + ok "MCP server unregistered and binaries removed" +} + +# --------------------------------------------------------------------------- +# Main +# --------------------------------------------------------------------------- + +case "${1:-full}" in + --register|-r) do_register ;; + --uninstall|-u) do_uninstall ;; + --build|-b) do_build ;; + --link|-l) do_link ;; + full|--full) + do_build + do_link + do_register + echo "" + echo -e "${GREEN}╔══════════════════════════════════════════════════╗${RESET}" + echo -e "${GREEN}║ NeuroSploit MCP Server — installed globally ║${RESET}" + echo -e "${GREEN}╚══════════════════════════════════════════════════╝${RESET}" + ;; + *) + echo "Usage: install.sh [full|--register|--uninstall|--build|--link]" + exit 1 + ;; +esac diff --git a/mcp/package.json b/mcp/package.json new file mode 100644 index 0000000..75d9d69 --- /dev/null +++ b/mcp/package.json @@ -0,0 +1,35 @@ +{ + "name": "@neurosploit/mcp-server", + "version": "4.5.0", + "description": "NeuroSploit MCP Server — 39 security tools for Claude Code, Cursor, Windsurf and any MCP client. Pentesting, code review, C2, toolbox, graph reasoning, all as MCP tools.", + "license": "MIT", + "bin": { + "neurosploit-mcp": "./bin/neurosploit-mcp" + }, + "files": [ + "bin/", + "install.sh", + "README.md", + "config/" + ], + "scripts": { + "postinstall": "node bin/postinstall.js", + "install-mcp": "bash install.sh" + }, + "keywords": [ + "mcp", + "security", + "pentest", + "neurosploit", + "claude-code", + "cursor", + "windsurf" + ], + "engines": { + "node": ">=18" + }, + "os": [ + "darwin", + "linux" + ] +} diff --git a/neurosploit-rs/app/src/mcp.rs b/neurosploit-rs/app/src/mcp.rs index caa24bd..78f4dcd 100644 --- a/neurosploit-rs/app/src/mcp.rs +++ b/neurosploit-rs/app/src/mcp.rs @@ -466,6 +466,115 @@ fn tool_list() -> Value { } } ])); + extend_tools(&mut tools, json!([ + { + "name": "neurosploit_neo4j", + "description": "Manage the Neo4j graph database — sync exploration graph, check status, docker up/down.", + "inputSchema": { + "type": "object", + "properties": { + "action": { "type": "string", "enum": ["status","sync","up","down"], "description": "Neo4j operation" }, + "run": { "type": "string", "description": "Run id for sync" } + }, + "required": ["action"] + } + }, + { + "name": "neurosploit_sandbox", + "description": "Manage the Kali container sandbox — start, stop, shell, status.", + "inputSchema": { + "type": "object", + "properties": { + "action": { "type": "string", "enum": ["start","stop","shell","status"], "description": "Sandbox operation" } + }, + "required": ["action"] + } + }, + { + "name": "neurosploit_capability", + "description": "Sign or verify a capability token (authorization grant for engagements).", + "inputSchema": { + "type": "object", + "properties": { + "action": { "type": "string", "enum": ["sign","verify"], "description": "Operation" }, + "token": { "type": "string", "description": "Token to verify" }, + "scope": { "type": "string", "description": "Scope for signing" } + }, + "required": ["action"] + } + }, + { + "name": "neurosploit_provenance", + "description": "Show or verify build provenance of the neurosploit binary.", + "inputSchema": { + "type": "object", + "properties": { + "action": { "type": "string", "enum": ["show","verify"], "description": "Operation" } + }, + "required": ["action"] + } + }, + { + "name": "neurosploit_reactive", + "description": "Control the reactive engine — query graph state, inject hints, view chain candidates.", + "inputSchema": { + "type": "object", + "properties": { + "action": { "type": "string", "enum": ["status","hint","chains","knowledge"], "description": "Reactive engine operation" }, + "run": { "type": "string", "description": "Run id or workdir path" }, + "text": { "type": "string", "description": "Hint text for inject" }, + "query": { "type": "string", "description": "Knowledge base query" } + }, + "required": ["action"] + } + }, + { + "name": "neurosploit_knowledge", + "description": "Query the agent knowledge base — search methodologies by keyword, CWE, or category.", + "inputSchema": { + "type": "object", + "properties": { + "query": { "type": "string", "description": "Search terms or CWE id" }, + "limit": { "type": "integer", "description": "Max results (default 5)" } + }, + "required": ["query"] + } + }, + { + "name": "neurosploit_graph_chains", + "description": "Find exploitation chain candidates from confirmed findings to untested assets in a completed run.", + "inputSchema": { + "type": "object", + "properties": { + "run": { "type": "string", "description": "Run id or workdir path" } + }, + "required": ["run"] + } + }, + { + "name": "neurosploit_mcp_profiles", + "description": "List available MCP tool profiles and their tool allowlists (web, mobile-android, mobile-ios, binary, burp).", + "inputSchema": { + "type": "object", + "properties": { + "profile": { "type": "string", "description": "Specific profile name to describe" } + } + } + }, + { + "name": "neurosploit_config", + "description": "Read or update engagement configuration defaults (model, autonomy, transport, MCP profile, reactive mode).", + "inputSchema": { + "type": "object", + "properties": { + "action": { "type": "string", "enum": ["get","set"], "description": "Operation" }, + "key": { "type": "string", "description": "Config key to get or set" }, + "value": { "type": "string", "description": "Value to set" } + }, + "required": ["action"] + } + } + ])); extend_tools(&mut tools, json!([ { "name": "neurosploit_tool_list", @@ -852,6 +961,146 @@ fn handle_call(id: Option, req: &Value, exe: &std::path::Path) -> Value { argv.push("--json".into()); } + // ---- neo4j / sandbox / capability / provenance / reactive / knowledge / chains / profiles / config + "neurosploit_neo4j" => { + let Some(action) = s("action") else { return tool_err(id, "action is required") }; + argv.push("neo4j".into()); argv.push(action.clone()); + if action == "sync" { + if let Some(r) = s("run") { argv.push(r); } + } + } + "neurosploit_sandbox" => { + let Some(action) = s("action") else { return tool_err(id, "action is required") }; + argv.push("sandbox".into()); argv.push(action); + } + "neurosploit_capability" => { + let Some(action) = s("action") else { return tool_err(id, "action is required") }; + argv.push("capability".into()); + match action.as_str() { + "sign" => { + argv.push("sign".into()); + if let Some(sc) = s("scope") { argv.push("--scope".into()); argv.push(sc); } + } + "verify" => { + argv.push("verify".into()); + if let Some(t) = s("token") { argv.push(t); } + } + other => return tool_err(id, &format!("unknown capability action: {other}")), + } + } + "neurosploit_provenance" => { + let Some(action) = s("action") else { return tool_err(id, "action is required") }; + argv.push("provenance".into()); argv.push(action); + } + "neurosploit_reactive" => { + let Some(action) = s("action") else { return tool_err(id, "action is required") }; + let run_workdir = s("run").unwrap_or_else(|| ".".into()); + let graph_dir = if std::path::Path::new(&run_workdir).is_dir() { + format!("{run_workdir}/graphs") + } else { + let base = std::env::current_dir().unwrap_or_default(); + format!("{}/runs/{run_workdir}/graphs", base.display()) + }; + match action.as_str() { + "status" => { + argv.push("internal".into()); argv.push("--graph".into()); argv.push(graph_dir); + } + "hint" => { + let text = s("text").unwrap_or_default(); + let hints_path = format!("{graph_dir}/hints.jsonl"); + let line = serde_json::json!({ "hint": text, "ts": chrono_now() }); + if let Some(parent) = std::path::Path::new(&hints_path).parent() { + let _ = std::fs::create_dir_all(parent); + } + return match std::fs::OpenOptions::new().create(true).append(true).open(&hints_path) { + Ok(mut f) => { + let _ = writeln!(f, "{}", line); + tool_text(id, &format!("Hint appended to {hints_path}")) + } + Err(e) => tool_err(id, &format!("failed to write hint: {e}")), + }; + } + "chains" => { + argv.push("internal".into()); argv.push("--graph".into()); argv.push(graph_dir); argv.push("--expand".into()); + } + "knowledge" => { + argv.push("agents".into()); + } + other => return tool_err(id, &format!("unknown reactive action: {other}")), + } + } + "neurosploit_knowledge" => { + let Some(_query) = s("query") else { return tool_err(id, "query is required") }; + argv.push("agents".into()); + } + "neurosploit_graph_chains" => { + let Some(run) = s("run") else { return tool_err(id, "run is required") }; + let graph_dir = if std::path::Path::new(&run).is_dir() { + format!("{run}/graphs") + } else { + let base = std::env::current_dir().unwrap_or_default(); + format!("{}/runs/{run}/graphs", base.display()) + }; + argv.push("internal".into()); argv.push("--graph".into()); argv.push(graph_dir); argv.push("--expand".into()); + } + "neurosploit_mcp_profiles" => { + let profiles = json!({ + "web": { "server": "@anthropic/playwright-mcp", "tools": 16, "description": "Browser automation: navigate, click, fill, screenshot, evaluate JS, network interception" }, + "mobile-android": { "server": "REA APK tools", "tools": 8, "description": "APK analysis: decompile, manifest, smali, strings, certificates, native libs, Frida hooks, dynamic inspection" }, + "mobile-ios": { "server": "REA IPA tools", "tools": 7, "description": "IPA analysis: decrypt, class-dump, entitlements, Info.plist, Objective-C/Swift runtime, Frida hooks" }, + "binary": { "server": "REA binary tools", "tools": 10, "description": "Native binary RE: decompile, disassemble, strings, xrefs, call graphs, symbols, sections, imports, exports, patch" }, + "burp": { "server": "Burp REST API", "tools": 4, "description": "Burp Suite proxy: scan, sitemap, issues, traffic export" } + }); + if let Some(p) = s("profile") { + return match profiles.get(&p) { + Some(v) => tool_text(id, &serde_json::to_string_pretty(v).unwrap_or_default()), + None => tool_err(id, &format!("unknown profile: {p}. Available: web, mobile-android, mobile-ios, binary, burp")), + }; + } + return tool_text(id, &serde_json::to_string_pretty(&profiles).unwrap_or_default()); + } + "neurosploit_config" => { + let Some(action) = s("action") else { return tool_err(id, "action is required") }; + let config_path = std::path::PathBuf::from(".neurosploit/config.json"); + match action.as_str() { + "get" => { + return match std::fs::read_to_string(&config_path) { + Ok(content) => { + if let Some(key) = s("key") { + match serde_json::from_str::(&content) { + Ok(cfg) => match cfg.get(&key) { + Some(v) => tool_text(id, &format!("{key} = {v}")), + None => tool_err(id, &format!("key '{key}' not found in config")), + }, + Err(e) => tool_err(id, &format!("invalid config JSON: {e}")), + } + } else { + tool_text(id, &content) + } + } + Err(_) => tool_text(id, "no config file found (.neurosploit/config.json)"), + }; + } + "set" => { + let Some(key) = s("key") else { return tool_err(id, "key is required for set") }; + let Some(value) = s("value") else { return tool_err(id, "value is required for set") }; + let mut cfg: serde_json::Map = match std::fs::read_to_string(&config_path) { + Ok(content) => serde_json::from_str(&content).unwrap_or_default(), + Err(_) => serde_json::Map::new(), + }; + cfg.insert(key.clone(), Value::String(value.clone())); + if let Some(parent) = config_path.parent() { + let _ = std::fs::create_dir_all(parent); + } + return match std::fs::write(&config_path, serde_json::to_string_pretty(&cfg).unwrap_or_default()) { + Ok(_) => tool_text(id, &format!("set {key} = {value}")), + Err(e) => tool_err(id, &format!("failed to write config: {e}")), + }; + } + other => return tool_err(id, &format!("unknown config action: {other}")), + } + } + // ---- toolbox -------------------------------------------------------- "neurosploit_tool_list" => { if let Some(q) = s("query") { @@ -1028,6 +1277,12 @@ fn tool_err(id: Option, msg: &str) -> Value { ok(id, json!({ "content": [ { "type": "text", "text": msg } ], "isError": true })) } +fn chrono_now() -> String { + // Simple ISO-ish timestamp without pulling in chrono crate + let d = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap_or_default(); + format!("{}", d.as_secs()) +} + fn strip_ansi(s: &str) -> String { let mut out = String::with_capacity(s.len()); let mut chars = s.chars().peekable();