27017,27018 - Pentesting MongoDB

Tip

Μάθετε & εξασκηθείτε στο AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Μάθετε & εξασκηθείτε στο GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Μάθετε & εξασκηθείτε στο Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Υποστηρίξτε το HackTricks

Βασικές Πληροφορίες

MongoDB είναι ένα σύστημα διαχείρισης βάσεων δεδομένων ανοιχτού κώδικα που χρησιμοποιεί ένα μοντέλο βάσης δεδομένων προσανατολισμένο σε έγγραφα για να χειρίζεται διάφορες μορφές δεδομένων. Προσφέρει ευελιξία και δυνατότητα κλιμάκωσης για τη διαχείριση μη δομημένων ή ημι-δομημένων δεδομένων σε εφαρμογές όπως ανάλυση μεγάλων δεδομένων και διαχείριση περιεχομένου. Default port: 27017, 27018

PORT      STATE SERVICE VERSION
27017/tcp open  mongodb MongoDB 2.6.9 2.6.9

Καταγραφή

Χειροκίνητο

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

Μερικές εντολές MongoDB:

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

Αυτοματοποιημένο

nmap -sV --script "mongo* and default" -p 27017 <IP> #By default all the nmap mongo enumerate scripts are used

Shodan

  • Όλα mongodb: “mongodb server information”
  • Αναζήτηση για πλήρως ανοιχτούς mongodb servers: “mongodb server information” -“partially enabled”
  • Μόνο μερικώς ενεργοποιημένη auth: “mongodb server information” “partially enabled”

Login

Από προεπιλογή το mongo δεν απαιτεί password.
Admin είναι μια κοινή βάση δεδομένων mongo.

mongo <HOST>
mongo <HOST>:<PORT>
mongo <HOST>:<PORT>/<DB>
mongo <database> -u <username> -p '<password>'

Το nmap script: mongodb-brute θα ελέγξει αν χρειάζονται creds.

nmap -n -sV --script mongodb-brute -p 27017 <ip>

Brute force

Κοιτάξτε μέσα στο /opt/bitnami/mongodb/mongodb.conf για να δείτε αν απαιτούνται credentials:

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

Example from here.

Mongo Object IDs are 12-byte hexadecimal strings:

http://techidiocy.com/_id-objectid-in-mongodb/

For example, here’s how we can dissect an actual Object ID returned by an application: 5f2459ac9fa6dc2500314019

  1. 5f2459ac: 1596217772 in decimal = Παρασκευή, 31 Ιουλίου 2020 17:49:32
  2. 9fa6dc: Machine Identifier
  3. 2500: Process ID
  4. 314019: An incremental counter

Από τα παραπάνω στοιχεία, το machine identifier θα παραμείνει το ίδιο όσο η βάση δεδομένων τρέχει στην ίδια φυσική/virtual μηχανή. Το Process ID θα αλλάξει μόνο αν ο MongoDB process επανεκκινηθεί. Το Timestamp ενημερώνεται κάθε δευτερόλεπτο. Η μόνη πρόκληση στο να μαντέψεις Object IDs απλά αυξάνοντας τον counter και τις τιμές του timestamp, είναι το γεγονός ότι το Mongo DB δημιουργεί και αναθέτει Object IDs σε επίπεδο συστήματος.

Το εργαλείο https://github.com/andresriancho/mongo-objectid-predict, δεδομένου ενός αρχικού Object ID (μπορείτε να δημιουργήσετε λογαριασμό και να πάρετε ένα starting ID), επιστρέφει περίπου 1000 πιθανά Object IDs που ενδέχεται να έχουν ανατεθεί στα επόμενα αντικείμενα, οπότε απλά χρειάζεται να τα bruteforce-άρετε.

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 πρέπει να είναι μέσα στα ευάλωτα εύρη (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.compressors or networkMessageCompressors must include zlib (default on many builds). Check it from the shell with:
db.adminCommand({getParameter: 1, networkMessageCompressors: 1})
  • Ο attacker χρειάζεται μόνο πρόσβαση δικτύου στη MongoDB port. Δεν απαιτείται authentication.

Exploitation & harvesting workflow

  1. Ξεκινήστε το wire-protocol handshake διαφημίζοντας compressors:["zlib"] ώστε η συνεδρία να χρησιμοποιεί zlib.
  2. Στείλτε OP_COMPRESSED frames των οποίων το δηλωμένο uncompressedSize είναι πολύ μεγαλύτερο από το πραγματικό αποσυμπιεσμένο payload, για να αναγκάσετε υπερμεγέθη allocation στο heap γεμάτο παλιά δεδομένα.
  3. Δημιουργήστε το ενσωματωμένο BSON χωρίς τον τελικό \x00 ώστε ο parser να διασχίσει τα attacker-controlled δεδομένα προς το oversized buffer αναζητώντας τον terminator.
  4. Το MongoDB εκπέμπει ένα σφάλμα που περιλαμβάνει το αρχικό μήνυμα συν όσα bytes του heap σαρώθηκαν, leaking memory. Επαναλάβετε με μεταβαλλόμενα μήκη/offsets για να συσσωρεύσετε secrets (creds/API keys/session tokens), WiredTiger stats, και /proc artifacts.

The public PoC automates the probing offsets and carving of the returned fragments:

python3 mongobleed.py --host <target> --max-offset 50000 --output leaks.bin

Σήμα θορύβου ανίχνευσης (συνδέσεις υψηλού ρυθμού)

Η επίθεση συνήθως δημιουργεί πολλές βραχύβιες αιτήσεις. Προσέξτε για αιχμές στις εισερχόμενες συνδέσεις προς mongod/mongod.exe. Παράδειγμα XQL hunt (>500 connections/min ανά απομακρυσμένη IP, εξαιρώντας κατά προεπιλογή τις ζώνες RFC1918/loopback/link-local/mcast/broadcast/reserved):

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>


## Αναφορές

- [Unit 42 – Σύντομη αναφορά απειλής: MongoDB Ευπάθεια (CVE-2025-14847)](https://unit42.paloaltonetworks.com/mongobleed-cve-2025-14847/)
- [Tenable – CVE-2025-14847 (MongoBleed): Ευπάθεια memory leak της MongoDB εκμεταλλεύτηκε στον πραγματικό κόσμο](https://www.tenable.com/blog/cve-2025-14847-mongobleed-mongodb-memory-leak-vulnerability-exploited-in-the-wild)
- [MongoDB Ειδοποίηση Ασφαλείας SERVER-115508](https://jira.mongodb.org/browse/SERVER-115508)
- [Censys – MongoBleed Ειδοποίηση](https://censys.com/advisory/cve-2025-14847)
- [MongoBleed PoC (joe-desimone/mongobleed)](https://github.com/joe-desimone/mongobleed)

---

> [!TIP]
> Μάθετε & εξασκηθείτε στο 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;">\
> Μάθετε & εξασκηθείτε στο 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;">
> Μάθετε & εξασκηθείτε στο 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>Υποστηρίξτε το HackTricks</summary>
>
> - Ελέγξτε τα [**σχέδια συνδρομής**](https://github.com/sponsors/carlospolop)!
> - **Εγγραφείτε στην** 💬 [**ομάδα Discord**](https://discord.gg/hRep4RUj7f) ή στην [**ομάδα telegram**](https://t.me/peass) ή **ακολουθήστε** μας στο **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Μοιραστείτε κόλπα hacking υποβάλλοντας PRs στα** [**HackTricks**](https://github.com/carlospolop/hacktricks) και [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
>
> </details>