Skip to content
SSRF Write-up Advanced

Exploiting a hidden and forgotten Bug

An HTML-to-PDF feature used an outdated TCPDF library that allowed an attacker to make the server upload its own internal files to a remote FTP server. The author confirmed the version from PDF metadata and extracted the password file as proof of concept.

Aditya Verma Follow

Published on cirius.medium.com

Hi, this writeup is about a bug that existed in HTML to PDF generation functionality in a program.

Aditya Verma, on cirius.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

This write-up covers a bug in an HTML to PDF generation feature of a program. The program let users create certificates from HTML together with a background template, and the backend rendered that HTML into a PDF file.

The community often says that HTML to PDF generating software is vulnerable to SSRF, so that was the angle I took: get the PDF renderer to make requests on my behalf, ideally to internal resources.

Setup

I used a TCP tunnel to observe outbound connections from the backend, and I inspected the PDF metadata in Burp Suite. I also registered a free FTP server at ftphosting.net to receive files, and later downloaded the exact version of TCPDF identified from the PDF metadata to reproduce the exploit locally.

Finding it

I tried injecting various payloads, searched for ideas and reread nahamsec's write-up on exploiting a similar function, but nothing worked. The only HTML tag that produced a response to my TCP tunnel was the <img> tag. The fetch that came from the backend gave no hint about which software was generating the PDF.

While trying various HTML tags, I found that injecting a <link> tag pointing to an internal file such as /etc/passwd, along with some other tags, produced an error on the POST request. The error did not contain much information, but it contained enough to keep going: it said TCPDF Error.

A search revealed that TCPDF is a PHP library used to create PDFs from HTML. I looked for known CVEs, but without the version I could not narrow the options down. I read the documentation to find any allowed HTML tag that could be leveraged against the backend, but TCPDF is reasonably secure on that front and did not allow any tag that would permit SSRF.

Exploitation

Step 1: Get the PDF and its metadata

I decided to look at what the generated PDF actually contains, since in the bug found by nahamsec the data came along with the PDF but was only visible in the metadata.

The website used one service to host PDFs and another service to display them. The PDFs shown in the frontend were converted to JPG before being displayed. The displaying service used the URL for the JPG format, but the hosting service response also contained a URL to the original PDF. The download URL for the PDF had yet another hostname and did not let me download the file. I reused the authentication headers from the hosting service hostname on this one, they worked, and I got the PDF metadata in Burp Suite.

TCPDF embeds the version number in the metadata. A single search showed the version was very old, TCPDF 6.0.043, which is vulnerable to CVE-2017-6100.

Step 2: Understand the vulnerability

TCPDF versions before 6.2 were vulnerable to uploading the server's internal files to a remote FTP server. The exploit had been presented by Frans Rosen in his blog, but there was still a long way to go: my TCP tunnel was not working correctly with FTP, and the exploit as presented did not work.

Step 3: Fix the FTP problem

I got a free FTP server from ftphosting.net, which resolved the first problem. Since I was sure the bug existed, I kept going and downloaded the exact version of TCPDF to do all the steps manually as described in the blog.

Step 4: Work out why the payload failed

Doing the steps manually showed that the payload was not working because the injected payload is serialised, and simply editing it to make the required changes rendered it useless. I generated a payload on my machine instead and passed that to the server, which extracted the passwd file from the target server to my FTP server as a proof of concept.

Root cause

The PDF generation used an outdated TCPDF instance (6.0.043). The version disclosure in the PDF metadata is what made the vulnerable component identifiable.

Impact

An attacker who can control the HTML that is rendered into a PDF could cause the backend to upload internal files, such as /etc/passwd, to an FTP server the attacker controls. In this case the proof of concept extracted the passwd file from the target server.

Fix

The report does not describe a fix that was applied.

Variants to test

  1. Inject a <link> tag pointing at an internal file such as /etc/passwd and watch for library-specific error text in the POST response. A positive result is an error naming the rendering library, which identifies the component to research.
  2. Inject an <img> tag pointing at a host you control and watch your listener. A positive result is an outbound fetch from the backend, confirming server-side rendering.
  3. Retrieve the generated PDF and inspect its metadata for a version string. A positive result is a version that maps to a known CVE for the renderer.
  4. If the PDF is served through several hostnames, replay the authentication headers from one hostname on another. A positive result is access to the original PDF or its metadata.
  5. For old TCPDF versions, generate the serialised payload locally against the exact version and submit it. A positive result is a file from the target server arriving on your FTP server.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

What happened, in plain words

A website let people create certificates by writing HTML (the language of web pages) and choosing a background template. The website then turned that HTML into a PDF file (a document format you can download and print). The author of this write-up, Aditya Verma, found that the software doing the conversion was an old version of a tool called TCPDF, and that this old version had a known security flaw. The flaw allowed an attacker to make the server send its own internal files (like the list of users on the system) to an FTP server (a file transfer service) controlled by the attacker. He proved it by receiving the passwd file on his own FTP server.

This article explains every step in beginner terms, including what each term means and why each action was taken.

Context

What is HTML to PDF generation?

Many websites offer a feature where you type or paste HTML (the code that describes a web page) and the site produces a PDF. This is common for invoices, tickets, certificates and reports. The website takes your HTML, passes it to a piece of software on its server (the backend), and that software renders the HTML into a PDF file.

What is SSRF?

SSRF stands for Server-Side Request Forgery. In plain terms, it means tricking a server into making a request (like fetching a web page or a file) that you, the attacker, are not allowed to make directly. Imagine you are visiting a building and the receptionist will fetch anything you ask for from inside the building. If you ask for a file from a locked room, the receptionist might bring it to you because they have access. SSRF is similar: the server has access to internal systems, and if you can control what it fetches, you can reach those internal systems.

The security community often says that HTML to PDF converters are prone to SSRF because they fetch resources (images, stylesheets, links) while rendering the HTML. If an attacker can inject HTML that points to an internal address, the converter might fetch it.

The approach

The author decided to test whether the PDF generator could be made to make requests on his behalf. He wanted to see if he could get it to fetch internal resources.

Setup

To observe what the server was doing, the author used two tools:

  • TCP tunnel: A service that gives you a public address and shows you any connections made to it. Think of it like a temporary phone number that logs every call. He used it to see if the backend made outbound connections (for example, when the HTML contained an image tag pointing to his tunnel).
  • Burp Suite: A tool that lets you intercept and inspect the HTTP traffic between your browser and the website. It is like a wiretap for web requests.

He also registered a free FTP server at ftphosting.net. FTP (File Transfer Protocol) is an old method for transferring files between computers. He needed a server he controlled to receive files from the target.

Later, he downloaded the exact version of TCPDF that he identified from the PDF metadata, so he could reproduce the exploit locally on his own machine.

Finding it

He started by injecting various payloads (pieces of code or data designed to trigger a behaviour) into the HTML input. He searched online for ideas and reread a write-up by nahamsec about exploiting a similar function. Nothing worked.

The only HTML tag that produced a response to his TCP tunnel was the <img> tag. An HTML tag is a building block of a web page, like <img> for images. However, the fetch gave no hint about which software was generating the PDF.

While trying various HTML tags, he found that injecting a <link> tag pointing to an internal file such as /etc/passwd, along with some other tags, produced an error on the POST request. A POST request is a way for a browser to send data to a server, often used when submitting a form. The error did not contain much information, but it contained enough to keep going: it said TCPDF Error.

From the original on cirius.medium.com

A quick search revealed that TCPDF is a PHP library (a collection of code) used to create PDFs from HTML. PHP is a programming language commonly used for web servers. He looked for known CVEs (Common Vulnerabilities and Exposures, public identifiers for security flaws), but without knowing the version, he could not narrow down the options. He read the documentation to find any allowed HTML tag that could be leveraged against the backend, but TCPDF is reasonably secure on that front and did not allow any tag that would permit SSRF.

Exploitation

Step 1: Get the PDF and its metadata

He decided to look at what the generated PDF actually contains. In the bug found by nahamsec, the data came along with the PDF but was only visible in the metadata. Metadata is information about the file, like its author, creation date, or the software that made it. It is not usually shown when you open the file, but it is stored inside.

The website used one service to host PDFs and another service to display them. The PDFs shown in the frontend (the part of the website you see) were converted to JPG (an image format) before being displayed. The displaying service used the URL for the JPG format, but the hosting service response also contained a URL to the original PDF. The download URL for the PDF had yet another hostname (a different domain name) and did not let him download the file. He reused the authentication headers from the hosting service hostname on this one. Authentication headers are pieces of information (like a username and password, or a token) that a browser sends to prove who it is. They worked, and he got the PDF metadata in Burp Suite.

TCPDF embeds the version number in the metadata. A single search showed the version was very old, TCPDF 6.0.043, which is vulnerable to CVE-2017-6100.

Step 2: Understand the vulnerability

TCPDF versions before 6.2 were vulnerable to uploading the server's internal files to a remote FTP server. The exploit had been presented by Frans Rosen in his blog. But there was still a long way to go: his TCP tunnel was not working correctly with FTP, and the exploit as presented did not work.

Step 3: Fix the FTP problem

He got a free FTP server from ftphosting.net, which resolved the first problem. Since he was sure the bug existed, he kept going and downloaded the exact version of TCPDF to do all the steps manually as described in the blog.

Step 4: Work out why the payload failed

Doing the steps manually showed that the payload was not working because the injected payload is serialised. Serialisation is the process of converting an object (a complex data structure) into a string of text so it can be stored or sent. Simply editing the serialised payload to make the required changes rendered it useless. He generated a payload on his machine instead and passed that to the server, which extracted the passwd file from the target server to his FTP server as a proof of concept.

Root cause

The PDF generation used an outdated TCPDF instance (6.0.043). The version disclosure in the PDF metadata is what made the vulnerable component identifiable.

Impact

An attacker who can control the HTML that is rendered into a PDF could cause the backend to upload internal files, such as /etc/passwd, to an FTP server the attacker controls. In this case the proof of concept extracted the passwd file from the target server.

Fix

The report does not describe a fix that was applied.

Variants to test

  1. Inject a <link> tag pointing at an internal file such as /etc/passwd and watch for library-specific error text in the POST response. A positive result is an error naming the rendering library, which identifies the component to research.
  2. Inject an <img> tag pointing at a host you control and watch your listener. A positive result is an outbound fetch from the backend, confirming server-side rendering.
  3. Retrieve the generated PDF and inspect its metadata for a version string. A positive result is a version that maps to a known CVE for the renderer.
  4. If the PDF is served through several hostnames, replay the authentication headers from one hostname on another. A positive result is access to the original PDF or its metadata.
  5. For old TCPDF versions, generate the serialised payload locally against the exact version and submit it. A positive result is a file from the target server arriving on your FTP server.

Glossary

  • API: Application Programming Interface; a set of rules that allows one piece of software to talk to another.
  • Authentication headers: Information sent with a web request to prove the identity of the sender, such as a token or credentials.
  • Backend: The part of a website that runs on the server and is not visible to users.
  • Burp Suite: A tool for intercepting and inspecting web traffic between a browser and a server.
  • CVE: Common Vulnerabilities and Exposures; a public identifier for a known security flaw.
  • Exfiltration: The unauthorised transfer of data from a system.
  • FTP: File Transfer Protocol; a standard method for transferring files between computers.
  • Frontend: The part of a website that users see and interact with in their browser.
  • HTML: HyperText Markup Language; the code used to structure web pages.
  • HTTP: HyperText Transfer Protocol; the protocol used for communication between web browsers and servers.
  • JPG: A common image file format.
  • Metadata: Data that describes other data, such as the author or creation date of a file.
  • PHP: A programming language often used for server-side web development.
  • POST request: An HTTP method used to send data to a server, typically when submitting a form.
  • Proof of concept (PoC): A demonstration that a vulnerability can be exploited, often by performing a harmless action.
  • Serialisation: The process of converting a data structure into a string of text for storage or transmission.
  • SSRF: Server-Side Request Forgery; a vulnerability where an attacker can make a server perform requests on their behalf.
  • TCP tunnel: A service that forwards network connections to a local machine, often used to expose a local server to the internet.
  • TCPDF: A PHP library for generating PDF files from HTML.
  • URL: Uniform Resource Locator; the address of a resource on the internet.

More by Aditya Verma

View all

3 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.