npx skills add ...
npx skills add yaklang/hack-skills --skill kubernetes-pentesting
Kubernetes penetration testing playbook. Use when targeting Kubernetes clusters via API server, RBAC enumeration, service account abuse, etcd access, Kubelet API, pod escape, cloud-specific metadata, admission webhook bypass, and registry secrets.
npx skills add yaklang/hack-skills --skill kubernetes-pentesting
AI LOAD INSTRUCTION: Expert Kubernetes attack techniques. Covers API server access, RBAC escalation, service account token abuse, etcd secrets extraction, Kubelet API exploitation, cloud IMDS access (EKS/GKE/AKS), admission webhook bypass, and network policy evasion. Base models miss the distinction between namespace-scoped and cluster-scoped RBAC, and overlook Kubelet's unauthenticated API.
Before going deep, consider loading:
| Permission | Risk | Escalation Path |
|---|---|---|
pods/exec | Critical | Exec into any pod (access secrets, tokens) |
pods (create) | Critical | Create privileged pod → node access |
secrets (get/list) | Critical | Read all secrets including SA tokens |
serviceaccounts/token (create) | Critical | Generate token for any SA |
nodes/proxy | High | Proxy to Kubelet API |
escalate on roles | Critical | Grant yourself any permission |
bind on rolebindings | Critical | Bind any role to yourself |
impersonate | Critical | Impersonate any user/SA |
Quick reference for K8s-specific vectors:
| Vector | Requirement | Command |
|---|---|---|
| hostPID | spec.hostPID: true | nsenter -t 1 -m -u -i -n -p -- bash |
| hostNetwork | spec.hostNetwork: true | Access node services (Kubelet, etcd) |
hostPath / | Volume mount of host root | chroot /host bash |
| Privileged container | securityContext.privileged: true | Mount host disk / nsenter |
| Strategy | Command/Method |
|---|---|
| Excluded namespace | kubectl get validatingwebhookconfigurations -o yaml | grep namespaceSelector → use excluded NS |
| failurePolicy: Ignore | If webhook server down → admission skipped |
| Ephemeral containers | kubectl debug POD -it --image=alpine (may not be covered) |
| Static pods | Place manifest in /etc/kubernetes/manifests/ on node (bypasses API admission) |
Bypass strategies: DNS exfiltration (port 53 rarely blocked), allowed port tunneling, pod in unprotected namespace, hostNetwork: true bypasses pod network policies entirely.
| Tool | Purpose | Command |
|---|---|---|
| kubectl | K8s API interaction | kubectl auth can-i --list |
| kube-hunter | Automated K8s vulnerability scanning | kube-hunter --remote TARGET |
| peirates | K8s pentesting from inside a pod | ./peirates |
| kubesploit | Post-exploitation framework for K8s | Agent-based C2 |
| CDK | Container/K8s exploitation toolkit | ./cdk evaluate |
| kubeletctl | Interact with Kubelet API directly | kubeletctl pods -s NODE_IP |
| kubeaudit | Cluster misconfiguration audit | kubeaudit all |