CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/vmware/poweroff_vm.rb
Views: 11784
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' => %Q{
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
end
30
31
def run
32
if vim_do_login(datastore['USERNAME'], datastore['PASSWORD']) == :success
33
vm_ref = vim_find_vm_by_name(datastore['VM'])
34
case vm_ref
35
when String
36
return_state = vim_powerOFF_vm(vm_ref)
37
case return_state
38
when 'success'
39
print_good "VM Powered Off Successfully"
40
when 'alreadyOFF'
41
print_status "The Server says that VM #{datastore['VM']} is already off."
42
else
43
print_error "The server returned an unexpected status #{return_state}"
44
end
45
when :noresponse
46
print_error "The request timed out"
47
when :error
48
print_error @vim_soap_error
49
when nil
50
print_error "Could not locate VM #{datastore['VM']}"
51
end
52
else
53
print_error "Login Failure on #{datastore['RHOST']}"
54
return
55
end
56
end
57
end
58
59