Container escape techniques

Container Escape Techniques

What Makes Container Escape Dangerous

Container escape techniques exploit misconfigurations, vulnerabilities, or design flaws in containerization technologies to break out of isolated container environments and gain access to the host system. Successful escapes can lead to complete host compromise, access to other containers, and potential lateral movement within container orchestration platforms.

The Attack Principle: Exploit scenarios where:

  • Containers run with excessive privileges or capabilities

  • Host resources are improperly mounted into containers

  • Container runtime vulnerabilities allow breakout

  • Orchestration platforms have security misconfigurations

  • Shared namespaces provide access to host resources

Why This Works: Containers share the host kernel and rely on namespace isolation. Misconfigurations or privilege escalations can break this isolation, allowing access to host resources and other containers.

Container Environment Discovery and Enumeration

Identifying Container Environment

Basic Container Detection:

# Check if running in container
ls -la /.dockerenv
cat /proc/1/cgroup | grep docker
cat /proc/self/cgroup | grep docker

# Check for container runtime
ps aux | grep -E "(docker|containerd|runc)"
ls -la /var/run/docker.sock

# Check container metadata
env | grep -i container
cat /proc/version
uname -a

Container Information Gathering:

Network and Process Analysis:

High-Value Container Escape Techniques

Docker Socket Escape

Why Docker Socket is Critical: Access to Docker socket allows full container management and host access.

Docker Socket Detection:

Docker Socket Exploitation:

Privileged Container Escape

Privileged Container Detection:

Privileged Escape via /proc:

Privileged Escape via Device Access:

Capability-Based Escape

CAP_SYS_ADMIN Escape:

Volume Mount Escape

Host Path Mount Detection:

Volume Mount Exploitation:

Kubernetes Pod Escape

Service Account Token Abuse

Service Account Discovery:

Pod Security Context Abuse

Privileged Pod Detection:

Host Namespace Access:

Real-World Container Escape Examples

Example 1: Docker Socket Mount

Discovery:

Exploitation:

Example 2: Privileged Container with CAP_SYS_ADMIN

Discovery:

Exploitation:

Key Operational Considerations

Success Indicators

  • Docker socket access providing full container control

  • Privileged container with host namespace access

  • Dangerous capabilities enabling host filesystem access

  • Host path mounts allowing direct host manipulation

  • Kubernetes API access with pod creation permissions

Common Failure Points

  • Security contexts preventing privileged operations

  • AppArmor/SELinux blocking container escapes

  • Network policies restricting API server access

  • Resource quotas preventing pod creation

  • Runtime security detecting escape attempts

Exploitation Notes

  • Development environments often have relaxed container security

  • Legacy containers may run with excessive privileges

  • Kubernetes misconfigurations frequently provide escape opportunities

  • Monitoring gaps may miss container escape activities

Container escape techniques are particularly effective in environments where container security best practices are not implemented, providing direct paths to host compromise and lateral movement within containerized infrastructures.

Last updated

Was this helpful?