27017,27018 - Pentesting MongoDB
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
๊ธฐ๋ณธ ์ ๋ณด
MongoDB๋ ๋ค์ํ ํํ์ ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด ๋ฌธ์ ์งํฅ ๋ฐ์ดํฐ ๋ชจ๋ธ์ ์ฌ์ฉํ๋ ์คํ ์์ค ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ด๋ฆฌ ์์คํ ์ ๋๋ค. ๋น ๋ฐ์ดํฐ ๋ถ์ ๋ฐ ์ฝํ ์ธ ๊ด๋ฆฌ์ ๊ฐ์ ์ ํ๋ฆฌ์ผ์ด์ ์์ ๋น์ ํ ๋๋ ๋ฐ์ ํ ๋ฐ์ดํฐ๋ฅผ ๊ด๋ฆฌํ ๋ ์ ์ฐ์ฑ๊ณผ ํ์ฅ์ฑ์ ์ ๊ณตํฉ๋๋ค. ๊ธฐ๋ณธ ํฌํธ: 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 ์๋ฒ ๊ฒ์:
"mongodb server information" -"partially enabled" - auth๊ฐ ๋ถ๋ถ์ ์ผ๋ก๋ง ํ์ฑํ๋ ๊ฒฝ์ฐ:
"mongodb server information" "partially enabled"
๋ก๊ทธ์ธ
๊ธฐ๋ณธ์ ์ผ๋ก mongo๋ ์ํธ๋ฅผ ์๊ตฌํ์ง ์์ต๋๋ค.
Admin๋ ์ผ๋ฐ์ ์ธ mongo ๋ฐ์ดํฐ๋ฒ ์ด์ค์
๋๋ค.
mongo <HOST>
mongo <HOST>:<PORT>
mongo <HOST>:<PORT>/<DB>
mongo <database> -u <username> -p '<password>'
nmap ์คํฌ๋ฆฝํธ: _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:

For example, hereโs how we can dissect an actual Object ID returned by an application: 5f2459ac9fa6dc2500314019
- 5f2459ac: 1596217772 in decimal = Friday, 31 July 2020 17:49:32
- 9fa6dc: Machine Identifier
- 2500: Process ID
- 314019: An incremental counter
์ ์์๋ค ์ค์์ machine identifier๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๊ฐ ๋์ผํ ๋ฌผ๋ฆฌ/๊ฐ์ ๋จธ์ ์์ ์คํ๋๋ ํ ๋์ผํ๊ฒ ์ ์ง๋ฉ๋๋ค. Process ID๋ MongoDB ํ๋ก์ธ์ค๋ฅผ ์ฌ์์ํ ๋๋ง ๋ณ๊ฒฝ๋ฉ๋๋ค. Timestamp๋ ๋งค์ด ์ ๋ฐ์ดํธ๋ฉ๋๋ค. ์นด์ดํฐ์ ํ์์คํฌํ ๊ฐ์ ๋จ์ํ ์ฆ๊ฐ์์ผ Object ID๋ฅผ ์ถ์ธกํ๋ ๋ฐ ์์ด์ ์ ์ผํ ๋๊ด์ Mongo DB๊ฐ ์์คํ ๋ ๋ฒจ์์ Object IDs๋ฅผ ์์ฑํ๊ณ ํ ๋นํ๋ค๋ ์ ์ ๋๋ค.
The tool https://github.com/andresriancho/mongo-objectid-predict, given a starting Object ID (you can create an account and get a starting ID), it sends back about 1000 probable Object IDs that could have possibly been assigned to the next objects, so you just need to bruteforce them.
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})
- ๊ณต๊ฒฉ์๋ MongoDB ํฌํธ์ ๋ํ ๋คํธ์ํฌ ์ ๊ทผ๋ง ํ์ํฉ๋๋ค. ์ธ์ฆ์ ํ์ํ์ง ์์ต๋๋ค.
์ต์คํ๋ก์ ๋ฐ ์์ง ์ํฌํ๋ก์ฐ
- ์ธ์
์ด zlib์ ์ฌ์ฉํ๋๋ก
compressors:["zlib"]๋ฅผ ๊ด๊ณ ํ๋ wire-protocol ํธ๋์ ฐ์ดํฌ๋ฅผ ์์ํฉ๋๋ค. - ์ ์ธ๋
uncompressedSize๊ฐ ์ค์ ์์ถ ํด์ ๋ ํ์ด๋ก๋๋ณด๋ค ํจ์ฌ ํฐOP_COMPRESSEDํ๋ ์์ ๋ณด๋ด ์ค๋๋ ๋ฐ์ดํฐ๋ก ๊ฐ๋ํ ๊ณผ๋ํ ํ ํ ๋น์ ๊ฐ์ ํฉ๋๋ค. - ํ์๊ฐ ์ข
๊ฒฐ์๋ฅผ ์ฐพ๋ ๋์ ๊ณต๊ฒฉ์๊ฐ ์ ์ดํ๋ ๋ฐ์ดํฐ๋ฅผ ์ง๋ ๊ณผ๋ํ ๋ฒํผ๋ก ๊ฑธ์ด๋ค์ด๊ฐ๊ฒ ํ๊ธฐ ์ํด ํฌํจ๋ BSON์ ๋ง์ง๋ง
\x00์์ด ์์ฑํฉ๋๋ค. - MongoDB๋ ์๋ณธ ๋ฉ์์ง์ ์ค์บ๋ ํ ๋ฐ์ดํธ๋ฅผ ํฌํจํ ์ค๋ฅ๋ฅผ ๋ฐ์์ํค๋ฉฐ, ์ด๋ก ์ธํด leaking memory๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ธธ์ด/์คํ์
์ ๋ณ๊ฒฝํด ๋ฐ๋ณตํ๋ฉด secrets (creds/API keys/session tokens), WiredTiger stats, ๊ทธ๋ฆฌ๊ณ
/proc์ํฐํฉํธ๋ค์ ์ง๊ณํ ์ ์์ต๋๋ค.
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๋ก์ ์ธ๋ฐ์ด๋ ์ฐ๊ฒฐ ๊ธ์ฆ์ ์ฃผ์ํ์ธ์. Example XQL hunt (>500 connections/min per remote IP, excluding RFC1918/loopback/link-local/mcast/broadcast/reserved ranges by default):
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 โ 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]
> AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:<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 ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ: <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 ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ: <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) ํ์ธํ๊ธฐ!
> - **๐ฌ [**๋์ค์ฝ๋ ๊ทธ๋ฃน**](https://discord.gg/hRep4RUj7f) ๋๋ [**ํ
๋ ๊ทธ๋จ ๊ทธ๋ฃน**](https://t.me/peass)์ ์ฐธ์ฌํ๊ฑฐ๋ **ํธ์ํฐ** ๐ฆ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**๋ฅผ ํ๋ก์ฐํ์ธ์.**
> - **[**HackTricks**](https://github.com/carlospolop/hacktricks) ๋ฐ [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.**
>
> </details>


