Kali Linux for Vagrant: Hands-on

The developers at Kali Linux have released a Vagrant distribution of their latest version. Here is a look at that release - and at the Vagrant tool itself

I recently saw the announcement for Kali Linux on Vagrant. I have been a huge fan of Kali Linux for a very long time, and I am interested in virtualization (and currently using VirtualBox in an educational environment), so this was a very interesting combination to me. I have now installed it on a few of my systems, and so far I am quite impressed with it.

The rising tension between IoT and ERP systems

The Internet of Things is the new frontier. However, generations of ERP systems were not designed to handle global networks of sensors and devices.

Read More

The logical place to start is with a brief overview of Vagrant itself. What is Vagrant? According to their web page:

Vagrant is a tool for building and managing virtual machine environments in a single workflow

What Vagrant actually does is provide a way of automating the building of virtualized development environments using a variety of the most popular providers, such as VirtualBox, VMware, AWS and others. It not only handles the initial setup of the virtual machine, it can also provision the virtual machine based on your specifications, so it provides a consistent environment which can be shared and distributed to others.

The first step, obviously, is to get Vagrant itself installed and working -- and as it turns out, doing that requires getting at least one of the virtual machine providers installed and working. In the case of the Kali distribution for Vagrant, this means getting VirtualBox installed.

Fortunately, both VirtualBox and Vagrant are available in the repositories of most of the popular Linux distributions. I typically work on openSUSE Tumbleweed, and I was able to install both of them from the YAST Software Management tool. I have also checked that both are available on Manjaro, Debian Testing and Linux Mint. I didn't find Vagrant on Fedora, but there are several articles in the Fedora Developer Portal which describe installing and using it.

SEE: 20 quick tips to make Linux networking easier (free PDF)

If you are not able to find Vagrant in the software sources of whatever operating system you are using, you can go to the Vagrant Downloads page, and you will find installation images for various Linux distributions (and a generic Linux image), macOS and Windows.

Once you have them both installed, you should give some thought to disk space. The Vagrant "box" file will require about 4GB for each virtual machine, and the actual Kali VM will be at least 10GB and possibly more depending on how you configure and provision it (other VMs may be much smaller, of course; the Vagrant precise64 image comes in at about 5GB, for example). Both of these will land in your home directory by default, so if you don't have that much free disk space, or you just prefer to keep data in some other specific place (/data in my case), you need to configure that first.

virtualbox.png
Image: J.A. Watson

For VirtualBox this is done using the File/Preferences dialog, as shown here. The first item is the default machine location, and you can see that I have mine set to "/data/VirtualBox VMs".

For Vagrant it is a bit less obvious; you have to set the environment variable VAGRANT_HOME. The typical way to do this on Linux is in your .bashrc file, by adding this statement:

export VAGRANT_HOME=/data/jw/.vagrant.d

Once you have made these two adjustments, you are ready to download the Kali Vagrant image. When you initialize a Vagrant configuration, it will create a text file containing the specifications of that image (creatively named Vagrantfile). You can only have one Vagrantfile in a directory, so the simplest way to do this is to make an empty directory for each image (or project) that you want to install, and then change to that directory before running the command:

$ vagrant init offensive-security/kali-linux

Note that this command does not require root privileges.

This will fetch the necessary information from the Vagrant Cloud, and create a default configuration file (Vagrantfile). Oh, a quick note about the Vagrant Cloud; if you are curious about what other images and versions are available, just follow that link and have a look around. There are all sorts of other Linux images (Debian, CentOS, Arch, more Ubuntu versions than you can shake a stick at, Oracle Enterprise Linux, and plenty of others), and a variety of pre-configured and provisioned development environments for both general development and specific applications.

The next step is to let Vagrant actually download and install the VM image, and start it up. This is done with the command:

$ vagrant up

This command checks to see if the necessary files have already been downloaded. If they have not (this is the first time you have started this VM), it will fetch everything it needs from the Vagrant Cloud website.

That will take some time (typically 10-15 minutes if you have a reasonable Internet connection; something measured in hours or days if you are doing it on Airport Free Wi-Fi...), and will produce a lot of text to keep you informed of what it is doing and how much progress is made on the downloads.

kalivagrant.png
Image: J.A. Watson

When the download is complete you will see the VM GUI pop up, and the normal Kali Linux boot process will run in that window. After about a minute or so, you will get the Kali login window shown here.

kalidesktop.png
Image: J.A. Watson

You can then login using the usual default account (root/toor), and you will get the standard Kali (Gnome 3) desktop. The Kali VM has a NAT interface configured, so you have internet access (as shown in the browser window within the screen shot).

One other small but very useful feature; Vagrant configures a shared directory between the host and the Kali guest, by mounting the current working directory of the host (the one containing the Vagrantfile) on the /vagrant directory of the Kali guest. This is particularly convenient because it allows you to keep data in the guest which will survive a reset of the Vagrant machine.

Let me expand on that a bit further. One of the biggest advantages of Vagrant is that it is very easy to reload a machine from scratch, and return to the original "clean" condition. This includes re-initializing the disk of the VM, so anything that you have stored there will be gone. Any files that you want to keep across such a reset can simply be placed in the /vagrant directory, and they will once again be there in the new system.

Vagrant also configures ssh access to the VM for you, without you having to figure out the IP address or port number; you just have to use vagrant ssh to connect.

SEE: How to find files in Linux with grep: 10 examples (free PDF)

There are a number of ways that you can manage your running Kali Vagrant system:

  • vagrant reload reboots the VM
  • vagrant suspend saves the current state of the VM and then stops it. This allows you to return to exactly the same state at a later time with vagrant up. Note that this uses even more disk space, because it stores the state of the VM RAM to disk as well, but it is faster than a vagrant halt / vagrant up sequence
  • vagrant halt stops the VM, performing a normal shutdown of Kali
  • vagrant destroy removes the VM from your system. If the VM is currently running, it will simply be killed -- there's no sense in bothering with a graceful shutdown, because the machine is toast anyway. Everything except the Vagrantfile will be deleted, so you will recover the disk space from that.

So there you have it. Vagrant provides an easy way to create, run and manage a virtual Linux system, and Kali now provides a distribution image for Vagrant. Together, this means that you can have Kali up and running in 30 minutes or less. Nice. In addition, if you get interested in Vagrant itself there are lots of other distributions available in the Vagrant Cloud. Extra nice.

RECENT AND RELATED COVERAGE

Hands-on with MX Linux: A pleasant, easy-to-install Linux distribution

MX Linux is a descendant/spin-off from Antix and MEPIS Linux. I want to see what it is like to install and run on both UEFI and MBR laptops.

Hands-on with Linux Mint Debian Edition 3 Beta

The long-awaited LMDE update is finally (really) on the way!

Linux phone battery bug: Purism's Librem 5 delayed until April 2019

Purism gave its Librem 5 phone an updated SoC, but found it has a battery-draining bug that's delayed production.

Even Linus Torvalds doesn't completely understand the Linux kernel

In a wide-ranging interview at Open Source Summit, Torvalds talked about programmers, Linux, and open-source development.

Linux distribution comparison chart (Tech Pro Research)

If you're new to the world of Linux and trying to figure out which distribution is right for your needs, this chart can help.

Microsoft's obsession with Windows is ending, and I couldn't be happier (CNET)

Commentary: It's all about AI and the web now.

How to expose an internal Linux server to the internet with PageKite (TechRepublic)

Jack Wallen shows you how to easily expose an internal Ubuntu server to the outside world with the help of PageKite.