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
- Privileged containers – run with
--privilegedflag, granting access to host devices. - Exposed Docker socket – mount
/var/run/docker.sockinto a container, allowing container breakout. - Insecure image registries – pull images from unauthenticated registries that may contain backdoors.
Escape Techniques (MITRE ATT&CK: T1611)
- cgroups breakout: Write to
/sys/fs/cgroupfrom 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 /hostto 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-adminrole 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
--privilegedon 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.
