Skip to content
SSRF Write-up Intermediate

A story of a nice SSRF vulnerability.

oXnoOneXo Follow

Published on medium.com

Bounty$500 View original

Hello friend, I’ll talk about a SSRF vulnerability i got with my friend Ahmed Elmorsi in a private bug bounty program. I’ll have a quick introduction about SSRF itself from OWASP:

oXnoOneXo, 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. 6 min read.

Context

This is a server-side request forgery (SSRF) finding that I got together with my friend Ahmed Elmorsi in a private bug bounty program. The product was, in the program's own description, a cloud banking platform that enables banking providers to rapidly create, launch and service loan and deposit products.

The subdomain we tested had two permission levels, Admin and User. While looking at the differences between those two roles we found two further vulnerabilities in the privilege handling, but the feature that interested us most was Process. A process lets a user define a task, or a set of tasks, that are executed once a condition the user specifies is met, for example doing something after x is equal to y, and so on.

One of the available task types was called API Call. As the name suggests, it makes an outbound HTTP request on the server's behalf, and that is exactly the kind of functionality that is worth testing for SSRF. Once the task is added to a process, the user can specify the Host and the method.

From the original on medium.com

For background, the OWASP description of SSRF that I quoted at the time frames the class of bug well: it abuses an application to interact with the internal or external network, or the machine itself, and one of the enablers is mishandling of URLs. Typical examples are an avatar image fetched from a user-supplied URL, a custom webhook whose callback URL the user provides, and internal requests made to another service to serve a specific functionality, where user data is sent along to be processed and, if poorly handled, can lead to injection attacks.

Setup

  • A private bug bounty program, so no public target details beyond the product description above.
  • An account on the subdomain under test, with the Admin and User permission levels available to compare.
  • The Process feature with the API Call task, which lets us choose the Host and the HTTP method, and later turned out to let us add custom headers.
  • Tools used during the attempts: IPFuscator for IP obfuscation, http://nicob.net/redir6a for a redirect to [redacted], IPv6 representations, and the DNS rebinding service at https://lock.cmpxchg8b.com/rebinder.html.

Finding it

The API Call task is a server-side HTTP client driven by user input: the user picks the host and the method. That is a direct SSRF primitive, so the first thing we tried was the AWS instance metadata address.

Exploitation

Step 1: direct request to the metadata service

We configured the task with the GET method and the host http://[redacted] to read the AWS instance metadata. The response was a 403.

a disappointing response From the original on medium.com

A disappointing response.

Step 2: bypass attempts

We tried several bypasses, none of which worked:

  1. IP obfuscation with IPFuscator.
  2. A redirect to [redacted] using http://nicob.net/redir6a.
  3. IPv6 representations of the address.

Step 3: DNS rebinding

We remembered DNS rebinding and its online tool at https://lock.cmpxchg8b.com/rebinder.html. A DNS rebinding attack manipulates name resolution so that the same domain name resolves between two IPs within a short time, governed by the TTL (time-to-live).

We put a Google IP and [redacted] into the rebinder tool and got back a domain name that would resolve between the two IPs. We used that domain in the API Call task and, after multiple tries, got our first different response.

From the original on medium.com

We did not understand why we were getting the 401, but the response header server: EC2ws was an indication that we had hit the internal AWS instance. We reported it as a blind SSRF and the team rejected it.

It ain’t the end yet. From the original on medium.com

It ain't the end yet.

Step 4: IMDSv2 token request

We went back to the team and, after 3 days, worked out from the AWS documentation at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html that a token has to be requested first by adding the header:

HTTP
X-aws-ec2-metadata-token-ttl-seconds: 21600

The returned token is then sent with the header:

HTTP
X-aws-ec2-metadata-token: TOKEN

The API Call task allowed us to add custom headers, thankfully.

From the original on medium.com

Step 5: token retrieval through the rebinding domain

We sent the new header against the domain name from the rebinder and, after some tries, got our saviour response.

From the original on medium.com

Step 6: using the token

We then used the returned token with the X-aws-ec2-metadata-token header.

TA DA From the original on medium.com

TA DA.

We finally did it after trying for 3 days.

Step 7: the report and the response

We updated the report with the final findings and detailed steps to reproduce the same results we got. Here is the team's response after 3 days of discussing the vulnerability.

I hate my life From the original on medium.com

I hate my life.

After arguing more with the team, they decided to reward us with 500 USD for the confusion and the troubles.

Root cause

The API Call task takes the host and method from user-controlled process configuration and performs the request from the server, with no restriction that keeps it away from internal addresses. The metadata endpoint at [redacted] answered the direct request with a 403, but a hostname that resolves to that address was not blocked. DNS rebinding worked because the same domain name can resolve between two IPs within a short time, governed by the TTL. The task also accepts custom headers, which is what made the IMDSv2 flow possible: the token request and the token-authenticated request could both be issued through the same feature.

Impact

Through the API Call task an authenticated user could make the server issue requests to the internal AWS instance metadata service and obtain an IMDSv2 token. The report does not enumerate which metadata fields were retrieved or what could be done with them beyond that. The finding was initially rejected as a blind SSRF; after the report was updated with reproduction steps and more arguing, the team rewarded them with 500 USD.

Fix

The report does not describe any fix that was applied. What the finding calls for is restricting the API Call task so that it cannot reach internal addresses: resolve the host and validate the resolved address at connection time rather than validating the hostname string, block link-local and other internal ranges, and do not let user-supplied custom headers drive requests to internal services.

Variants to test

  1. Any user-configurable outbound request feature. Webhook handlers, URL importers, avatar fetchers, integration callbacks. A positive result is a response from an internal address, or a distinguishable error or timing difference when pointing at one.
  2. Literal-address blocks. If [redacted] is refused, try IP obfuscation, redirects and IPv6 forms as we did. A positive result is any of them returning content instead of the block.
  3. DNS rebinding against hostname-based filters. Point a rebinding domain at an internal address and a public one. A positive result is an internal response, or an internal-looking header such as server: EC2ws, arriving through the rebinding name.
  4. Custom header support in the request feature. If the feature lets you set headers, try the IMDSv2 token request with X-aws-ec2-metadata-token-ttl-seconds: 21600 and then reuse the token with X-aws-ec2-metadata-token. A positive result is a token in the first response and metadata in the second.
  5. Blind SSRF that looks rejected. A 401 or an error is not proof the request did not reach the internal host; check response headers and timing before accepting a rejection.

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

What happened, in plain words

Two researchers, oXnoOneXo and Ahmed Elmorsi (@0Xhunterx), were testing a private bug bounty program. A bug bounty program is an arrangement where a company invites outside testers to look for security problems in its systems and pays them for the ones they find. "Private" means the program is not open to everyone: only invited testers can take part, and the details of the target are not public.

The product they were testing is described by the program itself as a cloud banking platform that lets banking providers quickly create, launch and run loan and deposit products. "Cloud" here just means the software runs on someone else's servers, reachable over the internet, rather than on a machine in the company's own building.

The subdomain they tested had two permission levels, Admin and User. A subdomain is one part of a larger website: if the main site is example.com, then app.example.com is a subdomain of it. While comparing what an Admin can do and what a User can do, they found two more vulnerabilities in how those permissions were handled. But the feature that interested them most was called Process.

A Process lets a user define a task, or a set of tasks, that run automatically once a condition the user sets is met. For example: do something after x is equal to y, and so on. Think of it like a rule you set up in an email app: "when a message from this person arrives, move it to this folder". The user describes the trigger and the action, and the software carries it out later without anyone watching.

One of the available task types was called API Call. An API (Application Programming Interface) is a way for one piece of software to talk to another over the network: one program sends a request, the other sends back a response. When a website shows you the weather, it is usually asking a weather service's API for the data. An API Call task, as the name suggests, makes the server send such a request on the user's behalf. That is exactly the kind of functionality worth testing for SSRF, because the user gets to influence where the server sends its request.

SSRF stands for Server-Side Request Forgery. It means tricking a server into making a request the attacker chooses, usually to somewhere the attacker could not reach directly. A simple comparison: imagine a receptionist who will phone any number you give them. You cannot walk into the building's private back office, but the receptionist can, and if you ask them to call the back office and read out what they hear, you have reached it through them. The server is the receptionist, and the attacker supplies the phone number.

For background, the OWASP description of SSRF that the researchers quoted frames the class of bug well. OWASP is a well-known non-profit that publishes guidance on web security. Its description says SSRF abuses an application to interact with the internal or external network, or the machine itself, and that one of the enablers is mishandling of URLs. Typical examples are:

  1. An avatar image fetched from a URL the user supplies, so the application downloads and uses it.
  2. A custom webhook, where users have to specify webhook handlers or callback URLs. A webhook is an automatic message one system sends to another when something happens; the callback URL is the address it sends to.
  3. Internal requests made to another service to serve a specific functionality. Most of the time user data is sent along to be processed, and if it is poorly handled this can lead to specific injection attacks.

Once the API Call task is added to a process, the user can specify the Host and the method. The "Host" is the address the request goes to, and the "method" is the type of request. The most common method is GET, which means "give me this thing"; it is what your browser uses when you open a page.

From the original on medium.com

The setup

To repeat this kind of test you would need:

  • A private bug bounty program, so no public target details beyond the product description above.
  • An account on the subdomain under test, with the Admin and User permission levels available to compare.
  • The Process feature with the API Call task, which lets you choose the Host and the HTTP method, and later turned out to let you add custom headers. A header is a small piece of extra information attached to a request or a response, like the label on a parcel that tells the postal service how to handle it.
  • Tools used during the attempts: IPFuscator for IP obfuscation, http://nicob.net/redir6a for a redirect to [redacted], IPv6 representations, and the DNS rebinding service at https://lock.cmpxchg8b.com/rebinder.html. Each of these is explained where it first comes up below.

Finding it

The API Call task is essentially a server-side HTTP client driven by user input: the user picks the host and the method, and the server makes the request. That is a direct SSRF primitive, meaning the feature itself gives an attacker the ability to choose where the server connects. So the first thing the researchers tried was the AWS instance metadata address.

AWS is Amazon Web Services, a large cloud provider. When you rent a virtual machine from AWS (an "instance"), that machine has a special internal address, [redacted], which serves information about the instance itself: its identity, its configuration, and sometimes credentials. This is called the instance metadata service. The address is "link-local", meaning it is only reachable from inside that machine's own network, not from the internet. If an attacker can make a server fetch from that address, they can often read secrets that belong to the server.

Exploitation

Step 1: a direct request to the metadata service

The researchers configured the task with the GET method and the host http://[redacted] to read the AWS instance metadata. The response was a 403. An HTTP status code is a number the server sends back to say how the request went: 200 usually means success, 404 means not found, and 403 means forbidden, that is, the server understood the request but refused to carry it out.

a disappointing response From the original on medium.com

A disappointing response.

Step 2: bypass attempts

A block on one exact address is easy to work around in principle, so the researchers tried several bypasses. None of them worked:

  1. IP obfuscation with IPFuscator. An IP address is the numeric address of a machine on a network, like a postal address for computers. The same address can be written in several equivalent ways, for example as a single large number or in different notations, and a filter that only checks for the familiar dotted form can be fooled by another form that still points to the same machine. IPFuscator generates those alternative forms.
  2. A redirect to [redacted] using http://nicob.net/redir6a. A redirect is when one web address answers by telling the client "go to this other address instead". If a filter checks the address the user typed but not where it ends up, a redirect can slip past it.
  3. IPv6 representations of the address. IPv6 is a newer version of the internet addressing system with much longer addresses. The same machine can have an IPv6 form of its address, and a filter written only for the older IPv4 format may not recognise it.

Step 3: DNS rebinding

They then remembered DNS rebinding and its online tool at https://lock.cmpxchg8b.com/rebinder.html.

To understand this, start with DNS. The Domain Name System is the internet's phone book: it translates a name people can read, like example.com, into the numeric IP address of a machine. When your browser visits a site, it asks DNS for the address first. Each answer comes with a TTL, time-to-live, which says how long the answer may be kept before asking again. A short TTL means the answer can change quickly.

A DNS rebinding attack manipulates name resolution so that the same domain name resolves between two IPs within a short time, governed by the TTL. The trick works like this: a security check may look up the name once and see a harmless public address, then the actual connection looks the name up again a moment later and gets an internal address. The check and the connection disagree, and the internal address is reached.

The researchers put a Google IP and [redacted] into the rebinder tool and got back a domain name that would resolve between the two IPs. They used that domain in the API Call task and, after multiple tries, got their first different response.

From the original on medium.com

They did not understand why they were getting a 401. A 401 means unauthorized: the server is saying "I do not know who you are, or you have not proved it". But the response header server: EC2ws was an indication that they had hit the internal AWS instance. A response header is extra information the server attaches to its answer; server names the software that produced it. Seeing an AWS-specific value there meant the request had reached the internal service even though the answer was an error.

They reported it as a blind SSRF and the team rejected it. "Blind" means the attacker cannot see the response content, only side effects such as timing or status codes. The team did not accept that as a finding.

It ain’t the end yet. From the original on medium.com

It ain't the end yet.

Step 4: requesting an IMDSv2 token

AWS changed its metadata service some years ago to defend against exactly this kind of attack. The older version, IMDSv1, answered anyone who asked. The newer version, IMDSv2, requires the client to first request a token and then present that token with the real request. A token is a short-lived piece of text that proves you were allowed to ask; think of a cloakroom ticket: you hand over your coat, get a ticket, and the ticket is what gets the coat back. Without the ticket, no coat.

The researchers went back to the team and, after 3 days, worked out from the AWS documentation at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html that a token has to be requested first by adding the header:

HTTP
X-aws-ec2-metadata-token-ttl-seconds: 21600

Line by line: X-aws-ec2-metadata-token-ttl-seconds is the name of the header. The X- prefix is a convention for custom headers that are not part of the core HTTP standard. The rest of the name says what it controls: the time-to-live, in seconds, of the token being requested. 21600 is the value, which is six hours. Sending this header to the metadata service asks it to issue a token valid for that long.

The returned token is then sent with the header:

HTTP
X-aws-ec2-metadata-token: TOKEN

Here X-aws-ec2-metadata-token is the header name and TOKEN is a placeholder for the actual string the service returned in the previous step. You put the real value there. This second request is the one that actually reads metadata, and it is only answered if the token is valid.

The API Call task allowed them to add custom headers, thankfully.

From the original on medium.com

Step 5: getting the token through the rebinding domain

They sent the new header against the domain name from the rebinder and, after some tries, got their saviour response.

From the original on medium.com

Step 6: using the token

They then used the returned token with the X-aws-ec2-metadata-token header.

TA DA From the original on medium.com

TA DA.

They finally did it after trying for 3 days.

Step 7: the report and the response

They updated the report with the final findings and detailed steps to reproduce the same results they got. Here is the team's response after 3 days of discussing the vulnerability.

I hate my life From the original on medium.com

I hate my life.

After arguing more with the team, they decided to reward them with 500 USD for the confusion and the troubles.

Why it worked

The API Call task takes the host and method from user-controlled process configuration and performs the request from the server, with no restriction that keeps it away from internal addresses. The metadata endpoint at [redacted] answered the direct request with a 403, but a hostname that resolves to that address was not blocked. DNS rebinding worked because the same domain name can resolve between two IPs within a short time, governed by the TTL. The task also accepts custom headers, which is what made the IMDSv2 flow possible: the token request and the token-authenticated request could both be issued through the same feature.

What it meant

Through the API Call task an authenticated user could make the server issue requests to the internal AWS instance metadata service and obtain an IMDSv2 token. The report does not enumerate which metadata fields were retrieved or what could be done with them beyond that. The finding was initially rejected as a blind SSRF; after the report was updated with reproduction steps and more arguing, the team rewarded them with 500 USD.

The fix

The report does not describe any fix that was applied. What the finding calls for is restricting the API Call task so that it cannot reach internal addresses: resolve the host and validate the resolved address at connection time rather than validating the hostname string, block link-local and other internal ranges, and do not let user-supplied custom headers drive requests to internal services.

Other places to look

  1. Any user-configurable outbound request feature. Webhook handlers, URL importers, avatar fetchers, integration callbacks. A positive result is a response from an internal address, or a distinguishable error or timing difference when pointing at one.
  2. Literal-address blocks. If [redacted] is refused, try IP obfuscation, redirects and IPv6 forms as the researchers did. A positive result is any of them returning content instead of the block.
  3. DNS rebinding against hostname-based filters. Point a rebinding domain at an internal address and a public one. A positive result is an internal response, or an internal-looking header such as server: EC2ws, arriving through the rebinding name.
  4. Custom header support in the request feature. If the feature lets you set headers, try the IMDSv2 token request with X-aws-ec2-metadata-token-ttl-seconds: 21600 and then reuse the token with X-aws-ec2-metadata-token. A positive result is a token in the first response and metadata in the second.
  5. Blind SSRF that looks rejected. A 401 or an error is not proof the request did not reach the internal host; check response headers and timing before accepting a rejection.

Glossary

  • API: a way for one piece of software to talk to another over the network, sending requests and receiving responses.
  • API Call task: the feature in the product that makes the server send an HTTP request to a host the user chooses.
  • AWS: Amazon Web Services, a cloud provider that rents virtual machines and other computing resources.
  • Blind SSRF: an SSRF where the attacker cannot read the response content, only side effects such as status codes, headers or timing.
  • Bug bounty program: an arrangement where a company invites outside testers to find security problems and pays for the ones they report.
  • Callback URL: the address a system sends an automatic message to when something happens.
  • Cloud: software that runs on someone else's servers, reachable over the internet.
  • DNS: the Domain Name System, the internet's phone book, translating readable names into numeric IP addresses.
  • DNS rebinding: an attack that manipulates name resolution so the same name resolves to different addresses within a short time, defeating checks that look up the name separately from the connection.
  • GET: the most common HTTP method, meaning "give me this thing".
  • Header: a small piece of extra information attached to a request or response, such as the server name or a token.
  • Host: the address a request is sent to.
  • HTTP status code: a number in a response saying how the request went, such as 200 for success, 401 for unauthorized and 403 for forbidden.
  • IMDSv1 / IMDSv2: the older and newer versions of the AWS instance metadata service; IMDSv2 requires a token before answering.
  • Instance: a virtual machine rented from a cloud provider.
  • Instance metadata service: an internal AWS address, [redacted], that serves information about the instance itself.
  • IP address: the numeric address of a machine on a network.
  • IP obfuscation: writing the same IP address in an alternative form so a filter that checks only the familiar form does not recognise it.
  • IPv6: a newer version of the internet addressing system with much longer addresses.
  • Link-local: an address only reachable from inside the local network, not from the internet.
  • Method: the type of an HTTP request, such as GET.
  • OWASP: a non-profit that publishes guidance on web security.
  • Permission level: a role such as Admin or User that determines what an account is allowed to do.
  • Process: the product feature that runs a set of tasks once a user-defined condition is met.
  • Redirect: a response telling the client to go to a different address instead.
  • Response header: extra information the server attaches to its answer, such as server: EC2ws.
  • SSRF: Server-Side Request Forgery, tricking a server into making a request the attacker chooses, often to an internal address.
  • Subdomain: one part of a larger website, such as app.example.com under example.com.
  • Token: a short-lived piece of text that proves the client was allowed to ask, used in IMDSv2 before reading metadata.
  • TTL (time-to-live): how long a DNS answer may be kept before asking again; also used for token lifetime.
  • Webhook: an automatic message one system sends to another when something happens.
  • 401: unauthorized, meaning the server does not know who you are or you have not proved it.
  • 403: forbidden, meaning the server understood the request but refused to carry it out.

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.