poc-harness 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. poc_harness-0.4.0/LICENSE +21 -0
  2. poc_harness-0.4.0/PKG-INFO +266 -0
  3. poc_harness-0.4.0/README.md +222 -0
  4. poc_harness-0.4.0/agent/__init__.py +18 -0
  5. poc_harness-0.4.0/agent/chain.py +86 -0
  6. poc_harness-0.4.0/agent/cli.py +71 -0
  7. poc_harness-0.4.0/agent/config.py +114 -0
  8. poc_harness-0.4.0/agent/dashboard.py +182 -0
  9. poc_harness-0.4.0/agent/diffing.py +100 -0
  10. poc_harness-0.4.0/agent/governance.py +94 -0
  11. poc_harness-0.4.0/agent/healing.py +76 -0
  12. poc_harness-0.4.0/agent/llm.py +200 -0
  13. poc_harness-0.4.0/agent/orchestrator.py +219 -0
  14. poc_harness-0.4.0/agent/payloads.py +49 -0
  15. poc_harness-0.4.0/agent/planner.py +89 -0
  16. poc_harness-0.4.0/agent/runner.py +22 -0
  17. poc_harness-0.4.0/agent/state.py +163 -0
  18. poc_harness-0.4.0/agent/tools.py +306 -0
  19. poc_harness-0.4.0/checks/__init__.py +0 -0
  20. poc_harness-0.4.0/checks/access_control.py +35 -0
  21. poc_harness-0.4.0/checks/blind_oast.py +42 -0
  22. poc_harness-0.4.0/checks/business_logic.py +44 -0
  23. poc_harness-0.4.0/checks/deserialization.py +48 -0
  24. poc_harness-0.4.0/checks/idor.py +61 -0
  25. poc_harness-0.4.0/checks/idor_semantic.py +79 -0
  26. poc_harness-0.4.0/checks/race_condition.py +73 -0
  27. poc_harness-0.4.0/checks/reflected_xss.py +64 -0
  28. poc_harness-0.4.0/cli/__init__.py +2 -0
  29. poc_harness-0.4.0/cli/__main__.py +4 -0
  30. poc_harness-0.4.0/cli/main.py +895 -0
  31. poc_harness-0.4.0/cli/output.py +164 -0
  32. poc_harness-0.4.0/harness.py +272 -0
  33. poc_harness-0.4.0/identity/__init__.py +1 -0
  34. poc_harness-0.4.0/identity/accounts.py +121 -0
  35. poc_harness-0.4.0/identity/tempmail.py +103 -0
  36. poc_harness-0.4.0/oast/__init__.py +4 -0
  37. poc_harness-0.4.0/oast/listener.py +121 -0
  38. poc_harness-0.4.0/poc_harness.egg-info/PKG-INFO +266 -0
  39. poc_harness-0.4.0/poc_harness.egg-info/SOURCES.txt +56 -0
  40. poc_harness-0.4.0/poc_harness.egg-info/dependency_links.txt +1 -0
  41. poc_harness-0.4.0/poc_harness.egg-info/entry_points.txt +2 -0
  42. poc_harness-0.4.0/poc_harness.egg-info/requires.txt +22 -0
  43. poc_harness-0.4.0/poc_harness.egg-info/top_level.txt +9 -0
  44. poc_harness-0.4.0/pyproject.toml +50 -0
  45. poc_harness-0.4.0/recon/__init__.py +1 -0
  46. poc_harness-0.4.0/recon/browser.py +247 -0
  47. poc_harness-0.4.0/recon/crawler.py +115 -0
  48. poc_harness-0.4.0/report.py +60 -0
  49. poc_harness-0.4.0/selftest/__init__.py +23 -0
  50. poc_harness-0.4.0/selftest/mock_target.py +148 -0
  51. poc_harness-0.4.0/selftest/run_advanced_selftest.py +145 -0
  52. poc_harness-0.4.0/selftest/run_agent_selftest.py +128 -0
  53. poc_harness-0.4.0/selftest/run_browser_integration.py +165 -0
  54. poc_harness-0.4.0/selftest/run_features_selftest.py +110 -0
  55. poc_harness-0.4.0/selftest/run_security_selftest.py +125 -0
  56. poc_harness-0.4.0/selftest/run_selftest.py +26 -0
  57. poc_harness-0.4.0/selftest/scope.yaml +8 -0
  58. poc_harness-0.4.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Artex09
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,266 @@
1
+ Metadata-Version: 2.4
2
+ Name: poc-harness
3
+ Version: 0.4.0
4
+ Summary: Scope-enforced AI-assisted web security testing with evidence capture and human approvals.
5
+ Author: Artex09
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Artex09/poc-harness
8
+ Project-URL: Repository, https://github.com/Artex09/poc-harness
9
+ Project-URL: Issues, https://github.com/Artex09/poc-harness/issues
10
+ Project-URL: Changelog, https://github.com/Artex09/poc-harness/blob/main/CHANGELOG.md
11
+ Keywords: security,bug-bounty,pentest,agent,llm,idor,oast
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Topic :: Internet :: WWW/HTTP
20
+ Classifier: Topic :: Security
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: requests
26
+ Requires-Dist: pyyaml
27
+ Requires-Dist: lxml
28
+ Requires-Dist: httpx
29
+ Provides-Extra: llm
30
+ Requires-Dist: anthropic; extra == "llm"
31
+ Requires-Dist: openai; extra == "llm"
32
+ Provides-Extra: tui
33
+ Requires-Dist: rich; extra == "tui"
34
+ Provides-Extra: browser
35
+ Requires-Dist: playwright; extra == "browser"
36
+ Requires-Dist: playwright-stealth; extra == "browser"
37
+ Provides-Extra: all
38
+ Requires-Dist: anthropic; extra == "all"
39
+ Requires-Dist: openai; extra == "all"
40
+ Requires-Dist: rich; extra == "all"
41
+ Requires-Dist: playwright; extra == "all"
42
+ Requires-Dist: playwright-stealth; extra == "all"
43
+ Dynamic: license-file
44
+
45
+ # poc-harness — the polite AI bug-bounty hunter 🕵️
46
+
47
+ **An autonomous, black-box web pentest agent that confirms *real* bugs with evidence — engineered to minimize ban risk.**
48
+
49
+ Most "AI hacking" tools are noisy scanners that hammer production, hallucinate
50
+ findings, and get your HackerOne/Bugcrowd account suspended. poc-harness is the
51
+ opposite: a scope-gated, mostly read-only, rate-limited agent that proves a vulnerability
52
+ the way a triager wants to see it — with the raw request/response — and stops.
53
+ It is a careful tool, not a magic shield — read **[Limits & honest caveats](#limits--honest-caveats)** before you point it at anything.
54
+
55
+ ```text
56
+ ╭────────────────────────────── POCH / LIVE RUN ────────────────────────────────────╮
57
+ │ POCH MockShop ollama / qwen35-9b-256k │
58
+ │ Goal: map the surface and safely confirm access-control and injection issues │
59
+ │ Step 8/40 ##################---- 2.4s │
60
+ │ Plan -> ScopeCheck -> Act -> Verdict │
61
+ │ # action scope verdict note │
62
+ │ 5 check_idor allow CONFIRMED /v1/orders/{id} │
63
+ │ 7 check_idor_semantic allow CONFIRMED marker-free response comparison │
64
+ │ 8 check_blind_oast allow CONFIRMED callback received │
65
+ │ │
66
+ │ 4 1 3 4 │
67
+ │ PAGES ENDPOINTS IDENTITIES CONFIRMED │
68
+ ╰───────────────────────────────────────────────────────────────────────────────────╯
69
+
70
+ ╭ Offline demo [PASS] ──────────────────────────────────────────────────────────────╮
71
+ │ Confirmed IDOR, reflected XSS, and blind SSRF on the safe loopback mock. │
72
+ │ Steps 9 Pages 4 Endpoints 1 Test identities 3 Confirmed findings 4 │
73
+ │ Report: .../poch_selftest/agent_evidence/report.md │
74
+ ╰───────────────────────────────────────────────────────────────────────────────────╯
75
+ ```
76
+ *Record your own GIF in one command — see [`docs/DEMO.md`](docs/DEMO.md): `python selftest/run_agent_selftest.py --tui`.*
77
+
78
+ ## Why it's built to minimize ban risk
79
+ Bug hunters are rightly terrified of automated tools torching their reputation.
80
+ No tool can *guarantee* you won't be banned — but every design decision here is
81
+ aimed at reducing that risk:
82
+
83
+ 1. **One `scope.yaml` per program.** Every HTTP request the agent makes is checked
84
+ against it *before it leaves your machine*. Off-scope **host** → hard block. Scope
85
+ is matched by host (not port/path) — see caveats.
86
+ 2. **Non-destructive by default.** `DELETE/PUT/PATCH` are blocked unless you opt in.
87
+ `GET`/`POST` are allowed (login, and the business-logic/race checks use POST), so
88
+ it's not *purely* read-only — impact is *demonstrated*, not *maximized*. No mass
89
+ create/modify/delete to "prove" a bug.
90
+ 3. **Polite rate limiting.** One clean request that proves the bug beats a thousand
91
+ noisy ones. No scanner storm against prod.
92
+ 4. **Automatic token redaction.** Your `Cookie`/`Authorization` never land in a report.
93
+ 5. **Human-in-the-loop.** Sensitive actions (account creation, payload sends) ask first,
94
+ unless you opt into full-auto.
95
+ 6. **Evidence-based.** Nothing is a "finding" until a check *confirms* it. No hallucinated CVEs.
96
+
97
+ ## Limits & honest caveats
98
+ Real talk, so you can make an informed call before pointing this at a program:
99
+ - **Scope defaults to host-level, but can go finer.** `ScopeGuard` matches hostname by default
100
+ (any port, any path). Scope a port with a `host:port` pattern in `in_scope_hosts`, and block
101
+ paths with `out_of_scope_paths` (fnmatch) in `scope.yaml`.
102
+ - **Not purely read-only.** `GET`/`POST` are allowed; `check_business_logic` and the race test
103
+ send `POST`, and **`check_race_condition` fires a concurrent burst that intentionally skips the
104
+ polite throttle** (that's the test — it still counts against the budget). Those tools, and the
105
+ low-level `http_request`, are gated behind human approval by default.
106
+ - **Rate + budget are now shared per-target.** The rate limit and the `max_requests` budget are
107
+ enforced across *all* identities on one target (not per-session), so multiple accounts can't
108
+ collectively outrun them.
109
+ - **Evidence is scrubbed but still sensitive.** Logged bodies/URLs have passwords, tokens, and
110
+ JWTs redacted by default (`evidence.scrub_secrets`; set `log_bodies: false` to drop bodies
111
+ entirely). Test-account passwords/sessions are **not** written to the state DB unless you set
112
+ `persist_credentials: true`. Still treat the evidence dir as secret; wipe it with `poch clean`.
113
+ - **A cloud brain sees target data.** With `--provider claude|openai`, target responses (URLs,
114
+ status, body snippets, the agent's observations) are sent to that provider in prompts as the
115
+ agent reasons, and your API key is read from the environment (the run prints a notice). The
116
+ local Ollama brain keeps all of it on your machine. Full detail: [`SECURITY.md`](SECURITY.md).
117
+ - **The browser is fully scope-gated.** When a `guard` is attached, Playwright intercepts *every*
118
+ request the browser makes — documents, subresources, XHR/fetch, and each redirect hop — and
119
+ aborts anything out of scope (the number dropped is returned as `blocked_requests`). Trade-off:
120
+ a page that genuinely needs a third-party host (a CDN, an SSO origin) will have those requests
121
+ blocked until you add that host to `scope.yaml`.
122
+ - **Email verification isn't automated.** Account creation registers and logs in, but it does not
123
+ click a confirmation link. `Mailbox.wait_for_link` (mail.tm) exists but is not wired into the
124
+ default flow, and the offline `MockEmailProvider` is the default — so a target that requires a
125
+ verified email needs the link handled manually. See [`SECURITY.md`](SECURITY.md).
126
+
127
+ ## What it does
128
+ - **Maps** a target's attack surface (pages, forms, parameters) — scope-bound crawler.
129
+ - **Creates** the test accounts it needs (disposable email via mail.tm, multi-identity).
130
+ - **Reasons** with an LLM — local **Ollama** (free, default), **Claude**, or **OpenAI** — to pick what to test where.
131
+ - **Confirms** bugs non-destructively: IDOR/BOLA, broken access control, reflected XSS, **blind SSRF/XSS (OAST)**.
132
+ - **Writes** a submission-ready Markdown report with the raw evidence.
133
+
134
+ ## 30-second start (fully offline — no target, no API key, no model)
135
+ ```bash
136
+ python selftest/run_agent_selftest.py # scripted brain drives the real loop end-to-end
137
+ python selftest/run_agent_selftest.py --tui # ...with the live dashboard
138
+ python selftest/run_features_selftest.py # diffing / semantic-IDOR / OAST / browser handoff
139
+ python selftest/run_advanced_selftest.py # self-healing / attack-chains / race / deser / stealth
140
+ ```
141
+ It spins up a deliberately-vulnerable loopback app, then the agent recons it, makes
142
+ two accounts, **confirms IDOR + reflected XSS + a true per-user IDOR + blind SSRF**,
143
+ and writes a Markdown report (its path is printed at the end).
144
+
145
+ ## Quick start
146
+ ```bash
147
+ python poch.py demo # watch it confirm 4 bug classes on a safe built-in target
148
+ python poch.py doctor # check your setup (brain, deps, PATH)
149
+ ```
150
+ On Windows you can use the bundled launcher — `.\poch demo`, `.\poch doctor` — no install, no PATH setup.
151
+
152
+ ## Install
153
+ ```bash
154
+ python -m pip install poc-harness
155
+ python -m pip install "poc-harness[all]" # TUI, cloud LLM providers, and browser support
156
+ ```
157
+
158
+ The base install includes the `poch` command and required HTTP/YAML/HTML packages.
159
+ The `all` extra adds Rich for the dashboard, Anthropic/OpenAI clients, and Playwright
160
+ for SPA browser handoff. Install Chromium separately with `python -m playwright install chromium`.
161
+ For development from a clone, use `python -m pip install -e .` (or `python -m pip install -e ".[all]"`).
162
+
163
+ ## Run it for real (authorized targets only)
164
+ ```bash
165
+ poch init # interactive: asks program name, hosts, start URL, brain
166
+ poch scope # inspect the allowed hosts, paths, and request limits
167
+ poch doctor # check provider, dependencies, and project config
168
+ poch run --tui # auto-uses ./agent.yaml + ./profile.json from init
169
+ # --yes full-auto (skip approvals)
170
+ # --provider claude --model claude-opus-5 stronger brain (set ANTHROPIC_API_KEY)
171
+ ```
172
+ Review `scope.yaml` against the program policy before running. Scope config is a technical boundary, not authorization.
173
+ Or try a legal practice target right now — see [`templates/`](templates/) (OWASP Juice Shop, DVWA).
174
+
175
+ ## CLI (`poch`)
176
+ ```
177
+ poch demo run the agent on a safe built-in target — zero setup
178
+ poch doctor check environment + setup and suggest fixes
179
+ poch init set up a program (scope + config), interactively
180
+ poch run run the autonomous agent (auto-uses ./agent.yaml + ./profile.json)
181
+ poch recon map a target's attack surface (crawl only)
182
+ poch report build the Markdown report from an evidence dir
183
+ poch scope validate and show what a scope.yaml allows / blocks
184
+ poch state inspect an evidence/state.db (counts, findings, identities)
185
+ poch oast start a standalone out-of-band callback listener
186
+ poch clean delete an evidence directory (captured traffic, state, report)
187
+ poch selftest run the self-tests (all = offline: agent | features | advanced | security; or browser)
188
+ poch version show version + environment
189
+ ```
190
+ `poch <command> -h` for options. On Windows use `.\poch <command>` (bundled launcher) if the
191
+ bare `poch` isn't on PATH — or `python poch.py <command>`.
192
+
193
+ > The agent **cannot test anything `scope.yaml` doesn't authorize.** Autonomy changes
194
+ > what it *decides*, never what it's *allowed to touch*.
195
+
196
+ ## Headline features
197
+ | Feature | What it buys you |
198
+ |---|---|
199
+ | **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. |
200
+ | **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.) |
201
+ | **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. |
202
+ | **Live TUI dashboard** (`agent/dashboard.py`) | The `Plan → ScopeCheck → Act → Verdict` loop, live, powered by `rich`. |
203
+ | **Local-first brain** | Runs on your own Ollama for free; swap to Claude/OpenAI with one flag. |
204
+
205
+ ### From scanner to operator (Phase 3)
206
+ | Capability | What it buys you |
207
+ |---|---|
208
+ | **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. |
209
+ | **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. |
210
+ | **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. |
211
+ | **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. |
212
+ | **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. |
213
+ | **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. |
214
+
215
+ ## How the agent works
216
+ ```
217
+ plan (LLM picks a tool) → authorize (governance / you) → act (through ScopeGuard)
218
+ → observe → record (SQLite state + audit log) → repeat until finish/budget
219
+ ```
220
+ All capability lives in `agent/tools.py`; all judgment in the LLM; all safety in
221
+ `agent/governance.py` + `harness.ScopeGuard`. Tools today: `recon_crawl`, `list_surface`,
222
+ `create_identity`, `browser_handoff`, `http_request` (with `heal`), `run_attack_chain`,
223
+ `check_idor`, `check_idor_semantic`, `check_access_control`, `check_reflected_xss`,
224
+ `check_blind_oast`, `check_business_logic`, `check_race_condition`, `check_deserialization`,
225
+ `record_note`, `finish`.
226
+
227
+ ## Add a new bug class in ~40 lines ⭐ (PRs welcome)
228
+ A check is just a function that takes guarded session(s) + a `target`, sends the
229
+ minimal request(s), decides confirmed/not, and records a verdict:
230
+
231
+ ```python
232
+ # checks/open_redirect.py
233
+ from harness import record_verdict
234
+
235
+ def run(guard, evidence_dir, target, sess):
236
+ canary = "https://evil.example"
237
+ r = sess.get(target["url_template"].format(payload=canary), allow_redirects=False)
238
+ location = r.headers.get("Location", "")
239
+ confirmed = r.status_code in (301, 302, 307, 308) and location.startswith(canary)
240
+ record_verdict(evidence_dir, {
241
+ "check": "open_redirect", "url": r.request.url, "confirmed": confirmed,
242
+ "severity_hint": "Medium" if confirmed else "n/a",
243
+ "reason": f"Redirects to attacker-controlled {location!r}" if confirmed
244
+ else "No external redirect — safe.",
245
+ })
246
+ return confirmed
247
+ ```
248
+ Then expose it as one `Tool(...)` in `agent/tools.py` and the agent can use it.
249
+ That's the whole plugin story. Good next ones: CSRF, JWT/auth flaws, read-only SQLi,
250
+ SSTI, CORS misconfig.
251
+
252
+ ## Project layout
253
+ - `harness.py` — ScopeGuard + GuardedSession + evidence capture (the safety spine).
254
+ - `agent/` — orchestrator loop, pluggable LLM, SQLite state, governance, tools, dashboard, diffing, planner+chain (multi-step), healing (self-correction), payloads.
255
+ - `recon/` — scope-bound crawler (`crawler.py`) + browser handoff (`browser.py`).
256
+ - `identity/` — mail.tm temp-email + multi-account session manager.
257
+ - `oast/` — out-of-band callback listener for blind vulns.
258
+ - `checks/` — the confirmable bug modules.
259
+ - `report.py` — evidence + verdicts → Markdown.
260
+ - `cli/` — the `poch` command (run/recon/report/scope/state/oast/init/selftest).
261
+ - `templates/` — ready-to-use Juice Shop / DVWA configs.
262
+ - `selftest/` — loopback vulnerable app + offline proofs.
263
+
264
+ ## The one boundary
265
+ It only ever talks to hosts a program has authorized you to test. Keep it that way,
266
+ and this tool keeps you *paid, not banned*.
@@ -0,0 +1,222 @@
1
+ # poc-harness — the polite AI bug-bounty hunter 🕵️
2
+
3
+ **An autonomous, black-box web pentest agent that confirms *real* bugs with evidence — engineered to minimize ban risk.**
4
+
5
+ Most "AI hacking" tools are noisy scanners that hammer production, hallucinate
6
+ findings, and get your HackerOne/Bugcrowd account suspended. poc-harness is the
7
+ opposite: a scope-gated, mostly read-only, rate-limited agent that proves a vulnerability
8
+ the way a triager wants to see it — with the raw request/response — and stops.
9
+ It is a careful tool, not a magic shield — read **[Limits & honest caveats](#limits--honest-caveats)** before you point it at anything.
10
+
11
+ ```text
12
+ ╭────────────────────────────── POCH / LIVE RUN ────────────────────────────────────╮
13
+ │ POCH MockShop ollama / qwen35-9b-256k │
14
+ │ Goal: map the surface and safely confirm access-control and injection issues │
15
+ │ Step 8/40 ##################---- 2.4s │
16
+ │ Plan -> ScopeCheck -> Act -> Verdict │
17
+ │ # action scope verdict note │
18
+ │ 5 check_idor allow CONFIRMED /v1/orders/{id} │
19
+ │ 7 check_idor_semantic allow CONFIRMED marker-free response comparison │
20
+ │ 8 check_blind_oast allow CONFIRMED callback received │
21
+ │ │
22
+ │ 4 1 3 4 │
23
+ │ PAGES ENDPOINTS IDENTITIES CONFIRMED │
24
+ ╰───────────────────────────────────────────────────────────────────────────────────╯
25
+
26
+ ╭ Offline demo [PASS] ──────────────────────────────────────────────────────────────╮
27
+ │ Confirmed IDOR, reflected XSS, and blind SSRF on the safe loopback mock. │
28
+ │ Steps 9 Pages 4 Endpoints 1 Test identities 3 Confirmed findings 4 │
29
+ │ Report: .../poch_selftest/agent_evidence/report.md │
30
+ ╰───────────────────────────────────────────────────────────────────────────────────╯
31
+ ```
32
+ *Record your own GIF in one command — see [`docs/DEMO.md`](docs/DEMO.md): `python selftest/run_agent_selftest.py --tui`.*
33
+
34
+ ## Why it's built to minimize ban risk
35
+ Bug hunters are rightly terrified of automated tools torching their reputation.
36
+ No tool can *guarantee* you won't be banned — but every design decision here is
37
+ aimed at reducing that risk:
38
+
39
+ 1. **One `scope.yaml` per program.** Every HTTP request the agent makes is checked
40
+ against it *before it leaves your machine*. Off-scope **host** → hard block. Scope
41
+ is matched by host (not port/path) — see caveats.
42
+ 2. **Non-destructive by default.** `DELETE/PUT/PATCH` are blocked unless you opt in.
43
+ `GET`/`POST` are allowed (login, and the business-logic/race checks use POST), so
44
+ it's not *purely* read-only — impact is *demonstrated*, not *maximized*. No mass
45
+ create/modify/delete to "prove" a bug.
46
+ 3. **Polite rate limiting.** One clean request that proves the bug beats a thousand
47
+ noisy ones. No scanner storm against prod.
48
+ 4. **Automatic token redaction.** Your `Cookie`/`Authorization` never land in a report.
49
+ 5. **Human-in-the-loop.** Sensitive actions (account creation, payload sends) ask first,
50
+ unless you opt into full-auto.
51
+ 6. **Evidence-based.** Nothing is a "finding" until a check *confirms* it. No hallucinated CVEs.
52
+
53
+ ## Limits & honest caveats
54
+ Real talk, so you can make an informed call before pointing this at a program:
55
+ - **Scope defaults to host-level, but can go finer.** `ScopeGuard` matches hostname by default
56
+ (any port, any path). Scope a port with a `host:port` pattern in `in_scope_hosts`, and block
57
+ paths with `out_of_scope_paths` (fnmatch) in `scope.yaml`.
58
+ - **Not purely read-only.** `GET`/`POST` are allowed; `check_business_logic` and the race test
59
+ send `POST`, and **`check_race_condition` fires a concurrent burst that intentionally skips the
60
+ polite throttle** (that's the test — it still counts against the budget). Those tools, and the
61
+ low-level `http_request`, are gated behind human approval by default.
62
+ - **Rate + budget are now shared per-target.** The rate limit and the `max_requests` budget are
63
+ enforced across *all* identities on one target (not per-session), so multiple accounts can't
64
+ collectively outrun them.
65
+ - **Evidence is scrubbed but still sensitive.** Logged bodies/URLs have passwords, tokens, and
66
+ JWTs redacted by default (`evidence.scrub_secrets`; set `log_bodies: false` to drop bodies
67
+ entirely). Test-account passwords/sessions are **not** written to the state DB unless you set
68
+ `persist_credentials: true`. Still treat the evidence dir as secret; wipe it with `poch clean`.
69
+ - **A cloud brain sees target data.** With `--provider claude|openai`, target responses (URLs,
70
+ status, body snippets, the agent's observations) are sent to that provider in prompts as the
71
+ agent reasons, and your API key is read from the environment (the run prints a notice). The
72
+ local Ollama brain keeps all of it on your machine. Full detail: [`SECURITY.md`](SECURITY.md).
73
+ - **The browser is fully scope-gated.** When a `guard` is attached, Playwright intercepts *every*
74
+ request the browser makes — documents, subresources, XHR/fetch, and each redirect hop — and
75
+ aborts anything out of scope (the number dropped is returned as `blocked_requests`). Trade-off:
76
+ a page that genuinely needs a third-party host (a CDN, an SSO origin) will have those requests
77
+ blocked until you add that host to `scope.yaml`.
78
+ - **Email verification isn't automated.** Account creation registers and logs in, but it does not
79
+ click a confirmation link. `Mailbox.wait_for_link` (mail.tm) exists but is not wired into the
80
+ default flow, and the offline `MockEmailProvider` is the default — so a target that requires a
81
+ verified email needs the link handled manually. See [`SECURITY.md`](SECURITY.md).
82
+
83
+ ## What it does
84
+ - **Maps** a target's attack surface (pages, forms, parameters) — scope-bound crawler.
85
+ - **Creates** the test accounts it needs (disposable email via mail.tm, multi-identity).
86
+ - **Reasons** with an LLM — local **Ollama** (free, default), **Claude**, or **OpenAI** — to pick what to test where.
87
+ - **Confirms** bugs non-destructively: IDOR/BOLA, broken access control, reflected XSS, **blind SSRF/XSS (OAST)**.
88
+ - **Writes** a submission-ready Markdown report with the raw evidence.
89
+
90
+ ## 30-second start (fully offline — no target, no API key, no model)
91
+ ```bash
92
+ python selftest/run_agent_selftest.py # scripted brain drives the real loop end-to-end
93
+ python selftest/run_agent_selftest.py --tui # ...with the live dashboard
94
+ python selftest/run_features_selftest.py # diffing / semantic-IDOR / OAST / browser handoff
95
+ python selftest/run_advanced_selftest.py # self-healing / attack-chains / race / deser / stealth
96
+ ```
97
+ It spins up a deliberately-vulnerable loopback app, then the agent recons it, makes
98
+ two accounts, **confirms IDOR + reflected XSS + a true per-user IDOR + blind SSRF**,
99
+ and writes a Markdown report (its path is printed at the end).
100
+
101
+ ## Quick start
102
+ ```bash
103
+ python poch.py demo # watch it confirm 4 bug classes on a safe built-in target
104
+ python poch.py doctor # check your setup (brain, deps, PATH)
105
+ ```
106
+ On Windows you can use the bundled launcher — `.\poch demo`, `.\poch doctor` — no install, no PATH setup.
107
+
108
+ ## Install
109
+ ```bash
110
+ python -m pip install poc-harness
111
+ python -m pip install "poc-harness[all]" # TUI, cloud LLM providers, and browser support
112
+ ```
113
+
114
+ The base install includes the `poch` command and required HTTP/YAML/HTML packages.
115
+ The `all` extra adds Rich for the dashboard, Anthropic/OpenAI clients, and Playwright
116
+ for SPA browser handoff. Install Chromium separately with `python -m playwright install chromium`.
117
+ For development from a clone, use `python -m pip install -e .` (or `python -m pip install -e ".[all]"`).
118
+
119
+ ## Run it for real (authorized targets only)
120
+ ```bash
121
+ poch init # interactive: asks program name, hosts, start URL, brain
122
+ poch scope # inspect the allowed hosts, paths, and request limits
123
+ poch doctor # check provider, dependencies, and project config
124
+ poch run --tui # auto-uses ./agent.yaml + ./profile.json from init
125
+ # --yes full-auto (skip approvals)
126
+ # --provider claude --model claude-opus-5 stronger brain (set ANTHROPIC_API_KEY)
127
+ ```
128
+ Review `scope.yaml` against the program policy before running. Scope config is a technical boundary, not authorization.
129
+ Or try a legal practice target right now — see [`templates/`](templates/) (OWASP Juice Shop, DVWA).
130
+
131
+ ## CLI (`poch`)
132
+ ```
133
+ poch demo run the agent on a safe built-in target — zero setup
134
+ poch doctor check environment + setup and suggest fixes
135
+ poch init set up a program (scope + config), interactively
136
+ poch run run the autonomous agent (auto-uses ./agent.yaml + ./profile.json)
137
+ poch recon map a target's attack surface (crawl only)
138
+ poch report build the Markdown report from an evidence dir
139
+ poch scope validate and show what a scope.yaml allows / blocks
140
+ poch state inspect an evidence/state.db (counts, findings, identities)
141
+ poch oast start a standalone out-of-band callback listener
142
+ poch clean delete an evidence directory (captured traffic, state, report)
143
+ poch selftest run the self-tests (all = offline: agent | features | advanced | security; or browser)
144
+ poch version show version + environment
145
+ ```
146
+ `poch <command> -h` for options. On Windows use `.\poch <command>` (bundled launcher) if the
147
+ bare `poch` isn't on PATH — or `python poch.py <command>`.
148
+
149
+ > The agent **cannot test anything `scope.yaml` doesn't authorize.** Autonomy changes
150
+ > what it *decides*, never what it's *allowed to touch*.
151
+
152
+ ## Headline features
153
+ | Feature | What it buys you |
154
+ |---|---|
155
+ | **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. |
156
+ | **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.) |
157
+ | **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. |
158
+ | **Live TUI dashboard** (`agent/dashboard.py`) | The `Plan → ScopeCheck → Act → Verdict` loop, live, powered by `rich`. |
159
+ | **Local-first brain** | Runs on your own Ollama for free; swap to Claude/OpenAI with one flag. |
160
+
161
+ ### From scanner to operator (Phase 3)
162
+ | Capability | What it buys you |
163
+ |---|---|
164
+ | **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. |
165
+ | **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. |
166
+ | **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. |
167
+ | **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. |
168
+ | **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. |
169
+ | **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. |
170
+
171
+ ## How the agent works
172
+ ```
173
+ plan (LLM picks a tool) → authorize (governance / you) → act (through ScopeGuard)
174
+ → observe → record (SQLite state + audit log) → repeat until finish/budget
175
+ ```
176
+ All capability lives in `agent/tools.py`; all judgment in the LLM; all safety in
177
+ `agent/governance.py` + `harness.ScopeGuard`. Tools today: `recon_crawl`, `list_surface`,
178
+ `create_identity`, `browser_handoff`, `http_request` (with `heal`), `run_attack_chain`,
179
+ `check_idor`, `check_idor_semantic`, `check_access_control`, `check_reflected_xss`,
180
+ `check_blind_oast`, `check_business_logic`, `check_race_condition`, `check_deserialization`,
181
+ `record_note`, `finish`.
182
+
183
+ ## Add a new bug class in ~40 lines ⭐ (PRs welcome)
184
+ A check is just a function that takes guarded session(s) + a `target`, sends the
185
+ minimal request(s), decides confirmed/not, and records a verdict:
186
+
187
+ ```python
188
+ # checks/open_redirect.py
189
+ from harness import record_verdict
190
+
191
+ def run(guard, evidence_dir, target, sess):
192
+ canary = "https://evil.example"
193
+ r = sess.get(target["url_template"].format(payload=canary), allow_redirects=False)
194
+ location = r.headers.get("Location", "")
195
+ confirmed = r.status_code in (301, 302, 307, 308) and location.startswith(canary)
196
+ record_verdict(evidence_dir, {
197
+ "check": "open_redirect", "url": r.request.url, "confirmed": confirmed,
198
+ "severity_hint": "Medium" if confirmed else "n/a",
199
+ "reason": f"Redirects to attacker-controlled {location!r}" if confirmed
200
+ else "No external redirect — safe.",
201
+ })
202
+ return confirmed
203
+ ```
204
+ Then expose it as one `Tool(...)` in `agent/tools.py` and the agent can use it.
205
+ That's the whole plugin story. Good next ones: CSRF, JWT/auth flaws, read-only SQLi,
206
+ SSTI, CORS misconfig.
207
+
208
+ ## Project layout
209
+ - `harness.py` — ScopeGuard + GuardedSession + evidence capture (the safety spine).
210
+ - `agent/` — orchestrator loop, pluggable LLM, SQLite state, governance, tools, dashboard, diffing, planner+chain (multi-step), healing (self-correction), payloads.
211
+ - `recon/` — scope-bound crawler (`crawler.py`) + browser handoff (`browser.py`).
212
+ - `identity/` — mail.tm temp-email + multi-account session manager.
213
+ - `oast/` — out-of-band callback listener for blind vulns.
214
+ - `checks/` — the confirmable bug modules.
215
+ - `report.py` — evidence + verdicts → Markdown.
216
+ - `cli/` — the `poch` command (run/recon/report/scope/state/oast/init/selftest).
217
+ - `templates/` — ready-to-use Juice Shop / DVWA configs.
218
+ - `selftest/` — loopback vulnerable app + offline proofs.
219
+
220
+ ## The one boundary
221
+ It only ever talks to hosts a program has authorized you to test. Keep it that way,
222
+ and this tool keeps you *paid, not banned*.
@@ -0,0 +1,18 @@
1
+ """
2
+ agent/ — the autonomous orchestration layer for poc-harness.
3
+
4
+ This package turns the existing safety + evidence + checks core into a
5
+ black-box AI penetration-testing agent:
6
+
7
+ config.py engine + LLM configuration
8
+ llm.py pluggable reasoning engine (Ollama / Claude / OpenAI / Scripted)
9
+ state.py SQLite memory: sitemap, endpoints, identities, sessions, findings
10
+ governance.py permission manager + human-in-the-loop over the Scope Guard
11
+ tools.py the tool registry the agent is allowed to call
12
+ orchestrator.py the plan -> act -> observe -> record loop
13
+ cli.py command-line entry point
14
+
15
+ Design principles (from the system spec):
16
+ black-box, modular, tool-agnostic, stateful, human-in-the-loop, evidence-based.
17
+ Every network action still passes through harness.ScopeGuard first.
18
+ """
@@ -0,0 +1,86 @@
1
+ """
2
+ Chain execution — the dynamic phase of graph-based planning.
3
+
4
+ Runs a PlanGraph in dependency order. Each step's result is captured into a
5
+ Blackboard; later steps reference those values via ${var} placeholders, so the
6
+ output of one step becomes the input of the next (leak -> reuse -> escalate).
7
+ """
8
+ from __future__ import annotations
9
+
10
+ import re
11
+
12
+ VAR_RE = re.compile(r"\$\{([^}]+)\}")
13
+
14
+
15
+ def dig(obj, path: str):
16
+ """Walk a dotted path into nested dicts/lists: 'json.user.token' or 'list.0.id'."""
17
+ cur = obj
18
+ for part in path.split("."):
19
+ if isinstance(cur, dict) and part in cur:
20
+ cur = cur[part]
21
+ elif isinstance(cur, list) and part.isdigit() and int(part) < len(cur):
22
+ cur = cur[int(part)]
23
+ else:
24
+ return None
25
+ return cur
26
+
27
+
28
+ class Blackboard:
29
+ def __init__(self, initial: dict | None = None):
30
+ self.vars = dict(initial or {})
31
+
32
+ def set(self, name, value):
33
+ self.vars[name] = value
34
+
35
+ def resolve(self, obj):
36
+ """Recursively replace ${var} in strings. A string that is exactly '${x}'
37
+ returns the raw (possibly non-string) value; otherwise it's substituted in."""
38
+ if isinstance(obj, str):
39
+ m = VAR_RE.fullmatch(obj.strip())
40
+ if m:
41
+ return dig_vars(self.vars, m.group(1))
42
+ return VAR_RE.sub(lambda mm: str(dig_vars(self.vars, mm.group(1)) or ""), obj)
43
+ if isinstance(obj, dict):
44
+ return {k: self.resolve(v) for k, v in obj.items()}
45
+ if isinstance(obj, list):
46
+ return [self.resolve(v) for v in obj]
47
+ return obj
48
+
49
+
50
+ def dig_vars(vars: dict, name: str):
51
+ if name in vars:
52
+ return vars[name]
53
+ return dig(vars, name) # supports ${token} and ${result.json.id}
54
+
55
+
56
+ def run_chain(graph, toolbox, ctx, blackboard: Blackboard | None = None,
57
+ on_event=None) -> dict:
58
+ """
59
+ Execute every node in topological order. Returns a summary:
60
+ {steps:[...], vars:{...}, ok:bool}
61
+ A node fails soft: its error is recorded and the chain continues (later nodes
62
+ that needed its output will see empty values — visible in the summary).
63
+ """
64
+ bb = blackboard or Blackboard()
65
+ steps = []
66
+ for node in graph.topo_order():
67
+ if node.tool not in toolbox:
68
+ steps.append({"id": node.id, "ok": False, "error": f"unknown tool {node.tool}"})
69
+ continue
70
+ args = bb.resolve(node.args)
71
+ if on_event:
72
+ on_event({"kind": "chain_step", "id": node.id, "tool": node.tool, "args": args})
73
+ try:
74
+ result = toolbox[node.tool].handler(ctx, **args)
75
+ except Exception as e:
76
+ steps.append({"id": node.id, "tool": node.tool, "ok": False, "error": str(e)})
77
+ continue
78
+ captured = {}
79
+ for var, path in (node.capture or {}).items():
80
+ val = dig(result, path)
81
+ bb.set(var, val)
82
+ captured[var] = val
83
+ steps.append({"id": node.id, "tool": node.tool, "ok": bool(result.get("ok", True)),
84
+ "captured": captured, "result_status": result.get("status"),
85
+ "confirmed": result.get("confirmed")})
86
+ return {"ok": True, "steps": steps, "vars": bb.vars}