Cross Site Scripting
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications. XSS enables attackers to inject client-side scripts into web pages viewed by other users.
Summary
Methodology
Cross-Site Scripting (XSS) is a type of computer security vulnerability typically found in web applications. XSS allows attackers to inject malicious code into a website, which is then executed in the browser of anyone who visits the site. This can allow attackers to steal sensitive information, such as user login credentials, or to perform other malicious actions.
There are 3 main types of XSS attacks:
Reflected XSS: In a reflected XSS attack, the malicious code is embedded in a link that is sent to the victim. When the victim clicks on the link, the code is executed in their browser. For example, an attacker could create a link that contains malicious JavaScript, and send it to the victim in an email. When the victim clicks on the link, the JavaScript code is executed in their browser, allowing the attacker to perform various actions, such as stealing their login credentials.
Stored XSS: In a stored XSS attack, the malicious code is stored on the server, and is executed every time the vulnerable page is accessed. For example, an attacker could inject malicious code into a comment on a blog post. When other users view the blog post, the malicious code is executed in their browsers, allowing the attacker to perform various actions.
DOM-based XSS: is a type of XSS attack that occurs when a vulnerable web application modifies the DOM (Document Object Model) in the user's browser. This can happen, for example, when a user input is used to update the page's HTML or JavaScript code in some way. In a DOM-based XSS attack, the malicious code is not sent to the server, but is instead executed directly in the user's browser. This can make it difficult to detect and prevent these types of attacks, because the server does not have any record of the malicious code.
To prevent XSS attacks, it is important to properly validate and sanitize user input. This means ensuring that all input meets the necessary criteria, and removing any potentially dangerous characters or code. It is also important to escape special characters in user input before rendering it in the browser, to prevent the browser from interpreting it as code.
Proof of Concept
When exploiting an XSS vulnerability, it’s more effective to demonstrate a complete exploitation scenario that could lead to account takeover or sensitive data exfiltration. Instead of simply reporting an XSS with an alert payload, aim to capture valuable data, such as payment information, personal identifiable information (PII), session cookies, or credentials.
Data Grabber
Obtains the administrator cookie or sensitive access token, the following payload will send it to a controlled page.
Write the collected data into a file.
CORS
UI Redressing
Leverage the XSS to modify the HTML content of the page in order to display a fake login form.
Javascript Keylogger
Another way to collect sensitive data is to set a javascript keylogger.
Other Ways
More exploits at http://www.xss-payloads.com/payloads-list.html?a#category=all:
Identify an XSS Endpoint
This payload opens the debugger in the developer console rather than triggering a popup alert box.
Modern applications with content hosting can use sandbox domains
to safely host various types of user-generated content. Many of these sandboxes are specifically meant to isolate user-uploaded HTML, JavaScript, or Flash applets and make sure that they can't access any user data.
For this reason, it's better to use alert(document.domain) or alert(window.origin) rather than alert(1) as default XSS payload in order to know in which scope the XSS is actually executing.
Better payload replacing <script>alert(1)</script>:
While alert() is nice for reflected XSS it can quickly become a burden for stored XSS because it requires to close the popup for each execution, so console.log() can be used instead to display a message in the console of the developer console (doesn't require any interaction).
Example:
References:
Tools
Most tools are also suitable for blind XSS attacks:
XSSStrike: Very popular but unfortunately not very well maintained
xsser: Utilizes a headless browser to detect XSS vulnerabilities
Dalfox: Extensive functionality and extremely fast thanks to the implementation in Go
XSpear: Similar to Dalfox but based on Ruby
domdig: Headless Chrome XSS Tester
XSS in HTML/Applications
Common Payloads
XSS using HTML5 tags
XSS using a remote JS
XSS in Hidden Input
in newer browsers : firefox-130/chrome-108
XSS in Uppercase Output
DOM Based XSS
Based on a DOM XSS sink.
XSS in JS Context
XSS in Wrappers for URI
Wrapper javascript
Wrapper data
Wrapper vbscript
only IE
XSS in Files
NOTE: The XML CDATA section is used here so that the JavaScript payload will not be treated as XML markup.
XSS in XML
XSS in SVG
Simple script. Codename: green triangle
More comprehensive payload with svg tag attribute, desc script, foreignObject script, foreignObject iframe, title script, animatetransform event and simple script. Codename: red ligthning. Author: noraj.
Short SVG Payload
Nesting SVG and XSS
Including a remote SVG image in a SVG works but won't trigger the XSS embedded in the remote SVG. Author: noraj.
SVG 1.x (xlink:href)
Including a remote SVG fragment in a SVG works but won't trigger the XSS embedded in the remote SVG element because it's impossible to add vulnerable attribute on a polygon/rect/etc since the style attribute is no longer a vector on modern browsers. Author: noraj.
SVG 1.x (xlink:href)
However, including svg tags in SVG documents works and allows XSS execution from sub-SVGs. Codename: french flag. Author: noraj.
XSS in Markdown
XSS in CSS
XSS in PostMessage
If the target origin is asterisk * the message can be sent to any domain has reference to the child page.
Blind XSS
XSS Hunter
XSS Hunter allows you to find all kinds of cross-site scripting vulnerabilities, including the often-missed blind XSS. The service works by hosting specialized XSS probes which, upon firing, scan the page and send information about the vulnerable page to the XSS Hunter service.
XSS Hunter is deprecated, it was available at https://xsshunter.com/app.
You can set up an alternative version
Self-hosted version from mandatoryprogrammer/xsshunter-express
Hosted on xsshunter.trufflesecurity.com
Other Blind XSS tools
Netflix-Skunkworks/sleepy-puppy - Sleepy Puppy XSS Payload Management Framework
LewisArdern/bXSS - bXSS is a utility which can be used by bug hunters and organizations to identify Blind Cross-Site Scripting.
ssl/ezXSS - ezXSS is an easy way for penetration testers and bug bounty hunters to test (blind) Cross Site Scripting.
Blind XSS endpoint
Contact forms
Ticket support
Referer Header
Custom Site Analytics
Administrative Panel logs
User Agent
Custom Site Analytics
Administrative Panel logs
Comment Box
Administrative Panel
Tips
You can use a data grabber for XSS and a one-line HTTP server to confirm the existence of a blind XSS before deploying a heavy blind-XSS testing tool.
Eg. payload
Eg. one-line HTTP server:
Mutated XSS
Use browsers quirks to recreate some HTML tags.
Example: Mutated XSS from Masato Kinugawa, used against cure53/DOMPurify component on Google Search.
Labs
References
Last updated