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.
Iz perspektive 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:
Fajl accessTokens.json u az cli pre 2.30 - Jan2022 - čuvao je pristupne tokene u čistom tekstu
Fajl azureProfile.json sadrži informacije o prijavljenom korisniku.
az logout uklanja token.
Starije verzije Az PowerShell čuvale su pristupne tokene u čistom tekstu u TokenCache.dat. Takođe čuva ServicePrincipalSecret u čistom tekstu u AzureRmContext.json. Cmdlet Save-AzContext može se koristiti za čuvanjetokena.
Koristite Disconnect-AzAccount da ih uklonite.
Nakon što ste uspeli da dobijete akreditive, treba da znate čijim akreditivima pripadaju, i čemu imaju pristup, tako da treba da izvršite neku osnovnu enumeraciju:
Basic Enumeration
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:
Bypass Login Conditions
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 (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 proverava
Nakon zaobilaženja, možda ćete moći da se vratite na svoju početnu postavku i još uvek imati pristup.
Learn how to install az cli, AzureAD and Az PowerShell in the Az - Entra ID section.
Jedna od prvih stvari koje treba da znate je ko ste vi (u kojem okruženju se nalazite):
azaccountlistazaccounttenantlist# Current tenant infoazaccountsubscriptionlist# Current subscription infoazadsigned-in-usershow# Current signed-in userazadsigned-in-userlist-owned-objects# Get owned objects by current userazaccountmanagement-grouplist#Not allowed by default
#Get the current session stateGet-AzureADCurrentSessionInfo#Get details of the current tenantGet-AzureADTenantDetail
# Get the information about the current context (Account, Tenant, Subscription etc.)Get-AzContext# List all available contextsGet-AzContext-ListAvailable# Enumerate subscriptions accessible by the current userGet-AzSubscription#Get Resource groupGet-AzResourceGroup# Enumerate all resources visible to the current userGet-AzResource# Enumerate all Azure RBAC role assignmentsGet-AzRoleAssignment# For all usersGet-AzRoleAssignment-SignInName test@corp.onmicrosoft.com # For current user
Jedna od najvažnijih komandi za enumeraciju Azure-a je Get-AzResource iz Az PowerShell-a jer vam omogućava da znate resurse koje vaš trenutni korisnik može da vidi.
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č:
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 'kontejner' 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:
azaccountmanagement-grouplist--outputtable--debug
Da biste izvršili MitM na alatu i proverili sve zahteve koje šalje ručno, možete uraditi:
export ADAL_PYTHON_SSL_NO_VERIFY=1export AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1export 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 variableopensslx509-in~/Downloads/cacert.der-informDER-out~/Downloads/cacert.pem-outformPEMexport REQUESTS_CA_BUNDLE=/Users/user/Downloads/cacert.pem
Import-Module monkey365Get-HelpInvoke-Monkey365Get-HelpInvoke-Monkey365-DetailedInvoke-Monkey365-IncludeEntraID -ExportTo HTML -Verbose -Debug -InformationAction ContinueInvoke-Monkey365- Instance Azure -Analysis All -ExportTo HTML
# Start Backendcd stormspotter\backend\pipenv shellpython ssbackend.pyz# Start Front-endcd stormspotter\frontend\dist\spa\quasar.cmd serve -p 9091--history# Run Stormcollectorcd stormspotter\stormcollector\pipenv shellaz 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)
# 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 $credsImport-Module AzureAD\AzureAD.psd1Connect-AzureAD-Credential $creds# Launch AzureHound. AzureHound\AzureHound.ps1Invoke-AzureHound-Verbose# Simple queries## All Azure UsersMATCH (n:AZUser) return n.name## All Azure ApplicationsMATCH (n:AZApp) return n.objectid## All Azure DevicesMATCH (n:AZDevice) return n.name## All Azure GroupsMATCH (n:AZGroup) return n.name## All Azure Key VaultsMATCH (n:AZKeyVault) return n.name## All Azure Resource GroupsMATCH (n:AZResourceGroup) return n.name## All Azure Service PrincipalsMATCH (n:AZServicePrincipal) return n.objectid## All Azure Virtual MachinesMATCH (n:AZVM) return n.name## All Principals with the ‘Contributor’ roleMATCH p = (n)-[r:AZContributor]->(g) RETURN p# Advanced queries## Get Global AdminsMATCH p =(n)-[r:AZGlobalAdmin*1..]->(m) RETURN p## Owners of Azure GroupsMATCH p = (n)-[r:AZOwns]->(g:AZGroup) RETURN p## All Azure Users and their GroupsMATCH p=(m:AZUser)-[r:MemberOf]->(n) WHERE NOT m.objectid CONTAINS 'S-1-5'RETURN p## Privileged Service PrincipalsMATCH p = (g:AZServicePrincipal)-[r]->(n) RETURN p## Owners of Azure ApplicationsMATCH p = (n)-[r:AZOwns]->(g:AZApp) RETURN p## Paths to VMsMATCH p = (n)-[r]->(g: AZVM) RETURN p## Paths to KeyVaultMATCH p = (n)-[r]->(g:AZKeyVault) RETURN p## Paths to Azure Resource GroupMATCH p = (n)-[r]->(g:AZResourceGroup) RETURN p## On-Prem users with edges to AzureMATCH 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 ADMATCH (n:Group) WHERE n.objectid CONTAINS 'S-1-5' AND n.azsyncid IS NOT NULL RETURN n
# You should use an account with at least read-permission on the assets you want to accessgitclonehttps://github.com/nccgroup/azucar.gitPS> Get-ChildItem-Recursec:\Azucar_V10|Unblock-FilePS> .\Azucar.ps1-AuthModeUseCachedCredentials-Verbose-WriteLog-Debug-ExportToPRINTPS> .\Azucar.ps1-ExportToCSV,JSON,XML,EXCEL-AuthModeCertificate_Credentials-CertificateC:\AzucarTest\server.pfx-ApplicationId00000000-0000-0000-0000-000000000000-TenantID00000000-0000-0000-0000-000000000000PS> .\Azucar.ps1-ExportToCSV,JSON,XML,EXCEL-AuthModeCertificate_Credentials-CertificateC:\AzucarTest\server.pfx-CertFilePasswordMySuperP@ssw0rd!-ApplicationId00000000-0000-0000-0000-000000000000-TenantID00000000-0000-0000-0000-000000000000# resolve the TenantID for an specific usernamePS> .\Azucar.ps1-ResolveTenantUserNameuser@company.com
#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.ps1Get-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_tokenG#et-UpdatableGroups#Gets groups that may be able to be modified by the current userGet-UpdatableGroups-Tokens $tokens#Get-DynamicGroups#Finds dynamic groups and displays membership rulesGet-DynamicGroups-Tokens $tokens#Get-SharePointSiteURLs#Gets a list of SharePoint site URLs visible to the current userGet-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