Azure CLI
Need credentials or some kind or token from here on out.
Azure CLI
A set of commands used to create and manage Azure resources. Enumeration - Azure CLI (az cli) • "A set of commands used to create and manage Azure resources." • Can be installed on multiple platforms and can be used with multiple clouds. Available in Cloud Shell too. Install using MSI - https://learn.microsoft.com/en-us/cli/azure/install- azure-cli.
To be able to use az cli, we must connect to Entra ID first (opens up a login page using Default browser):
Using credentials from command line (service principals and managed identity for VMs is also supported)
If the user has no permissions on the subscription
You can configure az cli to set some default behaviour (output type, location, resource group etc.
We can search for popular commands (based on user telemetry) on a particular topic!
We can format output using the --output parameter. The default format is JSON. You can change the default as discussed previously.
Azure CLI — Enumeration
List all the users in Entra ID and format output in table
List only the userPrincipalName and givenName (case sensitive) for all the users in Entra ID and format output in table. Az cli uses JMESPath (pronounced 'James path') query.
List only the userPrincipalName and givenName (case sensitive) for all the users in Entra ID, rename the properties and format output in table
We can use JMESPath query on the results of JSON output. Add --query-examples at the end of any command to see examples
Get details of the current tenant (uses the account extension)
Get details of the current subscription (uses the account extension)
List the current signed-in user
Azure CLI — AAD Users
Enumerate all users
Enumerate a specific user (lists all attributes)
Search for a user based on string in first characters of DisplayName (case sensitive)
When using PowerShell, search for users who contain the word "admin" in their Display name. This is NOT case-sensitive:
All users who are synced from on-prem
All users who are from Entra ID
Azure CLI — AAD Groups
List all groups
Enumerate a specific group using display name or object id
Search for groups that contain the word "admin" in their Display name (case sensitive) - run from cmd:
When using PowerShell, search for groups that contain the word "admin" in their Display name. This is NOT case-sensitive:
Get members of a groupAll groups that are synced from on-prem
All groups that are from Entra ID
Get members of a group
Check if a user is member of the specified group
Get the object IDs of the groups of which the specified group is a member
Azure CLI — AAD Apps
Get all the application objects registered with the current tenant (visible in App Registrations in Azure portal). An application object is the global representation of an app.
Get all details about an application using identifier uri, application id or object id
Get an application based on the display name (Run from cmd)
When using PowerShell, search for apps that contain the word "slack" in their Display name. This is NOT case-sensitive:
Get owner of an application
List apps that have password credentials
List apps that have key credentials (use of certificate authentication)
Azure CLI — AAD Service Principals
Enumerate Service Principals (visible as Enterprise Applications in Azure Portal). Service principal is local representation for an app in a specific tenant and it is the security object that has privileges. This is the 'service account'! Service Principals can be assigned Azure roles.
Get all service principals
Get all details about a service principal using service principal id or object id
Get a service principal based on the display name
When using PowerShell, search for service principals that contain the word "slack" in their Display name. This is NOT case-sensitive:
Get owner of a service principal
Get service principals owned by the current user
List apps that have password credentials
List apps that have key credentials (use of certificate authentication)
Azure CLI — Using Tokens with CLI
az cli can request a token but cannot use it! (Actually you can)
Request an access token (ARM)
Request an access token for aad-graph. Supported tokens - aad-graph, arm, batch, data-lake, media, ms-graph, oss-rdbms
az cli (before 2.30.0 – January 2022) stores access tokens in clear text in accessTokens.json in the directory C:\Users[username].Azure. We can read tokens from the file, use them and request new ones too! azureProfile.json in the same directory contains information about subscriptions. You can modify accessTokens.json to use access tokens with az cli but better to use with Az PowerShell module. To clear the access tokens, always use az logout
Last updated