Skip to content

Commit e624a6c

Browse files
committed
azure automatic tools
1 parent edbb9a8 commit e624a6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+390
-368
lines changed

src/pentesting-cloud/aws-security/aws-persistence/aws-sts-persistence.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ optional arguments:
4848
4949
<summary>Code to perform Role Juggling from PowerShell</summary>
5050
51-
```powershell
51+
```bash
5252
# PowerShell script to check for role juggling possibilities using AWS CLI
5353
5454
# Check for AWS CLI installation

src/pentesting-cloud/azure-security/README.md

Lines changed: 3 additions & 247 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ az account management-group list #Not allowed by default
9595

9696
{{#tab name="AzureAD" }}
9797

98-
```powershell
98+
```bash
9999
#Get the current session state
100100
Get-AzureADCurrentSessionInfo
101101
#Get details of the current tenant
@@ -106,7 +106,7 @@ Get-AzureADTenantDetail
106106

107107
{{#tab name="Az PowerShell" }}
108108

109-
```powershell
109+
```bash
110110
# Get the information about the current context (Account, Tenant, Subscription etc.)
111111
Get-AzContext
112112
# List all available contexts
@@ -130,7 +130,7 @@ Get-AzRoleAssignment -SignInName [email protected] # For current user
130130
>
131131
> You can get the same info in the **web console** going to [https://portal.azure.com/#view/HubsExtension/BrowseAll](https://portal.azure.com/#view/HubsExtension/BrowseAll) or searching for "All resources"
132132
133-
### ENtra ID Enumeration
133+
### Entra ID Enumeration
134134

135135
By default, any user should have **enough permissions to enumerate** things such us, users, groups, roles, service principals... (check [default AzureAD permissions](az-basic-information/index.html#default-user-permissions)).\
136136
You can find here a guide:
@@ -155,250 +155,6 @@ Use portal.azure.com and select the shell, or use shell.azure.com, for a bash or
155155

156156
Azure DevOps is separate from Azure. It has repositories, pipelines (yaml or release), boards, wiki, and more. Variable Groups are used to store variable values and secrets.
157157

158-
## Debug | MitM az cli
159-
160-
Using the parameter **`--debug`** it's possible to see all the requests the tool **`az`** is sending:
161-
162-
```bash
163-
az account management-group list --output table --debug
164-
```
165-
166-
In order to do a **MitM** to the tool and **check all the requests** it's sending manually you can do:
167-
168-
{{#tabs }}
169-
{{#tab name="Bash" }}
170-
171-
```bash
172-
export ADAL_PYTHON_SSL_NO_VERIFY=1
173-
export AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
174-
export HTTPS_PROXY="http://127.0.0.1:8080"
175-
export HTTP_PROXY="http://127.0.0.1:8080"
176-
177-
# If this is not enough
178-
# Download the certificate from Burp and convert it into .pem format
179-
# And export the following env variable
180-
openssl x509 -in ~/Downloads/cacert.der -inform DER -out ~/Downloads/cacert.pem -outform PEM
181-
export REQUESTS_CA_BUNDLE=/Users/user/Downloads/cacert.pem
182-
```
183-
184-
{{#endtab }}
185-
186-
{{#tab name="PS" }}
187-
188-
```bash
189-
$env:ADAL_PYTHON_SSL_NO_VERIFY=1
190-
$env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
191-
$env:HTTPS_PROXY="http://127.0.0.1:8080"
192-
$env:HTTP_PROXY="http://127.0.0.1:8080"
193-
```
194-
195-
{{#endtab }}
196-
{{#endtabs }}
197-
198-
## Automated Recon Tools
199-
200-
### [**ROADRecon**](https://github.com/dirkjanm/ROADtools)
201-
202-
```powershell
203-
cd ROADTools
204-
pipenv shell
205-
roadrecon auth -u [email protected] -p "Welcome2022!"
206-
roadrecon gather
207-
roadrecon gui
208-
```
209-
210-
### [Monkey365](https://github.com/silverhack/monkey365)
211-
212-
```powershell
213-
Import-Module monkey365
214-
Get-Help Invoke-Monkey365
215-
Get-Help Invoke-Monkey365 -Detailed
216-
Invoke-Monkey365 -IncludeEntraID -ExportTo HTML -Verbose -Debug -InformationAction Continue
217-
Invoke-Monkey365 - Instance Azure -Analysis All -ExportTo HTML
218-
```
219-
220-
### [**Stormspotter**](https://github.com/Azure/Stormspotter)
221-
222-
```powershell
223-
# Start Backend
224-
cd stormspotter\backend\
225-
pipenv shell
226-
python ssbackend.pyz
227-
228-
# Start Front-end
229-
cd stormspotter\frontend\dist\spa\
230-
quasar.cmd serve -p 9091 --history
231-
232-
# Run Stormcollector
233-
cd stormspotter\stormcollector\
234-
pipenv shell
235-
az login -u [email protected] -p Welcome2022!
236-
python stormspotter\stormcollector\sscollector.pyz cli
237-
# This will generate a .zip file to upload in the frontend (127.0.0.1:9091)
238-
```
239-
240-
### [**AzureHound**](https://github.com/BloodHoundAD/AzureHound)
241-
242-
```powershell
243-
# You need to use the Az PowerShell and Azure AD modules:
244-
$passwd = ConvertTo-SecureString "Welcome2022!" -AsPlainText -Force
245-
$creds = New-Object System.Management.Automation.PSCredential ("[email protected]", $passwd)
246-
Connect-AzAccount -Credential $creds
247-
248-
Import-Module AzureAD\AzureAD.psd1
249-
Connect-AzureAD -Credential $creds
250-
251-
# Launch AzureHound
252-
. AzureHound\AzureHound.ps1
253-
Invoke-AzureHound -Verbose
254-
255-
# Simple queries
256-
## All Azure Users
257-
MATCH (n:AZUser) return n.name
258-
## All Azure Applications
259-
MATCH (n:AZApp) return n.objectid
260-
## All Azure Devices
261-
MATCH (n:AZDevice) return n.name
262-
## All Azure Groups
263-
MATCH (n:AZGroup) return n.name
264-
## All Azure Key Vaults
265-
MATCH (n:AZKeyVault) return n.name
266-
## All Azure Resource Groups
267-
MATCH (n:AZResourceGroup) return n.name
268-
## All Azure Service Principals
269-
MATCH (n:AZServicePrincipal) return n.objectid
270-
## All Azure Virtual Machines
271-
MATCH (n:AZVM) return n.name
272-
## All Principals with the ‘Contributor’ role
273-
MATCH p = (n)-[r:AZContributor]->(g) RETURN p
274-
275-
# Advanced queries
276-
## Get Global Admins
277-
MATCH p =(n)-[r:AZGlobalAdmin*1..]->(m) RETURN p
278-
## Owners of Azure Groups
279-
MATCH p = (n)-[r:AZOwns]->(g:AZGroup) RETURN p
280-
## All Azure Users and their Groups
281-
MATCH p=(m:AZUser)-[r:MemberOf]->(n) WHERE NOT m.objectid CONTAINS 'S-1-5' RETURN p
282-
## Privileged Service Principals
283-
MATCH p = (g:AZServicePrincipal)-[r]->(n) RETURN p
284-
## Owners of Azure Applications
285-
MATCH p = (n)-[r:AZOwns]->(g:AZApp) RETURN p
286-
## Paths to VMs
287-
MATCH p = (n)-[r]->(g: AZVM) RETURN p
288-
## Paths to KeyVault
289-
MATCH p = (n)-[r]->(g:AZKeyVault) RETURN p
290-
## Paths to Azure Resource Group
291-
MATCH p = (n)-[r]->(g:AZResourceGroup) RETURN p
292-
## On-Prem users with edges to Azure
293-
MATCH p=(m:User)-[r:AZResetPassword|AZOwns|AZUserAccessAdministrator|AZContributor|AZAddMembers|AZGlobalAdmin|AZVMContributor|AZOwnsAZAvereContributor]->(n) WHERE m.objectid CONTAINS 'S-1-5-21' RETURN p
294-
## All Azure AD Groups that are synchronized with On-Premise AD
295-
MATCH (n:Group) WHERE n.objectid CONTAINS 'S-1-5' AND n.azsyncid IS NOT NULL RETURN n
296-
```
297-
298-
### [Azucar](https://github.com/nccgroup/azucar)
299-
300-
```bash
301-
# You should use an account with at least read-permission on the assets you want to access
302-
git clone https://github.com/nccgroup/azucar.git
303-
PS> Get-ChildItem -Recurse c:\Azucar_V10 | Unblock-File
304-
305-
PS> .\Azucar.ps1 -AuthMode UseCachedCredentials -Verbose -WriteLog -Debug -ExportTo PRINT
306-
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
307-
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
308-
309-
# resolve the TenantID for an specific username
310-
PS> .\Azucar.ps1 -ResolveTenantUserName [email protected]
311-
```
312-
313-
### [**MicroBurst**](https://github.com/NetSPI/MicroBurst)
314-
315-
```
316-
Import-Module .\MicroBurst.psm1
317-
Import-Module .\Get-AzureDomainInfo.ps1
318-
Get-AzureDomainInfo -folder MicroBurst -Verbose
319-
```
320-
321-
### [**PowerZure**](https://github.com/hausec/PowerZure)
322-
323-
```powershell
324-
Connect-AzAccount
325-
ipmo C:\Path\To\Powerzure.psd1
326-
Get-AzureTarget
327-
328-
# Reader
329-
$ Get-Runbook, Get-AllUsers, Get-Apps, Get-Resources, Get-WebApps, Get-WebAppDetails
330-
331-
# Contributor
332-
$ Execute-Command -OS Windows -VM Win10Test -ResourceGroup Test-RG -Command "whoami"
333-
$ Execute-MSBuild -VM Win10Test -ResourceGroup Test-RG -File "build.xml"
334-
$ Get-AllSecrets # AllAppSecrets, AllKeyVaultContents
335-
$ Get-AvailableVMDisks, Get-VMDisk # Download a virtual machine's disk
336-
337-
# Owner
338-
$ Set-Role -Role Contributor -User [email protected] -Resource Win10VMTest
339-
340-
# Administrator
341-
$ Create-Backdoor, Execute-Backdoor
342-
```
343-
344-
### [**GraphRunner**](https://github.com/dafthack/GraphRunner/wiki/Invoke%E2%80%90GraphRunner)
345-
346-
```powershell
347-
348-
#Get-GraphTokens
349-
#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)
350-
Import-Module .\GraphRunner.ps1
351-
Get-GraphTokens
352-
353-
#Invoke-GraphRecon
354-
#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.
355-
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
356-
357-
#Invoke-DumpCAPS
358-
#A module to dump conditional access policies from a tenant.
359-
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
360-
361-
#Invoke-DumpCAPS
362-
#A module to dump conditional access policies from a tenant.
363-
Invoke-DumpCAPS -Tokens $tokens -ResolveGuids
364-
365-
#Invoke-DumpApps
366-
#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.
367-
Invoke-DumpApps -Tokens $tokens
368-
369-
#Get-AzureADUsers
370-
#Gather the full list of users from the directory.
371-
Get-AzureADUsers -Tokens $tokens -OutFile users.txt
372-
373-
#Get-SecurityGroups
374-
#Create a list of security groups along with their members.
375-
Get-SecurityGroups -AccessToken $tokens.access_token
376-
377-
G#et-UpdatableGroups
378-
#Gets groups that may be able to be modified by the current user
379-
Get-UpdatableGroups -Tokens $tokens
380-
381-
#Get-DynamicGroups
382-
#Finds dynamic groups and displays membership rules
383-
Get-DynamicGroups -Tokens $tokens
384-
385-
#Get-SharePointSiteURLs
386-
#Gets a list of SharePoint site URLs visible to the current user
387-
Get-SharePointSiteURLs -Tokens $tokens
388-
389-
#Invoke-GraphOpenInboxFinder
390-
#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.
391-
Invoke-GraphOpenInboxFinder -Tokens $tokens -Userlist users.txt
392-
393-
#Get-TenantID
394-
#This module attempts to gather a tenant ID associated with a domain.
395-
Get-TenantID -Domain
396-
397-
#Invoke-GraphRunner
398-
#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.
399-
Invoke-GraphRunner -Tokens $tokens
400-
```
401-
402158
{{#include ../../banners/hacktricks-training.md}}
403159

404160

0 commit comments

Comments
 (0)