One of the things that I’ve noticed in the infosec community is the tendency to stick to the proprietary virtualization tools that are familiar. People often are quick discount tools that they don’t already know, so I have written this blog post in an attempt to foster an interest in exploring other virtualization options. My hope is that, even if you don’t come away wanting to use QEMU in your CTF lab or malware analysis playpen, you will at least be more open to looking into other forms of emulation and virtualization.
Many hacking event organizers spend ample time pointing and clicking through their VirtualBox and VMware configuration wizards to setup their hacking labs. What if I told you there was a better way that works on Linux, macOS, Windows, and Xen?
With QEMU your VMs are defined as
the arguments passed to QEMU on its invocation at the command line. For
example, you might invoke a VM as such (note that
> is a $PS2
prompt):
$ qemu-system-x86_64 -machine type=q35 --enable-kvm -cpu host -smp cpus=8 \
> -m 512M -netdev user,id=net0 -device e1000,netdev=net0 -hda dsk/vm-hdd.qcow
Obviously this isn’t a good long-term way to run your VM, but fear not, as there is a better way! All you have to do is save your VM arguments to an executable shell script like the following:
#!/usr/bin/env bash
# image creation command:
# qemu-img create -f qcow2 -o preallocation=metadata dsk/vm-hdd.qcow 20G
qemu-system-x86_64 \
-machine type=q35 \
--enable-kvm \
-cpu host \
-smp cpus=8 \
-m 512M
-netdev user,id=net0 \
-device e1000,netdev=net0 \
-hda dsk/vm-hdd.qcow \
;
Don’t forget to make your script executable!
$ chmod +x vm-foo
The nice thing about these scripts is that you can freely copy and edit them with the standard UNIX command-line tools that you are used to, meaning that you can use one VM script as a template for another virtual machine. Making a VM based on a template then becomes as simple as copying a bash script:
$ cp vm-foo vm-bar
For more information on creating QEMU disk images, see the qemu-img(1) man page.
QEMU is a capable of emulating foreign CPU architectures, as well as working in conjunction with a hypervisor to perform fully-accelerated, near native-performance virtualization. Some of the supported architectures for full-system emulation are:
Some of its other features include:
Stay tuned for more!