Skip to content
Misconfiguration Write-up Advanced

Host MITM attack via IPv6 rogue router advertisements (K8S CVE-2020-10749 / Docker CVE-2020-13401 / LXD / WSL2 / ...)

IPv6 router advertisements sent from a container or WSL2 VM can reconfigure the host's IPv6 routing, allowing the attacker to intercept the host's IPv6 traffic and, via WPAD, part of its IPv4 traffic. An attacker with root in a container or VM could thus man-in-the-middle host traffic.

Etienne Champetier Follow

Published on github.com

Bounty$1,000 View original

IPv6 is enabled by default on most devices and OSs today, and they also accept router advertisements (RA) by default to configure IPv6 IPs, routes and sometimes DNS servers.

Etienne Champetier / champtar, on github.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. 10 min read.

Context

IPv6 is enabled by default on most devices and operating systems today, and those devices also accept router advertisements (RA) by default in order to configure IPv6 addresses, routes and sometimes DNS servers. Any device on the same L2 segment can send router advertisements, but only routers are legitimate senders. To secure networks, most managed switches include a feature called RA-Guard that allows or blocks RA per port.

The container world, as the author puts it, forgot about this attack vector. By sending rogue router advertisements, an attacker can reconfigure the host to redirect part or all of the host's IPv6 traffic to an attacker-controlled container. Even if there was no IPv6 traffic before, when DNS returns both A (IPv4) and AAAA (IPv6) records, many HTTP libraries try IPv6 first and then fall back to IPv4, which gives the attacker an opportunity to respond.

The write-up covers reports sent to the Kubernetes team and to Microsoft. The Docker and LXD reports were very similar to the Kubernetes one.

Setup

The software the author tested, and the outcome for each:

Software Status
Kubernetes Affected, CNI CVE-2020-10749. Calico (CVE-2020-13597), Flannel (PR1298) and Weave Net (CVE-2020-11091) are also affected but were not tested by the author
Docker CVE-2020-13401
LXD Not affected in default config, but some fixes resulted from the report (PR7091, PR7097, PR7098)
Openstack Antispoofing enabled by default, so not affected (the author asked a friend for an iptables rules dump and did some code review)
Microsoft WSL2 Hyper-V has DHCP-Guard and Router-Guard enabled by default, but WSL2, which is based on Hyper-V, does not have those security features enabled

For the Kubernetes proof of concept the author used a POC based on smoltcp that sends router advertisements and implements a dummy HTTP server listening on any IPv6 address. The scenario assumes the attacker is able to run code as root in a normal pod of the cluster.

For the WSL2 proof of concept the testing was done on Microsoft Windows [Version 10.0.19041.172] with Ubuntu 18.04 WSL2. The author only had access to Win10 machines and could not test any Windows server editions.

Finding it

In many Kubernetes network configurations the container network interface is a virtual ethernet link going to the host (a veth interface). In that configuration, an attacker able to run a process as root in a container can send and receive arbitrary packets to the host using the CAP_NET_RAW capability, which is present in the default configuration.

In a Kubernetes cluster with an IPv4 internal network, if IPv6 is not totally disabled on the host (via ipv6.disable=1 on the kernel cmdline), it will be either unconfigured or configured on some interfaces, but it is pretty likely that IPv6 forwarding is disabled, that is /proc/sys/net/ipv6/conf/*/forwarding == 0. Also by default /proc/sys/net/ipv6/conf/*/accept_ra == 1. The combination of these two sysctls means the host accepts router advertisements and configures its IPv6 stack using them.

Because CAP_NET_ADMIN is not present by default in Kubernetes pods, the attacker cannot configure the IPs they want to MITM, cannot use iptables to NAT or REDIRECT the traffic, and cannot use IP_TRANSPARENT. The attacker can however still use CAP_NET_RAW and implement a TCP/IP stack in user space, which is what the smoltcp-based POC does.

On the WSL2 side, the "Hyper-V Virtual Ethernet Adapter" interfaces used for Hyper-V (vEthernet (Default Switch)) and for WSL2 (vEthernet (WSL)) are configured by default with static IPv4 but automatic IPv6. That means any rogue Hyper-V or WSL2 VM can reconfigure the host network using DHCPv6 or IPv6 router advertisements. Using WPAD, an attacker can also intercept part of the IPv4 traffic. The author describes this as "just" an insecure default configuration, but chained with any client RCE it could lead to VM escape to the host. Hyper-V does offer DHCP Guard and Router Guard settings, but the author could not find the equivalent for WSL2.

Exploitation

Kubernetes: sending rogue router advertisements from a pod

The POC recording is available as an asciinema cast:

  1. Download the source of the POC: Cargo.toml and src/main.rs.

  2. Compile it with cargo build --release. You now have a binary called ipv6mitm.

  3. Launch a dummy pod:

    Text
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
      name: ubuntu-pod
    spec:
      containers:
        - name: ubuntu
          image: ubuntu:latest
          command: [ "/bin/sleep", "inf" ]
    EOF
    

    In this scenario the attacker is able to run code as root in a normal pod of the cluster.

  4. Find on which node the ubuntu-pod is running using kubectl get pod -o wide, then ssh into it.

  5. On the node, try curl http://www.google.com -v. Right now you should get a normal response, and you can see in the first few lines that IPv4 was used.

  6. This is the attack part:

    Text
    # copy the ipv6mitm binary
    kubectl cp ipv6mitm ubuntu-pod:/
    # connect to the pod
    kubectl exec -it ubuntu-pod /bin/bash
    # and run the binary
    /ipv6mitm -i eth0
    

    The binary is copied into the pod, a shell is opened inside it, and ipv6mitm is started on the pod's eth0 interface.

  7. On the node, try curl http://www.google.com -v again. You should see that IPv6 was used and the response is just "ok", it came from the container.

WSL2: intercepting IPv6 traffic and part of IPv4 via WPAD

The POC shows how a root user in Ubuntu 18.04 WSL2 can easily intercept all IPv6 traffic, and, using WPAD, part of the IPv4 traffic of the host. The same attack also works from a Hyper-V VM. Two programs are used: mitmproxy, to receive the traffic from the host once it has been configured by WPAD, and rafun, to send the router advertisements and act as a DNS and an HTTP server.

  1. Start a Ubuntu 18.04 WSL2 shell and become root.

  2. Install mitmproxy:

    Text
    apt update
    apt install python3-pip
    pip3 install mitmproxy
    
  3. Build the rafun binary using golang 1.13+ by downloading rafun.go, go.sum and go.mod, then run CGO_ENABLED=0 go build.

  4. Configure an extra IPv6 address on eth0:

    Text
    ip addr add 2001:db8::1/128 dev eth0
    
  5. Configure ip6tables redirect rules to intercept IPv6 HTTP and DNS traffic:

    Text
    ip6tables -t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-ports 80
    ip6tables -t nat -I PREROUTING -i eth0 -p udp --dport 53 -j REDIRECT --to-ports 53
    

    The first rule sends inbound TCP port 80 traffic to the local port 80, the second sends inbound UDP port 53 traffic to the local port 53.

  6. Find the eth0 IPv4 address:

    Text
    ip a
    
  7. Start rafun to intercept IPv6 only:

    Text
    ./rafun -dnsAaddr=
    

    rafun is now sending IPv6 router advertisements with two /1 routes. If the host has IPv6 connectivity, the /1 routes take precedence over the default /0 route and the VM now effectively receives all the IPv6 traffic from the host. The vEthernet (WSL) status page says "IPv6 connectivity: Internet".

  8. On the host, in a PowerShell shell, run:

    Text
    Invoke-WebRequest www.google.com
    Invoke-WebRequest doesntexist.google.com
    Invoke-WebRequest [2001::1]
    

    If the host has no IPv6 connectivity, Windows programs prefer the primary interface's IPv4 connectivity, so the VM only receives DNS requests, but not a lot of traffic to mess with. If DNS requests on the DNS server of the primary interface fail, Windows uses the rafun DNS responses and some traffic is obtained. IPv6 requests always go to the VM, because the host has the two /1 routes. The author then moves on to WPAD.

  9. In a new WSL2 shell, start mitmproxy:

    Text
    mitmproxy -p 8080
    
  10. Stop rafun and start it again with:

    Text
    ./rafun -dnsAaddr= -wpaddat="PROXY :8080"
    

    In step 7 rafun was intentionally failing the WPAD DNS responses, so it might take a bit of time, but at some point the vEthernet (WSL) status page says IPv4/IPv6 connectivity: Internet.

  11. On the host, in a PowerShell shell, run:

    Text
    Invoke-WebRequest www.google.com
    

    The request appears in mitmproxy, meaning the attacker was able to spy on it and, if HTTPS was not used, modify it.

Root cause

The design mistake is that hosts accept router advertisements on interfaces that are attached to untrusted, container-controlled links. On Kubernetes nodes the relevant sysctls are /proc/sys/net/ipv6/conf/*/forwarding == 0 and /proc/sys/net/ipv6/conf/*/accept_ra == 1 by default, so the host accepts RAs and configures its IPv6 stack from them. The pod side needs only CAP_NET_RAW, which is present by default, to send those RAs; the missing CAP_NET_ADMIN does not prevent the attack because a user-space TCP/IP stack can be implemented on top of raw sockets.

On WSL2 the equivalent mistake is the default configuration of the vEthernet (Default Switch) and vEthernet (WSL) adapters: static IPv4 but automatic IPv6. Hyper-V has DHCP Guard and Router Guard, but WSL2 does not have those security features enabled, so a rogue Hyper-V or WSL2 VM can reconfigure the host network with DHCPv6 or router advertisements.

Impact

An attacker who can run a process as root in a container can redirect part or all of the host's IPv6 traffic to the attacker-controlled container. Even with no prior IPv6 traffic, dual-stack DNS answers (A and AAAA) make many HTTP libraries try IPv6 first, giving the attacker a chance to respond. If the host also has a vulnerability such as the previous year's RCE in apt (CVE-2019-3462), the attacker can escalate to the host.

On WSL2, a root user in Ubuntu 18.04 WSL2 can intercept all IPv6 traffic and, using WPAD, part of the IPv4 traffic of the host; the same attack works from a Hyper-V VM. The author frames this as an insecure default configuration that, chained with any client RCE, could lead to VM escape to the host. A VM should not be able to intercept host traffic by default.

Fix

For Kubernetes, the vulnerability can easily be fixed by setting accept_ra = 0 by default on any interface managed by CNI / Kubernetes. The report lists CNI CVE-2020-10749, Calico CVE-2020-13597, Flannel PR1298 and Weave Net CVE-2020-11091 as affected. Docker is listed as CVE-2020-13401. LXD was not affected in its default config, but some fixes resulted from the report (PR7091, PR7097, PR7098). Openstack was already protected by antispoofing enabled by default.

For WSL2, the author notes that changing the default configuration can be hard, but a VM should not be able to intercept host traffic by default. Microsoft confirmed that Hyper-V guests are protected by DHCP and Router Guard, but not WSL2, and decided to treat it as a normal bug rather than an Update Tuesday security bug.

Timeline

  • 2020-03-15: Initial report to the Kubernetes team
  • 2020-03-25: Initial report to the Docker team
  • 2020-03-26: Initial report to the LXD team
  • 2020-04-04: Initial report to the Microsoft team
  • 2020-06-01: Public disclosure for Kubernetes, Docker and many CNIs
  • 2020-06-24: Microsoft confirms that Hyper-V guests are protected by DHCP and Router Guard, but not WSL2, and decides to treat it as a normal bug and not an Update Tuesday security bug

Variants to test

  • Other CNI plugins on Kubernetes. The author lists Calico, Flannel and Weave Net as affected but did not test them.
  • Docker hosts. CVE-2020-13401 was reported for Docker with a report similar to the Kubernetes one.
  • LXD in non-default configurations. LXD is not affected in its default config, but the report led to PR7091, PR7097 and PR7098.
  • Hyper-V VMs and WSL2. The same attack works from a Hyper-V VM, and WSL2 lacks the DHCP Guard and Router Guard that Hyper-V offers.
  • Hosts with dual-stack DNS. Any environment where DNS returns AAAA records alongside A records is worth checking, because many HTTP libraries try IPv6 first.
  • Hosts with a client-side RCE. The author notes that chaining this with a host vulnerability such as CVE-2019-3462 allows escalation to the host.

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

What happened, in plain words

Every device that speaks IPv6 (the newer version of the internet's addressing system) can be told how to reach the rest of the network by a small announcement called a router advertisement, or RA. Think of it like a notice pinned to the building's front door saying "to reach the outside world, go through this corridor". Normally only the real router pins that notice. But on a shared local network, any device can pin a fake one, and most devices will believe it.

Managed network switches have a guard feature, RA-Guard, that blocks fake notices on each port. The container world, as the author puts it, forgot about this attack vector. A container is a lightweight, isolated box running on a machine (the host). If an attacker can run code inside a container, they can send a fake router advertisement to the host and convince it to send part or all of its IPv6 traffic into the container instead of to the real destination. That is a man-in-the-middle (MITM) attack: the attacker sits in the middle, sees the traffic, and can change it.

Even if the host had no IPv6 traffic before, many websites are reachable over both IPv4 (the older addressing system) and IPv6. When a name lookup returns both kinds of address, many programs try IPv6 first and only fall back to IPv4 if that fails. That first attempt is the attacker's chance to answer instead of the real site.

The write-up covers reports sent to the Kubernetes team and to Microsoft. The Docker and LXD reports were very similar to the Kubernetes one.

Setup

Before the attack, it helps to know which software the author tested and what came of each. The table below is the author's own summary.

Software Status
Kubernetes Affected, CNI CVE-2020-10749. Calico (CVE-2020-13597), Flannel (PR1298) and Weave Net (CVE-2020-11091) are also affected but were not tested by the author
Docker CVE-2020-13401
LXD Not affected in default config, but some fixes resulted from the report (PR7091, PR7097, PR7098)
Openstack Antispoofing enabled by default, so not affected (the author asked a friend for an iptables rules dump and did some code review)
Microsoft WSL2 Hyper-V has DHCP-Guard and Router-Guard enabled by default, but WSL2, which is based on Hyper-V, does not have those security features enabled

A few of those names deserve a plain explanation.

  • Kubernetes (often shortened to K8s) is a system for running many containers across many machines and keeping them organised. A pod is the smallest unit it runs: one or more containers that share a network address.
  • CNI stands for Container Network Interface. It is the plug-in that gives pods their network connections. Calico, Flannel and Weave Net are three popular CNI plug-ins.
  • Docker is the best-known tool for building and running containers on a single machine.
  • LXD is a container manager, mostly used on Linux servers.
  • OpenStack is a large platform for running cloud infrastructure.
  • WSL2 is Windows Subsystem for Linux, version 2: it lets you run a real Linux system inside Windows. Hyper-V is Microsoft's virtual machine technology, and WSL2 is built on top of it.
  • A CVE number is a public catalogue entry for a known security flaw, so people can refer to the same bug unambiguously. A PR is a pull request: a proposed change to a software project's code.

For the Kubernetes proof of concept the author used a POC (proof of concept, a small demonstration program) based on smoltcp, a library that implements the TCP/IP networking stack (the software that speaks internet protocols) in user space. The POC sends router advertisements and implements a dummy HTTP server listening on any IPv6 address. The scenario assumes the attacker is able to run code as root in a normal pod of the cluster. Root is the all-powerful administrator account inside that container.

For the WSL2 proof of concept the testing was done on Microsoft Windows [Version 10.0.19041.172] with Ubuntu 18.04 WSL2. The author only had access to Win10 machines and could not test any Windows server editions.

Finding it

Why a pod can talk to its host at all

In many Kubernetes network configurations the container network interface is a virtual ethernet link going to the host, called a veth interface. Picture a short cable with one end plugged into the container and the other into the host; packets cross it in both directions. In that configuration, an attacker able to run a process as root in a container can send and receive arbitrary packets to the host using the CAP_NET_RAW capability, which is present in the default configuration.

A capability is a small permission granted to a process, finer-grained than "root or not root". CAP_NET_RAW means "may craft and send raw network packets", the kind of low-level access a normal program does not need. It is on by default in pods, which is the key enabler here.

Why the host believes the fake router

In a Kubernetes cluster with an IPv4 internal network, if IPv6 is not totally disabled on the host (via ipv6.disable=1 on the kernel cmdline), it will be either unconfigured or configured on some interfaces, but it is pretty likely that IPv6 forwarding is disabled, that is /proc/sys/net/ipv6/conf/*/forwarding == 0. Also by default /proc/sys/net/ipv6/conf/*/accept_ra == 1. The combination of these two sysctls means the host accepts router advertisements and configures its IPv6 stack using them.

Unpacking that paragraph:

  • The kernel cmdline is the list of options the operating system passes to its core (the kernel) at boot. ipv6.disable=1 switches IPv6 off entirely.
  • /proc/sys/net/ipv6/conf/*/forwarding is a setting, one per network interface, that says whether the machine forwards IPv6 packets on behalf of others. 0 means no.
  • /proc/sys/net/ipv6/conf/*/accept_ra is a setting, again per interface, that says whether the machine listens to router advertisements. 1 means yes.
  • A sysctl is simply a kernel setting exposed as a file under /proc/sys; you read or write it like a text file.

So the host is not a router (forwarding off) but is still willing to take routing instructions from anyone who announces themselves as one (accept_ra on). That is the gap.

Why the attacker does not need more permissions

Because CAP_NET_ADMIN is not present by default in Kubernetes pods, the attacker cannot configure the IPs they want to MITM, cannot use iptables to NAT or REDIRECT the traffic, and cannot use IP_TRANSPARENT. The attacker can however still use CAP_NET_RAW and implement a TCP/IP stack in user space, which is what the smoltcp-based POC does.

In plain terms:

  • CAP_NET_ADMIN is the permission to change network configuration: addresses, routes, firewall rules. Pods do not get it by default.
  • iptables is the Linux firewall tool. NAT (network address translation) and REDIRECT are iptables actions that rewrite where traffic goes.
  • IP_TRANSPARENT is a socket option that lets a program accept traffic addressed to an IP that is not its own, a classic trick for intercepting traffic.
  • A user-space TCP/IP stack is a program that handles internet protocols itself, in ordinary application code, instead of relying on the operating system's built-in networking. With raw packet access, that is enough to answer traffic without any of the admin permissions above.

The WSL2 side

On the WSL2 side, the "Hyper-V Virtual Ethernet Adapter" interfaces used for Hyper-V (vEthernet (Default Switch)) and for WSL2 (vEthernet (WSL)) are configured by default with static IPv4 but automatic IPv6. That means any rogue Hyper-V or WSL2 VM can reconfigure the host network using DHCPv6 or IPv6 router advertisements. Using WPAD, an attacker can also intercept part of the IPv4 traffic. The author describes this as "just" an insecure default configuration, but chained with any client RCE it could lead to VM escape to the host. Hyper-V does offer DHCP Guard and Router Guard settings, but the author could not find the equivalent for WSL2.

Some of those terms:

  • A virtual ethernet adapter is a pretend network card that exists only in software. vEthernet (Default Switch) and vEthernet (WSL) are the names Windows gives to the two the author looked at.
  • Static IPv4 means the IPv4 address is fixed by hand; automatic IPv6 means the IPv6 settings are learned from the network, which is exactly the door the attack walks through.
  • DHCPv6 is the IPv6 version of the protocol that hands out network settings automatically.
  • WPAD (Web Proxy Auto-Discovery) is a mechanism where a machine asks the network "is there a proxy I should send my web traffic through?" and then obeys the answer. If the attacker can answer that question, they become the proxy.
  • RCE means remote code execution: someone else manages to run their own code on your machine. VM escape means getting out of a virtual machine onto the machine that hosts it.

Exploitation

Kubernetes: sending rogue router advertisements from a pod

The POC recording is available as an asciinema cast:

An asciinema cast is a recording of a terminal session that plays back like a video, showing the commands typed and their output.

  1. Download the source of the POC: Cargo.toml and src/main.rs.

    Cargo.toml is the project description file for Rust's build tool, Cargo; src/main.rs is the program's source code. Rust is the programming language the POC is written in.

  2. Compile it with cargo build --release. You now have a binary called ipv6mitm.

    Compiling turns source code into a runnable program. --release asks for an optimised build. The result is a single executable file named ipv6mitm.

  3. Launch a dummy pod:

    Text
    kubectl apply -f - <<'EOF'
    apiVersion: v1
    kind: Pod
    metadata:
      name: ubuntu-pod
    spec:
      containers:
        - name: ubuntu
          image: ubuntu:latest
          command: [ "/bin/sleep", "inf" ]
    EOF
    

    Line by line:

    • kubectl apply -f - tells the Kubernetes command-line tool to create whatever is described in a file, and the - means "read that file from standard input", i.e. from what follows.
    • <<'EOF' starts a here-document: everything up to the line EOF is fed in as that input.
    • apiVersion: v1 says which version of the Kubernetes object format is being used.
    • kind: Pod says the object being created is a pod.
    • metadata: holds identifying details; name: ubuntu-pod names this pod ubuntu-pod.
    • spec: describes what should run; under containers: there is one container, name: ubuntu, built from the ubuntu:latest image (a ready-made Ubuntu filesystem).
    • command: [ "/bin/sleep", "inf" ] makes the container run the sleep program with the argument inf, meaning "sleep forever". The container stays alive doing nothing, which is all the demonstration needs.
    • EOF closes the here-document.

    In this scenario the attacker is able to run code as root in a normal pod of the cluster.

  4. Find on which node the ubuntu-pod is running using kubectl get pod -o wide, then ssh into it.

    A node is one of the physical or virtual machines that make up a Kubernetes cluster. kubectl get pod -o wide lists pods with extra columns, including which node each one is on. ssh is the standard way to open a command shell on a remote machine.

  5. On the node, try curl http://www.google.com -v. Right now you should get a normal response, and you can see in the first few lines that IPv4 was used.

    curl is a command-line web client: it fetches a URL and prints what comes back. -v means verbose, so it also prints details of the connection. This step is the baseline: before the attack, the host reaches the site normally over IPv4.

  6. This is the attack part:

    Text
    # copy the ipv6mitm binary
    kubectl cp ipv6mitm ubuntu-pod:/
    # connect to the pod
    kubectl exec -it ubuntu-pod /bin/bash
    # and run the binary
    /ipv6mitm -i eth0
    

    Line by line:

    • The lines starting with # are comments, notes for the reader, not commands.
    • kubectl cp ipv6mitm ubuntu-pod:/ copies the compiled program from wherever it was built into the root directory of the pod's filesystem.
    • kubectl exec -it ubuntu-pod /bin/bash runs a command inside the pod; -it asks for an interactive terminal, and the command is the bash shell. You now have a shell inside the container.
    • /ipv6mitm -i eth0 starts the attack program, telling it to work on the interface named eth0, which inside the pod is the veth link towards the host.

    The binary is copied into the pod, a shell is opened inside it, and ipv6mitm is started on the pod's eth0 interface, which is the veth link towards the host.

  7. On the node, try curl http://www.google.com -v again. You should see that IPv6 was used and the response is just "ok", it came from the container.

    The same command as the baseline now behaves differently: IPv6 was used and the response is just "ok", it came from the container.

WSL2: intercepting IPv6 traffic and part of IPv4 via WPAD

The POC shows how a root user in Ubuntu 18.04 WSL2 can easily intercept all IPv6 traffic, and, using WPAD, part of the IPv4 traffic of the host. The same attack also works from a Hyper-V VM. Two programs are used: mitmproxy, to receive the traffic from the host once it has been configured by WPAD, and rafun, to send the router advertisements and act as a DNS and an HTTP server.

  • mitmproxy is an interactive proxy: a program that sits between a client and the internet, showing and optionally editing the traffic that passes through it.
  • rafun is the author's own program for this demonstration. It sends the fake router advertisements and also answers DNS (name lookup) and HTTP (web) requests.
  1. Start a Ubuntu 18.04 WSL2 shell and become root.

    Root is needed because the steps below change network settings.

  2. Install mitmproxy:

    Text
    apt update
    apt install python3-pip
    pip3 install mitmproxy
    

    Line by line:

    • apt update refreshes the list of available software packages on Ubuntu.
    • apt install python3-pip installs pip, Python's package installer.
    • pip3 install mitmproxy downloads and installs mitmproxy itself.
  3. Build the rafun binary using golang 1.13+ by downloading rafun.go, go.sum and go.mod, then run CGO_ENABLED=0 go build.

    Golang (Go) is a programming language. rafun.go is its source code; go.mod and go.sum describe the project and its dependencies. CGO_ENABLED=0 turns off a feature that links Go code to C libraries, producing a self-contained program; go build compiles it.

  4. Configure an extra IPv6 address on eth0:

    Text
    ip addr add 2001:db8::1/128 dev eth0
    

    Line by line:

    • ip addr add adds an address to a network interface.
    • 2001:db8::1/128 is the IPv6 address being added. The /128 means it is a single address, not a range. (The 2001:db8:: block is reserved for documentation examples, so it is safe to show.)
    • dev eth0 says which interface gets it.

    This gives the attacker's machine an address it can use when answering the host.

  5. Configure ip6tables redirect rules to intercept IPv6 HTTP and DNS traffic:

    Text
    ip6tables -t nat -I PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-ports 80
    ip6tables -t nat -I PREROUTING -i eth0 -p udp --dport 53 -j REDIRECT --to-ports 53
    

    Line by line:

    • ip6tables is the IPv6 version of the Linux firewall tool.
    • -t nat selects the table used for address and port rewriting.
    • -I PREROUTING inserts the rule at the top of the chain that sees packets as they arrive, before any routing decision.
    • -i eth0 limits it to packets arriving on eth0.
    • -p tcp --dport 80 matches TCP traffic destined for port 80, the standard web (HTTP) port.
    • -j REDIRECT --to-ports 80 sends that traffic to port 80 on the local machine instead.
    • The second rule does the same for -p udp --dport 53, UDP port 53, the standard DNS (name lookup) port, redirecting to local port 53.

    The first rule sends inbound TCP port 80 traffic to the local port 80, the second sends inbound UDP port 53 traffic to the local port 53.

  6. Find the eth0 IPv4 address:

    Text
    ip a
    

    ip a is short for ip address show: it lists every network interface with its addresses. The IPv4 address found here is needed for the WPAD step later.

  7. Start rafun to intercept IPv6 only:

    Text
    ./rafun -dnsAaddr=
    

    Line by line:

    • ./rafun runs the program in the current directory.
    • -dnsAaddr= sets the IPv4 address that rafun would hand out in DNS answers to an empty value, so for now it does not offer an IPv4 address and only IPv6 is intercepted.

    rafun is now sending IPv6 router advertisements with two /1 routes. If the host has IPv6 connectivity, the /1 routes take precedence over the default /0 route and the VM now effectively receives all the IPv6 traffic from the host. The vEthernet (WSL) status page says "IPv6 connectivity: Internet".

    A route is an instruction of the form "traffic for this range of addresses should go that way". The default route, written /0, covers the whole internet. A /1 route covers half of it, and two /1 routes together cover everything while being more specific than /0, so they win. That is how the attacker quietly becomes the preferred path.

  8. On the host, in a PowerShell shell, run:

    Text
    Invoke-WebRequest www.google.com
    Invoke-WebRequest doesntexist.google.com
    Invoke-WebRequest [2001::1]
    

    Line by line:

    • Invoke-WebRequest is PowerShell's built-in command for fetching a web page.
    • www.google.com is a real site, so this tests ordinary web traffic.
    • doesntexist.google.com is a name that should not resolve, so this tests what happens when a name lookup fails.
    • [2001::1] is an IPv6 address in square brackets, so this tests a direct IPv6 connection.

    If the host has no IPv6 connectivity, Windows programs prefer the primary interface's IPv4 connectivity, so the VM only receives DNS requests, but not a lot of traffic to mess with. If DNS requests on the DNS server of the primary interface fail, Windows uses the rafun DNS responses and some traffic is obtained. IPv6 requests always go to the VM, because the host has the two /1 routes. The author then moves on to WPAD.

  9. In a new WSL2 shell, start mitmproxy:

    Text
    mitmproxy -p 8080
    

    Line by line:

    • mitmproxy starts the proxy program.
    • -p 8080 makes it listen on port 8080, the port the WPAD answer will point the host at.
  10. Stop rafun and start it again with:

    Text
    ./rafun -dnsAaddr= -wpaddat="PROXY :8080"
    

    Line by line:

    • ./rafun runs the program again.
    • -dnsAaddr= keeps the IPv4 DNS answer empty, as before.
    • -wpaddat="PROXY :8080" is the text rafun will return when the host asks for its WPAD configuration. PROXY tells the client to use a proxy, and :8080 gives the port; the address part is left blank in the text as shown.

    In step 7 rafun was intentionally failing the WPAD DNS responses, so it might take a bit of time, but at some point the vEthernet (WSL) status page says IPv4/IPv6 connectivity: Internet.

    At some point the vEthernet (WSL) status page says IPv4/IPv6 connectivity: Internet.

  11. On the host, in a PowerShell shell, run:

    Text
    Invoke-WebRequest www.google.com
    

    Line by line:

    • Invoke-WebRequest fetches the page, as before.
    • www.google.com is the site being fetched.

    The request appears in mitmproxy, meaning the attacker was able to spy on it and, if HTTPS was not used, modify it.

    The request appears in mitmproxy, meaning the attacker was able to spy on it.

Root cause

The design mistake is that hosts accept router advertisements on interfaces that are attached to untrusted, container-controlled links. On Kubernetes nodes the relevant sysctls are /proc/sys/net/ipv6/conf/*/forwarding == 0 and /proc/sys/net/ipv6/conf/*/accept_ra == 1 by default, so the host accepts RAs and configures its IPv6 stack from them. The pod side needs only CAP_NET_RAW, which is present by default, to send those RAs; the missing CAP_NET_ADMIN does not prevent the attack because a user-space TCP/IP stack can be implemented on top of raw sockets.

A raw socket is a way for a program to send and receive network packets directly, without the operating system shaping them first. That is exactly what CAP_NET_RAW allows, and it is why the missing admin permission does not stop the attacker.

On WSL2 the equivalent mistake is the default configuration of the vEthernet (Default Switch) and vEthernet (WSL) adapters: static IPv4 but automatic IPv6. Hyper-V has DHCP Guard and Router Guard, but WSL2 does not have those security features enabled, so a rogue Hyper-V or WSL2 VM can reconfigure the host network with DHCPv6 or router advertisements.

A managed switch is a physical box that connects machines together and can enforce rules per port; a virtual interface inside one machine never passes through such a switch, so the guard never gets a chance to act.

Impact

An attacker who can run a process as root in a container can redirect part or all of the host's IPv6 traffic to the attacker-controlled container. Even with no prior IPv6 traffic, dual-stack DNS answers (A and AAAA) make many HTTP libraries try IPv6 first, giving the attacker a chance to respond. If the host also has a vulnerability such as the previous year's RCE in apt (CVE-2019-3462), the attacker can escalate to the host.

A dual-stack network or name lookup returns both kinds of address: an A record for IPv4 and an AAAA record for IPv6. apt is Ubuntu's package manager, the program that installs and updates software; the referenced flaw was a way to run code through it. Escalate means moving from a limited foothold (a container) to a bigger one (the host itself).

On WSL2, a root user in Ubuntu 18.04 WSL2 can intercept all IPv6 traffic and, using WPAD, part of the IPv4 traffic of the host; the same attack works from a Hyper-V VM. The author frames this as an insecure default configuration that, chained with any client RCE, could lead to VM escape to the host. A VM should not be able to intercept host traffic by default.

Fix

For Kubernetes, the vulnerability can easily be fixed by setting accept_ra = 0 by default on any interface managed by CNI / Kubernetes. In plain words: tell the host to stop listening to router advertisements on the links that lead to containers. The report lists CNI CVE-2020-10749, Calico CVE-2020-13597, Flannel PR1298 and Weave Net CVE-2020-11091 as affected. Docker is listed as CVE-2020-13401. LXD was not affected in its default config, but some fixes resulted from the report (PR7091, PR7097, PR7098). Openstack was already protected by antispoofing enabled by default.

Antispoofing means the platform refuses packets that claim to come from an address the sender does not own, which blocks this kind of impersonation before it starts.

For WSL2, the author notes that changing the default configuration can be hard, but a VM should not be able to intercept host traffic by default. Microsoft confirmed that Hyper-V guests are protected by DHCP and Router Guard, but not WSL2, and decided to treat it as a normal bug rather than an Update Tuesday security bug. Update Tuesday (also called Patch Tuesday) is Microsoft's regular monthly day for releasing security fixes; treating something as a normal bug means it does not get that special, widely announced treatment.

Timeline

  • 2020-03-15: Initial report to the Kubernetes team
  • 2020-03-25: Initial report to the Docker team
  • 2020-03-26: Initial report to the LXD team
  • 2020-04-04: Initial report to the Microsoft team
  • 2020-06-01: Public disclosure for Kubernetes, Docker and many CNIs
  • 2020-06-24: Microsoft confirms that Hyper-V guests are protected by DHCP and Router Guard, but not WSL2, and decides to treat it as a normal bug and not an Update Tuesday security bug

Public disclosure is the moment the details become visible to everyone, usually after the vendor has had time to fix the problem.

Variants to test

If you want to look for the same weakness elsewhere, these are the directions the author points at. Each one names what a positive result looks like, so you know when you have found something.

  • Other CNI plugins on Kubernetes. The author lists Calico, Flannel and Weave Net as affected but did not test them.
  • Docker hosts. CVE-2020-13401 was reported for Docker with a report similar to the Kubernetes one.
  • LXD in non-default configurations. LXD is not affected in its default config, but the report led to PR7091, PR7097 and PR7098.
  • Hyper-V VMs and WSL2. The same attack works from a Hyper-V VM, and WSL2 lacks the DHCP Guard and Router Guard that Hyper-V offers.
  • Hosts with dual-stack DNS. Any environment where DNS returns AAAA records alongside A records is worth checking, because many HTTP libraries try IPv6 first.
  • Hosts with a client-side RCE. The author notes that chaining this with a host vulnerability such as CVE-2019-3462 allows escalation to the host.

Glossary

  • AAAA record: a DNS entry that maps a name to an IPv6 address.
  • A record: a DNS entry that maps a name to an IPv4 address.
  • accept_ra: a per-interface kernel setting that says whether the machine listens to router advertisements; 1 means yes.
  • Antispoofing: a platform rule that rejects packets claiming to come from an address the sender does not own.
  • apt: Ubuntu's package manager, used to install and update software.
  • asciinema cast: a recording of a terminal session that plays back like a video.
  • CAP_NET_ADMIN: a Linux capability granting permission to change network configuration such as addresses, routes and firewall rules.
  • CAP_NET_RAW: a Linux capability granting permission to craft and send raw network packets.
  • Capability: a small, specific permission granted to a process, finer-grained than being root.
  • CNI: Container Network Interface, the plug-in that gives Kubernetes pods their networking.
  • Container: a lightweight, isolated box running an application on a shared machine.
  • CVE: a public catalogue number for a known security flaw.
  • DHCP Guard: a Hyper-V setting that blocks unauthorised DHCP servers on a virtual network.
  • DHCPv6: the IPv6 protocol that hands out network settings automatically.
  • DNS: the system that turns names like www.google.com into network addresses.
  • Docker: a tool for building and running containers on a single machine.
  • Dual-stack: supporting both IPv4 and IPv6 at the same time.
  • Escalate: to move from a limited foothold to a bigger one, for example from a container to its host.
  • eth0: the conventional name of the first network interface on a Linux machine.
  • forwarding: a kernel setting that says whether the machine passes network traffic on behalf of others.
  • Golang (Go): a programming language, used here to write rafun.
  • Host: the machine that runs containers or virtual machines.
  • HTTP: the protocol browsers use to fetch web pages.
  • HTTPS: HTTP with encryption, so a middleman can see that traffic happened but not read or change it.
  • Hyper-V: Microsoft's virtual machine technology.
  • Interface: a network connection point on a machine, physical or virtual.
  • ip6tables: the IPv6 version of the Linux firewall tool.
  • iptables: the Linux firewall tool, used to filter or rewrite traffic.
  • IP_TRANSPARENT: a socket option that lets a program accept traffic addressed to an IP that is not its own.
  • IPv4: the older internet addressing system, with addresses like 192.0.2.1.
  • IPv6: the newer internet addressing system, with addresses like 2001:db8::1.
  • Kernel cmdline: the options passed to the operating system's core at boot.
  • Kubernetes (K8s): a system for running and organising many containers across many machines.
  • LXD: a container manager, mostly used on Linux servers.
  • Man-in-the-middle (MITM): an attack where the attacker sits between two parties, seeing and possibly changing their traffic.
  • mitmproxy: an interactive proxy program that shows and can edit traffic passing through it.
  • NAT: network address translation, rewriting addresses in packets as they pass.
  • Node: one machine in a Kubernetes cluster.
  • OpenStack: a platform for running cloud infrastructure.
  • Pod: the smallest unit Kubernetes runs, one or more containers sharing a network address.
  • POC: proof of concept, a small demonstration that an attack works.
  • PowerShell: Microsoft's command-line shell and scripting tool on Windows.
  • PR (pull request): a proposed change to a software project's code.
  • Proxy: a program that sits between a client and the internet and relays traffic.
  • RA (router advertisement): a network announcement telling devices how to reach the rest of the network.
  • RA-Guard: a switch feature that blocks router advertisements on ports where they should not appear.
  • rafun: the author's demonstration program that sends fake router advertisements and answers DNS and HTTP.
  • Raw socket: a way for a program to send and receive network packets directly, without the operating system shaping them.
  • RCE: remote code execution, running your own code on someone else's machine.
  • REDIRECT: an iptables action that sends traffic to a different local port.
  • Root: the all-powerful administrator account on a Linux system.
  • Route: an instruction saying which way traffic for a range of addresses should go.
  • Router Guard: a Hyper-V setting that blocks unauthorised router advertisements on a virtual network.
  • smoltcp: a library that implements the TCP/IP networking stack in user space, used by the Kubernetes POC.
  • ssh: the standard way to open a command shell on a remote machine.
  • Static IPv4: an IPv4 address fixed by hand rather than learned automatically.
  • Sysctl: a kernel setting exposed as a file under /proc/sys.
  • TCP/IP stack: the software that speaks internet protocols; it can live in the operating system or in a user-space program.
  • Update Tuesday: Microsoft's regular monthly day for releasing security fixes.
  • User space: ordinary application code, as opposed to code running inside the operating system's core.
  • veth interface: a virtual ethernet link, one end in a container and the other on the host.
  • Virtual ethernet adapter: a pretend network card that exists only in software.
  • VM (virtual machine): a whole computer simulated in software, running its own operating system.
  • VM escape: getting out of a virtual machine onto the machine that hosts it.
  • WPAD: Web Proxy Auto-Discovery, a mechanism where a machine asks the network which proxy to use and then obeys the answer.
  • WSL2: Windows Subsystem for Linux, version 2, which runs a real Linux system inside Windows on top of Hyper-V.

More by Etienne Champetier

View all

4 more disclosed reports, best first.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.