☸️Kubernetes Container Escaping Labs

⚠️ Disclaimer

This lab is for training and awareness only! Never attempt container escapes in unauthorized environments.


🎯 Objective

Understand how misconfigured containers can allow attackers to escape into the host system.


🧰 Prerequisites

  • Kubernetes cluster (preferably local, like Minikube or kind)

  • kubectl configured

  • A pod is allowed to run in privileged mode (for simulation)


Lab 1: One-Liner Kubernetes Container Escape

Duffie Cooley and Ian Coldwater pulled the following Kubernetes one-liner together the first time they met:

Step 1: Run the one-liner

Just run this:

Step 2: Check for root in the process namespace

Step 3: Check for kernel PIDs to verify we’re in the root namespace


🔹 Lab 2: Deploy a Privileged Pod

Deploy a highly privileged pod:

✅ Pod runs with hostPID and privileged mode — dangerous in production!


🔹 Lab 3: Inspect Host Processes from Inside the Pod

Inside the container:

Expected: You see host system processes.


🔹 Lab 4: Access the Host Filesystem

Still inside the container:

(May fail if /host is not mounted — so let's try mounting it.)

Mount the host root filesystem:

✅ Gain access to the host filesystem.


🔹 Lab 5: Spawn a Host Shell

Inside the container (dangerous):

You are now running as root on the host from inside the container.


🔹 Lab 6: Defensive Countermeasures

  • Never allow privileged: true unless absolutely necessary.

  • Do not enable hostPID, hostNetwork, or hostIPC unless required.

  • Use PodSecurityAdmission with restricted level.

  • Enforce AppArmor, Seccomp, and readOnlyRootFilesystem.

  • Regularly audit pods for excessive privileges.


🔹 Lab 7: Clean Up


✅ Wrap-Up

  • ✅ Demonstrated how container misconfiguration can lead to host escape

  • ✅ Understood the power of privileged and hostPID

  • ✅ Learned prevention strategies for real-world defense


Last updated