# Clickjacking
htARTE (HackTricks AWS Red Team Expert) !HackTricks! Other ways to support HackTricks: * If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! * Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) * Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) * **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**.** * **Share your hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
\ Use [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\ Get Access Today: {% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} ## What is Clickjacking In a clickjacking attack, a **user** is **tricked** into **clicking** an **element** on a webpage that is either **invisible** or disguised as a different element. This manipulation can lead to unintended consequences for the user, such as the downloading of malware, redirection to malicious web pages, provision of credentials or sensitive information, money transfers, or the online purchasing of products. ### Prepopulate forms trick Sometimes is possible to **fill the value of fields of a form using GET parameters when loading a page**. An attacker may abuse this behaviour to fill a form with arbitrary data and send the clickjacking payload so the user press the button Submit. ### Populate form with Drag\&Drop If you need the user to **fill a form** but you don't want to directly ask him to write some specific information (like the email and or specific password that you know), you can just ask him to **Drag\&Drop** something that will write your controlled data like in [**this example**](https://lutfumertceylan.com.tr/posts/clickjacking-acc-takeover-drag-drop/). ### Basic Payload ```markup
Click me
``` ### Multistep Payload #### tlhIngan Hol Translation: ### cha'logh QaD #### HTML Example: ```html
``` #### tlhIngan Hol Example: ```html
``` ```markup
Click me first
Click me next
``` ### Drag\&Drop + Click payload #### Description This technique involves using a combination of drag and drop events along with a click event to execute a payload. It takes advantage of the clickjacking vulnerability to trick the user into performing an unintended action. #### How it works 1. The attacker creates a malicious webpage that contains an invisible element, such as an iframe, positioned over a legitimate button or link. 2. The attacker uses JavaScript to capture the drag and drop events on the webpage. 3. When the user attempts to drag and drop an object, the malicious webpage intercepts the event and moves the invisible element to the same position as the object being dragged. 4. As the user releases the object, the click event is triggered on the invisible element, which is positioned over the legitimate button or link. 5. The user unknowingly clicks on the invisible element, executing the payload. #### Mitigation To mitigate this attack, web developers should implement the following measures: - Implement frame-busting techniques to prevent clickjacking attacks. - Use the X-Frame-Options header to restrict framing of the webpage. - Implement Content Security Policy (CSP) to restrict the sources of the webpage's content. - Regularly update and patch web browsers to ensure they are protected against clickjacking vulnerabilities. #### Example ```html ``` #### References - [OWASP Clickjacking](https://owasp.org/www-community/attacks/Clickjacking) - [Clickjacking - Wikipedia](https://en.wikipedia.org/wiki/Clickjacking) ```markup
.
1. Click and press delete button
3.Click me

2.DRAG ME TO THE RED BOX

``` ### XSS + Clickjacking If you have identified an **XSS attack that requires a user to click** on some element to **trigger** the XSS and the page is **vulnerable to clickjacking**, you could abuse it to trick the user into clicking the button/link.\ Example:\ _You found a **self XSS** in some private details of the account (details that **only you can set and read**). The page with the **form** to set these details is **vulnerable** to **Clickjacking** and you can **prepopulate** the **form** with the GET parameters._\ \_\_An attacker could prepare a **Clickjacking** attack to that page **prepopulating** the **form** with the **XSS payload** and **tricking** the **user** into **Submit** the form. So, **when the form is submitted** and the values are modified, the **user will execute the XSS**. ## Strategies to Mitigate Clickjacking ### Client-Side Defenses Scripts executed on the client side can perform actions to prevent Clickjacking: * Ensuring the application window is the main or top window. * Making all frames visible. * Preventing clicks on invisible frames. * Detecting and alerting users to potential Clickjacking attempts. However, these frame-busting scripts may be circumvented: * **Browsers' Security Settings:** Some browsers might block these scripts based on their security settings or lack of JavaScript support. * **HTML5 iframe `sandbox` Attribute:** An attacker can neutralize frame buster scripts by setting the `sandbox` attribute with `allow-forms` or `allow-scripts` values without `allow-top-navigation`. This prevents the iframe from verifying if it is the top window, e.g., ```html ``` ### Server-Side Defenses #### X-Frame-Options **`X-Frame-Options` HTTP response header** informs browsers about the legitimacy of rendering a page in a `` or `