Docker and Kali Linux

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.

Using Kali Docker Images

Grab the latest rolling docker image with

sudo docker pull docker.io/kalilinux/kali-rolling
image

Followed by

image

NOTE: all the images do not come with the β€œdefault” metapackage. You will need to run:

Installing tools

It’s pretty simple and basic from here - run

Eg.

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.

image

Now when running our Kali image with these parameters:

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.

image

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

Then we install the XFCE desktop environment with

Since we chose port 13389 for our port to forward, we need to edit the xrdp config

Change the line that says

to

image

Then start the xrdp service

image

Verify the XRDP service is running

image

Before we start the RDP session, we need to change the root password with

image

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. image image

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

image

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.

image

We can change to the newly created user with

image

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

Then run

image

Save the container in an image you can transfer to other machines with

image

Now load the image on the new machine with

Now run the new container with all of our settings

image

I've added that as an alias in my terminal

image

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!

Last updated