Skip to content
SSRF Disclosed report Advanced CVE-2020-8562

Bypass apiserver proxy filter

The Kubernetes apiserver validated a node's hostname with one DNS lookup but then used a second lookup when proxying the request, so a custom DNS server could return a safe address first and an internal address second. An attacker who could create a node and send requests through the apiserver proxy could reach cloud metadata endpoints or localhost services.

javierprovecho Follow

Originally disclosed on HackerOne

Medium 6.8 View original
  • Triaged in 10 days
  • Fixed in 12 months
  • Paid in 15 days
  • Disclosed after 13 months

Summary by the researcher

TL,DR: Time-of-check (apiserver proxy filter) Time-of-use (apiserver proxy request) Race Condition.

The report

Report Submission Form

Summary:

TL,DR: Time-of-check (apiserver proxy filter) Time-of-use (apiserver proxy request) Race Condition.

When the apiserver is proxying a request to a node though one of its addresses, it performs a filter validation. If the address type is a DNS record (Hostname, ExternalDNS, InternalDNS), the apiserver performs two DNS queries, one for filter validation, another for proxying the request. If the attacker sets the hostname to a custom DNS server, that is able return different values with zero TTL, it is possible to bypass that filter.

Kubernetes Version:

1.18.0

Steps To Reproduce:

Preparation

  1. Create a server with port UDP/53 (DNS) exposed.
  2. Delegate a subdomain (e.g. fake.example.com) to the IP address of the server as a NS record.
  3. Copy, build and run the custom DNS server (source code attached, use go mod init and go mod tidy).
  4. Test that it successfully resolves any subdomain of the delegated zone (e.g. toctou.fake.example.com).

Execution

  1. Create a KIND cluster (manifest attached, defaults to v1.17).
  2. Create a Node (manifest attached, edit to change domain).
  3. Start kubectl proxy.
  4. Execute curl localhost:8001/api/v1/nodes/toctou:80/proxy/.

Supporting Material/References:

  • toctou-cluster.yml, a KIND cluster manifest
  • toctou-node.yml, a Node with a custom address.
  • toctou-dns-server.go, a custom DNS server that returns different results to consecutive queries.

Impact

https://github.com/kubernetes/kubernetes/pull/71980 was merged to mitigate dangerous proxying through the apiserver. An attacker with access to create nodes and send requests to them through apiserver proxy, could access cloud metadata endpoints or localhost services. This is specially important on as a service providers like https://github.com/oneinfra/oneinfra but could affect any vendor.

The original report as published on HackerOne, by javierprovecho. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The apiserver performed a time-of-check DNS lookup for filter validation and a separate time-of-use DNS lookup for the proxy request, allowing a custom DNS server to return different answers.

Impact

An attacker with permission to create nodes and send requests through the apiserver proxy could access cloud metadata endpoints or localhost services.

What the attacker needed

Ability to create nodes; ability to send requests through apiserver proxy; control of a DNS server for a delegated subdomain

The fix

A pull request was merged to mitigate dangerous proxying through the apiserver.

How it was found

  1. Set up a DNS server on UDP port 53.
  2. Delegate a subdomain to that server with an NS record.
  3. Run a custom DNS server that returns different answers to consecutive queries.
  4. Create a KIND cluster and a Node whose address uses the delegated hostname.
  5. Start kubectl proxy.
  6. Send a request through the apiserver proxy to the node's hostname.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When Kubernetes forwards a request to a node, it first checks the node's address to make sure it is not pointing at something internal. The report shows that check and the actual forwarding used two separate DNS lookups, so a malicious DNS server could give a harmless answer to the check and an internal address to the forwarding. That let an attacker reach services that should not be reachable from outside.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

More from Kubernetes

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.