# Design: Intruder

Status: backend built (`b17a509`), interface in progress. Reference:
`docs/guides/intruder.md`. Roadmap M2 ("Intruder workspace"). Builds on payload
collections (`docs/guides/payloads.md`), scope, the upstream TLS policy and the
redaction policies.

## Problem

A researcher takes one captured request, marks where values go, picks
payloads, and sends many variations to see which response is different.
In Phantom an attack is a research object like any other: it belongs to a vault, it is bound by
scope and rate limits enforced on the backend, its results can be
annotated, sent to Repeater or the Comparer, and turned into findings, and
an agent can run one through MCP within the same limits.

## Objects

### Attack

| Field | Notes |
|---|---|
| `id`, `vault_id` | Vault-owned. Deleting the vault deletes its attacks. |
| `name` | Defaults to `METHOD host/path`. |
| `base` | The request template: scheme, host, port and the raw request with insertion points marked `§name§` (default names `1`, `2`, ...). Recorded `source_flow_id` when started from history. |
| `positions` | Parsed from the template on save; each has a name and byte span. Auto-mark suggests query, form, JSON and cookie values. |
| `strategy` | `sniper` (one position at a time), `battering_ram` (same payload everywhere), `pitchfork` (lists in step), `cluster_bomb` (cartesian product). |
| `sources` | Per position: a payload collection (by id, read page by page), an inline list, a number range (from, to, step, format), or null payloads (n times). |
| `processing` | Ordered per-position steps: prefix, suffix, replace, URL, base64 or hex encode and decode, case, hash. Applied to the payload, never to the template. |
| `matchers` | Grep rules evaluated on each response: status in set, length range, regex or literal in headers or body (bounded regex, like intercept rules), response time above. Each result records which matched. |
| `options` | Concurrency (1–20, default 4), requests per second (0.5–50, default 10), delay jitter, timeout, retries on network errors, follow redirects off, update Content-Length on. |
| `status` | `draft`, `running`, `paused`, `completed`, `cancelled`, `failed`. |
| `total`, `sent` | Total is computed before start; an attack that exceeds the quota cannot start. |
| `actor` | `user` or `agent`. |

### Attack result

One row per request sent, stored in `attack_results`: index, the payload
per position, status code, response length, time, matched rules, error,
and a bounded copy of the response (same body limit as capture). A result
can be saved to history as a flow (`source = intruder`) on demand, never
automatically, so a 10,000-request attack does not flood the history.

## Safety and authorization

- Every request is checked against the vault scope before it is sent. A
  payload that changes the host (Host header, absolute URL) to an
  out-of-scope host is refused for that request and recorded as an error.
- Upstream TLS follows the global policy, exactly like replay.
- Quotas (constants, documented): requests per attack (100,000),
  concurrent running attacks per vault (2), global request rate cap.
- Rate limiting and concurrency are enforced in the backend runtime, not
  the client. Pause stops new requests at once; in-flight requests finish.
  Cancel ends the attack and keeps its results. A backend restart marks
  running attacks `paused`, never silently resumes them.
- Agents: MCP can create, start, pause and read attacks within the same
  scope, plus stricter agent quotas (10,000 requests per attack, 10 rps).
  A user setting `intruder.agents` (`allowed` by default, or `preview`:
  create and estimate only) is writable only by the user, like the
  redaction policies.
- Result payloads and responses go through the MCP redaction policy for
  agents and the export policy for exports.

## API (REST and MCP, same services)

- `GET/POST/PATCH/DELETE /vaults/{id}/attacks`
- `POST /vaults/{id}/attacks/{aid}/estimate` (total requests, positions,
  sources, warnings), `start`, `pause`, `resume`, `cancel`
- `GET /vaults/{id}/attacks/{aid}/results?after=&sort=&status=&matched=&search=`
  (keyset paging), `GET .../results/{index}` (full request and response),
  `POST .../results/{index}/save` (to history), export as CSV or JSON lines
- Events: `attack.updated` (status, sent, rate) throttled to a few per
  second, `attack.results` (counts only, never payloads).
- MCP tools: `attack_create`, `attack_estimate`, `attack_start`,
  `attack_pause`, `attack_cancel`, `attack_get`, `attack_results`,
  `attack_result_get`.

## Interface

- **Entry points:** "Send to Intruder" in the history row menu, the
  request panel and Repeater; Intruder as a Proxy tool next to Repeater.
- **Editor:** the shared request editor with insertion points highlighted
  in the accent colour; select text and press `§` (or "Add position") to
  mark it; "Auto" suggests positions; "Clear".
- **Payloads:** one compact row per position: source (collection picker
  with search and counts, inline list, numbers, null), processing steps as
  chips. Strategy as a segmented control with a one-line explanation and
  the live request estimate.
- **Run:** start, pause, resume, cancel in the header, with sent / total,
  rate, errors and matched counts as a quiet pulse row.
- **Results:** a virtualized table (index, payloads, status, length,
  time, matched rules), sortable and filterable, live while running;
  selecting a row shows the request and response in the shared message
  viewer with the payload marked. Row menu: send to Repeater, compare with
  the base response, save to history, add the payload to a collection,
  create a finding.
- Attacks list in the Proxy sidebar like Repeater tabs, persisted on the
  backend.

## Out of scope for the first cut

Recursive grep (feeding extracted values into later requests), macros and
session handling rules, resource pools shared across attacks, and payload
generators beyond the four sources above.
