hacktricks/pentesting/pentesting-kubernetes/README.md

79 lines
5.8 KiB
Markdown
Raw Normal View History

2022-04-28 15:38:48 +00:00
<details> <summary><strong>Support HackTricks and get benefits!</strong></summary> Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.** **Share your hacking tricks submitting PRs to the** [**hacktricks github repo**](https://github.com/carlospolop/hacktricks)**.** </details>
2022-01-16 17:15:05 +00:00
# Kubernetes Security
2021-03-29 16:19:04 +00:00
2021-12-22 15:22:43 +00:00
## Kubernetes Basics
2021-03-29 16:19:04 +00:00
2021-12-22 15:22:43 +00:00
If you don't know anything about Kubernetes this is a **good start**. Read it to learn about the **architecture, components and basic actions** in Kubernetes:
2021-04-24 11:40:49 +00:00
2021-12-22 15:22:43 +00:00
{% content-ref url="kubernetes-basics.md" %}
[kubernetes-basics.md](kubernetes-basics.md)
{% endcontent-ref %}
2021-12-22 15:22:43 +00:00
## Pentesting Kubernetes
2021-12-22 15:22:43 +00:00
### From the Outside
2021-12-22 15:22:43 +00:00
There are several possible **Kubernetes services that you could find exposed** on the Internet (or inside internal networks). If you find them you know there is Kubernetes environment in there.
2021-12-22 15:22:43 +00:00
Depending on the configuration and your privileges you might be able to abuse that environment, for more information:
2021-04-28 13:49:35 +00:00
{% content-ref url="pentesting-kubernetes-from-the-outside.md" %}
[pentesting-kubernetes-from-the-outside.md](pentesting-kubernetes-from-the-outside.md)
{% endcontent-ref %}
2021-04-28 16:27:24 +00:00
2021-04-27 23:18:16 +00:00
### Enumeration inside a Pod
2021-04-28 23:33:12 +00:00
If you manage to **compromise a Pod** read the following page to learn how to enumerate and try to **escalate privileges/escape**:
2021-12-22 15:22:43 +00:00
{% content-ref url="attacking-kubernetes-from-inside-a-pod.md" %}
[attacking-kubernetes-from-inside-a-pod.md](attacking-kubernetes-from-inside-a-pod.md)
{% endcontent-ref %}
2021-04-27 23:18:16 +00:00
2021-12-22 15:22:43 +00:00
### Enumerating Kubernetes with Credentials
2021-04-24 11:40:49 +00:00
2021-12-22 15:22:43 +00:00
You might have managed to compromise **user credentials, a user token or some service account toke**n. You can use it to talk to the Kubernetes API service and try to **enumerate it to learn more** about it:
2021-04-24 11:40:49 +00:00
2022-02-16 09:28:48 +00:00
{% content-ref url="../../cloud-security/pentesting-kubernetes/kubernetes-enumeration.md" %}
[kubernetes-enumeration.md](../../cloud-security/pentesting-kubernetes/kubernetes-enumeration.md)
{% endcontent-ref %}
2021-04-24 11:40:49 +00:00
2021-12-22 15:22:43 +00:00
Another important details about enumeration and Kubernetes permissions abuse is the **Kubernetes Role-Based Access Control (RBAC)**. If you want to abuse permissions, you first should read about it here:
2021-05-04 11:44:49 +00:00
2021-12-22 15:22:43 +00:00
{% content-ref url="kubernetes-role-based-access-control-rbac.md" %}
[kubernetes-role-based-access-control-rbac.md](kubernetes-role-based-access-control-rbac.md)
{% endcontent-ref %}
2021-04-27 09:44:49 +00:00
2021-12-22 15:22:43 +00:00
#### Knowing about RBAC and having enumerated the environment you can now try to abuse the permissions with:
2021-04-27 09:44:49 +00:00
2022-02-16 09:28:48 +00:00
{% content-ref url="../../cloud-security/pentesting-kubernetes/abusing-roles-clusterroles-in-kubernetes/" %}
[abusing-roles-clusterroles-in-kubernetes](../../cloud-security/pentesting-kubernetes/abusing-roles-clusterroles-in-kubernetes/)
2021-12-22 15:22:43 +00:00
{% endcontent-ref %}
2021-04-27 09:44:49 +00:00
2022-02-06 12:02:47 +00:00
### Privesc to a different Namespace
If you have compromised a namespace you can potentially escape to other namespaces with more interesting permissions/resources:
2022-02-17 01:23:02 +00:00
{% content-ref url="../../cloud-security/pentesting-kubernetes/namespace-escalation.md" %}
[namespace-escalation.md](../../cloud-security/pentesting-kubernetes/namespace-escalation.md)
{% endcontent-ref %}
2022-02-06 12:02:47 +00:00
2022-01-16 17:15:05 +00:00
### From Kubernetes to the Cloud
If you have compromised a K8s account or a pod, you might be able able to move to other clouds. This is because in clouds like AWS or GCP is possible to **give a K8s SA permissions over the cloud**.
2022-01-16 18:11:15 +00:00
{% content-ref url="../../cloud-security/pentesting-kubernetes/kubernetes-access-to-other-clouds.md" %}
[kubernetes-access-to-other-clouds.md](../../cloud-security/pentesting-kubernetes/kubernetes-access-to-other-clouds.md)
2022-01-16 17:15:05 +00:00
{% endcontent-ref %}
2021-12-23 12:20:46 +00:00
## Labs to practice and learn
* [https://securekubernetes.com/](https://securekubernetes.com)
* [https://madhuakula.com/kubernetes-goat/index.html](https://madhuakula.com/kubernetes-goat/index.html)
2021-12-29 01:10:37 +00:00
## Hardening Kubernetes
2021-12-29 12:26:06 +00:00
{% content-ref url="kubernetes-hardening/" %}
[kubernetes-hardening](kubernetes-hardening/)
{% endcontent-ref %}
2022-04-28 15:38:48 +00:00
<details> <summary><strong>Support HackTricks and get benefits!</strong></summary> Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)! Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family) Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com) **Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.** **Share your hacking tricks submitting PRs to the** [**hacktricks github repo**](https://github.com/carlospolop/hacktricks)**.** </details>