AWS - EKS Post Exploitation

Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!
Other ways to support HackTricks:


For mor information check

Enumerate the cluster from the AWS Console

If you have the permission eks:AccessKubernetesApi you can view Kubernetes objects via AWS EKS console (Learn more).

Connect to AWS Kubernetes Cluster

  • Easy way:
# Generate kubeconfig
aws eks update-kubeconfig --name aws-eks-dev
  • Not that easy way:
If you can get a token with aws eks get-token --name <cluster_name> but you don't have permissions to get cluster info (describeCluster), you could prepare your own ~/.kube/config. However, having the token, you still need the url endpoint to connect to and the name of the cluster.
In my case, I didn't find the info in CloudWatch logs, but I found it in LaunchTemaplates userData and in EC2 machines in userData also. You can see this info in userData easily, for example in the next example (the cluster name was cluster-name):
/etc/eks/ cluster-name --kubelet-extra-args ',,,role=worker,,,,type=ondemand, --max-pods=58' --b64-cluster-ca $B64_CLUSTER_CA --apiserver-endpoint $API_SERVER_URL --dns-cluster-ip $K8S_CLUSTER_DNS_IP --use-max-pods false
kube config
describe-cache-parametersapiVersion: v1
- cluster:
name: arn:aws:eks:us-east-1:<acc-id>:cluster/<cluster-name>
- context:
cluster: arn:aws:eks:us-east-1:<acc-id>:cluster/<cluster-name>
user: arn:aws:eks:us-east-1:<acc-id>:cluster/<cluster-name>
name: arn:aws:eks:us-east-1:<acc-id>:cluster/<cluster-name>
current-context: arn:aws:eks:us-east-1:<acc-id>:cluster/<cluster-name>
kind: Config
preferences: {}
- name: arn:aws:eks:us-east-1:<acc-id>:cluster/<cluster-name>
- --region
- us-west-2
- --profile
- <profile>
- eks
- get-token
- --cluster-name
- <cluster-name>
command: aws
env: null
interactiveMode: IfAvailable
provideClusterInfo: false

From AWS to Kubernetes

The creator of the EKS cluster is ALWAYS going to be able to get into the kubernetes cluster part of the group system:masters (k8s admin). At the time of this writing there is no direct way to find who created the cluster (you can check CloudTrail). And the is no way to remove that privilege.
The way to grant access to over K8s to more AWS IAM users or roles is using the configmap aws-auth.
Therefore, anyone with write access over the config map aws-auth will be able to compromise the whole cluster.
For more information about how to grant extra privileges to IAM roles & users in the same or different account and how to abuse this to privesc check this page.
Check also this awesome post to learn how the authentication IAM -> Kubernetes work.

From Kubernetes to AWS

It's possible to allow an OpenID authentication for kubernetes service account to allow them to assume roles in AWS. Learn how this work in this page.

Bypass CloudTrail

If an attacker obtains credentials of an AWS with permission over an EKS. If the attacker configures it's own kubeconfig (without calling update-kubeconfig) as explained previously, the get-token doesn't generate logs in Cloudtrail because it doesn't interact with the AWS API (it just creates the token locally).
So when the attacker talks with the EKS cluster, cloudtrail won't log anything related to the user being stolen and accessing it.
Note that the EKS cluster might have logs enabled that will log this access (although, by default, they are disabled).

EKS Ransom?

By default the user or role that created a cluster is ALWAYS going to have admin privileges over the cluster. And that the only "secure" access AWS will have over the Kubernetes cluster.
So, if an attacker compromises a cluster using fargate and removes all the other admins and deletes the AWS user/role that created the Cluster, the attacker could have ransomed the cluster.
Note that if the cluster was using EC2 VMs, it could be possible to get Admin privileges from the Node and recover the cluster.
Actually, If the cluster is using Fargate you could EC2 nodes or move everything to EC2 to the cluster and recover it accessing the tokens in the node.
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red Team Expert)!
Other ways to support HackTricks: