This talks' focus lays on a popular containerization tool called Kubernetes. Common implementations of Kubernetes are not secure by default and a lot of information about hardening is not known to the public. Since version 1.7 the security level has increased and common security misconfigurations have been mitigated. During this talk it will be demonstrated what happens if these mitigations are not applied and how to abuse them. The talk will be about both securing and attacking the platform and could be considered a 'purple team' talk. Multiple live demos are planned, most of them ending in a guest-to-host escape and a root shell.
2. whoami
works for KPN in the CERT team
infoSec / hacking enthusiast
attacker gone defender
<3 binary stuff
2 / 42
3. ls -l
what is kubernetes?
how to interact with kubernetes
common pitfalls
some dem0z
advice
3 / 42
4. /bin/kubernetes -h
open source container orchestration
written in go
uses docker
released by Google on 07/06/2014
July 2015 Kubernetes is part of Cloud Native
Computing Foundation
4 / 42
6. kubectl get namespaces
namespaces determine scope
administrative boundaries
resource restrictions
access control
$ kubectl get ns
NAME STATUS AGE
default Active 23d
kube-public Active 23d
kube-system Active 23d
safe-space Active 2h
6 / 42
7. kubectl get pods
kubernetes works with pods
a pod is a collection of one or more containers
configuration in yaml
images are freely available
pods are job based
$ kubectl get pods --namespace=kube-system
NAME READY
calico-etcd-rswwr 1/1
calico-kube-controllers-84fd4db7cd-twxh7 1/1
calico-node-mmpqm 2/2
coredns-78fcdf6894-th6ws 1/1
coredns-78fcdf6894-wrrzl 1/1
etcd-super-secure-k82 1/1
kube-apiserver-super-secure-k82 1/1
kube-controller-manager-super-secure-k82 1/1
kube-proxy-jcm7n 1/1
kube-scheduler-super-secure-k82 1/1
kubernetes-dashboard-6948bdb78-4kg5c 1/1
7 / 42
9. kubectl exec
executing commands on pods
opening a shell on nepal:
$ kubectl exec nepal -i --tty --namespace=countries -- /bin/bash
root@nepal:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@nepal:/#
-i is interactive
--tty set STDIN as TTY
9 / 42
10. kubectl get svc
another abstraction layer
clusterIP proxy services
loadbalances / exposes services from pods
$ kubectl get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP
default kubernetes ClusterIP 10.96.0.1
kube-system calico-etcd ClusterIP 10.96.232.136
kube-system kube-dns ClusterIP 10.96.0.10
kube-system kubernetes-dashboard ClusterIP 10.102.156.98
countries nepal NodePort 10.108.209.230
10 / 42
11. kubectl get secrets
Object to hold sensitive information
Created automatically for API access
$ kubectl get secrets --all-namespaces
NAMESPACE NAME
default default-token-h2rnd
kube-public default-token-zwtkt
kube-system attachdetach-controller-token-nsvgz
kube-system bootstrap-signer-token-6w725
[...SNIP...]
kube-system token-cleaner-token-dqww6
kube-system ttl-controller-token-7fd48
countries default-token-xgjmm
countries supersecret-token-token-8qrlc
11 / 42
25. privileged mode
> Processes within the container get almost the
same privileges that are available to processes
outside a container.
Great, right?
25 / 42
26. Example 2
accessible kubernetes-dashboard
version < 1.7 full admin priv by default
>= 1.7 minimal privileges granted, admin revoked
website displays steps for enabling admin (not
recommended)
26 / 42
27. inside
pod
do
privesc
$ ./kubectl get po --namespace=safe-space
NAME READY STATUS RESTARTS AGE
container2 1/1 Running 0 8m
running in safe space
$ ./kubectl --namespace=safe-space create -f
escape.yml
Error from server (Forbidden): error when creating
"escape.yml" pods is forbidden:
User "system:serviceaccount:safe-space:default"
cannot create pods in the namespace "safe-space"
$ ./kubectl --namespace=default create -f escape.yml
Error from server (Forbidden): error when creating
"escape.yml" pods is forbidden:
User "system:serviceaccount:safe-space:default"
cannot create pods in the namespace "default"
oh noes, no privesc?
27 / 42
28. inside
pod
do
privesc
recon...
$ ./kubectl get svc --namespace=kube-system
NAME CLUSTER-IP PORT(S)
calico-etcd 10.96.232.136 6666/TCP
kube-dns 10.96.0.10 53/UDP,53/TCP
kubernetes-dashboard 10.97.154.242 443/TCP
^ that dashboard looks interesting
28 / 42
29. inside
pod
do
privesc
recon...
$ ./kubectl get svc --namespace=kube-system
NAME CLUSTER-IP PORT(S)
calico-etcd 10.96.232.136 6666/TCP
kube-dns 10.96.0.10 53/UDP,53/TCP
kubernetes-dashboard 10.97.154.242 443/TCP
$ curl -v https://10.97.154.242 -k
[...SSL_STUFFZ...]
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 10.97.154.242
> Accept: */*
>
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: no-store
< Content-Length: 990
< Content-Type: text/html; charset=utf-8
< Last-Modified: Tue, 13 Feb 2018 11:17:03 GMT
< Date: Mon, 21 May 2018 08:59:25 GMT
<
<!doctype html> <html ng-app="kubernetesDashboard">
[...SNIP...]
yay! access to dashboardz
29 / 42
30. DEMO 2
access to pod in countries
attempt privesc
pwn host?
30 / 42
31. Example 3
port 10250 exposed
before 09/02/2018 exposed kubelet API
allowed unauthenticated code execution
now authenticated by default
readonly port 10255 still unauthenticated
$ curl --insecure -v -H "X-Stream-Protocol-Version: v2.channel.k8s.io"
-H "X-Stream-Protocol-Version: channel.k8s.io"
-X POST "https://kube-node-here:10250/exec/<namespace>/<podname>/
<container-name>
?command=touch&command=hello_world
&input=1&output=1&tty=1"
https://medium.com/handy-tech/analysis-of-a-kubernetes-hack-backdooring-through-
kubelet-823be5c3d67c
31 / 42
38. harden
network
harden
node
limit service exposure
limit user access (SSH pubkey)
disable privileged mode (if possible)
setup proper logging
do not auto-mount service account
credentials
use latest version of Kubernetes
run kube-bench / kubesec
https://github.com/aquasecurity/kube-bench
https://kubesec.io/
38 / 42
39. harden
network
harden
node
harden
pods
do not run as root by default
set pod security context
disable privesc (yes, this is an
option)
set DenyEscalatingExec on privileged
pods
set AllowPrivilegeEscalation to False
check containers for vulnerable
software
https://github.com/ahmetb/kubernetes-network-policy-recipes
39 / 42