Skip to content
SSRF Write-up Intermediate

Another vision for SSRF

An SSRF flaw in a subdomain could be used as a proxy that reflects the victim's requests, including session cookies set for the whole parent domain. An attacker could lure a victim to the vulnerable URL and capture the HttpOnly session cookie from their own server logs, leading to account takeover.

phor3nsic Follow

Published on gccybermonks.com

For a long time, I tested SSRF failures to search for services and ports from the internal network and use the information to obtain interesting data or reach a RCE. But in the last few days, I came across situations where I didn’t have an internal scenario, I had a good flaw but its impact would be low.

phor3nsic (@phor3nsic_br), on gccybermonks.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 write-up is about SSRF (Server Side Request Forgery) and a less common way of using it. The author, @phor3nsic_br, had spent a long time testing SSRF to enumerate services and ports on internal networks, looking for interesting data or a path to RCE. In recent engagements, however, the internal scenario was not available: the flaw was real but its impact looked low. The article describes an alternative angle, using the server side to reach the client side, and calls it SSRF To Account Takeover.

The article was posted on 06. June 2022 on gccybermonks.com. The report does not describe a specific production application or a specific vulnerable endpoint; the technique is illustrated with a lab built on app.localhost.io.

From the original on gccybermonks.com

What SSRF is, in the author's words

The article quotes the OWASP description to set the baseline:

"The target application may have functionality for importing data from a URL, publishing data to a URL or otherwise reading data from a URL that can be tampered with. The attacker modifies the calls to this functionality by supplying a completely different URL or by manipulating how URLs are built (path traversal etc.)."

Source: Owasp

Setup

The write-up does not describe a target program, accounts, roles, tool versions or a bounty. The only environment shown is a lab. The preconditions it sets out are:

  1. An SSRF that reflects the headers used by the client. The author notes this is common in SSRF that acts as a proxy, where the attacker can define a proxy in the application.
  2. An application on the same domain as the SSRF that performs authentication and sets its session cookie for the whole parent domain, so the cookie travels between subdomains.
  3. A way to make the victim's browser send a request to the vulnerable domain, so that the SSRF forwards that request, with cookies, to a server the attacker controls.

Finding it

The author's starting point is the common vision of SSRF: an attacker manipulates a server-side request to reach internal data. Companies that know about the problem segregate those hosts, restrict ports and add restrictions, so that SSRF is not accepted by bug bounty programs or by the client. The question the article asks is whether SSRF is limited to that.

The alternative view is to use the server side to reach the client side. To do this, the SSRF must reflect the headers used by the client, which is common when the SSRF works as a proxy and the attacker can define a proxy in the application. The author compares the result to a subdomain takeover, because the attacker can take over all the content that transits to that subdomain. On a domain this is already impactful; on an out-of-scope subdomain or a dev environment it may have less effect, because there are not many direct requests to such regions and the company can say it is not under their control, reducing the impact.

The next requirement is authentication or session cookies for applications on the same domain as the SSRF. If the SSRF is on ssrf.dev.example.com, the attacker needs an application with authentication on *.example.com whose cookie is set like this:

Java
Set-cookie: [redacted] domain=.example.com, HttpOnly

The cookie is set so that it can move freely between all subdomains of *.example.com. Because of the HttpOnly flag it cannot be obtained through XSS; the author links to the HttpOnly documentation. Even with XSS on any subdomain of example.com, the cookies cannot be captured, although they can still be reused with fetch (see Using Fetch).

If Set-Cookie also deploys SameSite like this:

Java
Set-cookie: [redacted] domain=.example.com, HttpOnly, SameSite=Lax

then the cookies can neither be obtained nor reused with fetch through XSS, because of the SameSite implementation.

The conclusion of this reasoning is the core of the article: cookies cannot be obtained or reused through XSS, but they can be stolen through SSRF.

The request carries cookies, and they can be obtained from the logs of the server that is monitoring the requests. The attacker has to make sure the SSRF directs requests to their server and then makes its content available through the vulnerable domain. By sending the server URL to the victim, the victim somehow accesses the URL, and the attacker soon gets the session cookie through their logs.

From the original on gccybermonks.com

Exploitation

The article illustrates the technique with a lab on app.localhost.io.

Step 1: observe the cookie

When accessing app.localhost.io, the application returns a cookie with the HttpOnly flag and domain=.localhost.io:

From the original on gccybermonks.com

Step 2: confirm XSS cannot read it

Trying to get that cookie through XSS does not work: the cookie is not even visible because of HttpOnly.

From the original on gccybermonks.com

Step 3: send the cookie through the SSRF

Using the SSRF described above, the cookies are sent to the destination server.

From the original on gccybermonks.com

Step 4: redirect the request to the attacker's server

By redirecting the request to the attacker's server, the requests can be viewed and the victim's cookies obtained.

From the original on gccybermonks.com

Root cause

The technique relies on the SSRF reflecting the client's headers, including cookies, to a destination the attacker controls. The cookie is set with domain=.localhost.io and the HttpOnly flag, so XSS cannot read it, yet the SSRF still sends it to the destination server. The author notes that with SameSite=Lax the cookies can neither be obtained nor reused with fetch through XSS. The existing defences (HttpOnly, SameSite) therefore do not stop this path.

Impact

An attacker who controls the SSRF destination can obtain the victim's session cookies for applications on the same parent domain, which the author frames as account takeover. The impact depends on the conditions above: the SSRF must reflect client headers, the cookie must be scoped to the parent domain, and the victim must be made to access the attacker's URL through the vulnerable domain. The author notes that on an out-of-scope subdomain or a dev environment the practical impact may be lower, because few direct requests reach such regions and the company may state it is not under their control.

Fix

Variants to test

  1. SSRF that reflects client headers: look for proxy-style SSRF features and check whether the request received on a controlled server contains the victim's Cookie header. A positive result is a request in your logs carrying a session cookie.
  2. Parent-domain cookies: enumerate applications on *.example.com that set domain=.example.com cookies with HttpOnly and SameSite. A positive result is a cookie that is sent to the vulnerable subdomain.
  3. Redirect to attacker server: make the SSRF follow a redirect to a server you control. A positive result is the redirected request arriving with the victim's cookies.
  4. Out-of-scope or dev subdomains: test the same technique where the SSRF sits on a dev or out-of-scope subdomain. A positive result is a cookie from an application on the parent domain arriving in your logs.

Closing

The author's conclusion is about method: the SSRF could have been dropped because the internal access was not there, but by stepping outside the usual list of thoughts a different impact appears. The article ends with the idea of not falling into any box and thinking above implanted limits.

Posted on 06. June 2022.

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

What happened, in plain words

A security researcher who goes by @phor3nsic_br wrote an article about a bug class called SSRF, short for Server Side Request Forgery. For a long time he had used SSRF the usual way: to make a company's server look around its own private network, find services and open ports, and use what it found to reach interesting data or even take over a machine (that last outcome is called RCE, remote code execution).

In recent work, though, that usual path was closed. The bug was real, but the internal network was locked down, so the impact looked low. The article describes a different way to use the same bug: instead of using the server to reach the inside of the company, you use it to reach the user's browser session, and from there the user's account. The author calls this idea SSRF To Account Takeover.

From the original on gccybermonks.com

It does not describe a specific production application or a specific vulnerable endpoint; the technique is shown with a small practice environment (a lab) built on app.localhost.io.

What SSRF is, in the author's words

Before going further, it helps to know what SSRF means. Many websites have features where the website's own server fetches something from a web address for you: a "preview this link" button, an image importer, a webhook, a PDF generator. Normally the server fetches from a sensible place. SSRF is when you, the attacker, can change the address the server fetches from, so the server makes a request of your choosing. Because the request comes from the server, it can reach places your own browser cannot, such as the company's internal network.

A useful everyday comparison: imagine a hotel concierge who will fetch anything you ask for from anywhere in the building. Normally guests ask for things from the lobby shop. If you can convince the concierge to walk into the staff-only rooms and bring back what is there, you have an SSRF.

The article quotes the OWASP description to set the baseline:

"The target application may have functionality for importing data from a URL, publishing data to a URL or otherwise reading data from a URL that can be tampered with. The attacker modifies the calls to this functionality by supplying a completely different URL or by manipulating how URLs are built (path traversal etc.)."

Source: Owasp

In plain words: the site has a feature that reads from a web address, and that address can be tampered with. The attacker swaps in a completely different address, or fiddles with how the address is assembled, and the server obediently fetches the attacker's choice.

Setup

The article does not describe a target program, accounts, roles, tool versions or a bounty. The only environment shown is a lab. Before the technique works, three conditions have to be in place:

  1. An SSRF that reflects the headers used by the client. A header is a small piece of extra information that a browser attaches to every request, such as which site it came from or what kind of content it accepts. "Reflects" means the server passes those headers on to wherever it fetches from. The author notes this is common in SSRF that acts as a proxy, where the attacker can define a proxy in the application. A proxy is a middleman: instead of talking to the destination directly, you ask the middleman to talk to it for you, and the middleman repeats your request.
  2. An application on the same domain as the SSRF that performs authentication and sets its session cookie for the whole parent domain, so the cookie travels between subdomains. A cookie is a small note a website asks your browser to keep and send back on every later request to that site; it is how the site remembers that you are logged in. A session cookie is the specific cookie that proves who you are. A domain is the part of a web address after the www, like example.com; a subdomain is a prefix in front of it, like app.example.com or ssrf.dev.example.com.
  3. A way to make the victim's browser send a request to the vulnerable domain, so that the SSRF forwards that request, with cookies, to a server the attacker controls.

Finding it

The author's starting point is the common vision of SSRF: an attacker manipulates a server-side request to reach internal data. Companies that know about the problem segregate those hosts, restrict ports and add restrictions, so that SSRF is not accepted by bug bounty programs or by the client. The question the article asks is whether SSRF is limited to that.

The alternative view is to use the server side to reach the client side. To do this, the SSRF must reflect the headers used by the client, which is common when the SSRF works as a proxy and the attacker can define a proxy in the application. The author compares the result to a subdomain takeover, because the attacker can take over all the content that transits to that subdomain. A subdomain takeover is when an attacker gains control of a subdomain that the company no longer properly manages, so visitors to that address end up seeing the attacker's content. On a domain this is already impactful; on an out-of-scope subdomain or a dev environment it may have less effect, because there are not many direct requests to such regions and the company can say it is not under their control, reducing the impact.

The next requirement is authentication or session cookies for applications on the same domain as the SSRF. If the SSRF is on ssrf.dev.example.com, the attacker needs an application with authentication on *.example.com whose cookie is set like this:

Java
Set-cookie: [redacted] domain=.example.com, HttpOnly

Line by line, in plain words:

  • Set-cookie: is the instruction a website sends to your browser to store a cookie. It is the server saying "keep this note for me".
  • [redacted] is the name and value of the cookie. sessionis the name;SECRET_SESSION` stands in for the real secret value that proves you are logged in. In a real attack this value is what the attacker wants to steal.
  • domain=.example.com tells the browser to send this cookie not only to the exact site that set it, but to every subdomain of example.com. The leading dot is the traditional way of writing "this domain and everything under it".
  • HttpOnly is a flag that tells the browser: do not let JavaScript read this cookie. It is a protection against a different bug, XSS (cross-site scripting), where an attacker manages to run their own JavaScript inside a page you are viewing.

The cookie is set so that it can move freely between all subdomains of *.example.com. Because of the HttpOnly flag it cannot be obtained through XSS; the author links to the HttpOnly documentation. Even with XSS on any subdomain of example.com, the cookies cannot be captured, although they can still be reused with fetch (see Using Fetch). Fetch is the browser feature JavaScript uses to make requests; "reuse" here means the attacker's script cannot read the cookie, but it can still make the browser send requests that carry it.

If Set-Cookie also deploys SameSite like this:

Java
Set-cookie: [redacted] domain=.example.com, HttpOnly, SameSite=Lax

Line by line:

  • Everything before SameSite is the same as the previous example: the cookie's name and value, its domain scope, and the HttpOnly flag.
  • SameSite=Lax is an extra instruction that limits when the browser will attach this cookie to requests that start from another website. Lax means the cookie is sent on ordinary navigation (clicking a link to the site) but not on many background requests started by other sites. It is a defence against a class of attacks where another site quietly makes your browser act on your behalf, known as CSRF (cross-site request forgery).

then the cookies can neither be obtained nor reused with fetch through XSS, because of the SameSite implementation.

The conclusion of this reasoning is the core of the article: cookies cannot be obtained or reused through XSS, but they can be stolen through SSRF.

The request carries cookies, and they can be obtained from the logs of the server that is monitoring the requests. A log is the running record a server keeps of every request it receives. The attacker has to make sure the SSRF directs requests to their server and then makes its content available through the vulnerable domain. By sending the server URL to the victim, the victim somehow accesses the URL, and the attacker soon gets the session cookie through their logs.

From the original on gccybermonks.com

Why does this work when XSS does not? Because the defences above are aimed at JavaScript running in the browser. HttpOnly stops scripts from reading the cookie. SameSite stops other sites from quietly making the browser send it. But here the browser is not the one making the final request: the company's own server is. The server takes the request it received, including the cookie, and forwards it to the address the attacker chose. The browser protections never get a say, because from the browser's point of view it is talking to the company's own site.

Exploitation

The article illustrates the technique with a lab on app.localhost.io.

Step 1: observe the cookie

When accessing app.localhost.io, the application returns a cookie with the HttpOnly flag and domain=.localhost.io:

From the original on gccybermonks.com

This step is about confirming the first precondition: the cookie really is scoped to the whole parent domain, so it will be sent to any subdomain of localhost.io, including the one with the SSRF. The screenshot shows the cookie with the HttpOnly flag and domain=.localhost.io.

Step 2: confirm XSS cannot read it

Trying to get that cookie through XSS does not work: the cookie is not even visible because of HttpOnly.

From the original on gccybermonks.com

This step exists to rule out the easy path. If the cookie could be read by JavaScript, the attacker would not need the SSRF at all. The screenshot shows the XSS attempt, where the cookie is not visible due to HttpOnly.

Step 3: send the cookie through the SSRF

Using the SSRF described above, the cookies are sent to the destination server.

From the original on gccybermonks.com

This is the pivot. The victim's browser makes a request to the vulnerable domain, the browser attaches the cookie because the domain matches, and the vulnerable server forwards that request, cookie included, to the destination the attacker set. The screenshot illustrates the cookies being sent to the destination server.

Step 4: redirect the request to the attacker's server

By redirecting the request to the attacker's server, the requests can be viewed and the victim's cookies obtained.

From the original on gccybermonks.com

A redirect is a server's way of saying "not here, go to this other address instead". The screenshot shows the requests and the victim's cookies obtained on the attacker's server.

Root cause

The technique relies on the SSRF reflecting the client's headers, including cookies, to a destination the attacker controls. The cookie's domain=.localhost.io scope means it is attached to requests to any subdomain, including the vulnerable one, and HttpOnly only protects the cookie from client-side script access; it does nothing once the server itself relays the request. The author notes that with SameSite=Lax the cookies can neither be obtained nor reused with fetch through XSS. The existing defences (HttpOnly, SameSite) therefore do not stop this path.

In everyday terms: the cookie's protections are rules for the browser. The moment the company's server picks up the request and passes it on, those rules no longer apply, because the server is not a browser and does not follow browser rules.

Impact

An attacker who controls the SSRF destination can obtain the victim's session cookies for applications on the same parent domain, which the author frames as account takeover. Account takeover means logging in as the victim without knowing their password, simply by holding their session cookie. The impact depends on the conditions above: the SSRF must reflect client headers, the cookie must be scoped to the parent domain, and the victim must be made to access the attacker's URL through the vulnerable domain. The author notes that on an out-of-scope subdomain or a dev environment the practical impact may be lower, because few direct requests reach such regions and the company may state it is not under their control.

Fix

The article does not describe a fix or a change made by the company. An allowlist is a list of addresses that are explicitly permitted; anything not on the list is refused.

Variants to test

If you want to look for this yourself, here are the angles the article points at. Each one is a small experiment with a clear sign of success.

  1. SSRF that reflects client headers: look for proxy-style SSRF features and check whether the request received on a controlled server contains the victim's Cookie header. A positive result is a request in your logs carrying a session cookie.
  2. Parent-domain cookies: enumerate applications on *.example.com that set domain=.example.com cookies with HttpOnly and SameSite. A positive result is a cookie that is sent to the vulnerable subdomain.
  3. Redirect to attacker server: make the SSRF follow a redirect to a server you control. A positive result is the redirected request arriving with the victim's cookies.
  4. Out-of-scope or dev subdomains: test the same technique where the SSRF sits on a dev or out-of-scope subdomain. A positive result is a cookie from an application on the parent domain arriving in your logs.

Closing

The author's conclusion is about method: the SSRF could have been dropped because the internal access was not there, but by stepping outside the usual list of thoughts a different impact appears. The article ends with the idea of not falling into any box and thinking above implanted limits.

Posted on 06. June 2022.

Glossary

  • SSRF (Server Side Request Forgery): a bug where an attacker can change the web address that a website's own server fetches from, so the server makes a request of the attacker's choosing.
  • RCE (remote code execution): a bug severe enough that an attacker can run their own commands on someone else's machine.
  • Account takeover: gaining access to someone else's account, usually by stealing their session, without needing their password.
  • Server side: work done by the website's own computer, the server, rather than by the visitor's browser.
  • Client side: work done in the visitor's browser, on their own computer.
  • Header: a small piece of extra information attached to every web request or response, such as the content type or the cookies being sent.
  • Reflect (headers): when a server passes the headers it received on to the next destination instead of dropping them.
  • Proxy: a middleman that receives a request and forwards it to the destination on your behalf.
  • Cookie: a small note a website asks your browser to store and send back on later requests, used to remember who you are.
  • Session cookie: the specific cookie that proves you are logged in; whoever holds it can act as you.
  • Domain: the main part of a web address, such as example.com.
  • Subdomain: a prefix added in front of a domain, such as app in app.example.com.
  • Parent domain: the domain that subdomains sit under, such as example.com for app.example.com.
  • Subdomain takeover: when an attacker gains control of a subdomain the company no longer properly manages, so visitors see the attacker's content.
  • HttpOnly: a cookie flag that stops JavaScript in the page from reading the cookie.
  • SameSite: a cookie setting that limits when the browser will attach the cookie to requests that start from another website.
  • XSS (cross-site scripting): a bug where an attacker gets their own JavaScript to run inside a page you are viewing.
  • CSRF (cross-site request forgery): a bug where another website quietly makes your browser send a request to a site you are logged in to.
  • Fetch: the browser feature JavaScript uses to make web requests.
  • Redirect: a server's reply telling the browser, or the requesting server, to go to a different address instead.
  • Log: the running record a server keeps of the requests it receives.
  • Allowlist: a list of addresses that are explicitly permitted, with everything else refused.
  • Lab: a practice environment built to demonstrate a technique safely.
  • Bug bounty program: a scheme where companies pay researchers for reporting security bugs to them.
  • Out of scope: outside the boundaries a company has set for what may be tested or reported.
  • Dev environment: a development copy of a site, used for testing rather than by real users.

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.