๐docker container escape
Theory
Docker is an open-source containerization platform used for developing, deploying, and managing applications in lightweight virtualized environments called containers.
Practical (Exploitation)
Checking if we're in Container
List running processes
If there are few no. of process is running then you might be in docker.
Look for docker.env file
If you see .dockerenv in base dir, then youโre in a container.
Those pesky cgroups
Navigating to โ/proc/1โ and then catting the โcgroupsโ file (cat cgroup).
Use following code to Verify you are in Docker
Docker Escaping Techniques
1. Escape via Exposed Docker Daemon
Run the following cmd
If weโre in bash
If weโre in alpine
You can see the images repo
NOTE: ubuntu:18.04 is the image repo
2. Shared Namespaces
By using ps aux you can view the process with processID see pid 1 is running root it is the first one that executed when the system is booted.
Exploiting it with nsenter
3. Escape By Mounting File System
NOTE: In this case sda2 is the dir we mount. Might be different in your case
4. Misconfigured Privileges
list out all the capabilities
If we get sys_admin capability, means the system is vuln.
On attacker VM:
First make a shell.sh and set python server and set listner.
On target machine:
5. Exploitation of docker.sock in /var/run or /run if you're ROOT
Check /var/run dir for docker.sock file, if itโs there and youโre root then you can exploit it. First see that you can use curl cmd, if not then wget static curl from your system for static curl see the arch of target machine and get the static curl from Resource
STEP1: Listing the images of the container of the host
STEP2: Now generate id_rsa in your machine
STEP3: Creating a new docker container with image ID
NOTE: replace โc3:latestโ with the docker image name that youโll get from step1. eg: โRepoTagsโ:[โc3:latestโ]
Now youโll see you created a docker and get the id. eg: {โIdโ:โc19a25c6cc7245030bf9741d300f632cc7f1e5f12adad238edce23d387ba00c2โ,โWarningsโ:[]}
STEP4: Now we gonna use the id and start the docker
STEP5: Login SSH via your private key as user root and now youโre root
6. Debugfs
3. Writeable Backup Scripts
If we can find any writable backup scripts in a docker instance then we can add our own reverse shell into it.
Run a netcat listener
After the script executes you should get a root shell on the real machine.
REFERENCES
Last updated