Initial Access
This section covers different ways of getting an initial access inside a K8S cluster either as anonymous/unauthenticated or with a foothold on a pod.
Overview
Initial access to Kubernetes clusters can be achieved through various attack vectors, ranging from misconfigurations in authentication mechanisms to exploitation of exposed services. This phase focuses on gaining the first foothold in the cluster.
Anonymous Access
Anonymous access is a rare misconfiguration, but it can occur if excessive access has been granted to the anonymous role.
# Dangerous anonymous binding
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:anonymous
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin # DANGEROUS!
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: system:anonymousTesting Anonymous Access
Obtaining anonymous access on certain API endpoints can lead to sensitive information disclosure.
Anonymous Permission Enumeration:
Exploitation Commands
Certificate Forgery
In Kubernetes, client authentication to the API server can be performed using TLS client certificates. If we gain access to the private key of the cluster Certificate Authority (CA) (ca-key.pem), they can forge valid client certificates and authenticate as any identity they choose, including highly privileged users.
Then create the K8S configuration to use the forged certificate:
Service Account Takeover
Token Presence and Extraction
By default, Kubernetes automatically mounts a service account token into most pods unless explicitly disabled. This token is a JWT used to authenticate to the Kubernetes API server.
At this point, we have valid API credentials.
Authenticated API Enumeration (without kubectl)
Even if kubectl is not present, the token can be used directly with curl to enumerate Kubernetes resources.
Permission Discovery and RBAC Enumeration
When kubectl is available, we can directly access RBAC permissions.
If the service account is bound to cluster-admin or a wildcard role, full cluster compromise is achieved.
Lateral Token Extraction
If the compromised service account has access to other pods, additional tokens can be harvested.
This enables privilege pivoting between service accounts.
Token Extraction from etcd (Critical Misconfiguration)
If etcd is exposed, service account tokens can be extracted directly from cluster storage.
This bypasses pod-level isolation entirely.
kubelet API Exploits
kubelet API ExploitsUnauthenticated kubelet Access
kubelet AccessIf you manage to reach to the kubelet API anonymously you might be able to obtain and RCE on pods.
kubelet API Discovery:
Pod Execution via kubelet:
kubelet Certificate Abuse
kubelet Certificate AbuseBeing able to access the kubelet certificate will grand you access to the API and thus perform the same actions as described above.
Certificate Extraction:
kubeletctl Usage:
etcd Direct Access
etcd Direct AccessUnauthenticated etcd Access
etcd AccessIf you manage to reach to the etcd API anonymously you might be able to leak cluster secrets and manipulate user config.
etcd Discovery and Access:
Secret Extraction from etcd:
etcd Data Manipulation
etcd Data ManipulationIf the RBAC allows you to do so you can modify the user model in etcd and for example grand cluster admin privileges to the anonymous account:
Last updated
Was this helpful?