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 지원하기

기본 정보

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:

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 = Friday, 31 July 2020 17:49:32
  2. 9fa6dc: Machine Identifier
  3. 2500: Process ID
  4. 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.compressors or networkMessageCompressors must include zlib (default on many builds). Check it from the shell with:
db.adminCommand({getParameter: 1, networkMessageCompressors: 1})
  • 공격자는 MongoDB 포트에 대한 네트워크 접근만 필요합니다. 인증은 필요하지 않습니다.

익스플로잇 및 수집 워크플로우

  1. 세션이 zlib을 사용하도록 compressors:["zlib"]를 광고하는 wire-protocol 핸드셰이크를 시작합니다.
  2. 선언된 uncompressedSize가 실제 압축 해제된 페이로드보다 훨씬 큰 OP_COMPRESSED 프레임을 보내 오래된 데이터로 가득한 과도한 힙 할당을 강제합니다.
  3. 파서가 종결자를 찾는 동안 공격자가 제어하는 데이터를 지나 과도한 버퍼로 걸어들어가게 하기 위해 포함된 BSON을 마지막 \x00 없이 작성합니다.
  4. 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>