The lab
here is how portswigger describes it
This lab contains an XSS vulnerability that is triggered by a click. Construct a clickjacking attack that fools the user into clicking the "Click me" button to call the print() function.
the earlier clickjacking labs used a stolen click to fire an account action, and this one uses it for something new, it triggers an xss. the target has a click triggered xss, so on its own the payload needs a real click to go off, and clickjacking is the perfect way to hand it that click.
The idea#
this lab is really two bugs working together, so it helps to see each one first.
the first is a dom based xss on the feedback form. the form takes a name, email, subject and message, and when you submit it the name is written back into the page's feedback result area by client side javascript. the catch is that it is written as html rather than as plain text, so if the name contains a tag, the browser builds it for real. dropping <img src=1 onerror=print()> into the name and submitting makes the browser try to load an image called 1, fail run the onerror, and call print. the key detail for this lab is that nothing happens until the submit is clicked, so this is a xss that only fires on a click.
the second bug is that the page can be framed, which is the clickjacking hole from the earlier labs. put the two together and the plan is straightforward, we frame the feedback page with the xss payload already loaded into it, and we clickjack the submit button so the victim's click is what sets the xss off. the click they think is harmless is the exact click the xss was waiting for.
Step 1 - Find the click triggered xss#
poking the application surface, there is no login but the posts have a feedback form under them. testing that form, the name value comes back into the feedback result on the page unescaped, so a name of <img src=1 onerror=print()> fires the print dialog when the feedback is submitted. that confirms a dom based xss that goes off on the submit click.
Step 2 - frame the feedback page with the payload primed#
on the exploit server we use the same overlay template as the earlier labs, but the iframe points at the feedback page with the whole form prefilled through the url, the xss payload sitting in the name parameter.
<style>
iframe {
position:relative;
width:500px;
height: 700px;
opacity: 0.1;
z-index: 2;
}
div {
position:absolute;
top:625px;
left:90px;
z-index: 1;
}
</style>
<div>Test me</div>
<iframe src="https://your-lab-id.web-security-academy.net/feedback?name=<img src=1 onerror=print()>&[email protected]&subject=test&message=test#feedbackResult"></iframe>
the query string on the iframe url fills every field of the feedback form for us the name gets our <img src=1 onerror=print()> payload and the email, subject and message get filler so the form is complete, and the #feedbackResult fragment lines the framed page up on the result area. so the page loads fully primed, and the one thing still missing is the click on submit, which is exactly what the overlay will steal. the iframe overlay itself, the opacity and the z index stacking, works the same way as the previous clickjacking labs.
Step 3 - align and deliver#
it is the same alignment routine as before. line the div up over the feedback submit button using the top and left values while opacity is easy to see against, then leave it at 0.1 so the real page is nearly invisible. change the lure text from Test me to Click me, store, and deliver.
when the victim opens the page they click the click me lure, the click lands on the feedback submit button in the framed page, the form submits with our payload in the name, the browser writes it into the result area as live html, and print is called.

with this, the lab is solved!
