Running kali linux on any linux distro using docker

Installing docker

You can follow this link to install docker on your machine

Install kali in docker

Run this command to pull kali images

1
docker pull kalilinux/kali-linux-docker

Run this command

1
docker run -Pti --privileged -e DISPLAY=:1.0 --device /dev/snd -v /tmp/.X11-unix:/tmp/.X11-unix -v /home/vuquangtam/Docker/Share:/share --net=host --name kali kalilinux/kali-linux-docker

to create a new container. It will return a shell to interact with. By default, there are no tools added to this image, so we must install additional toolpack, you can follow this link to choose your suitable one.

After create container. you can check containter id by run this command

1
docker ps -a

To start a container, run

1
docker start [container's id]

Adding GUI

You can install any desktop environment that kali support. In my case, i’ll install XFCE because it’s lightweight. Run this command to install XFCE in your docker container

1
apt-get install kali-defaults kali-root-login desktop-base xfce4 xfce4-places-plugin xfce4-goodies

Run Docker GUI in new xsession

If you want to run in new window in current xsession. you need to install Xephyr

1
apt-get install xserver-xephyr

I wrote a small script to run. You just need to copy it to /usr/bin for convenient. The script need a root priviledge to stop process.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
container="kali"
init_desktop () {
if [[ $1 = "window" ]]; then
nohup Xephyr -ac -br -noreset -screen 1280x600 -resizeable :1 &> /dev/null &
sleep 1
else
if [ ! -f /tmp/.X1-lock ]; then
nohup xinit -- :1 vt9 &> /dev/null &
sleep 4
fi
fi
}
stop_desktop () {
nohup kill $(pgrep xinit) &> /dev/null
nohup kill $(pgrep Xephyr) &> /dev/null
}
case "$1" in
"start")
echo "Starting..."
init_desktop $2
nohup docker start $container &> /dev/null
docker exec -it -d --privileged kali x-session-manager
;;
"run")
echo "Running $2..."
xhost + &> /dev/null
docker run -ti --rm --privileged --device /dev/snd -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /home/vuquangtam/Docker/Share:/share -p 8080:8080 --net=host vuquangtam/kali $2
;;
"shell")
nohup docker start $container &> /dev/null
docker exec -it --privileged kali bash
;;
"stop")
echo "Stopping..."
nohup docker stop $container &> /dev/null
stop_desktop
;;
"restart")
echo "Restarting..."
nohup docker restart $container &> /dev/null
docker exec -it -d --privileged kali x-session-manager
;;
"pause")
echo "Pausing..."
nohup docker pause $container &> /dev/null
stop_desktop
;;
"resume" | "unpause")
echo "Resuming..."
init_desktop $2
nohup docker unpause $container &> /dev/null
;;
*)
;;
esac

Some examples:

1
2
3
4
5
sudo nameOfScript start window # to run a new window in current xsession
sudo nameOfScript start # to start new session in vt9 (press Ctrl+Alt+F9 to switch in Ubuntu/Linux Mint)
sudo nameOfScript stop
sudo nameOfScript restart
sudo nameOfScript run wireshark