Docker escape
dockers which running with '--privileged' or '--cap-add=SYS_ADMIN ' parameters could be exploited to gain access to the underline system from the docker container.
How can you tell if you’re in a container?
cgroups stands for “control groups.” It is a Linux feature that isolates resource usage and is what Docker uses to isolate containers. You can tell if you are in a container by checking the init process’ control group at /proc/1/cgroup
. If you are not located inside a container, the control group should be /
. On the other hand, if you are inside a container, you should see /docker/CONTAINER_ID
instead.
How can you tell if a container is privileged?
Once you’ve determined that you are in a container, you need to determine if that container is privileged. The best way to do this is to run a command that requires the --privileged
flag and see if it succeeds.
For example, you can try to add a dummy interface by using an iproute2
command. This command requires the NET_ADMIN
capability, which the container would have if it is privileged:
If this command runs successfully, you can conclude that the container has the NET_ADMIN
capability. NET_ADMIN
is part of the privileged capabilities set, and containers that don’t have it are not privileged. You can clean up the dummy0
link after this test by running this command:
Exploit #1
Exploit #2
source:
https://medium.com/better-programming/escaping-docker-privileged-containers-a7ae7d17f5a1
Last updated