gensecaihq/react2shell-scanner

GitHub: gensecaihq/react2shell-scanner

针对 CVE-2025-55182 的 React Server Components 漏洞扫描与自动修复工具。

Stars: 56 | Forks: 7

# react2shell-guard **CVE-2025-55182** 的安全扫描器 - 一种针对 React Server Components 的关键(CVSS 10.0)无认证远程代码执行漏洞。 ## 感谢 本项目旨在帮助社区应对 CVE-2025-55182。我们认可并感谢: - **[Lachlan Davidson](https://github.com/lachlan2k)** ([react2shell.com](https://react2shell.com/)) - 于 2025 年 11 月 29 日发现并负责任地披露了 React Server Components 漏洞(CVE-2025-55182)。他的勤勉帮助识别了这一关键缺陷,并与 React 和 Next.js 团队合作确保了补丁的可用性。他的努力帮助保护了全球无数的应用程序和用户。请参阅他的 [原始 PoC](https://github.com/lachlan2k/React2Shell-CVE-2025-55182-original-poc) 以获取技术细节。 ## 快速开始 ### 1. 即时扫描(无需安装) 检查项目是否易受攻击的最快方式: ``` npx react2shell-guard . ``` 就这样!这将扫描当前目录并立即显示结果。 ### 2. 扫描特定项目 ``` npx react2shell-guard /path/to/your/project ``` ### 3. 自动修复漏洞 发现漏洞?自动修复它们: ``` # 预览将更改的内容 npx react2shell-guard fix --dry-run # 应用修复 npx react2shell-guard fix # 应用修复并重新安装依赖项 npx react2shell-guard fix --install ``` ### 4. 扫描活动 URL 检查已部署的应用程序是否易受攻击: ``` npx react2shell-guard scan-url https://your-app.com ``` ### 5. 验证补丁是否已应用 确认已部署的修复程序是否有效: ``` npx react2shell-guard verify-patch https://your-app.com ``` ### 6. 扫描容器镜像 检查 Docker 镜像是否包含易受攻击的软件包: ``` npx react2shell-guard scan-image myapp:latest ``` ### 7. 创建修复 PR(GitHub) 自动创建 GitHub PR 以修复漏洞: ``` npx react2shell-guard create-pr --dry-run # Preview npx react2shell-guard create-pr # Create PR ``` ## 什么是 CVE-2025-55182? 2025 年 11 月 29 日,安全研究员 Lachlan Davidson 发现并负责任地披露了 React Server Components 中的一项关键漏洞。该漏洞存在于 React 解码发送到 React Server Function 端点的负载的方式中,允许无认证攻击者在无需任何用户交互的情况下在受影响的服务器上实现远程代码执行。 CVE-2025-55182 被评为 CVSS 10.0(关键),并影响 React Server Components(RSC)以及使用 RSC “Flight” 协议的框架。 **受影响的软件包:** - `react-server-dom-webpack` 19.0.0、19.1.0-19.1.1、19.2.0 - `react-server-dom-parcel`(相同版本) - `react-server-dom-turbopack`(相同版本) - `next` 15.0.0-15.0.4、15.1.0-15.1.8、15.2.0-15.2.5、15.3.0-15.3.5、15.4.0-15.4.7、15.5.0-15.5.6、16.0.0-16.0.6 **更多信息:** - [React 安全公告](https://react.dev/blog/2025/12/03/critical-security-vulnerability-in-react-server-components) - [Wiz Research](https://www.wiz.io/blog/critical-vulnerability-in-react-cve-2025-55182) ## 安装(可选) 对于频繁使用,可以全局安装: ``` npm install -g react2shell-guard ``` 然后无需 `npx` 直接使用: ``` react2shell-guard . ``` ## 使用指南 ### 基本扫描 ``` # 扫描当前目录 react2shell-guard . # 扫描特定目录 react2shell-guard /path/to/project # 扫描并忽略某些路径 react2shell-guard . --ignore-path "examples/**" "test/**" ``` ### 输出格式 ``` # 易读文本(默认) react2shell-guard . # JSON 输出(用于脚本编写) react2shell-guard . --json # SARIF 输出(用于 GitHub Security 标签) react2shell-guard . --sarif # HTML 报告(独立,可共享) react2shell-guard . --html report.html ``` ### CLI 选项 | 选项 | 描述 | |------|------| | `--json` | 以 JSON 格式输出结果 | | `--sarif` | 以 SARIF 2.1.0 格式输出结果 | | `--html ` | 生成独立的 HTML 报告 | | `--no-exit-on-vuln` | 发现漏洞时不以代码 1 退出 | | `--ignore-path ` | 忽略的路径(例如 `examples/**`) | | `--debug` | 启用调试输出 | ### 退出代码 | 代码 | 含义 | |------|------| | `0` | 未发现漏洞 | | `1` | 检测到漏洞 | | `2+` | 致命错误 | ## 活动 URL 扫描 扫描活动端点以检测它们是否易受攻击: ``` # 扫描单个 URL react2shell-guard scan-url https://example.com # 从文件批量扫描(每行一个 URL) react2shell-guard scan-url urls.txt --list # 带选项 react2shell-guard scan-url https://example.com --timeout 5000 --json ``` ### 活动 URL 扫描的工作原理 扫描器使用 **被动指纹识别** 来检测易受攻击的 React Server Components 端点,而不会利用该漏洞: 1. **探测请求**:发送一个经过精心设计的 POST 请求,模拟 RSC Server Action 调用,包含最小的负载: - 使用 `multipart/form-data` 内容类型,并带有类似 RSC 的数据结构 - 包含 `Next-Action` 标头以触发 Server Action 处理 2. **响应分析**:分析 HTTP 响应是否存在漏洞特征: - 检查 HTTP 500 状态码(错误响应) - 匹配响应体中的 RSC Flight 协议错误模式: - `^[0-9]+:E{` - RSC Flight 协议错误格式 - `"digest":"...RSC` - 错误响应中的 RSC 摘要 - `ReactServerComponentsError` - React 错误类名 - `text/x-component.*error` - 组件错误内容类型 3. **非破坏性**:这纯粹是一种检测机制 - **不会** 执行任何恶意负载或利用漏洞。探测使用无害数据,在易受攻击的服务器上触发错误响应,但不会造成任何伤害。 ### URL 扫描选项 | 选项 | 描述 | |------|------| | `--list` | 将目标视为包含 URL 的文件 | | `--threads ` | 并发线程数(默认:10) | | `--timeout ` | 请求超时(毫秒,默认:10000) | | `--json` | 以 JSON 格式输出结果 | | `--skip-ssl-verify` | 跳过 SSL 证书验证 | | `--verbose` | 显示所有结果,包括非易受攻击的主机 | ## 补丁验证 验证目标是否已针对该漏洞打补丁: ``` # 验证补丁状态(运行多次扫描以确保准确性) react2shell-guard verify-patch https://example.com # 带 JSON 输出 react2shell-guard verify-patch https://example.com --json ``` ### 补丁验证的工作原理 补丁验证执行 **多次连续扫描**(默认:3 次),每次扫描之间有短暂延迟,以确保准确检测: 1. **多次探测**:以 500 毫秒的间隔运行相同的被动指纹识别检查 3 次 2. **置信度评分**: - **高置信度**:2 次或更多次成功扫描,结果一致 - **中等置信度**:1 次成功扫描且结果明确 - **低置信度**:所有扫描均失败或结果不一致 3. **结果分类**: - **PATCHED**:在所有成功的扫描中均未检测到漏洞特征 - **VULNERABLE**:在一次或多次扫描中检测到漏洞特征 - **Inconclusive**:结果混合或所有扫描均失败 这种多扫描方法可减少瞬态网络问题导致的误报,并提供更高的置信度。 ### 验证选项 | 选项 | 描述 | |------|------| | `--timeout ` | 请求超时(毫秒,默认:10000) | | `--json` | 以 JSON 格式输出结果 | | `--skip-ssl-verify` | 跳过 SSL 证书验证 | ## 容器镜像扫描 扫描 Docker/OCI 容器镜像中的易受攻击软件包: ``` # 扫描本地或远程镜像 react2shell-guard scan-image myapp:latest # 从注册表扫描 react2shell-guard scan-image registry.example.com/myapp:v1.0 # 跳过拉取(仅使用本地镜像) react2shell-guard scan-image myapp:latest --skip-pull # 带 JSON 输出 react2shell-guard scan-image myapp:latest --json # 带 SARIF 输出 react2shell-guard scan-image myapp:latest --sarif ``` ### 容器扫描选项 | 选项 | 描述 | |------|------| | `--timeout ` | 操作超时(毫秒,默认:120000) | | `--skip-pull` | 跳过从注册表拉取镜像(仅使用本地镜像) | | `--json` | 以 JSON 格式输出结果 | | `--sarif` | 以 SARIF 2.1.0 格式输出结果 | | `--no-exit-on-vuln` | 发现漏洞时不以代码 1 退出 | | `--debug` | 启用调试输出 | **要求:** - 必须安装并运行 Docker - 需要足够的磁盘用于镜像提取 ## Vercel 部署集成 在部署到达生产环境前阻止易受攻击的部署: ``` # 作为构建命令的一部分运行 react2shell-guard vercel-check # 在 package.json 中 { "scripts": { "vercel-build": "react2shell-guard vercel-check && next build" } } # 或在 vercel.json 中 { "buildCommand": "npx react2shell-guard vercel-check && npm run build" } ``` ### Vercel 检查选项 | 选项 | 描述 | |------|------| | `--no-fail` | 警告但不因漏洞使构建失败 | | `--ignore-path ` | 忽略的路径(通配符模式) | | `--debug` | 启用调试输出 | ## GitHub PR 自动化 自动创建拉取请求以修复漏洞: ``` # 预览将要执行的操作 react2shell-guard create-pr --dry-run # 创建分支并提交 PR react2shell-guard create-pr # 创建分支但不推送/创建 PR react2shell-guard create-pr --no-push # 自定义分支名称 react2shell-guard create-pr --branch fix/security-update ``` ### 创建 PR 选项 | 选项 | 描述 | |------|------| | `--branch ` | 用于修复的分支名称(默认:`fix/cve-2025-55182`) | | `--dry-run` | 显示将要执行的操作而不实际更改 | | `--no-push` | 创建分支和提交但不推送或创建 PR | **要求:** - 必须安装并认证 [GitHub CLI (gh)](https://cli.github.com/) - 必须位于具有远程仓库的 git 仓库中 ## 示例输出 ``` react2shell-guard - CVE-2025-55182 Scanner ────────────────────────────────────────────────── Scanned 1 project(s) ✗ my-app [VULNERABLE] Path: /path/to/my-app Framework: nextjs v15.2.1 App Router: Yes (RSC enabled) Vulnerabilities found: - react-server-dom-webpack @ 19.1.0 Upgrade to: 19.1.2 Advisory: https://react.dev/blog/2025/12/03/... - next @ 15.2.1 Upgrade to: 15.2.6 Advisory: https://react.dev/blog/2025/12/03/... ────────────────────────────────────────────────── VULNERABLE - Action required! Upgrade affected packages to patched versions immediately. ``` ## GitHub Actions 集成 ### GitHub 市场行动 最简单的集成方式是使用我们的官方 GitHub Action: ``` name: Security Scan on: [push, pull_request] jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Scan for CVE-2025-55182 uses: gensecaihq/react2shell-scanner@v1 with: path: '.' fail-on-vuln: true ``` ### 完整功能设置(SARIF + PR 评论) ``` name: Security Scan on: [push, pull_request] jobs: scan: runs-on: ubuntu-latest permissions: security-events: write # For SARIF upload pull-requests: write # For PR comments steps: - uses: actions/checkout@v4 - name: Scan for CVE-2025-55182 uses: gensecaihq/react2shell-scanner@v1 with: path: '.' format: sarif fail-on-vuln: true upload-sarif: true # Upload to GitHub Security tab add-pr-comment: true # Comment on PRs with results ignore-paths: 'examples/**,test/fixtures/**' ``` ### 操作输入 | 输入 | 描述 | 默认值 | |------|------|--------| | `path` | 要扫描的路径 | `.` | | `scan-type` | 扫描类型:`repo`、`sbom`、`container` | `repo` | | `format` | 输出格式:`text`、`json`、`sarif` | `text` | | `fail-on-vuln` | 发现漏洞时是否失败 | `true` | | `upload-sarif` | 上传 SARIF 到 GitHub 安全 | `false` | | `add-pr-comment` | 添加 PR 评论及结果 | `false` | | `ignore-paths` | 忽略的路径(逗号分隔) | `''` | | `sbom-file` | SBOM 文件路径(扫描类型为 sbom 时) | `''` | | `container-image` | Docker 镜像(扫描类型为 container 时) | `''` | ### 操作输出 | 输出 | 描述 | |------|------| | `vulnerable` | 是否发现漏洞(`true`/`false`) | | `findings-count` | 易受攻击的软件包数量 | | `scan-result` | 完整扫描结果(JSON 格式) | | `sarif-file` | SARIF 输出文件路径 | ### 扫描容器镜像 ``` - name: Scan Docker image uses: gensecaihq/react2shell-scanner@v1 with: scan-type: container container-image: myapp:latest ``` ### 扫描 SBOM 文件 ``` - name: Scan SBOM uses: gensecaihq/react2shell-scanner@v1 with: scan-type: sbom sbom-file: sbom.json ``` ### 手动 CLI 用法 如果偏好直接使用 CLI: ``` - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Scan for vulnerabilities run: npx react2shell-guard@latest . ``` ## 支持的软件包管理器 react2shell-guard 自动检测并解析以下软件包的锁定文件: - **npm** - `package-lock.json`(v2 和 v3 格式) - **pnpm** - `pnpm-lock.yaml` - **yarn** - `yarn.lock`(经典和 Berry 格式) ## 功能特性 - **快速扫描** - 直接分析锁定文件,无需安装依赖 - **单体仓库支持** - 自动发现并扫描所有项目 - **框架检测** - 识别 Next.js 和应用程序路由器的使用情况 - **多种输出格式** - 文本、JSON、SARIF 和 HTML 报告 - **CI/CD 就绪** - 退出代码和 GitHub Actions 集成 - **零网络调用** - 完全离线工作 - **自动修复** - 自动更新易受攻击的依赖项 - **预提交钩子** - 阻止提交包含易受攻击依赖项的代码 - **SBOM 扫描** - 扫描 CycloneDX SBOM 文件 - **MCP 集成** - 通过模型上下文协议支持 AI 助手 - **运行时保护** - 为 Express.js/Next.js 提供防御深度中间件 - **活动 URL 扫描** - 扫描已部署的应用程序是否存在漏洞 - **容器扫描** - 扫描 Docker/OCI 镜像中的易受攻击软件包 - **Vercel 集成** - 在生产环境部署前阻止易受漏洞影响的部署 - **GitHub PR 自动化** - 自动创建修复漏洞的 PR ## 自动修复漏洞 自动更新 `package.json` 以使用已修补的版本: ``` # 预览更改(演练) react2shell-guard fix --dry-run # 应用修复 react2shell-guard fix # 应用修复并运行 npm/pnpm/yarn install react2shell-guard fix --install ``` ## 预提交钩子 安装 git 钩子以防止提交易受攻击的依赖项: ``` # 自动检测钩子框架并安装 react2shell-guard init-hooks # 预览将要安装的内容 react2shell-guard init-hooks --dry-run # 强制特定钩子类型 react2shell-guard init-hooks --hook-type husky react2shell-guard init-hooks --hook-type lefthook react2shell-guard init-hooks --hook-type standalone ``` **支持的钩子框架:** - **Husky** - 追加到 `.husky/pre-commit` - **Lefthook** - 创建/更新 `lefthook.yml` - **独立** - 创建 `.git/hooks/pre-commit` 当 `package.json` 包含易受攻击的依赖项时,该钩子将阻止提交并建议运行 `react2shell-guard fix` 进行修复。 ## SBOM 扫描 扫描 CycloneDX SBOM 文件是否存在漏洞: ``` # 扫描 CycloneDX SBOM react2shell-guard scan-sbom bom.json # 带 JSON 输出 react2shell-guard scan-sbom bom.json --json # 带 SARIF 输出 react2shell-guard scan-sbom bom.json --sarif ``` ## MCP 服务器(AI 助手集成) 启动模型上下文协议服务器以集成 AI 助手: ``` react2shell-guard mcp-server ``` **可用的 MCP 工具:** - `scan_repo` - 扫描存储库中的漏洞 - `scan_sbom` - 扫描 CycloneDX SBOM 文件 **使用与 MCP 兼容的客户端进行配置(示例配置):** ``` { "mcpServers": { "react2shell-guard": { "command": "npx", "args": ["react2shell-guard", "mcp-server"] } } } ``` ## 运行时保护中间件 一种防御深度中间件,用于检测并阻止 CVE-2025-55182 的利用尝试。 ### Express.js ``` import express from 'express'; import { createExpressMiddleware } from 'react2shell-guard/middleware'; const app = express(); // Add raw body parser for RSC payloads app.use(express.raw({ type: 'text/x-component' })); app.use(express.json()); // Add protection middleware app.use(createExpressMiddleware({ action: 'block', // 'block' | 'log' | 'alert' onAlert: (result, req) => { // Send to your alerting system (Slack, PagerDuty, etc.) console.error('CVE-2025-55182 exploit attempt:', result); }, skipPaths: ['/health', '/metrics'], })); ``` ### Next.js ``` // middleware.ts import { withReact2ShellGuard } from 'react2shell-guard/middleware'; export const middleware = withReact2ShellGuard({ action: 'block', rscEndpointsOnly: true, // Only check RSC endpoints (recommended) }); export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'], }; ``` **检测模式:** - 序列化函数注入 - 原型污染尝试 - 格式不正确的模块引用 - 服务器操作篡改 - 编码的恶意负载 - RSC 流式传输格式滥用 ## API 用法 ``` import { scan } from 'react2shell-guard'; const result = scan({ path: '/path/to/project', ignorePaths: ['examples/**'], debug: false, }); console.log(result.vulnerable); // boolean console.log(result.projects); // ProjectResult[] ``` ## JSON 输出架构 ``` { "cve": "CVE-2025-55182", "vulnerable": true, "scanTime": "2025-12-04T10:30:00Z", "projects": [ { "name": "my-app", "path": "/path/to/my-app", "framework": { "type": "nextjs", "version": "15.2.1", "appRouterDetected": true }, "findings": [ { "package": "react-server-dom-webpack", "currentVersion": "19.1.0", "fixedVersion": "19.1.2", "severity": "critical", "advisoryUrl": "https://..." } ], "vulnerable": true } ], "errors": [] } ``` ## 修复 **自动修复(推荐):** ``` react2shell-guard fix --install ``` **手动升级 - React 软件包:** ``` npm install react-server-dom-webpack@19.1.2 # or 19.0.1, 19.2.1 ``` **手动升级 - Next.js:** ``` npm install next@15.2.6 # or other patched version for your release line ``` **按发布线修复的 Next.js 版本:** - 15.0.x → 15.0.5 - 15.1.x → 15.1.9 - 15.2.x → 15.2.6 - 15.3.x → 15.3.6 - 15.4.x → 15.4.8 - 15.5.x → 15.5.7 - 16.0.x → 16.0.7 ## 开发 ``` # 安装依赖项 npm install # 构建 npm run build # 运行测试 npm test # 以开发模式运行 npm run dev ``` ## 许可证 MIT
标签:AI Agent, AI应用开发, CVE-2025-55182, Docker镜像扫描, GitHub Actions, lockfile扫描, MITM代理, npm, pnpm, RCE, React Server Components, SARIF, SBOM, SEO, Vercel集成, yarn, 中间件, 安全扫描, 数据可视化, 时序注入, 硬件无关, 编程工具, 自动修复, 自动化攻击, 自动笔记, 请求拦截, 跌倒检测, 软件物料清单, 运行时保护, 远程代码执行