Did you know that you can now manage Kali Linux Virtual instance with Vagrant?. Being a huge fan of Kali Linux, I’m happy to share with you a process of running Kali Linux with Vagrant & VirtualBox hypervisor. Kali Linux is the leading advanced Penetration Testing and Security Auditing Operating system based on Debian.

Kali Linux contains several hundred tools geared toward computer Forensics, Penetration Testing, Reverse Engineering, Security research. Kali development is funded and maintained by Offensive Security, a leading information security training company.

For those new to Vagrant, Vagrant is an open source tool for building and managing virtual machine environments in an easy-to-use single workflow.

Setup Requirements

  • Any decent Linux distribution – Debian, Ubuntu, Arch, Fedora e.t.c
  • CPU with VT-X/AMD Virtualization extensions
  • VirtualBox and Vagrant installed

Step 1: Install Vagrant and VirtualBox

To install Vagrant and VirtualBox, refer to our previous guides:

How to install latest VirtualBox on Kali Linux Rolling

How to install the latest VirtualBox on Ubuntu 18.04 / Debian 9

Install Latest Vagrant on Ubuntu 18.04 / Debian 9 & Kali Linux

Step 2: Download Kali Vagrant box

After installing VirtualBox and Vagrant, download Kali Linux Vagrant box image. You have two options for this.

  1. Download Kali Linux full image – comes with all Kali packages
  2. Download Kali Linux Light – contains stripped down package list

Download Vagrant box using the command:

$ vagrant box add offensive-security/kali-linux
==> box: Loading metadata for box 'offensive-security/kali-linux'
    box: URL: https://vagrantcloud.com/offensive-security/kali-linux
==> box: Adding box 'offensive-security/kali-linux' (v2018.3.1) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/offensive-security/boxes/kali-linux/versions/2018.3.1/providers/virtualbox.box
==> box: Box download is resuming from prior download progress
==> box: Successfully added box 'offensive-security/kali-linux' (v2018.3.1) for 'virtualbox'!

For Kali Linux Light, replace kali-linux with kali-linux-light

$ vagrant box add offensive-security/kali-linux-light
==> box: Loading metadata for box 'offensive-security/kali-linux-light'
    box: URL: https://vagrantcloud.com/offensive-security/kali-linux-light
==> box: Adding box 'offensive-security/kali-linux-light' (v2018.3.1) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/offensive-security/boxes/kali-linux-light/versions/2018.3.1/providers/virtualbox.box
==> box: Successfully added box 'offensive-security/kali-linux-light' (v2018.3.1) for 'virtualbox'!

The added Vagrant boxes should be visible from

$ vagrant box list  | grep offensive 
offensive-security/kali-linux       (virtualbox, 2018.3.1)
offensive-security/kali-linux-light (virtualbox, 2018.3.1)

Step 3: Start Kali Linux virtual machine

Start by  creating an empty directory  for Kali project and then generate a Vagrant file from there:

$ mkdir -p vagrant-projects/kali
$ cd vagrant-projects/kali
$ vagrant init offensive-security/kali-linux

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

This command generates a Vagrantfile for you which contains all the configuration options for the virtual machine. It is worth knowing that every vagrant command should be run from the directory containing Vagrantfile.

You can modify the file to your liking before running the vagrant up command:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "offensive-security/kali-linux"
  config.vm.box_check_update = false
  config.vm.hostname = "kali"
  config.vm.synced_folder "/home/jmutai/Projects", "/vagrant_data"
  config.vm.provider "virtualbox" do |vb|
  # Display the VirtualBox GUI when booting the machine
     vb.gui = false
     vb.memory = "2048"
  end
end

When done with the modifications, save the file and run

$ vagrant up

Here is a sample output

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/jmutai/hacks/vagrant/labs/kali
    default: /vagrant_data => /home/jmutai/Projects

To access the VM shell, run:

$ vagrant ssh

You can also use your host ssh client and access the Kali Linux instance shell through assigned private IP address.

$ ssh [email protected]
Warning: Permanently added '192.168.90.99' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Linux kali 4.18.0-kali1-amd64 #1 SMP Debian 4.18.6-1kali1 (2018-09-10) x86_64

The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Oct 19 15:20:41 2018 from 10.0.2.2
[email protected]:~$

If you check instance IP addresses, the one configured on Vagrantfile should be available.

Whenever you make a change to the Vagrantfile, restart the machine for the changes to take effect.

$ vagrant reload

To stop the instance, use

$ vagrant halt

If you would like to save the current state of the VM while stopping it, use

$ vagrant suspend

With this, you’ll return to exactly the same state at a later time when VM is started.

Destroy the Vagrant machine when done  by running

$ vagrant destroy

Wrapping Up

In this guide, we have shown you how to manage Kali Linux instance with Vagrant. Don’t forget to check out the official documentation for more Vagrant configuration options.

More on Virtualization:

How to Install VMware Workstation on Arch Linux / Manjaro

How To Install Proxmox VE 6 on Debian 10 (Buster)

How to extend/increase KVM Virtual Machine (VM) disk size

How to Monitor VMware ESXi with Grafana and Telegraf