Cross site scripting (XSS)
Last updated
Last updated
Cross-site scripting is a type of computer security vulnerability typically found in web applications. XSS attacks enable attackers to inject client-side scripts into web pages viewed by other users. A cross-site scripting vulnerability may be used by attackers to bypass access controls such as the same-origin policy.
--
Javascript code sent in a request, e.g. via query parameters or form data, is reflected in the response.
E.g.:
To exploit victims you need an external delivery mechanism, like email, a tweet or other message.
Javascript code gets stored on the server and displayed in an unsafe way to other users.
Entry points:
URL query string
Message body
Request headers
Any out-of-band routes
Exit points:
All possible HTTP responses
-> Try to find links between entry and exit points.
E.g.:
Use <script>alert(1)</script>
as username, in a comment post, etc.
Via img: <img src="." onerror="alert('test');" />
Via url: <a href="javascript:alert('test')>test</a>
As your payload is stored on the server, you don't an external delivery mechanism (as for reflected XSS), therefore stored XSS is generally considered a more severe vulnerability.
Attacker gets control over Javascript variables that are written to the DOM or used in methods like
eval()
orinnerHTML
.
Place random alphanumeric strings into the source (e.g. location.search
) and inspect the DOM using a browsers developer tools.
Using the browsers developer tools you can inspect and follow your input through the JavaScript code and check if/how it is sent to a sink.
jQuery
Sinks:
attr()
$()
AngularJS
Check for ng-app
attribute, then use {{...}}
to inject JavaScript.
Similar to "Stored", but you won't see the output/impact directly. E.g.
Submitting a contact form containing XSS
Trigger XSS using custom html tags.
Using animation and onbegin
event:
Using svg animate
tag to set the href
attribute for a
nchor tag:
E.g. using:
Single quote, get's decoded first and then executed when used in event handlers like onclick
.
Templates literals are encapsulated in backticks and ${...}
syntax can be used to evaluate JavaScipt inside them.
Let the user request an image from your server and send his cookie as a GET param.
Start ./beef
Username: beef
Password: beef
See also .
Use "Copy tags to clipboard" and "Copy events to clipboard" from to detect unfiltered tags and events (e.g. using Burp Intruder).
BeEF is short for The Browser Exploitation Framework. It is a penetration testing tool that focuses on the web browser.