Metadata-Version: 2.4
Name: poc-harness
Version: 0.4.0
Summary: Scope-enforced AI-assisted web security testing with evidence capture and human approvals.
Author: Artex09
License: MIT
Project-URL: Homepage, https://github.com/Artex09/poc-harness
Project-URL: Repository, https://github.com/Artex09/poc-harness
Project-URL: Issues, https://github.com/Artex09/poc-harness/issues
Project-URL: Changelog, https://github.com/Artex09/poc-harness/blob/main/CHANGELOG.md
Keywords: security,bug-bounty,pentest,agent,llm,idor,oast
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: pyyaml
Requires-Dist: lxml
Requires-Dist: httpx
Provides-Extra: llm
Requires-Dist: anthropic; extra == "llm"
Requires-Dist: openai; extra == "llm"
Provides-Extra: tui
Requires-Dist: rich; extra == "tui"
Provides-Extra: browser
Requires-Dist: playwright; extra == "browser"
Requires-Dist: playwright-stealth; extra == "browser"
Provides-Extra: all
Requires-Dist: anthropic; extra == "all"
Requires-Dist: openai; extra == "all"
Requires-Dist: rich; extra == "all"
Requires-Dist: playwright; extra == "all"
Requires-Dist: playwright-stealth; extra == "all"
Dynamic: license-file

# poc-harness — the polite AI bug-bounty hunter 🕵️

**An autonomous, black-box web pentest agent that confirms *real* bugs with evidence — engineered to minimize ban risk.**

Most "AI hacking" tools are noisy scanners that hammer production, hallucinate
findings, and get your HackerOne/Bugcrowd account suspended. poc-harness is the
opposite: a scope-gated, mostly read-only, rate-limited agent that proves a vulnerability
the way a triager wants to see it — with the raw request/response — and stops.
It is a careful tool, not a magic shield — read **[Limits & honest caveats](#limits--honest-caveats)** before you point it at anything.

```text
╭────────────────────────────── POCH / LIVE RUN ────────────────────────────────────╮
│ POCH   MockShop   ollama / qwen35-9b-256k                                          │
│ Goal: map the surface and safely confirm access-control and injection issues      │
│ Step 8/40  ##################----  2.4s                                           │
│ Plan  ->  ScopeCheck  ->  Act  ->  Verdict                                         │
│ #  action              scope    verdict       note                                │
│ 5  check_idor          allow    CONFIRMED     /v1/orders/{id}                      │
│ 7  check_idor_semantic allow    CONFIRMED     marker-free response comparison     │
│ 8  check_blind_oast    allow    CONFIRMED     callback received                    │
│                                                                                   │
│       4                 1                 3                 4                     │
│     PAGES           ENDPOINTS         IDENTITIES         CONFIRMED                 │
╰───────────────────────────────────────────────────────────────────────────────────╯

╭ Offline demo [PASS] ──────────────────────────────────────────────────────────────╮
│ Confirmed IDOR, reflected XSS, and blind SSRF on the safe loopback mock.           │
│ Steps 9   Pages 4   Endpoints 1   Test identities 3   Confirmed findings 4          │
│ Report: .../poch_selftest/agent_evidence/report.md                                 │
╰───────────────────────────────────────────────────────────────────────────────────╯
```
*Record your own GIF in one command — see [`docs/DEMO.md`](docs/DEMO.md): `python selftest/run_agent_selftest.py --tui`.*

## Why it's built to minimize ban risk
Bug hunters are rightly terrified of automated tools torching their reputation.
No tool can *guarantee* you won't be banned — but every design decision here is
aimed at reducing that risk:

1. **One `scope.yaml` per program.** Every HTTP request the agent makes is checked
   against it *before it leaves your machine*. Off-scope **host** → hard block. Scope
   is matched by host (not port/path) — see caveats.
2. **Non-destructive by default.** `DELETE/PUT/PATCH` are blocked unless you opt in.
   `GET`/`POST` are allowed (login, and the business-logic/race checks use POST), so
   it's not *purely* read-only — impact is *demonstrated*, not *maximized*. No mass
   create/modify/delete to "prove" a bug.
3. **Polite rate limiting.** One clean request that proves the bug beats a thousand
   noisy ones. No scanner storm against prod.
4. **Automatic token redaction.** Your `Cookie`/`Authorization` never land in a report.
5. **Human-in-the-loop.** Sensitive actions (account creation, payload sends) ask first,
   unless you opt into full-auto.
6. **Evidence-based.** Nothing is a "finding" until a check *confirms* it. No hallucinated CVEs.

## Limits & honest caveats
Real talk, so you can make an informed call before pointing this at a program:
- **Scope defaults to host-level, but can go finer.** `ScopeGuard` matches hostname by default
  (any port, any path). Scope a port with a `host:port` pattern in `in_scope_hosts`, and block
  paths with `out_of_scope_paths` (fnmatch) in `scope.yaml`.
- **Not purely read-only.** `GET`/`POST` are allowed; `check_business_logic` and the race test
  send `POST`, and **`check_race_condition` fires a concurrent burst that intentionally skips the
  polite throttle** (that's the test — it still counts against the budget). Those tools, and the
  low-level `http_request`, are gated behind human approval by default.
- **Rate + budget are now shared per-target.** The rate limit and the `max_requests` budget are
  enforced across *all* identities on one target (not per-session), so multiple accounts can't
  collectively outrun them.
- **Evidence is scrubbed but still sensitive.** Logged bodies/URLs have passwords, tokens, and
  JWTs redacted by default (`evidence.scrub_secrets`; set `log_bodies: false` to drop bodies
  entirely). Test-account passwords/sessions are **not** written to the state DB unless you set
  `persist_credentials: true`. Still treat the evidence dir as secret; wipe it with `poch clean`.
- **A cloud brain sees target data.** With `--provider claude|openai`, target responses (URLs,
  status, body snippets, the agent's observations) are sent to that provider in prompts as the
  agent reasons, and your API key is read from the environment (the run prints a notice). The
  local Ollama brain keeps all of it on your machine. Full detail: [`SECURITY.md`](SECURITY.md).
- **The browser is fully scope-gated.** When a `guard` is attached, Playwright intercepts *every*
  request the browser makes — documents, subresources, XHR/fetch, and each redirect hop — and
  aborts anything out of scope (the number dropped is returned as `blocked_requests`). Trade-off:
  a page that genuinely needs a third-party host (a CDN, an SSO origin) will have those requests
  blocked until you add that host to `scope.yaml`.
- **Email verification isn't automated.** Account creation registers and logs in, but it does not
  click a confirmation link. `Mailbox.wait_for_link` (mail.tm) exists but is not wired into the
  default flow, and the offline `MockEmailProvider` is the default — so a target that requires a
  verified email needs the link handled manually. See [`SECURITY.md`](SECURITY.md).

## What it does
- **Maps** a target's attack surface (pages, forms, parameters) — scope-bound crawler.
- **Creates** the test accounts it needs (disposable email via mail.tm, multi-identity).
- **Reasons** with an LLM — local **Ollama** (free, default), **Claude**, or **OpenAI** — to pick what to test where.
- **Confirms** bugs non-destructively: IDOR/BOLA, broken access control, reflected XSS, **blind SSRF/XSS (OAST)**.
- **Writes** a submission-ready Markdown report with the raw evidence.

## 30-second start (fully offline — no target, no API key, no model)
```bash
python selftest/run_agent_selftest.py          # scripted brain drives the real loop end-to-end
python selftest/run_agent_selftest.py --tui    # ...with the live dashboard
python selftest/run_features_selftest.py       # diffing / semantic-IDOR / OAST / browser handoff
python selftest/run_advanced_selftest.py       # self-healing / attack-chains / race / deser / stealth
```
It spins up a deliberately-vulnerable loopback app, then the agent recons it, makes
two accounts, **confirms IDOR + reflected XSS + a true per-user IDOR + blind SSRF**,
and writes a Markdown report (its path is printed at the end).

## Quick start
```bash
python poch.py demo        # watch it confirm 4 bug classes on a safe built-in target
python poch.py doctor      # check your setup (brain, deps, PATH)
```
On Windows you can use the bundled launcher — `.\poch demo`, `.\poch doctor` — no install, no PATH setup.

## Install
```bash
python -m pip install poc-harness
python -m pip install "poc-harness[all]"  # TUI, cloud LLM providers, and browser support
```

The base install includes the `poch` command and required HTTP/YAML/HTML packages.
The `all` extra adds Rich for the dashboard, Anthropic/OpenAI clients, and Playwright
for SPA browser handoff. Install Chromium separately with `python -m playwright install chromium`.
For development from a clone, use `python -m pip install -e .` (or `python -m pip install -e ".[all]"`).

## Run it for real (authorized targets only)
```bash
poch init                 # interactive: asks program name, hosts, start URL, brain
poch scope                # inspect the allowed hosts, paths, and request limits
poch doctor               # check provider, dependencies, and project config
poch run --tui            # auto-uses ./agent.yaml + ./profile.json from init
#   --yes                                   full-auto (skip approvals)
#   --provider claude --model claude-opus-5   stronger brain (set ANTHROPIC_API_KEY)
```
Review `scope.yaml` against the program policy before running. Scope config is a technical boundary, not authorization.
Or try a legal practice target right now — see [`templates/`](templates/) (OWASP Juice Shop, DVWA).

## CLI (`poch`)
```
poch demo       run the agent on a safe built-in target — zero setup
poch doctor     check environment + setup and suggest fixes
poch init       set up a program (scope + config), interactively
poch run        run the autonomous agent (auto-uses ./agent.yaml + ./profile.json)
poch recon      map a target's attack surface (crawl only)
poch report     build the Markdown report from an evidence dir
poch scope      validate and show what a scope.yaml allows / blocks
poch state      inspect an evidence/state.db (counts, findings, identities)
poch oast       start a standalone out-of-band callback listener
poch clean      delete an evidence directory (captured traffic, state, report)
poch selftest   run the self-tests (all = offline: agent | features | advanced | security; or browser)
poch version    show version + environment
```
`poch <command> -h` for options. On Windows use `.\poch <command>` (bundled launcher) if the
bare `poch` isn't on PATH — or `python poch.py <command>`.

> The agent **cannot test anything `scope.yaml` doesn't authorize.** Autonomy changes
> what it *decides*, never what it's *allowed to touch*.

## Headline features
| Feature | What it buys you |
|---|---|
| **Differential Response Engine** (`agent/diffing.py`) | Marker-free IDOR proof: strips timestamps/tokens/nonces before comparing A's response to B's, so dynamic noise doesn't cause false positives. Also tells a real per-user IDOR apart from merely-public data. |
| **Hybrid Browser → API handoff** (`recon/browser.py`) | Playwright logs into JS/SPA apps, then hands the cookies/JWT to the fast `GuardedSession`. SPA support without the speed tax. (Optional dep.) |
| **Out-of-Band (OAST) listener** (`oast/`) | Catches blind SSRF/XSS via a local callback canary. Honest about reachability: set `public_base` to a tunnel for external targets. |
| **Live TUI dashboard** (`agent/dashboard.py`) | The `Plan → ScopeCheck → Act → Verdict` loop, live, powered by `rich`. |
| **Local-first brain** | Runs on your own Ollama for free; swap to Claude/OpenAI with one flag. |

### From scanner to operator (Phase 3)
| Capability | What it buys you |
|---|---|
| **Multi-step attack chains** (`agent/planner.py`, `agent/chain.py`) | A dependency graph of steps where each one's output feeds the next: *leak a token → reuse it → reach `/admin`*. Not just isolated findings — composite impact. |
| **Self-healing loop** (`agent/healing.py`) | On a WAF/4xx/5xx block, the failing response is fed back to the LLM, which proposes a repaired retry (extra header, tweaked param), bounded to N tries. The agent adapts instead of stalling. |
| **Browser stealth + SPA waiting** (`recon/browser.py`) | Built-in anti-automation evasions (masks `navigator.webdriver`, WebGL, plugins; uses `playwright-stealth` if installed) and `networkidle` waiting + token pre-injection for React/Vue apps behind anti-bot. |
| **Business-logic testing** (`checks/business_logic.py`) | Abuses the *workflow* (negative quantities, price tampering) and flags when the server accepts it — the flaws fuzzers miss. |
| **Race conditions** (`checks/race_condition.py`) | `asyncio`+`httpx` fires a concurrent burst to break single-use actions (TOCTOU/locking), counting successes vs. what should be possible. |
| **Blind deserialization** (`checks/deserialization.py`, `agent/payloads.py`) | Sends pickle/PHP/JSON payloads carrying an OAST canary and watches for the callback — object injection proven out-of-band. |

## How the agent works
```
plan (LLM picks a tool) → authorize (governance / you) → act (through ScopeGuard)
   → observe → record (SQLite state + audit log) → repeat until finish/budget
```
All capability lives in `agent/tools.py`; all judgment in the LLM; all safety in
`agent/governance.py` + `harness.ScopeGuard`. Tools today: `recon_crawl`, `list_surface`,
`create_identity`, `browser_handoff`, `http_request` (with `heal`), `run_attack_chain`,
`check_idor`, `check_idor_semantic`, `check_access_control`, `check_reflected_xss`,
`check_blind_oast`, `check_business_logic`, `check_race_condition`, `check_deserialization`,
`record_note`, `finish`.

## Add a new bug class in ~40 lines  ⭐ (PRs welcome)
A check is just a function that takes guarded session(s) + a `target`, sends the
minimal request(s), decides confirmed/not, and records a verdict:

```python
# checks/open_redirect.py
from harness import record_verdict

def run(guard, evidence_dir, target, sess):
    canary = "https://evil.example"
    r = sess.get(target["url_template"].format(payload=canary), allow_redirects=False)
    location = r.headers.get("Location", "")
    confirmed = r.status_code in (301, 302, 307, 308) and location.startswith(canary)
    record_verdict(evidence_dir, {
        "check": "open_redirect", "url": r.request.url, "confirmed": confirmed,
        "severity_hint": "Medium" if confirmed else "n/a",
        "reason": f"Redirects to attacker-controlled {location!r}" if confirmed
                  else "No external redirect — safe.",
    })
    return confirmed
```
Then expose it as one `Tool(...)` in `agent/tools.py` and the agent can use it.
That's the whole plugin story. Good next ones: CSRF, JWT/auth flaws, read-only SQLi,
SSTI, CORS misconfig.

## Project layout
- `harness.py` — ScopeGuard + GuardedSession + evidence capture (the safety spine).
- `agent/` — orchestrator loop, pluggable LLM, SQLite state, governance, tools, dashboard, diffing, planner+chain (multi-step), healing (self-correction), payloads.
- `recon/` — scope-bound crawler (`crawler.py`) + browser handoff (`browser.py`).
- `identity/` — mail.tm temp-email + multi-account session manager.
- `oast/` — out-of-band callback listener for blind vulns.
- `checks/` — the confirmable bug modules.
- `report.py` — evidence + verdicts → Markdown.
- `cli/` — the `poch` command (run/recon/report/scope/state/oast/init/selftest).
- `templates/` — ready-to-use Juice Shop / DVWA configs.
- `selftest/` — loopback vulnerable app + offline proofs.

## The one boundary
It only ever talks to hosts a program has authorized you to test. Keep it that way,
and this tool keeps you *paid, not banned*.
