27017,27018 - Pentesting MongoDB
Tip
Lernen & üben Sie AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Lernen & üben Sie GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Lernen & üben Sie Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Unterstützen Sie HackTricks
- Überprüfen Sie die Abonnementpläne!
- Treten Sie der 💬 Discord-Gruppe oder der Telegram-Gruppe bei oder folgen Sie uns auf Twitter 🐦 @hacktricks_live.
- Teilen Sie Hacking-Tricks, indem Sie PRs an die HackTricks und HackTricks Cloud GitHub-Repos senden.
Grundlegende Informationen
MongoDB ist ein Open-Source-Datenbankmanagementsystem, das ein dokumentenorientiertes Datenbankmodell verwendet, um verschiedene Datenformen zu verarbeiten. Es bietet Flexibilität und Skalierbarkeit bei der Verwaltung unstrukturierter oder semi-strukturierter Daten in Anwendungen wie Big-Data-Analysen und Inhaltsverwaltung. Standardport: 27017, 27018
PORT STATE SERVICE VERSION
27017/tcp open mongodb MongoDB 2.6.9 2.6.9
Enumeration
Manuell
from pymongo import MongoClient
client = MongoClient(host, port, username=username, password=password)
client.server_info() #Basic info
#If you have admin access you can obtain more info
admin = client.admin
admin_info = admin.command("serverStatus")
cursor = client.list_databases()
for db in cursor:
print(db)
print(client[db["name"]].list_collection_names())
#If admin access, you could dump the database also
Einige MongoDB-Befehle:
show dbs
use <db>
show collections
db.<collection>.find() #Dump the collection
db.<collection>.count() #Number of records of the collection
db.current.find({"username":"admin"}) #Find in current db the username admin
Automatisch
nmap -sV --script "mongo* and default" -p 27017 <IP> #By default all the nmap mongo enumerate scripts are used
Shodan
- Alle mongodb:
"mongodb server information" - Suche nach vollständig offenen mongodb-Servern:
"mongodb server information" -"partially enabled" - Nur teilweise aktivierte auth:
"mongodb server information" "partially enabled"
Anmeldung
Standardmäßig erfordert mongo kein Passwort.
Admin ist eine häufige mongo-Datenbank.
mongo <HOST>
mongo <HOST>:<PORT>
mongo <HOST>:<PORT>/<DB>
mongo <database> -u <username> -p '<password>'
Das nmap-Skript: mongodb-brute prüft, ob creds benötigt werden.
nmap -n -sV --script mongodb-brute -p 27017 <ip>
Brute force
Schau in /opt/bitnami/mongodb/mongodb.conf nach, ob Anmeldeinformationen benötigt werden:
grep "noauth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#" #Not needed
grep "auth.*true" /opt/bitnami/mongodb/mongodb.conf | grep -v "^#\|noauth" #Not needed
Mongo Objectid Predict
Beispiel from here.
Mongo Object IDs are 12-byte hexadecimal strings:

Zum Beispiel, so können wir eine tatsächliche von einer Anwendung zurückgegebene Object ID zerlegen: 5f2459ac9fa6dc2500314019
- 5f2459ac: 1596217772 in decimal = Freitag, 31. Juli 2020 17:49:32
- 9fa6dc: Maschinenkennung
- 2500: Prozess-ID
- 314019: Ein inkrementeller Zähler
Von den genannten Elementen bleibt die Maschinenkennung gleich, solange die Datenbank auf derselben physischen/virtuellen Maschine läuft. Die Prozess-ID ändert sich nur, wenn der MongoDB-Prozess neu gestartet wird. Der Timestamp wird jede Sekunde aktualisiert. Die einzige Herausforderung beim Erraten von Object IDs durch einfaches Inkrementieren des Zählers und der Timestamp-Werte besteht darin, dass Mongo DB Object IDs auf Systemebene generiert und zuweist.
Das Tool https://github.com/andresriancho/mongo-objectid-predict, gegeben eine Start-Object-ID (du kannst ein Konto erstellen und eine Start-ID erhalten), liefert etwa 1000 wahrscheinliche Object IDs zurück, die möglicherweise den nächsten Objekten zugewiesen wurden, sodass du sie nur noch bruteforce musst.
Post
If you are root you can modify the mongodb.conf file so no credentials are needed (noauth = true) and login without credentials.
MongoBleed zlib Memory Disclosure (CVE-2025-14847)
A widespread unauthenticated memory disclosure (“MongoBleed”) impacts MongoDB 3.6–8.2 when the zlib network compressor is enabled. The OP_COMPRESSED header trusts an attacker-supplied uncompressedSize, so the server allocates a buffer of that size and copies it back into responses even though only a much smaller compressed payload was provided. The extra bytes are uninitialized heap data from other connections, /proc, or the WiredTiger cache. Attackers then omit the expected BSON \x00 terminator so MongoDB’s parser keeps scanning that oversized buffer until it finds a terminator, and the error response echoes both the malicious document and the scanned heap bytes pre-auth on TCP/27017.
Exposure requirements & quick checks
- Server version must be within the vulnerable ranges (3.6, 4.0, 4.2, 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).
net.compression.compressorsornetworkMessageCompressorsmust includezlib(default on many builds). Check it from the shell with:
db.adminCommand({getParameter: 1, networkMessageCompressors: 1})
- Der Angreifer benötigt nur Netzwerkzugriff auf den MongoDB-Port. Es ist keine Authentifizierung erforderlich.
Exploitation & harvesting workflow
- Initiate the wire-protocol handshake advertising
compressors:["zlib"]so the session uses zlib. - Send
OP_COMPRESSEDframes whose declareduncompressedSizeis far larger than the real decompressed payload to force oversized heap allocation full of old data. - Craft the embedded BSON without a final
\x00so the parser walks past attacker-controlled data into the oversized buffer while looking for a terminator. - MongoDB emits an error that includes the original message plus whatever heap bytes were scanned, leaking memory. Wiederhole mit variierenden Längen/Offsets, um Geheimnisse (creds/API keys/session tokens), WiredTiger-Statistiken und
/proc-Artefakte zu aggregieren.
The public PoC automates the probing offsets and carving of the returned fragments:
python3 mongobleed.py --host <target> --max-offset 50000 --output leaks.bin
Erkennungsrauschen (Verbindungen mit hoher Rate)
Der Angriff erzeugt normalerweise viele kurzlebige Anfragen. Achten Sie auf Spitzen eingehender Verbindungen zu mongod/mongod.exe. Beispiel XQL hunt (>500 Verbindungen/min pro Remote-IP, standardmäßig ausgenommen RFC1918/loopback/link-local/mcast/broadcast/reserved-Bereiche):
Cortex XQL high-velocity Mongo connections
```sql // High-velocity inbound connections to mongod/mongod.exe (possible 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 and incidr(action_remote_ip, “127.0.0.0/8”) != true and incidr(action_remote_ip, “169.254.0.0/16”) != true and incidr(action_remote_ip, “224.0.0.0/4”) != true and incidr(action_remote_ip, “255.255.255.255/32”) != true and incidr(action_remote_ip, “198.18.0.0/15”) != 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
</details>
## Referenzen
- [Unit 42 – Threat Brief: MongoDB Vulnerability (CVE-2025-14847)](https://unit42.paloaltonetworks.com/mongobleed-cve-2025-14847/)
- [Tenable – CVE-2025-14847 (MongoBleed): MongoDB Memory Leak Vulnerability Exploited in the Wild](https://www.tenable.com/blog/cve-2025-14847-mongobleed-mongodb-memory-leak-vulnerability-exploited-in-the-wild)
- [MongoDB Security Advisory SERVER-115508](https://jira.mongodb.org/browse/SERVER-115508)
- [Censys – MongoBleed Advisory](https://censys.com/advisory/cve-2025-14847)
- [MongoBleed PoC (joe-desimone/mongobleed)](https://github.com/joe-desimone/mongobleed)
---
> [!TIP]
> Lernen & üben Sie AWS Hacking:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Lernen & üben Sie GCP Hacking: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Lernen & üben Sie Azure Hacking: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Unterstützen Sie HackTricks</summary>
>
> - Überprüfen Sie die [**Abonnementpläne**](https://github.com/sponsors/carlospolop)!
> - **Treten Sie der** 💬 [**Discord-Gruppe**](https://discord.gg/hRep4RUj7f) oder der [**Telegram-Gruppe**](https://t.me/peass) bei oder **folgen** Sie uns auf **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Teilen Sie Hacking-Tricks, indem Sie PRs an die** [**HackTricks**](https://github.com/carlospolop/hacktricks) und [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) GitHub-Repos senden.
>
> </details>


