Skip to content
SSRF Write-up Intermediate

Finding SSRF via HTML Injection inside a PDF file on AWS EC2

A stored HTML injection in a user address field was rendered unsanitised in an HTML preview and then in a server-side PDF conversion, allowing an attacker to embed an iframe that made the server request internal resources. This was escalated to SSRF, retrieving AWS EC2 instance metadata and temporary IAM credentials.

blog.appsecco.com

Published on blog.appsecco.com

During a recent application vulnerability assessment we found a Stored HTML Injection vulnerability that was quickly escalated to a full Server Side Request forgery (SSRF) on a AWS EC2.

The author, on blog.appsecco.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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the application failed to output-encode user-supplied data in the HTML preview and PDF generation contexts, allowing HTML injection that the server-side PDF renderer executed as a request.

Impact

An attacker could retrieve temporary AWS credentials for the EC2 instance's IAM role, potentially leading to further access to AWS services depending on the role's privileges.

What the attacker needed

Ability to register a user and set address; server-side PDF generation from HTML; EC2 instance with an IAM role attached

The fix

The client added additional checks at the entry points to mitigate the vulnerability, and the text recommends upgrading to IMDSv2 to protect against vanilla SSRF attempts.

How it was found

  1. Create a new user in the application and set the address field to an iframe pointing at a controlled listener.
  2. Preview the report in HTML to see if the iframe is rendered.
  3. Download the PDF and observe a DNS and HTTP request from the application server to the listener.
  4. Replace the iframe source with the EC2 metadata credentials path to list the IAM role name.
  5. Use the role name in the metadata path to retrieve temporary AWS credentials.
  6. Configure the AWS CLI with the stolen credentials and enumerate permissions.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The application let users type their address, and that address was later shown on a web page and turned into a PDF by the server. Because the address was not cleaned, an attacker could put special HTML code in it that told the server to fetch a secret internal web address. That internal address belongs to the cloud provider and hands out temporary passwords for the server's cloud account.

What is SSRF?

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

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.