Setting Up Kali in Docker
Docker helps developers build, share, run, and verify applications anywhere with containers. More info on containers here.
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.
My notes on Docker can be found here.
Introduction
This will be a guide on setting up Kali Linux in a docker container. Including pulling a new image, setting it up with prefer tools, services, configs, and a GUI if we want. Then covering how to save the image to a file to use on other machines or upload to docker hub to share.
Links
- Official Docker Images
- Kali Rolling Docker Image on Docker Hub
Using Kali Docker Images
Grab the latest rolling docker image with
sudo docker pull docker.io/kalilinux/kali-rolling
Followed by
sudo docker run -it kalilinux/kali-rolling
NOTE: all the images do not come with the “default” metapackage. You will need to run:
apt update && apt upgrade -y
Installing tools
It’s pretty simple and basic from here - run
apt install -y [tool-name]
Eg.
apt install -y nano bloodhound.py xrdp
Setting up a share
To get file sharing setup between our container and host, we need to have a directory setup for that. On our host, we make a folder wherever we want. Create a quick file in that directory so we can verify the share is working after we run it.
Now when running our Kali image with these parameters:
sudo docker run -v /home/th4ntis/Docker/Share:/home/share -it kalilinux/kali-rolling
When in our container, if we go to the /home/share directory, we can see the file we created on our host in the Share directory we made.
Getting a Graphical User Interface(GUI)
Most the tools we run in Kali will be CLI based but sometimes we may need/want a GUI. To get a gui running we need to run
sudo docker run -it -p 13389:13389 kalilinux/kali-rolling
Then we install the XFCE desktop environment with
apt install -y kali-desktop-xfce xrdp
Since we chose port 13389
for our port to forward, we need to edit the xrdp config
nano /etc/xrdp/xrdp.ini
Change the line that says
port=3389
to
port=13389
Then start the xrdp service
service xrdp start
Verify the XRDP service is running
service xrdp status
Before we start the RDP session, we need to change the root password with
passwd
Now we can use whatever RDP service we want to access our Kali Docker via GUI using localhost:13389
. I’m using Remmina, but you can use any software you choose that supports RDP.
NOTE: Depending on your RDP software, you will need to choose the screen resolution you want. Otherise it will default as a 600x800 resolution.
Adding a new non-root user
Some tools don’t play wel when running as root, so we should make a new user. To do this, we run
adduser [user]
Type in the password, then you can press ENTER
when asked for full name, room number, etc.
OPTIONAL: To add the new user to the sudoers file. This will make sure the new user can permissions with as a super user.
usermod -aG sudo [user]
We can change to the newly created user with
su [user]
Making a custom image
While in your container, install all your tools, setup configs, etc. It is important to keep the container running with all your settings, tools and configs! Exit the container and keep it running with
CTRL+P CTRL+Q
Then run
sudo docker commit [container_id] [image_name]
Save the container in an image you can transfer to other machines with
sudo docker save [image_name] > [image_name].tar
Now load the image on the new machine with
sudo docker image load < [container_name].tar
Now run the new container with all of our settings
sudo docker run -it -p 13389:13389 -v /home/[user]/Docker/Share:/home/share [container_name]
I’ve added that as an alias in my terminal
alias kali-docker='sudo docker run -it -p 13389:13389 -v /home/th4ntis/Docker/Share:/home/share [container_name]'
Conclusion
That’s it! Now you have a nice, custom Kali docker image setup with our tools, users, settings, and configs that don’t require any setup or even an internet connection!