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 允许创建 2 种类型的 Kafka 集群:预配置和无服务器。

从攻击者的角度来看,您需要知道:

  • 无服务器不能直接公开(它只能在没有任何公开暴露 IP 的 VPN 中运行)。然而,预配置 可以配置为获取 公共 IP(默认情况下不获取)并配置 安全组暴露 相关端口。

  • 无服务器 仅支持 IAM 作为身份验证方法。预配置 支持 SASL/SCRAM (密码) 身份验证、IAM 身份验证、AWS 证书 管理器 (ACM) 身份验证和 未认证 访问。

  • 请注意,如果启用了未认证访问,则无法公开暴露预配置的 Kafka。

Enumeration

#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

提权

未经身份验证的访问

持久性

如果您将要访问VPC,其中有一个Provisioned Kafka,您可以启用未经授权的访问,如果SASL/SCRAM身份验证从秘密中读取密码,给予一些其他受控用户IAM权限(如果使用IAM或无服务器),或通过证书保持持久性。

参考文献

支持HackTricks

Last updated