Skip to content

Commit 9c3a698

Browse files
committed
automation acc hybrid workers
1 parent b193c5c commit 9c3a698

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ Fore more information check:
1010
../az-services/az-automation-accounts.md
1111
{{#endref}}
1212

13+
### Hybrid Workers
14+
15+
Remember that if somehow an attacker can execute an arbitrary runbook (arbitrary code) in a hybrid worker, he will **pivot to the location of the VM**. This could be an on-premise machine, a VPC of a different cloud or even an Azure VM.
16+
17+
Moreover, if the hybrid worker is running in Azure with other Managed Identities attached, the runbook will be able to access the **managed identity of the runbook and all the managed identities of the VM from the metadata service**.
18+
19+
> [!TIP]
20+
> Remember that the **metadata service** has a different URL (**`http://169.254.169.254`**) than the service from where get the managed identities token of the automation account (**`IDENTITY_ENDPOINT`**).
21+
1322
### `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`)
1423

1524
As summary these permissions allow to **create, modify and run Runbooks** in the Automation Account which you could use to **execute code** in the context of the Automation Account and escalate privileges to the assigned **Managed Identities** and leak **credentials** and **encrypted variables** stored in the Automation Account.
@@ -43,7 +52,11 @@ az automation runbook publish \
4352
The permission **`Microsoft.Automation/automationAccounts/jobs/write`** allows the user to run a Runbook in the Automation Account using:
4453

4554
```bash
46-
az automation runbook start --automation-account-name <account-name> --resource-group <res-group> --name <runbook-name>
55+
az automation runbook start \
56+
--automation-account-name <account-name> \
57+
--resource-group <res-group> \
58+
--name <runbook-name> \
59+
[--run-on <name-hybrid-group>]
4760
```
4861

4962
The permission **`Microsoft.Automation/automationAccounts/jobs/output/read`** allows the user to read the output of a job in the Automation Account using:
@@ -170,6 +183,7 @@ az automation runbook replace-content --no-wait \
170183
--content 'echo "Hello World"'
171184

172185
# Run the unpublished code
186+
## Indicate the name of the hybrid worker group in runOn to execute the runbook there
173187
az rest \
174188
--method PUT \
175189
--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" \
@@ -205,11 +219,29 @@ az automation source-control create \
205219

206220
This will automatically import the runbooks from the Github repository to the Automation Account and with some other permission to start running them it would be **possible to escalate privileges**.
207221

208-
Moreiver, remember that four source control to work in Automation Accounts it must have a managed identity with the role **`Contributor`** and if it's a user managed identity this can be configured also by setting in the variable **`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`** the **client id** of the user managed identity to use.
222+
Moreover, remember that for source control to work in Automation Accounts it must have a managed identity with the role **`Contributor`** and if it's a user managed identity the cleint id of the MI must be specified in the variable **`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**.
209223

210224
> [!TIP]
211225
> Note that it's not possible to change the repo URL of a source control once it's created.
212226
227+
### `Microsoft.Automation/automationAccounts/variables/write`
228+
229+
With the permission **`Microsoft.Automation/automationAccounts/variables/write`** it's possible to write variables in the Automation Account using the following command.
230+
231+
```bash
232+
az rest --method PUT \
233+
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/variables/<variable-name>?api-version=2019-06-01" \
234+
--headers "Content-Type=application/json" \
235+
--body '{
236+
"name": "<variable-name>",
237+
"properties": {
238+
"description": "",
239+
"value": "\"<variable-value>\"",
240+
"isEncrypted": false
241+
}
242+
}'
243+
```
244+
213245
### Custom Runtime Environments
214246

215247
If an automation account is using a custom runtime environment, it could be possible to overwrite a custom package of the runtime with some malicious code (like **a backdoor**). This way, whenever a runbook using that custon runtime is executed and load the custom package, the malicious code will be executed.

src/pentesting-cloud/azure-security/az-services/az-automation-accounts.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ When the sync is enabled, in the **Github repository a webhook is created** to t
4646

4747
Note that these webhooks **won't be visible** when listing webhooks in the associated runbooks to the Github repo. Also note that it's **not possible to change the repo URL** of a source control once it's created.
4848

49-
In order for the configured source control to work, the **Azure Automation Account** needs to have a managed identity (system or user) with the **`Contributor`** role. Moreover, to assing a user managed identity to the Automation Account, it'spossible to do it just setting the variable **`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`** to the **User Managed Identity Client ID**.
49+
In order for the configured source control to work, the **Azure Automation Account** needs to have a managed identity (system or user) with the **`Contributor`** role. Moreover, to assing a user managed identity to the Automation Account, it's needed to indicate the client ID of the user MI in the variable **`AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID`**.
5050

5151
### Runtime Environments
5252

@@ -62,15 +62,22 @@ When creating a Runbook it'spossible to select the runtime environment. By defau
6262
However, it's also possible to **create your own environments**, using one of these as a base. In the case of python, it's possible to upload `.whl` packages to the environment that will be used. In the case of PowerShell, it's possible to upload `.zip` packages with the modules to have in the runtime.
6363

6464

65-
### Hybrid Worker
65+
### Hybrid Worker Groups
6666

67-
A Runbook can be run in a **container inside Azure** or in a **Hybrid Worker** (non-azure machine).\
68-
The **Log Analytics Agent** is deployed on the VM to register it as a hybrid worker.\
69-
The hybrid worker jobs run as **SYSTEM** on Windows and **nxautomation** account on Linux.\
70-
Each Hybrid Worker is registered in a **Hybrid Worker Group**.
67+
In Azure Automation, the default execution environment for runbooks is the **Azure Sandbox**, a cloud-based platform managed by Azure, suitable for tasks involving Azure resources. However, this sandbox has limitations, such as restricted access to on-premises resources and constraints on execution time and resource usage. To overcome these limitations, Hybrid Worker Groups are employed. A Hybrid Worker Group consists of **one or more Hybrid Runbook Workers installed on your own machines**, whether on-premises, in other cloud environments or Azure VMs. This setup allows runbooks to execute directly on these machines, providing direct access to local resources, the ability to run longer and more resource-intensive tasks, and the flexibility to interact with environments beyond Azure's immediate reach.
68+
69+
When a hybrid worker group is created it's needed to indicate the **credentials** to use. There are 2 options:
70+
71+
- **Default credentials**: You don't need to provide the credentials and the runbooks will be executed inside the VMs as **System**.
72+
- **Specific credentials**: You need to provide the name of the credentials object inside the automation account, which will be used to execute the **runbooks inside the VMs**. Therefore, in this case, it could be possible to **steal valid credentials** for the VMs.
7173

7274
Therefore, if you can choose to run a **Runbook** in a **Windows Hybrid Worker**, you will execute **arbitrary commands** inside an external machine as **System** (nice pivot technique).
7375

76+
Moreover, if the hybrid worker is running in Azure with other Managed Identities attached, the runbook will be able to access the **managed identity of the runbook and all the managed identities of the VM from the metadata service**.
77+
78+
> [!TIP]
79+
> Remember that the **metadata service** has a different URL (**`http://169.254.169.254`**) than the service from where get the managed identities token of the automation account (**`IDENTITY_ENDPOINT`**).
80+
7481
### State Configuration (SC)
7582

7683
>[!WARNING]
@@ -183,6 +190,15 @@ az automation dsc configuration show --automation-account-name <AUTOMATION-ACCOU
183190

184191
# Get State Configuration content
185192
az automation dsc configuration show-content --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <DSC-CONFIG-NAME>
193+
194+
# Get hybrid worker groups for an automation account
195+
az automation hrwg list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>
196+
197+
# Get hybrid worker group details
198+
az automation hrwg show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <HYBRID-WORKER-GROUP>
199+
200+
# Get more details about a hybrid worker group (like VMs inside it)
201+
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"
186202
```
187203

188204
```powershell

0 commit comments

Comments
 (0)