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 클러스터에는 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 권한을 부여하거나 인증서로 지속할 수 있습니다.

참고 자료

HackTricks 지원

Last updated