Intermediate Lab
![]()
Exploit SSRF with Gopher for GCP Initial Access
Learn how the impact of an SSRF (Server-Side Request Forgery) vulnerability can be much more severe when virtual machine instance metadata is available.
Overview
The beginner-friendly and fun web exploitation lab shows how the impact of an SSRF (Server-Side Request Forgery) vulnerability can be much more severe when virtual machine instance metadata is available. We'll also see how a protection against SSRF vulnerabilities can be bypassed if the gopher protocol is supported.
Scenario
"You have recently joined a red team and are on an engagement for the client Gigantic Retail. In scope is their on-premise and cloud environments. As the cloud specialist you are called upon to get initial access to their infrastructure, starting with an identified IP address.
"
Lab prerequisites
- Basic Linux command line knowledge
Learning outcomes
- Exploit an SSRF vulnerability using Burp
- Bypass a measure that protects against SSRF by leveraging Gopher
- Enumerate Google Cloud resources using cURL
Real-world context
SSRF vulnerabilities are common and come in at number 10 on the OWASP Top 10 (2021) list. Adoption of cloud services and hybrid cloud architectures are also rapidly increasing, but often there isn't an awareness of the security implications of this new type of infrastructure. This lab also features gopher in bypassing a protection against SSRF vulnerabilities, and while gopher is an old protocol that has largely been supplanted, some libraries still provide support for it by default. This also highlights the importance of understanding the protocols that are supported by default in the various libraries that are used.
KEY TAKEAWAY
Server-side request forgery in a cloud environment is a credential disclosure vulnerability, because the metadata server issues tokens for the instance's service account to anything that can reach it from the host. The application does not need to be compromised, only persuaded to make a request.
What this lab covers
You find a request forgery flaw, encounter a protection intended to stop it, and defeat that protection using a protocol the filter did not anticipate, then use the resulting access to enumerate Google Cloud resources.
The protocol smuggling element is the instructive part. Most SSRF defenses fail because they reason about the destination rather than about what the request-making library will accept, and that gap is where alternative schemes live.
It suits web testers moving into cloud and assumes no prior GCP experience.
How SSRF reaches cloud credentials
SSRF occurs when an application makes a request to a location influenced by user input. In a cloud environment the highest-value target is the metadata server, a link-local address reachable only from the instance, which returns configuration and access tokens for the attached service account.
Naive protections block obvious targets by string matching, denying the metadata hostname or address. These are defeated by alternative representations, redirects and, importantly, by different protocols, because the filter is reasoning about a URL while the underlying library is reasoning about a request.
The gopher scheme is useful to an attacker because it allows arbitrary bytes to be sent to a host and port, which turns a request forgery into something closer to a socket. That permits interaction with services that are not plain HTTP and gives fine control over what is transmitted, which many filters never contemplate.
How to detect this in your own environment
Watch for metadata server requests originating from unusual processes. Legitimate access comes from cloud SDKs and agents, so a request from a web request handler is anomalous and is the cleanest host-level signal.
Monitor application logs for requests to internal or link-local addresses, and for unusual URL schemes in parameters. Both are visible if outbound request destinations are logged, which many applications do not do.
The most reliable cloud-side detection is token misuse. Service account credentials used from outside the instance are theft regardless of how the theft occurred, and that signal does not depend on recognizing the exploit.
How to prevent it
Validate destinations against an allow list of permitted hosts, and resolve addresses before connecting so that a name resolving to a link-local address is rejected. Deny lists of known-bad targets are the approach that keeps failing.
Restrict which schemes the request library will accept. Most applications need HTTP and HTTPS only, and disabling everything else removes protocol smuggling as a category.
Scope the instance service account narrowly, because that is what an attacker inherits. This does not prevent SSRF and it decides what SSRF is worth, which in practice is the control that limits impact.
Real-world context
Server-side request forgery is listed in the OWASP Top 10, and its severity rose substantially with cloud adoption because the metadata server turned a request forgery into a route to credentials.
The 2019 Capital One breach, prosecuted by the US Department of Justice, is the reference case for this shape of attack, where a request forgery weakness led to instance credentials being obtained and used to access stored data. The mechanism is the same across providers even though the metadata endpoints differ.
The pattern maps to MITRE ATT&CK T1190 Exploit Public-Facing Application and T1552.005 Cloud Instance Metadata API.
Applying this at work
- Review your applications for anywhere a request destination is influenced by user input, and validate against an allow list rather than a deny list.
- Restrict URL schemes accepted by your HTTP client libraries to HTTP and HTTPS.
- Audit the service accounts attached to internet-facing workloads and reduce their permissions.
- Add detection for metadata server access from web application processes.
- Confirm you would notice instance credentials being used from outside the instance.
Frequently asked questions
Why is SSRF so serious in cloud environments?
Because the metadata server returns access tokens for the workload's service account to anything that can request them from the host. A request forgery therefore becomes credential disclosure without the application being compromised.
What makes the gopher protocol useful to an attacker?
It allows arbitrary bytes to be sent to a host and port rather than a structured HTTP request. That defeats filters reasoning about URLs and permits interaction with services that are not plain HTTP.
How should SSRF be prevented properly?
Validate destinations against an allow list, resolve addresses before connecting so names resolving to internal ranges are rejected, and restrict the schemes your request library accepts. Deny lists of known-bad targets are consistently bypassed.
Do I need my own Google Cloud account to practice this?
No. The lab runs in a live Google Cloud environment that Pwned Labs provisions for you, so there is nothing to set up and no risk to your own project.
Which certification covers this in depth?
The Google Cloud Red Team Professional (GCRTP) covers Google Cloud and Google Workspace attack paths in full, including service account abuse and privilege escalation, and is assessed hands-on in a live Google Cloud environment.
Watch the walkthrough
Want to see the full attack path first? Watch the complete video walkthrough of this lab: Exploit SSRF with Gopher for GCP Initial Access. You can also browse all cloud security lab walkthroughs.
Cloud Security Training To Protect Your Business
Pwned Labs for Business gives your team access to dedicated business content, including labs and cyber ranges.
We also offer in-person or remote workshops, and our cloud penetration services are helping businesses become more secure!