Docker Escape
Docker escape refers to a security vulnerability that could potentially allow an attacker to break out of a Docker container and gain access to the host system or other containers running on the same
Investigation
If we are in the docker container, we first need to investigate basic information about the container.
Access Another Host
If we found another host but cannot access it by restrictions, we need to port forward. Please see details for port fowarding.
Import Required Binary from Local Machine
The container generally has few command that we want to use to exploit, so we need to import manually the command binaries if we need. Below are examples to transfer arbitrary binary into the docker container.
Privilege Escalation to Root
Please see Linux Privilege Escalation.
Run Vulnerable Docker Image
According to Hacktricks, we can escape a docker container with the vulnerable image. Execute the following command in the target machine where a docker container is running..
Download Interesting Files
Also we can use “scp” under the condition that the local machine opens SSH server.
Run Existing Docker Image
1. Check if current user belongs to "docker" group
2. List Docker Images
3. Start Container and Get Shell
If we found Docker images running, we can use it to get a root shell Replace “example” with the docker image you found.
Alternatively we can use following commands.
After that, you can investigate sensitive information in the /mnt/
folders.
Docker Socket Escape
Reference: https://gist.github.com/PwnPeter/3f0a678bf44902eae07486c9cc589c25
Establish Persistence After PrivEsc
After that you invaded the docker container, you might be able to make it persistence while evading the IDS alerts by creating a docker compose file and abusing the entrypoint option to grant you a reverse shell.
Create a ~/docker-compose.yaml in the container.
You need to replace the <image>
, <local-ip>
, <local-ip>
with your environment.
Then start listener in your local machine.
Now run the docker compose in remote machine. You should gain a shell.
Amazon Elastic Container Registry (ECR) Public Gallery
1. Run the Docker Container
Retrieve a Container Image
Check if It was Pulled
Run the Container and Interect with It
2. Get Sensitive Information in the Container
You may be able to get the interesting data like api_key.
3. Get Sensitive Information in Local Machine
Check the Container Config and Retrieve Sensitive Information
Process the following flows in your local machine.
Last updated