mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-11-25 21:54:26 +01:00
feat(c2+toolbox): C2 framework, 200+ security tools catalog, WebShells and MCP integration
C2 framework: local daemon with HTTP listener, session management, task dispatch, beacon protocol. WebShell support for persistent access through web endpoints. Full CLI surface (neurosploit c2/webshell), MCP tools, REPL commands, and web console integration with real-time session monitoring. Toolbox: 200+ real security tools catalog (nmap, ffuf, sqlmap, nuclei, etc.) with structured output parsing, MCP tool server integration, and auto-install. Runner executes tools with timeout, audit trail, and output capture. Catalog is data-driven via tools/toolbox.json. MCP: expanded tool surface for C2 sessions, task management, webshell operations, and toolbox execution. All tools share one implementation with CLI, REPL, and web console. Web UI: C2 dashboard with session cards, task panels, webshell terminal. Toolbox browser with search, run modal, and output viewer. API endpoints for all operations. Pipeline: toolbox integration for auto-running tools during engagements when autonomy level permits. 0 build errors, test suite passes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
408d59d9de
commit
27ff689265
32 files changed
+12174
-7
No files matched your search
+57
@@ -302,3 +302,60 @@ to the CLI — the console never re-implements harness logic.
|
||||
| `GET` | `/api/runs/:id/findings/:findingId/traffic` | The HTTP exchanges that back one finding: the exchanges the harness measured (`evidence_data` — baseline/attack, the identity pair, matrix probes, the oracle), each with its wire `provenance`; the finding's `wire` check summary; and the recorded `flows.jsonl` entries on the same endpoint. Real bytes, not the agent's prose. |
|
||||
|
||||
`GET /api/runs/:id` now also returns `extras`: `{ graph, todo, traces, flows, deliverables[] }`.
|
||||
|
||||
---
|
||||
|
||||
## Toolbox (200+ tools) and MCP tool servers
|
||||
|
||||
These endpoints shell out to `neurosploit tools … --json`; the catalog, scope
|
||||
checks and runner live in the harness. Nothing runs until the operator clicks
|
||||
Run (or an agent with opt-in tool access requests it).
|
||||
|
||||
| Method | Path | What |
|
||||
|---|---|---|
|
||||
| `GET` | `/api/tools?q=&category=` | Catalog list/search. Returns the `ToolSpec` array (`id, name, binary, category, description, usage, tags, intrusive, requires_root, install, mcp`). |
|
||||
| `GET` | `/api/tools/profiles` | Recommended tool IDs per engagement mode (`run`, `host`, `ad`, `cloud`, `container`, `mobile`, `binary`, `aitest`). |
|
||||
| `GET` | `/api/tools/:id` | One tool's descriptor + install hints. |
|
||||
| `GET/POST` | `/api/tools/:id/check` | `neurosploit tools check <id>`; body `{ "sandbox": true }` checks inside Kali. Never runs a scan. |
|
||||
| `POST` | `/api/tools/run` | Body `{ tool, target?, args?, sandbox?, provision?, timeout? }`. Returns `{ tool, command, code, timed_out, duration_ms, stdout, stderr }`. |
|
||||
| `POST` | `/api/tools/install` | Body `{ tool, sandbox? }`. Explicit provisioning (apt/pipx/go/cargo/npm/gem/docker). |
|
||||
| `GET` | `/api/mcp/servers` | Curated MCP server catalog plus `configured` flags and the local `mcp.servers.json` path. |
|
||||
| `POST` | `/api/mcp/servers` | Body `{ action: "add"\|"remove", server }`. Writes `./mcp.servers.json`, merged into `.mcp.json` on the next `--mcp` run. |
|
||||
| `POST` | `/api/mcp/servers/test` | Body `{ server }` — checks the executable on PATH, or the HTTP endpoint. |
|
||||
| `GET` | `/api/mcp/servers/:name` | JSON `mcpServers` snippet for that server. |
|
||||
|
||||
---
|
||||
|
||||
## C2 and WebShell management
|
||||
|
||||
Opt-in and disabled by default. Mutating calls fail closed until
|
||||
`POST /api/c2/enable` receives an authorization reference. State and the audit
|
||||
trail live under `.neurosploit/c2/`; the local daemon binds `127.0.0.1`.
|
||||
|
||||
| Method | Path | What |
|
||||
|---|---|---|
|
||||
| `GET` | `/api/c2/status` | `{ policy, listeners, sessions, tasks, webshells, events, payloads, counts }`. |
|
||||
| `POST` | `/api/c2/enable` | Body `{ authorization, persistence?, lateral?, allowPublic?, hosts? }`. Required to use C2. |
|
||||
| `POST` | `/api/c2/disable` | Stops every listener and disables the module. |
|
||||
| `PUT/POST` | `/api/c2/policy` | Update guardrails (`allow_persistence`, `allow_lateral`, `allow_public_targets`, `allowed_hosts`, …). |
|
||||
| `GET/POST` | `/api/c2/listeners` | List/create HTTP beacon listeners (loopback by default). |
|
||||
| `POST` | `/api/c2/listeners/:id/start` · `/stop` | Listener lifecycle. |
|
||||
| `DELETE` | `/api/c2/listeners/:id` | Delete listener + its sessions/tasks. |
|
||||
| `GET` | `/api/c2/sessions` | Sessions (`hostname, username, os, arch, internal_ip, status, sleep_seconds, note`). |
|
||||
| `POST` | `/api/c2/sessions/:id/sleep` | Body `{ seconds, jitter }`. |
|
||||
| `POST` | `/api/c2/sessions/:id/note` | Body `{ note }`. |
|
||||
| `DELETE` | `/api/c2/sessions/:id` | Mark killed and cancel queued tasks. |
|
||||
| `GET/POST` | `/api/c2/tasks` | List/enqueue tasks (`exec`, `persist`, `lateral`, `pwd`, `ls`, `cd`, `upload`, `download`, `sleep`, `exit`). |
|
||||
| `GET` | `/api/c2/tasks/:id` · `/wait?timeout=` | Task result. `wait` blocks up to the timeout. |
|
||||
| `POST` | `/api/c2/tasks/:id/cancel` | Cancel a queued task. |
|
||||
| `GET` | `/api/c2/events?limit=` | Recent audit events. |
|
||||
| `GET` | `/api/c2/payloads` | Generated payloads (metadata). |
|
||||
| `GET` | `/api/c2/payloads/:name` | Raw payload download (0600 on disk). |
|
||||
| `POST` | `/api/c2/payloads/webshell` | Body `{ shell_type, password?, pass_param?, cmd_param?, filename? }`. |
|
||||
| `POST` | `/api/c2/payloads/beacon` | Body `{ listener_id, kind: bash\|python\|powershell\|php, host?, filename? }`. |
|
||||
| `POST` | `/api/c2/payloads/oneliner` | Body `{ listener_id }`. |
|
||||
| `GET/POST` | `/api/webshell/connections` | Saved WebShell connections (passwords never returned). |
|
||||
| `PUT/DELETE` | `/api/webshell/connections/:id` | Update/delete a connection. |
|
||||
| `POST` | `/api/webshell/connections/:id/test` | OS probe + `whoami`. |
|
||||
| `POST` | `/api/webshell/connections/:id/exec` | Body `{ command }`. |
|
||||
| `POST` | `/api/webshell/connections/:id/file` | Body `{ action: list\|read\|write\|upload\|delete\|mkdir\|rename, path, content?, target_path? }`. |
|
||||
+698
-1
@@ -125,7 +125,7 @@ function clearFieldErrors() { $$('.field-error').forEach((el) => { el.textConten
|
||||
// view navigation
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const ALL_VIEWS = ['homeView','dashView','wizardView','liveView','detailView','pentestsView','prreviewsView','issuesView','reposView','domainsView','networksView','vaultView','guardrailsView','integrationsView','settingsView'];
|
||||
const ALL_VIEWS = ['homeView','dashView','wizardView','liveView','detailView','pentestsView','prreviewsView','issuesView','reposView','domainsView','networksView','vaultView','guardrailsView','integrationsView','settingsView','c2View','toolboxView'];
|
||||
|
||||
function switchView(viewName) {
|
||||
state.activeView = viewName;
|
||||
@@ -147,6 +147,8 @@ function switchView(viewName) {
|
||||
if (viewName === 'prreviews') loadPrReviews();
|
||||
if (viewName === 'vault') loadVault();
|
||||
if (viewName === 'guardrails') loadGuardrails();
|
||||
if (viewName === 'c2') loadC2();
|
||||
if (viewName === 'toolbox') loadToolbox();
|
||||
if (viewName === 'dash') renderDashboard();
|
||||
if (viewName === 'home') renderHome();
|
||||
}
|
||||
@@ -676,6 +678,7 @@ function renderReview() {
|
||||
{ k: 'Intercept', v: $('#fieldIntercept').value === 'off' ? 'direct' : $('#fieldIntercept').value },
|
||||
{ k: 'Sandbox', v: $('#fieldSandbox').value ? 'Kali container' : 'host' },
|
||||
{ k: 'PoC re-validation', v: $('#fieldRevalidatePoc').checked ? 'on' : 'off' },
|
||||
{ k: 'C2 / post-exploitation', v: $('#fieldC2')?.checked ? `on${$('#fieldC2Persistence')?.checked ? ' · persistence' : ''}${$('#fieldC2Lateral')?.checked ? ' · lateral' : ''}` : 'off' },
|
||||
{ k: 'TypeSafe', v: $('#fieldTypesafe') ? $('#fieldTypesafe').value : 'auto' },
|
||||
{ k: 'Compliance', v: (['fieldCompPci', 'fieldCompHipaa', 'fieldCompSoc2', 'fieldCompGdpr'].map((id) => $(`#${id}`).checked && $(`#${id}`).value).filter(Boolean).join(', ')) || 'none' },
|
||||
{ k: 'Autonomy', v: $('#fieldAutonomy')?.value || 'standard' },
|
||||
@@ -753,6 +756,10 @@ async function startExploitation() {
|
||||
reactive: $('#fieldReactive')?.checked || false,
|
||||
mcpProfile: $('#fieldMcpProfile')?.value || undefined,
|
||||
autonomy: $('#fieldAutonomy')?.value || 'standard',
|
||||
c2: !!$('#fieldC2')?.checked,
|
||||
c2Authorization: $('#fieldC2Auth')?.value.trim() || undefined,
|
||||
c2Persistence: !!$('#fieldC2Persistence')?.checked,
|
||||
c2Lateral: !!$('#fieldC2Lateral')?.checked,
|
||||
};
|
||||
|
||||
$('#btnLaunch').disabled = true;
|
||||
@@ -3122,6 +3129,696 @@ document.addEventListener('keydown', (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C2 & Shells — opt-in Command & Control and WebShell management
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const c2State = { data: null, tab: 'sessions', session: '', webshell: '', output: '', payload: null, timer: null };
|
||||
|
||||
function c2Time(ts) {
|
||||
if (!ts) return '—';
|
||||
try { return new Date(ts).toLocaleTimeString(); } catch { return String(ts); }
|
||||
}
|
||||
function c2Badge(on, onText, offText) {
|
||||
return `<span class="badge ${on ? 'badge-ok' : 'badge-muted'}">${esc(on ? onText : offText)}</span>`;
|
||||
}
|
||||
function c2SetOutput(value) {
|
||||
c2State.output = String(value || '');
|
||||
}
|
||||
|
||||
async function loadC2() {
|
||||
if (state.activeView !== 'c2') return;
|
||||
const body = $('#c2Body');
|
||||
try {
|
||||
const data = await api('/api/c2/status');
|
||||
c2State.data = data;
|
||||
const sessions = data.sessions || [];
|
||||
if (!c2State.session || !sessions.some((x) => x.id === c2State.session)) {
|
||||
const active = sessions.find((x) => x.status === 'active') || sessions[0];
|
||||
c2State.session = active ? active.id : '';
|
||||
}
|
||||
const shells = data.webshells || [];
|
||||
if (!c2State.webshell || !shells.some((x) => x.id === c2State.webshell)) {
|
||||
c2State.webshell = shells[0] ? shells[0].id : '';
|
||||
}
|
||||
renderC2();
|
||||
if (!c2State.timer) {
|
||||
c2State.timer = setInterval(() => {
|
||||
if (state.activeView === 'c2') loadC2();
|
||||
}, 5000);
|
||||
}
|
||||
} catch (e) {
|
||||
if (body) body.innerHTML = `<div class="empty-state">C2 unavailable — ${esc(e.message)}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderC2() {
|
||||
const body = $('#c2Body');
|
||||
if (!body) return;
|
||||
const d = c2State.data || {};
|
||||
const p = d.policy || {};
|
||||
if (!p.enabled) {
|
||||
body.innerHTML = `
|
||||
<div class="config-card" style="max-width:780px;margin:24px auto;">
|
||||
<div class="config-card-title">C2 & WebShells are disabled</div>
|
||||
<div class="config-card-desc">
|
||||
This layer is opt-in and auditable. It exists for <b>authorized internal-network engagements</b>:
|
||||
listeners bind loopback by default, WebShell targets must resolve to private/loopback space unless
|
||||
explicitly allow-listed, and persistence/lateral movement each need their own opt-in.
|
||||
State and the audit trail live under <code>.neurosploit/c2/</code>.
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="c2Auth">Authorization reference (required)</label>
|
||||
<input id="c2Auth" type="text" placeholder="SOW / ticket / bug-bounty URL" />
|
||||
<div class="field-help">Recorded in every audit entry. A run launched with C2 also passes this to the agents.</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Additional authorized hosts / domains (optional, comma-separated)</label>
|
||||
<input id="c2Hosts" type="text" placeholder="10.20.0.0/24 · *.corp.local" />
|
||||
<div class="field-help">Targets outside private address space require an entry here (or explicit allow-public, below).</div>
|
||||
</div>
|
||||
<div class="check-row"><input type="checkbox" id="c2Persist" /> <label for="c2Persist">Allow <b>persistence</b> tasks (cron/bashrc/systemd/schtasks/registry)</label></div>
|
||||
<div class="check-row"><input type="checkbox" id="c2Lateral" /> <label for="c2Lateral">Allow <b>lateral movement</b> and file uploads</label></div>
|
||||
<div class="check-row"><input type="checkbox" id="c2Public" /> <label for="c2Public">Allow public targets (explicit opt-in — only for authorized external assets)</label></div>
|
||||
<div class="config-card-actions">
|
||||
<button class="btn btn-accent" data-c2-action="enable">Enable C2</button>
|
||||
</div>
|
||||
<div class="field-error" id="c2EnableError"></div>
|
||||
</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
const counts = d.counts || {};
|
||||
const tabs = [['sessions','Sessions'],['listeners','Listeners'],['tasks','Tasks'],['webshells','WebShells'],['payloads','Payloads'],['events','Events']];
|
||||
body.innerHTML = `
|
||||
<div class="config-card" style="margin-bottom:16px;">
|
||||
<div class="config-card-title">
|
||||
C2 enabled ${c2Badge(true, 'ON', 'OFF')}
|
||||
${c2Badge(!!p.allow_persistence, 'persistence', 'no persistence')}
|
||||
${c2Badge(!!p.allow_lateral, 'lateral', 'no lateral')}
|
||||
${c2Badge(!!p.allow_public_targets, 'public targets', 'private-only')}
|
||||
<span class="config-card-meta" style="margin-left:auto;">auth: ${esc(p.authorized_by || '—')}</span>
|
||||
</div>
|
||||
<div class="config-card-desc" style="margin-bottom:8px;">
|
||||
${counts.sessions_active || 0} active / ${counts.sessions_total || 0} sessions ·
|
||||
${counts.listeners || 0} listeners · ${counts.tasks_queued || 0} queued tasks ·
|
||||
${counts.webshells || 0} WebShells.
|
||||
<span class="mono">allow-list: ${esc((p.allowed_hosts || []).join(', ') || '(private space only)')}</span>
|
||||
</div>
|
||||
<div class="config-card-actions" style="border-top:none;padding-top:0;margin-top:0;">
|
||||
<button class="btn btn-sm" data-c2-action="disable">Disable C2</button>
|
||||
<button class="btn btn-sm" data-c2-action="refresh">Refresh</button>
|
||||
</div>
|
||||
</div>
|
||||
<nav class="run-tabs" style="margin-bottom:12px;">
|
||||
${tabs.map(([id, label]) => `<button class="run-tab ${c2State.tab === id ? 'active' : ''}" data-c2-tab="${id}">${label}</button>`).join('')}
|
||||
</nav>
|
||||
<div id="c2Panel">${renderC2Panel(d, p)}</div>
|
||||
${c2State.output ? `<div class="config-card" style="margin-top:16px;"><div class="config-card-title">Output</div><pre class="c2-output">${esc(c2State.output)}</pre></div>` : ''}`;
|
||||
}
|
||||
|
||||
function renderC2Panel(d, p) {
|
||||
const tab = c2State.tab;
|
||||
if (tab === 'listeners') return renderC2Listeners(d);
|
||||
if (tab === 'tasks') return renderC2Tasks(d);
|
||||
if (tab === 'webshells') return renderC2Webshells(d);
|
||||
if (tab === 'payloads') return renderC2Payloads(d);
|
||||
if (tab === 'events') return renderC2Events(d);
|
||||
return renderC2Sessions(d);
|
||||
}
|
||||
|
||||
function renderC2Sessions(d) {
|
||||
const sessions = d.sessions || [];
|
||||
const sel = sessions.find((x) => x.id === c2State.session) || null;
|
||||
const rows = sessions.map((s) => `
|
||||
<tr class="${s.id === c2State.session ? 'c2-selected' : ''}" data-c2-session="${esc(s.id)}">
|
||||
<td class="mono">${esc(s.id)}</td>
|
||||
<td>${esc(s.hostname || '?')}</td>
|
||||
<td class="mono">${esc(s.username || '?')}${s.is_admin ? ' (admin)' : ''}</td>
|
||||
<td>${esc(s.os || '?')}/${esc(s.arch || '?')}</td>
|
||||
<td class="mono">${esc(s.internal_ip || '?')}</td>
|
||||
<td><span class="badge ${s.status === 'active' ? 'badge-ok' : 'badge-muted'}">${esc(s.status)}</span></td>
|
||||
<td class="mono">${esc(c2Time(s.last_seen))}</td>
|
||||
<td class="mono">${esc(s.sleep_seconds)}s</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" data-c2-action="session-sleep" data-id="${esc(s.id)}">sleep 10s</button>
|
||||
<button class="btn btn-sm" data-c2-action="session-note" data-id="${esc(s.id)}">note</button>
|
||||
<button class="btn btn-sm" data-c2-action="session-kill" data-id="${esc(s.id)}">kill</button>
|
||||
</td>
|
||||
</tr>`).join('');
|
||||
return `
|
||||
<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Session</th><th>Host</th><th>User</th><th>OS/arch</th><th>Internal IP</th><th>Status</th><th>Last seen</th><th>Sleep</th><th></th></tr></thead>
|
||||
<tbody>${rows || '<tr><td colspan="9" class="empty-state">No sessions yet — start a listener and deploy an authorized beacon.</td></tr>'}</tbody>
|
||||
</table></div>
|
||||
${sel ? `
|
||||
<div class="config-card" style="margin-top:16px;">
|
||||
<div class="config-card-title">Task console — ${esc(sel.hostname)} <span class="mono">${esc(sel.id)}</span></div>
|
||||
<div class="config-card-desc">${esc(sel.username)}@${esc(sel.hostname)} · ${esc(sel.os)}/${esc(sel.arch)} · ${esc(sel.internal_ip)} ${sel.note ? `· note: ${esc(sel.note)}` : ''}</div>
|
||||
<div class="field-row">
|
||||
<div class="field-group" style="flex:3;">
|
||||
<label class="field-label" for="c2Cmd">Command (exec / lateral movement)</label>
|
||||
<input id="c2Cmd" type="text" placeholder="id; hostname; net view /domain" />
|
||||
</div>
|
||||
<div class="field-group" style="flex:1;">
|
||||
<label class="field-label" for="c2PersistMethod">Persistence method</label>
|
||||
<select id="c2PersistMethod">
|
||||
<option value="auto">auto</option><option value="cron">cron</option><option value="bashrc">bashrc</option>
|
||||
<option value="systemd">systemd (user)</option><option value="schtasks">schtasks</option><option value="registry">registry Run key</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="config-card-actions">
|
||||
<button class="btn btn-accent" data-c2-action="task-exec">Run command</button>
|
||||
<button class="btn" data-c2-action="task-persist">Install persistence</button>
|
||||
<button class="btn" data-c2-action="task-lateral">Lateral movement</button>
|
||||
</div>
|
||||
<div class="field-help">Persistence and lateral tasks fail unless enabled in the policy. Every action is audited.</div>
|
||||
</div>` : ''}`;
|
||||
}
|
||||
|
||||
function renderC2Listeners(d) {
|
||||
const rows = (d.listeners || []).map((l) => `
|
||||
<tr>
|
||||
<td class="mono">${esc(l.id)}</td>
|
||||
<td>${esc(l.name)}</td>
|
||||
<td class="mono">${esc(l.bind_host)}:${esc(l.bind_port)}</td>
|
||||
<td class="mono">${esc(l.callback_host || '—')}</td>
|
||||
<td><span class="badge ${l.status === 'running' ? 'badge-ok' : 'badge-muted'}">${esc(l.status)}</span></td>
|
||||
<td class="mono">${esc(l.sleep_seconds)}s</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" data-c2-action="listener-start" data-id="${esc(l.id)}">start</button>
|
||||
<button class="btn btn-sm" data-c2-action="listener-stop" data-id="${esc(l.id)}">stop</button>
|
||||
<button class="btn btn-sm" data-c2-action="listener-delete" data-id="${esc(l.id)}">delete</button>
|
||||
</td>
|
||||
</tr>`).join('');
|
||||
return `
|
||||
<div class="config-card" style="margin-bottom:16px;">
|
||||
<div class="config-card-title">New HTTP beacon listener</div>
|
||||
<div class="field-row">
|
||||
<div class="field-group"><label class="field-label" for="c2ListenerName">Name</label><input id="c2ListenerName" placeholder="lab-beacon" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2ListenerHost">Bind host</label><input id="c2ListenerHost" value="127.0.0.1" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2ListenerPort">Port</label><input id="c2ListenerPort" type="number" value="8443" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2ListenerCb">Callback host</label><input id="c2ListenerCb" placeholder="defaults to bind host" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2ListenerSleep">Sleep (s)</label><input id="c2ListenerSleep" type="number" value="5" /></div>
|
||||
</div>
|
||||
<div class="config-card-actions"><button class="btn btn-accent" data-c2-action="listener-create">Create listener</button></div>
|
||||
<div class="field-help">Binds loopback by default. Use a private address for a lab; public bind addresses require explicit allow-public.</div>
|
||||
</div>
|
||||
<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Listener</th><th>Name</th><th>Bind</th><th>Callback</th><th>Status</th><th>Sleep</th><th></th></tr></thead>
|
||||
<tbody>${rows || '<tr><td colspan="7" class="empty-state">No listeners yet.</td></tr>'}</tbody>
|
||||
</table></div>`;
|
||||
}
|
||||
|
||||
function renderC2Tasks(d) {
|
||||
const rows = (d.tasks || []).slice().reverse().slice(0, 100).map((t) => `
|
||||
<tr>
|
||||
<td class="mono">${esc(t.id)}</td>
|
||||
<td class="mono">${esc(t.session_id)}</td>
|
||||
<td>${esc(t.task_type)}</td>
|
||||
<td><span class="badge ${t.status === 'success' ? 'badge-ok' : (t.status === 'failed' || t.status === 'cancelled' ? 'badge-muted' : 'badge-warn')}">${esc(t.status)}</span></td>
|
||||
<td class="mono">${esc(c2Time(t.created_at))}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" data-c2-action="task-get" data-id="${esc(t.id)}">output</button>
|
||||
<button class="btn btn-sm" data-c2-action="task-cancel" data-id="${esc(t.id)}">cancel</button>
|
||||
</td>
|
||||
</tr>`).join('');
|
||||
return `<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Task</th><th>Session</th><th>Type</th><th>Status</th><th>Created</th><th></th></tr></thead>
|
||||
<tbody>${rows || '<tr><td colspan="6" class="empty-state">No tasks yet.</td></tr>'}</tbody>
|
||||
</table></div>`;
|
||||
}
|
||||
|
||||
function renderC2Webshells(d) {
|
||||
const shells = d.webshells || [];
|
||||
const sel = shells.find((w) => w.id === c2State.webshell) || null;
|
||||
const rows = shells.map((w) => `
|
||||
<tr class="${w.id === c2State.webshell ? 'c2-selected' : ''}" data-c2-ws="${esc(w.id)}">
|
||||
<td class="mono">${esc(w.id)}</td>
|
||||
<td>${esc(w.name || '—')}</td>
|
||||
<td class="mono">${esc(w.url)}</td>
|
||||
<td>${esc(w.shell_type)}/${esc(w.method)}</td>
|
||||
<td>${esc(w.os || 'auto')}</td>
|
||||
<td class="mono">${esc(c2Time(w.last_seen))}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" data-c2-action="ws-test" data-id="${esc(w.id)}">test</button>
|
||||
<button class="btn btn-sm" data-c2-action="ws-delete" data-id="${esc(w.id)}">delete</button>
|
||||
</td>
|
||||
</tr>`).join('');
|
||||
return `
|
||||
<div class="config-card" style="margin-bottom:16px;">
|
||||
<div class="config-card-title">Add WebShell connection</div>
|
||||
<div class="field-row">
|
||||
<div class="field-group" style="flex:2;"><label class="field-label" for="c2WsUrl">URL</label><input id="c2WsUrl" placeholder="http://10.0.0.5/uploads/shell.php" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsName">Name</label><input id="c2WsName" placeholder="web01" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsPass">Password</label><input id="c2WsPass" type="password" placeholder="shell password" /></div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsType">Type</label>
|
||||
<select id="c2WsType"><option>php</option><option>aspx</option><option>asp</option><option>jsp</option><option>custom</option></select>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsMethod">Method</label>
|
||||
<select id="c2WsMethod"><option>POST</option><option>GET</option></select>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsOs">OS</label>
|
||||
<select id="c2WsOs"><option>auto</option><option>linux</option><option>windows</option></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="config-card-actions"><button class="btn btn-accent" data-c2-action="ws-add">Save connection</button></div>
|
||||
<div class="field-help">Only private/loopback or explicitly allow-listed hosts are accepted.</div>
|
||||
</div>
|
||||
<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Connection</th><th>Name</th><th>URL</th><th>Type</th><th>OS</th><th>Last seen</th><th></th></tr></thead>
|
||||
<tbody>${rows || '<tr><td colspan="7" class="empty-state">No WebShell connections yet.</td></tr>'}</tbody>
|
||||
</table></div>
|
||||
${sel ? `
|
||||
<div class="config-card" style="margin-top:16px;">
|
||||
<div class="config-card-title">WebShell console — ${esc(sel.name)} <span class="mono">${esc(sel.id)}</span></div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsCmd">Command</label><input id="c2WsCmd" placeholder="id; uname -a; dir C:\\" /></div>
|
||||
<div class="config-card-actions"><button class="btn btn-accent" data-c2-action="ws-exec">Execute</button></div>
|
||||
<div class="field-row" style="margin-top:10px;">
|
||||
<div class="field-group"><label class="field-label" for="c2WsFileAction">File action</label>
|
||||
<select id="c2WsFileAction"><option>list</option><option>read</option><option>write</option><option>delete</option><option>mkdir</option><option>rename</option></select>
|
||||
</div>
|
||||
<div class="field-group" style="flex:2;"><label class="field-label" for="c2WsPath">Path</label><input id="c2WsPath" placeholder="/tmp" /></div>
|
||||
<div class="field-group" style="flex:2;"><label class="field-label" for="c2WsTarget">Target path (rename)</label><input id="c2WsTarget" placeholder="/tmp/new-name" /></div>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label" for="c2WsContent">Content (write)</label><textarea id="c2WsContent" rows="3" placeholder="file content"></textarea></div>
|
||||
<div class="config-card-actions"><button class="btn" data-c2-action="ws-file">Run file action</button></div>
|
||||
</div>` : ''}`;
|
||||
}
|
||||
|
||||
function renderC2Payloads(d) {
|
||||
const listeners = d.listeners || [];
|
||||
const opts = listeners.map((l) => `<option value="${esc(l.id)}">${esc(l.name)} (${esc(l.bind_host)}:${esc(l.bind_port)})</option>`).join('');
|
||||
const plist = (d.payloads || []).slice().reverse().slice(0, 40).map((pl) => `
|
||||
<tr><td class="mono">${esc(pl.name)}</td><td>${esc(pl.kind)}</td><td class="mono">${esc(pl.size)}</td><td class="mono">${esc(c2Time(pl.created_at))}</td>
|
||||
<td><a class="btn btn-sm" href="/api/c2/payloads/${encodeURIComponent(pl.name)}">download</a></td></tr>`).join('');
|
||||
return `
|
||||
<div class="config-card" style="margin-bottom:16px;">
|
||||
<div class="config-card-title">Generate payload</div>
|
||||
<div class="field-row">
|
||||
<div class="field-group" style="flex:2;">
|
||||
<label class="field-label" for="c2PayloadListener">Listener</label>
|
||||
<select id="c2PayloadListener">${opts || '<option value="">create a listener first</option>'}</select>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label" for="c2PayloadKind">Beacon language</label>
|
||||
<select id="c2PayloadKind"><option>bash</option><option>python</option><option>powershell</option><option>php</option></select>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label" for="c2PayloadType">WebShell type</label>
|
||||
<select id="c2PayloadType"><option>php</option><option>aspx</option><option>asp</option><option>jsp</option></select>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label" for="c2PayloadPass">WebShell password</label>
|
||||
<input id="c2PayloadPass" placeholder="ns_pass" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="config-card-actions">
|
||||
<button class="btn btn-accent" data-c2-action="payload-beacon">Generate beacon</button>
|
||||
<button class="btn" data-c2-action="payload-webshell">Generate WebShell</button>
|
||||
<button class="btn" data-c2-action="payload-oneliner">One-liner</button>
|
||||
</div>
|
||||
<div class="field-help">Payloads are written to <code>.neurosploit/c2/payloads/</code> with 0600 permissions and recorded in the audit log.</div>
|
||||
</div>
|
||||
${c2State.payload ? `<div class="config-card" style="margin-bottom:16px;"><div class="config-card-title">${esc(c2State.payload.name || c2State.payload.kind)}</div>
|
||||
<div class="config-card-desc mono">${esc(c2State.payload.path || c2State.payload.callback || '')}</div>
|
||||
<textarea rows="12" class="c2-payload">${esc(c2State.payload.content || c2State.payload.oneliner || '')}</textarea>
|
||||
${c2State.payload.name ? `<div class="config-card-actions"><a class="btn btn-sm" href="/api/c2/payloads/${encodeURIComponent(c2State.payload.name)}">Download</a></div>` : ''}
|
||||
</div>` : ''}
|
||||
<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Name</th><th>Kind</th><th>Size</th><th>Created</th><th></th></tr></thead>
|
||||
<tbody>${plist || '<tr><td colspan="5" class="empty-state">No payloads generated yet.</td></tr>'}</tbody>
|
||||
</table></div>`;
|
||||
}
|
||||
|
||||
function renderC2Events(d) {
|
||||
const rows = (d.events || []).map((e) => `
|
||||
<tr><td class="mono">${esc(new Date(e.ts).toLocaleString())}</td><td>${esc(e.level)}</td><td>${esc(e.kind)}</td><td>${esc(e.message)}</td></tr>`).join('');
|
||||
return `<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Time</th><th>Level</th><th>Kind</th><th>Message</th></tr></thead>
|
||||
<tbody>${rows || '<tr><td colspan="4" class="empty-state">No events yet.</td></tr>'}</tbody>
|
||||
</table></div>`;
|
||||
}
|
||||
|
||||
async function c2Post(path, body) {
|
||||
const r = await api(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
|
||||
return r;
|
||||
}
|
||||
|
||||
document.addEventListener('click', async (ev) => {
|
||||
const tab = ev.target.closest('[data-c2-tab]');
|
||||
if (tab) { c2State.tab = tab.dataset.c2Tab; renderC2(); return; }
|
||||
const sess = ev.target.closest('[data-c2-session]');
|
||||
if (sess) { c2State.session = sess.dataset.c2Session; renderC2(); return; }
|
||||
const ws = ev.target.closest('[data-c2-ws]');
|
||||
if (ws) { c2State.webshell = ws.dataset.c2Ws; renderC2(); return; }
|
||||
const el = ev.target.closest('[data-c2-action]');
|
||||
if (!el || !el.closest('#c2Body')) return;
|
||||
const action = el.dataset.c2Action;
|
||||
const id = el.dataset.id || '';
|
||||
try {
|
||||
if (action === 'enable') {
|
||||
const auth = $('#c2Auth')?.value.trim();
|
||||
if (!auth) { fieldError('c2EnableError', 'an authorization reference is required'); return; }
|
||||
await c2Post('/api/c2/enable', {
|
||||
authorization: auth,
|
||||
hosts: $('#c2Hosts')?.value || '',
|
||||
persistence: !!$('#c2Persist')?.checked,
|
||||
lateral: !!$('#c2Lateral')?.checked,
|
||||
allowPublic: !!$('#c2Public')?.checked,
|
||||
});
|
||||
toast('C2 enabled — listeners still need to be started explicitly', 'info');
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'disable') { await c2Post('/api/c2/disable'); c2SetOutput(''); await loadC2(); return; }
|
||||
if (action === 'refresh') { await loadC2(); return; }
|
||||
if (action === 'listener-create') {
|
||||
await c2Post('/api/c2/listeners', {
|
||||
name: $('#c2ListenerName')?.value || 'listener',
|
||||
bind_host: $('#c2ListenerHost')?.value || '127.0.0.1',
|
||||
bind_port: Number($('#c2ListenerPort')?.value) || 8443,
|
||||
callback_host: $('#c2ListenerCb')?.value || '',
|
||||
sleep_seconds: Number($('#c2ListenerSleep')?.value) || 5,
|
||||
});
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'listener-start' || action === 'listener-stop' || action === 'listener-delete') {
|
||||
const path = action === 'listener-delete'
|
||||
? `/api/c2/listeners/${encodeURIComponent(id)}`
|
||||
: `/api/c2/listeners/${encodeURIComponent(id)}/${action === 'listener-start' ? 'start' : 'stop'}`;
|
||||
await api(path, { method: action === 'listener-delete' ? 'DELETE' : 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'session-sleep') {
|
||||
await c2Post(`/api/c2/sessions/${encodeURIComponent(id)}/sleep`, { seconds: 10, jitter: 10 });
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'session-note') {
|
||||
const note = window.prompt('Session note:');
|
||||
if (note === null) return;
|
||||
await c2Post(`/api/c2/sessions/${encodeURIComponent(id)}/note`, { note });
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'session-kill') {
|
||||
if (!window.confirm('Mark this session killed and cancel queued tasks?')) return;
|
||||
await api(`/api/c2/sessions/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'task-exec' || action === 'task-lateral') {
|
||||
if (!c2State.session) { toast('select a session first', 'error'); return; }
|
||||
const command = $('#c2Cmd')?.value.trim();
|
||||
if (!command) { toast('enter a command', 'error'); return; }
|
||||
const r = await c2Post('/api/c2/tasks', {
|
||||
session_id: c2State.session,
|
||||
task_type: action === 'task-lateral' ? 'lateral' : 'exec',
|
||||
payload: { command }, wait: true, timeout: 40,
|
||||
});
|
||||
c2SetOutput(r.task ? `${r.task.id} · ${r.task.status}\n${r.task.output || ''}\n${r.task.error || ''}` : JSON.stringify(r, null, 2));
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'task-persist') {
|
||||
if (!c2State.session) { toast('select a session first', 'error'); return; }
|
||||
const method = $('#c2PersistMethod')?.value || 'auto';
|
||||
const r = await c2Post('/api/c2/tasks', {
|
||||
session_id: c2State.session, task_type: 'persist', payload: { method }, wait: true, timeout: 60,
|
||||
});
|
||||
c2SetOutput(r.task ? `${r.task.id} · ${r.task.status}\n${r.task.output || ''}\n${r.task.error || ''}` : JSON.stringify(r, null, 2));
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'task-get') {
|
||||
const r = await api(`/api/c2/tasks/${encodeURIComponent(id)}`);
|
||||
c2SetOutput(r.task ? `${r.task.id} · ${r.task.status}\n${r.task.output || ''}\n${r.task.error || ''}` : JSON.stringify(r, null, 2));
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'task-cancel') {
|
||||
await c2Post(`/api/c2/tasks/${encodeURIComponent(id)}/cancel`, {});
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'ws-add') {
|
||||
await c2Post('/api/webshell/connections', {
|
||||
url: $('#c2WsUrl')?.value.trim(), name: $('#c2WsName')?.value.trim(),
|
||||
password: $('#c2WsPass')?.value || '', shell_type: $('#c2WsType')?.value || 'php',
|
||||
method: $('#c2WsMethod')?.value || 'POST', os: $('#c2WsOs')?.value || 'auto',
|
||||
});
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'ws-test') {
|
||||
const r = await c2Post(`/api/webshell/connections/${encodeURIComponent(id)}/test`, {});
|
||||
c2SetOutput(`ok=${r.ok} http=${r.http_status} os=${r.detected_os}\n${r.output || ''}`);
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'ws-exec') {
|
||||
if (!c2State.webshell) { toast('select a WebShell first', 'error'); return; }
|
||||
const command = $('#c2WsCmd')?.value.trim();
|
||||
if (!command) { toast('enter a command', 'error'); return; }
|
||||
const r = await c2Post(`/api/webshell/connections/${encodeURIComponent(c2State.webshell)}/exec`, { command });
|
||||
c2SetOutput(`http=${r.http_status} ok=${r.ok}\n${r.output || ''}`);
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'ws-file') {
|
||||
if (!c2State.webshell) { toast('select a WebShell first', 'error'); return; }
|
||||
const r = await c2Post(`/api/webshell/connections/${encodeURIComponent(c2State.webshell)}/file`, {
|
||||
action: $('#c2WsFileAction')?.value || 'list',
|
||||
path: $('#c2WsPath')?.value || '.',
|
||||
target_path: $('#c2WsTarget')?.value || '',
|
||||
content: $('#c2WsContent')?.value || '',
|
||||
});
|
||||
c2SetOutput(`http=${r.http_status} ok=${r.ok}\n${r.output || ''}`);
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'ws-delete') {
|
||||
if (!window.confirm('Delete this saved WebShell connection?')) return;
|
||||
await api(`/api/webshell/connections/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'payload-beacon' || action === 'payload-oneliner') {
|
||||
const listener = $('#c2PayloadListener')?.value;
|
||||
if (!listener) { toast('create and select a listener first', 'error'); return; }
|
||||
const body = action === 'payload-oneliner'
|
||||
? { listener_id: listener }
|
||||
: { listener_id: listener, kind: $('#c2PayloadKind')?.value || 'bash' };
|
||||
const r = await c2Post(action === 'payload-oneliner' ? '/api/c2/payloads/oneliner' : '/api/c2/payloads/beacon', body);
|
||||
c2State.payload = r;
|
||||
c2SetOutput('');
|
||||
await loadC2(); return;
|
||||
}
|
||||
if (action === 'payload-webshell') {
|
||||
const r = await c2Post('/api/c2/payloads/webshell', {
|
||||
shell_type: $('#c2PayloadType')?.value || 'php',
|
||||
password: $('#c2PayloadPass')?.value || '',
|
||||
});
|
||||
c2State.payload = r;
|
||||
c2SetOutput('');
|
||||
await loadC2(); return;
|
||||
}
|
||||
} catch (e) {
|
||||
toast(e.message, 'error', 9000);
|
||||
}
|
||||
});
|
||||
|
||||
$('#btnC2Refresh')?.addEventListener('click', () => loadC2());
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Toolbox — 200+ real tools + MCP tool servers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const toolboxState = { catalog: [], mcp: null, check: {}, selected: '', output: '', profiles: null, filter: '', category: '' };
|
||||
|
||||
async function loadToolbox() {
|
||||
if (state.activeView !== 'toolbox') return;
|
||||
const body = $('#toolboxBody');
|
||||
try {
|
||||
const [catalog, mcp] = await Promise.all([
|
||||
api('/api/tools'),
|
||||
api('/api/mcp/servers').catch(() => ({ servers: [], config: '' })),
|
||||
]);
|
||||
toolboxState.catalog = catalog || [];
|
||||
toolboxState.mcp = mcp || {};
|
||||
renderToolbox();
|
||||
} catch (e) {
|
||||
if (body) body.innerHTML = `<div class="empty-state">Toolbox unavailable — ${esc(e.message)}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
function toolboxCategories() {
|
||||
const counts = {};
|
||||
for (const t of toolboxState.catalog) counts[t.category] = (counts[t.category] || 0) + 1;
|
||||
return Object.entries(counts).sort((a, b) => a[0].localeCompare(b[0]));
|
||||
}
|
||||
|
||||
function toolboxFiltered() {
|
||||
let items = toolboxState.catalog;
|
||||
if (toolboxState.category) items = items.filter((t) => t.category === toolboxState.category);
|
||||
const q = toolboxState.filter.trim().toLowerCase();
|
||||
if (q) {
|
||||
items = items.filter((t) => [t.id, t.name, t.binary, t.category, t.description, ...(t.tags || [])]
|
||||
.join(' ').toLowerCase().includes(q));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
function renderToolbox() {
|
||||
const body = $('#toolboxBody');
|
||||
if (!body) return;
|
||||
const cats = toolboxCategories();
|
||||
const items = toolboxFiltered();
|
||||
const mcp = toolboxState.mcp || {};
|
||||
const servers = mcp.servers || [];
|
||||
const selected = toolboxState.catalog.find((t) => t.id === toolboxState.selected) || null;
|
||||
const rows = items.slice(0, 400).map((t) => {
|
||||
const chk = toolboxState.check[t.id];
|
||||
const status = chk
|
||||
? (chk.installed ? `<span class="badge badge-ok">installed</span>` : `<span class="badge badge-muted">missing</span>`)
|
||||
: '';
|
||||
return `<tr class="${t.id === toolboxState.selected ? 'c2-selected' : ''}">
|
||||
<td class="mono">${esc(t.id)}</td>
|
||||
<td>${esc(t.category)}</td>
|
||||
<td class="mono">${esc(t.binary)}</td>
|
||||
<td>${esc(t.description)} ${status}</td>
|
||||
<td class="mono">${chk && chk.version ? esc(chk.version.slice(0, 60)) : ''}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" data-tool-action="select" data-id="${esc(t.id)}">run</button>
|
||||
<button class="btn btn-sm" data-tool-action="check" data-id="${esc(t.id)}">check</button>
|
||||
${chk && !chk.installed ? `<button class="btn btn-sm" data-tool-action="install" data-id="${esc(t.id)}">install</button>` : ''}
|
||||
</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
|
||||
body.innerHTML = `
|
||||
<div class="config-card" style="margin-bottom:16px;">
|
||||
<div class="config-card-title">${toolboxState.catalog.length} real tools across ${cats.length} categories</div>
|
||||
<div class="config-card-desc">Run them directly here, or let agents use the same catalog with <code>--tools</code> / <code>--agent-tools</code>. Scope, operator constraints and timeouts are enforced by the CLI runner.</div>
|
||||
<div class="field-row">
|
||||
<div class="field-group" style="flex:2;">
|
||||
<label class="field-label" for="toolboxSearch">Search</label>
|
||||
<input id="toolboxSearch" placeholder="nmap, kerberos, sqli, cloud…" value="${esc(toolboxState.filter)}" />
|
||||
</div>
|
||||
<div class="field-group">
|
||||
<label class="field-label" for="toolboxCategory">Category</label>
|
||||
<select id="toolboxCategory">
|
||||
<option value="">all (${toolboxState.catalog.length})</option>
|
||||
${cats.map(([c, n]) => `<option value="${esc(c)}" ${toolboxState.category === c ? 'selected' : ''}>${esc(c)} (${n})</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<div class="field-group" style="flex:0;min-width:auto;">
|
||||
<label class="field-label"> </label>
|
||||
<button class="btn" data-tool-action="profiles">Recommended by mode</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
${selected ? `
|
||||
<div class="config-card" style="margin-bottom:16px;">
|
||||
<div class="config-card-title">Run ${esc(selected.name)} <span class="mono">${esc(selected.id)}</span></div>
|
||||
<div class="config-card-desc mono">${esc(selected.usage)}</div>
|
||||
<div class="field-row">
|
||||
<div class="field-group" style="flex:2;"><label class="field-label" for="toolboxTarget">Target</label><input id="toolboxTarget" placeholder="10.0.0.5 or https://app" /></div>
|
||||
<div class="field-group" style="flex:3;"><label class="field-label" for="toolboxArgs">Args (optional)</label><input id="toolboxArgs" placeholder="-sV -p 22,80,443" /></div>
|
||||
<div class="field-group" style="flex:0;min-width:auto;"><label class="field-label" for="toolboxTimeout">Timeout (s)</label><input id="toolboxTimeout" type="number" value="300" style="width:90px;" /></div>
|
||||
</div>
|
||||
<div class="check-row"><input type="checkbox" id="toolboxSandbox" /> <label for="toolboxSandbox">Run in Kali sandbox</label></div>
|
||||
<div class="check-row"><input type="checkbox" id="toolboxProvision" /> <label for="toolboxProvision">Allow install if missing (explicit)</label></div>
|
||||
<div class="config-card-actions">
|
||||
<button class="btn btn-accent" data-tool-action="run">Run tool</button>
|
||||
<button class="btn" data-tool-action="check" data-id="${esc(selected.id)}">Check install</button>
|
||||
</div>
|
||||
<div class="field-help">${selected.intrusive ? '<b>Intrusive:</b> actively probes the target. ' : ''}${selected.requires_root ? 'May require root/CAP_NET_RAW. ' : ''}Stay within the authorized scope.</div>
|
||||
</div>` : ''}
|
||||
|
||||
${toolboxState.output ? `<div class="config-card" style="margin-bottom:16px;"><div class="config-card-title">Last tool output</div><pre class="c2-output">${esc(toolboxState.output)}</pre></div>` : ''}
|
||||
${toolboxState.profiles ? `<div class="config-card" style="margin-bottom:16px;"><div class="config-card-title">Recommended toolchains</div><pre class="c2-output">${esc(toolboxState.profiles)}</pre></div>` : ''}
|
||||
|
||||
<div class="table-wrap" style="margin-bottom:20px;"><table class="data-table">
|
||||
<thead><tr><th>ID</th><th>Category</th><th>Binary</th><th>Description</th><th>Version</th><th></th></tr></thead>
|
||||
<tbody>${rows || '<tr><td colspan="6" class="empty-state">No tools match.</td></tr>'}</tbody>
|
||||
</table></div>
|
||||
|
||||
<div class="config-card">
|
||||
<div class="config-card-title">MCP tool servers <span class="config-card-meta">${esc(mcp.config || '')}</span></div>
|
||||
<div class="config-card-desc">Add a curated server to <code>mcp.servers.json</code>; the next <code>--mcp</code> run merges it into the agent's tool list.</div>
|
||||
<div class="table-wrap"><table class="data-table">
|
||||
<thead><tr><th>Server</th><th>Transport</th><th>Description</th><th>Status</th><th></th></tr></thead>
|
||||
<tbody>${servers.map((s) => `
|
||||
<tr>
|
||||
<td class="mono">${esc(s.name)}</td>
|
||||
<td>${esc(s.transport)}</td>
|
||||
<td>${esc(s.description)}</td>
|
||||
<td>${s.configured ? '<span class="badge badge-ok">configured</span>' : '<span class="badge badge-muted">not configured</span>'}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" data-tool-action="mcp-add" data-id="${esc(s.name)}">add</button>
|
||||
<button class="btn btn-sm" data-tool-action="mcp-test" data-id="${esc(s.name)}">test</button>
|
||||
<button class="btn btn-sm" data-tool-action="mcp-remove" data-id="${esc(s.name)}">remove</button>
|
||||
</td>
|
||||
</tr>`).join('') || '<tr><td colspan="5" class="empty-state">No MCP servers available.</td></tr>'}
|
||||
</tbody>
|
||||
</table></div>
|
||||
<div class="field-help">nmap MCP uses <code>npx gc-nmap-mcp</code>; Kali uses the <code>kali-mcp</code> entrypoint (pipx/Docker). Configure credentials/URLs in <code>mcp.servers.json</code>.</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
async function toolboxCheck(id) {
|
||||
const r = await api(`/api/tools/${encodeURIComponent(id)}/check`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sandbox: !!$('#toolboxSandbox')?.checked }) });
|
||||
const check = Array.isArray(r) ? r[0] : r;
|
||||
if (check) toolboxState.check[id] = check;
|
||||
renderToolbox();
|
||||
}
|
||||
|
||||
document.addEventListener('click', async (ev) => {
|
||||
const el = ev.target.closest('[data-tool-action]');
|
||||
if (!el || !el.closest('#toolboxBody')) return;
|
||||
const action = el.dataset.toolAction;
|
||||
const id = el.dataset.id || '';
|
||||
try {
|
||||
if (action === 'select') { toolboxState.selected = id; renderToolbox(); return; }
|
||||
if (action === 'check') { await toolboxCheck(id); return; }
|
||||
if (action === 'install') {
|
||||
if (!window.confirm(`Install ${id}? This runs the catalog installer (apt/pipx/go/...) with your permission.`)) return;
|
||||
const r = await api('/api/tools/install', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tool: id, sandbox: !!$('#toolboxSandbox')?.checked }) });
|
||||
toolboxState.output = JSON.stringify(r, null, 2);
|
||||
await toolboxCheck(id);
|
||||
return;
|
||||
}
|
||||
if (action === 'run') {
|
||||
if (!toolboxState.selected) return;
|
||||
const target = $('#toolboxTarget')?.value.trim() || '';
|
||||
const args = $('#toolboxArgs')?.value.trim() || '';
|
||||
const r = await api('/api/tools/run', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
tool: toolboxState.selected, target, args,
|
||||
sandbox: !!$('#toolboxSandbox')?.checked,
|
||||
provision: !!$('#toolboxProvision')?.checked,
|
||||
timeout: Number($('#toolboxTimeout')?.value) || 300,
|
||||
}),
|
||||
});
|
||||
toolboxState.output = `$ ${r.command}\n${r.timed_out ? '[TIMED OUT]\n' : ''}${r.stdout || ''}${r.stderr ? `\n--- stderr ---\n${r.stderr}` : ''}`;
|
||||
renderToolbox();
|
||||
return;
|
||||
}
|
||||
if (action === 'profiles') {
|
||||
const r = await api('/api/tools/profiles');
|
||||
toolboxState.profiles = (r || []).map((p) => `${p.mode.padEnd(10)} ${(p.tools || []).join(', ')}`).join('\n');
|
||||
renderToolbox();
|
||||
return;
|
||||
}
|
||||
if (action === 'mcp-add' || action === 'mcp-remove') {
|
||||
const r = await api('/api/mcp/servers', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action: action === 'mcp-add' ? 'add' : 'remove', server: id }) });
|
||||
toolboxState.mcp = r;
|
||||
renderToolbox();
|
||||
return;
|
||||
}
|
||||
if (action === 'mcp-test') {
|
||||
const r = await api('/api/mcp/servers/test', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ server: id }) });
|
||||
toast(`${id}: ${r.ok ? 'OK' : 'not ready'} — ${r.detail || ''}`, r.ok ? 'info' : 'error', 8000);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
toast(e.message, 'error', 9000);
|
||||
}
|
||||
});
|
||||
|
||||
$('#btnToolboxRefresh')?.addEventListener('click', () => loadToolbox());
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// boot
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -51,6 +51,8 @@
|
||||
<button class="sb-nav-item" data-view="vault"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="8" cy="15" r="3.8"/><path d="m10.7 12.3 8.8-8.8M16 7l3 3M13.5 9.5l2 2"/></svg></span> Vault</button>
|
||||
<button class="sb-nav-item" data-view="guardrails"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 3.2 19.5 6v5.6c0 4.4-3.1 7.5-7.5 9.2-4.4-1.7-7.5-4.8-7.5-9.2V6z"/><path d="m9 12 2.2 2.2L15.2 10"/></svg></span> Guardrails</button>
|
||||
<div class="sb-nav-separator"></div>
|
||||
<button class="sb-nav-item" data-view="c2"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 5h16v11H4z"/><path d="M8 20h8M12 16v4"/><path d="m7 9 2.5 2L7 13M12 13h4"/></svg></span> C2 & Shells</button>
|
||||
<button class="sb-nav-item" data-view="toolbox"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 7h16M4 12h16M4 17h16"/><circle cx="7" cy="7" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="17" cy="17" r="1"/></svg></span> Toolbox</button>
|
||||
<button class="sb-nav-item" id="sbTerminal"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m5 7 5 5-5 5M12.5 18H19"/></svg></span> Terminal</button>
|
||||
<button class="sb-nav-item" data-view="integrations"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 3v5M15 3v5M6.5 8h11v3.5a5.5 5.5 0 0 1-11 0zM12 17v4"/></svg></span> Integrations</button>
|
||||
<button class="sb-nav-item" data-view="settings"><span class="sb-nav-icon"><svg class="ico" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 7h9M17 7h3M4 12h3M11 12h9M4 17h11M19 17h1"/><circle cx="15" cy="7" r="2"/><circle cx="9" cy="12" r="2"/><circle cx="17" cy="17" r="2"/></svg></span> Settings</button>
|
||||
@@ -262,6 +264,32 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- ============ TOOLBOX ============ -->
|
||||
<section class="page-view" id="toolboxView" hidden>
|
||||
<header class="topbar">
|
||||
<div>
|
||||
<div class="topbar-title">Toolbox</div>
|
||||
<div class="topbar-sub">200+ real pentest tools (web, infra, Active Directory, cloud, container, mobile, binary, forensics, AI) and MCP tool servers</div>
|
||||
</div>
|
||||
<div class="topbar-spacer"></div>
|
||||
<button class="btn btn-sm" id="btnToolboxRefresh">Refresh</button>
|
||||
</header>
|
||||
<div class="page-body" id="toolboxBody"><div class="empty-state">Loading…</div></div>
|
||||
</section>
|
||||
|
||||
<!-- ============ C2 & SHELLS ============ -->
|
||||
<section class="page-view" id="c2View" hidden>
|
||||
<header class="topbar">
|
||||
<div>
|
||||
<div class="topbar-title">C2 & Shells</div>
|
||||
<div class="topbar-sub">Command & Control and WebShell management for authorized internal engagements — opt-in, private-scope first, fully audited</div>
|
||||
</div>
|
||||
<div class="topbar-spacer"></div>
|
||||
<button class="btn btn-sm" id="btnC2Refresh">Refresh</button>
|
||||
</header>
|
||||
<div class="page-body" id="c2Body"><div class="empty-state">Loading…</div></div>
|
||||
</section>
|
||||
|
||||
<!-- ============ GUARDRAILS ============ -->
|
||||
<section class="page-view" id="guardrailsView" hidden>
|
||||
<header class="topbar">
|
||||
@@ -672,6 +700,14 @@
|
||||
</select>
|
||||
<div class="field-help">Runs attack commands off the host, with the Kali toolbox. Needs docker or podman.</div>
|
||||
</div>
|
||||
<div class="field-group">
|
||||
<label class="field-label">C2 / post-exploitation</label>
|
||||
<div class="check-row"><input type="checkbox" id="fieldC2" /> <label for="fieldC2"><b>Enable C2</b> for this internal engagement</label></div>
|
||||
<input id="fieldC2Auth" type="text" placeholder="Authorization reference (SOW / ticket / bug-bounty URL)" />
|
||||
<div class="check-row"><input type="checkbox" id="fieldC2Persistence" /> <label for="fieldC2Persistence">Allow persistence tasks</label></div>
|
||||
<div class="check-row"><input type="checkbox" id="fieldC2Lateral" /> <label for="fieldC2Lateral">Allow lateral movement & uploads</label></div>
|
||||
<div class="field-help">Opt-in. Listeners bind loopback by default; WebShell targets must resolve to private space unless allow-listed. Persistence and lateral movement are separate explicit opt-ins. All actions are audited under <code>.neurosploit/c2/</code>.</div>
|
||||
</div>
|
||||
<div class="field-group"><label class="field-label">PoC re-validation</label>
|
||||
<div class="check-row"><input type="checkbox" id="fieldRevalidatePoc" /> <label for="fieldRevalidatePoc">Re-run every PoC; demote what no longer reproduces</label></div>
|
||||
</div>
|
||||
|
||||
@@ -1544,3 +1544,35 @@ input[type="number"] { font-variant-numeric: tabular-nums; }
|
||||
|
||||
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: inherit; text-decoration: underline; }
|
||||
.btn-link:hover { opacity: 0.8; }
|
||||
|
||||
/* ============================================================ C2 & Shells */
|
||||
#c2View .run-tabs { margin-bottom: var(--sp-3); }
|
||||
#c2View .run-tab { cursor: pointer; }
|
||||
.c2-selected td { background: var(--surface-2, rgba(127,127,127,.08)); }
|
||||
.c2-output {
|
||||
margin: 0;
|
||||
padding: var(--sp-3);
|
||||
max-height: 360px;
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-family: var(--mono);
|
||||
font-size: var(--fs-xs);
|
||||
background: var(--surface-2, rgba(127,127,127,.06));
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
.c2-payload {
|
||||
width: 100%;
|
||||
min-height: 180px;
|
||||
font-family: var(--mono);
|
||||
font-size: var(--fs-xs);
|
||||
background: var(--surface-2, rgba(127,127,127,.06));
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: var(--sp-3);
|
||||
}
|
||||
#c2View .badge { display: inline-block; font-size: var(--fs-xs); font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
|
||||
#c2View .badge-ok { color: var(--sev-low-fg, #1a7f37); border-color: var(--sev-low-fg, #1a7f37); background: var(--sev-low-bg, rgba(26,127,55,.08)); }
|
||||
#c2View .badge-warn { color: var(--sev-medium-fg, #9a6700); border-color: var(--sev-medium-fg, #9a6700); background: var(--sev-medium-bg, rgba(154,103,0,.08)); }
|
||||
#c2View .badge-muted { color: var(--text-faint); }
|
||||
+343
@@ -122,6 +122,67 @@ const VERSION = binaryVersion();
|
||||
|
||||
const PORT = Number(process.env.NEUROSPLOIT_WEB_PORT || process.env.PORT || 4173);
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Toolbox / MCP tool servers — thin proxy over `neurosploit tools`.
|
||||
// The tool catalog and runner live in the harness; the console only drives it.
|
||||
// Nothing is executed unless the operator clicks Run (and target scope is
|
||||
// enforced by the CLI).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function toolsCall(args) {
|
||||
const out = await runCli(['tools', ...args, '--json']);
|
||||
const text = stripAnsi(out.buf || '').trim();
|
||||
if (out.code !== 0) {
|
||||
let msg = text || 'tool command failed';
|
||||
try { const v = JSON.parse(text); msg = v.error || msg; } catch { /* keep text */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
try { return JSON.parse(text); }
|
||||
catch {
|
||||
const m = text.match(/\{[\s\S]*\}\s*$/);
|
||||
if (m) { try { return JSON.parse(m[0]); } catch { /* fall through */ } }
|
||||
throw new Error(text || 'tool command returned no JSON');
|
||||
}
|
||||
}
|
||||
|
||||
async function toolsText(args) {
|
||||
const out = await runCli(['tools', ...args]);
|
||||
if (out.code !== 0) throw new Error(stripAnsi(out.buf || '').trim() || 'tool command failed');
|
||||
return stripAnsi(out.buf || '').trim();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// C2 / WebShell — thin proxy over the local C2 daemon (spawned by the CLI).
|
||||
// The daemon owns listener sockets, sessions, tasks and the audit trail; the
|
||||
// console never re-implements them. Disabled by default: every mutating call
|
||||
// fails closed until the operator enables it with an authorization reference.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function c2Call(args) {
|
||||
const prefix = args[0] === 'webshell' ? [] : ['c2'];
|
||||
const out = await runCli([...prefix, ...args, '--json']);
|
||||
const text = stripAnsi(out.buf || '').trim();
|
||||
if (out.code !== 0) {
|
||||
let msg = text || 'C2 command failed';
|
||||
try { const v = JSON.parse(text); msg = v.error || msg; } catch { /* keep text */ }
|
||||
throw new Error(msg);
|
||||
}
|
||||
try { return JSON.parse(text); }
|
||||
catch {
|
||||
const m = text.match(/\{[\s\S]*\}\s*$/);
|
||||
if (m) { try { return JSON.parse(m[0]); } catch { /* fall through */ } }
|
||||
throw new Error(text || 'C2 returned no JSON');
|
||||
}
|
||||
}
|
||||
|
||||
/// Values that become argv entries; the daemon re-validates everything.
|
||||
function c2PushStr(args, flag, value) {
|
||||
if (value !== undefined && value !== null && String(value).length) args.push(flag, String(value));
|
||||
}
|
||||
function c2PushBool(args, flag, on) { if (on) args.push(flag); }
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Providers — mirrors crates/harness/src/models.rs `providers()`. Kept as a
|
||||
// literal table (not parsed from CLI output) so `kind` ("cli" = usable via a
|
||||
@@ -1299,6 +1360,13 @@ function buildArgs(body) {
|
||||
if (body.reactive) args.push('--reactive');
|
||||
if (body.mcpProfile) args.push('--mcp-profile', body.mcpProfile);
|
||||
if (body.autonomy && body.autonomy !== 'standard') args.push('--autonomy', body.autonomy);
|
||||
// C2 is opt-in: without an authorization reference the CLI refuses to run it.
|
||||
if (body.c2) {
|
||||
if (body.c2Authorization) args.push('--c2-authorization', body.c2Authorization);
|
||||
if (body.c2Persistence) args.push('--c2-persistence');
|
||||
if (body.c2Lateral) args.push('--c2-lateral');
|
||||
args.push('--c2');
|
||||
}
|
||||
args.push('--verbose');
|
||||
return args;
|
||||
}
|
||||
@@ -1374,6 +1442,13 @@ function authArgs(body) {
|
||||
if (body.decisionBackend) args.push('--decision-backend', body.decisionBackend);
|
||||
if (body.intercept && body.intercept !== 'off') args.push('--intercept', body.intercept);
|
||||
if (body.sandbox) args.push('--sandbox', body.sandbox === 'default' ? '' : body.sandbox);
|
||||
// C2 is global (launcher-level), like the authorization ceiling.
|
||||
if (body.c2) {
|
||||
if (body.c2Authorization) args.push('--c2-authorization', body.c2Authorization);
|
||||
if (body.c2Persistence) args.push('--c2-persistence');
|
||||
if (body.c2Lateral) args.push('--c2-lateral');
|
||||
args.push('--c2');
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -1401,6 +1476,10 @@ function sanitizeLaunch(body) {
|
||||
quick: !!body.quick,
|
||||
research: !!body.research,
|
||||
maxAgents: body.maxAgents || undefined,
|
||||
c2: !!body.c2,
|
||||
c2Authorization: body.c2Authorization || undefined,
|
||||
c2Persistence: !!body.c2Persistence,
|
||||
c2Lateral: !!body.c2Lateral,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2156,6 +2235,270 @@ const server = http.createServer(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---- Toolbox / MCP tool servers ---------------------------------------
|
||||
if (p.startsWith('/api/tools') || p.startsWith('/api/mcp')) {
|
||||
try {
|
||||
if (req.method === 'GET' && p === '/api/tools') {
|
||||
const q = u.searchParams.get('q');
|
||||
const cat = u.searchParams.get('category');
|
||||
const args = q ? ['search', q] : ['list'];
|
||||
if (cat) args.push('--category', cat);
|
||||
return sendJson(res, 200, await toolsCall(args));
|
||||
}
|
||||
if (req.method === 'GET' && p === '/api/tools/profiles') {
|
||||
return sendJson(res, 200, await toolsCall(['profiles']));
|
||||
}
|
||||
let tm = p.match(/^\/api\/tools\/([\w.-]+)\/check$/);
|
||||
if ((req.method === 'GET' || req.method === 'POST') && tm) {
|
||||
const args = ['check', tm[1]];
|
||||
const body = req.method === 'POST' ? await readBody(req).catch(() => ({})) : {};
|
||||
if (body.sandbox || u.searchParams.get('sandbox') === '1') args.push('--sandbox');
|
||||
return sendJson(res, 200, await toolsCall(args));
|
||||
}
|
||||
tm = p.match(/^\/api\/tools\/([\w.-]+)$/);
|
||||
if (req.method === 'GET' && tm) {
|
||||
return sendJson(res, 200, await toolsCall(['info', tm[1]]));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/tools/run') {
|
||||
const b = await readBody(req);
|
||||
const args = ['run', String(b.tool || '')];
|
||||
c2PushStr(args, '--target', b.target);
|
||||
c2PushStr(args, '--args', b.args);
|
||||
if (b.sandbox) args.push('--sandbox');
|
||||
if (b.provision) args.push('--provision');
|
||||
if (b.timeout) args.push('--timeout', String(Number(b.timeout) || 300));
|
||||
return sendJson(res, 200, await toolsCall(args));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/tools/install') {
|
||||
const b = await readBody(req);
|
||||
const args = ['install', String(b.tool || '')];
|
||||
if (b.sandbox) args.push('--sandbox');
|
||||
return sendJson(res, 200, await toolsCall(args));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/mcp/servers') {
|
||||
return sendJson(res, 200, await toolsCall(['mcp', 'list']));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/mcp/servers') {
|
||||
const b = await readBody(req);
|
||||
const action = String(b.action || 'add');
|
||||
if (!['add', 'remove'].includes(action)) return sendJson(res, 400, { error: 'action must be add or remove' });
|
||||
const out = await toolsText(['mcp', action, String(b.server || '')]);
|
||||
return sendJson(res, 200, { ok: true, output: out, ...(await toolsCall(['mcp', 'list'])) });
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/mcp/servers/test') {
|
||||
const b = await readBody(req);
|
||||
return sendJson(res, 200, await toolsCall(['mcp', 'test', String(b.server || '')]));
|
||||
}
|
||||
tm = p.match(/^\/api\/mcp\/servers\/([\w.-]+)$/);
|
||||
if (req.method === 'GET' && tm) {
|
||||
return sendJson(res, 200, await toolsCall(['mcp', 'json', tm[1]]));
|
||||
}
|
||||
return sendJson(res, 404, { error: 'not found' });
|
||||
} catch (e) {
|
||||
return sendJson(res, 400, { error: e.message });
|
||||
}
|
||||
}
|
||||
|
||||
// ---- C2 / WebShell management ------------------------------------------
|
||||
if (p.startsWith('/api/c2') || p.startsWith('/api/webshell')) {
|
||||
try {
|
||||
if (req.method === 'GET' && p === '/api/c2/status') {
|
||||
return sendJson(res, 200, await c2Call(['status']));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/enable') {
|
||||
const b = await readBody(req);
|
||||
if (!b.authorization || !String(b.authorization).trim()) {
|
||||
return sendJson(res, 400, { error: 'authorization reference is required to enable C2' });
|
||||
}
|
||||
const args = ['enable', '--authorization', String(b.authorization).trim()];
|
||||
c2PushBool(args, '--persistence', b.persistence);
|
||||
c2PushBool(args, '--lateral', b.lateral);
|
||||
c2PushBool(args, '--allow-public', b.allowPublic || b.allow_public);
|
||||
for (const h of String(b.hosts || '').split(/[,;\s]+/).filter(Boolean)) args.push('--host', h);
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/disable') {
|
||||
return sendJson(res, 200, await c2Call(['disable']));
|
||||
}
|
||||
if ((req.method === 'PUT' || req.method === 'POST') && p === '/api/c2/policy') {
|
||||
const b = await readBody(req);
|
||||
const args = ['policy'];
|
||||
c2PushStr(args, '--authorized-by', b.authorized_by);
|
||||
if (typeof b.allow_persistence === 'boolean') args.push('--persistence', String(b.allow_persistence));
|
||||
if (typeof b.allow_lateral === 'boolean') args.push('--lateral', String(b.allow_lateral));
|
||||
if (typeof b.allow_public_targets === 'boolean') args.push('--allow-public', String(b.allow_public_targets));
|
||||
if (Array.isArray(b.allowed_hosts) && b.allowed_hosts.length) {
|
||||
for (const h of b.allowed_hosts) args.push('--host', String(h));
|
||||
}
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/c2/listeners') {
|
||||
return sendJson(res, 200, await c2Call(['listener', 'list']));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/listeners') {
|
||||
const b = await readBody(req);
|
||||
const args = ['listener', 'create', '--name', String(b.name || 'listener')];
|
||||
c2PushStr(args, '--bind-host', b.bind_host);
|
||||
if (b.bind_port) args.push('--bind-port', String(Number(b.bind_port) || 8443));
|
||||
c2PushStr(args, '--callback-host', b.callback_host);
|
||||
if (b.sleep_seconds) args.push('--sleep', String(Number(b.sleep_seconds) || 5));
|
||||
if (b.jitter_percent) args.push('--jitter', String(Number(b.jitter_percent) || 0));
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
let m2 = p.match(/^\/api\/c2\/listeners\/([\w.-]+)\/(start|stop)$/);
|
||||
if (req.method === 'POST' && m2) {
|
||||
return sendJson(res, 200, await c2Call(['listener', m2[2], m2[1]]));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/listeners\/([\w.-]+)$/);
|
||||
if (req.method === 'DELETE' && m2) {
|
||||
return sendJson(res, 200, await c2Call(['listener', 'delete', m2[1]]));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/c2/sessions') {
|
||||
return sendJson(res, 200, await c2Call(['session', 'list']));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/sessions\/([\w.-]+)\/sleep$/);
|
||||
if (req.method === 'POST' && m2) {
|
||||
const b = await readBody(req);
|
||||
const args = ['session', 'sleep', m2[1]];
|
||||
if (b.seconds) args.push('--seconds', String(Number(b.seconds) || 5));
|
||||
if (b.jitter) args.push('--jitter', String(Number(b.jitter) || 0));
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/sessions\/([\w.-]+)\/note$/);
|
||||
if (req.method === 'POST' && m2) {
|
||||
const b = await readBody(req);
|
||||
return sendJson(res, 200, await c2Call(['session', 'note', m2[1], '--note', String(b.note || '')]));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/sessions\/([\w.-]+)$/);
|
||||
if (req.method === 'DELETE' && m2) {
|
||||
return sendJson(res, 200, await c2Call(['session', 'kill', m2[1]]));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/c2/tasks') {
|
||||
const args = ['task', 'list'];
|
||||
if (u.searchParams.get('session_id')) args.push('--session', u.searchParams.get('session_id'));
|
||||
if (u.searchParams.get('status')) args.push('--status', u.searchParams.get('status'));
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/tasks') {
|
||||
const b = await readBody(req);
|
||||
const args = ['task', 'enqueue', '--session', String(b.session_id || ''), '--type', String(b.task_type || 'exec')];
|
||||
const payload = b.payload || {};
|
||||
args.push('--payload', JSON.stringify(payload));
|
||||
if (b.wait) args.push('--wait');
|
||||
if (b.timeout) args.push('--timeout', String(Number(b.timeout) || 60));
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/tasks\/([\w.-]+)\/wait$/);
|
||||
if (req.method === 'GET' && m2) {
|
||||
const t = Number(u.searchParams.get('timeout') || 60);
|
||||
return sendJson(res, 200, await c2Call(['task', 'wait', m2[1], '--timeout', String(t)]));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/tasks\/([\w.-]+)\/cancel$/);
|
||||
if (req.method === 'POST' && m2) {
|
||||
return sendJson(res, 200, await c2Call(['task', 'cancel', m2[1]]));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/tasks\/([\w.-]+)$/);
|
||||
if (req.method === 'GET' && m2) {
|
||||
return sendJson(res, 200, await c2Call(['task', 'get', m2[1]]));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/c2/events') {
|
||||
const n = Number(u.searchParams.get('limit') || 100);
|
||||
return sendJson(res, 200, await c2Call(['events', '--limit', String(n)]));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/c2/payloads') {
|
||||
return sendJson(res, 200, await c2Call(['payload', 'list']));
|
||||
}
|
||||
m2 = p.match(/^\/api\/c2\/payloads\/([\w.-]+)$/);
|
||||
if (req.method === 'GET' && m2) {
|
||||
const safe = m2[1];
|
||||
const file = path.join(ROOT, '.neurosploit', 'c2', 'payloads', safe);
|
||||
if (!file.startsWith(path.join(ROOT, '.neurosploit', 'c2', 'payloads') + path.sep) || !fs.existsSync(file)) {
|
||||
return sendJson(res, 404, { error: 'payload not found' });
|
||||
}
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Disposition': `attachment; filename="${safe.replace(/[^a-zA-Z0-9_.-]/g, '_')}"`,
|
||||
});
|
||||
return fs.createReadStream(file).pipe(res);
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/payloads/webshell') {
|
||||
const b = await readBody(req);
|
||||
const args = ['payload', 'webshell', '--shell-type', String(b.shell_type || 'php')];
|
||||
c2PushStr(args, '--password', b.password);
|
||||
c2PushStr(args, '--pass-param', b.pass_param);
|
||||
c2PushStr(args, '--cmd-param', b.cmd_param);
|
||||
c2PushStr(args, '--filename', b.filename);
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/payloads/beacon') {
|
||||
const b = await readBody(req);
|
||||
const args = ['payload', 'beacon', '--listener', String(b.listener_id || ''), '--kind', String(b.kind || 'bash')];
|
||||
c2PushStr(args, '--host', b.host);
|
||||
c2PushStr(args, '--filename', b.filename);
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/c2/payloads/oneliner') {
|
||||
const b = await readBody(req);
|
||||
return sendJson(res, 200, await c2Call(['payload', 'oneliner', '--listener', String(b.listener_id || '')]));
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && p === '/api/webshell/connections') {
|
||||
return sendJson(res, 200, await c2Call(['webshell', 'list']));
|
||||
}
|
||||
if (req.method === 'POST' && p === '/api/webshell/connections') {
|
||||
const b = await readBody(req);
|
||||
const args = ['webshell', 'add', '--url', String(b.url || '')];
|
||||
c2PushStr(args, '--name', b.name);
|
||||
c2PushStr(args, '--password', b.password);
|
||||
c2PushStr(args, '--shell-type', b.shell_type);
|
||||
c2PushStr(args, '--method', b.method);
|
||||
c2PushStr(args, '--cmd-param', b.cmd_param);
|
||||
c2PushStr(args, '--pass-param', b.pass_param);
|
||||
c2PushStr(args, '--os', b.os);
|
||||
c2PushStr(args, '--encoding', b.encoding);
|
||||
c2PushStr(args, '--note', b.note);
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
m2 = p.match(/^\/api\/webshell\/connections\/([\w.-]+)$/);
|
||||
if ((req.method === 'PUT' || req.method === 'PATCH') && m2) {
|
||||
const b = await readBody(req);
|
||||
const args = ['webshell', 'update', m2[1]];
|
||||
for (const k of ['url', 'name', 'password', 'shell_type', 'method', 'cmd_param', 'pass_param', 'os', 'encoding', 'note']) {
|
||||
if (b[k] !== undefined) args.push('--' + k.replace(/_/g, '-'), String(b[k]));
|
||||
}
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
if (req.method === 'DELETE' && m2) {
|
||||
return sendJson(res, 200, await c2Call(['webshell', 'delete', m2[1]]));
|
||||
}
|
||||
m2 = p.match(/^\/api\/webshell\/connections\/([\w.-]+)\/(test|exec|file)$/);
|
||||
if (req.method === 'POST' && m2) {
|
||||
const b = await readBody(req);
|
||||
if (m2[2] === 'test') return sendJson(res, 200, await c2Call(['webshell', 'test', m2[1]]));
|
||||
if (m2[2] === 'exec') {
|
||||
return sendJson(res, 200, await c2Call(['webshell', 'exec', '--id', m2[1], '--command', String(b.command || '')]));
|
||||
}
|
||||
const args = ['webshell', 'file', '--id', m2[1], '--action', String(b.action || 'list')];
|
||||
c2PushStr(args, '--path', b.path);
|
||||
c2PushStr(args, '--content', b.content);
|
||||
c2PushStr(args, '--target-path', b.target_path);
|
||||
return sendJson(res, 200, await c2Call(args));
|
||||
}
|
||||
|
||||
return sendJson(res, 404, { error: 'not found' });
|
||||
} catch (e) {
|
||||
return sendJson(res, 400, { error: e.message });
|
||||
}
|
||||
}
|
||||
|
||||
// ---- aggregate stats for the dashboard ----
|
||||
if (req.method === 'GET' && p === '/api/stats') {
|
||||
return sendJson(res, 200, await stats());
|
||||
|
||||
Reference in new issue
Block a user