请求走私往往存在于前后端服务器之中,客户端发送TCP流给前端服务器(如nginx,Cloudflare,Tomcat,Apache),再转发给后端。两者解析请求的方式不一样导致漏洞存在
HTTP request smuggling, basic CL.TE vulnerability
To solve the lab, smuggle a request to the back-end server, so that the next request processed by the back-end server appears to use the method
GPOST.
根据 HTTP/1 规范,前端可以使用两个不同的头部(header)来指定不同的消息长度。如果两种方法发生冲突,后端会优先使用 Transfer-Encoding。
假如前端仅支持Content-Length发送请求,而后端用Transfer-Encoding解析
首先,我们把请求发送到 Repeater,并启用 Show non-printable chars(显示不可打印字符),这样我们就能知道如何编写结尾。此外,我们必须在 Inspector 中将 HTTP 协议从 2 降级到 1。

然后,我们在请求中伪造了两种方法。
Content-Length: 6
Transfer-Encoding:chunked
之后,我们在下方两行处构造了分块(chunk)结束标记 0\r\n\r\n,后面跟着载荷(payload)G。
发送两次后,我们可以注意到第二次响应中显示了一条消息 "Unrecognized method GPOST",这是因为我们写下的 G 被添加到了第二个请求的开头。

HTTP request smuggling, basic TE.CL vulnerability
This lab involves a front-end and back-end server, and the back-end server doesn't support chunked encoding. The front-end server rejects requests that aren't using the GET or POST method.
To solve the lab, smuggle a request to the back-end server, so that the next request processed by the back-end server appears to use the method
GPOST.
假如前端仅支持Transfer-Encoding发送请求,而后端用Content-Length解析
在开始之前,我们需要先理解 HTTP RFC 的机制。
一个分块(chunk)被分为三个部分:
> hex number\r\n (指的是分块(chunk)数据的字节长度,不包含 \r\n )
> content\r\n
> 0\r\n\r\n
由于前端使用了 Transfer-Encoding 头部,我们必须在请求中伪造一个分块(chunk)。
Content-Length: 3
Transfer-Encoding: chunked
3
uky
0
注意这里有两个数字 3,它们有不同的含义。
Content-Length 中的第一个 3 指的是 3\r\n,使用 Content-Length 方法的后端会识别出应在字符串 uky 之前进行截断。第二个 3 用于分块(chunk)中,用来指定字符的大小。
然后,剩余的载荷(payload)会被保存到 TCP 缓冲区中。当发送下一个请求时,uky0 会被添加到它的开头。

TE.TE behavior: obfuscating the TE header
This lab involves a front-end and back-end server, and the two servers handle duplicate HTTP request headers in different ways. The front-end server rejects requests that aren't using the GET or POST method.
To solve the lab, smuggle a request to the back-end server, so that the next request processed by the back-end server appears to use the method
GPOST.
如果两个都使用Transfer-Encoding。但为了让请求走私成功,我们需要人为混淆某一端的Transfer-Encoding头部使它失效,再使用Content-Length
我们所要做的,就是让前端产生歧义使TE失效,于是我们写了两条TE,其中一条是假的

我们也可以用
Transfer-Encoding:xchunked
Transfer-Encoding: chunked
Transfer-Encoding:chunked
达成歧义效果
Exploiting HTTP request smuggling to reveal front-end request rewriting
This lab involves a front-end and back-end server, and the front-end server doesn't support chunked encoding.
这个实验涉及前端和后端服务器,而前端服务器不支持分块编码技术。There's an admin panel at
/admin, but it's only accessible to people with the IP address 127.0.0.1. The front-end server adds an HTTP header to incoming requests containing their IP address. It's similar to theX-Forwarded-Forheader but has a different name.
在/admin有一个管理面板,但只有具有 IP 地址 127.0.0.1 的用户才能访问该面板。前端服务器会在收到的请求中添加带有该 IP 地址的 HTTP 头信息。这个头信息与X-Forwarded-For头信息类似,但名称不同。
从信息可知,这是CL.TE型的请求走私
首先我们要先知道XFF的头是什么,这是从前端服务器添加的,而响应是从后端服务器返回的,所以我们需要的是前端服务器到后端服务器之间的请求
其中,在我们使用搜索功能时会传递search参数,如果我们搜索不存在的字段,他就会返回0 search results for 'XXX'这个XXX就是我们的突破口,因为它是后端处理过后的东西,肯定经过了前端,我们需要把前端服务器处理过后的请求包含在里面
通过走私一个包含search的请求到后端的TCP缓存里,然后再发送一个正常请求,经过前端加上XFF就会和缓存请求里的搜索字段拼接在一起,报错就会返回XFF

这个过程就叫请求重写
H2.CL request smuggling
This lab is vulnerable to request smuggling because the front-end server downgrades HTTP/2 requests even if they have an ambiguous length.
To solve the lab, perform a request smuggling attack that causes the victim's browser to load and execute a malicious JavaScript file from the exploit server, calling
alert(document.cookie). The victim user accesses the home page every 10 seconds.
先看懂http2的连接过程
TCP/TLS 连接
└─ 前奏: PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n + SETTINGS
├─ Stream 1 (请求A)
├─ HEADERS ─ DATA(END_STREAM)
├─ [连接级] PING / SETTINGS / WINDOW_UPDATE / GOAWAY
└─ 结束: GOAWAY
建立 TLS 后,客户端要先发一段 24 字节的魔数,再加一个 SETTINGS 帧 ( 连接配置参数 ),服务端发收到后发送SETTINGS+ACK确认,建立了一条连接
其中值得注意的是, 24 字节的魔数PRI * HTTP/2.0...的作用就是为了确保在不支持http/2的服务端中能够降级成http/1.1
在这条连接中,每个请求叫做流,一个流里包含 1 个 HEADERS 帧(+ 可能 CONTINUATION)+ 0~N 个 DATA 帧 ,最后那个帧带 END_STREAM 标志表示消息结束,其中Stream 0代表该条连接,用于全局设置(连接级)
HEADERS 帧里是由 HPACK 压缩成的二进制伪头,伪头明文为
:method: POST
:scheme: https
:authority: example.com
:path: /api/login
http2支持在伪头下面加上普通头,比如content-type,content-length,这是请求劫持的关键;后面则是Data帧
H2.CL指的是客户端和前端服务器必须是Http2传输,但后端服务器只支持Http1的CL处理数据,所以请求必须经过一次降级。一般来说数据帧降级时会统计帧负载字节数自动转换为一样的Content-Length,但假如我们提前在伪头里写入Content-Length,后端可能直接复用
burp支持自解析,可以把http2请求转化成http1的格式

可以看到访问/resources的请求成功走私进后端TCP缓存中了,我们根据提示改/resources就行了
而且还发现一条连接只能成功一次,因为tcp缓存区不会自动清理
H2.TE漏洞类似,把Content-Length换成Transfer-Encoding: chunked\r\n\0r\n\r\n,这些漏洞其实都却决于前端服务器是否配置得当
HTTP/2 request smuggling via CRLF injection
This lab is vulnerable to request smuggling because the front-end server downgrades HTTP/2 requests and fails to adequately sanitize incoming headers.
To solve the lab, use an HTTP/2-exclusive request smuggling vector to gain access to another user's account. The victim accesses the home page every 15 seconds.
假如前端服务器做了防范,会自动识别CL TE并去除,我们可以利用两个协议的差别来混淆前端
这个差别就是header的识别方式,http2是以二进制键值对识别请求头,而http1是利用CRLF也就是换行符识别
那么我们可以利用CRLF混淆前端识别,从而走私到后端
我们可以看到搜索的结果在主页面有回显

于是我们构造一个走私请求,其中加上一个特殊的请求头,利用换行符把TE混淆进去,然后后面跟上结束符和走私内容(即搜索请求)

值得注意的是,burp不会显示发生在http2里的换行符注入内容,他会提示kettled已搁置,但这并不影响我们使用
绕过前端的检测后,后端的http1就会利用换行符把TE分成一个新请求头,进而使搜索请求走私到缓存
当某个用户访问该网站时,他的隐私就会泄露

请求头还可以用换行符混淆新的请求,具体方法一样,叫做请求分割
到这里其实Request smuggling的内容基本差不多了,后面预计会做OAuth 2.0安全的靶场
