Skip to content
Pwnversity
LIN-DOCKERadvanced · 6 min · upd. 2026-10

Container and Docker Escapes

T1611

Containers (Docker, containerd, LXC) isolate processes, but that isolation is weaker than a VM’s: they share the host’s kernel. For an attacker there are two key scenarios: being in a host’s docker group (= trivial root on the host) or being inside a container and wanting to escape to the host. Both are very common escalation vectors, especially on development and CI/CD servers.

flowchart TD
    A{Where am I?} -->|docker/lxd group| B["Mount host / in a container"]
    A -->|inside a container| C{How confined?}
    C -->|--privileged| D["Mount host disk /dev/sdaX"]
    C -->|docker.sock mounted| E["Control the host daemon"]
    C -->|cap_sys_admin| F["cgroups release_agent"]
    C -->|vulnerable kernel| G["Kernel exploit"]
    B & D & E & F & G --> H["root on the host"]

The container boundary is the shared kernel plus a set of restrictions (namespaces, cgroups, capabilities, seccomp, AppArmor). The attacker gains the host if any restriction is missing: belonging to the docker group (daemon control), a privileged container (host device access), the Docker socket mounted inside, excess capabilities, or a vulnerable kernel. The impact of an escape is total: root on the node, and from there to the rest of the containers and the network.

A container is an ordinary host process with restricted views (PID, net, mount, user namespaces) and limits (cgroups). There’s no hypervisor: if the process manages to access host resources (its disk, its daemon, its kernel), the isolation breaks. The two broad classes are misconfiguration (privileged, socket, caps, mounts) and runtime or kernel vulnerability.

Scenario 1 — being in the docker group (= root)

Section titled “Scenario 1 — being in the docker group (= root)”

If your user is in the docker group, you launch a container with the host filesystem mounted → trivial root. It isn’t an “escape”: the docker group equals root by design.

Ventana de terminal
id # docker/lxd in the groups?
docker run -v /:/mnt --rm -it alpine chroot /mnt sh # root over the host FS

Same with lxd/lxc: add an image and launch a privileged container mounting the host /.

Scenario 2 — am I in a container and how confined?

Section titled “Scenario 2 — am I in a container and how confined?”
Ventana de terminal
cat /proc/1/cgroup; ls -la /.dockerenv # am I in a container?
capsh --print; grep Cap /proc/self/status # process capabilities
mount; cat /proc/mounts # mounts (host paths?)

Has almost all capabilities and access to the host’s devices → easy escape:

Ventana de terminal
fdisk -l # see host disks
mount /dev/sda1 /mnt && chroot /mnt sh # mount the host disk
# alternative: abuse cgroups release_agent to execute on the host

If /var/run/docker.sock is mounted inside the container, you control the host daemon → equivalent to root:

Ventana de terminal
ls -la /var/run/docker.sock
docker -H unix:///var/run/docker.sock run -v /:/mnt --rm -it alpine chroot /mnt sh

CAP_SYS_ADMIN (mounts, cgroups v1 release_agent) is the most dangerous. The others depend on what the container can see: CAP_SYS_PTRACE only reaches host processes if it shares the host PID namespace (--pid=host); CAP_DAC_READ_SEARCH (the shocker technique) only reads the host FS if host inodes are reachable. In other words, they open escape paths depending on the container’s namespaces and mounts, not on their own. See capabilities.

  • runC — CVE-2019-5736: overwrite the host’s runc binary from a container → escape when docker exec runs.
  • CVE-2022-0492: cgroups v1 release_agent with cap_sys_admin → escape.
  • Dirty Pipe / Dirty COW: if the kernel is vulnerable, escape via kernel (see Kernel Exploits).
  • deepce.sh: enumerates and automates container escapes.
  • amicontained: which capabilities/seccomp/restrictions I have.
  • linpeas in container mode.
  • auditd/Falco: mount of host devices inside a container, writes to /var/run/docker.sock, module loads, chroot to host mounts, changes to the runc binary.
  • Container telemetry (runtime security, eBPF): processes breaking the namespace, nsenter, access to the host’s /proc/1/root.
  • Correlate anomalous Docker daemon spawns in the SIEM.
  • Don’t add users to the docker group without understanding it equals root; use scoped sudo or rootless Docker.
  • No --privileged except in extreme need; don’t mount docker.sock inside containers.
  • Drop capabilities (--cap-drop ALL and add only what’s needed), seccomp/AppArmor by default, non-root user (USER), read-only rootfs.
  • User namespaces (remap root), don’t mount sensitive host paths.
  • Patch the runtime (runc) and kernel; scan images; least privilege in CI/CD. See Container security.

A confirmed escape compromises the whole node: isolate the host, review the other containers, rotate cluster secrets, and rebuild.

  • Am I in the docker/lxd group? → trivial root on the host
  • Am I in a container? (/.dockerenv, /proc/1/cgroup)
  • Privileged? capabilities and mounts (capsh/amicontained)
  • Is docker.sock mounted inside?
  • Host disk accessible (/dev/sdaX) → mount/chroot
  • Dangerous capabilities → release_agent/cgroups
  • Runtime CVEs (runc CVE-2019-5736, CVE-2022-0492)
  • Blue: cap-drop, seccomp, no privileged, no socket, rootless?