hacktricks/pentesting-web/http-request-smuggling/request-smuggling-in-http-2-downgrades.md

165 lines
9.6 KiB
Markdown
Raw Normal View History

2022-04-28 23:27:22 +00:00
# Request Smuggling in HTTP/2 Downgrades
2022-04-28 16:01:33 +00:00
2022-05-01 13:25:53 +00:00
## Request Smuggling in HTTP/2 Downgrades
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Support HackTricks and get benefits!</strong></summary>
Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
**Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.**
**Share your hacking tricks submitting PRs to the** [**hacktricks github repo**](https://github.com/carlospolop/hacktricks)**.**
</details>
2022-05-01 13:25:53 +00:00
## Origins
2021-11-05 20:59:42 +00:00
2021-11-30 16:46:07 +00:00
The main origin of this vulnerability is the fact that the **reverse proxy** is going to **talk with the client** using **HTTP/2** but then it will **transform** that **communication** with the **back-end server** to **HTTP/1.1**.
2021-11-05 20:59:42 +00:00
2022-03-09 12:12:51 +00:00
![](<../../.gitbook/assets/image (636) (1).png>)
2021-11-05 20:59:42 +00:00
The problem with this approach is that the **user** is going to be able to **inject** unnecessarily **headers** in the **HTTP/2 communication** that probably **won't be checked** by the proxy. But then, when those are **injected blindly in the HTTP/1.1 communication**, **a request smuggling attack can be performed**.
2022-05-01 13:25:53 +00:00
## Examples
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### H2.CL Desync
2021-11-05 20:59:42 +00:00
The HTTP/2 specification indicates that the **Content-Length header isn't needed but can be indicated**. Therefore, the **reverse proxy** will **treat all the content sent by the users** as the request, but then, when **downgrading to HTTP/1.1**, this **header** is going to be **injected** in the **request** and therefore, the **back-end will treat the request as 2 different requests** as you can see in the image below:
![](<../../.gitbook/assets/image (639).png>)
2022-05-01 13:25:53 +00:00
### H2.TE Desync URL Token Hijack
2021-11-05 20:59:42 +00:00
The HTTP/2 specification also indicates that **any message containing connection-specific header fields MUST be treated as malformed... but if you don't follow this rule, you are vulnerable**.
This technique was abused on AWS load balancer, so making sure that the users access a Host header pointing to a server controlled by the attacker will make them access that server.
2022-03-09 12:33:12 +00:00
![](<../../.gitbook/assets/image (631) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### H2.TE Desync Header Hijack
2021-11-05 20:59:42 +00:00
This is exactly the same technique as before, but checking the requests James noticed that clients were asking to send him their credentials, so he just modified his server to allow CORS to send him peoples credentials:
2022-04-22 08:32:18 +00:00
![](<../../.gitbook/assets/image (662) (1) (1) (1) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### H2.TE via Request Header Injection
2021-11-05 20:59:42 +00:00
2021-11-30 16:46:07 +00:00
**HTTP/2 also won't allow to put not permitted characters in headers**, but if the server **isn't respecting** this rule, you can **inject arbitrary headers** when the communication is **downgraded** to HTTP/1.1.
2021-11-05 20:59:42 +00:00
In this case **the header Transfer-Encoding was injected**.
2022-04-25 12:04:04 +00:00
![](<../../.gitbook/assets/image (648) (1) (1) (1) (1) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### H2.TE via Header Name Injection
2021-11-05 20:59:42 +00:00
2022-04-28 23:27:22 +00:00
HTTP/2 on some servers lets you put a **colon in the header name, and with a** you can inject a new header inside the header name like this:
2021-11-05 20:59:42 +00:00
2022-02-17 16:34:34 +00:00
![](<../../.gitbook/assets/image (632) (1).png>)
2021-11-05 20:59:42 +00:00
Note that if you put just the new line characters sending a header without content, the request is going to be treated as **invalid**:
2022-04-20 12:35:33 +00:00
![](<../../.gitbook/assets/image (647) (1) (1) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### H2.TE via Request LIne Injection
2021-11-05 20:59:42 +00:00
In this case the injection was performed inside the request line:
2022-05-29 12:54:31 +00:00
![](<../../.gitbook/assets/image (645) (1) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### URL Prefix Injection
2021-11-06 01:29:12 +00:00
Inside the scheme of the HTTP/2 connection you might be able to send a full URL that will overwrite the one indicated in the path:
2022-04-05 22:13:36 +00:00
![](<../../.gitbook/assets/image (661) (1) (1).png>)
2021-11-06 01:29:12 +00:00
2022-05-01 13:25:53 +00:00
### Request Line Injection via spaces
2021-11-06 01:29:12 +00:00
2022-03-13 16:39:41 +00:00
![](<../../.gitbook/assets/image (641) (1).png>)
2021-11-06 01:29:12 +00:00
2022-05-01 13:25:53 +00:00
## Frontend->backend connection reuse
2021-11-05 20:59:42 +00:00
Sometimes you will find that preforming a HTTP Request Smuggling attack **you can only attack yourself**. This could be because the reverse proxy has decided to **use a different connection with the back-end** server per IP.
Note that **even** with that **restriction** you still can perform attacks like **authorization bypasses**, internal headers leakage and **cache deception and cache poisoning** attacks.
2021-11-30 16:46:07 +00:00
Usually this restriction doesn't exist so you can **smuggle request into the connection between the reverse proxy and the back end** that other people are using, but it's even **possible** that the **proxy** doesn't **even reuse a connection with connections from the same IP** (pretty heavy restriction for this kind of attack).
2021-11-05 20:59:42 +00:00
2022-03-09 12:12:51 +00:00
![](<../../.gitbook/assets/image (646) (1) (1).png>)
2021-11-05 20:59:42 +00:00
In the heaviest restriction (no connection reuse) you will detect the vulnerability with the Time Based technique, but then testing it you will find that it's a "false positive".
2022-05-01 13:25:53 +00:00
### Tunnelling Confirmation
2021-11-05 20:59:42 +00:00
2021-11-30 16:46:07 +00:00
A way to **confirm** if the **endpoint is vulnerable** but the connection is **inside a "tunnel"** is to **smuggle 2 full requests** into 1.
2021-11-05 20:59:42 +00:00
The **problem** with **HTTP/1.1** is that if you **receive 2 HTTP responses** you **don't know** if the endpoint was **vulnerable** or it isn't and the **"smuggled" request was just treated as a regular request**.
However, this technique can be used **in HTTP/2** because if the endpoint was **vulnerable** and you smuggled one request, you will see the **headers of the response to the smuggled request in the response from the reverse proxy**:
2022-04-20 12:35:33 +00:00
![](<../../.gitbook/assets/image (652) (1) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### Tunnel-vision Problem
2021-11-05 20:59:42 +00:00
2021-11-30 16:46:07 +00:00
There could be another problem, if the **response** to the legit request **contains** a **Content-Length**, the **reverse prox**y is only going to **read the bytes specified there and no more, so you won't be able to read the response from the smuggled request.**
2021-11-05 20:59:42 +00:00
However, the **HEAD** request **doesn't contain a body** but it usually **contains** the **Content-Length** as if the request was a GET request. Therefore, sending a **HEAD** request **instead of a POST** request you can **read the HEAD Content-Length** bytes of the smuggled request response.
2022-03-21 17:37:28 +00:00
![](<../../.gitbook/assets/image (628) (1) (1).png>)
2021-11-05 20:59:42 +00:00
2022-05-01 13:25:53 +00:00
### Leaking Internal Headers via Tunneling
2021-11-05 20:59:42 +00:00
If you find a **POST** **parameter** inside the application whose **content** is going to be **reflected** in the **response**, then you can try to inject HTTP/1.1 \r\n characters inside a HTTP/2 request header so the newly injected headers by the proxy are going to be appended in the POST parameter that will be reflected in the response:
2022-03-09 12:12:51 +00:00
![](<../../.gitbook/assets/image (656) (1) (1).png>)
2021-11-05 20:59:42 +00:00
Note that in this case the **attacker** just cares about the **response** to the **first** **request**, he doesn't need to read the request to the smuggled invalid second request.
{% hint style="info" %}
Using this attack **agains different parts of the web (method, path...)** can lead to different back-ends being used and **different sensitive information being leaked**
{% endhint %}
2022-05-01 13:25:53 +00:00
### Cache Poisoning via Tunneling
2021-11-05 20:59:42 +00:00
In this scenario a **HEAD** request to the **URL** **whose** **cache** is going to be **poisoned** is sent while **smuggling** a **request** whose **response content will be containing the payload** (maybe some XSS payload).
Due to the fact the the **HEAD response contains the `Content-Type: text/html`** and because the reverse proxy thinks that the **whole response to the smuggled request is the body of the HEAD** request, the **XSS payload** is going to be **treated as HTML** even if the page wasn't vulnerable to XSS.
2022-03-09 12:12:51 +00:00
![](<../../.gitbook/assets/image (659) (1).png>)
2021-11-06 01:29:12 +00:00
2022-05-01 13:25:53 +00:00
## Hidden HTTP/2
2021-11-06 01:29:12 +00:00
Usually servers advertise the support via ALPN field in TLS handshake, but some doesn't.
It can be easily detected using `curl --http2 --http2-prior-knowledge`
2022-05-01 13:25:53 +00:00
## Tools
2021-11-06 01:29:12 +00:00
* Burp extension: HTTP Request Smuggler
* [https://github.com/neex/http2smugl](https://github.com/neex/http2smugl)
2022-05-01 13:25:53 +00:00
## References
2021-11-06 01:29:12 +00:00
* This talk explains perfectly all the techniques indicated here: [https://www.youtube.com/watch?v=rHxVVeM9R-M](https://www.youtube.com/watch?v=rHxVVeM9R-M)
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Support HackTricks and get benefits!</strong></summary>
Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
**Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.**
**Share your hacking tricks submitting PRs to the** [**hacktricks github repo**](https://github.com/carlospolop/hacktricks)**.**
</details>