Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 53 ยท Building a Safe Lab

Building a Safe Home Lab

Plan an isolated home security lab: virtual machines, host-only networks, snapshots, deliberately vulnerable training apps and rules that keep testing off real systems.

Security skills come from practice, and practice needs a place where mistakes are harmless. A home lab is a small, isolated set of virtual machines where you can scan, break, fix and rebuild things without touching anyone else's systems or your own important data. Building one is also your first lesson in security design, because the lab's most important property is something absent: a path from the vulnerable machines to the real world.

This lesson explains the pieces of a lab, how virtual networks isolate it, how snapshots let you undo disasters, and which training targets are made to be attacked. The setup commands are shown read-only because they run on your own computer. A runnable stand-in validates a lab network plan, the check you should do before you power anything on.

Anatomy of a safe lab

Host Your real computer. Keep it clean.
Virtual machines Attacker box and vulnerable targets.
Isolated network Virtual switch with no way out.
Snapshots Undo any mistake in seconds.

Isolation protects you, your family and strangers.

1 / 2

Hardware and virtualization

You do not need a data center. A laptop or desktop with 16 GB of RAM (8 GB is workable for one or two small machines), a modern multi-core CPU with virtualization support turned on in the firmware, and 100 GB or more of free disk is enough to start. An SSD makes everything feel better.

A hypervisor runs virtual machines (VMs): VirtualBox (free), VMware Workstation or Fusion, Hyper-V on Windows, KVM/libvirt on Linux, or UTM on macOS. A VM behaves like a separate computer with its own operating system and virtual network card, but its files live in a few large files on your disk. If a target is compromised, the damage stays inside that VM.

A typical starter lab has three roles:

  • Attacker/analyst VM: a Linux distribution with your testing tools. You will learn the command line in Linux and Command-Line Skills for Security Work.
  • Target VMs: machines you are allowed to attack because you created them, such as a deliberately vulnerable web app, an old unpatched server image or a fresh Linux server you will harden.
  • Defender/monitor VM (optional but valuable): collects logs and watches traffic so you can see what your own tests look like from the other side. See Logging, Monitoring and SIEM Basics.

Isolated virtual networks

The networking mode of each VM decides what it can reach. These are the common hypervisor options, with the names VirtualBox uses (others have equivalents):

Mode VM can reach Reachable from outside Use in a lab
NAT Internet, via the host No (unless port-forwarded) Updates and downloads for the attacker VM
Bridged The real home network, as its own device Yes, by everyone on the LAN Avoid for vulnerable targets
Host-only Host and other VMs on the same host-only network Only the host Good for targets and an attacker VM
Internal network Only VMs on the same named network Not even the host Strongest isolation

The key rule: a deliberately vulnerable VM must never be bridged to your real network, because other devices (and any malware already on them) could reach it, and it may reach them. Give vulnerable targets a host-only or internal network only. If the attacker VM needs the internet, use two network adapters: one NAT adapter for updates, and one host-only adapter for the lab. Many people disable the NAT adapter while testing, so there is no bridge between the lab and the internet at all.

flowchart LR
    I(("Internet")) --- N["NAT adapter<br/>(updates only)"]
    N --- A["Attacker VM"]
    A --- S["Host-only<br/>virtual switch<br/>192.168.56.0/24"]
    S --- T1["Target VM 1<br/>web app"]
    S --- T2["Target VM 2<br/>old server"]
    S --- M["Monitor VM"]

Targets only plug into the host-only switch. They have no adapter that touches the internet or your home network.

Choosing addresses

Use private address ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), and pick a range that does not overlap your real home network, so a mistake never makes the lab and your router share addresses. If your home router uses 192.168.1.0/24, use something like 192.168.56.0/24 or 10.50.0.0/24 for the lab. Write the plan down: which VM, which adapter, which address.

Snapshots: your undo button

A snapshot records a VM's complete state (disk, and optionally memory) at a moment in time. Break the machine, crash it, infect it with a training sample, and you can roll back in seconds. Good habits:

  • Take a snapshot after the clean install and updates, named clean-base.
  • Take one before every experiment, with a descriptive name (before-sqli-practice).
  • Use clones to make several targets from one base image.
  • Remember that snapshots are not backups: if the disk dies, they die too. Export the VMs you care about.

Typical VirtualBox commands look like this (read-only here; they run on your host, not in this site):

TEXT
VBoxManage list vms
VBoxManage snapshot "target-web" take "clean-base"
VBoxManage snapshot "target-web" restore "clean-base"
VBoxManage hostonlyif create
VBoxManage modifyvm "target-web" --nic1 hostonly --hostonlyadapter1 vboxnet0

Other hypervisors have their own tools, but the same ideas apply.

Deliberately vulnerable training targets

Never practice on a system that was built to be secure and belongs to someone else. Practice on software designed to be attacked, which you run yourself:

  • Vulnerable web applications such as OWASP Juice Shop, DVWA (Damn Vulnerable Web Application), WebGoat and bWAPP. They ship with known flaws and often with hints and scoreboards.
  • Intentionally vulnerable machines published for training, which you download and run in your host-only network.
  • Your own builds: install a web server and an old version of a CMS, then attack it, then patch it, then attack again. This teaches both sides.
  • Online practice platforms that give you legal, hosted targets (covered in Certifications, Practice Platforms and Careers).

Download images only from the project's official page, verify published checksums where offered, and treat the VMs as hostile: they contain intentional holes and sometimes unknown software.

Lab rules. Attack only machines you created in your lab. Never point a tool at your school, employer, neighbors, a website you do not own or a home network device unless you own it and know exactly what it will do. If you are unsure whether an address is yours, do not scan it.

Protecting yourself

  • Keep the host fully updated and do not store sensitive files in shared folders that VMs can reach. Disable clipboard sharing and drag-and-drop between the host and untrusted VMs.
  • Do not log into personal accounts inside lab VMs.
  • Make sure the host firewall does not forward traffic from the host-only network outward.
  • Keep tools in the attacker VM only; do not install attack tools on your daily computer.
  • Write down which VMs are vulnerable and shut them down when you finish.

Stand-in: validate a lab network plan

Before powering a lab on, check the plan. The model below holds a list of VMs and their network adapters, then reports violations of the rules above: a vulnerable VM that is bridged or has NAT access, addresses outside the host-only range, and duplicate addresses. It is a model of a design review, not something that reads your real hypervisor.

JS Lab plan validator

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Fix the plan by changing old-server to a host-only adapter in the right range and giving dvwa its own address, then run it again. Notice that the monitor VM on a different internal network passes the checks yet cannot see the others: validation catches unsafe designs, not useless ones.

Stand-in: resource budget

Labs fail quietly when the host runs out of memory. This second model adds up the RAM and disk you plan to use and compares them with your machine, leaving room for the host itself.

JS Will the lab fit on my computer?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Setting up DVWA, a practice web application

DVWA (Damn Vulnerable Web Application) is a small PHP and MySQL application whose entire purpose is to be insecure. It is a good first target for the web chapters of this course, because each page demonstrates one flaw and has a security level switch that changes how well it defends itself.

DVWA contains real vulnerabilities. Run it only on a VM or container with a host-only or internal network, never on a server reachable from the internet and never on a machine that holds anything you care about.

Installation outline

The details change between releases, so follow the project's own README, but the outline is stable. Commands are read-only examples for a fresh Debian-style lab VM.

TEXT
# 1. LAMP stack: Apache (or nginx), PHP, MariaDB/MySQL
sudo apt update
sudo apt install apache2 mariadb-server php php-mysqli php-gd

# 2. Database and a dedicated lab user (use your own lab password)
sudo mysql -e "CREATE DATABASE dvwa;"
sudo mysql -e "CREATE USER 'dvwa'@'localhost' IDENTIFIED BY 'lab-only-password';"
sudo mysql -e "GRANT ALL ON dvwa.* TO 'dvwa'@'localhost';"

# 3. Put the DVWA files in the web root and copy the sample config
#    edit the database name, user and password in config/config.inc.php

# 4. Open the setup page in the browser on the lab network and press "Create / Reset Database"

A container image is an even quicker route: one command starts the app and its database, and removing the container resets everything. Either way, take a snapshot before you begin so you can undo your experiments.

Security levels

DVWA offers four levels that you set from its settings page:

  • Low has no protection at all. Use it to see what the flaw is.
  • Medium adds naive defenses that can be bypassed, which teaches why simple filters fail.
  • High adds stronger checks that need more careful testing.
  • Impossible shows a secure implementation. Read this code last: it is the lesson in how to fix the issue.

What you can practice

The modules line up with this course. Each module is one lesson's topic:

  • Brute force and weak sessions (Authentication Flaws)
  • Command injection and SQL injection (SQL Injection)
  • Cross-site scripting (reflected, stored and DOM) and CSRF (XSS and CSRF)
  • File inclusion and file upload flaws (Server-Side Flaws)
  • Content security policy and insecure CAPTCHA examples
  • Weak session IDs and JavaScript-side validation

Work the way a real tester does: capture the request in a proxy, change one thing, explain the result and then switch the level and see how the code defends itself. Write a short finding for each one, using the report format from Reporting.

A lab readiness check

The stand-in checks an invented lab configuration against the safety rules above. Use the same idea as a pre-flight list before you start practicing.

Node.js Pre-flight check for a vulnerable lab app

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Other practice apps (Juice Shop, WebGoat, bWAPP) follow the same rules: isolate, snapshot, practice, write up, reset.

Installing Metasploitable 2 safely

Metasploitable 2 is an intentionally vulnerable Linux virtual machine, published so learners can practice scanning and testing legally. Because it is full of known holes it must never be reachable from the internet or your normal network.

  1. Download the image only from the project's official source and check its checksum if one is published.
  2. Import it into your hypervisor (VirtualBox or VMware) and give it a host-only or internal network adapter, not bridged.
  3. Boot it and log in with the credentials printed on the console banner of the lab documentation.
  4. Run basic post-installation checks: note its IP address, confirm the interface is on the isolated network, take a snapshot of the clean state.
  5. Verify network connectivity from your attacker VM with a simple ping, and confirm from your real network that the machine is not reachable.

Revert to the snapshot after every exercise. For modern practice, prefer maintained training targets, but Metasploitable remains useful for learning the vocabulary of services and flaws.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which network mode is the worst choice for a deliberately vulnerable VM?

    Bridged puts the VM on your real network, where other devices can reach it and it can reach them.
  2. 2. What is the best time to take a snapshot?

    A snapshot is an undo point, so it must exist before the risky step.
  3. 3. Why choose a lab address range that does not overlap your home network?

    Overlapping ranges cause routing confusion and make it easy to scan or reach a real device by mistake.
  4. 4. Which of these is a legal, appropriate practice target?

    Practice only on systems you own or that are explicitly offered for practice, such as training apps you run yourself.
  5. 5. Snapshots are NOT a substitute for what?

    Snapshots live on the same disk as the VM. If the disk fails or the files are deleted, both are lost, so export important VMs.

Summary

  • A lab is isolated virtual machines on a virtual network where mistakes cannot reach real systems.
  • Use NAT for updates, host-only or internal networks for targets, and never bridge vulnerable machines.
  • Plan addresses in a private range that does not overlap your home network, and write the plan down.
  • Snapshots before each experiment let you roll back; export VMs you want to keep because snapshots are not backups.
  • Practice on deliberately vulnerable apps and your own builds, from official sources, and treat them as hostile.
  • Never point a tool at a system you do not own.

Next: Linux and Command-Line Skills for Security Work.