Python - Exposed docker daemon
Exposed docker daemon over HTTP rest API
First download the OVA to start on virtualbox https://www.vulnhub.com/entry/vulnerable-docker-1,208/
After downloading the image run it and start it in easy mode. After you have found the IP address of the machine than happy hacking!
By default, Docker runs through a non-networked UNIX socket. It can also optionally communicate using an HTTP socket, as is what we see with this vulnerable VM.
If you need Docker to be reachable through the network in a safe manner, you can enable TLS by specifying the tlsverify flag and pointing Docker’s tlscacert flag to a trusted CA certificate.
In the daemon mode, it only allows connections from clients authenticated by a certificate signed by that CA. In the client mode, it only connects to servers with a certificate signed by that CA.
However this is not the case for the following example, let's see if we can now gain control over the Docker host machine by exploiting this open Docker API.
Recon
A normal nmap scan does not find any interesting results:
However, when we start scanning the entire port range, here comes some interesting information:
Now that we have found the port on which the Docker API is listening let's see if we can get some interesting information from there? We can either do a curl to the following endpoint, or simply put the following GET request in the browser to see the results.
we now find information about all the current running images:
Now let's see if we can make it more interesting. First i want to make my Docker client communicate with the remote Daemon API I do this by running the following command:
alternatively we could also use the docker engine SDK as described here:
Now, we first test that the alias works, we do this by simply running the following command:
exploitation
Now, we want to become root on the Docker host machine, we can achieve this by running a special container.
The command below is going to perform the privilege escalation and fetches a Docker image from the Docker Hub Registry and runs it. The -v parameter that you pass to Docker specifies that you want to create a volume in the Docker instance. The -i and -t parameters put Docker into ‘shell mode’ rather than starting a daemon process.
The instance is set up to mount the root filesystem of the host machine to the instance’s volume, so when the instance starts it immediately loads a chroot into that volume. This effectively gives you root on the machine.
There are many, many other ways to achieve this, but this was one of the most straightforward.
Congratulations, we now are root on the Docker host machine!
Last updated