โธ๏ธkubernetes pentesting
Kubernetes Pentesting
Theory
Kubernetes Architecture
Understanding the entirety of the Kubernetes architecture 2 will help you analyze its weaknesses. The ๏ฌrst component would be to understand the control plane. The control plane of Kubernetes itself is made up of the containers listed next.
NOTE The control plane of a system is the plane, or zone, in which the system operates outside of its standard workloads. This zone is responsible for the backend of the system and organizes the components that make up the system. The plane that a user would interact with for a workload on Kubernetes, such as the web applications hosted on Kubernetes, would be called the data plane.
API Server
The API Server is the heart of the system, and it is integral for communication between the Kubernetes Nodes and the Kubernetes Components.
Etcd
This is a key/value store that contains the database for control plane components. It is a ๏ฌleless equivalent to the /etc directory in a Unix operating system.
kube-scheduler
This is the scheduling system; it maintains the operation of the containers. The kube- scheduler looks at what should be running, how it should be running, and whether it should be running and then ensures those operations execute.
kube-controller-manager
This is a series of controllers that maintain di๏ฌerent operating components. Each controller has a speci๏ฌc task, and the manager organizes them.
cloud-controller-manager
The cloud-controller- manager is an abstraction for each cloud, and this allows for Kubernetes to work across di๏ฌerent cloud providers or on-premises systems.
Kubelet
The Kubernetes Agent that communicates back to the Kubernetes API Server.
Kube-proxy
A port-forwarding tool thatโs like SSH port forwarding. This allows the operator of the system to communicate with individual containers that are internally available in the cluster.
Practical
Find Kubernetes API Servers
First Method
Certi๏ฌcate transparency reports
Brute-forcing DNS entries
Information disclosure through people submitting code blocks or samples
Second Method
we can ๏ฌnd these same endpoints if we have access to a container in which they are connected to an existing cluster.
Control plane: Port 6443, Kubernetes API server
TCP: Inbound, 2379-2380, etcd server client API
Worker node(s): TCP Inbound, 10250, Kubelet API
Kubernetes Native URIs
/version The response may include a keyword like gitVersion, goVersion, or โplatformโ.
/api/v1/pods If you get an answer with โapiVersionโ and do not see โpods is forbidden,โ then you have found a critical system issue where unauthenticated users can get to pods.
/api/v1/info Same as pods, but this is an additional endpoint to ensure that general-purpose permissions are appropriately set.
/ui This is the lesser-used Kubernetes Dashboard project URI, which should never be exposed to the Internet.
Scanners may also be keying into speci๏ฌc text in the HTML that is returned by scans:
โKubernetes Dashboardโ This string reveals HTML that could indicate the presence of the Kubernetes Dashboard.
Fingerprint Kubernetes Servers
Hacking Kubernetes from Within
Get AWS EKS Authentication Token
Kubestriker
This application allows you to scan, specify a URL, or use a con๏ฌguration ๏ฌle to attack a Kubernetes environment.
Run an Ubuntu-based Container Image
Enumeration on Ubuntu Container
Attack API Server
There are two ways to approach this:
We can move our tools onto the local container. The downside is that we may be caught by any monitoring tools installed in the cluster, such as EDR tools or tools speci๏ฌc to Kubernetes Admission Controller scanning or Kubernetes Container scanning. Sysdig has an open source agent that can provide this type of telemetry. The tools generally will understand how to use the existing credentials in this case.
We can move the tokens outside the cluster and then attach to our clusters remotely using those keys. This is done by using the /var/run/secrets/kubernetes.io/serviceaccount/token, ca.crt, and the IP or hostname of the server.
Fist Option
This attack will do the following:
Install a container node with a backdoor listener that executes a Bash shell.
Start it with all local privileges and then mount the host disk to the local system.
Files Needed:
ncat-svc.yml This ๏ฌle exposes the port to the cluster.
ncat.yml This is the main deployment script.
Write the files in Container
Once these two ๏ฌles are on the remote server, we will need to download the kubectl ๏ฌle. Once we have all these pieces in the system, we can then have the kubectl apply a new pod to do the following:
The pod will open port 9999.
It will mount all the hostโs PIDs, environment variables, and networking.
It will mount the root ๏ฌle system right into the container.
We can then connect on that port to gain access to the container, which has elevated privileges:
REFERENCES
https://kubernetes.io/partners/#conformance
https://kubernetes.io/docs/concepts/architecture/
https://aws.amazon.com/eks/getting-started/
https://microservices-demo.github.io/
https://isc.sans.edu/forums/diary/Using+Certi๏ฌcate+Transparency+as+an+Attack+Defense+Tool/24114/
https://github.com/coreos/coreos-kubernetes/blob/master/Documentation/kubernetes-networking.md
https://istio.io/
https://www.github.com/mosesrenegade/tools-repo/