{"id":2090,"date":"2024-11-05T08:30:00","date_gmt":"2024-11-05T13:30:00","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=2090"},"modified":"2024-10-31T08:44:20","modified_gmt":"2024-10-31T12:44:20","slug":"exploring-vm-security-how-to-identify-encrypted-virtual-disks-in-vsphere","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/exploring-vm-security-how-to-identify-encrypted-virtual-disks-in-vsphere\/","title":{"rendered":"Exploring VM Security: How to Identify Encrypted Virtual Disks in vSphere"},"content":{"rendered":"\n<p>I was recently looking at some virtual machines in a lab and trying to determine which had encrypted virtual disks vs. encrypted configuration folders only. This data is visible in the vSphere UI.  From the VM list view we can select the &#8216;pick columns&#8217; icon in the lower left near the export button (in vCenter Server 8 this is called Manage Columns) and select the checkbox for Encryption.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"268\" height=\"185\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-5.png\" alt=\"\" class=\"wp-image-2100\"\/><\/a><\/figure>\n\n\n\n<p>With this selected, we can see that 4 VMs are all encrypted.  <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"447\" height=\"140\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-6.png\" alt=\"\" class=\"wp-image-2101\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-6.png 447w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-6-300x94.png 300w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/a><\/figure>\n\n\n\n<p>However, if we dig a little deeper, we can see that one VM has the configuration files and the only hard disk encrypted, as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"544\" height=\"216\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-2.png\" alt=\"\" class=\"wp-image-2096\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-2.png 544w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-2-300x119.png 300w\" sizes=\"auto, (max-width: 544px) 100vw, 544px\" \/><\/a><\/figure>\n\n\n\n<p>Another VM only has the first hard disk encrypted (note that Hard disk 2 does not show the word &#8216;Encrypted&#8217; below the disk size).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"254\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-4.png\" alt=\"\" class=\"wp-image-2098\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-4.png 525w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-4-300x145.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/a><\/figure>\n\n\n\n<p>And yet another VM only has encrypted configuration files and the hard disk is not encrypted at all.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"204\" src=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-3.png\" alt=\"\" class=\"wp-image-2097\" srcset=\"https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-3.png 547w, https:\/\/enterpriseadmins.org\/blog\/wp-content\/uploads\/2024\/10\/image-3-300x112.png 300w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/a><\/figure>\n\n\n\n<p>This makes sense, as the virtual machine view does not list each virtual disk, only the VM configuration.  We can encrypt only the configuration, but we can&#8217;t encrypt only a hard disk without also encrypting the configuration.  This view shows that there is something going on with encryption, but for what I was looking for we&#8217;ll need to dig bit deeper. <\/p>\n\n\n\n<p>Since I wanted to check each VMDK of each VM, that&#8217;s not something that is easily viewable in the UI without lots of clicking, so I switched over to PowerCLI. I found a blog post from a couple years back (<a href=\"https:\/\/blogs.vmware.com\/vsphere\/2016\/12\/powercli-for-vm-encryption.html\">https:\/\/blogs.vmware.com\/vsphere\/2016\/12\/powercli-for-vm-encryption.html<\/a>) which mentioned a community powershell module (<a href=\"https:\/\/github.com\/vmware\/PowerCLI-Example-Scripts\/tree\/master\/Modules\/VMware.VMEncryption\">https:\/\/github.com\/vmware\/PowerCLI-Example-Scripts\/tree\/master\/Modules\/VMware.VMEncryption<\/a>) to report on encryption. Browsing through the code, I saw a &#8216;KeyID&#8217; property that is present on VMs and Hard Disks where the configuration is encrypted. I created a quick script to loop through all the VMs looking for either of these properties.  I could have used the published module, but for this simple exercise it was easy enough to pick\/choose the fields I needed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$myResults = @()\nforeach ($thisVM in Get-VM) {\n  foreach ($thisVMDK in ($thisVM | Get-HardDisk) ) {\n    $myResults += $thisVMDK | Select-Object @{N='VM';E={$thisVM.Name}}, @{N='ConfigEncrypted';E={ if($thisVM.extensionData.config.keyId.KeyId){'True'} }}, \n                @{N='VMDK Encrypted';E={if($_.extensionData.Backing.KeyId.KeyID){'True'} }}, @{N='Hard Disk';E={$_.Name}},\n                @{N='vTPM';E={if($thisVM.ExtensionData.config.Hardware.device | ?{$_.key -eq 11000}){'True'} }}\n  } # end foreach VMDK\n} # end foreach VM\n\n$myResults | Sort-Object VM | Format-Table -AutoSize<\/code><\/pre>\n\n\n\n<p>Our <code>$myResults<\/code> variable now contains a row for each virtual hard disk, showing the VM Name, whether or not the &#8216;Home&#8217; configuration is encrypted, if the VMDK is encrypted, the Hard Disk Name, and if the system has a vTPM or not. By default, the output will sort all the VMs by name, and list all of the properties. However, if I needed a list of all the VMs that might have one or more encrypted VMDKs, I could use the following <code>Where-Object<\/code> filter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$myResults | Where-Object {$_.'VMDK Encrypted' -eq 'True'} | Select-Object VM -Unique<\/code><\/pre>\n\n\n\n<p>This will result in a list of VM names, showing only two interesting VMs.  The above screenshot from the UI showed four VMs with encrypted configs.<\/p>\n\n\n\n<p>Hopefully this will be helpful if you are looking for encrypted VMs in an environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently looking at some virtual machines in a lab and trying to determine which had encrypted virtual disks vs. encrypted configuration folders only. This data is visible in the vSphere UI. From the VM list view we can &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/exploring-vm-security-how-to-identify-encrypted-virtual-disks-in-vsphere\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-2090","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2090","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=2090"}],"version-history":[{"count":6,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2090\/revisions"}],"predecessor-version":[{"id":2109,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/2090\/revisions\/2109"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=2090"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=2090"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=2090"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}