
Container Security
Container security including Docker escape techniques, containerization fundamentals, and hardening best practices for penetration testing and security assessments.
Overview
Most modern applications ship in containers, and a container is only as isolated as its configuration. On cloud-native and DevOps engagements you will regularly land inside one, and the question becomes whether you can reach the host or the orchestrator from there. These notes cover how the isolation works, how to break out of Docker, and how to lock it down.
Container fundamentals
- Containerization fundamentals: namespaces, cgroups, capabilities and the other kernel features that do the isolating
Container escape
- Docker container escape: getting from inside a Docker container to the host
Container hardening
- Container hardening: configuration for container deployments and orchestration that shuts those escapes down
Attack methodology
Phase 1: enumerate the container
- Identify the runtime (Docker, Podman, containerd)
- Check capabilities and the security context
- Review mounted volumes and host paths
- Map container networking
- Check whether the container is privileged
- Look for access to the Docker socket
Phase 2: find the weakness
- Misconfigured security settings
- Privileged mode or dangerous capabilities
- A mounted Docker socket
- Secrets in environment variables or files
- A host kernel version with a known escape exploit
- Vulnerable packages in the image
Phase 3: exploitation
- Escape through a privileged container
- Abuse a mounted Docker socket
- Exploit dangerous capabilities (CAP_SYS_ADMIN, CAP_SYS_PTRACE)
- Break namespace isolation
- Use a kernel exploit if one applies
Phase 4: post-escape
- Enumerate the host
- Escalate privileges on the host
- Access other containers
- Pivot to the orchestration layer (Kubernetes)
- Establish persistence
Common container misconfigurations
Dangerous capabilities
CAP_SYS_ADMIN: mount operations and namespace manipulationCAP_SYS_PTRACE: debug and inject into processesCAP_SYS_MODULE: load kernel modulesCAP_DAC_READ_SEARCH: bypass file read permission checks
Dangerous mounts
/var/run/docker.sock: lets you create new containers, including privileged ones/proc: host process information/: the full host filesystem/dev: raw device access
Insecure configurations
- Privileged mode (
--privileged) --pid=host(shares the host PID namespace)--network=host(shares the host network stack)- Running as root inside the container
- Sensitive ports and services exposed
Container security tools
| Tool | Primary use |
|---|---|
| Docker | Container runtime and management |
| kubectl | Kubernetes cluster interaction |
| crictl | Container runtime interface CLI |
| amicontained | Container environment enumeration |
| CDK | Container penetration toolkit |
Kubernetes considerations
When the container is a Kubernetes pod:
- Enumerate service accounts and RBAC permissions
- Check for a token mounted in
/var/run/secrets/kubernetes.io/serviceaccount/ - Review Pod Security Admission settings and admission controllers (PodSecurityPolicy was removed in Kubernetes 1.25)
- Test for unauthenticated API access
- Look for privilege escalation through pod creation
- Check for an exposed Kubernetes dashboard
Related resources
- Linux Security: Linux privilege escalation applies to container hosts
- Cloud Security: managed container services (ECS, AKS, GKE)
- Network Protocol Attacks: container networking attacks
GCP Security Assessment and Enumeration
GCP security assessment methodology covering project enumeration, service account discovery, storage bucket exposure, and metadata API exploitation.
Docker Container Escape Techniques
Docker container escape techniques including privileged containers, exposed Docker sockets, kernel exploits, and misconfiguration exploitation methods.