hacktricks/cryptography/padding-oracle-priv.md

125 lines
8.5 KiB
Markdown
Raw Normal View History

2022-04-28 16:01:33 +00:00
<details>
2024-02-11 02:13:58 +00:00
<summary><strong>Jifunze kuhusu kuhack AWS kutoka sifuri hadi bingwa 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:
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
* Ikiwa unataka kuona **kampuni yako inatangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi ya PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**The PEASS Family**](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** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Shiriki mbinu zako za kuhack kwa kuwasilisha PRs kwenye** [**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>
2022-05-01 16:32:23 +00:00
# CBC - Cipher Block Chaining
2024-02-11 02:13:58 +00:00
Katika mode ya CBC, **block iliyotangulia iliyofichwa hutumiwa kama IV** ya XOR na block inayofuata:
2024-02-08 21:36:35 +00:00
![https://defuse.ca/images/cbc\_encryption.png](https://defuse.ca/images/cbc\_encryption.png)
2024-02-11 02:13:58 +00:00
Kwa kufichua CBC, **operesheni za kinyume** zinafanywa:
2024-02-08 21:36:35 +00:00
![https://defuse.ca/images/cbc\_decryption.png](https://defuse.ca/images/cbc\_decryption.png)
2024-02-11 02:13:58 +00:00
Tambua jinsi inavyohitajika kutumia **funguo za kufichua** na **IV**.
2024-02-11 02:13:58 +00:00
# Kupamba Ujumbe
2024-02-11 02:13:58 +00:00
Kwa kuwa kufichua kunafanywa kwa **vipande vya ukubwa uliowekwa**, **pamba** kawaida inahitajika kwenye **block ya mwisho** ili kukamilisha urefu wake.\
Kawaida **PKCS7** hutumiwa, ambayo inazalisha pamba **inayorudia** **idadi** ya **baiti** **inayohitajika** kukamilisha block. Kwa mfano, ikiwa block ya mwisho inakosa byte 3, pamba itakuwa `\x03\x03\x03`.
2024-02-11 02:13:58 +00:00
Tuangalie mifano zaidi na **vipande 2 vya urefu wa 8baiti**:
2024-02-11 02:13:58 +00:00
| namba ya byte #0 | namba ya byte #1 | namba ya byte #2 | namba ya byte #3 | namba ya byte #4 | namba ya byte #5 | namba ya byte #6 | namba ya byte #7 | namba ya byte #0 | namba ya byte #1 | namba ya byte #2 | namba ya byte #3 | namba ya byte #4 | namba ya byte #5 | namba ya byte #6 | namba ya byte #7 |
2021-10-10 22:24:28 +00:00
| ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| P | A | S | S | W | O | R | D | 1 | 2 | 3 | 4 | 5 | 6 | **0x02** | **0x02** |
| P | A | S | S | W | O | R | D | 1 | 2 | 3 | 4 | 5 | **0x03** | **0x03** | **0x03** |
| P | A | S | S | W | O | R | D | 1 | 2 | 3 | **0x05** | **0x05** | **0x05** | **0x05** | **0x05** |
| P | A | S | S | W | O | R | D | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** | **0x08** |
2021-09-22 14:27:03 +00:00
2024-02-11 02:13:58 +00:00
Tambua jinsi katika mfano wa mwisho **block ya mwisho ilikuwa kamili kwa hivyo nyingine ilizalishwa tu na pamba**.
2022-05-01 16:32:23 +00:00
# Padding Oracle
2024-02-11 02:13:58 +00:00
Wakati programu inafichua data iliyofichwa, kwanza itaifichua data; kisha itaondoa pamba. Wakati wa kusafisha pamba, ikiwa **pamba batili inasababisha tabia inayoweza kugundulika**, una **mdudu wa padding oracle**. Tabia inayoweza kugundulika inaweza kuwa **kosa**, **ukosefu wa matokeo**, au **majibu polepole**.
2024-02-11 02:13:58 +00:00
Ikiwa unagundua tabia hii, unaweza **kufichua data iliyofichwa** na hata **kuficha maandishi wazi yoyote**.
2024-02-11 02:13:58 +00:00
## Jinsi ya kufaidika
2024-02-11 02:13:58 +00:00
Unaweza kutumia [https://github.com/AonCyberLabs/PadBuster](https://github.com/AonCyberLabs/PadBuster) kufaidika na aina hii ya mdudu au tu fanya
2021-10-10 22:24:28 +00:00
```
sudo apt-get install padbuster
```
2024-02-11 02:13:58 +00:00
Ili kujaribu kama kuki ya tovuti ina kasoro, unaweza kujaribu:
```bash
2021-10-10 22:24:28 +00:00
perl ./padBuster.pl http://10.10.10.10/index.php "RVJDQrwUdTRWJUVUeBKkEA==" 8 -encoding 0 -cookies "login=RVJDQrwUdTRWJUVUeBKkEA=="
```
2024-02-11 02:13:58 +00:00
**Ukodishaji 0** una maana kwamba **base64** inatumika (lakini nyingine zinapatikana, angalia menyu ya msaada).
2024-02-11 02:13:58 +00:00
Unaweza pia **kutumia udhaifu huu kuweka data mpya. Kwa mfano, fikiria kuwa maudhui ya kuki ni "**_**mtumiaji=JinaLanguLaMtumiaji**_**", basi unaweza kubadilisha kuwa "\_mtumiaji=msimamizi\_" na kuongeza mamlaka ndani ya programu. Unaweza pia kufanya hivyo kwa kutumia `paduster` ukitaja -plaintext** kama parameter:
```bash
2021-10-10 22:24:28 +00:00
perl ./padBuster.pl http://10.10.10.10/index.php "RVJDQrwUdTRWJUVUeBKkEA==" 8 -encoding 0 -cookies "login=RVJDQrwUdTRWJUVUeBKkEA==" -plaintext "user=administrator"
```
2024-02-11 02:13:58 +00:00
Ikiwa tovuti ina kasoro, `padbuster` itajaribu kiotomatiki kupata wakati kosa la padding linatokea, lakini unaweza pia kuonyesha ujumbe wa kosa kwa kutumia kipengele cha **-error**.
```bash
2021-10-10 22:24:28 +00:00
perl ./padBuster.pl http://10.10.10.10/index.php "" 8 -encoding 0 -cookies "hcon=RVJDQrwUdTRWJUVUeBKkEA==" -error "Invalid padding"
```
2024-02-11 02:13:58 +00:00
## Nadharia
2024-02-11 02:13:58 +00:00
Kwa kifupi, unaweza kuanza kufichua data iliyofichwa kwa kudhani thamani sahihi ambazo zinaweza kutumika kuunda **paddings tofauti** zote. Kisha, shambulio la padding oracle litianza kufichua herufi kutoka mwisho hadi mwanzo kwa kudhani ni thamani ipi sahihi ambayo **inaunda padding ya 1, 2, 3, nk**.
2022-02-02 15:35:20 +00:00
![](<../.gitbook/assets/image (629) (1) (1).png>)
2024-02-11 02:13:58 +00:00
Fikiria una maandishi yaliyofichwa ambayo yanachukua **vikundi 2** vilivyoundwa na herufi kutoka **E0 hadi E15**.\
Ili **kufichua** **kikundi** **cha mwisho** (**E8** hadi **E15**), kikundi kizima kinapitia "ufichuzi wa block cipher" na kuzalisha **herufi za kati I0 hadi I15**.\
Hatimaye, kila herufi ya kati inafanyiwa **XOR** na herufi zilizofichwa hapo awali (E0 hadi E7). Hivyo:
2021-09-22 14:27:03 +00:00
* `C15 = D(E15) ^ E7 = I15 ^ E7`
* `C14 = I14 ^ E6`
2021-10-28 10:53:20 +00:00
* `C13 = I13 ^ E5`
* `C12 = I12 ^ E4`
* ...
2024-02-11 02:13:58 +00:00
Sasa, ni **inawezekana kubadilisha `E7` hadi `C15` iwe `0x01`**, ambayo pia itakuwa padding sahihi. Kwa hivyo, katika kesi hii: `\x01 = I15 ^ E'7`
2024-02-11 02:13:58 +00:00
Kwa hivyo, kwa kupata E'7, ni **inawezekana kuhesabu I15**: `I15 = 0x01 ^ E'7`
2024-02-11 02:13:58 +00:00
Hii inaturuhusu kuhesabu C15: `C15 = E7 ^ I15 = E7 ^ \x01 ^ E'7`
2024-02-11 02:13:58 +00:00
Kwa kujua **C15**, sasa ni **inawezekana kuhesabu C14**, lakini wakati huu kwa kubadilisha padding `\x02\x02`.
2024-02-11 02:13:58 +00:00
BF hii ni ngumu kama ile ya awali kwani inawezekana kuhesabu E''15 ambayo thamani yake ni 0x02: `E''7 = \x02 ^ I15` kwa hivyo inahitajika tu kupata **`E'14`** ambayo inazalisha **`C14` sawa na `0x02`**.\
Kisha, fanya hatua sawa za kufichua C14: **`C14 = E6 ^ I14 = E6 ^ \x02 ^ E''6`**
2024-02-11 02:13:58 +00:00
**Fuata mnyororo huu hadi ufichue maandishi yote yaliyofichwa.**
2024-02-11 02:13:58 +00:00
## Uchunguzi wa udhaifu
2024-02-11 02:13:58 +00:00
Jisajili na akaunti na ingia kwa akaunti hiyo.\
Ikiwa unajisajili mara nyingi na daima unapata **cookie ile ile**, kuna uwezekano mkubwa kuna **kitu kibaya** katika programu. Kuki inayotumwa inapaswa kuwa **tofauti** kila wakati unapoingia. Ikiwa kuki **daima** ni **ile ile**, itakuwa inawezekana daima kuwa halali na **hakutakuwa na njia ya kuitengua**.
2024-02-11 02:13:58 +00:00
Sasa, ikiwa jaribu **kubadilisha** kuki, utaona kuwa unapata **kosa** kutoka kwa programu.\
Lakini ikiwa unatumia BF kwenye padding (kwa kutumia padbuster kwa mfano) unaweza kupata kuki nyingine halali kwa mtumiaji tofauti. Hali hii ina uwezekano mkubwa wa kuwa na udhaifu wa padbuster.
2021-10-10 22:24:28 +00:00
2024-02-11 02:13:58 +00:00
## Marejeo
2021-10-28 10:53:20 +00:00
* [https://en.wikipedia.org/wiki/Block\_cipher\_mode\_of\_operation](https://en.wikipedia.org/wiki/Block\_cipher\_mode\_of\_operation)
2022-04-28 16:01:33 +00:00
2022-05-01 16:32:23 +00:00
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:
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
* Ikiwa unataka kuona **kampuni yako inatangazwa kwenye HackTricks** au **kupakua HackTricks kwa muundo wa PDF** Angalia [**MPANGO WA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**swag rasmi wa PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**The PEASS Family**](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** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PR kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>