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:

  1. Install LXD

  2. Launch a Kali container

  3. Install additional packages inside the container

  4. Create non-root user

  5. 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:

  1. Install LXD

  2. Create GUI profile and launch a Kali GUI container

  3. Install additional packages inside the container

  4. Create non-root user

  5. Start Kali Xfce panel

  6. 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:

  1. Install and setup lxc

  2. Download the kali image from the image server

  3. Start the container

  4. 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:

  1. Install and setup lxc

  2. Setup LXC for unprivileged containers

  3. Download the kali image from the image server

  4. Start the container

  5. Install some additional packages

  6. Create non-root user

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

Was this helpful?