Skip to content

Architecture

sm0k3net edited this page Nov 28, 2026 · 7 revisions

Architecture

dsh-redteam is a DSH plugin with two halves that share one store: a Host half that owns all state and every side effect, and a Web client that renders one snapshot and posts operator actions. There is no second copy of the truth and no privileged side channel. Long form: docs/ARCHITECTURE.md.

On this page: process model · module map · state directory · data model · HTTP bridge · client build · security invariants · testing.

Two halves, one process model

DSH Host (Node)
  index.js  apply(ctx, config)
    Store      $DSH_HOME/redteam/     snapshots + JSONL audit
    Engine     phases, graph, gates, approvals, exec, evidence, reports
    services   kali · wordlists · wordlist-ai · scope-ai · osint · keys · methodology
               browser · web-audit · api-pentest · api-fuzz · evidence · report/docx/pdf · bundle
    tools.js   51 pentest_* tools
    api.js     /dsh-redteam/* routes
        ▲  HTTP + SSE, same origin
Browser (DSH Web UI)
  client.js  build artifact of src-client/*.js
    eight tabs · eight drawers · topology view · approval modal

index.js exports inject = ['tools', 'webServer'] and apply(ctx, config). Optional services (credentials, llm, agentDefaultModel) are resolved defensively, so a profile without them still activates: OSINT keys fall back to the env file and AI wordlists report available:false. Every registration goes through ctx.effect/ctx.on; disposal closes child processes, browser sessions and timers.

Module map

Module Responsibility
store.js, domain.js Per-session JSON, atomic writes, append-only JSONL, plus node/edge/phase vocabulary.
engine.js Snapshot assembly, phase gates, node/edge operations, approvals, execution, evidence capture, reports, completion checklist.
scope.js Host, domain, CIDR and exclusion matching; blocked schemes and metadata addresses.
tools.js The 51 tool definitions: name, description, JSON schema, thin handler; resolves child agents to the root session and consumes plan budget per call.
api.js HTTP bridge: routing, allowlists, origin gate, body caps, error shaping, SSE, downloads.
kali.js Docker lifecycle, argv-only exec, catalog, apt search/install, host fallback, process tracking.
wordlists.js, wordlist-ai.js Bundled manifest, uploads, per-runtime resolution, container sync, consent-gated generation and adaption.
skills.js 20 offensive-security playbooks with validated ATT&CK/WSTG references and deterministic list/get/recommend selectors; never executes a tool.
scope-ai.js Strict-JSON scope/RoE draft through the Host model route; local validation, metadata refusal, redaction; never writes the store.
browser.js Isolated Chromium over the DevTools protocol with document-level scope interception; JS dialogs are dismissed and timed-out snapshots retry once.
web-audit.js Bounded fetch assessment: headers, cookies, forms, technology, endpoints, safe probes.
api-pentest.js, api-fuzz.js OpenAPI/GraphQL discovery, JS mining, scoped requests, nine-category fuzzing with anomaly detection.
osint.js / keys.js 39 connectors (recon, exposure, threat intelligence, identity, vulnerabilities, exploits, breach/leak, dark-web, reference) plus the passive enrichment pipelines, and the four-layer credential chain, with a scope guard, CIDR sampling caps, allowlist, leak approval, budgets and loopback-only Tor.
osint-report.js Standalone OSINT deliverable (Markdown/HTML/JSON) from stored facts: deterministic, escaped, secret-scrubbed, no network or evidence access.
methodology.js Query layer over lib/host/knowledge/*.json.
evidence.js Write-once vault, SHA-256, manifests, redaction, path guards, ZIP packaging and the shared deterministic buildZip.
report.js / report-i18n.js / pdf.js / docx.js Deterministic report model, six formats, en/ru templates, dependency-free PDF and DOCX writers with embedded PNG evidence images.
bundle.js Pure project-bundle assembler: reports, evidence, process timeline, state, audit, tool runs, findings CSV/JSON and SARIF, manifest and sums.
verifiers.js Deterministic evidence-only verifiers for ten CWE families plus a fallback; named checks, confidence and missing proof.
identity.js Accounts/roles/auth/MFA/access, account × asset matrix and coverage gaps; secrets are never stored.
oob.js Local OOB canary state: unguessable tokens, TTL, hit dedupe and caps; the Host route feeds hits.
planner.js One plan with steps, dependencies, budgets and maxParallel, plus a deterministic critic.
team.js Nine-role team plan, dependency-ordered task board, focus/reassign/handoff and delegation prompts.
sarif.js Pure SARIF 2.1.0 exporter with CWE rules, OWASP/WSTG tags, CVSS and stable fingerprints.
retest.js Offline replay planner/evaluator for GET/HEAD/POST over HTTP(S), with destructive-path refusal.

State directory

Everything lives under $DSH_HOME/redteam/ with 0700 directories and 0600 files; JSON writes go through a temporary file and rename, the audit file is append-only, and session ids are sanitized into one path segment.

redteam/
  sessions/<session>.json      engagement, graph, runs, approvals
  audit/<session>.jsonl        append-only audit trail
  reports/<session>/           md, html, json, pdf, slides, docx
  bundles/<session>/           deterministic project ZIPs
  evidence/<session>/          <evId>/<slug>, meta.json, manifest.json, manifest.jsonl
  artifacts/<session>/browser/ screenshots and HTML snapshots
  wordlists/                   custom and AI lists, _meta.json, ai-meta.json

Data model

engine.snapshot(sessionId) returns plain JSON with no secret inside:

{
  rev, sessionId, lang,
  engagement: { id, name, client, status, scope, roe, mode, modeChangedAt },
  phases: [{ id, order, status, startedAt, endedAt, note, workers, tools }],
  nodes:  [{ id, type, title, detail, phase, status, severity, cvss, cwe, owasp,
             wstg, remediation, evidence, toolRunId, parentId, createdAt, meta }],
  edges:  [{ id, from, to, kind, label, createdAt }],
  toolRuns: [{ id, tool, command, target, category, exitCode, status, runtime }],
  findings, assets, approvals, toolState, wordlists, osint, engine, report, audit,
  evidence, api, browser, ai,
  plan, planCritic, teamStatus, identity, identityGaps, oob, retests
}

Node types: goal, intent, fact, finding, asset. Edge kinds: spawns (dashed), yields (solid), derived_from (dotted), proves (bold), parent (gray). The nine phases, in fixed order: pre-engagement, recon, enumeration, vulnerability-analysis, exploitation, privilege-escalation, lateral-movement, post-exploitation, reporting. A phase advances at most one step forward and may be revisited; completion needs every non-reporting phase done or skipped with a reason.

HTTP bridge

Routes are registered under /dsh-redteam:

Route Method Purpose
/health GET Liveness, version, revision, routes, effective config.
/state?sessionId= GET One bounded snapshot.
/stream?sessionId= GET (SSE) Frames on store change, coalesced at 350 ms, with heartbeats.
/action POST Operator actions: acceptRoe, setMode, resolveApproval, installs, scope edits.
/report?sessionId=&id=&format= GET Download a generated report.
/wordlist, /wordlist/upload GET, POST Preview and upload wordlists.
/browser/screenshot GET Serve a screenshot from a session's artifact directory.
/evidence/file, /evidence/package GET Download one record or the ZIP package.
/canary/<token> GET, POST Local OOB callback: records one hit, answers a 1×1 PNG. Token is the capability; per-token rate limit and 4 KiB body cap.

Shared gates: a method allowlist per route, a JSON content-type check, a 512 KiB JSON cap and 32 MiB upload cap, an Origin/Host check for mutations, bounded errors, and realpath checks that confine every path to the session directory. The bridge labels calls actor: 'operator'; the engine rejects acceptRoe, setMode and resolveApproval for any other actor.

Client build and slots

scripts/build-client.mjs concatenates src-client/*.js in filename order into one window.__ModuleLoader__.load({...}) call. client.js is committed and CI fails on drift; sources must not use import/export.

The client registers a tab type (dsh-redteam/panel, kind redteam) through sidebarRightTabs, injects sidebar.right.pane.tab and .title, and auto-opens once per session per page load when an engagement starts or an approval is pending. useSnapshot subscribes to /stream with polling fallback every five seconds; strings go through RT.t(lang, key).

Sixteen security invariants

  1. No agent path to operator authority: RoE, mode and approvals are operator actions only.
  2. No execution without scope and an accepted RoE: every acting entry point checks first.
  3. Gated categories block in Safe mode; approvals never happen implicitly and expire.
  4. No shell interpolation: argv arrays only, validated tool names, no shell: true.
  5. Secrets never cross the boundary: keys and credential headers are redacted everywhere.
  6. Evidence is immutable and verifiable: write-once, SHA-256, manifest and sha256sums.txt.
  7. Paths stay inside the vault: bridge and evidence paths are resolved and confined.
  8. The audit trail is append-only; every report contains the audit appendix it read.
  9. No self-propagation: no worm, no unapproved persistence, no exfiltration path.
  10. verified/exploited findings need evidence, a tool run, evidence ids or a validation record.
  11. Reports and bundles are deterministic for a given state, written 0600, and bundles carry a manifest and SHA-256 sums.
  12. Verification is evidence-only and one-way: no request, no invented evidence, and a confirmed verdict may only promote unverified → verified.
  13. OOB tokens are bearer capabilities, redacted from the snapshot, audit and bundles; the callback route is rate-limited and body-capped.
  14. Retest replay is bounded: GET/HEAD/POST, one request, confirm: true, in-scope, destructive paths refused, and it never sets exploited.
  15. Identity data is not credential storage: only whitelisted fields persist and bundles never carry secrets.
  16. The plan is advisory and the critic deterministic; budget overruns are reported, never clamped.

Testing

node --test test/*.test.mjs runs 714 cases (712 passing, 0 failing, 2 environment-dependent skips) with Node builtins only: store atomicity, phase gates and engine policy, tool schemas, wordlist resolution, AI generation against a fake model route, scope-AI parsing and validation, OSINT normalization with a fake fetch, methodology data integrity, evidence hashing/redaction/ZIP, every report format including DOCX structure and the PDF text layer, the deterministic bundle, topology layout, client components under a React shim, and browser flows that skip when Chromium is absent. Tests never touch the network or a real container; the opt-in live Docker check (test/docker-live.test.mjs) runs only with REDTEAM_DOCKER_TEST=1. CI runs on Node 20 and 22, rebuilds the client artifact, fails on drift, and syntax-checks both entries.

Related

Clone this wiki locally