Om 'n AZURE omgewing te oudit, is dit baie belangrik om te weet: watter dienste gebruik word, wat is blootgestel, wie het toegang tot wat, en hoe is interne Azure dienste en eksterne dienste gekoppel.
Vanuit 'n Red Team perspektief, is die eerste stap om 'n Azure omgewing te kompromitteer om te slaag om 'n paar akkrediteer vir Azure AD te verkry. Hier is 'n paar idees oor hoe om dit te doen:
Die lêer accessTokens.json in az cli voor 2.30 - Jan2022 - gestoor toegangstokens in duidelike teks
Die lêer azureProfile.json bevat inligting oor die ingelogde gebruiker.
az logout verwyder die token.
Ou weergawe van Az PowerShell het toegangstokens in duidelike teks in TokenCache.dat gestoor. Dit stoor ook ServicePrincipalSecret in duidelike teks in AzureRmContext.json. Die cmdlet Save-AzContext kan gebruik word om tokens te stoor.
Gebruik Disconnect-AzAccount om hulle te verwyder.
Nadat jy daarin geslaag het om akkrediteer te verkry, moet jy weet aan wie behoort daardie akkrediteer, en waartoe hulle toegang het, so jy moet 'n paar basiese enumerasie uitvoer:
Basiese Enumerasie
Onthou dat die luidste deel van die enumerasie die inlog is, nie die enumerasie self nie.
SSRF
As jy 'n SSRF in 'n masjien binne Azure gevind het, kyk hierdie bladsy vir truuks:
In gevalle waar jy 'n paar geldige akkrediteer het, maar jy kan nie inlog nie, is dit 'n paar algemene beskermings wat in plek kan wees:
IP witlys -- Jy moet 'n geldige IP kompromitteer
Geo beperkings -- Vind waar die gebruiker woon of waar die kantore van die maatskappy is en kry 'n IP van dieselfde stad (of land ten minste)
Blaaier -- Miskien is slegs 'n blaaier van sekere OS (Windows, Linux, Mac, Android, iOS) toegelaat. Vind uit watter OS die slagoffer/maatskappy gebruik.
Jy kan ook probeer om Service Principal akkrediteer te kompromitteer, aangesien hulle gewoonlik minder beperk is en hul inlog minder nagegaan word
Nadat jy dit omseil het, mag jy in staat wees om terug te keer na jou aanvanklike opstelling en jy sal steeds toegang hê.
Leer hoe om az cli, AzureAD en Az PowerShell te installeer in die Az - Entra ID afdeling.
Een van die eerste dinge wat jy moet weet is wie jy is (in watter omgewing jy is):
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
Een van die belangrikste opdragte om Azure te evalueer is Get-AzResource van Az PowerShell, aangesien dit jou inligting gee oor die hulpbronne wat jou huidige gebruiker kan sien.
Standaard behoort enige gebruiker voldoende regte te hê om dinge soos gebruikers, groepe, rolle, diensprinsipale... te evalueer (kyk standaard AzureAD regte).
Jy kan hier 'n gids vind:
Nou dat jy 'n bietjie inligting oor jou akrediteer het (en as jy 'n rooi span is, hoop ek jy is nie opgespoor nie). Dit is tyd om uit te vind watter dienste in die omgewing gebruik word.
In die volgende afdeling kan jy 'n paar maniere kyk om 'n paar algemene dienste te evalueer.
App Service SCM
Kudu-konsol om in te log in die App Service 'houer'.
Webshell
Gebruik portal.azure.com en kies die shell, of gebruik shell.azure.com, vir 'n bash of powershell. Die 'skyf' van hierdie shell word as 'n beeldlêer in 'n stoorrekening gestoor.
Azure DevOps
Azure DevOps is apart van Azure. Dit het repositories, pipelines (yaml of release), borde, wiki, en meer. Veranderlike Groepe word gebruik om veranderlike waardes en geheime te stoor.
Debug | MitM az cli
Deur die parameter --debug te gebruik, is dit moontlik om al die versoeke wat die hulpmiddel az stuur, te sien:
azaccountmanagement-grouplist--outputtable--debug
Om 'n MitM na die hulpmiddel te doen en al die versoeke wat dit handmatig stuur te kontroleer, kan jy doen:
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