PISA Pakistan — Community CERT

← 🚩 CTF: Getting Started

30. Container Security in CTF: Docker & Kubernetes Exploitation

⏱ 8 min

Container Security in CTF: Docker & Kubernetes Exploitation

Containers as CTF Targets

Modern CTF challenges run on containerized workloads (e.g., Docker Compose, Kubernetes). Understanding how to escape a container, abuse pod privileges, or pivot across pods is a valuable skill for any competitor.

Docker Misconfigurations

  1. Privileged containers – run with --privileged flag, granting access to host devices.
  2. Exposed Docker socket – mount /var/run/docker.sock into a container, allowing container breakout.
  3. Insecure image registries – pull images from unauthenticated registries that may contain backdoors.

Escape Techniques (MITRE ATT&CK: T1611)

  • cgroups breakout: Write to /sys/fs/cgroup from a privileged container to spawn a process on the host.
  • Docker socket abuse: From inside the container, use docker -H unix:///var/run/docker.sock run -v /:/host alpine chroot /host to obtain a host shell.

Kubernetes Attack Surface

  • API Server exposure (T1200): Default port 6443 can be accessible if misconfigured.
  • RBAC over‑privilege: A service account with cluster-admin role can create pods in any namespace.
  • Secrets in etcd: Unencrypted secrets can be read with kubectl get secrets.

Tools & Lab Steps

  • kubectl – enumerate cluster roles: kubectl get clusterrolebindings.
  • kubesec – audit pod security contexts.
  • CDK (Container Dyson Toolkit) – quickly run container escape scripts.
  • Falco – detect anomalous container behavior in real time.

Pakistani Use Cases

Banks like MCB and HBL have moved core services to Kubernetes. CTF labs that replicate these environments teach participants how to spot exposed API servers and mis‑applied RBAC policies.

Do / Don't

  • Do spin up a minikube cluster on your workstation to practice safe exploitation.
  • Don’t run containers with --privileged on any production system.
  • Do report any discovered container escape in a real cloud environment to the cloud provider and NCCIA 1799.

Takeaway

Deploy a vulnerable Docker container on your lab VM, attempt a cgroups escape, and verify the host shell with id. This hands‑on step will cement the container‑breakout concept.

← PrevNext →