Skip to content
SSRF Write-up Beginner

A tale of my first ever full SSRF bug

A newsletter subscription endpoint accepted a URL parameter and fetched it server-side, allowing an attacker to reach the cloud instance metadata service. The attacker could read instance metadata and obtain temporary AWS credentials.

Jadek Mark Follow

Published on medium.com

Bounty$1,000 View original

{{media:0}}

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

Context

After a couple of weeks of fruitless probing at web applications on public programmes, the author took a break and came back with a fresh mind. The result was a Server Side Request Forgery (SSRF) vulnerability that gave unrestricted access to a programme's instance metadata environment and could have disclosed its AWS access keys. The programme was found through the HackerOne programme directory and is referred to here as redacted; the programme allowed the write-up on condition that the relevant details were redacted.

The target was the subdomain https://collate.redacted.com/, reached from the programme's policy page. At first glance nothing on it seemed particularly interesting, but scrolling to the bottom of the home page revealed a text box where a visitor could submit an email address to subscribe to the company's newsletter. That newsletter form is the feature that turned out to be vulnerable.

Setup

The work was done against a public programme on HackerOne. The only tooling described is Burp Suite, used to intercept the newsletter submission, and a Burp Collaborator client, used to confirm that the server made outbound requests. The author typed a personal email address into the form to generate the traffic. No accounts, roles or specific versions are described beyond the browser user agent that appears in the captured requests.

Finding it

The author had a hunch about what happened in the background during the email submission process, so they started Burp Suite, typed an email address into the text box and clicked submit. The captured request showed that the email was being routed through a proxy endpoint to an internal mailing list. The author could tell it was Mailchimp from the way the URL was structured.

The email address was submitted to the back end with the following POST request:

The interesting part is the url query parameter on /cloud-app/api/proxy-post, which carries a URL-encoded Mailchimp subscribe endpoint. The request also carries an Authorization: ApiKey header and a session cookie, both redacted here. Decoded, the URL parameter looked like this:

?url=https://redacted.eu11.list-manage.com/subscribe/post?u=65bd5a1857b73643aad556093

A proxy endpoint that takes a full URL from the client is a natural SSRF candidate, because the server is being told where to send a request on the user's behalf.

Exploitation

Step 1: Confirm the server makes outbound requests

The author modified the URL parameter in the captured request, replacing it with a payload from their Burp Collaborator client. The server made HTTP requests to the supplied Collaborator URL, confirming that the application was vulnerable to SSRF.

Step 2: Probe for further reach

The author then attempted some further internal service enumeration and tried to read local files, but had no luck with either. They also tried various protocols: gopher://, file://, ldap:// and ftp://. These were not supported, leaving http:// and https:// as the only two available options.

Step 3: Reach the cloud metadata service

The author pointed the URL parameter at the instance metadata address, requesting the user data document:

Note the change from a POST to a GET request. The response came back with Amazon EC2 instance metadata:

HTTP
HTTP/1.1 200 OK Date: Sun, 17 May 2020 06:59:20 GMT Content-Type: text/html; charset=utf-8 Content-Length: 66 Connection: close Set-Cookie: AWSALB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Expires=Sun, 24 May 2020 06:59:20 GMT; Path=/ Set-Cookie: AWSALBCORS=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Expires=Sun, 24 May 2020 06:59:20 GMT; Path=/; SameSite=None X-DNS-Prefetch-Control: off X-Frame-Options: SAMEORIGIN Strict-Transport-Security: max-age=15552000; includeSubDomains X-Download-Options: noopen X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block ETag: W/”42-TCtERKSIzlhv3bS2BY0KADPY5wI” Vary: Accept-Encoding #!/bin/bash echo ECS_CLUSTER=cloud-app >>/etc/ecs/ecs.config

The body is the EC2 user data script, which writes the ECS cluster name cloud-app into /etc/ecs/ecs.config. The response headers also show load balancer cookies (AWSALB, AWSALBCORS), consistent with the request being served through an AWS load balancer.

Step 4: Retrieve the instance role credentials

A quick look at Swissky's PayloadsAllTheThings repository allowed the author to go through some more AWS endpoints. The next request targeted the credentials of the instance role:

The response returned the temporary credentials for the ecsInstanceRole role:

The JSON body contains an AccessKeyId, a SecretAccessKey, a session Token and an Expiration timestamp, the standard shape of temporary STS credentials issued to an instance role. With those in hand, it was time to write up and submit a report.

Root cause

The /cloud-app/api/proxy-post endpoint accepts a full URL in the url parameter and makes a server-side request to it. The newsletter form only ever needs to reach the Mailchimp subscribe endpoint, but the endpoint applied no restriction on the destination host, so any address reachable from the instance, including the link-local metadata address [redacted], could be requested. The only restriction observed was on the scheme: gopher://, file://, ldap:// and ftp:// were rejected, leaving http:// and https://. That is enough to reach the metadata service, which speaks HTTP. The report does not describe any allowlist, egress filtering or metadata hardening (such as IMDSv2) that would have stopped the request.

Impact

Through the proxy endpoint an attacker could reach the instance metadata environment without restriction. In this case that disclosed the EC2 user data and, more seriously, the temporary AWS credentials of the ecsInstanceRole instance role, which could have given an attacker access to the programme's AWS environment for the lifetime of those credentials. The author notes the bug could have disclosed the programme's AWS access keys to an attacker.

Fix

The programme's engineers disabled the feature a few hours after the report was submitted. The report does not describe the code change itself.

Variants to test

  1. Proxy or fetch parameters on other targets. Look for parameters that carry a full URL, such as url=, dest=, redirect=, image=, webhook= or feed=, in forms, PDF generators, avatar importers and link previews. A positive result is a request arriving at your Collaborator host when you substitute your own URL.
  2. Metadata endpoints over HTTP. Point the parameter at http://[redacted]/latest/user-data and then at http://[redacted]/latest/meta-data/iam/security-credentials/ followed by the role name. A positive result is a user data script or a JSON body containing AccessKeyId, SecretAccessKey and Token.
  3. Scheme handling. Try gopher://, file://, ldap:// and ftp:// as well as http:// and https://. A positive result is any scheme the server accepts beyond the two HTTP schemes, since file:// can expose local files and gopher:// can be used to craft arbitrary TCP payloads.
  4. Redirect-based bypasses. If a host allowlist is present, host a URL on your own server that redirects to the metadata address and submit that instead. A positive result is the redirect being followed to the internal address.
  5. Internal service enumeration. Once outbound requests are confirmed, vary the host and port to map internal services. A positive result is a response that differs from the baseline error, indicating a reachable service.

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

What happened, in plain words

A security researcher spent a couple of weeks poking at web applications on public bug bounty programmes without finding anything. He took a break, came back with a fresh mind, and found a serious flaw in a newsletter sign-up box. The flaw let him make the company's own server fetch any web address he chose, including a special internal address that cloud servers use to hand out their own credentials. That could have exposed the company's Amazon Web Services (AWS) access keys. He reported it, the company switched the feature off within hours, and he was paid a $1,000 bounty.

This article walks through the whole thing from the beginning, assuming you have never done security testing before. You only need to know how to use a browser.

Mase
Mase From the original on medium.com

The background you need first

A few ideas come up again and again below, so here they are in plain words.

Bug bounty programme. A company publishes a page saying "if you find a security problem in our systems, tell us and we may pay you". Researchers look through a directory of these programmes (the author used the HackerOne programme directory) and pick a target. The company in this story is called "redacted" throughout, because the programme only allowed the write-up if the identifying details were removed.

Subdomain. A smaller site that belongs to a bigger one. If the main site is example.com, then shop.example.com and collate.example.com are subdomains. Here the target was https://collate.redacted.com/, found by reading the programme's policy page.

API. Short for Application Programming Interface. It is the part of a website that a program talks to, rather than a person clicking buttons. When you fill in a form, your browser sends a request to an API address behind the scenes, and the API does the actual work. Think of a restaurant: the dining room is the website you see, the kitchen is the API, and the waiter carries your order between them.

Endpoint. One specific address inside an API, like one particular counter at the restaurant. /cloud-app/api/proxy-post is an endpoint.

HTTP request and response. When your browser asks a website for something, it sends a request: a method (such as GET, meaning "give me this", or POST, meaning "here is some data, please process it"), a path, some headers (extra information), and sometimes a body (the data itself). The server answers with a response: a status code (200 means OK), headers, and a body.

Header. A labelled line of extra information attached to a request or response, such as Content-Type (what kind of data this is) or Cookie (see below).

Cookie. A small piece of data a website stores in your browser so it can recognise you on your next request. It is how a site knows you are still logged in. If someone steals your cookie, they can often act as you.

API key / token. A long random string that acts like a password for a program rather than a person. The request below carries an Authorization: ApiKey ... header, which is the application proving to the back end that it is allowed to call it.

Proxy. A middleman. Instead of your browser talking directly to a destination, it asks a proxy to fetch the destination on its behalf. Companies use proxies so that one central service can make outbound requests for them.

Server-Side Request Forgery (SSRF). The vulnerability class in this story. Normally, when you type a web address into a form, your own browser fetches it. In SSRF, the website takes an address from you and its own server fetches it. That matters because the server sits inside the company's private network, where it can reach things you cannot: internal machines, internal admin pages, and cloud metadata (below). The everyday comparison: a hotel concierge who will fetch anything you ask for. Ask for a newspaper from the shop and that is fine. Ask him to open the staff room door and hand you the safe key, and you have a problem.

Cloud instance and metadata. A cloud server (an "instance") is a rented computer running in a data centre. AWS gives each instance a special internal address, [redacted], that only the instance itself can reach. Ask that address questions and it answers with facts about the instance, including, if the instance has a role attached, temporary access keys for the company's AWS account. It is like a staff noticeboard inside the building that lists the keys to every door.

Burp Suite and Burp Collaborator. Burp Suite is a tool that sits between your browser and a website and lets you read and edit every request before it is sent. Collaborator is a companion feature: it gives you a unique web address that nobody else uses, and tells you if anything ever contacts it. If you put that address into a form and Collaborator reports a hit, you know the server, not your browser, made the request.

Finding the form

The author opened the target subdomain and looked around for anything worth testing. At first glance nothing stood out. Then, scrolling to the bottom of the home page, there was a text box where a visitor could type an email address to subscribe to the company's newsletter.

That is the feature that turned out to be vulnerable. The reasoning for looking at it: a newsletter box is a small, boring feature, and boring features are often built quickly and tested lightly. More importantly, a newsletter box has to send data somewhere, and the author wanted to know exactly how.

Capturing the request

To see what happens behind the scenes, the author started Burp Suite, typed an email address into the box and clicked submit. Burp caught the request before it left the browser.

What the request showed was that the email was not sent straight to the mailing list. It was routed through a proxy endpoint on the company's own server, which then forwarded it to an internal mailing list. The author could tell the mailing list was Mailchimp from the shape of the URL.

Here is the captured request:

Line by line, in plain words:

  • POST /cloud-app/api/proxy-post?url=... is the method, the endpoint and the query string. The method is POST because data is being submitted. The endpoint is the proxy. The query string is everything after the ?, and it contains one parameter called url whose value is a long encoded web address.
  • HTTP/1.1 is the version of the web protocol being spoken.
  • Host: collate.redacted.com says which site the request is for.
  • Content-Length: 108 says the body is 108 bytes long.
  • Authorization: ApiKey ... is the application proving to the back end that it is allowed to call it. The key shown here is a placeholder, not a real secret.
  • User-Agent: ... identifies the browser that made the request.
  • Content-Type: application/x-www-form-urlencoded says the body is formatted like a form submission.
  • Accept, Origin, Referer, Accept-Encoding, Accept-Language are housekeeping headers: what response formats are acceptable, which page the request came from, and what language and compression the browser prefers.
  • Cookie: ... is the session cookie, redacted here. It is what would let the server recognise the visitor.
  • Connection: close asks the server to close the connection after answering.
  • The last line is the body: a form field named after the Mailchimp list, left empty, and EMAIL=[redacted], the address being subscribed.

The part that matters is the url parameter. The server is being handed a full web address and told to fetch it. That is exactly the shape of an SSRF candidate, because the server is being told where to send a request on the user's behalf.

Decoded, the URL parameter looked like this:

?url=https://redacted.eu11.list-manage.com/subscribe/post?u=65bd5a1857b73643aad556093

The %3A, %2F and similar sequences are percent-encoding: a way of writing characters that would otherwise confuse the URL parser. %3A is a colon, %2F is a slash. Decoding turns the unreadable string back into an ordinary web address, and now you can see it points at a Mailchimp subscribe page.

Step 1: Confirming the server makes requests

The author replaced the url value with an address from their Burp Collaborator client and sent the request again. The server made HTTP requests to that Collaborator address. Since nobody else knew that address, the only way it could have been contacted is if the company's server did it. That confirmed the application was vulnerable to SSRF.

Why this step first: before going further, you want proof that the server, and not your browser, is doing the fetching. Collaborator gives you that proof cleanly.

Step 2: Seeing how far the server can reach

Next the author tried to use the same trick to list internal services and to read files on the server itself. Neither worked. They also tried other protocols: gopher://, file://, ldap:// and ftp://. These were not supported. Only http:// and https:// were accepted.

Why this matters: different protocols open different doors. file:// would read files on the server's own disk, and gopher:// can be abused to send hand-crafted data to other services. Being limited to the two web protocols narrows what is possible, but it is not a dead end, because the cloud metadata service speaks HTTP.

Step 3: Reaching the cloud metadata service

The author pointed the url parameter at the instance metadata address and asked for the user data document:

What changed and why:

  • The method is now GET instead of POST. The author was no longer submitting a form, just asking the server to fetch a page, so GET is the natural choice. The report notes the change explicitly.
  • The url value now decodes to http://[redacted]/latest/user-data. That address is the cloud metadata service, and /latest/user-data is the startup script the instance was given when it was created.
  • Everything else, including the Authorization header and the cookie, is the same as before.

The response came back with Amazon EC2 instance metadata:

HTTP
HTTP/1.1 200 OK Date: Sun, 17 May 2020 06:59:20 GMT Content-Type: text/html; charset=utf-8 Content-Length: 66 Connection: close Set-Cookie: AWSALB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Expires=Sun, 24 May 2020 06:59:20 GMT; Path=/ Set-Cookie: AWSALBCORS=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; Expires=Sun, 24 May 2020 06:59:20 GMT; Path=/; SameSite=None X-DNS-Prefetch-Control: off X-Frame-Options: SAMEORIGIN Strict-Transport-Security: max-age=15552000; includeSubDomains X-Download-Options: noopen X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block ETag: W/”42-TCtERKSIzlhv3bS2BY0KADPY5wI” Vary: Accept-Encoding #!/bin/bash echo ECS_CLUSTER=cloud-app >>/etc/ecs/ecs.config

Reading it line by line:

  • HTTP/1.1 200 OK means the request succeeded.
  • Date is when the response was produced.
  • Content-Type: text/html; charset=utf-8 says the body is text.
  • Content-Length: 66 says the body is 66 bytes.
  • Connection: close means the connection will be closed after this response.
  • The two Set-Cookie lines set AWSALB and AWSALBCORS. These are cookies placed by an AWS load balancer, which is the piece of equipment that spreads incoming traffic across several servers. Seeing them tells you the request was served through AWS.
  • X-DNS-Prefetch-Control, X-Frame-Options, Strict-Transport-Security, X-Download-Options, X-Content-Type-Options, X-XSS-Protection are security-related response headers. They are ordinary hardening settings, not part of the bug.
  • ETag is a fingerprint of this version of the content, used for caching.
  • Vary: Accept-Encoding tells caches that the response depends on the compression the client asked for.
  • The last line is the body: a small shell script that appends ECS_CLUSTER=cloud-app to a configuration file. That is the instance's startup script, and it reveals the name of the cluster the server belongs to.

At this point the author had proven that the proxy could reach the internal metadata service. That alone is a finding, but the metadata service holds something more valuable.

Step 4: Retrieving the instance role credentials

A quick look at Swissky's PayloadsAllTheThings repository, a public collection of known attack payloads, gave the author more AWS metadata addresses to try. The next request targeted the credentials of the instance role:

What is different: only the url value. Decoded, it is http://[redacted]/latest/meta-data/iam/security-credentials/ecsInstanceRole. The path asks the metadata service for the security credentials attached to a role called ecsInstanceRole. A role is a set of permissions that a cloud server is allowed to use, and the metadata service will hand out temporary keys for that role to anyone who asks from inside the instance.

The response returned those temporary credentials:

Line by line:

  • The status line and headers are the same kind as before: success, a date, a content type, load balancer cookies, security headers, an ETag, and a content length of 1310 bytes.
  • The body is JSON, a text format for structured data. It contains Code: Success, meaning the metadata service answered.
  • LastUpdated is when the credentials were issued.
  • Type: AWS-HMAC describes the kind of credentials.
  • AccessKeyId, SecretAccessKey and Token are the three pieces of a temporary AWS credential. Together they let a program act as the role. They are redacted here.
  • Expiration is when they stop working.

With those in hand, the author had everything needed to write up and submit a report.

Why it worked

The /cloud-app/api/proxy-post endpoint takes a full web address in the url parameter and fetches it from the server. The newsletter form only ever needs to reach the Mailchimp subscribe page, but the endpoint put no restriction on which host could be requested. So any address the server could reach, including the internal metadata address [redacted], could be requested. The only restriction the author observed was on the protocol: gopher://, file://, ldap:// and ftp:// were rejected, leaving http:// and https://. That is enough, because the metadata service speaks HTTP. The report does not describe any allowlist, outbound traffic filtering or metadata hardening that would have stopped the request.

What the impact was

Through the proxy endpoint, an attacker could reach the instance metadata environment without restriction. In this case that exposed the startup script and, more seriously, the temporary AWS credentials of the ecsInstanceRole role. Those credentials could have given an attacker access to the programme's AWS environment for as long as they remained valid. The author notes the bug could have disclosed the programme's AWS access keys.

The fix and the timeline

The programme's engineers disabled the feature a few hours after the report was submitted. The report does not describe the code change itself.

The author was rewarded with a $1,000 bounty over the course of the next months.

Timeline:

  • May 17, 2020: reported.
  • May 18, 2020: triaged.
  • May 18, 2020: feature disabled.
  • June 11, 2020: bounty awarded.

The author adds that the issue was found on a non-paying programme, but because of its severity the programme decided to reward the finding anyway.

Things to try on other targets

If you want to look for the same class of bug yourself, these are the variations worth testing. Each one names what a positive result looks like, so you know when you have found something.

  1. Proxy or fetch parameters on other targets. Look for parameters that carry a full web address, such as url=, dest=, redirect=, image=, webhook= or feed=, in forms, PDF generators, avatar importers and link previews. A positive result is a request arriving at your Collaborator address when you substitute your own URL.
  2. Metadata endpoints over HTTP. Point the parameter at http://[redacted]/latest/user-data and then at http://[redacted]/latest/meta-data/iam/security-credentials/ followed by the role name. A positive result is a startup script or a JSON body containing AccessKeyId, SecretAccessKey and Token.
  3. Protocol handling. Try gopher://, file://, ldap:// and ftp:// as well as http:// and https://. A positive result is any protocol the server accepts beyond the two web ones, since file:// can expose local files and gopher:// can be used to send hand-crafted data to other services.
  4. Redirect-based bypasses. If a host allowlist is in place, host a URL on your own server that redirects to the metadata address and submit that instead. A positive result is the redirect being followed to the internal address.
  5. Internal service enumeration. Once outbound requests are confirmed, vary the host and port to map internal services. A positive result is a response that differs from the baseline error, indicating a reachable service.

Glossary

  • API: the part of a website that programs talk to, rather than people clicking buttons.
  • API key: a long random string that acts like a password for a program.
  • AWS: Amazon Web Services, a cloud provider that rents out servers and storage.
  • AWSALB / AWSALBCORS: cookies set by an AWS load balancer to keep a visitor on the same server.
  • Body: the data part of an HTTP request or response.
  • Bug bounty programme: a scheme where a company pays researchers who report security problems to it.
  • Burp Collaborator: a feature that gives you a unique web address and tells you if anything contacts it.
  • Burp Suite: a tool that sits between your browser and a website so you can read and edit requests.
  • Cloud instance: a rented computer running in a data centre.
  • Cookie: a small piece of data a site stores in your browser so it can recognise you later.
  • EC2: Amazon's service for running cloud instances.
  • ECS: Amazon's service for running containers, small packaged applications, across a cluster of servers.
  • Endpoint: one specific address inside an API.
  • ETag: a fingerprint of a particular version of content, used for caching.
  • GET: an HTTP method meaning "give me this".
  • Header: a labelled line of extra information attached to a request or response.
  • HTTP / HTTPS: the protocol browsers and servers use to talk; HTTPS is the encrypted version.
  • Instance metadata: facts a cloud server can ask about itself at the internal address [redacted], including temporary credentials.
  • Instance role: a set of permissions attached to a cloud server, whose temporary keys the metadata service will hand out.
  • JSON: a text format for structured data.
  • Load balancer: equipment that spreads incoming traffic across several servers.
  • Mailchimp: a service companies use to run mailing lists and newsletters.
  • Metadata service: the internal address [redacted] that answers questions about the cloud instance.
  • Method: the verb of an HTTP request, such as GET or POST.
  • Percent-encoding: writing characters in a URL as % followed by a code, so they do not confuse the parser.
  • POST: an HTTP method meaning "here is some data, please process it".
  • Protocol: the agreed language two computers use to communicate, such as http:// or ftp://.
  • Proxy: a middleman that fetches something on someone else's behalf.
  • Query string: the part of a URL after the ?, carrying parameters.
  • Response: what a server sends back after a request.
  • Role: see instance role.
  • Server-Side Request Forgery (SSRF): a flaw where a website takes a web address from a user and its own server fetches it, letting the user reach internal systems.
  • Session cookie: a cookie that identifies your logged-in session.
  • Status code: the number at the start of a response saying how it went, such as 200 for OK.
  • Subdomain: a smaller site belonging to a bigger one, such as collate.example.com under example.com.
  • Temporary credentials: short-lived keys issued by a cloud provider, valid only until an expiry time.
  • Token: a string that proves identity or permission, often short-lived.
  • Triaged: reviewed and accepted as a valid report by the programme.
  • User data: the startup script a cloud instance is given when it is created.
  • User-Agent: a header identifying the browser or program making a request.
  • Vulnerability: a weakness in software that someone can abuse to do something the owner did not intend.

More by Jadek Mark

View all

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