# ---------------------------------------------------------------------------
# Lab VM for "Computer Security: The Foundations".
#
# A full virtual machine, in contrast to the Dockerfile alongside it.  Prefer
# this when you want real two-machine networking (Activity 13), a genuine
# kernel to disable ASLR on (Activity 11), or an isolated host-only network to
# scan (Activity 8).
#
#   vagrant up
#   vagrant ssh
#
# Pin the box version; see the Lab Setup Guide for why "latest" ages badly.
# ---------------------------------------------------------------------------
Vagrant.configure("2") do |config|
  config.vm.box         = "debian/bookworm64"
  config.vm.box_version = "12.20240905.1"     # pin; update deliberately
  config.vm.hostname    = "seccourse-lab"

  # A host-only network.  A second VM on this network is the sanctioned scan
  # target for Activity 8 and the second machine for Activity 13.  It is not
  # routable to the internet.
  config.vm.network "private_network", ip: "192.168.56.10"

  config.vm.provider "virtualbox" do |vb|
    vb.memory = 2048
    vb.cpus   = 2
  end

  config.vm.provision "shell", inline: <<-SHELL
    set -e
    export DEBIAN_FRONTEND=noninteractive
    apt-get update
    apt-get install -y --no-install-recommends \
        build-essential gcc-multilib gdb curl ca-certificates \
        netcat-openbsd python3 python3-pip python3-venv \
        openssl imagemagick libimage-exiftool-perl testdisk nmap \
        binutils file unzip
    pip3 install --no-cache-dir --break-system-packages bcrypt pyopenssl pem

    # Activity 11: disable ASLR persistently.  LAB IMAGE ONLY -- this removes a
    # real protection from the whole machine.
    echo 'kernel.randomize_va_space = 0' > /etc/sysctl.d/99-lab-aslr.conf
    sysctl --system

    # Activity 2 dictionary.
    mkdir -p /opt/lab/wordlists
    curl -fsSL -o /opt/lab/wordlists/10k-most-common.txt \
      https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10k-most-common.txt \
      || echo "fetch the dictionary manually into /opt/lab/wordlists/"

    echo "Lab VM ready.  Starter files (simple_web_server.py, victim-2020,"
    echo "sample media) are on the companion website."
  SHELL
end
