Azure Pentesting
{{#include ../../banners/hacktricks-training.md}}
Basic Information
{{#ref}} az-basic-information/ {{#endref}}
Azure Pentester/Red Team Methodology
AZURE वातावरण का ऑडिट करने के लिए यह बहुत महत्वपूर्ण है: कौन से सेवाएँ उपयोग में हैं, क्या प्रकट किया जा रहा है, किसके पास पहुँच है, और आंतरिक Azure सेवाएँ और बाहरी सेवाएँ कैसे जुड़ी हुई हैं।
Red Team के दृष्टिकोण से, Azure वातावरण को समझौता करने का पहला कदम Azure AD के लिए कुछ क्रेडेंशियल्स प्राप्त करना है। यहाँ कुछ विचार दिए गए हैं कि आप ऐसा कैसे कर सकते हैं:
- Leaks github (या समान) में - OSINT
- Social Engineering
- Password पुन: उपयोग (पासवर्ड लीक)
- Azure-Hosted Applications में कमजोरियाँ
- Server Side Request Forgery जो मेटाडेटा एंडपॉइंट तक पहुँच प्रदान करता है
- Local File Read
/home/USERNAME/.azureC:\Users\USERNAME\.azure- फ़ाइल
accessTokens.jsonaz cliमें 2.30 से पहले - Jan2022 - access tokens को स्पष्ट पाठ में संग्रहीत किया गया - फ़ाइल
azureProfile.jsonमें लॉग इन किए गए उपयोगकर्ता के बारे में जानकारी होती है। az logoutटोकन को हटा देता है।- पुराने संस्करणों में
Az PowerShellने access tokens को स्पष्ट पाठ मेंTokenCache.datमें संग्रहीत किया। यह ServicePrincipalSecret को भी स्पष्ट पाठ मेंAzureRmContext.jsonमें संग्रहीत करता है।Save-AzContextcmdlet का उपयोग tokens को संग्रहित करने के लिए किया जा सकता है।
उन्हें हटाने के लिएDisconnect-AzAccountका उपयोग करें। - 3rd पार्टियों द्वारा breached
- Internal Employee
- Common Phishing (क्रेडेंशियल्स या Oauth ऐप)
- Device Code Authentication Phishing
- Azure Password Spraying
यहाँ तक कि अगर आपने Azure टेनेन्ट के अंदर किसी उपयोगकर्ता को समझौता नहीं किया है, तो आप इससे कुछ जानकारी एकत्र कर सकते हैं:
{{#ref}} az-unauthenticated-enum-and-initial-entry/ {{#endref}}
Note
एक बार जब आप क्रेडेंशियल्स प्राप्त करने में सफल हो जाते हैं, तो आपको यह जानने की आवश्यकता है कि ये क्रेडेंशियल्स किसके हैं, और इनके पास क्या पहुँच है, इसलिए आपको कुछ बुनियादी एन्यूमरेशन करने की आवश्यकता है:
Basic Enumeration
Note
याद रखें कि एन्यूमरेशन का सबसे शोर वाला भाग लॉगिन है, न कि एन्यूमरेशन स्वयं।
SSRF
यदि आपने Azure के अंदर एक मशीन में SSRF पाया है, तो ट्रिक्स के लिए इस पृष्ठ की जाँच करें:
{{#ref}} https://book.hacktricks.xyz/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf {{#endref}}
Bypass Login Conditions

उन मामलों में जहाँ आपके पास कुछ मान्य क्रेडेंशियल्स हैं लेकिन आप लॉगिन नहीं कर सकते, ये कुछ सामान्य सुरक्षा उपाय हो सकते हैं:
- IP whitelisting -- आपको एक मान्य IP को समझौता करना होगा
- Geo restrictions -- पता करें कि उपयोगकर्ता कहाँ रहता है या कंपनी के कार्यालय कहाँ हैं और उसी शहर (या कम से कम देश) से एक IP प्राप्त करें
- Browser -- शायद केवल कुछ OS (Windows, Linux, Mac, Android, iOS) से एक ब्राउज़र की अनुमति है। पता करें कि पीड़ित/कंपनी कौन सा OS उपयोग करती है।
- आप Service Principal क्रेडेंशियल्स को भी समझौता करने की कोशिश कर सकते हैं क्योंकि ये आमतौर पर कम सीमित होते हैं और इसका लॉगिन कम समीक्षा किया जाता है
इसे बायपास करने के बाद, आप अपनी प्रारंभिक सेटअप पर वापस जाने में सक्षम हो सकते हैं और आपके पास अभी भी पहुँच होगी।
Subdomain Takeover
Whoami
Caution
जानें कैसे स्थापित करें az cli, AzureAD और Az PowerShell को Az - Entra ID अनुभाग में।
आपको जानने की आवश्यकता है कि आप कौन हैं (आप किस वातावरण में हैं):
{{#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
Azure को सूचीबद्ध करने के लिए सबसे महत्वपूर्ण कमांडों में से एक है
Get-AzResourceAz PowerShell से, क्योंकि यह आपको जानने देता है कि आपके वर्तमान उपयोगकर्ता के पास किन संसाधनों की दृश्यता है।आप वही जानकारी वेब कंसोल में https://portal.azure.com/#view/HubsExtension/BrowseAll पर जाकर या "सभी संसाधन" खोजकर प्राप्त कर सकते हैं।
ENtra ID Enumeration
डिफ़ॉल्ट रूप से, किसी भी उपयोगकर्ता को चीजों को सूचीबद्ध करने के लिए पर्याप्त अनुमतियाँ होनी चाहिए जैसे, उपयोगकर्ता, समूह, भूमिकाएँ, सेवा प्रमुख... (देखें डिफ़ॉल्ट AzureAD अनुमतियाँ).
आप यहाँ एक गाइड पा सकते हैं:
{{#ref}} az-services/az-azuread.md {{#endref}}
Note
अब जब आपके पास आपकी क्रेडेंशियल्स के बारे में कुछ जानकारी है (और यदि आप एक रेड टीम हैं, तो उम्मीद है कि आप पता नहीं चले हैं)। यह पता लगाने का समय है कि वातावरण में कौन सी सेवाएँ उपयोग की जा रही हैं।
अगले अनुभाग में आप कुछ सामान्य सेवाओं को सूचीबद्ध करने के कुछ तरीके देख सकते हैं।
App Service SCM
App Service 'container' में लॉग इन करने के लिए Kudu कंसोल।
Webshell
portal.azure.com का उपयोग करें और शेल का चयन करें, या bash या powershell के लिए shell.azure.com का उपयोग करें। इस शेल का 'डिस्क' एक स्टोरेज-खाता में एक इमेज फ़ाइल के रूप में संग्रहीत होता है।
Azure DevOps
Azure DevOps Azure से अलग है। इसमें रिपॉजिटरी, पाइपलाइन्स (yaml या रिलीज़), बोर्ड, विकी, और अधिक हैं। वेरिएबल ग्रुप्स का उपयोग वेरिएबल मान और रहस्यों को संग्रहीत करने के लिए किया जाता है।
Debug | MitM az cli
पैरामीटर --debug का उपयोग करके यह देखना संभव है कि उपकरण az सभी अनुरोध भेज रहा है:
az account management-group list --output table --debug
एक MitM करने के लिए टूल पर और सभी अनुरोधों की मैन्युअल रूप से जांच करने के लिए आप कर सकते हैं:
{{#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 }}
स्वचालित पुनः खोज उपकरण
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}}