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/lib/rex/post/meterpreter/extensions/stdapi/sys/power.rb
Views: 11792
1
# -*- coding: binary -*-
2
3
require 'rex/post/process'
4
require 'rex/post/meterpreter/packet'
5
require 'rex/post/meterpreter/client'
6
require 'rex/post/meterpreter/extensions/stdapi/constants'
7
require 'rex/post/meterpreter/extensions/stdapi/stdapi'
8
9
module Rex
10
module Post
11
module Meterpreter
12
module Extensions
13
module Stdapi
14
module Sys
15
16
###
17
#
18
# This class provides access to the power of the remote machine (reboot, etc).
19
#
20
###
21
class Power
22
23
class <<self
24
attr_accessor :client
25
end
26
27
#
28
# Calls ExitWindows on the remote machine with the supplied parameters.
29
#
30
def Power._exitwindows(flags, reason = 0, force = 0) # :nodoc:
31
request = Packet.create_request(COMMAND_ID_STDAPI_SYS_POWER_EXITWINDOWS)
32
33
flags |= EWX_FORCEIFHUNG if force == 1
34
flags |= EWX_FORCE if force == 2
35
36
request.add_tlv(TLV_TYPE_POWER_FLAGS, flags);
37
request.add_tlv(TLV_TYPE_POWER_REASON, reason);
38
39
client.send_request(request)
40
end
41
42
#
43
# Reboots the remote machine.
44
#
45
def Power.reboot(force = 0, reason = 0)
46
self._exitwindows(EWX_REBOOT, reason, force)
47
end
48
49
#
50
# Shuts down the remote machine.
51
#
52
def Power.shutdown(force = 0, reason = 0)
53
self._exitwindows(EWX_POWEROFF, reason, force)
54
end
55
56
end
57
58
end end end end end end
59
60