Creating VetSecs Wargame Pt. 1: Intro to Vagrant and creating a custom VM

September 22, 2018


Hello everyone! With VetSec growing every day, we have decided to work on becoming a nonprofit organization. Our current focus is to be able to provide veterans and those currently serving with training and guidance into the ever-growing field of Cyber Security. To help aid in this training, I have begun working on our very own Wargame, which will provide tutorials and challenges for those who are interested. Creating a Wargame is completely new to me, so I hope to learn a lot from this process while providing others with insight to learn alongside me.

This post will be focused on the creation of the VetSec Wargame VM. My intentions are to make this lightweight and easily accessible for users. With the use of Vagrant, I should be able to provide users with a simple process and minimal amount of downloads while having access to a large variety of tools and challenges to learn from. This is also my first blog post, so please feel free to provide any feedback, good or bad, so I can learn how to become a better teacher/blogger.

How to get started with Vagrant:

First off, what is Vagrant? Vagrant is a tool that is used for building and managing virtual machine environments in a single workflow. It focuses on automation and creating portable work environments. It can spin up VM’s with VirtualBox, VMware, AWS, and other providers in a quick and easy to use manner.

If you intend on following along for your own knowledge, you will need to download Vagrant for your operating system as well as whichever provider you intend on using for your VM. In my case, I am using Ubuntu 18.04 and I went with VirtualBox since it was free and easy to use.

These can be obtained with the following commands in a terminal (on linux):

$ wget
$ sudo apt install virtualbox && sudo dpkg -i vagrant_2.1.5_x86_64.deb

Installing Vagrant and VirtualBox on Ubuntu

After getting these both installed, we need to create our Vagrantfile, which is a file that describes the type of VM we will be creating with any customizations we want. Following the guide provided by Vagrant, we should create a new directory to host our files in, then change directories into this folder and run ‘vagrant init‘, which will place a Vagrantfile into the current directory. I ran mkdir vagarant to create a folder called ‘vagrant‘ and then ran ‘vagrant init‘ from within the newly created vagrant directory. From there, I ran vim on the Vagrantfile to modify the VM to my liking. You can view my file below and/or download it from my Github.


Vagrantfile for VetSec-Wargame

This may look confusing, so I will explain what it means. Most of these commands can be found here and here.

  • Vagrant suggests using Vagrant version 2, which represents configurations for version 1.1+ and leading up to 2.0.x, which is what is meant by the first line with “Vagrant.configure(‘2’)“. The “do |config|” part allows us to just use an object called ‘config’ to do our configuration.
  • The next chunk configures our VM. I set the hostname with “config.vm.hostname = ‘vetsec-wg’“, then I set the vm to be an ubuntu 18.04 box from Vagrants provided VM’s, and finally, I allow a couple shared folders between the VM and our host OS, to allow for easy transferring of files, if needed. Any file we place into the ‘vagrant‘ directory can be accessed from both within our VM and from the host os, super useful!
  • The “config.ssh.username = ‘vagrant’” part isn’t necessary, as our default login via SSH is the user ‘vagrant‘ anyway, but I added it for ease of swapping default usernames later down the road.
  •  “config.vm.provider :virtualbox” sets our VM to use the provider Virtualbox (this can be swapped out with any provider, whichever you decide to use), and again, the “do |vb|” part just gives us an object with a name ‘vb’ to allow us to more easily access the configuring of the Virtualbox side of our vm.
  • = ‘vetsec-wargame’” sets the name of our VM in Virtualbox. “vm.customize [‘modifyvm’, :id, ‘–memory’, ‘768’, ‘–cpus’, ‘2’]” allows us to modify our vm and set the memory to 768MB and using 2 corees.
    vb.gui = false” is also not necessary, since the default for GUI is set to off, but if I decide that a GUI might be more beneficial later for some challenges, I may want to turn this capability on.
  • Now I set up the provisioning. “config.vm.provision :shell do |shell|” tells Vagrant that we will provision our vm via the shell provided in the VM, and we will use ‘shell‘ to provide further configuring of the provisioning.
  • First, I set the shell to not privileged with “shell.privileged = false“, because later when I try to work with the home directory (~), it kept trying to access the home directory for ‘root‘ instead of for the user ‘vagrant‘.
  • Then, with “shell.inline = <<-SHELL“, I’m able to provide shell commands one after another, without having to write “shell.inline” multiple times.
  • After this, I installed ‘gdb‘ (GNU Project Debugger) and ‘peda‘ (Python Exploit Development Assistance) via the command line with ‘apt’, which will be useful tools for the first set of challenges I intend to create for this Wargame. NOTE: I have since changed my Vagrantfile to run a shell script to install packages I provide with the box to prevent error in future usage of the wargame.

If you decide to update this Vagrantfile with new features and would like to have them be installed without completely tearing down and spinning up a new VM, just run ‘vagrant reload‘ and your VM will reprovision, installing any new features!

Vagrant up:

That’s it for the setting up, now let’s get into the VM and make sure it works! Vagrant provides us with simple commands to get the VM spun up and to access it. First, run ‘vagrant up‘ to create our new VM which should look similar to this:


Vagrant up on our VM

It will hang a little bit during the SSH auth method: private key, due to the nature of vagrant creating a new private key for us to access this VM. Unfortunately, as of right now, I don’t know of any work-around if we want to keep the command to spin up our VM nice and simple, so a little delay is fine with me for an initial setup.

Now, once we have our VM spun up, we can access it with ‘vagrant ssh‘, to SSH into our VM! We should see that we have access to the tools that were downloaded when provisioning, which in my case, is just ‘gdb‘ and ‘peda‘, which you can test with just typing ‘gdb‘ into the terminal.

This has essentially created a headless Ubuntu 18.04 VM to play with at our hearts content. To leave the VM, just type ‘logout‘, and you will return to your host OS. The VM can be suspended with the command ‘vagrant suspend‘ and it can be completely shut down with ‘vagrant halt‘. If you would like to return to a completely clean slate, just run ‘vagrant destroy‘ and you will remove the VM entirely.

How to use later:

This box can now be created with ease by having both the Vagrantfile and in the same folder and then running

$ vagrant up

Or, as an alternative, if you package the box together by running

$ vagrant package --output --include --vagrantfile Vagrantfile

you can just put the .box in a folder and run

$ vagrant box add vetsec-wg
$ vagrant up

to spin it up!

Staying up to date with the Wargame:

This wargame is clearly a work in progress. I will be posting updated versions to my Github primarily, with the occasional update to the portable box file on my Google Drive.

Stay posted for future blog posts!

Part 2 is in the works!

Other considerations:

Shell script provisioning (update Sept 23 2018)

After some thought, I decided that having a shell script install all of the needed components would be better than configuring a Vagrantfile. The script I wrote currently looks like the following:

installscript (name is now

I think this will make for an easier time in the future when dealing with modifying what tools should be installed from the get go. As you can see, I did make a few changes than what was initially in my Vagrantfile before, like a small customization to Vim and a new tool to be installed called ‘radare2‘.

Radare2 is a command line disassembler, which I intend to have people use for the reverse engineering challenges I will create down the road. I am new to using this tool, so I will also create a tutorial for it while I learn it myself in a future post while reading up on their introduction book for the tool.


Since I am trying to keep this as light as possible while utilizing the current latest Ubuntu OS, I am limited the VM to headless by default. GUI’s can be installed, but this would hinder the learning process of utilizing the CLI (Command Line Interface), which is an extremely useful tool when working with Linux. To install a Vanilla Gnome Desktop GUI, you can run the following command:

$ sudo apt install gnome-session gdm3 --fix-missing

Or for the full Ubuntu experience:

$ sudo apt install tasksel
$ sudo tasksel install ubuntu-desktop

After your preferred GUI is installed,  you can access it by changing the Vagrantfile to:

vb.gui = true

Then logging in via the credentials:
username: vagrant

password: vagrant

I hope this was a useful tutorial and/or learning opportunity for you guys! If you have any feedback or want to chat, feel free to contact me on one of my many means of communication. Thanks!

@emtuls twitter_thumb

If you’re a veteran interested in Cyber Security, consider joining our Slack channel.