This lab contains a vulnerability in the search query tracking functionality where angle brackets are encoded. The reflection occurs inside a JavaScript string. To solve this lab, perform a cross-site scripting attack that breaks out of the JavaScript string and calls the alert
function.
After accessing the lab, I intercepted the search request:
In the response, I noticed my input was embedded within a script tag:
To exploit this, I crafted a payload to break out of the JavaScript context, inject my malicious script, and comment out the rest to prevent errors. Here’s the payload:
This payload works as follows:
';
closes the existing string.
alert(1)
injects a script that triggers an alert.
//
comments out the remainder of the JavaScript code to avoid syntax errors.
After injecting this payload, an alert box popped up, confirming the XSS vulnerability and solving the lab.