AWS - MSK Enum

Support HackTricks

Amazon MSK

**Amazon Managed Streaming for Apache Kafka (Amazon MSK)**는 Apache Kafka를 통해 스트리밍 데이터를 처리하는 애플리케이션의 개발 및 실행을 용이하게 하는 완전 관리형 서비스입니다. 클러스터의 생성, 업데이트 및 삭제를 포함한 제어-plane 작업은 Amazon MSK에서 제공합니다. 이 서비스는 데이터 생산 및 소비를 포함하는 Apache Kafka data-plane operations의 사용을 허용합니다. 기존 애플리케이션, 도구 및 파트너와 Apache Kafka 커뮤니티의 플러그인과의 호환성을 보장하기 위해 Apache Kafka오픈 소스 버전에서 작동하며, 애플리케이션 코드의 변경 필요성을 없앱니다.

신뢰성 측면에서 Amazon MSK는 일반적인 클러스터 실패 시나리오를 자동으로 감지하고 복구하도록 설계되어, 생산자 및 소비자 애플리케이션이 최소한의 중단으로 데이터 쓰기 및 읽기 활동을 지속할 수 있도록 보장합니다. 또한, 교체된 브로커의 저장소를 재사용하려고 시도하여 데이터 복제 프로세스를 최적화하여 Apache Kafka가 복제해야 하는 데이터 양을 최소화하는 것을 목표로 합니다.

Types

AWS에서 생성할 수 있는 Kafka 클러스터의 유형은 두 가지입니다: 프로비저닝 및 서버리스.

공격자의 관점에서 알아야 할 사항은 다음과 같습니다:

  • 서버리스는 직접적으로 공개될 수 없습니다 (공개적으로 노출된 IP 없이 VPN에서만 실행될 수 있습니다). 그러나 프로비저닝공개 IP를 얻도록 구성할 수 있습니다 (기본적으로는 그렇지 않음) 및 관련 포트를 노출하도록 보안 그룹을 구성할 수 있습니다.

  • 서버리스는 인증 방법으로 IAM만 지원합니다. 프로비저닝은 SASL/SCRAM (비밀번호) 인증, IAM 인증, AWS Certificate Manager (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

Privesc

AWS - MSK Privesc

Unauthenticated Access

AWS - MSK Unauthenticated Enum

Persistence

Provisioned Kafka가 있는 VPC에 접근할 수 있다면, 무단 접근을 활성화할 수 있습니다. SASL/SCRAM 인증을 사용하고, 비밀에서 비밀번호를 읽고, 다른 제어된 사용자 IAM 권한을 부여하거나 (IAM 또는 서버리스 사용 시) 인증서로 지속할 수 있습니다.

References

Support HackTricks

Last updated