NoSQL Injection
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.
Summary
Tools
codingo/NoSQLmap - Automated NoSQL database enumeration and web application exploitation tool
digininja/nosqlilab - A lab for playing with NoSQL Injection
matrix/Burp-NoSQLiScanner - This extension provides a way to discover NoSQL injection vulnerabilities.
Methodology
NoSQL injection occurs when an attacker manipulates queries by injecting malicious input into a NoSQL database query. Unlike SQL injection, NoSQL injection often exploits JSON-based queries and operators like $ne, $gt, $regex, or $where in MongoDB.
Operator Injection
$ne
not equal
$regex
regular expression
$gt
greater than
$lt
lower than
$nin
not in
Example: A web application has a product search feature
An attacker can inject a NoSQL query: { "$gt": 0 }.
Instead of returning a specific product, the database returns all products with a price greater than zero, leaking data.
Authentication Bypass
Basic authentication bypass using not equal ($ne) or greater ($gt)
HTTP data
JSON data
Extract Length Information
Inject a payload using the $regex operator. The injection will work when the length is correct.
Extract Data Information
Extract data with "$regex" query operator.
HTTP data
JSON data
Extract data with "$in" query operator.
WAF and Filters
Remove pre-condition:
In MongoDB, if a document contains duplicate keys, only the last occurrence of the key will take precedence.
In this case, the final value of "id" will be "100".
Blind NoSQL
POST with JSON Body
Python script:
POST with urlencoded Body
Python script:
GET
Python script:
Ruby script:
Labs
References
Last updated