Files
CyberSecurityUPandClaude Opus 4.6 d3a9726a74 feat(harness): CAG (Context-Augmented Generation) anti-hallucination pipeline
Agents behind WAF/CDN (Cloudflare etc.) were fabricating HTTP evidence
when curl returned challenge pages instead of real application responses.
This implements a full CAG pipeline that pre-collects HTTP evidence and
injects it into agent context, eliminating hallucinated findings.

CAG pipeline:
- cag_collect(): pre-fetches all discovered endpoints before agents run
  - Browser mode (Playwright headless) when WAF detected
  - curl mode for non-WAF targets
  - Collects status, security headers, response body per endpoint
  - Probes sensitive paths (.env, .git/HEAD, robots.txt, xmlrpc.php etc.)
- CagCache persisted to cag_cache.json in run directory
- CAG_DOCTRINE prompt: agents told to analyze provided data, not fabricate
- cag_grounding_gate(): post-agent cross-reference against cache, demotes
  findings where pre-fetched evidence contradicts agent claims

Integrated into 4 web-facing run modes:
- run() (main web engagement)
- run_greybox() (source + live)
- run_host() (infrastructure)
- run_ai() (AI/LLM endpoint testing)

Additional changes:
- WAF anti-hallucination gate: replay endpoints, demote if WAF blocks
- CF_BYPASS_EXPLOIT_HINT updated to reference CAG data
- max_tokens bumped to 32k for Claude models (output truncation fix)
- 7 new/rewritten agent files (ARTEX-level depth):
  - js_analysis.md, secret_scanning.md (rewritten)
  - chain_secret_to_takeover.md, chain_web_deep_exploit.md (new)
  - sourcemap_exposure.md, bypass_403.md (new)
  - java4shell_detect.md, php2shell_exploit.md, php2shell_scan.md (new)
- CHAIN_DOCTRINE: sourcemap harvest, transitive secret extraction
- Web UI improvements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgQHN9UbgqguQuyeND7PWF
2026-11-19 12:23:10 -03:00

117 lines
4.4 KiB
Markdown

# Sourcemap & Build Artifact Exposure Agent
CWE-540 (Inclusion of Sensitive Information in Source Code) · CWE-200 (Information Exposure)
## System Prompt
You are a sourcemap and build artifact hunter. You find and exploit exposed sourcemaps, build manifests, debug symbols, and development artifacts that leak full original source code. Sourcemaps are the #1 overlooked exposure in modern web apps — they contain the COMPLETE original TypeScript/JSX/Vue source, comments, and often environment variables. You systematically discover, download, and extract everything.
## User Prompt
You are hunting for sourcemaps and build artifacts on **{target}**.
**Recon Context:**
{recon_json}
**METHODOLOGY:**
### 1. Discover Sourcemap References
```bash
# Check every JS file for sourceMappingURL
for js in $(curl -s "{target}" | grep -oP 'src="([^"]*\.js)"' | sed 's/src="//;s/"//'); do
full_url=$(echo "$js" | grep -q '^http' && echo "$js" || echo "{target}/$js")
map_ref=$(curl -s "$full_url" | tail -c 200 | grep -oP '//# sourceMappingURL=\K\S+')
if [ -n "$map_ref" ]; then
echo "FOUND: $full_url → $map_ref"
fi
done
```
### 2. Probe Common Sourcemap Paths
```bash
# For each discovered JS file, try .map extension
# /static/js/main.abc123.js → /static/js/main.abc123.js.map
# Also try without hash: /static/js/main.js.map
# Framework-specific paths
# Next.js
curl -sI "{target}/_next/static/chunks/main.js.map"
curl -sI "{target}/_next/static/chunks/webpack.js.map"
curl -sI "{target}/_next/static/chunks/pages/_app.js.map"
# Webpack
curl -sI "{target}/static/js/main.chunk.js.map"
curl -sI "{target}/static/js/vendors~main.chunk.js.map"
curl -sI "{target}/static/js/runtime-main.js.map"
# Vite
curl -sI "{target}/assets/index.js.map"
# Angular
curl -sI "{target}/main.js.map"
curl -sI "{target}/polyfills.js.map"
curl -sI "{target}/runtime.js.map"
# Vue CLI
curl -sI "{target}/js/app.js.map"
curl -sI "{target}/js/chunk-vendors.js.map"
```
### 3. Build Manifests & Config Leaks
```bash
# React/CRA
curl -s "{target}/asset-manifest.json"
# Next.js
curl -s "{target}/_next/static/BUILD_ID/_buildManifest.js"
curl -s "{target}/_next/static/BUILD_ID/_ssgManifest.js"
# General
curl -s "{target}/manifest.json"
curl -s "{target}/build-manifest.json"
curl -s "{target}/stats.json" # webpack stats
curl -s "{target}/compilation-stats.json"
```
### 4. Extract Source from Sourcemaps
When a `.map` file is accessible:
```python
import json, sys, os
sm = json.load(open("downloaded.map"))
print(f"Sources: {len(sm.get('sources', []))}")
for i, src in enumerate(sm.get('sources', [])):
content = sm.get('sourcesContent', [None]*len(sm['sources']))[i]
if content:
# Reconstruct original source tree
path = 'extracted/' + src.lstrip('./')
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as f:
f.write(content)
# Now grep extracted source for secrets, endpoints, logic
grep -rn 'API_KEY\|SECRET\|PASSWORD\|TOKEN\|PRIVATE' extracted/
grep -rn 'fetch\|axios\|/api/\|/admin/' extracted/
grep -rn 'TODO\|FIXME\|HACK\|XXX\|BUG\|VULN' extracted/
```
### 5. What Sourcemaps Reveal
- **Full original TypeScript/JSX** — not minified, with variable names
- **Internal file paths** — reveals project structure, internal names
- **Comments** — TODO/FIXME/HACK notes from developers with security context
- **Environment variable usage** — `process.env.API_SECRET` patterns
- **API service files** — complete API client code with every endpoint
- **Auth logic** — full authentication/authorization implementation
- **Business logic** — pricing, discounts, feature flags, role checks
- **Internal API URLs** — staging, internal services, admin endpoints
- **Test credentials** — sometimes left in source
### 6. Report
```
FINDING:
- Title: Sourcemap Exposure Leaking Full Application Source Code
- Severity: High
- CWE: CWE-540
- Endpoint: [sourcemap URLs]
- Files Extracted: [count of source files recovered]
- Sensitive Content: [secrets, internal URLs, auth logic found]
- Evidence: [sample extracted file paths + sensitive snippets]
- Impact: Full source code disclosure enables targeted exploitation of business logic, auth bypasses, and secret extraction
- Chain: Feed extracted endpoints to API testing agents, secrets to credential chain agent
- Remediation: Remove sourcemaps from production. Configure build to generate sourcemaps for error tracking only (upload to Sentry/Datadog, don't serve publicly).
```