HTTP smuggling is an attack vector that exploits the way HTTP requests and responses are parsed and transmitted between a client and server. It involves hiding data in unexpected places, such as HTTP headers or request bodies, to bypass security restrictions and execute malicious activities.
Here's a complex example of HTTP smuggling:
Let's say an application provides a RESTful API that allows users to upload files. To prevent remote code execution (RCE) attacks, the server checks the Content-Type header of each uploaded file to ensure that it's a valid image or document format.
However, an attacker can use HTTP smuggling to bypass this restriction by crafting a malicious request that includes two requests separated by a blank line. The first request is a legitimate file upload, while the second request is a malicious payload that's hidden in the blank line and pretends to be a new request's content.
Here's an example:
code
POST /upload HTTP/1.1
Host: example.com
Content-Length: 4096
Content-Type: image/jpeg
[binary JPEG file here]
--hidden--
POST /execute HTTP/1.1
Host: example.com
Content-Length: 100
Content-Type: application/x-shellscript
#!/bin/bash
whoami
echo "Executed by an attacker" >> /tmp/smuggled.txt
In this example, the attacker splits the request into two parts by inserting "--hidden--" at the end of the legitimate file upload. This line serves as a boundary between the two requests and indicates to the server that the first request is complete.
The second request is hidden in the blank line after "--hidden--". This request appears to be a new request with a different Content-Type header, but in reality, it's part of the first request that's being smuggled.
The server receives the request, parses the first request (which contains the JPEG file) and checks its Content-Type header. It then parses the blank line and sees the "--hidden--" boundary, which indicates that the first request is complete.
The server then continues parsing the request and sees the second request's headers, including its Content