CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/multi/manage/screensaver.rb
Views: 1904
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::Post
7
def initialize(info = {})
8
super(
9
update_info(
10
info,
11
'Name' => 'Multi Manage the screensaver of the target computer',
12
'Description' => %q{
13
This module allows you to turn on or off the screensaver of the target computer and also
14
lock the current session.
15
},
16
'License' => MSF_LICENSE,
17
'Author' => [ 'Eliott Teissonniere'],
18
'Platform' => [ 'linux', 'osx', 'win' ],
19
'SessionTypes' => [ 'shell', 'meterpreter' ],
20
'Actions' => [
21
[ 'LOCK', { 'Description' => 'Lock the current session' } ],
22
[ 'START', { 'Description' => 'Start the screensaver, may lock the current session' } ],
23
[ 'STOP', { 'Description' => 'Stop the screensaver, user may be prompted for its password' }]
24
]
25
)
26
)
27
end
28
29
#
30
# cmd_exec but with some controls and verbosity
31
#
32
def cmd_vexec(cmd)
33
print_status("Executing '#{cmd}'")
34
35
begin
36
cmd_exec(cmd)
37
rescue EOFError
38
print_error('Command failed')
39
return false
40
end
41
42
true
43
end
44
45
def lock_session
46
case session.platform
47
when 'linux'
48
cmd_vexec('xdg-screensaver lock')
49
when 'osx'
50
cmd_vexec('pmset displaysleepnow')
51
when 'windows'
52
cmd_vexec('rundll32 user32.dll,LockWorkStation')
53
end
54
55
true
56
end
57
58
def start_screensaver
59
case session.platform
60
when 'linux'
61
cmd_vexec('xdg-screensaver activate')
62
when 'osx'
63
cmd_vexec('open -a ScreenSaverEngine')
64
when 'windows'
65
cmd_vexec('powershell -w hidden -nop -c "Start-Process C:\\Windows\\System32\\scrnsave.scr"')
66
end
67
68
true
69
end
70
71
def stop_screensaver
72
case session.platform
73
when 'linux'
74
cmd_vexec('xdg-screensaver reset')
75
when 'osx'
76
print_error('Not supported on Mac OSX, you can still lock the screen or start the screensaver')
77
return false
78
when 'windows'
79
print_error('Not supported on Windows, you can still lock the screen or start the screensaver')
80
return false
81
end
82
83
true
84
end
85
86
def run
87
if action.nil?
88
print_error('Please specify an action')
89
end
90
91
case action.name
92
when 'LOCK'
93
return lock_session
94
when 'START'
95
return start_screensaver
96
when 'STOP'
97
return stop_screensaver
98
end
99
end
100
end
101
102