Skip to content
SSRF Write-up Intermediate

Story about Escalation of HTML Injection to EC2 Instance credentials leak

Harsh Tandel Follow

Published on medium.com

So here in web app there was functionality for generating invoices.There was blacklist based filtering and input is allowed to limited numbers.There was company address textbox which allowed html attributes an has capacity of more character then any other fields.

Harsh Tandel, on 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

The target was a web application with an invoice generation feature. Users could fill in fields such as a company address textbox, select a data range, and generate an invoice, which could then be downloaded as a PDF. The company address field accepted HTML attributes and allowed more characters than any other field in the form. The application applied blacklist based filtering to its input, and input was allowed to a limited number of characters.

The researcher, Harsh Tandel (@H4r5h_T4nd37), describes how an HTML injection in that address field was escalated into a server-side request forgery that pulled EC2 instance credentials out of the AWS instance metadata service and rendered them into the generated invoice PDF.

Setup

The report does not describe any accounts, roles, tools or versions. The only precondition it makes explicit is the invoice generation feature itself: a form with a company address textbox that accepts HTML and is longer than the other fields, a data range selector, and a save action followed by invoice generation and download.

Finding it

The researcher first validated that the address field was injectable with a simple HTML payload:

HTML
<h1>TEST</h1><b>test</b>

After entering it, he selected a data range and generated the invoice. The payload executed in the invoice PDF, confirming HTML injection. That result is what motivated the escalation attempt.

Exploitation

Step 1: try the metadata endpoint directly

The escalation idea was to embed an iframe pointing at the AWS instance metadata service:

Text
http://[redacted]/latest/meta-data/

On clicking save, the request was blocked. On clicking save, the request was blocked, so the next problem was bypassing the filter.

Step 2: probe the filter with a redirect

He first tried to bypass the filter using redirection, but that ended in an error because the application was not following redirects. That redirect attempt ended in an error because the application was not following redirects.

Step 3: convert the address to decimal

He then turned to encoding, converting the IP address to its decimal form. [redacted] becomes 2852039166. The converted value passed the blacklist filter and the data saved successfully.

Step 4: confirm the SSRF

He generated the invoice and clicked download. The metadata page was printed in the address text box, so the SSRF was confirmed. The next attempt, aimed at the IAM credentials path:

Text
http://2852039166/latest/meta-data/iam/security-credentials

was blocked again. Being able to display the metadata index was not enough on its own.

Step 5: find a path that is not blocked

Reviewing the metadata output, he found the identity-credentials endpoint. He repeated the procedure against it and eventually reached:

Text
identity-credentials/ec2/security-credentials/ec2-instance

That path returned the EC2 instance access key, secret key and token.

Step 6: deliver the payload

The final URL was:

Text
http://2852039166/latest/meta-data/identity -credentials/ec2/security-credentials/ec2-instance

and the payload placed in the address field was:

HTML
<iframe src = “http://2852039166/latest/meta-data/identity -credentials/ec2/security-credentials/ec2-instance” width =“800” height = “800”></iframe>

He saved it successfully, generated the invoice and downloaded it. The EC2 credentials were leaked into the PDF.

Root cause

The address field accepted HTML and the value was carried into the generated invoice PDF, so injected markup was rendered rather than treated as text. The blacklist did not stop the attack: the decimal form of the metadata address passed the filter, and the server then fetched it. The redirect attempt failed because redirects were not followed. The report does not describe the server-side code, so the exact fetching component is not shown.

Impact

In this case, saving an invoice with a crafted company address made the server fetch the instance metadata service and render the response into the invoice PDF. In this case that exposed the EC2 instance access key, secret key and token. The researcher notes that he could have used the credentials to get into the EC2 instance, but that was outside the engagement scope, so he stopped there.

Fix

Variants to test

  1. Decimal, octal and hex forms of the metadata address. A positive result is the metadata index appearing in the generated document where the literal address was blocked.
  2. Other metadata paths that are not on the blacklist. Enumerate the metadata tree and try paths such as identity-credentials/ec2/security-credentials/ec2-instance when iam/security-credentials is filtered. A positive result is credentials or other sensitive values rendered into the output.
  3. Redirect based bypasses. The report says redirects were not followed here, but on another target a redirect from an allowed host to the metadata address is worth trying; a positive result is metadata content appearing after the redirect.
  4. HTML injection in any field that reaches a generated document. Try a simple <h1> and <b> payload as the researcher did, then check whether the markup renders in the PDF. A positive result is rendered markup rather than escaped text.
  5. Longer fields with weaker filtering. The company address field allowed more characters than the others; test fields with larger limits for the same injection, since length limits often correlate with weaker validation.

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. 9 min read.

What happened, in plain words

A security researcher found a way to make a website's invoice generator fetch secret cloud credentials and print them into a PDF invoice. He started with a simple test: he typed some HTML code into the company address field of an invoice form. When he generated the invoice, the code ran, which showed the field was not properly protected. He then tried to make the invoice generator fetch the AWS metadata service address. That address was blocked by a filter, so he wrote the same address in a different number format (decimal) to sneak past the filter. That worked, and the invoice PDF showed the metadata page. He then found a deeper path in the metadata that returned the cloud server's access keys, secret key and token. He put that path into an iframe (a small window that loads another web page) and saved it in the address field. When he downloaded the invoice, the credentials were printed in the PDF. He could have used those credentials to log into the cloud server, but that was outside the scope of the test, so he stopped.

Background: what is an invoice generator?

Many web apps let users create invoices. You fill in a form with your company details, pick a date range, and click a button to generate an invoice. The invoice is often available as a PDF file that you can download. In this case, the form had a field for the company address. That field accepted more characters than other fields and allowed HTML code to be typed in. The app tried to block dangerous input using a blacklist: a list of known bad words or patterns that it refuses to accept. The researcher's goal was to see if he could abuse that field to make the server do something it should not.

Step 1: Test for HTML injection

HTML injection is when a website displays user input as if it were part of the page's code, instead of showing it as plain text. If you type <h1>Hello</h1> and the page shows a big heading "Hello" instead of the literal text, the site is vulnerable. The researcher typed this simple payload into the company address field:

HTML
<h1>TEST</h1><b>test</b>

This code tells the browser to show "TEST" as a large heading and "test" in bold. He then selected a date range and generated the invoice. When he opened the PDF, the words appeared formatted (big and bold), which meant the HTML had been executed. That confirmed the field was injectable. This was the first clue that he could do more than just change text appearance.

Step 2: Try to reach the cloud metadata service

The researcher knew that many cloud servers (like Amazon EC2) have a special internal web address that only the server itself can access: http://[redacted]/latest/meta-data/. This address gives information about the server, including temporary security credentials. If an attacker can make the server fetch that address and show the result, they can steal those credentials. This type of attack is called Server-Side Request Forgery (SSRF): the attacker tricks the server into making a request to a destination of the attacker's choosing.

He tried to embed that address in an iframe, a piece of HTML that loads another web page inside the current one. The idea was that when the invoice PDF is generated, the server would fetch the metadata address and include it in the PDF. He used this URL:

Text
http://[redacted]/latest/meta-data/

But when he clicked save, the request was blocked. So he needed a way around the filter.

Step 3: Try a redirect (and why it failed)

One common bypass is to use a URL that redirects to the blocked address. For example, a URL on an allowed domain that sends a redirect response to http://[redacted]/. The researcher tried this, but it ended with an error. The reason: the application did not follow redirects. When the server received a redirect response, it simply stopped instead of following the new location. So that bypass did not work here.

Step 4: Convert the IP address to decimal

Every IP address can be written in different formats. The usual dotted-decimal form (like [redacted]) is just one way. You can also write it as a single decimal number. The researcher converted [redacted] to its decimal equivalent: 2852039166. This number represents the same address, but it looks completely different to a simple blacklist filter. He replaced the IP in the iframe URL with the decimal form, and the data saved successfully. The filter did not recognise 2852039166 as the blocked address.

Step 5: Confirm the SSRF

He generated the invoice and clicked download. The PDF now contained the metadata page printed in the address textbox. That proved the server had fetched the metadata address and included the response in the PDF. The SSRF was confirmed. However, the metadata index page alone is not very useful; he needed to reach the credentials. He then tried to access the IAM credentials path:

Text
http://2852039166/latest/meta-data/iam/security-credentials

But this was blocked again. But this was blocked again. So he could show the metadata index, but not the credentials directly.

Step 6: Find an unblocked path to credentials

He reviewed the metadata output and noticed an endpoint called identity-credentials. He repeated the same procedure (using the decimal IP and the iframe) but with this new path. Eventually he reached:

Text
identity-credentials/ec2/security-credentials/ec2-instance

This path returned the EC2 instance's access key, secret key and token. These are like a username and password for the cloud server, allowing programmatic access to AWS resources. The researcher had now found a way to get the credentials.

Step 7: Deliver the final payload

The final URL he used was:

Text
http://2852039166/latest/meta-data/identity -credentials/ec2/security-credentials/ec2-instance

Note the space before -credentials; that is exactly as it appears in the report. He placed this URL inside an iframe tag and put the whole thing in the company address field:

HTML
<iframe src = “http://2852039166/latest/meta-data/identity -credentials/ec2/security-credentials/ec2-instance” width =“800” height = “800”></iframe>

This HTML creates an iframe that loads the metadata URL. He saved the invoice, generated it, and downloaded the PDF. The PDF now contained the EC2 credentials: the access key, secret key and token were printed in the address textbox area.

Why it worked

The company address field allowed HTML, and that HTML was carried into the generated PDF without being escaped. Escaping means converting special characters like < and > into harmless codes so they appear as text instead of being interpreted as code. Because the HTML was not escaped, the iframe was rendered, and the server fetched the URL inside it. The blacklist filter was ineffective because the decimal equivalent 2852039166 and the identity-credentials path were not blocked. The redirect bypass failed because the server did not follow redirects, but that is a limitation of the fetcher, not a security control.

Impact

An attacker who can save an invoice with a crafted company address can make the server fetch the metadata service and leak the EC2 credentials into the PDF. With those credentials, the attacker could potentially access the EC2 instance. In this case, the researcher stopped because accessing the EC2 instance was outside the scope of the engagement. The report does not mention the bug bounty program, the bounty amount, or the severity rating.

Fix

The report does not describe any fix or remediation applied by the target.

Variants to test

If you are testing a similar application, here are some variations to try:

  1. Decimal, octal and hex forms of the metadata address. Try writing [redacted] as a decimal number (2852039166), as octal (e.g. 0250.0376.0250.0376), or as hexadecimal (e.g. 0xA9.0xFE.0xA9.0xFE). If the metadata index appears in the generated document where the literal address was blocked, the bypass worked.
  2. Other metadata paths that are not on the blacklist. Explore the metadata tree and try paths like identity-credentials/ec2/security-credentials/ec2-instance when iam/security-credentials is blocked. If credentials or other sensitive data appear in the output, you have found a leak.
  3. Redirect based bypasses. The report says redirects were not followed here, but on another target a redirect from an allowed host to the metadata address might work. If metadata content appears after the redirect, the bypass succeeded.
  4. HTML injection in any field that reaches a generated document. Try a simple <h1> and <b> payload as the researcher did, then check if the markup renders in the PDF. If you see formatted text instead of literal tags, the field is vulnerable.
  5. Longer fields with weaker filtering. The company address field allowed more characters than others; test fields with larger limits for the same injection, as length limits often correlate with weaker validation.

Glossary

  • HTML injection: A vulnerability where user input is interpreted as HTML code by the browser, allowing an attacker to insert and execute HTML elements.
  • SSRF (Server-Side Request Forgery): A vulnerability where an attacker can make a server send requests to arbitrary destinations, often to internal services not meant to be exposed.
  • AWS metadata service: A special web service available at http://[redacted]/ on Amazon EC2 instances that provides information about the instance, including temporary security credentials.
  • EC2 instance: A virtual server in Amazon's Elastic Compute Cloud (EC2).
  • Credentials: Information like access keys, secret keys, and tokens that prove identity and grant access to cloud resources.
  • Blacklist filter: A security measure that blocks input matching a list of known bad patterns or values.
  • Iframe: An HTML element that embeds another web page within the current page.
  • PDF: Portable Document Format, a file format for documents that can include text and images.
  • Decimal IP address: A way to represent an IPv4 address as a single integer, e.g. [redacted] becomes 2852039166.
  • Redirect: An HTTP response that tells the client to go to a different URL.
  • IAM: Identity and Access Management, AWS's service for managing access to resources.
  • Access key: A unique identifier for an AWS user or role, used with a secret key to sign programmatic requests.
  • Secret key: A secret value paired with an access key to authenticate requests.
  • Token: A temporary security credential, often used with temporary access keys.
  • Engagement scope: The agreed boundaries of a security test, specifying what systems and actions are allowed.
  • Bug bounty program: A program where organisations reward researchers for finding and reporting security vulnerabilities.
  • Severity: A rating of how serious a vulnerability is, often using scales like CVSS.
  • CVSS: Common Vulnerability Scoring System, a standard for rating the severity of security vulnerabilities.
  • Payload: The code or data an attacker sends to exploit a vulnerability.
  • Endpoint: A specific URL or path in a web application that performs a function or returns data.
  • Escaping: Converting special characters in user input into harmless representations so they are not interpreted as code.
  • Octal: A base-8 number system; in IP addresses, each octet can be written in octal (e.g. 0250 for 168).
  • Hexadecimal: A base-16 number system; in IP addresses, each octet can be written in hex (e.g. 0xA9 for 169).

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.