d3xitfl0w@web: ~$ |

d3xitfl0w / ... / Virtual Penetration Testing Home Lab

Created Wed, 28 May 2025 15:10:34 +0000 Modified Thu, 17 Jul 2025 11:45:23 +0000

In this post you will get to know benefits of using virtual lab and learn how to setup your own virtual penetration testing home lab based on VirtualBox.

Home Lab for Penetration Testing - Introduction

Setting up your own home lab is an essential step for anyone serious about pursuing a career in cybersecurity, ethical hacking, or penetration testing. There are a number of reasons why configuring a safe environment is a such important thing. It is not just useful but crucial for learning, testing, and improving your skills in a safe and controlled environment.
Let’s have a look at some benefits having your virtual lab:

  • Controlled and Isolated Environment - that allows you palying around with different tools, techniques, scaning, vulnerabilities exploitation without risking legal issues or harming any real-world systems. If you make a mistake, you can learn from it, fix it or even revert the change easilty through a VM snapshot.

  • Hands-On Experience - which is crucial for getting deeper understanding of how systems can be attacked, how attackers think, and how to defend against those attacks. This is especially important for penetration testing which requires highly practical skillset.

  • Understanding Attack and Defense Techniques. Being a penetration tester is not only about knowing how to break into the systms it also about knowing how to defend the systems. After exploiting a system you can remediate or mitigate vulnerability and implement countermeasures like patching, firewalls (FW), configuration hardening, Intrustion Detection/Prevention Systems (IDS/IPS). This allows you to check what countermeasure fits best in a given scenario to prevent the system from being exploited. That is also a chance to learn about best security practices.

  • Real-World Attack Simulations. Thanks to virtual environment and its flexebility you can build and map a real-world corporate environment, configuring for example: internal and external network, operating systems (OS), vulnerable machines, different endpoints, etc. This allows you to explore and learn how adverseries perform attacks on applications and systems without putting real-world systems at risk.

  • Budget-Friendly - having your home lab does not have to be exmpensive. In fact it can be quite cheap. There are a lot of free resources available on the internet. For example: free hipervisors like VirtualBox, VMware Workstation; free operating systems e.g. Kali Linux, Parrot Security OS, Pentoo, Debian, Ubuntu; vulnerable machines: Metasploitable, DVWA, OWASP Juice Shop. The only thing you can pay for is your electricity :) and PC that does’t have to be the new top-line, instead it can be just repurposed laptop (not toooo old 😃 - however it can still be useful 😎) , with sufficient amount of RAM - depending on a size of your LAB.

This post will conver basic pentesting lab setup based on VirtualBox running on well known Linux distribution - Ubuntu. This gives us a powerfull and flexible lab on a human-frendly Linux distribution with a hugue community and great support. We will install and configure a couple of VMs including: Kali, Ubuntu, Windows, and Metasploitable. Additionally we will install pfSense wich will act as a dedicated virtual router/firewall for our lab network. Having VMs with internal virtual network behind pfSense, mimicks a real-world network topology. You can even configure segmented LANs, WANs, DMZs, etc. However, we will be using basic pfSense configuration setup here - sufficient for our needs. If you are not comfortable with pfSense for some reasons, you can always configure your lab environment without this extra step, but remember to use NAT for Network Adapter in VMs, where you want to have access to the internet, and attach Network Adapter as Internal Network, where the internet connection is not needed.

OK, let’s dive into technical details and make our lab live!

VirtualBox Setup

The guidline described here is dedicated for Ubuntu linux distribution. If you are running different OS you will have to make adjustments in order to meet your system specific requirements.

  1. Ensure your system is up-to-date.
sudo apt update && sudo apt upgrade -y
  1. Download Oracle singnature verification key.
wget https://www.virtualbox.org/download/oracle_vbox_2016.asc
  1. Add Oracle VirtualBox repository to your system.

In this example we will be using VirtualBox 7.1.8 on Ubuntu 24 (jammy). Adjust according to your Ubuntu dstribution codname if it differs e.g. “jammy”-> “noble”. To check a codename on your system you can use lsb_release -c command.

# Add repo without auto replacement of distribution codename. You have to replace <mydist> with your version.
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian <mydist> contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
# --OR--
# Add repo with auto replacement of distribution codename (<mydist>). 
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs | tail -1) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
  1. Import the Oracle VirtualBox public key for package signature verification:
# Recommended way:
sudo gpg --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg --dearmor oracle_vbox_2016.asc
# Depricated way:
# wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -

If you don’t add the key of Oracle’s repository, apt package manager will not allow package installation from the added repository.

If you previously added the Oracle key(s) to your default keyring (now considered insecure), remove them again with:

sudo apt-key remove 5CDFA2F683C52980AECF
sudo apt-key remove D9C954422A4B98AB5139
  1. Update your package lists and install virtualbox.
sudo apt update
sudo apt install virtualbox-7.1

Extention Pack

After installation, it is recommended to install the VirtualBox Extension Pack, which unlocks additional features like USB 2.0/3.0 support, RDP, PXE boot, and more.

  1. Download the Extension Pack from the VirtualBox downloads page. Replace “7.1.8” with your version.
wget https://download.virtualbox.org/virtualbox/7.1.8/Oracle_VM_VirtualBox_Extension_Pack-7.1.8.vbox-extpack
  1. Check SHA256 checksum.

Look for your Extention Pack version and its SHA256 checksum at: https://www.virtualbox.org/download/hashes/7.1.8/SHA256SUMS

Compare with the downloaded package:

sha256sum Oracle_VM_VirtualBox_Extension_Pack-7.1.8.vbox-extpack

Returned digest should match the one from the official virtualbox website.

  1. Install the Extention Pack using the VirtualBox graphical user interface - GUI (open Virtualbox -> go to File -> Preferences -> Extentions -> Add new package -> Browse for your .vbox-extpack -> Open -> Install) or using the following command:
sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-7.1.8.vbox-extpack
# -- OR --
# chmod u+x Oracle_VirtualBox_Extension_Pack-7.1.8.vbox-extpack
# ./Oracle_VirtualBox_Extension_Pack-7.1.8.vbox-extpack
  1. Restart your VirtualBox if needed.

  2. Add Your User to the “vboxusers” Group

Sometimes, you may need to add your user to the “vboxusers” group to allow the creation and management of virtual machines.

sudo usermod -aG vboxusers $(whoami)

Log out and log back in for the group changes to take effect.

Good job! 😃 You should now have your ready to use VirtualBox installed on the Ubuntu system. Now you can start creating virtual machines, testing various configurations, or running different operating systems within VirtualBox 🤓

VirtualBox VM Setup

pfSense VM Setup

pfsense is an open source router/firewall, that we will use in our lab to protect our virtual machines from outside attacks. It is like a guard that stands between the internet and your internal network. It will inspect traffic entering and leaving your network to ensure that your internal network is secure from outside attackers. This creates a safe place for you to add vulnerable machines that only you can attack.

Download pfSense image

  1. Download the pfSense source files from its official website. Choose the AMD64 (64-bit) architecture, the DVD image (ISO) installer, and the server location closest to you before clicking the download button.

When you try AMD 64 installer version and you face problems to run it on VM, then download USB stick image that will do the work. General CE version should also work.

Note 💡 pfsense website changed the way images are downloaded and types of images available. However The old repo with images still works and you don’t have to create an account on Netgate to download the image. As of now (time of this post) the link below is still available.

Go to the following link and download the latest CE version:

https://atxfiles.netgate.com/mirror/downloads/

Unzip the file if necessary.

Install pfSense on VM Machine

Once you downloaded a pfSense image open up the VirtualBox and select Machine from the top menu, and click on New icon. Adjust the following options:

  • Enter “pfSense” as the name, “BSD” as the type, and “FreeBSD (64-bit)” as substype
  • In ISO Image select an pfSense iso image you already downloaded.
  • change location in Folder field if you prefer different place to store your VM files.
  • Go to Hardware tab and set the memory size to 1024MB (pfSense virtual machine doesn’t require much RAM).
  • for Hard Disk options, select Create a Virtual Hard Disk Now. Select VDI (VirtualBox Disk Image) for the Hard Disk File Type and Variant.
  • Make sure the path for a new VDI will be created in is correct
  • Set 5GB for the VDI size - which is quite enough for the pfSense in our lab (Additionally In the older versions of VirtualBox, make sure a new virtual hard disk is dynamically allocated)
  • Click Finish

Note 💡 When installing the new version of pfSense, users will need to select the Auto (UFS) BIOS option.

Next, launch pfSense and configure our virtual router settings. Make sure you set this settings correctly, otherwise you might find your virtual machines to have no internet access.

  • Double-click pfSense in your list of virtual machines in order to boot pfSense.
  • Once it has booted you should agree to the Copyright and Trademark Notices by pressing ENTER. Make sure Install option is selected and Press ENTER to install pfSense. Stick with the default options.

After the install has completed, type reboot into terminal when prompted and press ENTER to confirm. When pfSense reboots, you’ll be directed to the “Copyright and distribution notice” once again. This occurs because the pfSense virtual machine is again booting from the ISO image we used earlier. To fix this, first click the File tab in the upper left of the pfSense machine, and then click Close. Select Power off the machine and click OK.

Once the pfSense virtual machine is powered off, right-click it in your list of virtual machines and select Settings. Navigate to the Storage tab and right-click the ISO image you previously chose. Then select Remove Attachment and confirm that you want to delete the optical drive. Select Remove and click OK.

pfSense Network Setup

Note 💡 Ensure that your virtual machine is turned off before adjusting the network settings.

  • When the VM is powered off, right-click pfSense in your list of virtual machines and then click Settings
  • Navigate to the Network tab.
  • Under Adapter 1 select Enable Network Adapter checkbox.
  • Select Bridged Adapter in the Attached to drop-down menu, with the same name in the Name field as your existing wireless or ethernet card. Enabling a Bridged Adapter creates a direct connection between the pfSense virtual machine and the internet.
  • Under Adapter 2 tab select Enable Network Adapter checkbox.
  • Select Internal Network in the Attached to drop-down menu and name it Internal LAN. This internal network will connect pfSense to our other virtual machines.
  • Once you click OK, the internal network should be available to other virtual machines.

Now you can start your pfSense VM with the new network settings.

  • Right-click pfSense VM, and click Start to start the VM.

pfSense and ipv6 Conections Issue on VMs

💡 Internal network with pfSense does not have access to internet via ipv6 which is servsed by default when pfsense is enabled. Fix might be to disable v6 or tunel them into v4 or change priority to choose ip v4 first and v6 next.

⚠️ Symptom: ping google.com … Time out

✅ Fix: Change priority to choose ip v4 first and v6 next.

Login to pfSense web interface via web browser from another machine e.g. Ubuntu (Desktop) VM with default pfSense creds.

Web interface address: http://<IP_OF_PFSENSE_VM>

Default login credentials to the pfSense web interface:

  • username: admin
  • password: pfsense

Go to System -> Advanced -> Networking and select Prefer to use IPv4 even if IPv6 is available checkbox and unselect All IPv6 checkbox.

Kali Linux VM Download

Download the Kali Linux VirtualBox image (.OVA file) from the official Kali website

Note Ensure that the files listed are Kali Linux VirtualBox images and not VMWare images Select the VirtualBox image version that is suitable for your system (64-bit or 32-bit)

Kali Linux VM Setup

  • Add the Kali machine to VirtualBox: right-click the downloaded OVA file and open it using VirtualBox. You should be prompted with a screen containing the preconfigured settings for the machine.
  • On the left side of the page, you should see a folder icon. Click it and select your downloaded OVA file.

Default login credentials to your Kali VM:

  • username: kali
  • password: kali

Kali VM Network Setup

Note 💡 Ensure that your virtual machine is turned off before adjusting the network settings.

  • When the VM is powered off, right-click the Kali virtual machine in your list of virtual machines and then click Settings.
  • Click the Network tab and then click Adapter 1.
  • Select the Enable Network Adapter checkbox and set Attached to from the drop-down menu to Internal Network.
  • Leave the name as “Internal LAN” and click OK.

Now you can start your Kali VM with the new network settings.

  • Right-click Kali VM, and click Start to start the VM.

Note 💡 If your Kali Linux displays nothing but a black screen, make sure the PAE/NX checkbox is selected in Settings -> General -> System -> Processor.

Ubuntu VM Setup

We will set up the Ubuntu Linux Desktop virtual machine to demonstrate how a hacker can attack a victim’s desktop or laptop. The following steps outline how to download and configure Ubuntu. Here, we’ll configure only the Ubuntu machine that is attached to our internal LAN. You can also configure a second Ubuntu machine that is associated with the private network where you can directly connect to the first instance of the Ubuntu without the internet.

Ubuntu VM Download

Download the latest Ubuntu Desktop ISO image from the Ubuntu website

Ubuntu VM Installation

Open up the VirtualBox and click the New button in the top menu. Provide infromation about your new machine. For example:

  • Enter Ubuntu as the name, Linux for the type, and Ubuntu (64-bit) for the version.
  • Attach the Ubuntu ISO image you already downloaded.
  • Click Continue.
  • Allocate 2048MB of RAM and a 10/15GB hard disk.
  • In the Summarize section, review all the option and click Finish.
  • Start the Ubuntu machine, select your desired language.
  • Click Install Ubuntu, and follow on-sceen options. 

Ubuntu VM Network Setup

Note 💡 Ensure that your virtual machine is turned off before adjusting the network settings.

  • When the VM is powered off, right-click the Ubuntu virtual machine in your list of virtual machines and then click Settings.
  • Navigate to the Network tab.
  • Under Adapter 1 select the Enable Network Adapter checkbox.
  • Select the internal network we created earlier Internal LAN in the Attached to drop-down menu.
  • Click OK.

Now you can start your Ubuntu VM with the new network settings.

  • Right-click Ubuntu VM, and click Start to start the VM.

Vulnerable VM

Vulnarable machines (Web Application Pentesting)

While there are many intentionally made vulnerable machines on the internet one of the great resources with awasome preconfigured VMs can be found at vulnhub.com. There are a lot already prepared VMs with exciting scenarios waiting for you to try them out. If you want to test a machine for web application vulnerabilites and get root access, I recommend check the DC series - especially the DC-9 vulnerable machine which is highly suitable for web app penetration testing. This VM has many weeknesses and vulnerabilities you can exploit in order to completely takeover the machine and get root access.

If you want to try it out, download the machine (DC-9.zip) from download page.
Next, unzip the package, and import the DC-9.ova file into your VirtualBox (or VMware Workstation Player). The root password of the system is unknown and the goal here is to gain root privileges without needing to know the root password. It is worth to give it a try and learn how to get access to the machine without credentials.

Metasploitable

Metasploitable is an intentionally vulnerable virtual machine designed to showcase and explore the capabilities of the Metasploit framework in a controlled environment. Commonly used by cybersecurity students, penetration testers, and ethical hackers, it serves as a practical tool for developing and refining hacking skills, experimenting with various security techniques, and gaining hands-on experience with real-world exploitation scenarios. By simulating a target system full of security flaws, Metasploitable 2 provides a great platform for understanding how vulnerabilities are discovered, exploited, and mitigated using Metasploit.

While there is a Metasploitable version 3 available, here I recommend to start with Metasploitable 2 as it is much easier and quicker to setup comparing to version 3, and still giving you a wide filed of exploration.

Download Metasploitable 2

Download the Metasploitable 2 virtual machine image from the Rapid7 website

Unzip the downloaded .zip file.

Metasploitable VM setup

  • Open up the VirtualBox
  • Click the New button.
  • Set your machine’s name to Metasploitable
  • Set type to Linux, and version to Ubuntu (64-bit)
  • Click Continue.
  • On the Memory Size page, use the suggested amount of memory. When prompted to choose a hard disk
  • Select Use an existing virtual hard disk file
  • Click the folder icon, and browse to your unzipped Metasploitable download.
  • Select the your .vmdk downloaded file and click Create.

Default login credentials to your Metasploitable VM:

  • username: msfadmin
  • password: msfadmin

Metasploitable VM Network Setup

Note 💡 Ensure that your virtual machine is turned off before adjusting the network settings.

  • When the VM is powered off, right-click the Metasploitable machine in your list of virtual machines and then click Settings.
  • Navigate to the Network tab.
  • Under Adapter 1 select the Enable Network Adapter checkbox.
  • Select the internal network we created earlier Internal LAN in the Attached to drop-down menu.
  • Click `OK'

Now you can start your Metasploitable VM with the new network settings.

  • Right-click Metasploitable VM, and click Start to start the VM.

SSH to Metasploitable Issue

💡 Notice ssh msfadmin@<ip_address> only works when you use very older SSH client. With the newer SSH versions you will get an error.

⚠️ Symptom: ssh msfadmin@<ip_address> Unable to negotiate with 192.x.x.x port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss

✅ Fix: ssh msfadmin@ip_address -oHostKeyAlgorithms=+ssh-rsa

Windows VM Setup

Download the Windows 10 ISO

Go to the Windows 10 download page and select “Windows 10 (multi-edition ISO)” from drop-down menu. If you are a Windows user, Microsoft will prompt you to download the Media Creation Tool before allowing you to download an OS image. You can use this tool to create an ISO file locally, or you can follow these additional instructions to download the ISO manually without being forced to grab the tool first.

Install Windows 10 on VM machine.

Once you downloaded a Windows image open up the VirtualBox and select “Machine” from the top menu, and click on “New” icon. Adjust the following options:

  • Provide the name for you VM e.g. WIndows 10.
  • Change the default path in Folder field if you want to change a location your VM will be stored in.
  • For ISO Image field select the Windows ISO you just downloaded downloaded.
  • Confirm the type (Microsoft Windows) and version fields are correct, and click on Next.
  • Set the credentials on the next screen. You can add a product key to make it official if you want.
  • Select Next.
  • In the “Hardware” section allocate RAM and CPU cores. Provide at least 4GB of RAM and at least two CPU cores.
  • In “Virtual Hard Disk” section allocate a disk space of around 100GB. The minimum here is 64GB for installation but you most likely will need more for future upgrades, some downloaded files or tools you would need to install.
  • Select Next
  • In the Summary window review all the options and if everything is fine, then click Finish.
  • Follow the on-screen instructions to input basic settings. Microsoft would aks you to provide your Microsoft account or create one if you don’t have it, however there is still option to avoid it, and the simplest solution is to just disconnect device from the internet, which should allows you to create a local account during Windows installation. Since this is a VM you can do it by disabling network adapter (on the VM window -> Devices -> Network).

Download the Windows 11 ISO

Go to Windows 11 download page and look for ISO image.

Install Windows 11 on VM machine.

Once you downloaded a Windows image open up the VirtualBox and select Machine from the top menu, and click on New icon. Windows 11 installation process will be the same as for Win 10 described in the previous section. For more information go back to Windows 10 setup section.

📣 Pro Tips 😎

1. Always use VirtualBox to manage snapshots and backups.

Avoid using direct copy paste of VMs files on a disk drive. It’s just better to use VirtualBox’s built-in features for creating and managing backups. This way you will avoid issues with inconsistency and potential data loss.

To ensure consistency and integrity of your VMs, follow the following 4 stesps:

  1. Shut Down the VM: Ensure the VM is powered off before making any changes or backups.
  2. Use VirtualBox’s Export Functionality: Utilize VirtualBox’s export capabilities to create a consistent snapshot of your VM. This can be done via the File menu, where you can choose to export the VM as an OVA (Open Virtualization Format Archive) or OVF (Open Virtualization Format) file.
  3. Copy the Entire VM Folder: After exporting, you can safely copy the entire VM folder, which includes all configuration files and disk images, to a secure location. This ensures that all components of the VM are backed up together, maintaining consistency.
  4. Avoid Directly Copying Disk Images: Simply copying disk images (like VDI files) without the corresponding configuration files can result in incomplete backups and potential issues when restoring.
  5. Use virtualbox to remove snapshots: Instad directly delting snapshots from the drive always use virtualbox’s built-in delete future. This will ensure that virtual box will delete snashot properly and merge to the changes.

2. Update User Accounts

It is always a good practice to update default credentials when you start your fresh operating system (OS). Using the following commands you can make some adjustments to the system defaults.

sudo passwd kali (provide a new more complex password)
sudo useradd -m your_username (create new user account)
sudo usermod -aG sudo your_username (add your account to sudo group)
sudo chsh -s /bin/zsh your_username (optionally if you want to change the default shell to zsh)
sudo passwd your_username (provide a new more complex password)

3. Make a VM snapshot before guest OS upgrade.

It is recommended to always take a snapshot of VM before guest OS upgrade as sometimes your VM might spot difficulties to boot or work properly after an upgrade. If you took a snashot you would quickly go back to the previous working VM state and safe time for trouble-shooting system and fix any issues that occurred.