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.
- 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:
Step 2: Download Kali Vagrant box
After installing VirtualBox and Vagrant, download Kali Linux Vagrant box image. You have two options for this.
- Download Kali Linux full image – comes with all Kali packages
- 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
$ 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.network "private_network", ip: "192.168.90.99" 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
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.
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
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.