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をサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリに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" - 認証が部分的に有効なもののみ:
"mongodb server information" "partially enabled"
Login
デフォルトでは 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
credentials が必要かどうかを確認するには、/opt/bitnami/mongodb/mongodb.conf を確認してください:
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
例 from here.
Mongo Object IDs は 12バイトの16進数 の文字列です:

例えば、アプリケーションが返す実際の Object ID を分解すると次のようになります: 5f2459ac9fa6dc2500314019
- 5f2459ac: 1596217772(10進数) = 2020年7月31日金曜日 17:49:32
- 9fa6dc: マシン識別子
- 2500: プロセスID
- 314019: 増分カウンタ
上記要素のうち、マシン識別子はデータベースが同じ物理/仮想マシン上で動作している限り同じままです。プロセスID は MongoDB プロセスが再起動された場合のみ変わります。タイムスタンプは毎秒更新されます。カウンタとタイムスタンプの値を単純にインクリメントして Object ID を推測する際の唯一の課題は、Mongo DB がシステムレベルで Object ID を生成し割り当てるという点です。
ツール https://github.com/andresriancho/mongo-objectid-predict は、開始となる Object ID を与えると(アカウントを作成して開始IDを取得できます)、次に割り当てられる可能性のある約1000件の推定 Object ID を返すので、それらを bruteforce するだけで済みます。
Post
root の場合、mongodb.conf ファイルを変更して認証を不要に(noauth = true)し、認証なしでログインできます。
MongoBleed zlib Memory Disclosure (CVE-2025-14847)
認証不要の広範なメモリ開示(“MongoBleed”)は、MongoDB 3.6–8.2 に影響し、zlib network compressor is enabled の場合に発生します。OP_COMPRESSED ヘッダは攻撃者が提供した uncompressedSize を信用するため、サーバはそのサイズのバッファを割り当て、実際にははるかに小さい圧縮ペイロードしか提供されていないにもかかわらずレスポンスにコピーします。余分なバイトは他の接続や /proc、WiredTiger キャッシュからの uninitialized heap data です。攻撃者は期待される BSON \x00 terminator` を省略し、MongoDB のパーサはターミネータが見つかるまでその過大なバッファを走査し続けます。エラー応答は悪意のあるドキュメントと走査されたヒープバイトを、pre-auth の状態で TCP/27017 上にエコーします。
露出条件と簡易チェック
- サーバのバージョンが脆弱な範囲内である必要があります(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またはnetworkMessageCompressorsにzlibが含まれている必要があります(多くのビルドでデフォルト)。シェルから次のコマンドで確認してください:
db.adminCommand({getParameter: 1, networkMessageCompressors: 1})
- 攻撃者は MongoDB ポートへのネットワークアクセスだけで十分です。認証は不要です。
Exploitation & harvesting workflow
compressors:["zlib"]を宣言して wire-protocol handshake を開始し、セッションで zlib を使用させる。- 宣言された
uncompressedSizeが実際の展開ペイロードよりもはるかに大きいOP_COMPRESSEDフレームを送信し、oversized heap allocation full of old data を強制する。 - 埋め込まれた BSON を without a final
\x00の形で作成し、parser が terminator を探している間に attacker-controlled data を越えて oversized buffer に進ませる。 - 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への着信接続の急増に注意してください。例: XQL ハント(リモートIPごとに >500 接続/分、デフォルトで 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 – 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)を確認してください!
> - **💬 [**Discordグループ**](https://discord.gg/hRep4RUj7f)または[**テレグラムグループ**](https://t.me/peass)に参加するか、**Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**をフォローしてください。**
> - **[**HackTricks**](https://github.com/carlospolop/hacktricks)および[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud)のGitHubリポジトリにPRを提出してハッキングトリックを共有してください。**
>
> </details>


