Course contentsShow
← Security
Lesson 2148 of 3,05242. Penetration Testing and Red TeamingFree lesson

Container Escape for Privilege Escalation

Breaking out of Docker containers through misconfigurations, privileged containers, or exposed sockets.

Container Escape for Privilege Escalation

What you'll learn: How attackers break out of Docker containers to gain root access on the host system by exploiting misconfigurations and design weaknesses.

The Core Concept

Containers provide isolation, but they're not virtual machines—they share the host kernel. Think of containers like separate apartments in a building: they feel isolated, but they share fundamental infrastructure (plumbing, electrical, foundation). If you find a gap in the walls or a maintenance door, you can access areas you shouldn't.

Container escape means breaking out of this isolation to gain control of the host operating system, typically with root privileges. This turns a compromised container into full system compromise.

Common Escape Vectors

Privileged Containers

Running containers with --privileged flag disables most security barriers. It's like giving an apartment tenant master keys to the entire building. Privileged containers can access all host devices and lack AppArmor/SELinux restrictions.

Exposed Docker Socket

Mounting /var/run/docker.sock inside a container gives that container control over Docker itself. An attacker can spawn a new privileged container with the host filesystem mounted, then execute commands on the host.

Vulnerable Capabilities

Linux capabilities grant specific privileges. The CAP_SYS_ADMIN capability is particularly dangerous—it allows mounting filesystems, loading kernel modules, and other host-level operations that can be chained for escape.

Kernel Exploits

Since containers share the host kernel, kernel vulnerabilities can be exploited from within containers to gain root on the host, bypassing container isolation entirely.

Why This Matters

Many organizations assume containers provide security boundaries, but misconfigurations turn them into privilege escalation opportunities. Attackers routinely check for privileged mode, mounted sockets, and excessive capabilities during post-exploitation enumeration.

Key Takeaway: Container isolation depends on proper configuration—privileged mode, exposed Docker sockets, and dangerous capabilities can all provide paths from container compromise to full host root access.