Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/vmware/poweroff_vm.rb
19593 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::HttpClient
8
include Msf::Auxiliary::Report
9
include Msf::Exploit::Remote::VIMSoap
10
11
def initialize
12
super(
13
'Name' => 'VMWare Power Off Virtual Machine',
14
'Description' => %(
15
This module will log into the Web API of VMWare and try to power off
16
a specified Virtual Machine.),
17
'Author' => ['theLightCosine'],
18
'License' => MSF_LICENSE,
19
'DefaultOptions' => { 'SSL' => true }
20
)
21
22
register_options(
23
[
24
Opt::RPORT(443),
25
OptString.new('USERNAME', [ true, 'The username to Authenticate with.', 'root' ]),
26
OptString.new('PASSWORD', [ true, 'The password to Authenticate with.', 'password' ]),
27
OptString.new('VM', [true, 'The VM to try to Power Off'])
28
]
29
)
30
end
31
32
def run
33
if vim_do_login(datastore['USERNAME'], datastore['PASSWORD']) == :success
34
vm_ref = vim_find_vm_by_name(datastore['VM'])
35
case vm_ref
36
when String
37
return_state = vim_powerOFF_vm(vm_ref)
38
case return_state
39
when 'success'
40
print_good 'VM Powered Off Successfully'
41
when 'alreadyOFF'
42
print_status "The Server says that VM #{datastore['VM']} is already off."
43
else
44
print_error "The server returned an unexpected status #{return_state}"
45
end
46
when :noresponse
47
print_error 'The request timed out'
48
when :error
49
print_error @vim_soap_error
50
when nil
51
print_error "Could not locate VM #{datastore['VM']}"
52
end
53
else
54
print_error "Login Failure on #{datastore['RHOST']}"
55
return
56
end
57
end
58
end
59
60