# Privesc Container K8S Pod Escape

> Use when authorized container or Kubernetes testing gives you a shell inside a pod and you need to test escape to the node, to other pods, or to cluster admin. Covers pod security context and capability abuse, hostPath and host network or PID namespace escapes, service account token abuse, kubelet and API server access from inside the pod, and secrets exposure, with detection notes. For authorized penetration tests, labs, and CTFs only.

- Skill: `mizazhaider-ceh/privesc-container-k8s-pod-escape` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/privesc-container-k8s-pod-escape`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/privesc-container-k8s-pod-escape/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/privesc-container-k8s-pod-escape

---

A shell inside a Kubernetes pod is not the end of the test. It is the start of a new privilege question - can this pod reach the node, other pods, the kubelet, or the API server, and can it turn a service account token into cluster privilege? Pod escapes succeed through configuration, not through container runtime zero-days, in most authorized assessments - a privileged pod, a hostPath mount, host namespaces, a powerful Linux capability, or an over-permissioned service account. This sub-skill maps those configurations, shows how to enumerate them from inside the pod, and explains the escape and lateral movement steps inside scope. It builds on the parent skill privesc-container-escape, which covers container escapes generally, and applies that method to Kubernetes specifically.

## Quick Workflow

1. Confirm scope - record the cluster, namespace, pod name, and whether node access, other namespaces, or cluster admin are in scope, and whether destructive pod changes are allowed.
2. Enumerate the pod context from inside - capabilities, mounts, namespaces, service account token, and environment variables, without changing anything.
3. Classify the escape surface - privileged flag, host namespaces, hostPath mounts, capabilities, and service account permissions, in that order of reliability.
4. Verify the most promising vector by hand - check the mount actually reaches host files, the capability actually permits the operation, or the token actually authorizes the API call.
5. Escape or move laterally one step at a time, re-enumerating from each new context, and stop at the objective named in scope.
6. Capture evidence for each hop - pod spec fields, mount output, API responses, and node identity - and record which configuration enabled it.
7. Clean up any test pods, tokens, or role bindings you created, and report the pod security configuration as the root cause with detection notes.

## 1. Enumerating pod context from inside

Start inside the pod with the facts that decide everything else. Capabilities, mounts, and namespace membership are visible from inside, and they determine which escapes are even possible.

```bash
cat /proc/self/status | grep -i cap
capsh --print 2>/dev/null | head -30
cat /proc/self/mountinfo | head -40
ls -l /var/run/secrets/kubernetes.io/serviceaccount/ 2>/dev/null
```

The capability output shows effective capabilities - CAP_SYS_ADMIN, CAP_SYS_PTRACE, CAP_NET_RAW, and CAP_DAC_READ_SEARCH each open different escape families. The mountinfo output shows hostPath mounts, which appear as host directories mounted into the pod, and the service account directory shows whether a token is mounted and readable. If no token is mounted, API-based paths need another credential source. If the token file exists, read its namespace and check its permissions before using it, because an automounted token for a default service account and a token for a dedicated workload identity are very different findings.

```bash
cat /proc/self/cgroup 2>/dev/null | head -10
ls -l /proc/1/ns/
env | grep -i -e kubernetes -e service | head -20
```

The cgroup and namespace listings confirm whether the pod shares the host PID, network, or IPC namespace - shared namespaces collapse the escape problem, because host processes or host network interfaces become directly visible. Environment variables reveal the API server address and service host, which are needed for API tests. Record all of this before attempting any escape, because a failed escape attempt that modifies the pod can destroy the evidence of the original configuration.

## 2. Privileged pods, host namespaces, and hostPath escapes

A privileged pod, or a pod with hostPID, hostNetwork, or hostIPC set, is the shortest escape path in Kubernetes testing. A privileged pod can often mount the host filesystem, access host devices, and run with capabilities that make node access straightforward. A hostPID pod can see and interact with host processes, and a hostNetwork pod can reach node services bound to localhost.

```bash
mount | grep -e " /host" -e "hostPath"
ls -l /host/etc/ 2>/dev/null | head -20
nsenter --target 1 --mount --uts --ipc --net --pid sh 2>&1 | head -5
```

The first commands check whether a host directory is already mounted into the pod, which is the hostPath case - if the host root or a sensitive host directory is mounted writable, writing a cron job, a systemd unit, or an SSH authorized key onto the host is the node escape, subject to scope and to the rule against persistent backdoors outside the agreed test method. The nsenter command is the hostPID case - entering namespace 1 from a hostPID pod reaches the host init namespace, and a shell there is effectively node root. Test nsenter only when node access is in scope, and prefer a read-only probe, such as listing host processes, before running a full shell, so the finding is proven without unnecessary host modification.

HostPath escapes deserve a severity note - a read-only hostPath mount of a sensitive directory is exposure, while a writable mount of the host root is full node compromise. Report the mount path, the read or write mode, and the pod spec field that created it, because the fix is a pod security policy or admission control rule that blocks that mount, not a patch.

## 3. Capability abuse inside the pod

When the pod is not privileged and shares no host namespace, capabilities decide the next step. CAP_SYS_ADMIN is the most powerful - it permits mounting filesystems, administering namespaces, and a range of operations that can lead to host access when combined with a hostPath mount or a writable host device. CAP_SYS_PTRACE permits tracing host processes when hostPID is also shared, and CAP_DAC_READ_SEARCH permits reading host files past permission checks when a host filesystem is reachable. CAP_NET_RAW and CAP_NET_ADMIN matter for network attacks against node services and other pods, but they do not by themselves give node root.

```bash
python3 -c "import os; print(hex(int(open('/proc/self/status').read().split('CapEff:')[1].split()[0], 16)))"
ls -l /dev/ | head -30
find / -maxdepth 4 -name "*.sock" 2>/dev/null | head -20
```

Decoding the effective capability mask confirms which capabilities are actually effective, rather than merely permitted, because container runtimes and pod security contexts can drop capabilities at different layers. The device listing shows whether host devices are exposed into the pod, and the socket search finds Docker, containerd, CRI-O, or kubelet sockets mounted into the pod - a runtime socket inside a pod is a parent-skill container escape applied to Kubernetes, and it often gives node-level container control directly. Verify each socket by checking its process and permissions before concluding it is usable.

## 4. Service account tokens and API server abuse

Every pod with an automounted service account token can talk to the API server, and the question is always what that token is allowed to do. Default service accounts in many clusters can list pods and services but little else, while workload identities are often granted broad permissions through role bindings that were copied from examples without review. Test the token with read-only API calls first, and escalate the test only when the read results justify it.

```bash
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
APISERVER="https://kubernetes.default.svc"
curl -sk -H "Authorization: Bearer $TOKEN" "$APISERVER/api/v1/namespaces/default/pods" | head -40
curl -sk -H "Authorization: Bearer $TOKEN" "$APISERVER/apis/rbac.authorization.k8s.io/v1/namespaces/default/roles" | head -40
```

Replace the namespace with the pod namespace from the token directory or the downward API. The first call tests pod listing, and the second tests RBAC visibility. If the token can list secrets, read the secret names but not necessarily the values in the first pass - secret listing alone proves broad read access, and reading values should follow the scope rules for credential handling. If the token can create pods, create role bindings, or escalate roles, that is a cluster privilege path - a pod created in a privileged namespace, or a role binding that grants cluster admin to the service account, converts pod access into cluster admin. Test creation only in a dedicated test namespace when scope allows it, and delete every test object immediately.

Also check for cloud credential exposure - pods on managed clusters may mount cloud instance metadata endpoints or workload identity tokens, and the node metadata service may be reachable from the pod network. A token that reaches cloud APIs extends the blast radius beyond the cluster, so check metadata reachability and report it as a separate finding with its own scope note.

```bash
curl -s -m 5 http://169.254.169.254/ 2>&1 | head -10
env | grep -i -e aws -e azure -e gcp | head -10
```

A reachable metadata endpoint from inside a pod is a configuration finding even before any credential is retrieved, because the metadata service was designed for node use, not pod use. Do not retrieve live cloud credentials beyond what scope explicitly permits, and never use a retrieved cloud credential outside the agreed test window.

## 5. Kubelet, node services, and lateral movement to other pods

The kubelet runs on every node and exposes an API on ports 10250 and 10255 in many configurations, with varying authentication. From inside a pod on the same node, or from a hostNetwork pod, the kubelet may allow pod listing, log access, or command execution in other pods on that node. Test kubelet reachability from the pod network, and check whether authentication is required, before concluding this path is open.

```bash
NODE_IP=$(grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' /etc/hosts | head -1)
curl -sk "https://$NODE_IP:10250/pods" 2>&1 | head -20
curl -sk "https://$NODE_IP:10250/runningpods/" 2>&1 | head -20
```

Unauthenticated kubelet access that lists pods is a serious finding, and kubelet exec access to other pods is lateral movement to every workload on the node. Node services bound to localhost, such as debug endpoints or monitoring agents, become reachable from a hostNetwork pod or after a hostPID escape, so re-run service enumeration from each new context. Lateral movement between pods also follows ordinary network paths - a pod that can reach another pod service without network policy restriction can attack that service directly, and network policies are the control that should prevent it. Test pod to pod reachability with a simple connection check, and report open paths by source pod, destination service, and the missing policy.

Detection note for this family - pod escapes generate distinctive telemetry. Privileged pod creation, hostPath mounts, host namespace flags, and broad role bindings are all visible in API audit logs. Service account token use from unexpected pods, kubelet exec calls, and node filesystem writes from pod contexts are high-value alerts. Defenders should enforce pod security standards, block host namespaces and hostPath mounts by admission control, scope service account permissions to the minimum per workload, disable token automounting where the workload does not need the API, and alert on API audit events for pod creation and role binding changes outside deployment pipelines.

## Edge cases

- A service account token may be mounted but expired, scoped to a namespace with no useful permissions, or bound to a workload identity that resolves differently than the token name suggests.
- HostPath mounts may be read-only, may mount an empty directory, or may mount a host path that does not contain sensitive data, so verify contents and write mode before concluding node access.
- Capabilities shown as permitted are not always effective - check the effective mask, not just the bounding set, before building a capability exploit plan.
- Kubelet authentication varies by cluster configuration - an endpoint that is open on one cluster may require client certificates on another, so test authentication rather than assuming it.
- Network policies may block pod to pod traffic even when the pod network appears flat, so a failed connection may be policy, not absence of a service.
- Managed clusters may restrict node access entirely, so a pod escape that works on a self-managed cluster may stop at the node boundary on a managed one, and that boundary is itself a finding to report.
- Creating test pods or role bindings in a production namespace can disrupt workloads, so use a dedicated test namespace when scope allows it, and delete test objects immediately.
- Cloud metadata endpoints may return a redirect or an empty response when blocked by a metadata proxy, which is a control working as intended, not a failed test.

## Key references

- MITRE ATT&CK T1611 (Escape to Host), T1552 (Unsecured Credentials), T1078 (Valid Accounts), T1610 (Deploy Container)
- Kubernetes pod security standards - https://kubernetes.io/docs/concepts/security/pod-security-standards/
- Kubernetes RBAC documentation - https://kubernetes.io/docs/reference/access-authn-authz/rbac/
- HackTricks Kubernetes pentesting - https://book.hacktricks.xyz/cloud-security/kubernetes-pentesting
- CIS Kubernetes Benchmark - https://www.cisecurity.org/benchmark/kubernetes

