Containers for Pentesters
About Me
Ex-Pentester/IT Security person
Senior Security Advocate at Datadog
CIS Benchmark author, Docker and Kubernetes
Member of Kubernetes SIG-Security & CNCF TAG-Security
What's a container then?
Demo
The goal of this demo is to show that containers are just processes.
ps -fC nginx
docker run – name webserver -d nginx
ps -fC nginx
docker exec webserver touch /my_new_file
sudo ls /proc/PID/root
What Does Docker do?
Demo
sudo socat -v UNIX-LISTEN:/tmp/tempdock.sock,fork UNIX-CONNECT:/var/run/docker.sock
sudo docker -H unix:///tmp/tempdock.sock images
Docker Desktop
An important Aside : Docker Security model
docker run -ti
--privileged
--net=host --pid=host --ipc=host
--volume /:/host
busybox
chroot /host
Why do we need these things as pentesters?
VM vs Container
We're looking here at contrasting VMs and containers. The major difference is in likely size. It's kind of difficult to get smaller VM images, to roughly the size of container images.
Also if you need old obscure pentest tools, you can containerize them so they can get all the old libs they rely on.
Also you can avoid splatting one set of python/php/node/ruby libs with another.
Docker Hub
Images from Docker Hub
Generally you should not use people's images directly from Docker hub, instead you can get inspiration from Dockerfiles and build your own.
Outside of the base images.
Important point is that a) there could be malware and b) more likely it just hasn't been patched in years.
These are some of my images, the point here is to talk about the fact that other people are using them.
This is basically not a good idea, as apart from me, no-one has any idea that these images are maintained, secure and not actively malicious.
Make your own Images
Before we go on to talk about approaches, the point of the last two slides has essentially been about the dangers of using someone else's images.
Tool specific
vs
Kitchen Sink
There are two approaches we can take to using Containers for pentesting, one is image per tool, the other is kitchen sink containers.
Whilst purists will say that the Tool specific option is the only correct one, in reality it's a lot easier to maintain a couple of kitchen sink images.
Choosing a base distro
Scratch
Alpine
Debian/Ubuntu
Red Hat
Not CentOS*
Dockerfile Basics - Single command image
FROM ubuntu:22.04
RUN apt update && apt install -y nmap && apt-get clean
ENTRYPOINT ["nmap" ]
Demo - Using the Basic image
docker build -t nmap -f Dockerfile.nmap .
docker run --net=host nmap -v -n -sT 127.0.0.1
Trick - Getting root back in non-root envs
It's possible to have an image that can still do root things even if it's not root, using file capabilities
FROM ubuntu:22.04
RUN cp /bin/bash /bin/setuidbash && chmod 4755 /bin/setuidbash
RUN adduser tester
USER tester
CMD ["/bin/bash" ]
Getting Data in and out of containers
docker run -it -v ~/testdata:/testdata [image] /bin/bash
This is an important point about how you get data in and out of your containers. We should also mention that permissions are important. If you're root (or sudo root) locally it's fine, if you're running as a standard user, some finagling might be needed.
Conclusion
Containers are quite easy to use once you understand what they do.
Very helpful for keeping tool envs clean
Very helpful for jobs that use Kubernetes
Resume presentation
Containers for Pentesters
{"metaMigratedAt":"2023-06-18T02:53:31.448Z","metaMigratedFrom":"YAML","title":"Containers for Pentesters","breaks":false,"description":"Containers for Pentesters As a pentester,red teamer,general security person, there’s often the need to use a lot of tools to get the job done, and often a need for different environments for different customers. Traditionally this kind of requirement has been managed by using Virtual Machines to create isolated environments, but keeping those VMs updated with patches and storing them can be a bit of a pain. However, there is another way! Containers can be used to create regularly updated, isolated environments for running tools with less resource overhead than VMs. This talk will explain a bit about how containers work, and go through the tricks and tips of using them for security work.","slideOptions":"{\"theme\":\"blood\",\"allottedMinutes\":30}","contributors":"[{\"id\":\"d371f3af-4727-4a8c-863f-ebcf30897cef\",\"add\":8827,\"del\":2828}]"}