Az - Automation Accounts
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
基本信息
Azure Automation Accounts 是 Microsoft Azure 中的云服务,帮助自动化任务,如资源管理、配置和更新,跨 Azure 和本地环境。它们提供Runbooks(执行的自动化脚本)、计划和混合工作组来运行自动化作业,实现基础设施即代码(IaC)和流程自动化,以提高管理云资源的效率和一致性。
设置
- 凭据:密码仅在自动化帐户内的 runbook 中可访问,用于安全存储用户名和密码。
- 变量:用于存储可以在 runbooks 中使用的配置数据。这也可以是敏感信息,如 API 密钥。如果变量是加密存储的,则仅在自动化帐户内的 runbook 中可用。
- 证书:用于存储可以在 runbooks 中使用的证书。
- 连接:用于存储与外部服务的连接信息。这可能包含敏感信息。
- 网络访问:可以设置为公共或私有。
Runbooks & Jobs
Azure Automation 中的 Runbook 是一个自动执行任务的脚本,在您的云环境中运行。Runbooks 可以用 PowerShell、Python 或图形编辑器编写。它们帮助自动化管理任务,如 VM 管理、打补丁或合规检查。
在Runbooks中的代码可能包含敏感信息(如凭据)。
作业是 Runbook 执行的一个实例。当您运行一个 Runbook 时,会创建一个作业来跟踪该执行。每个作业包括:
- 状态:排队、运行、完成、失败、挂起。
- 输出:Runbook 执行的结果。
- 开始和结束时间:作业开始和完成的时间。
作业包含Runbook执行的输出。如果您可以读取这些作业,请这样做,因为它们包含运行的输出(潜在的敏感信息)。
Schedules & Webhooks
执行 Runbook 有 3 种主要方式:
- 计划:用于在特定时间或间隔触发 Runbooks。
- Webhooks:这些是可以用于从外部服务触发 Runbooks 的HTTP 端点。请注意,创建后 webhook URL 是不可见的。
- 手动触发:您可以从 Azure 门户和 CLI 手动触发 Runbook。
Source Control
它允许从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_SC_USER_ASSIGNED_IDENTITY_ID**中指明用户 MI 的客户端 ID。
Runtime Environments
创建 Runbook 时,可以选择运行时环境。默认情况下,以下运行时环境可用:
- Powershell 5.1
- Powershell 7.1
- PowerShell 7.2
- Python 3.10
- Python 3.8
- Python 2.7
但是,也可以创建自己的环境,以其中一个作为基础。在 Python 的情况下,可以将 .whl 包上传到将要使用的环境。在 PowerShell 的情况下,可以上传包含要在运行时使用的模块的 .zip 包。
Hybrid Worker Groups
在 Azure Automation 中,Runbooks 的默认执行环境是Azure Sandbox,这是一个由 Azure 管理的云平台,适合涉及 Azure 资源的任务。然而,这个沙箱有一些限制,例如对本地资源的访问受限以及执行时间和资源使用的限制。为了解决这些限制,采用了混合工作组。混合工作组由一个或多个安装在您自己机器上的混合 Runbook Worker组成,无论是在本地、其他云环境还是 Azure 虚拟机上。此设置允许 Runbooks 直接在这些机器上执行,提供对本地资源的直接访问,能够运行更长时间和更资源密集的任务,并灵活地与超出 Azure 直接范围的环境进行交互。
创建混合工作组时,需要指明要使用的凭据。有 2 个选项:
- 默认凭据:您无需提供凭据,Runbooks 将作为系统在虚拟机内执行。
- 特定凭据:您需要提供自动化帐户内凭据对象的名称,该凭据将用于在虚拟机内执行Runbooks。因此,在这种情况下,可能会窃取虚拟机的有效凭据。
因此,如果您可以选择在混合工作者中运行Runbook,您将以系统身份在外部机器上执行任意命令(很好的转移技术)。
此外,如果混合工作者在 Azure 中运行并附加了其他托管身份,Runbook 将能够访问Runbook 的托管身份和虚拟机的所有托管身份的元数据服务。
Tip
请记住,元数据服务的 URL 与获取自动化帐户的托管身份令牌的服务的 URL(
IDENTITY_ENDPOINT)不同(http://169.254.169.254)。
State Configuration (SC)
Warning
如文档所示,Azure Automation State Configuration 将于 2027 年 9 月 30 日退役,并由Azure Machine Configuration取代。
Automation Accounts 还支持状态配置(SC),这是一个帮助配置和维护您的虚拟机状态的功能。可以创建和应用 DSC 配置到Windows和Linux机器。
从攻击者的角度来看,这很有趣,因为它允许在所有配置的虚拟机中执行任意 PS 代码,从而提升到这些虚拟机的托管身份,可能转移到新的网络……此外,配置可能包含敏感信息。
枚举
# 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
az 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>
# Get hybrid worker groups for an automation account
az automation hrwg list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
# Get hybrid worker group details
az automation hrwg show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <HYBRID-WORKER-GROUP>
# Get more details about a hybrid worker group (like VMs inside it)
az rest --method GET --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/hybridRunbookWorkerGroups/<hybrid-worker-group-name>/hybridRunbookWorkers?&api-version=2021-06-22"
# 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>
权限提升与后期利用
Az - Automation Accounts Privesc
持久性
Az - Automation Accounts Persistence
参考
- https://learn.microsoft.com/en-us/azure/automation/overview
- https://learn.microsoft.com/en-us/azure/automation/automation-dsc-overview
- https://github.com/rootsecdev/Azure-Red-Team#runbook-automation
Tip
学习并练习 AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

