Docker Engine API Pentesting
The Docker Engine API is a RESTfull API accessed by an HTTP client. The default ports are 2375, 2376. The socket file is located at /var/run/docker.sock.
Enumeration
Privilege Escalation from Docker Image
We may be able to get a root shell from remote Docker images.
1. Check if Docker is Running in Local Machine
In local machine, check if docker is running.
If the docker is not running, start it.
2. List Remote Docker Images
We need to find what images exist in target Docker API.
3. Get a Shell
After getting an image, we can use it to create a new container and run with executing sh
.
Now we should get a root shell.
Remote Code Execution (RCE)
Reference: https://dejandayoff.com/the-danger-of-exposing-docker.sock/
We might be able to execute remote code by create a new container image using the existing one.
1. Check the Image Name
First we need to find the existing container image and the name of it.
2. Create/Start a New Container
If we found the container image name, prepare a new container configuration named “image.json”.
Then create a new container using Docker Engine API.
We get the new container ID, so copy it.
After that, start the new container.
3. Create a New Exec Instance
Next create a exec instance to reverse shell.
Ncat
Socat
We get a exec ID, so copy it.
4. Start an Exec Instance & Reverse Shell
Start a listener in local machine.
Now start an exec instance and get a shell.
We should get a shell.
Last updated