az cli의 accessTokens.json 파일 - 2.30 이전 - 2022년 1월 - 액세스 토큰을 평문으로 저장
azureProfile.json 파일은 로그인한 사용자에 대한 정보를 포함합니다.
**az logout**는 토큰을 제거합니다.
이전 버전의 **Az PowerShell**은 **TokenCache.dat**에 액세스 토큰을 평문으로 저장했습니다. 또한 **AzureRmContext.json**에 ServicePrincipalSecret을 평문으로 저장합니다. Save-AzContext cmdlet을 사용하여 토큰을 저장할 수 있습니다.
Disconnect-AzAccount를 사용하여 제거하세요.
Az - Entra ID 섹션에서 az cli, AzureAD 및 Az PowerShell을 설치하는 방법을 배우세요.
가장 먼저 알아야 할 것은 당신이 누구인지 (어떤 환경에 있는지)입니다:
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
Azure를 열거하는 데 가장 중요한 명령 중 하나는 **Get-AzResource**입니다. 이 명령은 현재 사용자가 볼 수 있는 리소스를 알 수 있게 해줍니다.
이제 자격 증명에 대한 정보가 있습니다 (그리고 레드 팀이라면 탐지되지 않았기를 바랍니다). 환경에서 사용 중인 서비스가 무엇인지 파악할 시간입니다.
다음 섹션에서는 일반 서비스 열거 방법을 확인할 수 있습니다.
App Service SCM
App Service '컨테이너'에 로그인하기 위한 Kudu 콘솔입니다.
Webshell
portal.azure.com을 사용하고 셸을 선택하거나 shell.azure.com을 사용하여 bash 또는 powershell을 사용할 수 있습니다. 이 셸의 '디스크'는 스토리지 계정에 이미지 파일로 저장됩니다.
Azure DevOps
Azure DevOps는 Azure와 별개입니다. 리포지토리, 파이프라인(yaml 또는 릴리스), 보드, 위키 등이 있습니다. 변수 그룹은 변수 값과 비밀을 저장하는 데 사용됩니다.
Debug | MitM az cli
매개변수 **--debug**를 사용하면 도구 **az**가 보내는 모든 요청을 볼 수 있습니다:
azaccountmanagement-grouplist--outputtable--debug
MitM 공격을 도구에 수행하고 수동으로 전송하는 모든 요청을 확인하려면 다음을 수행할 수 있습니다:
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-IncludeAzureActiveDirectory -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 -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 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