Inject virtual machines in the clouds

31 March 2020


Recently we[1] played saarctf[2]. It was really really funny to play. This competition was an attack/defence CTF, you can find a link[3] to the liveoverflow video that describe how this kind of competitions works.

As you can see from the site of the CTF, it includes a router per team in the network layout. Based on Linux. But...when we decided our infrastructure the chosen operating system for the routing was OpenBSD. How unfortunate!

That is not a problem, you may think, you replace the provided router with your OpenBSD machine and you're well to go.

Well, yes...and no.

This was the first attack/defence CTF we played from home thanks to the ncovid-2019. :) As many of us doesn't have powerful x86_64 machines and/or optical-fiber based network connection we decided to use a cloud provider to host our infrastructure[4].

And now comes the problem: many cloud providers do not support OpenBSD.

VM injector

To run an unsupported operating system on the cloud I've created a script that push the operating system raw image and burn it into the virtual disk[5].

If you are still reading I suppose that you do not want a copy and paste of the readme of the project but the gory details in their entire glory. ;)

When the image get pushed we cannot just burn it to the running disk. We need, at least, to move it to a disk that will not be touched by the burning process and unmount the target disk. Unfortunately, the root partition is on the disk we want to nuke. :)

This bring us to the next component of the script, pivot_root. This systemcall will change the running root of the system, giving us the opportunity to mount the system over a ramdisk and wipe the main disk. As we will not have any program in the new root we first copy busybox and the target image to a new ramdisk, and then we pivot_root in.

After that step we can dd the new disk over the pre-installed main disk and reboot. Then the new system will (hopefully) show up.

OpenBSD autoinstall installXX.fs

There is only another step to complete our system: OpenBSD can be autoinstalled using a file called /install.conf. To do so you need to recompile the OpenBSD install image and place the file in the root of your custom install.fs

If you don't have an OpenBSD system the easiest way to do that is create a virtual machine running it. The installation process is pretty straightforward, but we have a vagrant VirtualBox virtual machine available in the vagrant repository[6].
You can init that machine using
 $ mkdir openbsd_autoinstaller
$ cd openbsd_autoinstaller
$ cat - >Vagrantfile <<_END_
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "berdav/openbsd6.6"
  config.ssh.shell = "/bin/ksh"
  config.ssh.sudo_command = "/bin/doas %s"

  config.vm.box_check_update = true

  config.vm.synced_folder ".", "/vagrant",disabled: true

  config.vm.provider "virtualbox" do |vb|
    # Customize the amount of memory on the VM:
    vb.memory = "4096"
$ vagrant up
$ vagrant ssh  
Now that you've an installation of OpenBSD up and running you can configure your custom installfs.
In a following post I'll show how to create a custom install fs with a script.

Have fun and stay home!

[1] The ULISSE team.
[2] saarctf Attack/defence challenge
[3] LiveOverflow video that explains the A/D CTF format youtube link.
[4] Hetzner cloud provider
[5] Script hosted on github
[6] openbsd virtual machine disk hosted on vagrantup