Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

Kubernetes Pentest

All-in-one:
The Ultimate Toolkit
Sergey Kanibor
Luntry

@r0binak
whoami

§ R&D, Container Security at Luntry

§ Focused on containers &


Kubernetes security

§ Talks at PHDays, HackConf,


CyberCamp, VolgaCTF, БЕКОН

§ Editor Telegram channel


@k8secuirty

Kubernetes Pentest All-in-One: The Ultimate Toolkit 2


Agenda

Typical Kubernetes Pentest

Target Environment

MTKPI

Conclusions

Kubernetes Pentest All-in-One: The Ultimate Toolkit 3


Typical Kubernetes
Pentest
Threat actors

Threat Actors

Compromised
External
Developer

Internal

Kubernetes Pentest All-in-One: The Ultimate Toolkit 5


External

See the Kubernetes network


outside the cluster

§ Vulnerable K8S components

External actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 6


External

See the Kubernetes network


outside the cluster

§ Vulnerable K8S components

§ Vulnerable applications

External actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 7


External

See the Kubernetes network


outside the cluster

§ Vulnerable K8S components

§ Vulnerable applications

§ Misconfigured Kubernetes components


(API Server, Kubelet, etcd)

External actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 8


External

See the Kubernetes network


outside the cluster

§ Vulnerable K8S components

§ Vulnerable applications

§ Misconfigured Kubernetes components


(API Server, Kubelet, etcd)

§ Misconfigured Docker/Containerd/CRIO
daemon

External actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 9


External

See the Kubernetes network


outside the cluster

§ Vulnerable K8S components

§ Vulnerable applications

§ Misconfigured Kubernetes components


(API Server, Kubelet, etcd)

§ Misconfigured Docker/Containerd/CRIO
daemon

§ Misconfigured dashboards (Weave


Scope, Kubernetes Dashboard, Octant) External actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 10


Internal – in Pod

Inside the Pod

§ Bad Pods

Internal actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 11


Internal – in Pod

Inside the Pod

§ Bad Pods

§ Private keys, tokens & creds in ENV

Internal actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 12


Internal – in Pod

Inside the Pod

§ Bad Pods

§ Private keys, tokens & creds in ENV

§ Other services, cluster components

Internal actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 13


Internal – in Pod

Inside the Pod

§ Bad Pods

§ Private keys, tokens & creds in ENV

§ Other services, cluster components

§ Service account permissions

Internal actor ways

Kubernetes Pentest All-in-One: The Ultimate Toolkit 14


Internal – on Node

Inside the Node

§ Keys, SA tokens, configs, certs


§ Kubernetes Privilege Escalation:
Container Escape == Cluster
Admin? (Yuval Avrahami & Shaul
Ben Hai, Palo Alto Networks.
BlackHat USA 2022)

Kubernetes Pentest All-in-One: The Ultimate Toolkit 15


Internal – on Node

Inside the Node

§ Keys, SA tokens, configs, certs


§ Kubernetes Privilege Escalation:
Container Escape == Cluster
Admin? (Yuval Avrahami & Shaul
Ben Hai, Palo Alto Networks.
BlackHat USA 2022)

§ Old dumps, sensitive logs

Kubernetes Pentest All-in-One: The Ultimate Toolkit 16


Internal – on Node

Inside the Node

§ Keys, SA tokens, configs, certs


§ Kubernetes Privilege Escalation:
Container Escape == Cluster
Admin? (Yuval Avrahami & Shaul
Ben Hai, Palo Alto Networks.
BlackHat USA 2022)

§ Old dumps, sensitive logs

§ Third-party instances

Kubernetes Pentest All-in-One: The Ultimate Toolkit 17


Compromised Developer

Compromised Developer

Kubernetes Pentest All-in-One: The Ultimate Toolkit 18


Compromised Developer

§ Can push its own images in registry

Compromised Developer

Kubernetes Pentest All-in-One: The Ultimate Toolkit 19


Compromised Developer

§ Can push its own images in registry

§ There is access to internal services

Compromised Developer

Kubernetes Pentest All-in-One: The Ultimate Toolkit 20


Pentesting Kubernetes: From Zero to Hero

Get more info about Kubernetes


pentest for newbies:

Link

Kubernetes Pentest All-in-One: The Ultimate Toolkit 21


Target Environment
Environment

Policy Runtime Network


Engine Security Policy

§ SOC, DevSecOps, AppSec

§ Policy Engine RBAC Scanners SIEM

§ Runtime Security

§ Network Policy

§ RBAC

Kubernetes Pentest All-in-One: The Ultimate Toolkit 23


MTKPI
MTKPI – Multi Tool Kubernetes Pentest Image

Inspired by:

§ botty

§ Hacker container

§ netshoot

§ alpine-containertools

Kubernetes Pentest All-in-One: The Ultimate Toolkit 25


Whatever you need
§ Reconnaissance
§ kdigger

§ botb
§ deepce

Kubernetes Pentest All-in-One: The Ultimate Toolkit 26


Whatever you need
§ Reconnaissance
§ kdigger

§ botb
§ deepce

§ Privilege Escalation
§ Traitor

§ linuxprivchecker

Kubernetes Pentest All-in-One: The Ultimate Toolkit 27


Whatever you need
§ Reconnaissance
§ kdigger

§ botb
§ deepce

§ Privilege Escalation
§ Traitor

§ linuxprivchecker

§ Network
§ curl
§ dig
§ nc

Kubernetes Pentest All-in-One: The Ultimate Toolkit 28


Whatever you need
§ Reconnaissance § Combine tools
§ kdigger § kubeletctl
§ botb § kubesploit C2 agent
§ deepce § CDK
§ peirates
§ Privilege Escalation
§ ctrsploit
§ Traitor
§ kube-hunter
§ linuxprivchecker
§ kubectl
§ Network
§ curl
§ dig
§ nc

Kubernetes Pentest All-in-One: The Ultimate Toolkit 29


Microsoft – Threat Matrix for Kubernetes

Kubernetes Pentest All-in-One: The Ultimate Toolkit 30


Microsoft – Threat Matrix for Kubernetes

Kubernetes Pentest All-in-One: The Ultimate Toolkit 31


Just Dockerfile

Kubernetes Pentest All-in-One: The Ultimate Toolkit 32


Just Dockerfile

Kubernetes Pentest All-in-One: The Ultimate Toolkit 33


MTKPI in action
Bypassing Vulnerability Scanners

§ There are a number of files and directories that contain information used by vulnerability scanners
and SBOM tools

Kubernetes Pentest All-in-One: The Ultimate Toolkit 35


Bypassing Vulnerability Scanners

§ There are a number of files and directories that contain information used by vulnerability scanners
and SBOM tools

§ No feeds == no vulns J

Kubernetes Pentest All-in-One: The Ultimate Toolkit 36


Bypassing Vulnerability Scanners – techniques

§ Modified /etc/os/release

§ Deleted APK metadata

§ Symlinked Language Dependency Files

§ UPX packed binaries

§ Multi-stage build with all techniques Talks, Slides, Repo, Blog

Kubernetes Pentest All-in-One: The Ultimate Toolkit 37


Get shell in Pod

§ We don't have pods/exec rights

Kubernetes Pentest All-in-One: The Ultimate Toolkit 38


Get shell in Pod

§ We don't have pods/exec rights

§ We need access to the shell to


execute the command

Kubernetes Pentest All-in-One: The Ultimate Toolkit 39


Get shell in Pod

§ We don't have pods/exec rights

§ We need access to the shell to


execute the command

§ We can proxy the traffic to


ourselves on localhost

Kubernetes Pentest All-in-One: The Ultimate Toolkit 40


Get shell in Pod

§ We don't have pods/exec rights

§ We need access to the shell to


execute the command

§ We can proxy the traffic to


ourselves on localhost

§ Share the terminal over the web

Kubernetes Pentest All-in-One: The Ultimate Toolkit 41


Get shell in Pod

§ We don't have pods/exec rights

§ We need access to the shell to


execute the command

§ We can proxy the traffic to


ourselves on localhost

§ Share the terminal over the web

kubectl port-forward <pod-name> 28015:27017

Kubernetes Pentest All-in-One: The Ultimate Toolkit 42


LoTL attack

§ Attacks in which the attacker uses legitimate utilities to perform malicious actions

Kubernetes Pentest All-in-One: The Ultimate Toolkit 43


LoTL attack

§ Attacks in which the attacker uses legitimate utilities to perform malicious actions

§ There are usually quite a few of these utilities in the container

Kubernetes Pentest All-in-One: The Ultimate Toolkit 44


LoTL attack

§ Attacks in which the attacker uses legitimate utilities to perform malicious actions

§ There are usually quite a few of these utilities in the container

§ GTFObins

Kubernetes Pentest All-in-One: The Ultimate Toolkit 45


LoTL attack

§ Attacks in which the attacker uses legitimate utilities to perform malicious actions

§ There are usually quite a few of these utilities in the container

§ GTFObins

§ Use traitor to automate this

Kubernetes Pentest All-in-One: The Ultimate Toolkit 46


Getting root back in non-root envs

Kubernetes Pentest All-in-One: The Ultimate Toolkit 47


RWX in readOnly

§ Use ddexec.sh for fileless attack

Kubernetes Pentest All-in-One: The Ultimate Toolkit 48


RWX in readOnly

§ Use ddexec.sh for fileless attack

§ /dev/shm for RW only

Kubernetes Pentest All-in-One: The Ultimate Toolkit 49


RWX in readOnly

§ Use ddexec.sh for fileless attack

§ /dev/shm for RW only

§ You have RWX permissions at


/etc/hosts, /dev/termination-log

Kubernetes Pentest All-in-One: The Ultimate Toolkit 50


RWX in readOnly

§ Use ddexec.sh for fileless attack

§ /dev/shm for RW only

§ You have RWX permissions at


/etc/hosts, /dev/termination-log

§ Executing Arbitrary Code &


Executables in Read-Only
FlieSystems

Kubernetes Pentest All-in-One: The Ultimate Toolkit 51


hostNetwork gotcha

§ Kubernetes usually runs your pods in


their own isolated network

Kubernetes Pentest All-in-One: The Ultimate Toolkit 52


hostNetwork gotcha

§ Kubernetes usually runs your pods in


their own isolated network

§ hostNetwork: true

Kubernetes Pentest All-in-One: The Ultimate Toolkit 53


hostNetwork gotcha

§ Kubernetes usually runs your pods in


their own isolated network

§ hostNetwork: true

§ Doing this, bypasses network


policies altogether. Your pod will be
able to communicate just like any
other process that is running on the
host itself.

Kubernetes Pentest All-in-One: The Ultimate Toolkit 54


Gain a reverse rootshell on a Node

Kubernetes Pentest All-in-One: The Ultimate Toolkit 55


Signature / rule bypass (Falco – part 1)

Kubernetes Pentest All-in-One: The Ultimate Toolkit 56


Signature / rule bypass demo – part 1

Kubernetes Pentest All-in-One: The Ultimate Toolkit 57


Signature / rule bypass (Falco – part 2)

Kubernetes Pentest All-in-One: The Ultimate Toolkit 58


Bypass Falco signature – in Dockerfile

Kubernetes Pentest All-in-One: The Ultimate Toolkit 59


Signature / rule bypass demo – part 2

Kubernetes Pentest All-in-One: The Ultimate Toolkit 60


Falco bypasses by default J

§ https://github.com/blackberry/Falco-bypasses
§ https://www.antitree.com/2019/09/container-runtime-security-bypasses-on-falco/
§ https://www.youtube.com/watch?v=nGqWskXRSmo
§ https://github.com/falcosecurity/falco/security/advisories/GHSA-rfgw-vmxp-hp5g

Kubernetes Pentest All-in-One: The Ultimate Toolkit 61


Bypass Tetragon – rule

Kubernetes Pentest All-in-One: The Ultimate Toolkit 62


Bypass Tetragon – rule

Bypassing eBPF-based Security Enforcement Tools

Kubernetes Pentest All-in-One: The Ultimate Toolkit 63


Conclusions
Conclusions

§ With proper preparation, even secure environments aren't so secure after all

Kubernetes Pentest All-in-One: The Ultimate Toolkit 65


Conclusions

§ With proper preparation, even secure environments aren't so secure after all

§ Classic security methods (vulnerability compliance, signatures, ...) are bypassed


quite easily in containerized environments (especially if you can use a custom
image)

Kubernetes Pentest All-in-One: The Ultimate Toolkit 66


Conclusions

§ With proper preparation, even secure environments aren't so secure after all

§ Classic security methods (vulnerability compliance, signatures, ...) are bypassed


quite easily in containerized environments (especially if you can use a custom
image)

§ To ensure a high level of security in Kubernetes, strive for the ZeroTrust model
(NetworkPolicy, behavior models, AppArmor, Policy Engines, ...)

Kubernetes Pentest All-in-One: The Ultimate Toolkit 67


Conclusions

§ With proper preparation, even secure environments aren't so secure after all

§ Classic security methods (vulnerability compliance, signatures, ...) are bypassed


quite easily in containerized environments (especially if you can use a custom
image)

§ To ensure a high level of security in Kubernetes, strive for the ZeroTrust model
(NetworkPolicy, behavior models, AppArmor, Policy Engines, ...)

§ MTKPI will both simplify pentesting and verify your actual level of security in
containerized environments

Kubernetes Pentest All-in-One: The Ultimate Toolkit 68


Future plans

§ Reduce image size

§ Add new tools

§ Integrate with BUS tools

Kubernetes Pentest All-in-One: The Ultimate Toolkit 69


Useful links

§ Kubernetes Pentesting (HackCloud)

§ Kubernetes Pentest Methodology

§ Container Security Site

Kubernetes Pentest All-in-One: The Ultimate Toolkit 70


Thank you!

MTKPI @k8security

Kubernetes Pentest All-in-One: The Ultimate Toolkit 71

You might also like