Cross-site Scripting
Introduction
XSS happens when the user input is given as output without sanitization on input and output.
Goals of XSS:
Cookie stealing
Complete control on browser
Initiating an exploitation phase against browser plugins first and and the machine
Keylogging
3 types:
Reflected (Server side code is vulnerable)
Stored
DOM (Client side code is vulnerable)
Reflected XSS
Victims bring the payload in the HTTP request to the vulnerable website. Then the browser renders the payload in the victim's context.
Persistent XSS
Persistent XSS is able to deface a webpage.
This type of attack does not need the victims to click on any links. It happens when a victim browses a vulnerable page injected with persistent XSS code.
DOM-based XSS
Make use of the HTML tree.
Find XSS
Input could be:
GET/POST variables
COOKIE
HTTP HEADERS
First, try to inject <plaintext>
tag to see if the page will be broken after.
Then, check if we can inject script using <script>
or using one of the DOM events (e.g. <h1>
).
When inspecting the source code, look for all the points where the application outputs data (totally / partially) supplied by the user without sanitization and tracking it back to the source where it is retrieved for the first time.
XSS tricks
Simple:
<script>alert('xss')</script>
IMG tag onload:
<img src="xxx" onload="javascript:alert('xss')">
<img src="xxx" onload="alert('xss')">
<img src="xxx" onload="alert(String.fromCharCode(88,83,83))">
XSS Exploit
Cookie Stealing
Find injection point
Read the cookie using JS
Redirect the cookie to attacker server
Retrieve and install the stolen cookie on browser
Example:
Note %2b
= +
The steal.php
could be:
We can also do some other thing, for example, change form action
location:
Web Defacement
Make use of Persistent XSS
Change the appearance of the web by manipulating the DOM
Phishing
By modifying the form action's destination
BeEF
XSS Evasion
Last updated