Azure CLI Cheat Sheet
Microsoft Azure command-line tool for subscription, VM, storage, and Entra ID enumeration in cloud pentests.
Overview
Azure CLI (az) manages Azure resources and Microsoft Entra ID (via extension). Use after obtaining user creds, service principals, or managed identity access from apps/VMs.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bashaz versionLogin
az loginaz login --service-principal -u APP_ID -p SECRET --tenant TENANT_IDEssential commands
Account context
az account showaz account list -o tableSet subscription
az account set --subscription "Subscription Name"Resource groups
az group list -o tableCommon workflows
Post-compromise enumeration —
az account list-locations -o tableaz resource list -o tableaz vm list -o tableaz vm show -g RG -n VMNameRun command on VM (if RBAC allows)
az vm run-command invoke -g RG -n VMName --command-id RunShellScript --scripts "id; hostname"Storage accounts —
az storage account list -o tableaz storage container list --account-name ACCOUNT --auth-mode loginaz storage blob list --account-name ACCOUNT -c container --auth-mode loginaz storage blob download --account-name ACCOUNT -c container -n secret.zip -f secret.zip --auth-mode loginKey Vault —
az keyvault list -o tableaz keyvault secret list --vault-name VAULTaz keyvault secret show --vault-name VAULT -n db-password --query value -o tsvEntra ID / users (requires directory permissions) —
az ad user list -o tableaz ad user show --id user@tenant.onmicrosoft.comaz ad sp list --display-name "app" -o tableaz rest --method GET --url "https://graph.microsoft.com/v1.0/me"From inside VM
curl -H "Metadata: true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"export AZURE_ACCESS_TOKEN=...az account get-access-tokenFlags reference
-o table / json / tsv | Output format |
|---|---|
--query JMESPath | Filter fields |
--subscription ID | Per-command subscription |
--only-show-errors | Suppress warnings |
az configure | Defaults (no telemetry, etc.) |
az extension add --name NAME | Extra command groups |
Tips
- ROADtools / AzureHound complement az for BloodHound-style paths.
- Many reads need specific RBAC — note AuthorizationFailed vs empty results.
- az login opens browser — use SP or device code for headless: az login --use-device-code.
- Graph API often needs separate token: az account get-access-token --resource-type ms-graph.