hacktricks/pentesting-web/http-response-smuggling-desync.md

160 lines
10 KiB
Markdown
Raw Normal View History

# HTTP Response Smuggling / Desync
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 %}
**The technique of this post was taken from the video:** [**https://www.youtube.com/watch?v=suxDcYViwao\&t=1343s**](https://www.youtube.com/watch?v=suxDcYViwao\&t=1343s)
2022-04-28 16:01:33 +00:00
## HTTP Request Queue Desynchronisation
2024-02-06 03:10:38 +00:00
Kwanza kabisa, mbinu hii **inatumia udhaifu wa HTTP Request Smuggling**, hivyo unahitaji kujua ni nini hicho:
2024-02-06 03:10:38 +00:00
**tofauti** **kuu** kati ya mbinu hii na HTTP Request smuggling ya kawaida ni kwamba **badala** ya **kushambulia** **ombile** la **mhasiriwa** **kwa kuongeza kiambatisho** kwake, tunakwenda **kuvuja au kubadilisha jibu ambalo mhasiriwa anapata**. Hii inafanywa kwa, badala ya kutuma ombi 1 na nusu ili kutumia HTTP Request smuggling, **tuma ombi 2 kamili ili kuondoa usawa wa foleni za majibu ya proxies**.
2021-11-05 20:59:42 +00:00
Hii ni kwa sababu tutakuwa na uwezo wa **kuondoa usawa wa foleni ya majibu** ili **jibu** kutoka kwa **ombile** la **halali** la **mhasiriwa litumwe kwa mshambuliaji**, au kwa **kuingiza maudhui yanayodhibitiwa na mshambuliaji katika jibu kwa mhasiriwa**.
2021-11-05 20:59:42 +00:00
### HTTP Pipeline Desync
2021-11-05 20:59:42 +00:00
HTTP/1.1 inaruhusu kuomba **rasilimali tofauti bila kuhitaji kusubiri zilizopita**. Hivyo, ikiwa kuna **proxy** katikati, ni jukumu la proxies **kuweka usawa wa maombi yaliyotumwa kwa backend na majibu yanayotoka kutoka kwake**.
2021-11-05 20:59:42 +00:00
Hata hivyo, kuna tatizo la kuondoa usawa wa foleni za majibu. Ikiwa mshambuliaji atatuma shambulio la HTTP Response smuggling na majibu kwa **ombile la awali na lile lililovuja yanajibiwa mara moja**, jibu lililovuja halitaingizwa ndani ya foleni ya jibu la mhasiriwa bali litakataliwa **kama kosa**.
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (633).png>)
2021-11-05 20:59:42 +00:00
Hivyo, inahitajika kwamba **ombile** **lililovuja** **lichukue muda mrefu zaidi kutekelezwa** ndani ya seva ya backend. Hivyo, wakati ombi lililovuja linaposhughulikiwa, mawasiliano na mshambuliaji yatakuwa yameisha.
2021-11-05 20:59:42 +00:00
Ikiwa katika hali hii maalum **mhasiriwa ametuma ombi** na **ombile lililovuja linajibiwa kabla** ya ombi halali, **jibu lililovuja litatumwa kwa mhasiriwa**. Hivyo, mshambuliaji atakuwa **akidhibiti ombi "lililofanywa" na mhasiriwa**.
2021-11-05 20:59:42 +00:00
Zaidi ya hayo, ikiwa **mshambuliaji kisha atafanya ombi** na **jibu halali** kwa **ombile** la **mhasiriwa** linajibiwa **kabla** ya ombi la mshambuliaji. **Jibu kwa mhasiriwa litatumwa kwa mshambuliaji**, **kuchukua** jibu kwa mhasiriwa (ambalo linaweza kuwa na mfano kichwa **Set-Cookie**).
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (1020).png>)
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (719).png>)
2021-11-05 20:59:42 +00:00
### Multiple Nested Injections
2021-11-05 20:59:42 +00:00
Tofauti nyingine **ya kuvutia** na **HTTP Request Smuggling** ya kawaida ni kwamba, katika shambulio la kawaida la smuggling, **lengo** ni **kubadilisha mwanzo wa ombi la mhasiriwa** ili lifanye kitendo kisichotarajiwa. Katika **shambulio la HTTP Response smuggling**, kwa kuwa unatumia **maombi kamili**, unaweza **kuingiza katika payload moja majibu kumi** ambayo yatakuwa **yakiondoa usawa wa watumiaji kumi** ambao watakuwa **wakipokea** **majibu yaliyoingizwa**.
2021-11-05 20:59:42 +00:00
Mbali na kuwa na uwezo wa **kusambaza kwa urahisi majaribio kumi** kati ya watumiaji halali, hii pia inaweza kutumika kusababisha **DoS** katika seva.
2021-11-05 20:59:42 +00:00
### Exploit Organisation
2021-11-05 20:59:42 +00:00
Kama ilivyoelezwa hapo awali, ili kutumia mbinu hii, inahitajika kwamba **ujumbe wa kwanza ulioingizwa** ndani ya seva **uchukue muda mwingi kutekelezwa**.
2021-11-05 20:59:42 +00:00
Hii **ombile linalochukua muda** ni ya kutosha ikiwa tunataka tu **kujaribu kuiba jibu la mhasiriwa.** Lakini ikiwa unataka kufanya exploit ngumu zaidi hii itakuwa muundo wa kawaida kwa exploit.
Kwanza kabisa **ombile la awali** linalotumia **HTTP** **Request** **smuggling**, kisha **ombile linalochukua muda** na kisha **ombile 1 au zaidi** ambayo majibu yake yatatumwa kwa mhasiriwa.
## Abusing HTTP Response Queue Desynchronisation
2021-11-05 20:59:42 +00:00
### Capturing other users' requests <a href="#capturing-other-users-requests" id="capturing-other-users-requests"></a>
Kama ilivyo na payloads za HTTP Request Smuggling zinazojulikana, unaweza **kuiba ombi la mhasiriwa** kwa tofauti moja muhimu: Katika kesi hii unahitaji tu **kupeleka maudhui ili yaonyeshwe katika jibu**, **hakuna hifadhi ya kudumu** inahitajika.
Kwanza, mshambuliaji anatuma payload inayojumuisha **ombile la mwisho la POST lenye parameter iliyoonyeshwa** mwishoni na Content-Length kubwa.
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (1053).png>)
2021-11-05 20:59:42 +00:00
Kisha, mara tu **ombile la awali** (bluu) liliposhughulikiwa na **wakati** **ombile la usingizi** linaposhughulikiwa (njano) **ombile linalofuata linalotoka kwa mhasiriwa** litakuwa **limeongezwa kwenye foleni mara tu baada ya parameter iliyoonyeshwa**:
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (794).png>)
2021-11-05 20:59:42 +00:00
Kisha, **mhasiriwa** atapokea **jibu** kwa **ombile la usingizi** na ikiwa wakati huo **mshambuliaji** **alituma** **ombile** **lingine**, **jibu kutoka kwa ombi la maudhui yaliyoonyeshwa litatumwa kwake**.
2021-11-05 20:59:42 +00:00
## Response Desynchronisation
2021-11-05 20:59:42 +00:00
Hadi sasa, tumefundishwa jinsi ya kutumia shambulio la HTTP Request Smuggling ili **kudhibiti** **ombile** **ambalo** **jibu** ambalo **mteja** atakuwa **akipokea** na jinsi unaweza kisha **kuiba jibu ambalo lilikuwa limekusudiwa kwa mhasiriwa**.
2021-11-05 20:59:42 +00:00
Lakini bado inawezekana **kuondoa usawa hata** zaidi majibu.
2021-11-05 20:59:42 +00:00
Kuna maombi ya kuvutia kama **HEAD** ambayo yameelezwa kutokuwa na **maudhui yoyote ndani ya mwili wa majibu** na ambayo yanapaswa (lazima) **kujumuisha Content-Length** ya ombi kama **kama ingekuwa ombi la GET**.
Hivyo, ikiwa mshambuliaji **anaingiza** ombi la **HEAD**, kama katika picha hizi:
![](<../.gitbook/assets/image (1107).png>)
Kisha, **mara tu bluu inajibiwa kwa mshambuliaji**, ombi linalofuata la mhasiriwa litakuwa limeingizwa kwenye foleni:
![](<../.gitbook/assets/image (999).png>)
Kisha, **mhasiriwa** atapokea **jibu** kutoka kwa **ombile la HEAD**, ambalo **litakuwa na Content-Length lakini hakuna maudhui kabisa**. Hivyo, proxy **haitatuma jibu hili** kwa mhasiriwa, bali itangojea **maudhui**, ambayo kwa kweli yatakuwa **jibu kwa ombi la njano** (pia lililoingizwa na mshambuliaji):
![](<../.gitbook/assets/image (735).png>)
2021-11-05 20:59:42 +00:00
### Content Confusion
Kufuata mfano wa awali, ukijua kwamba unaweza **kudhibiti mwili** wa ombi ambalo jibu litakalopokea mhasiriwa na kwamba **jibu la HEAD** kawaida lina **Content-Type na Content-Length** katika vichwa vyake, unaweza **kutuma ombi kama ifuatavyo** ili **kusababisha XSS** kwa mhasiriwa bila ukurasa kuwa na udhaifu wa XSS:
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (688).png>)
2021-11-05 20:59:42 +00:00
### Cache Poisoning
2021-11-05 20:59:42 +00:00
Kutatiza shambulio la awali lililozungumziwa la desynchronisation ya jibu la Content Confusion, **ikiwa cache inahifadhi jibu kwa ombi lililofanywa na mhasiriwa na jibu hili ni la kuingizwa linalosababisha XSS, basi cache inakuwa na sumu**.
2021-11-05 20:59:42 +00:00
Ombi la uhalifu likijumuisha payload ya XSS:
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (614).png>)
2021-11-05 20:59:42 +00:00
Jibu la uhalifu kwa mhasiriwa ambalo lina kichwa kinachoonyesha kwa cache kuhifadhi jibu:
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (566).png>)
2021-11-05 20:59:42 +00:00
{% hint style="warning" %}
Note that in this case if the **"victim" is the attacker** he can now perform **cache poisoning in arbitrary URLs** as he can **control the URL that is going to be cached** with the malicious response.
2021-11-05 20:59:42 +00:00
{% endhint %}
### Web Cache Deception
2021-11-05 20:59:42 +00:00
Shambulio hili ni sawa na la awali, lakini **badala ya kuingiza payload ndani ya cache, mshambuliaji atakuwa akihifadhi taarifa za mhasiriwa ndani ya cache:**
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (991).png>)
2021-11-05 20:59:42 +00:00
### Response Splitting
2021-11-05 20:59:42 +00:00
**Lengo** la shambulio hili ni kutumia tena **desynchronisation** ya **jibu** ili **kufanya proxy itume jibu 100% lililotengenezwa na mshambuliaji**.
2021-11-05 20:59:42 +00:00
Ili kufikia hili, mshambuliaji anahitaji kupata mwisho wa programu ya wavuti ambayo **inaonyesha baadhi ya thamani ndani ya jibu** na **ajue urefu wa maudhui ya jibu la HEAD**.
2021-11-05 20:59:42 +00:00
Atatuma **exploit** kama:
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (911).png>)
2021-11-05 20:59:42 +00:00
Baada ya ombi la kwanza kutatuliwa na kutumwa kwa mshambuliaji, **ombile la mhasiriwa linaongezwa kwenye foleni**:
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (737).png>)
2021-11-05 20:59:42 +00:00
Mhasiriwa atapokea kama jibu **jibu la HEAD + maudhui ya jibu la ombi la pili (linalojumuisha sehemu ya data iliyoonyeshwa):**
2021-11-05 20:59:42 +00:00
![](<../.gitbook/assets/image (356).png>)
2021-11-05 20:59:42 +00:00
Hata hivyo, angalia jinsi **data iliyoonyeshwa ilikuwa na ukubwa kulingana na Content-Length** ya **jibu la HEAD** ambayo **ilitoa jibu halali la HTTP katika foleni ya majibu**.
Hivyo, **ombile linalofuata la mhasiriwa wa pili** litakuwa **likipokea** kama **jibu kitu kilichotengenezwa kabisa na mshambuliaji**. Kwa kuwa jibu linatengenezwa kabisa na mshambuliaji anaweza pia **kufanya proxy ihifadhi jibu**.
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)
<details>
<summary>Support HackTricks</summary>
* 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.
</details>
{% endhint %}