1 of 33

Red Teaming Kubernetes

From App-Level CVEs to Full Cluster Takeover

1

Lenin Alevski

2 of 33

About Me

  • Lenin Alevski 🇲🇽
  • Security Engineer @ Google 🇺🇸
  • Open Source Contributor
  • Corporate & Startup world
  • I’m obsessed with cybersecurity ❤️

3 of 33

Agenda

  • Introduction to Kubernetes
  • Kubernetes Threat Model
  • Most common attack techniques in K8S
  • Hands-On / CTF style challenges

4 of 33

What Is Kubernetes Anyways?

5 of 33

6 of 33

Kubernetes Application

7 of 33

Kubernetes Components

Control Plane Components

  • kube-apiserver
  • etcd
  • kube-scheduler
  • kube-controller

Node Components

  • kube-proxy
  • kubelet
  • container runtime

8 of 33

Kubernetes Threat Model: If An Attacker Controls ...

Control plane nodes: Attacker controls your cluster. They can modify, access and destroy everything

Pod / Container: Attacker controls application and may be able to escape and attack the node

Kubelet: Attacker controls running pods

Worker nodes: Attacker controls running pods. They can attack master nodes

9 of 33

OWASP Kubernetes Risks Top (2022)

  • K01: Insecure Workload Configurations
  • K02: Supply Chain Vulnerabilities
  • K03: Overly Permissive RBAC Configurations
  • K04: Lack of Centralized Policy Enforcement
  • K05: Inadequate Logging and Monitoring
  • K06: Broken Authentication Mechanisms
  • K07: Missing Network Segmentation Controls
  • K08: Secrets Management Failures
  • K09: Misconfigured Cluster Components
  • K10: Outdated and Vulnerable Kubernetes Components

10 of 33

Kubernetes Most Common Attack Techniques

11 of 33

Threat Matrix For Kubernetes (2022)

12 of 33

Initial Access

  • Using cloud credentials
  • Compromised images and registry
  • Kubeconfig file
  • Application Vulnerability
  • Exposed sensitive interfaces

13 of 33

Kubeconfig File - Hunting For .kube/config Files

14 of 33

Application Vulnerabilities

  • OWASP Top 10
  • SQLi
  • RCE
  • Command injection
  • Etc

A01:2021

Broken Access Control

A02:2021

Cryptographic Failures

A03:2021

Injection

A04:2021

Insecure Design

A05:2021

Security Misconfiguration

A06:2021

Vulnerable and Outdated Components

A07:2021

Identification and Authentication Failures

A08:2021

Software and Data Integrity Failures

A09:2021

Security Logging and Monitoring Failures

A10:2021

Server-Side Request Forgery

15 of 33

Application Vulnerabilities

16 of 33

Execution

  • Application exploit (RCE)
  • Exec into container
  • New container
  • Sidecar Injection

17 of 33

Exec Into The Container

18 of 33

Credential Access

  • List Kubernetes secrets
  • Mount Service Principal
  • Access container service account
  • Applications credentials in �configuration files
  • Access managed identity credential
  • Malicious admission controller

19 of 33

Access managed identity credential

20 of 33

Discovery

  • Access the Kubernetes API server
  • Access Kubelet API
  • Network mapping
  • Access Kubernetes dashboard
  • Instance Metadata API

21 of 33

Kubernetes Service

22 of 33

Lateral Movement

  • Access cloud resources
  • Container service account
  • Cluster internal networking
  • Applications credentials in �configuration files
  • Writable volume mounts on the host
  • CoreDNS poisoning

23 of 33

Lateral Movement and Credential Theft in Kubernetes

24 of 33

Privilege Escalation

  • HostPath mount
  • Access cloud resources
  • Privileged container
  • Cluster-admin binding

25 of 33

Privileged Container

26 of 33

A Container That Doesn't Contain Anything

27 of 33

Cluster-Admin Binding

28 of 33

Hands-on 🙌💻🏴‍☠️

29 of 33

30 of 33

31 of 33

Ingress-nightmare Lab

https://github.com/Alevsk/dvka/tree/master/workshop/labs/ingress-nightmare

32 of 33

Escenario:

33 of 33

Thanks