Kubernetes Cluster Penetration Testing: Red Team Tactics for Container Environments
Kubernetes (K8s) clusters are the backbone of modern cloud‑native workloads in Pakistani enterprises, government clouds, and fintech platforms such as easypaisa. This lesson walks through a red‑team approach to uncover RBAC misconfigurations, privileged containers, and secrets leakage before an adversary can exploit them.
Enumeration & Service Discovery
- Use kubectl with a read‑only service account to list pods, services, and namespaces:
kubectl auth can-i --list --namespace=default kubectl get pods -o wide - Scan the Kubernetes API (port 6443) with Nmap:
nmap -p 6443 --script=k8s-api-info <cluster-ip> - Enumerate etcd endpoints (2379) for stored secrets:
kubeletctl scan etcd --server <etcd-ip>
Exploiting Misconfigurations
- Over‑privileged RBAC: Identify bindings that grant
cluster-adminto a low‑privileged user (kubectl get clusterrolebindings | grep -i <user>). - Default Service Accounts: Abuse the
defaultSA to execute commands inside pods:kubectl exec -it <pod> -- /bin/sh - ConfigMaps/Secrets exposed: Extract plain‑text secrets:
kubectl get secret db-credentials -o yaml
Container Escape & Lateral Movement
- HostPath mount escape: If a pod mounts
/var/run/docker.sock, mount the host root:volumeMounts: - name: docker-socket mountPath: /host/var/run/docker.sock - Use metasploit module
exploit/linux/local/container_escapeto pivot to the node. - Deploy a malicious sidecar pod to capture traffic on the node’s network namespace.
Reporting & Remediation
- Document each finding with CVSS vector, MITRE ATT&CK tactic (T1613, T1614), and remediation steps.
- Provide a remediation checklist: enforce least‑privilege RBAC, enable PodSecurityPolicy, rotate etcd encryption keys, and enable audit logging to
audit.k8s.io.
Do / Don't
- Do use a dedicated red‑team namespace and avoid touching production clusters.
- Don't leave
defaultSA withcluster-adminprivileges; always restrict binding. - Do test escape techniques in an isolated lab (e.g., VirtualBox‑based KinD cluster).
Takeaway: By systematically enumerating K8s API permissions, exploiting RBAC flaws, and demonstrating container escape, a red team can deliver actionable hardening guidance to protect critical cloud‑native services in Pakistan.
