Sub topic 12
Security and Isolation of Virtual Machines
This chapter assumes you know what a host, a guest, and a hypervisor are. It also assumes you know the four virtual network modes (NAT, bridged, host-only, internal) and basic Windows or Linux administration. Here you will see how virtual machines (VMs) are isolated from the host and from each other, where that isolation breaks down, and which settings reduce the risk.
The Isolation Model
A hypervisor gives each guest its own virtual CPU, memory, disk, and network adapter. The guest operating system (OS) cannot read the memory or files of the host or of other guests unless the hypervisor lets it. This separation is called isolation. It is the reason people use VMs as sandboxes, which are contained environments for running untrusted software or testing changes.
Isolation is a strong boundary, but it is not absolute. The hypervisor is software, so it can have bugs. The host OS, the virtual network, and any features you enable can also open paths between guest and host.
What Isolation Protects
- Malware containment. If a guest is infected, the malware normally cannot touch the host's files. You can delete or revert the guest.
- Safe testing. You can try an untrusted installer, a risky browser extension, or a suspicious email attachment inside a guest.
- Separation of roles. A technician can keep a work environment and a personal environment on one PC, each in its own guest.
- Legacy containment. An old OS that no longer receives security updates can run in a guest on a restricted network instead of directly on the network.
Where Isolation Breaks Down
VM escape
A VM escape is an attack in which code in a guest breaks out of its VM and runs on the host or in the hypervisor. It requires a flaw in the hypervisor or its drivers. These flaws are rare, but they are serious because one escape can expose every guest on the host. The defense is to keep the hypervisor and host OS patched.
Shared features that bridge the boundary
Convenience features connect the guest to the host. Each one is a path that malware could use.
| Feature | Convenience | Risk |
|---|---|---|
| Shared folders | Move files between host and guest | Malware in the guest can write to or encrypt host files in the shared folder |
| Shared clipboard | Copy and paste between the two | Data or malicious content crosses the boundary |
| Drag and drop | Easy file transfer | Same as shared folders |
| Removable device pass-through (USB) | Use a USB drive in the guest | A guest can read or infect the device, which then moves to the host |
| Guest additions or integration tools | Better display and performance | Extra drivers and services add attack surface |
For a high-risk sandbox, disable shared folders, clipboard sharing, and drag and drop. Mount a shared folder read-only if you must have one.
VM sprawl
VM sprawl is the uncontrolled growth in the number of VMs, many of them forgotten. Each unused guest still has an OS and software that need patches. Unpatched, unmonitored VMs are easy targets and can be a way into the network. Keep an inventory, assign owners, and delete guests that are no longer needed.
Resource exhaustion
Guests share the host's CPU, RAM, disk, and network. A runaway or compromised guest can use so many resources that the host and other guests slow down or crash. This is a form of denial of service. Set limits on each guest's memory, CPU count, and disk size.
Network Mode and Exposure
The virtual network mode decides who can reach the guest and what the guest can reach. Choose the most restrictive mode that still lets the guest do its job.
| Mode | Guest can reach internet | Other LAN devices can reach guest | Typical security use |
|---|---|---|---|
| NAT | Yes | No, unless you add port forwarding | Default for general testing and browsing |
| Bridged | Yes | Yes, the guest has its own LAN address | Servers or services that other devices must reach. Highest exposure. |
| Host-only | No | Only the host | Testing with no internet path, such as analyzing malware |
| Internal | No | Only other guests on the same internal network | Fully isolated lab of several guests |
A bridged guest sits on the same LAN as physical machines. If it is infected, it can scan and attack them. An unpatched legacy guest in bridged mode is a poor choice. Put it in NAT, host-only, or internal mode instead.
Snapshots and Checkpoints
A snapshot (called a checkpoint in Hyper-V) saves the state of a guest at one moment, so you can return to it later. For a sandbox, the workflow is simple:
- Install the guest OS and tools.
- Take a clean snapshot.
- Run the risky software.
- Revert to the clean snapshot.
Snapshots have limits:
- They are not backups. They usually depend on the original virtual disk, so losing that disk loses the snapshots.
- A snapshot taken while the guest is running can store memory contents, including passwords and keys.
- Long snapshot chains slow the guest and use a lot of disk space.
- Reverting a domain-joined or time-sensitive guest can cause problems, such as an out-of-date machine password or old security data.
Keep real backups of important guests in addition to snapshots.
Protecting the Host and the Guests
Treat each guest as a real computer. A guest has its own OS and needs the same protection as a physical PC.
- Patch the guest. Install OS and application updates inside each guest.
- Run antimalware in each guest. Host antivirus does not necessarily see inside a guest's disk file.
- Use a host firewall and a guest firewall. The two are separate.
- Use strong passwords and least privilege. Do not give guest accounts more rights than needed.
- Encrypt the virtual disks or the host drive. A virtual disk is just a file. Anyone who copies it can mount it and read it. Full-disk encryption on the host, or encryption inside the guest, protects it if the file or laptop is stolen.
- Protect the hypervisor account. Anyone who can administer the hypervisor can read, copy, or change any guest. Limit who has that access.
- Isolate the host. Run as little as possible on a Type 1 hypervisor host, because every extra service adds attack surface. On a Type 2 hypervisor, the host OS is a normal desktop OS, so a compromise of that OS also exposes every guest.
Licensing and Compliance
Each guest OS and its applications need a valid license. A VM is not exempt. Some licenses restrict how many VMs you may run or move between hosts. Compliance is a security and legal concern, because unlicensed software cannot always be updated.
Hardware-Assisted Protections
Modern CPUs add features for virtualization (covered in the hardware support chapter). They help the hypervisor keep guests apart in memory. Keep the BIOS/UEFI firmware updated, because firmware flaws can undermine the hypervisor. Also set a firmware password so that nobody can quietly change virtualization settings.
Quick Decision Guide
| Need | Setting |
|---|---|
| Open a suspicious file | Guest with NAT or host-only mode, no shared folder, snapshot first |
| Analyze malware | Host-only or internal mode, no clipboard, no shared folder |
| Run a legacy OS | Internal or host-only mode. Add NAT only if the internet is required. |
| Host a service for other PCs | Bridged mode, fully patched guest, firewall on |
| Several guests that talk only to each other | Internal mode |
Common Mistakes
- Leaving shared folders on in a malware test, which lets malware reach host files.
- Using bridged mode by default, exposing the guest to the whole LAN.
- Treating a snapshot as a backup.
- Forgetting to patch guests that are rarely powered on.
- Assuming host antivirus protects the inside of every guest.
- Leaving virtual disk files unencrypted on a laptop.
Exercise
A technician needs to open a suspicious attachment on a laptop. The laptop holds client files. Describe how to configure a guest VM for this task, including network mode, shared features, and what to do afterward.
Show answer
Create or use a guest with a clean snapshot. Set the network mode to host-only, or to NAT if internet access is not avoidable. Disable shared folders, clipboard sharing, drag and drop, and USB pass-through so the malware cannot reach host files. Open the attachment in the guest. When finished, revert to the clean snapshot (or delete the guest) so any infection is discarded.
Exercise
An unpatched Windows 7 guest is needed for an old application that must be reachable by one other guest only. Which network mode is best, and why is bridged mode a poor choice?
Show answer
Internal mode is best, because only guests on the same internal network can reach each other, and the host, LAN, and internet are not reachable. Bridged mode gives the guest its own address on the physical LAN, so the unpatched OS would be exposed to other devices and could attack them if infected.
Exercise
What is a VM escape, and what is the main defense against it?
Show answer
A VM escape is an attack where code in a guest breaks out of its VM to reach the host or hypervisor, possibly exposing every guest. The main defense is to keep the hypervisor, host OS, and firmware patched, and to limit shared features between guest and host.