Kali Linux LXC/LXD Images
Content:
Overview
Command line Kali LXD container on Ubuntu host
Gui Kali LXD container on Ubuntu host
Privileged Kali LXC container on Kali host
Unprivileged Kali LXC container on Kali host
References
Overview
Kali Linux containers are the ideal solution to
run Kali Linux within other Linux distributions
provide isolated environments for development or testing activities
without the overhead of virtual machines. Docker is the preferred solution for applications whilst LXC/LXD are preferred for entire systems.
Linux containers provide features like snapshots and freezing which comes in very handy when developing or testing software.
Kali images are available on the image server for LXC and LXD and can easily be launched either in LXD using the βimages:β image server or in LXC using the βlxc-downloadβ template.
LXC is a userspace interface for the Linux kernel containment features. Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers.
LXD is a next generation system container manager. It offers a user experience similar to virtual machines but using Linux containers instead. Itβs image based with pre-made images available for a wide number of Linux distributions and is built around a very powerful, yet pretty simple, REST API.
LXD vs LXC:
LXD is the more convenient of the two but is only available in Ubuntu or other distributions (such as Kali) as snap package.
LXC is available in more distributions and preferred in Kali as it is supported natively and does not required snapd to be running.
Command line Kali LXD container on Ubuntu host
Installing a Kali Linux container in Ubuntu only requires a few steps:
Install LXD
Launch a Kali container
Install additional packages inside the container
Create non-root user
Login
1 - Install lxd via snap and perform initial setup:
2 - Launch your first Kali Linux container with
3 - Install additional packages inside the container via
4 - Create non-root user - βkaliβ in this example:
5 - Login to the new container as user βkaliβ via
Voila!
Container management:
Start:
lxc start my-kali
Stop:
lxc stop my-kali
Remove:
lxc destroy my-kali
GUI Kali LXD container on Ubuntu host
Installing a Kali container to run GUI applications is similar to the previous example with a few additional steps:
Install LXD
Create GUI profile and launch a Kali GUI container
Install additional packages inside the container
Create non-root user
Start Kali Xfce panel
Customise Kali Xfce panel
1 - Install lxd via snap and perform initial setup (if not already done):
2 - Launch your first Kali Linux container with
3 - Install additional packages inside the container via
4 - Create non-root user - βkaliβ in this example:
5 - Start Kali Xfce panel via
Customise the panel as desired.
Container management:
Start:
lxc start gui-kali
Stop:
lxc stop gui-kali
Remove:
lxc destroy gui-kali
Privileged Kali LXC container on Kali host
Privileged containers are containers created by root and running as root. They are quicker to setup than unprivileged containers but are inherently unsafe. Installing a privileged Kali Linux container on a Kali host only requires to:
Install and setup lxc
Download the kali image from the image server
Start the container
Attach to the container
1 - Install lxc and setup the network:
2 - Download the Kali Linux image from the image server via
This will list all available images.
When prompted, enter:
Distribution: kali
Release: current
Architecture: amd64 (or other as applicable)
3 - Start the container with
4 - Attach to the container via
There you have it. Next you should set a root password and install the βkali-linux-defaultβ metapackage.
Container management:
Start:
sudo lxc-start -n my-kali -d
Stop:
sudo lxc-stop -n my-kali
List:
sudo lxc-ls -f
Info:
sudo lxc-info -n my-kali
Remove:
sudo lxc-destroy -n my-kali
Unprivileged Kali LXC container on Kali host
Unprivileged containers run in a user context and are considered safer and are preferred over using privileged container. The setup it slightly more involved:
Install and setup lxc
Setup LXC for unprivileged containers
Download the kali image from the image server
Start the container
Install some additional packages
Create non-root user
Login
1 - Install lxc (if required):
2 - Setup LXC for unprivileged containers
Next we have to add two lines into ~/.config/lxc/default.conf
whose subuid & subguid match those listed in /etc/subuid
and /etc/subgid
. First letβs get the idβs via cat /etc/s*i d grep $USER
The result should look like this:
Substitute the IDβs in the following commands with the ones in the previous output:
3 - Download the Kali Linux image from the image server via
This will list all available images.
When prompted, enter:
Distribution: kali
Release: current
Architecture: amd64 (or other as applicable)
4 - Start the container with
But before we login, we perform some post-installation setup tasks
5 - Install default packages:
6 - Create a non-root user:
7 - Login as non-root user via
And perform the following on initial login to get some colors in the console:
Container management:
Start:
sudo lxc-start -n my-kali -d
Stop:
sudo lxc-stop -n my-kali
List:
sudo lxc-ls -f
Info:
sudo lxc-info -n my-kali
Remove:
sudo lxc-destroy -n my-kali
References:
Last updated