[Azure] What To Do If?
"What To Do If" is a blog that will be updated continuously to contain valuable information about Azure Cloud resources exploit.
Last update: July 23, 2024
Hi there! In this blog, from its title, we will answer the question "What to do if you found resource XYZ in Azure?" It's very simple and will be updated continuously to contain the latest updates, commands, tools, and more. I used this guide to pass CARTP (Certified Azure Red Team Professional) certificate from Altered Security, so thanks to them especially Nikhil for the great content.
For example, If you have an assessment in an Azure environment and you gained access to a specific account or application-managed identity, what's the first step you will take? what are you gonna do if you find yourself having a specific role assignment to a virtual machine or key vault? Exactly that's what we gonna discuss here, so let's get started...
All the following steps we will follow are circular, not sequential, which means if you logged in and followed the 2 steps then you found leaked credentials and logged in again with the new user, you may need to follow the same steps from the beginning again depends on the resources you have.
Content
Used Tools
Azure AD user account & Managed Identity.
Virtual Machine & Extensions
KeyVaults
Storage Blob & Storage Accounts
Automation Account
Used Tools
The most used tool we will depend on is Az Powershell, but we will use different tools for specific tasks, and we will add them here to collect them in one section
Az Powershell
Az CLi
Download and install it from here
Azure AD user account & Managed Identity
This is your first step in any assessment to have an account or managed identity with specific roles because Azure pentest is unlike any normal website pentest, it seems like configuration review more than doing red team on on-prem environments. So, once you get an account, please do the following steps to know your roles and the resources you have access to.
Login using Az Powershell
$passwd = ConvertTo-SecureString "pass@1234" -AsPlainText -Force;$creds = New-Object System.Management.Automation.PSCredential ("test@aykalam.onmicrosoft.com", $passwd);Connect-AzAccount -Credential $creds
Check the
Get-AzResource`
to know the resources you have access to.Check the
Get-AzRoleAssignment
to know the roles you have in a specific resourceCheck the owned objects by the user using the
Az
Moduleaz ad signed-in-user list-owned-objects
Check if we have Storage accounts / Blob using MicroBrust Scripts
Try to login to the Azure portal and check the Deployment history
Try to login to the Azure portal and if you have a Dynamic Group try to invite other users.
If you aren't able to login to the Azure portal due to access policy, check the following solutions:
+ Try to login using the Az CLI, Az PowerShell, or AzureAD tools.
+ Try to change the user-agent in the browser to any other device "Maybe allowed access only for specific devices".
Virtual Machine & Extensions
Check the VM network profile and IP
Run
Get-AzResource
Run
Get-AzRoleAssignment
because you have to gain read access at least for the VM and the network profileCheck the roles you have in this VM from the above API call to get the permissions
Get the network profile name
Get-AzVM -Name VMName -ResourceGroupName RGName | select -ExpandProperty NetworkProfile
Get the interface name
Get-AzNetworkInterface -Name InterfaceName
Get the public IP
Get-AzPublicIpAddress -Name IPAddressName
If you have a Command Executer role.
Run directly ready scripts to add a user
Connect using the created account
Extract credentials from console history (after gaining a shell)
Check if there's any User Data stored in the machine (after gaining a shell)
Try the PowerShell transcripts (after gaining a shell)
Dealing with Extensions if you have read or write permission
If you found yourself in the AzureAD Connect machine with On-Prem, try to reset the Sync_ account
KeyVault
At first, we will check if we have access to key vaults or not, and if we have, then we will try to get its secret and read it as plain text. It's very simple.
Storage Blob / Accounts
Enumerate the storage blob using MicroBrust
If you found a container, try to access it using the <Name> </Name>
tag parameter after the URL endpoint.
Check Containers
If you find your user has access to the storage account. Check if there is a container that the user has access to
If you found SAS URL or Account creds have access to Storage Blob, Open the Storage Explorer application and authenticate using the SAS URL or the Account
Automation Account
Check your permissions over the automation account
Check if the hybrid worker is in use in the automation account
Gain reverse shell access
Import PowerShell runbook file to download a reverse shell from your host machine and run it on the hybrid worker.
To be continued...
Thanks for reading <3 Stay in touch
Last updated