AWS - MSK Enum

HackTricksのサポート

Amazon MSK

Amazon Managed Streaming for Apache Kafka (Amazon MSK)は、Apache Kafkaを介してストリーミングデータを処理するアプリケーションの開発と実行を容易にする完全に管理されたサービスです。Amazon MSKにより、クラスタの作成、更新、削除などのコントロールプレーン操作が提供されます。 このサービスは、Apache Kafkaのデータプレーン操作の利用を許可し、データの生成と消費を含みます。Apache Kafkaのオープンソースバージョンを使用しており、既存のアプリケーション、ツール、およびApache Kafkaコミュニティからのプラグインとの互換性を確保し、アプリケーションコードの変更が不要となります。

信頼性の観点から、Amazon MSKは一般的なクラスタ障害シナリオを自動的に検出および回復し、生産者および消費者アプリケーションがデータの書き込みと読み取り活動を最小限の中断で継続できるように設計されています。さらに、Apache Kafkaによるレプリケーションプロセスを最適化し、置換されたブローカーのストレージを再利用することで、レプリケーションが必要なデータ量を最小限に抑えることを目指しています。

タイプ

AWSが作成を許可するKafkaクラスタには2つのタイプがあります: ProvisionedとServerless。

攻撃者の観点から知っておくべきこと:

  • Serverlessは直接公開できません(公開されたIPを持たず、VPN内でのみ実行可能)。ただし、ProvisionedパブリックIPを取得できるように構成できます(デフォルトではできません)し、セキュリティグループを構成して関連ポートを公開できます。

  • Serverlessは認証方法としてIAMのみをサポートします。ProvisionedはSASL/SCRAM(パスワード)認証、IAM認証、AWS Certificate Manager(ACM)認証、および非認証アクセスをサポートします。

  • 注意: Provisioned Kafkaで非認証アクセスが有効になっている場合、公開はできません。

#Get clusters
aws kafka list-clusters
aws kafka list-clusters-v2

# Check the supported authentication
aws kafka list-clusters |  jq -r ".ClusterInfoList[].ClientAuthentication"

# Get Zookeeper endpoints
aws kafka list-clusters | jq -r ".ClusterInfoList[].ZookeeperConnectString, .ClusterInfoList[].ZookeeperConnectStringTls"

# Get nodes and node enspoints
aws kafka kafka list-nodes --cluster-arn <cluster-arn>
aws kafka kafka list-nodes --cluster-arn <cluster-arn> | jq -r ".NodeInfoList[].BrokerNodeInfo.Endpoints" # Get endpoints

# Get used kafka configs
aws kafka list-configurations #Get Kafka config file
aws kafka describe-configuration --arn <config-arn> # Get version of config
aws kafka describe-configuration-revision --arn <config-arn> --revision <version> # Get content of config version

# If using SCRAN authentication, get used AWS secret name (not secret value)
aws kafka list-scram-secrets --cluster-arn <cluster-arn>

Kafka IAM アクセス(サーバーレス)

# Guide from https://docs.aws.amazon.com/msk/latest/developerguide/create-serverless-cluster.html
# Download Kafka
wget https://archive.apache.org/dist/kafka/2.8.1/kafka_2.12-2.8.1.tgz
tar -xzf kafka_2.12-2.8.1.tgz

# In kafka_2.12-2.8.1/libs download the MSK IAM JAR file.
cd kafka_2.12-2.8.1/libs
wget https://github.com/aws/aws-msk-iam-auth/releases/download/v1.1.1/aws-msk-iam-auth-1.1.1-all.jar

# Create file client.properties in kafka_2.12-2.8.1/bin
security.protocol=SASL_SSL
sasl.mechanism=AWS_MSK_IAM
sasl.jaas.config=software.amazon.msk.auth.iam.IAMLoginModule required;
sasl.client.callback.handler.class=software.amazon.msk.auth.iam.IAMClientCallbackHandler

# Export endpoints address
export BS=boot-ok2ngypz.c2.kafka-serverless.us-east-1.amazonaws.com:9098
## Make sure you will be able to access the port 9098 from the EC2 instance (check VPS, subnets and SG)

# Create a topic called msk-serverless-tutorial
kafka_2.12-2.8.1/bin/kafka-topics.sh --bootstrap-server $BS --command-config client.properties --create --topic msk-serverless-tutorial --partitions 6

# Send message of every new line
kafka_2.12-2.8.1/bin/kafka-console-producer.sh --broker-list $BS --producer.config client.properties --topic msk-serverless-tutorial

# Read messages
kafka_2.12-2.8.1/bin/kafka-console-consumer.sh --bootstrap-server $BS --consumer.config client.properties --topic msk-serverless-tutorial --from-beginning

特権昇格

AWS - MSK Privesc

認証されていないアクセス

AWS - MSK Unauthenticated Enum

永続性

Provisioned Kafka がある VPC にアクセス権がある場合、SASL/SCRAM 認証が有効になっている場合、秘密からパスワードを読み取り、他の制御されたユーザーに IAM 権限を付与する(IAM またはサーバーレスが使用されている場合)、または証明書を使用して永続化することができます。

参考文献

HackTricks のサポート

Last updated