00->1
Learning pathStep 58 of 62Detection, response and testing ← All writeups

Build a Safe Practice Lab, Explained

If you are reading this, you have probably been told to "practise in a lab" and you want to know what that actually means, what to install, and how to stop your lab from becoming a hole in your own network.

By the end you will know what a practice lab is for, how to pick a way to run virtual machines on your computer, how to choose a network mode that keeps a vulnerable machine away from your real network, how to protect yourself with snapshots and verified downloads, where to find targets that are legal to attack, and the rules that keep a hobby on the right side of the law.

You do not need special hardware or money. You do need to read the documentation of whichever tool you pick, because menus and defaults change. This post tells you what to look for and why.


1. What a lab is for

Reading explains an idea. Practice builds the skill. A lab gives you somewhere to:

A lab has two kinds of machine:

Machine Role Example
Tools machine The computer you work from. It has your terminal, scanners and notes A Linux virtual machine such as Kali, or any Linux distribution you like
Target A deliberately weak system you are allowed to attack A vulnerable web application or a practice virtual machine

Everything in this post is about keeping the target away from anything real.


2. Choose how to run machines: virtual machines

A virtual machine (VM) is a complete computer simulated by software, running inside your real one. The software that runs VMs is a hypervisor or virtualization tool. The point for a lab: if a VM is damaged or infected, you delete or restore it and your real computer is untouched. (This protection is strong, not absolute, which is why the safety habits below matter.)

Step 1: know your processor

A VM image is built for a processor family, and an image built for one family will not simply run on another. Check what you have:

uname -m

On macOS and Linux, x86_64 means an Intel or AMD processor, and arm64 (macOS) or aarch64 (Linux) means an Arm processor, such as Apple silicon. On an Arm computer you should pick images that offer an Arm version, or use a tool that can emulate x86, which the VirtualBox manual describes as modest in performance (below).

Two facts from the tools' own documentation show why this matters:

  • The VirtualBox manual says its package for macOS on Arm64 (Apple silicon) lets you "run some guest operating systems for Intel x86/x64 CPUs in an emulation", and calls that package a Developer Preview that "represents a work in progress project and the performance is very modest" (VirtualBox manual, chapter 1). Read the current manual before you rely on it.
  • Kali Linux's download page labels its installer images for "Apple Silicon (ARM64)" as well as x86-64, and also lists pre-built VMs for VMware, VirtualBox, Hyper-V and QEMU (Kali downloads).

Step 2: pick a tool

Tool What its own site says Note
VirtualBox Separate macOS downloads exist for Intel hosts and for Apple silicon (Arm) hosts (downloads page) Free. See the Arm caveat above
UTM "A full featured system emulator and virtual machine host for iOS and macOS", based on QEMU (UTM docs) Runs on macOS (and iOS)
VMware (Workstation, Fusion) Listed in Kali's documentation, including a page for Apple silicon Macs Check current licence terms on VMware's site
Hyper-V, QEMU Both appear in Kali's list of pre-built VM formats Check your operating system's documentation to see what it offers

The right choice depends on your computer, so there is no single answer here. Whichever you choose, the safety ideas in the rest of this post are the same.

Step 3: check your resources

A VM uses your computer's memory and disk while it runs. Kali's documentation gives these figures for installing Kali: a minimal install with no desktop needs "as little as 128 MB of RAM (512 MB recommended)" and 2 GB of disk, while the default desktop setup recommends "at least 2 GB of RAM" and 20 GB of disk (Kali installation requirements). Remember your own computer needs memory too, so close other programs and run only the VMs you need.


3. Isolate the network: the most important rule

A deliberately vulnerable target must never be reachable from your real network, and certainly not from the internet. Most hypervisors let you choose how a VM's virtual network card connects. Here are VirtualBox's modes from its manual (Table 6.1). Other tools offer similar modes, sometimes under different names, so check the manual of the one you use:

Mode VM to host Host to VM VM to VM VM to internet/LAN Internet/LAN to VM
NAT Yes Only via port forwarding No Yes Only via port forwarding
NAT service (NAT Network) Yes Only via port forwarding Yes Yes Only via port forwarding
Bridged Yes Yes Yes Yes Yes
Host-only Yes Yes Yes No No
Internal No No Yes No No

(VirtualBox manual, chapter 6.)

How to use this:

  • Bridged puts the VM on your real network as if it were another device. A vulnerable target on a bridged adapter can be reached by every device that can reach your network. Do not do this with practice targets.
  • Internal is the strictest. The manual describes it as similar to bridged networking "in that the VM can directly communicate with the outside world. However, the outside world is limited to other VMs on the same host which connect to the same internal network." Your VMs can talk to each other, and nothing else can reach them.
  • Host-only lets the VMs and your computer talk to each other, but gives no access to the external network.
  • NAT lets a VM reach the internet (for updates) but hides it from outside connections unless you set up port forwarding.

A simple lab layout

          internet
             |
           [NAT]
             |
      +--------------+    "lab-net" (internal network)    +------------------+
      | Tools VM     |------------------------------------| Target VM or app |
      | (Kali/Linux) |                                    | (vulnerable)     |
      +--------------+                                    +------------------+
  • The tools VM has two virtual network adapters: one on NAT so it can update itself, and one on an internal network called, say, lab-net.
  • The target has only the internal adapter. It has no route to the internet and no one outside can reach it.
  • Most hypervisors let you give a VM more than one adapter and set each adapter's mode separately. Check how yours does it.

Two extra precautions, which are good practice rather than something a single manual states:

  1. Features that connect a guest to the host, such as shared folders, shared clipboard and drag-and-drop, are also paths between them. Turn them off for guests you are attacking or analysing.
  2. Do not copy real passwords, personal files or work files into a practice VM.

4. Snapshots: undo for your lab

A snapshot saves a VM's state so you can come back to it. The VirtualBox manual says: "With snapshots, you can save a particular state of a virtual machine for later use", and you can return to that state even after changing the VM considerably. It also warns that when you restore a snapshot, "the current state of the machine is lost" and so are the files created since the snapshot (VirtualBox manual, chapter 1). It suggests taking a new snapshot first if you want to keep the current state.

A good routine:

  1. Install and update the VM, then take a snapshot called "clean".
  2. Take another snapshot before a risky experiment.
  3. When you finish, restore the clean snapshot so the VM starts fresh next time.

Snapshots are not a backup of important files. Keep your notes and scripts outside the VM (or in a repository, see Git and GitHub).


5. Verify what you download

Security tools and practice images are an attractive thing for attackers to fake. Always download from the project's official site, and check the file before you run it.

Kali describes a three-step check (Kali: verifying downloaded images):

  1. Download the checksum file (SHA256SUMS) and its signature (SHA256SUMS.gpg) from the same place as the image.
  2. Import Kali's signing key and check that its fingerprint matches the one printed on that page.
  3. Verify the signature with gpg --verify SHA256SUMS.gpg SHA256SUMS. Kali says: if you do not see a "Good signature" message or the key ID does not match, "you should stop the process and review whether you downloaded the images from a legitimate Kali mirror."

Then compare the image's own hash with the value in the checksum file:

shasum -a 256 kali-linux-IMAGE-NAME.iso     # macOS (sha256sum on Linux)

If the two values do not match exactly, delete the file. Cryptography Basics explains why a signature on the checksum file matters: a hash only proves integrity if the reference hash is trustworthy.


Only attack things built for it, or things you own. Good starting points:

Target What it is Notes
OWASP Juice Shop Described by OWASP as "probably the most modern and sophisticated insecure web application for security trainings, awareness demos and CTFs" (OWASP) Runs on your own machine. See the Docker commands, which publish the port on 127.0.0.1 only, in Web-Based Attacks and the OWASP Top 10
OWASP WebGoat An insecure application with guided lessons Same post. Its README warns that your machine will be "extremely vulnerable to attack" while it runs
DVWA (Damn Vulnerable Web Application) A deliberately vulnerable web application. Its README warns not to put it in a hosting provider's public web folder or on any internet-facing server (DVWA) A good reminder: never host these publicly
OWASP WrongSecrets A "vulnerable app with examples showing how to not use secrets" (GitHub) Pairs well with Git and GitHub
VulnHub A catalogue of "breakable, hackable & exploitable" virtual machines for learning in "a safe environment" (VulnHub) Downloaded VMs come from the community. Verify the download, run them on an internal network, and check the processor type
Online platforms PortSwigger Web Security Academy, Hack The Box Academy, TryHackMe and others The lab runs on their servers, so nothing vulnerable sits on your network. Read each site's rules. See the practice table on the What next page

7. The rules

  1. Own it or have permission. Attack only your own lab, practice platforms inside their rules, or systems with written authorization. Testing someone else's systems without permission can be a crime even if you "only look around". Security Testing explains scope and authorization.
  2. Keep targets isolated. No bridged adapters, no port-forwarding a vulnerable service to your network, no internet exposure.
  3. Never aim lab tools at the real world "just to see". A scanner pointed at an address you do not own can break an acceptable use policy and can get you into trouble. The Nmap documentation says that when used improperly the tool "can (in rare cases) get you sued, fired, expelled, jailed, or banned by your ISP" (Nmap: Legal Issues).
  4. Do not reuse real credentials in the lab, and do not store real data in it.
  5. Snapshot first, restore after.
  6. Update the tools machine while it is clean, and keep the host operating system updated too.
  7. Keep notes. Write down what you tried, what happened and what you learned. It is the habit that Writing a Report That Gets Fixed builds on.

8. Common mistakes

Mistake The facts
"I'll bridge the target so it is easier to reach" Bridged mode puts it on your real network, reachable by other devices. Use an internal or host-only network
"A VM is perfectly safe, so I can be careless" VMs add a strong barrier but not an absolute one. Keep targets isolated and the host updated
"I'll use my real password in the lab" Lab data should be fake. Credentials in a lab can leak into notes, logs and screenshots
"I'll download that tool from the first search result" Download from the project's official site and verify the checksum and signature
"I forgot to take a clean snapshot" Take it right after install and updates, before any experiments
"I'll host my practice app online so I can reach it from anywhere" DVWA's own README says never to put it on an internet-facing server. Use a private network or VPN you control, or run it only locally
"I'll scan my school/work network to practise" Without written permission this can break policy and law. Scan your lab
"Emulation works on my Arm laptop, so any x86 image is fine" Emulation can be very slow, and the VirtualBox manual calls its Arm package a developer preview. Prefer images built for your processor
"Shared folders and clipboard are harmless" They are channels between guest and host. Turn them off for risky guests
"The snapshot is my backup" Restoring loses changes made since. Keep real notes and scripts outside the VM

Closing

A lab is a safe place to be wrong. It is only safe if you build it that way: virtual machines to contain mistakes, isolated networks to keep vulnerable targets away from everything real, snapshots so you can undo, verified downloads so you know what you are running, and a firm rule to attack only what you own or are authorised to test.

Keep these points:

  • Match images to your processor. Check with uname -m.
  • Isolate the network. Use an internal or host-only network for targets. Never use bridged for a vulnerable machine.
  • Snapshot a clean state and restore after risky work.
  • Verify downloads with the official checksum and signature.
  • Use targets built for practice, and never host them publicly.
  • Permission first, always.

If you can draw your lab on paper, say which adapter each machine has, and explain why the target cannot be reached from your home network, you are ready to practise.

Related: Packet Capture and Port Scanning Basics gives you the first things to do inside the lab, Linux Fundamentals covers the operating system you will work in, and Security Testing explains the rules of engagement for the real world.