# Cross-Site Scripting A web application is vulnerable to XSS if it uses unsanitized user input. XSS is possible in Javascript, VBScript, Flash and CSS. ## Stored XSS This is where a malicious string originates from the websites database. ### Examples * Sanity test by changing DOM content ``` ``` * Cookie stealing ``` ``` * Navigte to `/logs` and take sid * Open nc port and collect cookies ```sh ``` ## Reflected XSS In a reflected cross-site scripting attack, the malicious payload is part of the victims request to the website. The website includes this payload in response back to the user. To summarise, an attacker needs to trick a victim into clicking a URL to execute their malicious payload. ### Usage As script inside parameter ```sh http://example.com/search?keyword= ``` * Show server IP ``` http://example.com/reflected?keyword= ``` ## DOM based XSS With DOM-Based xss, an attackers payload will only be executed when the vulnerable Javascript code is either loaded or interacted with. It goes through a Javascript function like so: ```javascript var keyword = document.querySelector('#search') keyword.innerHTML = ``` ### Usage * Find the sub-object inside the document ```javascript test" onmouseover="alert('YO!')" ``` * Show cookie ``` test" onmouseover="alert(document.cookie)" ``` ## Bypass Filters * `script>alert("1")</script> ``` * `alert()` sanitizing ```javascript 0\"autofocus/onfocus=alert(1)-->"-confirm(3)-" ``` or ```javascript 0\"autofocus/onfocus=alert(1)-->