Server Side Request Forgery with huge impact in production application
A PHP page accepted a URL parameter and fetched its content without any validation, allowing server-side request forgery. An attacker could use it to read local files and retrieve AWS EC2 instance credentials.
Published on medium.com
Hi all, I hope all is well. I’m going to talk about the SSRF I found a long time ago.
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.
Context
This is a short account of a server side request forgery (SSRF) found in a production application during a broad reconnaissance pass over a wildcard scope. The researcher describes the finding as easy, and the write-up is mostly about the recon workflow that led to the vulnerable page rather than about a complicated bypass.
The affected feature is a PHP page that takes a URL from a request parameter, fetches that URL on the server side and renders the result back to the user. In normal use it is a simple fetch-and-display helper. Because the server performs the request, the parameter is an SSRF sink: whatever the server can reach, the page can be made to reach.
Setup
The work targets a wildcard scope of the form *.anywebsite.com. No accounts, roles or special access are mentioned. The toolset is five public tools:
- subfinder, for subdomain discovery.
- httpx, to probe which subdomains are up and to filter URLs by status code.
- gau, to fetch known URLs for the subdomains from AlienVault's Open Threat Exchange, the Wayback Machine and Common Crawl.
- ffuf, as the web fuzzer for directories and endpoints.
- LinkFinder, to extract endpoints from JavaScript files.
The researcher notes that manual searching is preferred over the automated steps.
Finding it
The recon flow is described as follows:
- Collect subdomains of the target with subfinder.
- Use httpx to keep the subdomains that are up.
- Use gau to fetch URLs belonging to those subdomains.
- Filter by extension, keeping dynamic and script files such as
.php,.aspx,.jspand.js, and run httpx over the filtered list again. - Treat URLs that return 200 as targets, then fuzz them with ffuf and LinkFinder to find new endpoints.
On one host the researcher found a page of the form redacted.com/x/y/z/anything.php, described as a very clear PHP page. Fuzzing the containing directory with ffuf, using redacted.com/x/y/z/FUZZ as the pattern, revealed crossdomain.php in the same directory. That page required a URL parameter and pulled the site named in the parameter directly and displayed it on the page. The server fetched the supplied URL with no protection or filtering, which is the condition that makes SSRF worth testing.
Exploitation
With a server-side fetch under attacker control, the researcher moved through the standard SSRF vectors, referencing the HackTricks SSRF page as the source of the payloads. The write-up shows the payloads and the resulting pages as screenshots rather than as raw HTTP traffic.
Step 1: Confirm the fetch and test for XSS
The first payload points the parameter at an arbitrary file on an attacker-controlled host:
https://anything.com/test.svg or anyfile -> XSS
The note against the payload records that serving a file such as an SVG results in XSS. The note against the payload records that serving a file such as an SVG results in XSS, because the fetched content is rendered in the application's origin.
Step 2: Read local files with the file scheme
The next two payloads switch from HTTP to the file:// scheme, which the fetcher accepts:
file:///proc/version
file:///etc/passwd
The write-up shows these payloads with screenshots of the results.
Step 3: Reach the cloud metadata service
The final two payloads target the EC2 instance metadata endpoint at the link-local address:
http://[redacted]/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance
http://[redacted]/latest/meta-data/iam/security-credentials/ec2-default
The researcher characterises the overall impact as huge and says the bug was found a long time ago.
Root cause
The page takes a user-supplied URL, performs the request server side and returns the body to the client. The server fetched the supplied URL with no protection or filtering. The note against the first payload records that serving a file such as an SVG results in XSS. The report does not describe any defence that was present and bypassed; the absence of filtering is the finding.
Impact
Under the conditions shown, an attacker who can reach the page can:
- read local files on the server through
file://; - reach internal-only HTTP services, including the EC2 metadata endpoint, and retrieve instance identity credentials and IAM role credentials;
- execute script in the application's origin by pointing the parameter at attacker-controlled content such as an SVG.
The report does not enumerate the permissions of that role or describe any follow-on use of the credentials.
Fix
The write-up does not state what the application changed. The fix implied by the finding is to stop fetching arbitrary user-supplied URLs: restrict the parameter to an allowlist of expected hosts and schemes, resolve and reject private, loopback and link-local addresses (including [redacted]), disable redirects or re-validate them, and serve fetched content as inert data rather than rendering it in the application's origin. Enforcing IMDSv2 on the instance side would also limit the value of a metadata fetch.
Variants to test
- Scheme switching. Submit
file://,gopher://,dict://andftp://where the parameter expectshttp. A positive result is any non-HTTP scheme returning content or causing an outbound connection. - Redirect-based bypass. Host a URL on your own server that redirects to
http://[redacted]/. If the fetcher follows redirects without re-checking the destination, the metadata response comes back. - Decimal and alternative IP encodings. Try
http://2852039166/,http://0xa9fea9fe/and similar forms of the link-local address. A positive result is the same metadata content returned despite a naive string filter. - DNS rebinding. Use a hostname that resolves first to a permitted address and then to an internal one. A positive result is a response from the internal target on the second resolution.
- Content reflection. Point the parameter at an HTML or SVG file you control. If the markup renders in the application's origin, the sink is also an XSS vector.
- Metadata path enumeration. On cloud hosts, walk
/latest/meta-data/and the IAM credential paths to see which identities are exposed. A positive result is any credential material returned through the page.
What happened, in plain words
A security researcher was looking for bugs across a large set of websites belonging to one company. The scope was a wildcard, *.anywebsite.com, meaning every subdomain of that domain. During this sweep the researcher found a page that would fetch any web address you gave it and show you the result. Because the fetching was done by the company's own server, not by the visitor's browser, the researcher could ask that server to fetch things it was never meant to reach: files sitting on the server's own disk, and a special internal address that cloud servers use to hand out login credentials. The report calls the impact huge. The finding itself was easy; most of the write-up is about how the researcher got there.
This article walks through the same story from zero. If you have never heard of a subdomain, a parameter, or server side request forgery, that is fine. Every term is explained the first time it appears, and there is a glossary at the end.
The idea you need first: who makes the request
When you type an address into your browser and press Enter, your computer asks a web server for a page, and the server sends it back. The request comes from your machine. Your machine can reach the public internet and very little else.
Some web features work differently. You give the website a link, and the website's server goes and fetches that link for you, then shows you what came back. Think of a hotel concierge: you ask for a newspaper, and the concierge walks out and brings one back. You never leave the building, but the concierge can go into staff-only corridors that you cannot.
That is the whole shape of this bug. If a website lets you choose what its server fetches, you are choosing where the concierge walks. The server usually sits inside a private network, close to databases, internal tools and cloud management addresses that the public internet cannot touch. A feature that fetches on your behalf can therefore be tricked into fetching those private things and handing them back to you.
Security people call this Server Side Request Forgery, or SSRF: the server is tricked into forging a request on the attacker's behalf. The input that causes it (here, a URL parameter) is called a sink.
The target and the tools
The scope was a wildcard: *.anywebsite.com. The asterisk means every subdomain. A subdomain is a name in front of the main domain, like shop.example.com or api.example.com. Large companies have many of them, and each one can be a separate application with its own bugs.
The researcher used five free, publicly available tools. You do not need to install them to follow the story, but here is what each one does:
- subfinder finds subdomains. It asks public sources which names exist under a domain.
- httpx is a prober. Given a list of addresses, it checks which ones actually respond, and it can filter results by the HTTP status code (200 means OK).
- gau (get all URLs) collects web addresses that are already publicly known for a domain, gathered from AlienVault's Open Threat Exchange, the Wayback Machine (an archive of old web pages) and Common Crawl (a public archive of crawled pages).
- ffuf is a fuzzer. You give it a URL with a placeholder such as
FUZZ, plus a word list, and it tries every word in the list in place of the placeholder, reporting which ones produce a real response. It is how you discover pages that are not linked anywhere. - LinkFinder reads JavaScript files and pulls out the web addresses mentioned inside them. JavaScript is the code that runs in your browser; it often contains the addresses of the application's own endpoints.
An endpoint is simply a specific address on a server that does something, for example /login or /api/users. The researcher adds a note that manual searching was preferred over the automated steps, meaning looking at pages by hand rather than only trusting tool output.
The recon flow, step by step
The researcher describes the process in five steps. Here is each one, with the reason behind it.
- Collect subdomains with subfinder. You cannot test what you do not know exists. The wildcard scope means every discovered name is in play.
- Keep the ones that are up with httpx. A list of subdomains contains many dead names. Probing them first saves time later.
- Fetch known URLs with gau. Old archives remember pages that may no longer be linked from anywhere. Those pages are often forgotten and less protected.
- Filter by file extension and probe again with httpx. The researcher kept dynamic and script files such as
.php,.aspx,.jspand.js. The reasoning: a.phppage is generated by code on the server, and server-side code is where server-side bugs live. A plain image or stylesheet is far less interesting. - Treat URLs that return 200 as targets, then fuzz them with ffuf and LinkFinder. A 200 response means the page exists and works. Fuzzing the directory around it and mining its JavaScript can reveal further endpoints that nobody linked to.
Finding the vulnerable page
On one host the researcher found a page shaped like this:
redacted.com/x/y/z/anything.php
This is a URL. redacted.com stands in for the real domain, which the report hides. The path /x/y/z/ is a folder-like location on the server, and anything.php is a file ending in .php, which tells you the server runs PHP code to build the page. The researcher describes it as a very clear PHP page.
Next, the researcher fuzzed the folder that contains it, using this pattern:
redacted.com/x/y/z/FUZZ
FUZZ is ffuf's placeholder. ffuf replaces it with each word from a word list and requests the result, so FUZZ becomes admin, backup, crossdomain and so on. This revealed a second page in the same folder, crossdomain.php.
That page required a URL parameter. A parameter is the part of an address after a question mark, like ?url=.... It is how you pass a value to a page. This page took the URL you supplied in the parameter, fetched it from the server, and displayed the result on the page. The server pulled whatever it was given, with no protection and no filtering.
That is the condition worth testing. When a server makes a request and you can influence where that request goes, you test for SSRF. The researcher then worked through the standard SSRF attack vectors, using the HackTricks SSRF page as the reference for the payloads. A payload is the specific value you send to trigger a behaviour.
Step 1: Confirm the fetch, and find XSS
The first payload points the parameter at a file on a host the attacker controls:
https://anything.com/test.svg or anyfile -> XSS
Line by line: https://anything.com/test.svg is an address of an image file in SVG format. SVG is a picture format that is actually written in markup, the same language web pages use, so it can contain script. The or anyfile part notes that any file works. The -> XSS part records the result: cross-site scripting.
XSS, or cross-site scripting, means getting your own code to run inside someone else's website, in that site's origin. An origin is the combination of scheme, host and port, for example https plus redacted.com plus the default port. Browsers treat everything from one origin as the same trusted place. If your script runs in the application's origin, it can read what the application can read.
Why this step: it proves two things at once. The server really does go out and fetch remote content, and it puts that content into the page as if it were the application's own. The note against the payload says that serving a file such as an SVG results in XSS, because the fetched content is rendered in the application's origin.
Step 2: Read files on the server with the file scheme
The next two payloads stop using http and use file:// instead:
file:///proc/version
Line by line: file:// is a scheme, the first part of an address that says how to reach something. http:// means speak the web protocol to a remote machine. file:// means read a file from the local disk. The triple slash is followed by an absolute path. /proc/version is a file on Linux systems that reports which kernel version is running. The point of asking for it is that it is harmless to read and proves the fetcher will read local files at all.
file:///etc/passwd
Line by line: same scheme, different path. /etc/passwd is a classic Linux file that lists user accounts. On modern systems it does not contain passwords, but it still reveals which users exist, and reading it is the standard proof that a server will hand over its own files.
Why these steps: the first payload showed the server fetches remote pages. These show the fetcher is not restricted to http at all. If file:// works, the server process can read files it should never expose, and the person controlling the parameter can read them through the page.
Step 3: Reach the cloud metadata service
The last two payloads target a special address inside cloud networks:
http://[redacted]/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance
Line by line: http:// is the normal web scheme. [redacted] is a link-local address. Link-local addresses are only meaningful on the local network segment; they are never routed across the public internet. Cloud providers such as Amazon Web Services put a small web service on this address on every virtual machine. It is called the instance metadata service. ec2 refers to Amazon's virtual machines. The path /latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance asks that service for the identity credentials of the instance.
http://[redacted]/latest/meta-data/iam/security-credentials/ec2-default
Line by line: same address and service, different path. iam stands for Identity and Access Management, the cloud system that decides what each machine and user is allowed to do. This path asks for the credentials attached to the instance's IAM role. A role is a set of permissions. Credentials are the keys that prove you hold that role.
Why these steps: this is where the impact becomes serious. The metadata service exists so that a machine can learn its own identity without a password being stored on disk. It answers anyone who can reach [redacted] from inside the machine. Normally that is only the machine itself. Here the vulnerable page is the machine, so the researcher can ask it to fetch the metadata address and hand back the answer.
The researcher describes the overall impact as huge and says the bug was found a long time ago.
Why it worked
The page takes a URL supplied by the user, performs the request on the server side, and returns the body to the visitor. The server fetched the supplied URL with no protection or filtering.
- There is no allowlist of permitted hosts or schemes. An allowlist is the opposite of a blocklist: instead of naming what is forbidden, you name the only things allowed, and everything else is refused.
- Private and link-local address ranges are not blocked. These are the address ranges used inside networks, which the public internet cannot reach.
- There is no separation between the component that fetches and the content returned to the user. The fetched body is rendered in the application's own origin, so fetched HTML or SVG runs as application content. That turns the same sink into reflected XSS as well as SSRF. Reflected means the payload comes back in the response rather than being stored on the server.
The report does not describe any defence that was present and bypassed. The absence of filtering is the finding.
What an attacker could do with it
Under the conditions shown, someone who can reach the page can:
- read local files on the server through
file://; - reach internal-only HTTP services, including the EC2 metadata endpoint, and retrieve instance identity credentials and IAM role credentials;
- run script in the application's origin by pointing the parameter at content they control, such as an SVG.
The report does not list the permissions of that role and does not describe any follow-on use of the credentials.
How to fix it
The write-up does not state what the application changed. The fix implied by the finding is to stop fetching arbitrary user-supplied URLs:
- restrict the parameter to an allowlist of expected hosts and schemes;
- resolve addresses and reject private, loopback and link-local ranges, including
[redacted]; - disable redirects, or re-validate the destination after each redirect;
- serve fetched content as inert data rather than rendering it in the application's origin.
On the cloud side, enforcing IMDSv2 would also limit the value of a metadata fetch. IMDSv2 is a newer version of the metadata service that requires a session token obtained with a special request first, which a simple fetch-and-display page cannot easily produce.
Variants worth testing
These are the same class of test applied in slightly different ways. Each one lists what a positive result looks like.
- Scheme switching. Submit
file://,gopher://,dict://andftp://where the parameter expectshttp. A positive result is any non-HTTP scheme returning content or causing an outbound connection. - Redirect-based bypass. Host a URL on your own server that redirects to
http://[redacted]/. A redirect is a server telling the client "the thing you want is over there, go ask that address instead". If the fetcher follows redirects without re-checking the destination, the metadata response comes back. - Decimal and alternative IP encodings. Try
http://2852039166/,http://0xa9fea9fe/and similar forms of the link-local address. These are different ways of writing the same number:2852039166in decimal and0xa9fea9fein hexadecimal both equal[redacted]. A positive result is the same metadata content returned despite a naive string filter that only looks for the dotted form. - DNS rebinding. Use a hostname that resolves first to a permitted address and then to an internal one. DNS is the system that turns names into addresses. A positive result is a response from the internal target on the second resolution.
- Content reflection. Point the parameter at an HTML or SVG file you control. If the markup renders in the application's origin, the sink is also an XSS vector.
- Metadata path enumeration. On cloud hosts, walk
/latest/meta-data/and the IAM credential paths to see which identities are exposed. A positive result is any credential material returned through the page.
Glossary
- Allowlist: a list of the only things permitted; everything not on it is refused.
- API: a defined way for one piece of software to ask another for data or actions, usually over HTTP.
- Blocklist: a list of things forbidden; everything not on it is allowed.
- Credentials: the keys or secrets that prove an identity, such as access keys for a cloud role.
- Cross-site scripting (XSS): getting your own code to run inside another website's origin.
- DNS: the system that translates names like
example.cominto numeric addresses. - DNS rebinding: making a name resolve to a harmless address first and an internal address later, to slip past a check.
- Endpoint: a specific address on a server that performs an action.
- ffuf: a web fuzzer that tries words from a list in place of a placeholder such as
FUZZ. - gau: a tool that collects known URLs for a domain from public archives.
- httpx: a tool that probes addresses and reports which respond, optionally filtered by status code.
- IAM: Identity and Access Management, the cloud system that defines who and what may do which actions.
- IMDSv2: a newer version of the cloud instance metadata service that requires a session token before answering.
- Instance: a single virtual machine in a cloud provider.
- Instance metadata service: a small web service on
[redacted]that tells a cloud machine about itself, including its credentials. - Link-local address: an address valid only on the local network segment, never routed over the public internet;
[redacted]is one. - LinkFinder: a tool that extracts endpoints from JavaScript files.
- Loopback address: an address that refers to the machine itself, such as
[redacted]. - Origin: the combination of scheme, host and port that a browser treats as one trusted place.
- Parameter: a value passed to a page in the address, after a question mark, such as
?url=.... - Payload: the specific value sent to trigger a behaviour.
- PHP: a programming language commonly used to build web pages on the server.
- Private address range: address ranges used only inside networks, not reachable from the public internet.
- Redirect: a server response telling the client to request a different address instead.
- Role: a set of permissions in a cloud system, which credentials can be issued for.
- Scheme: the first part of an address, such as
http://orfile://, that says how to reach the target. - Server Side Request Forgery (SSRF): tricking a server into making a request to a destination the attacker chooses.
- Sink: the input in an application that causes a dangerous action when controlled by an attacker.
- subfinder: a tool that discovers subdomains from public sources.
- Subdomain: a name in front of a main domain, such as
shop.example.com. - SVG: an image format written in markup, which can contain script.
- Wildcard scope: a bug bounty scope covering every subdomain of a domain, written
*.example.com. - Word list: a file of common names used by a fuzzer to guess paths.
- XSS: see cross-site scripting.