Pentest Lab Setup: Kali Linux, Metasploitable 2, and DVWA on VirtualBox

Deepak Prasad
Tested on Windows 11; Ubuntu 24.04 (VirtualBox 7.x host screenshots)
Package Oracle VirtualBox 7.x
Metasploitable 2
DVWA 1.0.7 VulnHub ISO
Applies to Windows
Linux
macOS
Privilege Host administrator rights to install VirtualBox; sudo on Kali for package installs
Scope Lab component overview, install order, host-only topology, adapter layout, and snapshots. Links to dedicated Kali and DVWA install guides. Does not cover exploitation walkthroughs on the targets.

A penetration testing lab gives you legal, isolated targets for ethical hacking practice. This guide builds a three-VM layout on Oracle VirtualBox: Kali Linux as the attacker, Metasploitable 2 for network targets, and DVWA for web application testing.

IMPORTANT
Use this lab only on networks and systems you control. Exploiting hosts without authorization is illegal in most jurisdictions.

Lab VMs and packages

This lab is a small, repeatable stack — not every tool you will ever use in a career, but enough surface area to practice recon, network exploitation, web attacks, and Metasploit workflows without touching a production network. Below is what we install, what role each piece plays, and where it fits in the ethical hacking course.

Component What it is Why we use it in this lab
Oracle VirtualBox Free desktop hypervisor on your Windows, Linux, or macOS host Runs multiple VMs on one physical machine, supports snapshots for reset between exercises, and ships host-only networking for isolation without extra hardware
VirtualBox Extension Pack Optional add-on matched to your VirtualBox version Enables USB 2/3 passthrough and fuller host-only adapter support on some hosts
Host-only virtual network Private VirtualBox subnet shared only by your lab VMs Keeps exploit traffic, malware samples, and ARP/DNS lab tricks off your home LAN and the Internet
Kali NAT adapter (second NIC) Outbound Internet path for the attacker VM only Lets Kali run apt update, pull Metasploit modules, and download wordlists while Metasploitable and DVWA stay on host-only with no direct route to the Internet

Install order for this guide

Follow these steps in order. Each step links to a dedicated guide where the full Kali or DVWA install is already documented with screenshots.

Step Task Section
1 Install VirtualBox on your host Step 1
2 Install the VirtualBox Extension Pack Step 2
3 Create the host-only lab network Step 3
4 Install Kali and attach lab adapters Step 4
5 Install DVWA (web target) Step 5
6 Install Metasploitable 2 (network target) Step 6
7 Verify connectivity and take snapshots Step 7

Do not skip ahead — Metasploitable and DVWA need the host-only network from Step 3, and verification in Step 7 assumes Kali is already on that subnet.

What we did not include (and why)

Not in the base lab Reason
Cloud lab (AWS/Azure) Valid for scale, but adds cost and networking complexity; local VirtualBox is free and matches our screenshot-based walkthroughs
Physical spare PCs Best for Wi-Fi and hardware attacks; this guide focuses on a laptop-friendly virtual lab first

After the base lab is running, extend it from the optional targets section at the end of this page.


Lab topology

Role VM Adapters
Attacker Kali Linux Host-only + NAT
Network target Metasploitable 2 Host-only
Web target DVWA (guest VM or on Kali) Host-only

VirtualBox often assigns 192.168.56.0/24 on the default host-only adapter. Refreshed walkthroughs on this site use TARGET = 192.168.56.114 and KALI_IP = 192.168.56.115 on that subnet when your lab matches the default range. Substitute your own addresses from ip addr on each VM.

Metasploitable 2 console: msfadmin / msfadmin
Take a snapshot of each target VM after install and before your first exploit.

Here is the topology for this lab — Kali on host-only with targets DVWA and Metasploitable on the same segment:

Pentest lab topology with Kali Linux, DVWA, and Metasploitable 2 on a VirtualBox host-only network

Virtualization keeps vulnerable services off your physical network. Malware analysis, ARP spoofing, and Metasploit payloads can disrupt real systems if they leak onto a production LAN. The host-only network in Step 3 limits impact to VMs on that adapter.


Step-by-step lab build

Work through Steps 1–7 in order. Screenshots below were captured on VirtualBox 7.x with a Windows host; menu names may differ slightly on Linux or macOS hosts.

Step 1: Install VirtualBox on the host

  1. Open the Oracle VirtualBox downloads page.
  2. Download the installer for your host OS (Windows, macOS, or Linux).

VirtualBox download page on Windows host

  1. Run the installer and accept the defaults on Windows, or follow install Oracle VirtualBox on Linux on RHEL-family hosts.
  2. Confirm VirtualBox opens without errors before you continue to Step 2.

Step 2: Install the VirtualBox Extension Pack

  1. On the same VirtualBox downloads page, download the Extension Pack that matches your VirtualBox version.
  2. Double-click the Extension Pack file or install it from ToolsExtension Pack Manager in VirtualBox.
  3. Accept the license prompt.

VirtualBox Extension Pack download

Step 3: Create the host-only network

This private subnet keeps lab VMs isolated from your home LAN.

  1. In VirtualBox, open FileToolsNetwork.

VirtualBox Tools Network manager

  1. Select Host-only Networks on the right panel.
  2. Open the default VirtualBox Host-Only Ethernet Adapter and set the Adapter tab values to match your lab plan (default 192.168.56.1 / 255.255.255.0 works with most refreshed course walkthroughs).

Host-only adapter IPv4 settings

  1. Switch to the DHCP Server tab and enable DHCP or note the assigned range.

Host-only DHCP server settings

  1. Click Apply and confirm the adapter appears under Host-only Networks.

Step 4: Install Kali Linux and attach lab network adapters

Part A — Install Kali

  1. Follow Install Kali Linux on VirtualBox from start to finish (bare-metal ISO or pre-built VirtualBox image).
  2. Confirm the Kali VM boots to a login prompt before you change network settings.

Part B — Wire Kali into this lab topology

  1. Select the Kali VM → SettingsNetwork.
  2. Set Adapter 1: Enabled, Host-only Adapter (the network from Step 3).
  3. Set Adapter 2: Enabled, NAT (Internet for apt and msfupdate).

Kali VM host-only adapter on Adapter 1

  1. Optional: on Adapter 2, add NAT port forwarding if you want SSH from the host without bridging lab traffic.

Kali VM NAT adapter on Adapter 2

  1. Start Kali and log in with the credentials from the Kali download page (often kali / kali).

Kali Linux login console in VirtualBox

Kali Linux desktop after login

  1. On Kali, run ip -4 addr show and confirm the host-only interface received an address on your lab subnet.

Step 5: Install DVWA (web target)

Pick one path below.

Option A — DVWA as a separate guest VM (VulnHub ISO)

  1. Download DVWA 1.0.7 from VulnHub.
  2. In VirtualBox, click MachineNew and name the VM.

Create new VirtualBox VM for DVWA

  1. Allocate 2 GB RAM and 1 vCPU.

DVWA VM memory and processor settings

  1. Create a 10 GB dynamically allocated virtual disk.

DVWA virtual disk size

  1. Open SettingsNetworkAdapter 1: Host-only Adapter (same network as Kali).

DVWA VM host-only network adapter

  1. Mount the DVWA ISO, start the VM, and boot the installer.

Start DVWA VM installation from ISO

  1. At the boot menu, choose start the installer directly.

DVWA installer boot menu

  1. Complete installation until the console shows DVWA running.

DVWA installed and running

  1. From Kali, browse to http://DVWA_IP/ after you read the address with ip addr on the DVWA guest.

Option B — DVWA on Kali (single-machine web lab)

  1. Follow Install DVWA on Kali Linux.
  2. Keep DVWA on localhost or the host-only interface only — do not expose it on a bridged adapter.
  3. Continue with DVWA SQL injection after the setup wizard completes.

Step 6: Install Metasploitable 2

  1. Download metasploitable-linux-2.0.0.zip from SourceForge.
  2. Extract the archive to a folder on your host.

Extracted Metasploitable 2 VMDK files

  1. In VirtualBox, click MachineNewExpert Mode.

Create new VirtualBox VM in Expert Mode

  1. Assign 2 GB RAM (512 MB minimum).

Metasploitable VM RAM allocation

  1. Attach the extracted VMDK as the virtual hard disk. The VM name must match the extracted folder name.

Attach existing Metasploitable VMDK to the VM

If you are building an empty VM instead of attaching the VMDK directly, add an 8 GB dynamic VDI under SettingsStorage:

Add virtual disk in Metasploitable VM storage settings

  1. Open SettingsNetworkAdapter 1: Host-only Adapter (same network as Kali). Do not use bridged networking for this lab.

Metasploitable VM host-only network adapter

  1. Start the VM.

Power on Metasploitable 2 in VirtualBox

  1. Log in with msfadmin / msfadmin.

Metasploitable 2 login prompt

Metasploitable 2 console after login

  1. From Kali, open http://TARGET/ in a browser to reach the Metasploitable web menu (after you identify TARGET with ip addr on the Metasploitable console or a subnet scan).

Metasploitable web application menu in browser

Continue exploitation in Learn hacking with Metasploitable 2.

Step 7: Verify the lab and snapshot each VM

  1. On Kali, ping Metasploitable (substitute your target address):
bash
ping -c 2 TARGET
  1. Optional: sweep the host-only subnet to list all lab guests:
bash
nmap -sn 192.168.56.0/24
  1. Run spot checks from Kali:
Check Command Expected
Metasploitable SSH nmap -p 22 --open TARGET Port 22 open
Metasploitable web curl -I http://TARGET/ HTTP response
DVWA curl -I http://DVWA_IP/ HTTP 200 or redirect to setup
  1. In VirtualBox, snapshot Kali, Metasploitable, and DVWA (or note the snapshot name if you use Kali-only DVWA). Restore these snapshots between exercises so each service starts from a known state.

Optional targets

Add more vulnerable apps on the same host-only network as you advance:


Troubleshooting

Problem Likely cause Fix
Kali cannot ping Metasploitable Different networks Match host-only adapter on all lab VMs
No Internet on Kali NAT adapter missing Enable Adapter 2 NAT on Kali only
Wrong IP range Custom host-only subnet Run ip -4 addr on each VM; update TARGET / KALI_IP in walkthroughs
Metasploitable VM fails to boot VM name ≠ folder name Rename VM or re-link VMDK in SettingsStorage

Summary

You now have a standard ethical hacking lab: Kali on host-only + NAT, Metasploitable 2 and DVWA on host-only only, and snapshots for reset between exercises. Next steps:

  1. Metasploit tutorialmsfconsole basics
  2. Learn hacking with Metasploitable 2 — exploits against the network target
  3. DNS enumeration or banner grabbing — recon on Metasploitable services

Keep every scan and exploit inside this isolated network.

Kennedy Muthii

Information Security Analyst

Accomplished professional proficient in Python, ethical hacking, Linux, cybersecurity, and OSINT. With a track record including winning a national cybersecurity contest, launching a startup in Kenya, and holding a degree in information science, he is currently engaged in cutting-edge research in ethical hacking.

  • Python (programming language)
  • Certified Ethical Hacker
  • White Hat (Computer Security)
  • Linux
  • Penetration Testing