nginx 邮件代理模块(ngx_mail_proxy_module)中存在一个释放后使用漏洞:当客户端在 IMAP 认证流程中于精确的时机发送 TCP RST 时即可触发。被释放的共享会话上下文随后会被上游处理器解引用,导致 worker 崩溃。
| 字段 | 值 |
|---|---|
| CVE | CVE-2026-113425 |
| CVSS 3.1 | 7.5 High — AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| CWE | CWE-416(释放后使用) |
| 组件 | ngx_mail_proxy_module |
| 受影响版本 | nginx 0.5.33 – 1.31.8 |
| 修复版本 | nginx 1.30.7 / 1.31.9 |
| 需要认证 | 否 |
| 披露日期 | 2026-11-18 |
当 nginx 将邮件客户端代理到上游 IMAP/SMTP/POP3 服务器时,它会分配一个在下游和上游事件处理器之间共享的会话上下文。如果客户端通过 SO_LINGER 并配合 l_linger = 0 在恰当的时机发送 TCP RST——即在上游连接已建立、但 nginx 尚未完成会话拆除之前——客户端侧处理器会释放该共享上下文,而上游处理器仍持有指向它的指针。随后发生的上游事件便会解引用已释放的内存。
实验环境布局:
client (poc.py) → nginx:1.31.8 mail proxy → imapd:143 (fake IMAP, holds LOGIN for 20s)
↑ auth_http → authd:9000 (always OK)
flowchart LR
A([Attacker]) -->|TCP connect :143\nIMAP greeting| B[nginx mail proxy\n1.31.8]
B -->|proxy to upstream\nIMAPD| C[Fake IMAP\nHolds LOGIN 20s]
A -->|TCP RST via SO_LINGER\nat LOGIN hold window| B
B -->|client handler frees\nshared session context| D{UAF}
D -->|upstream event\ndereferences freed ptr| E[Worker SIGSEGV\nDoS]
style A fill:#3d1a1a,stroke:#f85149,color:#f85149
style E fill:#1a1f2e,stroke:#f85149,color:#f85149
警告: 仅限 Docker Compose 实验环境。切勿对生产邮件服务器运行。
docker compose up --build -d
sleep 3
python3 poc.py
预期输出——存在漏洞的 nginx:
[+] SIGSEGV detected in nginx worker — USE-AFTER-FREE CONFIRMED
docker compose logs -f nginx
# RST immediately after receiving the IMAP greeting
python3 poc.py --mode after-greeting
# RST after sending LOGIN command, before response
python3 poc.py --mode mid-login
# RST 500ms into the 20-second hold window (default)
python3 poc.py --mode after-auth
# Stress test: 50 parallel connections with mixed RST timings
python3 poc.py --mode burst --count 50
| 标志 | 描述 |
|---|---|
--mode after-greeting|mid-login|after-auth|burst | RST 时序(默认:after-auth) |
--count N | burst 模式的连接数 |
--host HOST | nginx 主机(默认:127.0.0.1) |
--port PORT | IMAP 端口(默认:143) |
| 模式 | RST 时序 |
|---|---|
after-greeting | 收到 * OK 后立即发送 |
mid-login | 发送 LOGIN 后、响应之前 |
after-auth | 在 20 秒保持窗口的第 500 毫秒 |
burst | 大量并行连接,混合时序 |
docker compose logs -f nginx
# Look for: "worker process <pid> exited on signal 11"
# Patch the Dockerfile
sed -i 's/nginx:1.31.8/nginx:1.31.9/' nginx/Dockerfile
docker compose build --no-cache nginx && docker compose up -d
python3 poc.py --mode after-auth
# nginx handles RST cleanly, logs: "connection reset by peer"
| 指标 | 说明 |
|---|---|
| nginx worker 崩溃(信号 11) | nginx error.log:“worker process exited on signal 11” |
| 低流量下 worker 反复重启 | 主进程在 IMAP 认证尝试后重新生成 worker |
使用 SO_LINGER=0 连接到邮件端口 | 在 IMAP LOGIN 期间于网络层检测到 TCP RST |
未认证的远程拒绝服务。每个 nginx worker 只需一个精心构造的连接即可使其崩溃。在 worker_processes N 的情况下,需要 N 个连接才能完全拒绝服务。典型情况下不存在内存损坏——重启即可恢复服务。
升级到 nginx 1.30.7(稳定版)或 nginx 1.31.9(主线版)。该修复确保会话上下文的生命周期在客户端和上游处理器中均被正确跟踪。
| 操作 | 详情 |
|---|---|
| 升级 nginx | 1.30.7(稳定版)或 1.31.9(主线版) |
| 监控 worker 重启 | 对 nginx worker 反复出现信号 11 的情况发出告警 |
| 限制 IMAP 连接速率 | 在防火墙处限制每个 IP 的连接数 |
免责声明: 仅用于授权的安全研究和受控实验室环境。MIT 许可证。