Understand how docker works
Go to the Intro to Docker ๐ณ note.
.dockerenv
- If we find a
.dockerenv
file in the root directory, we are running inside a docker container
- If we find a
.sh
on the/opt/backups
directory like a backup script that might be running a cron job, we can try to write a reverse shell to it:
Being part of the docker group
- If we find out that our victim user belongs to the docker group, we can do the following (based on GTFObins):
Escaping a container
-
Once we are root by exploiting a capability vulnerability as example, we have to pivot to the host of the container as follows:
-
Check environment variables for misconfigurations with
printenv
-
Run
ifconfig
to see if we are connected to the eth0 -
Run
arp -a
to discover other hosts on the network
- So now we know that
172.17.0.1
is our host - Now we want to perform an nmap scan to it, so we will upload a nmap binary
- Download the source code one
- Install with the following:
-
If you haver dependency errors try this nmap binary
- With this one just upload it to the container and the add it execution permissions
-
Now run:
- The port 5986 is for Microsoftโs Open Management Infraestructure (OMI) service for remote configuration management of *nix VMs in Azure. Our host must be a simulation of an Azure Linux VM.
- There is aย CVE for an unauthenticated RCE, and aย public exploitย for OMI we can test.
- You can check the exploitation in this notes in CVE-2021-38647
Unprotected TCP socket (port 2375, 2376)
Utilizing Docker via unprotected tcp socket (2375/tcp, maybe 2376/tcp with tls but without tls-auth), an attacker can create a docker container with the โ/โ path mounted with read/write permissions on the host server that is running the docker container and use chroot to escape the container-jail.