Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Web attacks

Lab · Hard · 3 hoursFree account

HTTP Request Smuggling

CL.TE and TE.CL desync attacks to bypass front-end security controls.

  • request-smuggling
  • http2
  • desync
  • crlf
On this page 9 sections
  1. ·Lab Setup
  2. ·Build the target
  3. 1Detect a CL.TE / TE.CL desync
  4. 2Exploit the CL.TE desync
  5. Locked: Exploit the reverse: TE.CL
  6. Locked: CRLF injection into a reflected header
  7. Locked: HTTP/2 downgrade smuggling
  8. Locked: Defence and Detection
  9. Locked: Check Your Work

Before you start

Request smuggling exploits a parsing mismatch between a front-end proxy and a back-end server, so one HTTP request is split into two by the back-end. A smuggled prefix hijacks the next user's response or reaches an admin path behind the proxy, and shared production proxies have leaked other visitors' sessions this way. The steps below detect a CL.TE desync, build CL.TE and TE.CL payloads, inject CRLF into a reflected header, and reproduce the same bug through an HTTP/2 downgrade.

What You'll Learn

  • Detect a CL.TE / TE.CL desync between a front-end and a back-end server
  • Build a CL.TE smuggling payload that prepends to the next user's request
  • Build a TE.CL smuggling payload that poisons the response queue
  • Inject raw CRLF bytes into a header value the app reflects unsanitised
  • Explain how an HTTP/2-to-HTTP/1.1 downgrade can reopen the same class of bug
  • Map the fix to each desync type

Lab Setup

Request smuggling depends on exact, malformed bytes that curl normalises away. You need raw socket control.

Tools and versions

  • Python 3 (standard library socket only — no third-party package needed).
  • nghttp (from the nghttp2-client package) for the Step 5 HTTP/2 request.
  • curl 8.x to confirm ordinary behaviour before you start desyncing the connection.

Build the target

KaliRange hosts no targets, no virtual machines and no lab files. You run this lab on your own machine, against two servers that you build. The host names kalirange-proxy.lab and kalirange-backend.lab are the example names of this lab. Replace them with the names or addresses of your own servers, in the commands and in smuggle.py.

Your lab must have these parts:

HostRole
kalirange-proxy.labFront-end reverse proxy. An older nginx build that you keep deliberately unpatched. It listens on port 80 and on port 443 with HTTP/2.
kalirange-backend.labBack-end web application. The proxy forwards to it on a persistent, reused connection.
  • The front-end and the back-end must read the length of a request by different rules, so that Steps 1 to 3 show the hang and the second response.
  • The back-end answers GET /admin with 403 Forbidden, and GET / with a normal page.
  • The path /redirect?to=/home answers 302 Found with Location: /home. It copies the value of X-Forwarded-Host into a response header without removing line breaks (Step 4).
  • The front-end ends HTTP/2 from the client and sends the request to the back-end as HTTP/1.1 text, without checking the header values again (Step 5).

Build it from free, legal parts: two virtual machines or containers on your own computer, with an older, unpatched nginx as the proxy and a small web application of your own as the back-end. No public training target is named here, because the flaw is in how your two servers are set up. Take a snapshot of each machine before Step 1.

Test only a front-end that you own or have written permission to test. A smuggled request can land in front of a real visitor's traffic. Outside an isolated lab, that is an attack on other people's sessions, not just the server. Never run this against shared or production infrastructure, even your employer's own, without a signed, explicit smuggling-test authorisation.

Save this small helper once. It sends an exact byte string and prints the raw response, with no normalisation.

cat > smuggle.py << 'EOF'
#!/usr/bin/env python3
import socket, sys
host, port = "kalirange-proxy.lab", 80
req = sys.stdin.buffer.read()
s = socket.create_connection((host, port), timeout=5)
s.sendall(req)
s.settimeout(3)
try:
    data = s.recv(8192)
    print(data.decode(errors="replace"))
except socket.timeout:
    print("[no more data — connection likely hung]")
s.close()
EOF

Step 1: Detect a CL.TE / TE.CL desync

1

A desync exists when the front-end and the back-end disagree about where one request ends. You find this before exploiting it by sending a request that the two would parse to different lengths, and watching for a hang: proof that one of them is still waiting for bytes the other already thinks it has consumed.

printf 'POST / HTTP/1.1\r\nHost: kalirange-proxy.lab\r\nContent-Length: 4\r\nTransfer-Encoding: chunked\r\n\r\n1\r\nA\r\n0\r\n\r\n' | python3 smuggle.py

Example output:

[no more data — connection likely hung]

What to notice: this request has both Content-Length: 4 and a Transfer-Encoding: chunked body. If the front-end trusts Content-Length and forwards exactly 4 bytes (1\r\nA), the back-end — which trusts Transfer-Encoding — is left waiting for the terminating 0\r\n\r\n chunk that never arrived. A hang here is the classic timing signature of a CL.TE desync.

Never run this detection probe, or any step below, against a server with real traffic on it. A hung connection on a shared front-end can tie up a worker thread and affect other visitors while you are testing.

Step 2: Exploit the CL.TE desync

2

In a CL.TE mismatch, the front-end forwards a short body by Content-Length, but the back-end re-reads past that point because it is parsing Transfer-Encoding: chunked. Whatever bytes sit after the short body become the start of a second, smuggled request on the same connection.

printf 'POST / HTTP/1.1\r\nHost: kalirange-proxy.lab\r\nContent-Length: 13\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\nSMUGGLED' | python3 smuggle.py

Example output:

HTTP/1.1 200 OK
Content-Type: text/html

<html>...normal page...</html>

What to notice: the front-end reads exactly Content-Length: 13 bytes (0\r\n\r\nSMUGGLED) as this request's whole body and forwards it as-is. The back-end instead reads the 0\r\n\r\n as a zero-length final chunk, ending this request right there, and treats the leftover text SMUGGLED as the first bytes of the next request it reads off the same reused connection — which is wherever the next real visitor's request lands.

Sign in to continue

5 more sections are for signed-in members. It is free: sign in with Google.