The lab
here is how portswigger describes it
This lab contains login functionality and a delete account button that is protected by a CSRF token. A user will click on elements that display the word "click" on a decoy website.
To solve the lab, craft some HTML that frames the account page and fools the user into deleting their account. The lab is solved when the account is deleted.
What clickjacking is?#
clickjacking is a trick played on your eyes rather than on the server. the attacker loads the real target site inside an iframe on their own page then makes that iframe almost completely transparent and lays it over a harmless looking lure a button or a bit of text that says something inviting like click me. the lure is positioned so that it sits exactly on top of a sensitive button inside the hidden real page. you think you are clicking the lure but because the invisible real page is layered above it your click actually lands on the real button underneath on the real site in your own logged in session.
that is also why a csrf token is no defence here a csrf token stops a forged request that an attacker builds from scratch, but clickjacking does not forge anything. the framed page is the genuine account page, it already contains its own valid token, and the click that submits it is a real click from the real user. everything is authentic except your intention. the only thing that actually stops clickjacking is the site telling browsers not to allow itself to be framed, with a header like X-Frame-Options or a csp frame-ancestors rule
Step 1 - Log in and find the target button#
logging in with the provided credentials, the account page has an email change form and lower down a delete account button which is our target.

Step 2 - Frame the account page under a lure#
on the exploit server we build a page that puts the account page in an iframe and a decoy element on top of it. here is the html and css
<style>
iframe {
position:relative;
width:500px;
height: 700px;
opacity: 0.1;
z-index: 2;
}
div {
position:absolute;
top:300px;
left:60px;
z-index: 1;
}
</style>
<div>Test me</div>
<iframe src="https://your-lab-id.web-security-academy.net/my-account"></iframe>
reading the pieces. the iframe loads the victim's own account page, and we size it with width and height. opacity: 0.1 makes it almost see through, so during the attack the victim barely notices the real page is there. the z-index: 2 is the important bit it stacks the iframe above the div, even though the iframe is nearly invisible it is the layer on top that actually receives clicks. the div is our lure, the visible thing the victim reads and aims at, and position: absolute with top and left lets us drag it to any spot on the page. we give it z-index: 1 so it sits underneath the iframe, showing through the faint iframe as the label the victim sees. so the victim looks at our div but their click passes to the delete button in the iframe above it. lining those two up is the whole thing here
Step 3 - Line the lure up with the delete button#
to position it accurately store the page and view the exploit but first bump opacity up to 1 so the real account page is fully visible and you can see exactly where the delete button sits

then set opacity back to 0.1 so the page goes nearly invisible again, which is how the victim will see it.

now adjust the top and left values on the div until your lure sits right over the delete account button so a click on the lure will land on that button.

Step 4 - Label it and deliver#
the lab's simulated victim only clicks things that say click so once the lure is lined up, change its text from Test me to Click me and store the page
then deliver the exploit to the victim. their browser loads our page they see a harmless click me, they click it and the click lands on the delete account button inside the framed real page which submits with its own genuine token and deletes their account.

with this, the lab is solved!
