TExcelTAD
Home › Security Foundations: Concepts, Law, Ethics & Your Lab › Hypervisors, VM Networks and Snapshots

Hypervisors, VM Networks and Snapshots

Every offensive lesson in this track ends with the same instruction: try it in your lab. That raises a practical question before any security one: where is "the lab", and what stops it from touching anything else? A deliberately vulnerable machine is, by design, easy to break into. Put it on your home Wi-Fi and it is easy to break into for your neighbour's infected laptop too, or for a worm on the Internet if your router forwards a port. Run an attack tool against the wrong address range and you are scanning your ISP.

The answer is virtualisation with an isolated network: virtual machines that can see each other and nothing else, on a computer you own, with snapshots so every experiment can be undone. This lesson covers the three pieces: the hypervisor, the network modes, and snapshots. How virtualisation works inside the CPU and the kernel is in Virtualization; Windows' own hypervisor is in WSL & Hyper-V.

Hypervisors

A hypervisor runs virtual machines (VMs): complete computers with their own kernel, made of CPU time, memory and disk images borrowed from the host.

Type Runs on Examples For a home lab
Type 1 ("bare metal") directly on the hardware VMware ESXi, Microsoft Hyper-V, Xen, Proxmox VE (built on KVM) a spare PC or small server that does nothing else
Type 2 ("hosted") as an application on a normal OS Oracle VirtualBox, VMware Workstation, VMware Fusion, GNOME Boxes, Parallels your everyday laptop or desktop

KVM sits between the two: it is part of the Linux kernel, so Linux itself becomes the hypervisor, usually managed with libvirt and virt-manager. Any of them works for this track. Two practical limits matter more than the brand: memory (a Windows Server VM wants 4 GB or more, Kali 2–4 GB, a small Ubuntu Server 1–2 GB) and CPU virtualisation support (Intel VT-x or AMD-V switched on in the firmware). On Windows, Hyper-V and VirtualBox can coexist, but VirtualBox then runs on top of Hyper-V's platform and may be slower.

Containers (Docker) are a lighter option for single vulnerable web apps, covered in Lab Machines and Vulnerable Apps. They share the host's kernel, so they isolate less than a VM, which matters for anything that might attack the kernel.

Network modes

Each virtual network card of a VM is attached to one kind of network. The names below are VirtualBox's; every hypervisor has the same ideas under other names (VMware: NAT, Bridged, Host-only, LAN segment; Hyper-V: External, Internal and Private virtual switches; libvirt: NAT, routed, isolated networks).

Mode VM ↔ other VMs Host → VM VM → home LAN and Internet Home LAN → VM Use in the lab
NAT no (each VM has its own NAT) only with port forwarding yes no updates for a tools VM, never for targets
NAT Network yes, on the same NAT network only with port forwarding yes no a group of VMs that need updates
Bridged yes, as LAN peers yes yes yes never for vulnerable machines
Host-only yes yes no no targets you reach from tools on the host
Internal yes, on the same named network no no no the most isolated: targets and attack VM only
Not attached no no no no malware samples, offline analysis
Internet home LAN, router host computer (you own it) hypervisor: VirtualBox, VMware, KVM, Hyper-V NAT only NAT (updates) 2nd NIC, off during attacks internal network "lab" 10.10.0.0/24 Kali.5 Ubuntu.10 Win Server.20 vuln apps.30 no route out: no NAT, no bridge, no host interface bridged targets:never

A common and safe design is the one in the figure: all lab machines on one internal network (10.10.0.0/24 in this track); the attack VM (Kali) has a second card on NAT that you connect only to download updates and tools, and disconnect while you work on targets. Kali doesn't route between its two cards (net.ipv4.ip_forward is 0 by default), so the targets still can't reach out.

Checking a design

Reachability follows directly from the table, so you can check a lab plan before building it. The model below gives each mode the reachability of the table, takes a plan (which VM has which cards), and lists everything that can reach a vulnerable target from outside the lab.

python · try it yourself
# what each attachment can reach / be reached by (VirtualBox semantics, simplified)
REACH = {
    "nat":       {"internet": True,  "from_lan": False, "from_host": False},
    "natnet":    {"internet": True,  "from_lan": False, "from_host": False},
    "bridged":   {"internet": True,  "from_lan": True,  "from_host": True},
    "host-only": {"internet": False, "from_lan": False, "from_host": True},
    "internal":  {"internet": False, "from_lan": False, "from_host": False},
}
plan = {
    "kali":        {"vulnerable": False, "nics": ["internal:lab", "nat"]},
    "ubuntu-srv":  {"vulnerable": False, "nics": ["internal:lab"]},
    "metasploit2": {"vulnerable": True,  "nics": ["internal:lab"]},
    "dvwa-vm":     {"vulnerable": True,  "nics": ["bridged"]},
    "win2022":     {"vulnerable": True,  "nics": ["internal:lab", "host-only"]},
}

def mode(nic):
    return nic.split(":")[0]

def shares_net(a, b):
    return any(n in plan[b]["nics"] for n in plan[a]["nics"] if mode(n) in ("internal", "natnet", "host-only"))

for vm, spec in plan.items():
    if not spec["vulnerable"]:
        continue
    exposure = []
    for nic in spec["nics"]:
        r = REACH[mode(nic)]
        if r["from_lan"]:
            exposure.append("home LAN can reach it")
        if r["internet"]:
            exposure.append("it can reach the Internet")
        if r["from_host"]:
            exposure.append("host can reach it")
    peers = sorted(o for o in plan if o != vm and shares_net(vm, o))
    print(f"{vm:12} peers={','.join(peers) or '-':28} {'; '.join(exposure) or 'isolated'}")
metasploit2  peers=kali,ubuntu-srv,win2022      isolated
dvwa-vm      peers=-                            home LAN can reach it; it can reach the Internet; host can reach it
win2022      peers=kali,metasploit2,ubuntu-srv  host can reach it

metasploit2 is isolated: only the lab VMs see it. dvwa-vm on a bridged card is the finding to fix at once. win2022 with an extra host-only card is a judgement call: your host can now reach a vulnerable machine, and the machine can reach your host's host-only interface, so keep the host firewall in mind or drop the card.

Snapshots

A snapshot saves the state of a VM's disks (and optionally its memory) at one moment. Later writes go to a new differencing file, so you can revert to the snapshot in seconds. In the lab you take one:

  • after a clean install and updates ("baseline"),
  • before every experiment that changes the target (a misconfiguration you add on purpose, an exploit run, a malware sample),
  • before you hand the VM to someone else, so they start from a known state.

Snapshots are not backups: they live next to the VM's disk on the same drive, a long chain slows the disk down, and deleting the base disk loses all of them. Export a VM (.ova) or copy its folder for a real backup. Revert to the baseline after each experiment, or old changes will confuse the next one.

How problems are detected

  • On the host, list each VM's network attachments before starting it (the VM's network settings, VBoxManage showvminfo <vm> --machinereadable | grep -i nic, virsh domiflist <vm>).
  • From inside a target, ip route should show no default gateway on an internal network, and ping of a public address should fail. Check this once after building the lab.
  • From your home LAN (another device), the vulnerable services should not answer.

How it is fixed or prevented

  • Targets get internal (or host-only) cards only; never bridged, never NAT.
  • The attack VM gets internal plus an on-demand NAT card, disconnected during attacks.
  • Shared folders, clipboard sharing and drag-and-drop off for targets; they are channels between the target and your host.
  • Hypervisor and host OS kept up to date: VM escape bugs exist and are patched regularly.

Pitfalls

  • Bridged "just to make it work": the most common way a lab machine ends up on someone else's network.
  • Host-only is not internal: your host is on that network.
  • Docker publishes on all interfaces by default (-p 3000:3000 is 0.0.0.0:3000), the container equivalent of bridged. Bind to 127.0.0.1.
  • Snapshots without discipline: if you never revert, a snapshot protects nothing.

Practice

  1. A friend's lab has Metasploitable on NAT "because it can't be reached from outside". What is still wrong?
  2. Which mode would you give a VM in which you open an unknown file sample, and why?
  3. Change dvwa-vm in the plan to internal:lab and predict the new output line.
Answers
  1. NAT lets the vulnerable VM reach the Internet: anything you run on it (or anything that compromises it) can download tools or contact outside hosts. Its services are also reachable through any port forward someone adds. Use an internal network.
  2. Not attached (or an internal network with only an analysis VM), with a snapshot first: the sample can't reach anything, and you revert afterwards.
  3. dvwa-vm peers=kali,metasploit2,ubuntu-srv,win2022 isolated (the peer list is longer than the 28-character column, so there is no padding before isolated).

Test yourself

Which VirtualBox network mode lets VMs talk to each other but not to the host or the outside?

  1. NAT
  2. Bridged
  3. Host-only
  4. Internal network

Why should a deliberately vulnerable VM never use a bridged adapter?

  1. Bridged is slow
  2. It becomes a peer on your real LAN, reachable by every device there
  3. Bridged disables snapshots
  4. Bridged needs a licence

What is a snapshot not?

  1. A saved state you can revert to
  2. A backup that survives losing the VM's disk
  3. Useful before an experiment
  4. Possible on most hypervisors

Which is a Type 1 hypervisor?

  1. VMware Workstation
  2. Oracle VirtualBox
  3. VMware ESXi
  4. GNOME Boxes