MongoDB 27017
1. Nmap Scans for MongoDB
nmap --script mongodb-info -p 27017 <target-ip>
For database enumeration:
nmap --script mongodb-databases -p 27017 <target-ip>
2. Brute Forcing Credentials
Single username, password list:
hydra -l username -P passwords.txt <target-ip> mongodb
Username list, single password:
hydra -L usernames.txt -p password <target-ip> mongodb
3. Connecting to MongoDB
mongo
mongo --port 27017
mongo --host <target-ip> --port 27017
For authenticated access:
mongo "mongodb://username:password@<target-ip>:27017/?authSource=admin"
4. Basic Commands
Switch database or create if it doesn’t exist:
List collections in the current database:
List all users in the current database:
5. Data Retrieval Using Queries
Find all documents in a collection:
Find one document matching a condition:
6. Exploitation Techniques
Unsecured Instances:
Unauthenticated MongoDB instances allow direct access. Simply connect using:
Export data using mongodump:
Weak Credentials:
If credentials are identified (e.g., via brute force), authenticate and escalate data access.
No Authorization Restrictions:
Misconfigured MongoDB can allow creation or modification of collections:
Script Injection via $where:
Execute JavaScript within queries:
7. Automation with Scripts
You can automate enumeration and exploitation using custom scripts or tools:
Python automation script: