TL;DR
This guide shows you how to build a simple virtual environment for running security training simulations. We’ll use VirtualBox and Vagrant to create isolated machines, making it safe to practice attacks and defences without risking your main system.
1. Install VirtualBox
VirtualBox is free software that lets you run operating systems inside your existing one (like Windows, macOS or Linux). Download and install it from the official website.
2. Install Vagrant
Vagrant automates the creation and configuration of virtual machines. Download and install it from the official website. Make sure you get the version for your operating system.
3. Choose a Base Box
A ‘box’ is a pre-built virtual machine image. We recommend using Ubuntu Server as it’s widely used and has lots of security tools available. Find one on Vagrant Cloud.
4. Create a Vagrantfile
The Vagrantfile tells Vagrant what to do. Create an empty file named Vagrantfile in the directory where you want your lab to be. Open it with a text editor.
5. Configure the Vagrantfile
Add the following lines to your Vagrantfile, replacing ‘ubuntu/focal64’ with the box name you chose:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provider "virtualbox" do |
vbox|
vbox.memory = "2048MB"
vbox.cpus = 2
end
end
This sets up a VM with Ubuntu, forwards port 80 on the VM to port 8080 on your host machine, and allocates 2GB of RAM and 2 CPUs.
6. Start the Virtual Machine
Open a terminal or command prompt in the directory containing your Vagrantfile and run:
vagrant up
This will download the box (if you haven’t already) and start the virtual machine. It may take some time.
7. Access the Virtual Machine
Once started, connect to the VM using SSH:
vagrant ssh
This will log you in as the ‘vagrant’ user with a default password of ‘vagrant’.
8. Install Security Tools
Inside the VM, update the package list and install some common security tools:
sudo apt update
sudo apt install -y nmap wireshark tcpdump netcat
9. Create Additional VMs (Optional)
To simulate a network, create multiple Vagrantfiles in separate directories. Each VM can have different roles (e.g., attacker, victim, server). Modify the network settings in each Vagrantfile to allow communication between them.
10. Network Configuration
For VMs to talk to each other, you need to configure their networks. Use ‘private_network’ or ‘forwarded_port’ options in the Vagrantfile. For example:
config.vm.network "private_network", ip: "192.168.33.10"
This assigns a static IP address to the VM.
11. Running Simulations
Now you have isolated VMs ready for security training! You can run penetration testing tools, practice incident response scenarios, or set up honeypots without affecting your main system. Remember to take snapshots before making significant changes so you can easily revert if something goes wrong.
12. Snapshots
Take a snapshot of the VM before major configuration changes:
vagrant snapshot save "before-tools"
To restore to a previous state:
vagrant snapshot revert "before-tools"