Path: blob/master/modules/post/multi/manage/screensaver.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6Rank = ExcellentRanking78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Multi Manage the screensaver of the target computer',13'Description' => %q{14This module allows you to turn on or off the screensaver of the target computer and also15lock the current session.16},17'License' => MSF_LICENSE,18'Author' => [19'Eliott Teissonniere', # Metasploit module20'Julien Voisin' # Linux improvements21],22'Platform' => [ 'linux', 'osx', 'win', 'unix', 'solaris' ],23'SessionTypes' => [ 'shell', 'meterpreter' ],24'DefaultAction' => 'LOCK',25'Actions' => [26[ 'LOCK', { 'Description' => 'Lock the current session' } ],27[ 'UNLOCK', { 'Description' => 'Unlock the current session' } ],28[ 'START', { 'Description' => 'Start the screensaver, may lock the current session' } ],29[ 'STOP', { 'Description' => 'Stop the screensaver, user may be prompted for its password' }],30],31'References' => [32['URL', 'https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7530']33],34'Notes' => {35'Reliability' => [ ],36'Stability' => [CRASH_SAFE],37'SideEffects' => [SCREEN_EFFECTS]38}39)40)41end4243#44# cmd_exec but returning a boolean45#46def cmd_vexec(cmd)47vprint_status("Executing '#{cmd}'")4849begin50cmd_exec(cmd)51rescue StandardError52return false53end5455true56end5758def lock_session59case session.platform60when 'linux', 'solaris'61ret = false62if command_exists?('xdg-screensaver-lock')63ret |= cmd_vexec('xdg-screensaver lock')64end65if command_exists?('qdbus')66ret |= cmd_vexec('qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock')67end68if command_exists?('dbus-send')69ret |= cmd_exec('dbus-send --type=method_call --print-reply --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:true')70end71if command_exists?('loginctl')72self.class.include Msf::Post::Linux::Priv73if is_root?74ret |= cmd_vexec('loginctl lock-sessions')75else76ret |= cmd_vexec('loginctl lock-session')77end78end79print_error('Unable to lock session.') unless ret80return ret81when 'osx'82cmd_vexec('pmset displaysleepnow')83when 'windows'84cmd_vexec('rundll32 user32.dll,LockWorkStation')85end8687true88end8990def unlock_session91case session.platform92when 'linux', 'solaris'93ret = false94if command_exists?('xdg-screensaver')95ret |= cmd_vexec('xdg-screensaver reset')96end97if command_exists?('qdbus')98ret |= cmd_vexec('qdbus org.freedesktop.ScreenSaver /ScreenSaver Unlock')99end100if command_exists?('dbus-send')101ret |= cmd_exec('dbus-send --type=method_call --print-reply --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:false')102end103if command_exists?('loginctl')104self.class.include Msf::Post::Linux::Priv105if is_root?106ret |= cmd_vexec('loginctl unlock-sessions')107else108ret |= cmd_vexec('loginctl unlock-session')109end110end111print_error('Unable to unlock session.') unless ret112return ret113when 'osx'114fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Mac OSX, you can still lock the screen or start the screensaver')115when 'windows'116fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Windows, you can still lock the screen or start the screensaver')117end118119true120end121122def start_screensaver123case session.platform124when 'linux', 'solaris'125cmd_vexec('xdg-screensaver activate')126when 'osx'127cmd_vexec('open -a ScreenSaverEngine')128when 'windows'129cmd_vexec('powershell -w hidden -nop -c "Start-Process C:\\Windows\\System32\\scrnsave.scr"')130end131132true133end134135def stop_screensaver136case session.platform137when 'linux', 'solaris'138cmd_vexec('xdg-screensaver reset') if command_exists?('xdg-screensaver')139when 'osx'140fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Mac OSX, you can still lock the screen or start the screensaver')141when 'windows'142fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Windows, you can still lock the screen or start the screensaver')143end144145true146end147148def run149print_error('Please specify an action') if action.nil?150151case action.name152when 'LOCK'153return lock_session154when 'UNLOCK'155return unlock_session156when 'START'157return start_screensaver158when 'STOP'159return stop_screensaver160end161end162end163164165