XSS
Types of XSS
Type | Description |
---|---|
| The most critical type of XSS, which occurs when user input is stored on the back-end database and then displayed upon retrieval (e.g., posts or comments) |
| Occurs when user input is displayed on the page after being processed by the backend server, but without being stored (e.g., search result or error message) |
| Another Non-Persistent XSS type that occurs when user input is directly shown in the browser and is completely processed on the client-side, without reaching the back-end server (e.g., through client-side HTTP parameters or anchor tags) |
Stored XSS
Tip: Many modern web applications utilize cross-domain IFrames to handle user input, so that even if the web form is vulnerable to XSS, it would not be a vulnerability on the main web application. This is why we are showing the value of window.origin
in the alert box, instead of a static value like 1
. In this case, the alert box would reveal the URL it is being executed on, and will confirm which form is the vulnerable one, in case an IFrame was being used.
Will pop up the browser print dialog, which is unlikely to be blocked by any browser
Cookies
Reflected XSS
The single quotes contain our XSS payload '<script>alert(window.origin)</script>'
.
GET
request sends their parameters and data as part of the URL. So, to target a user, we can send them a URL containing our payload
.
DOM XSS
Sink:
document.write()
DOM.innerHTML
DOM.outerHTML
jQuery:
add()
after()
append()
innerHTML
function does not allow the use of the <script>
tags within it as a security feature
Payload:
XSS Discovery
Burp, Nessus, ZAP
Open Source
Other great tool:
Release Page - build in - Just download
Commercial Tool - Knoxss
Manual
See Payload
Note: XSS can be injected into any input in the HTML page, which is not exclusive to HTML input fields, but may also be in HTTP headers like the Cookie or User-Agent (i.e., when their values are displayed on the page).
Defacing
Three HTML elements are usually utilized to change the main look of a web page:
Background Color
document.body.style.background
Background
document.body.background
Page Title
document.title
Page Text
DOM.innerHTML
Changing Background
Tip: Here we set the background color to the default Hack The Box background color. We can use any other hex value, or can use a named color like = "black"
.
Changing Page Title
Changing Page Text
jQuery
innerHTML
document.getElementsByTagName('body')
=> by specifying [0]
, we are selecting the first body
element, which should change the entire text of the web page
Phishing
Tip: To understand which payload should work, try to view how your input is displayed in the HTML source after you add it.
Login Form Injection
Login form:
Payload:
Vicitm URL: http://SERVER_IP/phishing/index.php?url=...SNIP...
Remove the URL field, such that they may think that they have to log in to be able to use the page. To do so, we can use the JavaScript function document.getElementById().remove()
function.
Find the id
of the HTML element we want to remove:
Final Payload:
Remove the original HTML code left after our injected login form
Credential Stealing
If any victim attempts to log in with the form, we will get their credentials.
Use a basic PHP script that logs the credentials from the HTTP request and then returns the victim to the original page without any injections
index.php:
Start a PHP
listening server,
Session Hijacking
Blind XSS Detection
Identify the vulnerable input field that executed the script
If we get a request for /username
, then we know that the username
field is vulnerable to XSS, and so on.
Payloads from PayloadsAllTheThings
Now we can start testing these payloads one by one by using one of them for all of input fields and appending the name of the field after our IP
Tip: We will notice that the email must match an email format, even if we try manipulating the HTTP request parameters, as it seems to be validated on both the front-end and the back-end. Hence, the email field is not vulnerable, and we can skip testing it. Likewise, we may skip the password field, as passwords are usually hashed and not usually shown in cleartext. This helps us in reducing the number of potentially vulnerable input fields we need to test.
Session Hijacking
Payloads
Write any of these JavaScript payloads to script.js
, which will be hosted on our VM
Change the URL in the XSS payload we found earlier to use script.js
If there were many cookies, we may not know which cookie value belongs to which cookie header. So, we can write a PHP script to split them with a new line and write them to a file
Save the following PHP script as index.php
Ressources
Payload
Tools
See XSS Discovery for more tools
Last updated