Agent SkillsAgent Skills
anshumanbh

nosql-injection-testing

@anshumanbh/nosql-injection-testing
anshumanbh
263
61 forks
Updated 3/31/2026
View on GitHub

Validate NoSQL injection vulnerabilities across MongoDB, Cassandra, CouchDB, Redis, and other NoSQL databases. Test operator injection, JavaScript injection, and query manipulation patterns. Use when testing CWE-943 (Improper Neutralization of Special Elements in Data Query Logic) and related NoSQL injection classes.

Installation

$npx agent-skills-cli install @anshumanbh/nosql-injection-testing
Claude Code
Cursor
Copilot
Codex
Antigravity

Details

Pathpackages/core/securevibes/skills/dast/nosql-injection-testing/SKILL.md
Branchmain
Scoped Name@anshumanbh/nosql-injection-testing

Usage

After installing, this skill will be available to your AI coding assistant.

Verify installation:

npx agent-skills-cli list

Skill Instructions


name: nosql-injection-testing description: Validate NoSQL injection vulnerabilities across MongoDB, Cassandra, CouchDB, Redis, and other NoSQL databases. Test operator injection, JavaScript injection, and query manipulation patterns. Use when testing CWE-943 (Improper Neutralization of Special Elements in Data Query Logic) and related NoSQL injection classes. allowed-tools: Read, Write, Bash

NoSQL Injection Testing Skill

Purpose

Validate NoSQL injection vulnerabilities by injecting special operators, JavaScript code, or malformed queries into user-controlled inputs and observing:

  • Authentication bypass via operator injection ($ne, $gt, $regex)
  • Data exfiltration via query manipulation
  • JavaScript execution in databases supporting server-side JS ($where, mapReduce)
  • Boolean-based inference by comparing response differences
  • Time-based inference via heavy operations or sleep-like constructs

Vulnerability Types Covered

1. Operator Injection (CWE-943)

Inject MongoDB query operators to manipulate query logic.

Detection Methods:

  • {"$ne": ""} β€” not equal empty, bypasses equality checks
  • {"$gt": ""} β€” greater than empty, returns all matching documents
  • {"$regex": ".*"} β€” regex wildcard match
  • {"$or": [...]} β€” logical OR injection

Example Attack:

// Normal: {"username": "admin", "password": "secret"}
// Attack: {"username": "admin", "password": {"$ne": ""}}
// Effect: Returns admin user regardless of password

2. JavaScript Injection (CWE-943)

Inject JavaScript in databases supporting server-side execution.

Detection Methods:

  • $where clause injection: {"$where": "this.password.length > 0"}
  • mapReduce function injection
  • $function aggregation operator (MongoDB 4.4+)

Example Attack:

// Payload: {"$where": "sleep(5000) || true"}
// Effect: 5-second delay if JS execution enabled

3. Array/Object Injection (CWE-943)

Exploit type confusion when arrays or objects are passed where strings expected.

Detection Methods:

  • username[$ne]= via query string (Express.js extended query parser)
  • Array index manipulation: items[0]=malicious

4. Aggregation Pipeline Injection (CWE-943)

Inject into MongoDB aggregation pipelines.

Detection Methods:

  • $lookup injection for cross-collection access
  • $out or $merge for write operations
  • $group manipulation for data extraction

Database-Specific Notes

DatabaseOperator InjectionJS InjectionBoolean-BasedTime-Based
MongoDBβœ“ ($ne, $gt, $regex, $or)βœ“ ($where, mapReduce)βœ“βœ“ (via $where sleep or heavy ops)
CouchDBβœ“ (view manipulation)βœ“ (design doc JS)βœ“Limited
CassandraLimited (CQL injection)Noβœ“Limited
RedisCommand injection patternsLua script injectionβœ“βœ“ (DEBUG SLEEP)
Elasticsearchβœ“ (query DSL manipulation)βœ“ (scripting if enabled)βœ“βœ“ (script-based)
DynamoDBCondition expression injectionNoβœ“No

Prerequisites

  • Target reachable; NoSQL-backed functionality identified (API endpoints, forms, JSON bodies)
  • Know (or infer) database type to select appropriate payloads
  • If authentication required: test accounts available or mark paths UNVALIDATED
  • VULNERABILITIES.json with suspected NoSQLi findings if provided

Testing Methodology

Phase 1: Identify Injection Points

  • JSON POST bodies (most common for NoSQL APIs)
  • URL query parameters (especially with extended query parsers)
  • HTTP headers (authorization tokens, custom headers)
  • Path parameters

Key Insight: NoSQL APIs typically accept JSON; look for object/array inputs where operators can be injected.

Phase 2: Establish Baseline

  • Send a normal request; record status, content, and response time
  • Note authentication/authorization behavior
  • Identify error message patterns

Phase 3: Execute NoSQL Injection Tests

Operator Injection (Authentication Bypass):

# Baseline
baseline = post("/login", json={"username": "admin", "password": "wrong"})
# Expected: 401 Unauthorized

# Test with $ne operator
test = post("/login", json={"username": "admin", "password": {"$ne": ""}})
# If 200 OK: VALIDATED - operator injection bypassed auth

Operator Injection (Data Extraction):

# Baseline
baseline = get("/api/users?role=user")
# Expected: Returns only users with role="user"

# Test with $gt operator
test = get("/api/users?role[$gt]=")
# If returns more users: VALIDATED - operator injection expanded query

Boolean-Based Inference:

# True condition
true_resp = post("/api/search", json={"name": {"$regex": "^a"}})
# False condition
false_resp = post("/api/search", json={"name": {"$regex": "^zzzzz"}})
# Compare response lengths/content
if len(true_resp.text) != len(false_resp.text):
    status = "VALIDATED"

JavaScript Injection (if enabled):

# Time-based test
baseline_time = measure(post("/api/query", json={"filter": "normal"}))
test_time = measure(post("/api/query", json={"$where": "sleep(5000) || true"}))
if test_time > baseline_time + 4.5:
    status = "VALIDATED"

Phase 4: Classification Logic

StatusMeaning
VALIDATEDClear NoSQLi indicators (auth bypass, data leak, JS execution, boolean/time diff)
FALSE_POSITIVENo indicators; operators rejected or sanitized
PARTIALWeak signals (small differences, inconsistent results)
UNVALIDATEDBlocked, error, or insufficient evidence

Phase 5: Capture Evidence

Capture minimal structured evidence (redact PII/secrets, truncate to 8KB, hash full response):

  • status, injection_type, cwe
  • Baseline request (url/method/status/body hash)
  • Test request (url/method/status/body hash)
  • Payload used
  • Authentication bypass details if applicable

Phase 6: Safety Rules

  • Detection-only payloads; never destructive operations ($out, db.dropDatabase())
  • Avoid data exfiltration; use boolean/time-based confirmation
  • Do not execute arbitrary JS that modifies data
  • Respect rate limits
  • Redact credentials, tokens, and personal data in evidence

Output Guidelines

  • Keep responses concise (1-4 sentences)
  • Include endpoint, payload, detection method, and impact

Validated examples:

NoSQL injection on /login - $ne operator bypassed password check (CWE-943). Admin access without credentials.
MongoDB $where injection on /api/search - sleep(5000) caused 5.1s delay (CWE-943). Server-side JS execution confirmed.
Operator injection on /api/users - $gt operator returned all users instead of filtered set (CWE-943).

Unvalidated example:

NoSQL injection test incomplete on /api/data - operators rejected with 400 Bad Request. Evidence: path/to/evidence.json

CWE Mapping

Primary CWE (DAST-testable):

  • CWE-943: Improper Neutralization of Special Elements in Data Query Logic
    • This is THE designated CWE for NoSQL injection
    • Alternate terms: "NoSQL Injection", "NoSQLi"
    • Covers: MongoDB, Cassandra, CouchDB, Redis, Elasticsearch, DynamoDB, and other NoSQL databases

Parent/Related CWEs (context):

  • CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') β€” parent class
  • CWE-20: Improper Input Validation β€” related root cause
  • CWE-116: Improper Encoding or Escaping of Output β€” related mitigation failure

Sibling CWEs under CWE-943 (for reference):

  • CWE-89: SQL Injection (separate skill)
  • CWE-90: LDAP Injection
  • CWE-643: XPath Injection
  • CWE-652: XQuery Injection

Related Attack Pattern:

  • CAPEC-676: NoSQL Injection

Note: Unlike SQL injection (CWE-89), NoSQL injection does not have a dedicated base-level CWE. CWE-943 at the class level is the correct mapping for NoSQL injection vulnerabilities per MITRE guidance.

Notable CVEs (examples)

  • CVE-2024-50672 (eLearning Platform): NoSQL injection via Mongoose find function allowing password resets.
  • CVE-2021-20736 (Rocket.Chat): NoSQL injection in team collaboration product.
  • CVE-2021-22911 (Rocket.Chat): Blind NoSQL injection allowing admin account takeover.
  • CVE-2020-35666 (PaaS Platform): NoSQL injection using MongoDB operator.
  • CVE-2019-2389 (MongoDB): Information disclosure via aggregation pipeline.
  • CVE-2017-18381 (KeystoneJS): NoSQL injection in password reset functionality.

Safety Reminders

  • ONLY test against user-approved targets; stop if production protections trigger
  • Do not log or store sensitive data; redact in evidence
  • Prefer parameterized queries and input validation in mitigations
  • Disable server-side JavaScript execution in production MongoDB (--noscripting)

Reference Implementations

  • See reference/nosql_payloads.py for NoSQLi payloads by database type
  • See reference/validate_nosqli.py for NoSQLi-focused validation flow
  • See examples.md for concrete NoSQLi scenarios and evidence formats

Additional Resources

More by anshumanbh

View all
agentic-security-threat-modeling
263

Identify agentic AI security threats based on OWASP Top 10 for Agentic Applications 2026. Use when analyzing AI agents, LLM-powered applications, chatbots, auto-reply systems, tool-using AI, browser automation, sandbox execution, or any application that uses AI/LLM APIs (Anthropic, OpenAI, Claude, GPT) to process user input and take actions.

sql-injection-testing
263

Validate SQL injection vulnerabilities (including blind SQLi) across time-based, error-based, boolean-based, UNION-based, stacked-query, and out-of-band patterns. Use when testing CWE-89 (SQL Injection), CWE-564 (Hibernate SQL Injection), and related SQL injection classes across MySQL, PostgreSQL, MSSQL, Oracle, and SQLite targets.

xss-testing
263

Validate Cross-Site Scripting (XSS) vulnerabilities including Reflected, Stored, and DOM-based XSS. Test by injecting script payloads into user-controlled inputs and observing if they execute in browser context. Use when testing CWE-79 (XSS), CWE-80 (Basic XSS), CWE-81 (Error Message XSS), CWE-83 (Attribute XSS), CWE-84 (URI Scheme XSS), CWE-85 (Doubled Character XSS), CWE-86 (Invalid Character XSS), CWE-87 (Alternate XSS Syntax), or related XSS findings.

command-injection-testing
263

Validate OS Command Injection vulnerabilities including direct command injection, blind command injection via time delays, and out-of-band command execution. Test by injecting shell metacharacters and commands into user-controlled inputs. Use when testing CWE-78 (OS Command Injection), CWE-77 (Command Injection), CWE-88 (Argument Injection), or related command execution vulnerabilities.