Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/gather/enum_hyperv_vms.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Powershell78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Hyper-V VM Enumeration',13'Description' => %q{14This module will check if the target machine is a Hyper-V host and, if it is, will return a list of all15of the VMs running on the host, as well as stats such as their state, version, CPU Usage, uptime, and status.16},17'License' => MSF_LICENSE,18'Platform' => ['win'],19'SessionTypes' => ['meterpreter'],20'Author' => [21'gwillcox-r7' # Metasploit post module22],23'Notes' => {24'Stability' => [CRASH_SAFE],25'Reliability' => [],26'SideEffects' => []27}28)29)30end3132def run33unless have_powershell?34fail_with(Failure::NoAccess, "The target does not have PowerShell installed so we can't access the state of the Hyper-V VMs")35end36error_token = Rex::Text.rand_text_alpha(8)37get_vm = "try { Get-VM } catch {echo #{error_token}; echo $Error[0]}"38results = psh_exec(get_vm)39if results.starts_with?(error_token)40results = results.delete_prefix(error_token).strip41print_error('Error running `Get-VM` command:')42print_line(results)43return44end45vprint_status(results)46filtered_result = results.match(/^Name(?:.+\r\n){1,2000}/) # If your running more than 2000 VMs on a single host, you have my sincerest sympathy.47if filtered_result.nil?48print_error("Sorry, no results were found! Perhaps the target has Hyper-V installed but doesn't have any VMs set up?")49return50end51print_status(filtered_result.to_s)52loot_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")53print_good("Stored loot at #{loot_location}")54end55end565758