2. XSS types and payloads

stored xss payloads and examples / definition

Also known as persistent Stored in back-end db and retrieved on visit

basic xss payload

<script>alert(window.origin)</script>

to test if xss is stored, we refresh page and determine if we get alert again


reflected xss payloads + examples

Unlike persistent - non-persist XSS vulns are temporary, not persisted through page refreshes. Attacks only affect targeted user (instead of all users)

Reflected XSS vulnerabilities occur when input reaches backend and returns without filtering/sanitization

![](/img/Pasted image 20241002173742.png) in the above example we inserted test in the input box - our input is Reflected back to us we can try the same basic payloads above as before if we view page source we can see our payload in the source

revisiting the page the error message does not appear meaning it is non-persistent

TO TARGET A USER SPECIFICALLY with a reflected xss payload we craft our HTTP request

http://94.237.49.214:47518/index.php?task=<script>alert(document.cookie)</script>

DOM XSS

Another non-persistent

Difference between reflected and dom xss:

![](/img/Pasted image 20241002174546.png) Adding a test item to the list, and viewing network traffic in browser, we would observe that NO HTTP REQUESTS are being made to make this change to the page.

Input parameter in the url is using a pound sign (#) for the item we've added

Viewing page source we'll see test string is nowhere to be found.

Understanding DOM-based XSS

Source and Sink

Commonly used JS fxs to write to DOM:

Commonly used jQuery lib functions to write to DOM object:

If Sink fx writes exact input without any sanitization (like the above functions) and no other means of sanitization were used then we know page is likely vulnerable to XSS

Looking at source of page we can view script.js file and see source is being taken from task= parameter

var pos = document.URL.indexOf("task=");
var task = document.URL.substring(pos + 5, document.URL.length);

below these lines we'll see page uses the innerHTML function to write task variable in the todo DOM

document.getElementById("todo").innerHTML = "<b>Next Task:</b> " + decodeURIComponent(task);

Thus if we can control input and output isn't sanitized, dom xss

DOM attacks

Trying xss payload we used earlier it will not work innerHTML function does not allow the use of <script> tags There's many other XSS payloads we can use that do not contain <script> tags

<img src="" onerror=alert(window.origin)>

![](/img/Pasted image 20241002201926.png) ![](/img/Pasted image 20241002201949.png)