You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pentesting-cloud/kubernetes-security/abusing-roles-clusterroles-in-kubernetes/README.md
+21-45Lines changed: 21 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,11 +213,16 @@ Therfore, it's possible to **get inside a pod and steal the token of the SA**, o
213
213
kubectl exec -it <POD_NAME> -n <NAMESPACE> -- sh
214
214
```
215
215
216
+
> [!NOTE]
217
+
> By default the command is executed in the first container of the pod. Get **all the pods in a container** with `kubectl get pods <pod_name> -o jsonpath='{.spec.containers[*].name}'` and then **indicate the container** where you want to execute it with `kubectl exec -it <pod_name> -c <container_name> -- sh`
218
+
219
+
If it's a distroless container you could try using **shell builtins** to get info of the containers or uplading your own tools like a **busybox** using: **`kubectl cp </path/local/file> <podname>:</path/in/container>`**.
220
+
216
221
### port-forward
217
222
218
223
This permission allows to **forward one local port to one port in the specified pod**. This is meant to be able to debug applications running inside a pod easily, but an attacker might abuse it to get access to interesting (like DBs) or vulnerable applications (webs?) inside a pod:
219
224
220
-
```
225
+
```bash
221
226
kubectl port-forward pod/mypod 5000:5000
222
227
```
223
228
@@ -599,7 +604,7 @@ For a [`mutatingwebhookconfigurations` example check this section of this post](
599
604
600
605
### Escalate
601
606
602
-
As you can read in the next section: [**Built-in Privileged Escalation Prevention**](#built-in-privileged-escalation-prevention), a principal cannot update neither create roles or clusterroles without having himself those new permissions. Except if he has the **verb `escalate`** over **`roles`** or **`clusterroles`.**\
607
+
As you can read in the next section: [**Built-in Privileged Escalation Prevention**](#built-in-privileged-escalation-prevention), a principal cannot update neither create roles or clusterroles without having himself those new permissions. Except if he has the **verb `escalate` or `*`** over **`roles`** or **`clusterroles`** and the respective binding options.\
603
608
Then he can update/create new roles, clusterroles with better permissions than the ones he has.
604
609
605
610
### Nodes proxy
@@ -659,61 +664,31 @@ The privilege to create Rolebindings allows a user to **bind roles to a service
659
664
660
665
By default there isn't any encryption in the communication between pods .Mutual authentication, two-way, pod to pod.
661
666
662
-
#### Create a sidecar proxy app <a href="#create-a-sidecar-proxy-app" id="create-a-sidecar-proxy-app"></a>
663
-
664
-
Create your .yaml
667
+
#### Create a sidecar proxy app
665
668
666
-
```bash
667
-
kubectl run app --image=bash --command -oyaml --dry-run=client > <appName.yaml> -- sh -c 'ping google.com'
668
-
```
669
+
A sidecar container consists just on adding a **second (or more) container inside a pod**.
669
670
670
-
Edit your .yaml and add the uncomment lines:
671
+
For example, the following is part of the configuration of a pod with 2 containers:
command: ["sh","-c","<execute something in the same pod but different container>"]
702
681
```
703
682
704
-
See the logs of the proxy:
705
-
706
-
```bash
707
-
kubectl logs app -C proxy
708
-
```
683
+
For example, to backdoor an existing pod with a new container you could just add a new container in the specification. Note that you could **give more permissions** to the second container that the first won't have.
709
684
710
685
More info at: [https://kubernetes.io/docs/tasks/configure-pod-container/security-context/](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/)
711
686
712
687
### Malicious Admission Controller
713
688
714
689
An admission controller **intercepts requests to the Kubernetes API server** before the persistence of the object, but **after the request is authenticated** **and authorized**.
715
690
716
-
If an attacker somehow manages to **inject a Mutationg Admission Controller**, he will be able to **modify already authenticated requests**. Being able to potentially privesc, and more usually persist in the cluster.
691
+
If an attacker somehow manages to **inject a Mutation Admission Controller**, he will be able to **modify already authenticated requests**. Being able to potentially privesc, and more usually persist in the cluster.
As you can see in the above image, we tried running image `nginx` but the final executed image is `rewanthtammana/malicious-image`. What just happened!!?
The `./deploy.sh` script establishes a mutating webhook admission controller, which modifies requests to the Kubernetes API as specified in its configuration lines, influencing the outcomes observed:
0 commit comments