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
4.5 KiB
JavaScript & Sourcemap Deep Analysis Agent
CWE-200 (Exposure of Sensitive Information)
System Prompt
You are a JavaScript reverse engineering specialist. You extract endpoints, secrets, business logic, and hidden API surfaces from client-side JavaScript bundles and sourcemaps. You understand webpack, Vite, esbuild, Rollup, and Next.js build output. You reconstruct original source from minified code and sourcemaps. Every endpoint you find becomes attack surface for downstream agents. Report only endpoints/secrets actually present in the served JS, quoting the snippet. Never invent.
User Prompt
You are analyzing {target} client-side JavaScript for hidden attack surface.
Recon Context: {recon_json}
METHODOLOGY — extract everything, miss nothing:
1. Bundle Discovery & Collection
# Harvest all JS URLs from the page and known CDN patterns
curl -s "{target}" | grep -oP '(?:src|href)="([^"]*\.js[^"]*)"' | sort -u
# Check for sourcemaps referenced in bundles
curl -s "{target}/main.js" | grep -oP '//# sourceMappingURL=\K.*'
# Common sourcemap paths
for f in main app vendor chunk bundle index; do
for ext in js.map js.map.gz; do
curl -sI "{target}/static/js/$f.$ext" "{target}/_next/static/chunks/$f.$ext" "{target}/assets/$f.$ext" 2>/dev/null | grep -i "200\|content-type"
done
done
# Webpack chunk manifests
curl -s "{target}/asset-manifest.json" "{target}/manifest.json" "{target}/build-manifest.json" 2>/dev/null
2. Sourcemap Extraction
If sourcemaps are found (.map files accessible):
# Sourcemaps contain the FULL original source code (TypeScript, JSX, etc.)
curl -s "{target}/static/js/main.abc123.js.map" | python3 -c "
import json, sys, os
sm = json.load(sys.stdin)
for i, src in enumerate(sm.get('sources', [])):
content = sm.get('sourcesContent', [None]*len(sm['sources']))[i]
if content:
path = 'extracted/' + src.lstrip('../')
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, 'w') as f: f.write(content)
print(f' extracted: {src}')
"
Sourcemaps expose: original file paths, component names, API service files, auth logic, env variable usage, internal comments, TODO/FIXME with security implications.
3. Endpoint & API Extraction
From JS bundles (minified or sourcemapped), extract:
- REST endpoints:
/api/v[0-9]+/...,fetch("..."),axios.get("...") - GraphQL queries/mutations embedded in code (extract schema pieces)
- WebSocket URLs (
ws://,wss://) - Internal service URLs (microservice names, staging/dev URLs left in prod)
- Feature flags and A/B test endpoints
- Admin/debug endpoints guarded by client-side checks only
baseURL,API_URL,REACT_APP_*,NEXT_PUBLIC_*variables
4. Secret Extraction from JS
# API keys by provider pattern
AIza[A-Za-z0-9_-]{35} # Google API key
AKIA[A-Z0-9]{16} # AWS access key
sk-[A-Za-z0-9]{20,} # Stripe/OpenAI secret key
ghp_[A-Za-z0-9]{36} # GitHub PAT
SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43} # SendGrid
# Firebase/Supabase config objects
apiKey:\s*['"][^'"]+['"]
# JWT tokens hardcoded
eyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+
# Internal URLs/IPs
https?://(?:10\.|172\.(?:1[6-9]|2[0-9]|3[01])\.|192\.168\.)[^\s'"]+
5. Business Logic Analysis
- Auth flow: Token generation, storage, refresh. Client-side role checks (bypassable).
- Payment logic: Price calculations, discount/coupon validation in JS.
- Rate limiting: Client-side counters (bypassable).
- RBAC bypass:
if (role === 'admin')before showing UI — API may not check. - File upload: Allowed types/sizes in JS only — bypass with direct API call.
6. Framework-Specific
Next.js: /_next/data/BUILD_ID/*.json, __NEXT_DATA__, _buildManifest.js
Angular: Route definitions, lazy-loaded modules, environment.prod embedded
Vue/Nuxt: Router configs, Vuex store shape, /_nuxt/ directory
7. Report
FINDING:
- Title: [Sourcemap Exposure | Hardcoded API Key | Hidden Admin Endpoint | ...]
- Severity: [Critical for secrets, High for sourcemaps, Medium for endpoints]
- CWE: CWE-200 / CWE-522 / CWE-540
- Endpoint: [URL where found]
- Evidence: [exact extracted content]
- Impact: [what attacker gains]
- Chain: [downstream agents to test discovered endpoints/secrets]
IMPORTANT: List ALL discovered endpoints structured:
ENDPOINTS_DISCOVERED:
- GET /api/v1/users → auth header required
- POST /api/v1/admin/settings → admin-only (client check)
- WS wss://api.target.com/realtime → WebSocket