C2 Games Infrastructure Challenges are structured as Ansible roles that can be deployed to a variety of Operating Systems (OS’s). Challenges should be tested against CentOS 7+ and Ubuntu 18.04+ at a minimum.

To reduce setup time, Vagrant can be utilized to create test and development Virtual Machines (VM’s).

Getting help

We’re here to help! The C2Games maintainers and community are happy to help answer questions and debug issues, if the instructions or FAQ can not help.

We can be reached by the following means:

  • Email: opfor-content@c2games.org
  • Discord: https://discord.gg/H2jwMxt

Setup Environment using Vagrant

Vagrant is the recommended way to set up a local development environment, if the environment will be run on your local machine with Virtualbox or HyperV. The Dev Environment is 3 total Virtual Machines, or VMs; 1 development VM, and 2 test VMs. Using the development VM is optional. The default login to these systems is:

Username: vagrant

Password: vagrant

NOTE: By default, the VMs are configured with "Bridged" networking within VirtualBox. This means that vulnerable VMs are put on the same network as the host system, ex – your home Wifi or employer network. Use appropriate caution when creating vulnerable systems.

Host System Requirements

  • 8+ GB RAM
  • OS with Virtualbox or Hyper-V support

Install host dependencies

  1. Download and Install Vagrant from https://www.vagrantup.com/downloads

    • Check here for more installation instructions and documentation: https://www.vagrantup.com/docs/installation
    • Note: On Debian or Ubuntu, select the "Debian" download instead of the Linux download. The "Linux" has some known issues with vagrant ssh, and must be installed manually.
  2. Install Virtualization Provider

    • Vagrant supports several virtualization providers, including virtualbox and Hyper-V. Install a supported virtualization provider according to their instructions.

      • NOTE: On Linux, virtualbox may require the package bsdtar to be installed. On Ubuntu, it can be installed with: sudo apt install libarchive-tools
      • NOTE: You must restart your host to finish the installation or enabling of a virtualization provider.

Create Virtual Machines

  1. Provision and Start VMs with the provision_all.sh script (or the Provision-All.ps1 on Windows)

    • Virtualbox is the default provider. To use HyperV as the provider on Windows, use the commands: powershell -ExecutionPolicy bypass -File Provision-All.ps1 Provision-All.ps1 -Provider hyperv
    • The Provision script will ask vagrant to fetch the base OS images, configure them, and provide network access.
      • NOTE if prompted for which interface the VM network should bridge to, use the one on your host machine which connects you to the internet. It normally is the option 1
      • NOTE when using Virtualbox, VMs will be given a bridged adapter and an IP directly on the host network. When using HyperV, VMs will be given a private IP with internet access via NAT
    • The Provision script will take a running snapshot of each VM with the snapshot name "clean", providing a clean state to test challenges against.
  2. Login to the development VM to run Ansible with the command vagrant ssh dev.

    • To log into a test VM, use vagrant ssh centos_test or vagrant ssh ubuntu_test
    • With VirtualBox, each VM is on the same network as the host (ex, if your PC is on your home WiFi, so is the VM). The VM will get an IP on the same network as the host, which can be used to connect to the VM.
    • The IP Address of each system is available on the TTY Login Screen.

Start Virtual Machines

  1. Change directories into setup_dev_environment
  2. Start all test and dev VMs vagrant up or start individual VMs by specifying their names: dev/ubuntu_test/centos_test vagrant up ubuntu_test
  3. Restore Test VMs to their clean snapshot vagrant snapshot restore clean ubuntu_test centos_test

Stop Virtual Machines

  1. Change directories into setup_dev_environment
  2. Stop all test and dev VMs vagrant halt or stop individual VMs by specifying their names: dev/ubuntu_test/centos_test vagrant halt ubuntu_test

Gather the IPs of the Test VMs

To deploy an ansible role, you will have to know the IP address’ of the test VMs you are deploying to.

vagrant ssh -c "ip addr" ubuntu_test will run the ip addr command within the ubuntu_test VM over SSH.

Develop

  1. Start developing on your host system with your favorite editor.

    • The infrastructure-examples/ directory on the host is synced to the folder /home/vagrant/c2games within the development VM. All changes made on the host and synced to the Development VM, leaving the Development environment disposable. Development should be performed on the host system, and will automatically be synced into the VM.
    • See [Development Environment](TODO LINK) for more information about editors, extensions, and more.
  2. Test an Ansible Role by executing the Ansible Playbook with the following command from within the Development System, where IP_ADDR_1 and IP_ADDR_2 are replaced with the IP addresses of the test systems.

    ansible-playbook playbook.yml -i IP_ADDR_1,IP_ADDR_2
    
  3. Revert your VMs to the clean snapshot state to re-test roles from a clean state.

    • VMs can be restored using the Virtualization Provider or using Vagrant. To use vagrant, run the following commands on the host system:
    vagrant snapshot restore centos_test clean
    vagrant snapshot restore ubuntu_test clean
    

To delete all VMs using vagrant, use the command vagrant destroy. The VMs can also be managed using the Virtualization Provider (ex, the VirtualBox or HyperV interface).