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 集群:预配和无服务器。

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

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

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

  • 请注意,如果启用了无身份验证访问,则无法公开预配的 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