Docker breakout exploit analysis
A Docker container was granted the CAP_DAC_READ_SEARCH capability, which allowed a process inside the container to use the open_by_handle_at system call to open files on the host filesystem, such as /etc/shadow, by brute-forcing file handles. An attacker with access to such a container could read sensitive host files.
medium.com
Published on medium.com
Recently, an interesting Docker exploit was posted (http://stealth.openwall.net/xSports/shocker.c) that demonstrates an information leak where a Docker container can access some privileged filesystem data where it shouldn’t. As I was just discussing the relative merits of using Docker, and how security is often quoted…
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
Impact
An attacker with access to a container could read sensitive host files such as /etc/shadow, but this only worked in Docker versions before 1.0.0 where the capability was granted by default.
What the attacker needed
Docker version before 1.0.0; Container has CAP_DAC_READ_SEARCH capability; Ability to run code inside the container
The fix
Docker 1.0.0 changed the default to drop all kernel capabilities, so CAP_DAC_READ_SEARCH is no longer granted unless explicitly requested.
How it was found
- Open a file that is bind-mounted from the host, such as /.dockerinit, to get a file descriptor for the host filesystem.
- Use the root inode (2) as a starting file handle and recursively search for the target path by listing directories and brute-forcing the remaining 32 bits of the file handle.
- Once the correct file handle for the target file is found, call open_by_handle_at with that handle to open the file.
- Read the file contents from the returned file descriptor.
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 containers are meant to be isolated from the host computer, like a box inside a box. This report shows that if a container is given a special permission called CAP_DAC_READ_SEARCH, a program inside it can use a system call to open files on the host, such as the file that stores user passwords. The permission was accidentally included by default in old Docker versions, so containers could break out and read host files.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.