Skip to content

Commit 27d07ae

Browse files
committed
improvements
1 parent 02042a1 commit 27d07ae

File tree

5 files changed

+211
-129
lines changed

5 files changed

+211
-129
lines changed

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

Lines changed: 95 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,47 @@ In order to audit an AZURE environment it's very important to know: which **serv
1616

1717
From a Red Team point of view, the **first step to compromise an Azure environment** is to manage to obtain some **foothold**.
1818

19-
### Initial Access
19+
### External enum & Initial Access
2020

21-
Here you can find the most common ways to get initial access to an Azure/Entra ID environment:
21+
The first step is of course to enumerate information about the tenant you are attacking and try to get a foothold.
2222

23-
- **OSINT**: Check for **leaks** in Github or any other open source platform that could contain **credentials** or interesting information.
24-
-
25-
- **Social** Engineering
26-
- **Password** reuse, leaks or [password spraying](az-unauthenticated-enum-and-initial-entry/az-password-spraying.md)
27-
- Vulnerabilities in Azure-Hosted Applications
28-
- [**Server Side Request Forgery**](https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html) with access to metadata endpoint
29-
- **Local File Read**
30-
- `/home/USERNAME/.azure`
31-
- `C:\Users\USERNAME\.azure`
32-
- The file **`accessTokens.json`** in `az cli` before 2.30 - Jan2022 - stored **access tokens in clear text**
33-
- The file **`azureProfile.json`** contains **info** about logged user.
34-
- **`az logout`** removes the token.
35-
- Older versions of **`Az PowerShell`** stored **access tokens** in **clear** text in **`TokenCache.dat`**. It also stores **ServicePrincipalSecret** in **clear**-text in **`AzureRmContext.json`**. The cmdlet **`Save-AzContext`** can be used to **store** **tokens**.\
36-
Use `Disconnect-AzAccount` to remove them.
37-
- 3rd parties **breached**
38-
- **Internal** Employee
39-
- [**Common Phishing**](https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-methodology/index.html) (credentials or Oauth App)
40-
- [Device Code Authentication Phishing](az-unauthenticated-enum-and-initial-entry/az-device-code-authentication-phishing.md)
23+
Based on the domain name it's possible to know **if the company if using Azure**, get the **tenant ID**, get other **valid domains** in the same tenant (if more) and get **relevant information** like if SSO is enabled, mail configurations, valid user emails...
4124

42-
Even if you **haven't compromised any user** inside the Azure tenant you are attacking, you can **gather some information** from it:
25+
Check the folloeing page to learn how to perform the **external enumeration**:
4326

4427
{{#ref}}
4528
az-unauthenticated-enum-and-initial-entry/
4629
{{#endref}}
4730

48-
> [!NOTE]
49-
> After you have managed to obtain credentials, you need to know **to who do those creds belong**, and **what they have access to**, so you need to perform some basic enumeration:
31+
With this information the most common ways to try to get a foothold are:
32+
- **OSINT**: Check for **leaks** in Github or any other open source platform that could contain **credentials** or interesting information.
33+
- **Password** reuse, leaks or [password spraying](az-unauthenticated-enum-and-initial-entry/az-password-spraying.md)
34+
- Buy credentials to an employee
35+
- [**Common Phishing**](https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-methodology/index.html) (credentials or Oauth App)
36+
- [Device Code Authentication Phishing](az-unauthenticated-enum-and-initial-entry/az-device-code-authentication-phishing.md)
37+
- 3rd parties **breached**
38+
- Vulnerabilities in Azure-Hosted Applications
39+
- [**Server Side Request Forgery**](https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html) with access to metadata endpoint
40+
- **Subdomain takeovers** like in [https://godiego.co/posts/STO-Azure/](https://godiego.co/posts/STO-Azure/)
41+
- If some developer laptop is compromised ([WinPEAS and LinPEAS](https://github.com/peass-ng/PEASS-ng) can find this info):
42+
- Inside **`<HOME>/.Azure`**
43+
- **`azureProfile.json`** contains info about logged in users from the past
44+
- **`clouds.config contains`** info about subscriptions
45+
- **`service_principal_entries.json`** contains applications credentials (tenant id, clients and secret). Only in Linux & macOS
46+
- **`msal_token_cache.json`** contains contains access tokens and refresh tokens. Only in Linux & macOS
47+
- **`service_principal_entries.bin`** and msal_token_cache.bin are used in Windows and are encrypted with DPAPI
48+
- **`msal_http_cache.bin`** is a cache of HTTP request
49+
- Load it: `with open("msal_http_cache.bin", 'rb') as f: pickle.load(f)`
50+
- **`AzureRmContext.json`** contains information about previous logins using Az PowerShell (but no credentials)
51+
- Inside **`C:\Users\<username>\AppData\Local\Microsoft\IdentityCache\*`** are several `.bin` files with **access tokens**, ID tokens and account information encrypted with the users DPAPI.
52+
- It’s possible to find more **access tokens** in the `.tbres` files inside **`C:\Users\<username>\AppData\Local\Microsoft\TokenBroken\Cache\`** which contain a base64 encrypted with DPAPI with access tokens.
53+
- In Linux and macOS you can get **access tokens, refresh tokens and id tokens** from Az PowerShell (if used) running `pwsh -Command "Save-AzContext -Path /tmp/az-context.json"`
54+
- In Windows this just generates id tokens.
55+
- Possible to see if Az PowerShell was used in Linux and macSO checking is `$HOME/.local/share/.IdentityService/` exists (although the contained files are empty and useless)
5056

51-
## Basic Enumeration
5257

5358
> [!NOTE]
54-
> Remember that the **noisiest** part of the enumeration is the **login**, not the enumeration itself.
55-
56-
### SSRF
57-
58-
If you found a SSRF in a server inside Azure check this page for tricks:
59-
60-
{{#ref}}
61-
https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html#azure{{#endref}}
62-
63-
### Subdomain Takeover
64-
65-
- [https://godiego.co/posts/STO-Azure/](https://godiego.co/posts/STO-Azure/)
59+
> Remember that usually the **noisiest** part of the enumeration is the **login**, not the enumeration itself.
6660
6761
### Azure & Entra ID tooling
6862

@@ -108,18 +102,7 @@ az account management-group list #Not allowed by default
108102

109103
{{#endtab }}
110104

111-
{{#tab name="AzureAD" }}
112-
113-
```bash
114-
#Get the current session state
115-
Get-AzureADCurrentSessionInfo
116-
#Get details of the current tenant
117-
Get-AzureADTenantDetail
118-
```
119-
120-
{{#endtab }}
121-
122-
{{#tab name="Az PowerShell" }}
105+
{{#tab name="Az" }}
123106

124107
```bash
125108
# Get the information about the current context (Account, Tenant, Subscription etc.)
@@ -130,22 +113,33 @@ Get-AzContext -ListAvailable
130113
Get-AzSubscription
131114
#Get Resource group
132115
Get-AzResourceGroup
133-
# Enumerate all resources visible to the current user
134-
Get-AzResource
135-
# Enumerate all Azure RBAC role assignments
136-
Get-AzRoleAssignment # For all users
137-
Get-AzRoleAssignment -SignInName [email protected] # For current user
116+
```
117+
118+
{{#endtab }}
119+
120+
{{#tab name="Mg" }}
121+
122+
```bash
123+
#Get the current session
124+
Get-MgContext
125+
```
126+
127+
{{#endtab }}
128+
129+
{{#tab name="AzureAD" }}
130+
131+
```bash
132+
#Get the current session state
133+
Get-AzureADCurrentSessionInfo
134+
#Get details of the current tenant
135+
Get-AzureADTenantDetail
138136
```
139137

140138
{{#endtab }}
141139
{{#endtabs }}
142140

143-
> [!CAUTION]
144-
> Oone of the most important commands to enumerate Azure is **`Get-AzResource`** from Az PowerShell as it lets you **know the resources your current user has visibility over**.
145-
>
146-
> 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"
147141

148-
### Entra ID Enumeration
142+
### Entra ID Enumeration & Privilege Escalation
149143

150144
By default, any user should have **enough permissions to enumerate** things such as users, groups, roles, service principals... (check [default AzureAD permissions](az-basic-information/index.html#default-user-permissions)).\
151145
You can find here a guide:
@@ -154,11 +148,50 @@ You can find here a guide:
154148
az-services/az-azuread.md
155149
{{#endref}}
156150

157-
> [!NOTE]
158-
> Now that you **have some information about your credentials** (and if you are a red team hopefully you **haven't been detected**). It's time to figure out which services are being used in the environment.\
159-
> In the following section you can check some ways to **enumerate some common services.**
151+
Check the **Post-Exploitation tools** to find tools to escalate privileges in Entra ID like **AzureHound:**
152+
153+
{{#ref}}
154+
az-enumeration-tools.md#automated-post-exploitation-tools
155+
{{#endref}}
156+
157+
158+
### Enumerate Azure Services
159+
160+
Once you know who you are, you can start enumerating the **Azure services you have access to**.
161+
162+
The Az PoswerShell command **`Get-AzResource`** lets you **know the resources your current user has visibility over**.
160163

161-
###
164+
Moreover, 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" or executing: `az rest --method GET --url "https://management.azure.com/subscriptions/<subscription-id>/resources?api-version=2021-04-01"`
165+
166+
Furthermore, with enough permissions, the role **`Get-AzRoleAssignment`** can be used to **enumerate all the roles** in the subscription or the permission over a specific resource indicatig it like in: **`Get-AzRoleAssignment -Scope /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.RecoveryServices/vaults/vault-m3ww8ut4`**
167+
168+
In the following section you can find information about the most common Azure services and how to enumerate them:
169+
170+
{{#ref}}
171+
az-services/
172+
{{#endref}}
173+
174+
### Privilege Escalation, Post-Exploitation & Persistence in Azure Services
175+
176+
Once you know how is the Azure environment structured and what services are being used, you can start looking for ways to **escalate privileges, move laterally, perform other post-exploitation attacks and maintain persistence**.
177+
178+
In the following section you can find information about how to escalate privileges in the most common Azure services:
179+
180+
{{#ref}}
181+
az-privilege-escalation/
182+
{{#endref}}
183+
184+
In the following one you can find information about how to perform post-exploitation attacks in the most common Azure services:
185+
186+
{{#ref}}
187+
az-post-exploitation/
188+
{{#endref}}
189+
190+
In the following one you can find information about how to maintain persistence in the most common Azure services:
191+
192+
{{#ref}}
193+
az-persistence/
194+
{{#endref}}
162195

163196
{{#include ../../banners/hacktricks-training.md}}
164197

src/pentesting-cloud/azure-security/az-basic-information/az-tokens-and-public-applications.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ new_azure_cli_bearer_tokens_for_graph_api = (
146146
pprint(new_azure_cli_bearer_tokens_for_graph_api)
147147
```
148148

149+
### Other access token fields
150+
151+
- **appid**: Application ID used to generate the token
152+
- **appidacr**: The Application Authentication Context Class Reference indicates how the client was authenticated, for a public client the value is 0, and if a client secret is used the value is 1
153+
- **acr**: The Authentication Context Class Reference claim is "0" when the end-user authentication did not meet the requirements of ISO/IEC 29115.
154+
- **amr**: The Authentication method indicates how the token was authenticated. A value of “pwd” indicates that a password was used.
155+
- **groups**: Indicates the groups where the principal is a member.
156+
- **iss**: The issues identifies the security token service (STS) that generated the token. e.g. https://sts.windows.net/fdd066e1-ee37-49bc-b08f-d0e152119b04/ (the uuid is the tenant ID)
157+
- **oid**: The object ID of the principal
158+
- **tid**: Tenant ID
159+
- **iat, nbf, exp**: Issued at (when it was issued), Not before (cannot be used before this time, usually same value as iat), Expiration time.
160+
161+
149162
## FOCI Tokens Privilege Escalation
150163

151164
Previously it was mentioned that refresh tokens should be tied to the **scopes** it was generated with, to the **application** and **tenant** it was generated to. If any of these boundaries is broken, it's possible to escalate privileges as it will be possible to generate access tokens to other resources and tenants the user has access to and with more scopes than it was originally intended.
@@ -198,6 +211,7 @@ pprint(microsoft_office_bearer_tokens_for_graph_api)
198211
## References
199212

200213
- [https://github.com/secureworks/family-of-client-ids-research](https://github.com/secureworks/family-of-client-ids-research)
214+
- [https://github.com/Huachao/azure-content/blob/master/articles/active-directory/active-directory-token-and-claims.md](https://github.com/Huachao/azure-content/blob/master/articles/active-directory/active-directory-token-and-claims.md)
201215

202216
{{#include ../../../banners/hacktricks-training.md}}
203217

src/pentesting-cloud/azure-security/az-enumeration-tools.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ export REQUESTS_CA_BUNDLE=/Users/user/Downloads/cacert.pem
9393

9494
{{#endtab }}
9595

96+
{{#tab name="CMD" }}
97+
98+
```bash
99+
set ADAL_PYTHON_SSL_NO_VERIFY=1
100+
set AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
101+
set HTTPS_PROXY="http://127.0.0.1:8080"
102+
set HTTP_PROXY="http://127.0.0.1:8080"
103+
104+
# If this is not enough
105+
# Download the certificate from Burp and convert it into .pem format
106+
# And export the following env variable
107+
openssl x509 -in cacert.der -inform DER -out cacert.pem -outform PEM
108+
set REQUESTS_CA_BUNDLE=C:\Users\user\Downloads\cacert.pem
109+
```
110+
111+
{{#endtab }}
112+
96113
{{#tab name="PS" }}
97114

98115
```bash

0 commit comments

Comments
 (0)