Labs
A set of reflected XSS levels. The aim for each is to execute the JavaScript alert function with the string THM, for example:
<script>alert('THM');</script>
Level One
You're presented with a form asking for your name; once entered, it's shown on the line below:
Viewing the page source shows your name reflected in the code
Instead of entering your name, enter the JavaScript payload <script>alert('THM');</script>. Now when you click the enter button, you'll get an alert popup with the string THM, and the page source will look like the following:
You then get a confirmation message that your payload was successful, with a link to the next level.
Level Two
Like the previous level, you're asked to enter your name. This time it's reflected inside an input tag:
The page source shows your name inside the value attribute of the input tag:
It wouldn't work to try the previous payload, because you can't run it from inside the input tag. Instead we need to escape the input tag first so the payload can run properly, with "><script>alert('THM');</script>. The important part is the ">, which closes the value parameter and then closes the input tag, allowing the JavaScript payload to run:
Now when you click the enter button, you'll get an alert popup with the string THM, and then a confirmation message that your payload was successful with a link to the next level.
Level Three
Another name form. This time your name is reflected inside a textarea tag:
We escape the textarea differently from the input tag, with </textarea><script>alert('THM');</script>.
This Turns This
Into This
The important part of the payload is </textarea>, which causes the textarea element to close so the script will run. Now when you click the enter button, you'll get an alert popup with the string THM, and then a confirmation message that your payload was successful with a link to the next level.
Level Four
Entering your name reflects it on the page. This looks like level one, but the page source shows your name reflected inside some JavaScript code:
You'll have to escape the existing JavaScript command so you can run your own code; you can do this with the payload ';alert('THM');//, which you'll see from the screenshot below will execute your code. The ' closes the field specifying the name, then the ; signifies the end of the current command, and the // at the end makes anything after it a comment rather than executable code:
Now when you click the enter button, you'll get an alert popup with the string THM, and then a confirmation message that your payload was successful with a link to the next level.
Level Five
This looks like level one and your name reflects in the same place, but <script>alert('THM');</script> won't work. The page source shows why:
The word script gets removed from your payload, because there is a filter that strips out any potentially dangerous words. When a word gets removed from a string, there's a helpful trick that you can try: wrap the dangerous word around itself so that removing the inner copy leaves a valid word behind.
Original Payload
<sscriptcript>alert('THM');</sscriptcript>
Text to Be Removed (by the Filter)
<sscriptcript>alert('THM');</sscriptcript>
Final Payload (After Passing the Filter)
<script>alert('THM');</script>
Try entering the payload <sscriptcript>alert('THM');</sscriptcript> and click the enter button; you'll get an alert popup with the string THM, and then a confirmation message that your payload was successful with a link to the next level.
Level Six
Similar to level two, we try "><script>alert('THM');</script>, but it doesn't work. The page source shows why:
You can see that the < and > characters get filtered out from our payload, preventing us from escaping the IMG tag. To get around the filter, we can take advantage of the additional attributes of the IMG tag, such as the onload event, which executes the code of your choosing once the image specified in the src attribute has loaded onto the web page.
Change the payload to /images/cat.jpg" onload="alert('THM'); and then view the page source to see how this will work:
Now when you click the enter button, you'll get an alert popup with the string THM. This being the last level, you'll receive a flag that can be entered below.