Azure Pentesting
{{#include ../../banners/hacktricks-training.md}}
Osnovne Informacije
{{#ref}} az-basic-information/ {{#endref}}
Azure Pentester/Red Team Metodologija
Da biste auditovali AZURE okruženje, veoma je važno znati: koje usluge se koriste, šta je izloženo, ko ima pristup čemu, i kako su interne Azure usluge i eksterne usluge povezane.
Sa stanovišta Red Teama, prvi korak za kompromitovanje Azure okruženja je da se uspe da se dobiju neki akreditivi za Azure AD. Evo nekoliko ideja kako to uraditi:
- Leakovi na github-u (ili sličnim mestima) - OSINT
- Socijalno inženjerstvo
- Ponovna upotreba lozinki (leakovi lozinki)
- Ranljivosti u aplikacijama hostovanim na Azure-u
- Server Side Request Forgery sa pristupom metapodacima
- Čitanje lokalnih fajlova
/home/USERNAME/.azureC:\Users\USERNAME\.azure- Fajl
accessTokens.jsonuaz clipre 2.30 - Jan2022 - čuvao je pristupne tokene u čistom tekstu - Fajl
azureProfile.jsonsadrži informacije o prijavljenom korisniku. az logoutuklanja token.- Starije verzije
Az PowerShellčuvale su pristupne tokene u čistom tekstu uTokenCache.dat. Takođe čuva ServicePrincipalSecret u čistom tekstu uAzureRmContext.json. CmdletSave-AzContextmože se koristiti za čuvanje tokena.
KoristiteDisconnect-AzAccountda ih uklonite. -
- strane provaljene
- Interni zaposleni
- Uobičajeni Phishing (akreditivi ili Oauth aplikacija)
- Phishing putem autentifikacije uređaja
- Azure Password Spraying
Čak i ako niste kompromitovali nijednog korisnika unutar Azure tenanta koji napadate, možete prikupiti neke informacije iz njega:
{{#ref}} az-unauthenticated-enum-and-initial-entry/ {{#endref}}
Note
Nakon što ste uspeli da dobijete akreditive, morate znati čijim akreditivima pripadaju, i čemu imaju pristup, tako da treba da izvršite neku osnovnu enumeraciju:
Osnovna Enumeracija
Note
Zapamtite da je najbučniji deo enumeracije prijava, a ne sama enumeracija.
SSRF
Ako ste pronašli SSRF na mašini unutar Azure-a, proverite ovu stranicu za trikove:
{{#ref}} https://book.hacktricks.xyz/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf {{#endref}}
Zaobilaženje Uslova Prijave

U slučajevima kada imate neke važeće akreditive, ali ne možete da se prijavite, ovo su neke uobičajene zaštite koje bi mogle biti na snazi:
- IP beljenje -- Morate kompromitovati važeći IP
- Geo ograničenja -- Pronađite gde korisnik živi ili gde su kancelarije kompanije i dobijte IP iz istog grada (ili barem iz iste zemlje)
- Pregledač -- Možda je dozvoljen samo pregledač sa određenog OS-a (Windows, Linux, Mac, Android, iOS). Saznajte koji OS koristi žrtva/kompanija.
- Takođe možete pokušati da kompromitujete akreditive Service Principal-a jer su obično manje ograničeni i njihova prijava se manje pregledava.
Nakon zaobilaženja, možda ćete moći da se vratite na svoju početnu postavku i još uvek imati pristup.
Preuzimanje Poddomena
Whoami
Caution
Naučite kako da instalirate az cli, AzureAD i Az PowerShell u Az - Entra ID sekciji.
Jedna od prvih stvari koje treba da znate je ko ste vi (u kojem okruženju se nalazite):
{{#tabs }} {{#tab name="az cli" }}
az account list
az account tenant list # Current tenant info
az account subscription list # Current subscription info
az ad signed-in-user show # Current signed-in user
az ad signed-in-user list-owned-objects # Get owned objects by current user
az account management-group list #Not allowed by default
{{#endtab }}
{{#tab name="AzureAD" }}
#Get the current session state
Get-AzureADCurrentSessionInfo
#Get details of the current tenant
Get-AzureADTenantDetail
{{#endtab }}
{{#tab name="Az PowerShell" }}
# Get the information about the current context (Account, Tenant, Subscription etc.)
Get-AzContext
# List all available contexts
Get-AzContext -ListAvailable
# Enumerate subscriptions accessible by the current user
Get-AzSubscription
#Get Resource group
Get-AzResourceGroup
# Enumerate all resources visible to the current user
Get-AzResource
# Enumerate all Azure RBAC role assignments
Get-AzRoleAssignment # For all users
Get-AzRoleAssignment -SignInName test@corp.onmicrosoft.com # For current user
{{#endtab }} {{#endtabs }}
Caution
Jedna od najvažnijih komandi za enumeraciju Azure-a je
Get-AzResourceiz Az PowerShell-a jer vam omogućava da znate resurse koje vaš trenutni korisnik može da vidi.Istu informaciju možete dobiti u web konzoli odlaskom na https://portal.azure.com/#view/HubsExtension/BrowseAll ili pretražujući "Svi resursi"
ENtra ID Enumeration
Podrazumevano, svaki korisnik bi trebao imati dovoljno dozvola za enumeraciju stvari kao što su korisnici, grupe, uloge, servisni principi... (proverite podrazumevane AzureAD dozvole).
Ovde možete pronaći vodič:
{{#ref}} az-services/az-azuread.md {{#endref}}
Note
Sada kada imate neke informacije o vašim kredencijalima (i ako ste red tim, nadamo se da niste otkriveni). Vreme je da saznate koje se usluge koriste u okruženju.
U sledećem odeljku možete proveriti neke načine za enumeraciju nekih uobičajenih usluga.
App Service SCM
Kudu konzola za prijavu u 'container' App Service-a.
Webshell
Koristite portal.azure.com i izaberite shell, ili koristite shell.azure.com, za bash ili powershell. 'Disk' ovog shell-a se čuva kao slika u storage-account-u.
Azure DevOps
Azure DevOps je odvojen od Azure-a. Ima repozitorijume, pipeline-ove (yaml ili release), table, wiki i još mnogo toga. Grupa varijabli se koristi za čuvanje vrednosti varijabli i tajni.
Debug | MitM az cli
Korišćenjem parametra --debug moguće je videti sve zahteve koje alat az šalje:
az account management-group list --output table --debug
Da biste izvršili MitM na alatu i ručno proverili sve zahteve koje šalje, možete uraditi:
{{#tabs }} {{#tab name="Bash" }}
export ADAL_PYTHON_SSL_NO_VERIFY=1
export AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
export HTTPS_PROXY="http://127.0.0.1:8080"
export HTTP_PROXY="http://127.0.0.1:8080"
# If this is not enough
# Download the certificate from Burp and convert it into .pem format
# And export the following env variable
openssl x509 -in ~/Downloads/cacert.der -inform DER -out ~/Downloads/cacert.pem -outform PEM
export REQUESTS_CA_BUNDLE=/Users/user/Downloads/cacert.pem
{{#endtab }}
{{#tab name="PS" }}
$env:ADAL_PYTHON_SSL_NO_VERIFY=1
$env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
$env:HTTPS_PROXY="http://127.0.0.1:8080"
$env:HTTP_PROXY="http://127.0.0.1:8080"
{{#endtab }} {{#endtabs }}
Automatizovani alati za rekognosciranje
ROADRecon
cd ROADTools
pipenv shell
roadrecon auth -u test@corp.onmicrosoft.com -p "Welcome2022!"
roadrecon gather
roadrecon gui
Monkey365
Import-Module monkey365
Get-Help Invoke-Monkey365
Get-Help Invoke-Monkey365 -Detailed
Invoke-Monkey365 -IncludeEntraID -ExportTo HTML -Verbose -Debug -InformationAction Continue
Invoke-Monkey365 - Instance Azure -Analysis All -ExportTo HTML
Stormspotter
# Start Backend
cd stormspotter\backend\
pipenv shell
python ssbackend.pyz
# Start Front-end
cd stormspotter\frontend\dist\spa\
quasar.cmd serve -p 9091 --history
# Run Stormcollector
cd stormspotter\stormcollector\
pipenv shell
az login -u test@corp.onmicrosoft.com -p Welcome2022!
python stormspotter\stormcollector\sscollector.pyz cli
# This will generate a .zip file to upload in the frontend (127.0.0.1:9091)
AzureHound
# You need to use the Az PowerShell and Azure AD modules:
$passwd = ConvertTo-SecureString "Welcome2022!" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("test@corp.onmicrosoft.com", $passwd)
Connect-AzAccount -Credential $creds
Import-Module AzureAD\AzureAD.psd1
Connect-AzureAD -Credential $creds
# Launch AzureHound
. AzureHound\AzureHound.ps1
Invoke-AzureHound -Verbose
# Simple queries
## All Azure Users
MATCH (n:AZUser) return n.name
## All Azure Applications
MATCH (n:AZApp) return n.objectid
## All Azure Devices
MATCH (n:AZDevice) return n.name
## All Azure Groups
MATCH (n:AZGroup) return n.name
## All Azure Key Vaults
MATCH (n:AZKeyVault) return n.name
## All Azure Resource Groups
MATCH (n:AZResourceGroup) return n.name
## All Azure Service Principals
MATCH (n:AZServicePrincipal) return n.objectid
## All Azure Virtual Machines
MATCH (n:AZVM) return n.name
## All Principals with the ‘Contributor’ role
MATCH p = (n)-[r:AZContributor]->(g) RETURN p
# Advanced queries
## Get Global Admins
MATCH p =(n)-[r:AZGlobalAdmin*1..]->(m) RETURN p
## Owners of Azure Groups
MATCH p = (n)-[r:AZOwns]->(g:AZGroup) RETURN p
## All Azure Users and their Groups
MATCH p=(m:AZUser)-[r:MemberOf]->(n) WHERE NOT m.objectid CONTAINS 'S-1-5' RETURN p
## Privileged Service Principals
MATCH p = (g:AZServicePrincipal)-[r]->(n) RETURN p
## Owners of Azure Applications
MATCH p = (n)-[r:AZOwns]->(g:AZApp) RETURN p
## Paths to VMs
MATCH p = (n)-[r]->(g: AZVM) RETURN p
## Paths to KeyVault
MATCH p = (n)-[r]->(g:AZKeyVault) RETURN p
## Paths to Azure Resource Group
MATCH p = (n)-[r]->(g:AZResourceGroup) RETURN p
## On-Prem users with edges to Azure
MATCH p=(m:User)-[r:AZResetPassword|AZOwns|AZUserAccessAdministrator|AZContributor|AZAddMembers|AZGlobalAdmin|AZVMContributor|AZOwnsAZAvereContributor]->(n) WHERE m.objectid CONTAINS 'S-1-5-21' RETURN p
## All Azure AD Groups that are synchronized with On-Premise AD
MATCH (n:Group) WHERE n.objectid CONTAINS 'S-1-5' AND n.azsyncid IS NOT NULL RETURN n
Azucar
# You should use an account with at least read-permission on the assets you want to access
git clone https://github.com/nccgroup/azucar.git
PS> Get-ChildItem -Recurse c:\Azucar_V10 | Unblock-File
PS> .\Azucar.ps1 -AuthMode UseCachedCredentials -Verbose -WriteLog -Debug -ExportTo PRINT
PS> .\Azucar.ps1 -ExportTo CSV,JSON,XML,EXCEL -AuthMode Certificate_Credentials -Certificate C:\AzucarTest\server.pfx -ApplicationId 00000000-0000-0000-0000-000000000000 -TenantID 00000000-0000-0000-0000-000000000000
PS> .\Azucar.ps1 -ExportTo CSV,JSON,XML,EXCEL -AuthMode Certificate_Credentials -Certificate C:\AzucarTest\server.pfx -CertFilePassword MySuperP@ssw0rd! -ApplicationId 00000000-0000-0000-0000-000000000000 -TenantID 00000000-0000-0000-0000-000000000000
# resolve the TenantID for an specific username
PS> .\Azucar.ps1 -ResolveTenantUserName user@company.com
MicroBurst
Import-Module .\MicroBurst.psm1
Import-Module .\Get-AzureDomainInfo.ps1
Get-AzureDomainInfo -folder MicroBurst -Verbose
PowerZure
Connect-AzAccount
ipmo C:\Path\To\Powerzure.psd1
Get-AzureTarget
# Reader
$ Get-Runbook, Get-AllUsers, Get-Apps, Get-Resources, Get-WebApps, Get-WebAppDetails
# Contributor
$ Execute-Command -OS Windows -VM Win10Test -ResourceGroup Test-RG -Command "whoami"
$ Execute-MSBuild -VM Win10Test -ResourceGroup Test-RG -File "build.xml"
$ Get-AllSecrets # AllAppSecrets, AllKeyVaultContents
$ Get-AvailableVMDisks, Get-VMDisk # Download a virtual machine's disk
# Owner
$ Set-Role -Role Contributor -User test@contoso.com -Resource Win10VMTest
# Administrator
$ Create-Backdoor, Execute-Backdoor
GraphRunner
#Get-GraphTokens
#A good place to start is to authenticate with the Get-GraphTokens module. This module will launch a device-code login, allowing you to authenticate the session from a browser session. Access and refresh tokens will be written to the global $tokens variable. To use them with other GraphRunner modules use the Tokens flag (Example. Invoke-DumpApps -Tokens $tokens)
Import-Module .\GraphRunner.ps1
Get-GraphTokens
#Invoke-GraphRecon
#This module gathers information about the tenant including the primary contact info, directory sync settings, and user settings such as if users have the ability to create apps, create groups, or consent to apps.
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
#Invoke-DumpCAPS
#A module to dump conditional access policies from a tenant.
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
#Invoke-DumpCAPS
#A module to dump conditional access policies from a tenant.
Invoke-DumpCAPS -Tokens $tokens -ResolveGuids
#Invoke-DumpApps
#This module helps identify malicious app registrations. It will dump a list of Azure app registrations from the tenant including permission scopes and users that have consented to the apps. Additionally, it will list external apps that are not owned by the current tenant or by Microsoft's main app tenant. This is a good way to find third-party external apps that users may have consented to.
Invoke-DumpApps -Tokens $tokens
#Get-AzureADUsers
#Gather the full list of users from the directory.
Get-AzureADUsers -Tokens $tokens -OutFile users.txt
#Get-SecurityGroups
#Create a list of security groups along with their members.
Get-SecurityGroups -AccessToken $tokens.access_token
G#et-UpdatableGroups
#Gets groups that may be able to be modified by the current user
Get-UpdatableGroups -Tokens $tokens
#Get-DynamicGroups
#Finds dynamic groups and displays membership rules
Get-DynamicGroups -Tokens $tokens
#Get-SharePointSiteURLs
#Gets a list of SharePoint site URLs visible to the current user
Get-SharePointSiteURLs -Tokens $tokens
#Invoke-GraphOpenInboxFinder
#This module attempts to locate mailboxes in a tenant that have allowed other users to read them. By providing a userlist the module will attempt to access the inbox of each user and display if it was successful. The access token needs to be scoped to Mail.Read.Shared or Mail.ReadWrite.Shared for this to work.
Invoke-GraphOpenInboxFinder -Tokens $tokens -Userlist users.txt
#Get-TenantID
#This module attempts to gather a tenant ID associated with a domain.
Get-TenantID -Domain
#Invoke-GraphRunner
#Runs Invoke-GraphRecon, Get-AzureADUsers, Get-SecurityGroups, Invoke-DumpCAPS, Invoke-DumpApps, and then uses the default_detectors.json file to search with Invoke-SearchMailbox, Invoke-SearchSharePointAndOneDrive, and Invoke-SearchTeams.
Invoke-GraphRunner -Tokens $tokens
{{#include ../../banners/hacktricks-training.md}}