This lab contains a vulnerability in the stock checker functionality. It uses the JavaScript document.write
function, which writes data out to the page. The document.write
function is called with data from location.search
which you can control using the website URL. The data is enclosed within a select element.
To solve this lab, perform a cross-site scripting attack that breaks out of the select element and calls the alert
function.
After accessing the lab, I began examining the source code of each page since this lab is vulnerable to DOM-based XSS, which means the vulnerability lies in the client-side JavaScript. While inspecting the /product
page, I found the following script:
I noticed immediately the presence of a source which is location.search
:
So here it is storing the value of the parameter storeId into the the store variable. To confirm the vulnerability, I crafted a URL with a storeId
parameter containing a simple string:
After sending this and inspecting the page i can see that ichyaboy was added to the dropdown and as a selected item
and that's what the script exactly doing. By adding the encoded payload to the storeId
parameter in the URL, I constructed the following request:
After sending the request, the injected payload is executed by the browser, causing the onerror
event to trigger and display an alert box. This confirms the XSS vulnerability has been successfully exploited.
The search
property of the interface is a search string, also called a query string; that is, a string containing a '?'
followed by the parameters of the URL.