Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/multi/manage/screensaver.rb
Views: 11784
##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'Actions' => [25[ 'LOCK', { 'Description' => 'Lock the current session' } ],26[ 'UNLOCK', { 'Description' => 'Unlock the current session' } ],27[ 'START', { 'Description' => 'Start the screensaver, may lock the current session' } ],28[ 'STOP', { 'Description' => 'Stop the screensaver, user may be prompted for its password' }],29],30'References' => [31['URL', 'https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7530']32],33'Notes' => {34'Reliability' => [ ],35'Stability' => [ ],36'SideEffects' => [ ]37}38)39)40end4142#43# cmd_exec but returning a boolean44#45def cmd_vexec(cmd)46vprint_status("Executing '#{cmd}'")4748begin49cmd_exec(cmd)50rescue StandardError51return false52end5354true55end5657def lock_session58case session.platform59when 'linux', 'solaris'60ret = false61if command_exists?('xdg-screensaver-lock')62ret |= cmd_vexec('xdg-screensaver lock')63end64if command_exists?('qdbus')65ret |= cmd_vexec('qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock')66end67if command_exists?('dbus-send')68ret |= cmd_exec('dbus-send --type=method_call --print-reply --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:true')69end70if command_exists?('loginctl')71self.class.include Msf::Post::Linux::Priv72if is_root?73ret |= cmd_vexec('loginctl lock-sessions')74else75ret |= cmd_vexec('loginctl lock-session')76end77end78print_error('Unable to lock session.') unless ret79return ret80when 'osx'81cmd_vexec('pmset displaysleepnow')82when 'windows'83cmd_vexec('rundll32 user32.dll,LockWorkStation')84end8586true87end8889def unlock_session90case session.platform91when 'linux', 'solaris'92ret = false93if command_exists?('xdg-screensaver')94ret |= cmd_vexec('xdg-screensaver reset')95end96if command_exists?('qdbus')97ret |= cmd_vexec('qdbus org.freedesktop.ScreenSaver /ScreenSaver Unlock')98end99if command_exists?('dbus-send')100ret |= cmd_exec('dbus-send --type=method_call --print-reply --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.SetActive boolean:false')101end102if command_exists?('loginctl')103self.class.include Msf::Post::Linux::Priv104if is_root?105ret |= cmd_vexec('loginctl unlock-sessions')106else107ret |= cmd_vexec('loginctl unlock-session')108end109end110print_error('Unable to unlock session.') unless ret111return ret112when 'osx'113fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Mac OSX, you can still lock the screen or start the screensaver')114when 'windows'115fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Windows, you can still lock the screen or start the screensaver')116end117118true119end120121def start_screensaver122case session.platform123when 'linux', 'solaris'124cmd_vexec('xdg-screensaver activate')125when 'osx'126cmd_vexec('open -a ScreenSaverEngine')127when 'windows'128cmd_vexec('powershell -w hidden -nop -c "Start-Process C:\\Windows\\System32\\scrnsave.scr"')129end130131true132end133134def stop_screensaver135case session.platform136when 'linux', 'solaris'137cmd_vexec('xdg-screensaver reset') if command_exists?('xdg-screensaver')138when 'osx'139fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Mac OSX, you can still lock the screen or start the screensaver')140when 'windows'141fail_with(Msf::Exploit::Failure::NoTarget, 'Not supported on Windows, you can still lock the screen or start the screensaver')142end143144true145end146147def run148print_error('Please specify an action') if action.nil?149150case action.name151when 'LOCK'152return lock_session153when 'UNLOCK'154return unlock_session155when 'START'156return start_screensaver157when 'STOP'158return stop_screensaver159end160end161end162163164