How I accidentally became root through Docker
A “keyword counter” page, a semicolon, and a group membership that should never have been there.
This was my first ever write-up. I’ve kept it the way I wrote it. The lab is on thundercipher.tech.
Step 1: recon.
I started with a basic Nmap scan to see what I was dealing with. It returned five open ports, which gave me a few places to start poking around.
$ nmap -sC -sV 192.168.5.109 PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 80/tcp open http (Apache) 3306/tcp open mysql 8000/tcp open http-alt (Nginx)
Step 2: checking the doors.
- FTP (21): I logged in as
anonymousand it worked. I found a note file and got excited, but it was a rabbit hole. - SSH and MySQL (22, 3306): without credentials I was locked out.
- Web (80, 8000): port 80 was a default Apache page. Port 8000 was running Nginx, which was more interesting.
Since the ports weren’t giving much away, I ran Gobuster on both web ports to find hidden files.
$ gobuster dir -u http://192.168.5.109:8000 -w common.txt -x php,txt,sh
That was the breakthrough. It found .bashrc and a very suspicious test.php.
Step 3: breaking the script.
I opened test.php. It was blank, but it answered with an error: “Please POST a proper query.” That told me it wanted a POST request, and that the parameter was probably called query.
My guess was that the script took my input and ran a command with it, so I tried command injection with a semicolon.
$ curl -X POST -d "query=;id" http://192.168.5.109:8000/test.php
uid=1001(apiuser) gid=1001(apiuser)
Step 4: the Docker mistake.
I was in, but I wasn’t root. I looked at my user again and saw the important part: groups=1001(apiuser),115(docker).
Being in the docker group is dangerous. It means I can talk to the Docker daemon, which runs as root. I didn’t need a password. I only had to ask Docker to start a container with the host’s disk mounted inside it.
query=;docker run -v /:/mnt ubuntu cat /mnt/root/root.txt
docker run ... ubuntustarts an Ubuntu container.-v /:/mnttakes the server’s entire disk and plugs it into the container at/mnt.cat /mnt/root/root.txtreads the flag.
Docker obeyed, and the flag printed on my screen.
Proof of pwn.

Challenge completed on Thunder Cipher.