Full Docker Breakout Exploit
A vulnerability in Docker's cp command allowed a malicious or compromised container to load a shared library from the container filesystem, leading to code execution on the host. An attacker could escape the container and gain root control of the host and all other containers.
unit42.paloaltonetworks.com
Published on unit42.paloaltonetworks.com
In the last few years, several vulnerabilities in the copy (cp) command were found in various container platforms, including Docker, Podman and Kubernetes. The most severe among those was only recently discovered and disclosed in July.
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The docker-tar helper process was chrooted into the container but not containerised, and it dynamically loaded shared libraries (libnss_*.so) from the container filesystem, allowing a malicious container to supply a library that executes code with host root privileges.
Impact
An attacker could escape the container and gain root code execution on the host, affecting all other containers; however, running containers as a non-root user prevents the attack because the attacker cannot overwrite the root-owned libraries.
What the attacker needed
A compromised container or malicious image; user runs docker cp from that container; container runs as root (non-root prevents exploit)
The fix
The fix patched docker-tar to load the libnss libraries before chrooting, so they come from the host filesystem; users should upgrade to Docker 19.03.1 or later and avoid running untrusted images.
How it was found
- Build a malicious libnss library with a constructor function that runs on load.
- Place the malicious library in a container image or replace the library in a compromised container.
- Run docker cp to copy files from that container.
- The docker-tar process loads the malicious library and executes the constructor.
- The constructor runs a breakout script that mounts the host filesystem and writes to the host.
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 write-up has not been written yet. The Original tab links to the source.
Docker is a tool that runs applications in isolated boxes called containers. A command to copy files out of a container used a helper program that loaded some system libraries from inside the container instead of from the host. Because those libraries could be replaced by an attacker, the helper program would run the attacker's code with full privileges on the host, breaking the isolation.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.