Kali Linux | Deploy it in a Docker Container

0
linfra-docker-kali-featured

If you are like me, you prefer to not have to dual boot and certainly do not want to install Kali directly on your production machine – and if you don’t mind going without a GUI, there is a solution. Using Kali in a docker container will give you all of the capabilities and tools (with a few limitations) that you love about Kali without the install, dual-boot or live environment.

Since I am primarily an Ubuntu/Debian guy, I am writing this assuming that you are too! I am sure the same (or similar) process can be followed on your distribution of choice as well but I will only be covering Ubuntu here.

The first thing that we must do is install docker. I have taken the following commands directly from the docker documentation here to get docker up and running on an Ubuntu based machine.

The following procedure assumes that you do not already have docker running.

# remove older versions of Docker:
sudo apt-get remove docker docker-engine docker.io containerd runc

# Add Docker GPG key to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add Docker repository to your system:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# install Docker:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

# Validate that Docker installed:
docker --version
Docker version 20.10.12, build e91ed57

Now you should have a functioning Docker installation on your machine. As it stands, you will need to run docker with elevated privileges using sudo. This is not ideal. You can create a Docker group to allow you to run Docker commands without needing to use sudo by following the instructions below – also found here. NOTE: Before you are able to run Docker commands without sudo, you will need to log out and back into your system.

# Add Docker group to your system:
sudo groupadd docker

# Add your user to the Docker group created above:
sudo usermod -aG docker $USER

Now we will need to get Kali running in a docker container. Kali publishes an official Docker image so this is relatively straight forward in Docker.

# Download Kali linux Docker image:
docker pull kalilinux/kali-rolling

Now we will create a Docker image of Kali that we can easily start and interact with repeatedly as needed. This will start the image interactively but will also give us the ability to start it on demand much easier.

# Create Docker image called 'kali':
docker run --name kali --net="host" --privileged -e DISPLAY=$DISPLAY -it -v /tmp/.X11-unix:/tmp/.X11-unix kalilinux/kali-rolling /bin/bash

# Start kali Docker image whenever you would like to use it with the following command:
docker start kali /bin/bash

# Install the default metapackage in your Kali container:
apt update; apt install kali-linux-headless

That is it! Now you have a configured docker image of Kali Linux at your disposal to use on-demand whenever you need to do a little hacking!

Happy Hacking!

Leave a Reply