Skip to content

CTF Setup Overview

On This page we will walkthrough how to stand up a CTF instance from scratch with no challenges added (This will be another article). We will also stand up an empty SSH server for challenges to be hosted if you require it. For this setup we will utilize CTFd as the CTF server software as it quick and easy to build and get up and running.

End Goal

When we are done here you will have a CTF server and an SSH Server created for dockized challenges.

Hardware Requirements

This is dependent on the volume of traffic you are looking to host, but for this guide let’s assume this is a small event of 50 players that will run for a few days.

CTF Server

  • OS: Ubuntu Minimal Server 64-bit VM

  • CPU: 4-6 cores

  • Memory: 4-8 GB

  • HDD: 32 GB

  • Network: Single NIC with Internet Access (Bridge or NAT)

SSH Server

  • OS: Ubuntu Minimal Server 64-bit VM

  • CPU: 4-6 cores

  • Memory: 4-8 GB

  • HDD: 32 GB

  • Network: Single NIC with Internet Access (Bridge or NAT)

We have two similar Ubuntu Server VMs, now we need to start the configuration of the servers

CTFd Server Install

Let's Walk through the steps and then we will pull it all together in a script.

  1. Update and upgrade the server.

    sudo apt update && sudo apt upgrade -y
    
    Screenshot

    update/upgrade

  2. Remove snap installed docker (or verify that it was not already installed)

    It is easier to work with the docker documented install via the direct official repository

    sudo snap remove docker docker-compose
    
    Screenshot

    snap remove

  3. Remove any other remnants of potential docker instances that did not come from the official docker repo

    sudo apt-get remove docker docker-engine docker.io containerd runc
    
    Screenshot

    other docker removal

  4. Install the required files to add a repository

    sudo apt-get install ca-certificates curl gnupg -y
    
    Screenshot

    Prereqs install

  5. Install Docker GPG Public Key

    curl  -fsSL https://download.docker.com/linux/ubuntu/gpg| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    
    Screenshot

    gpg install

  6. Add the Official Docker Repo for the Ubuntu Version we are running.

    This line will work for any Ubuntu distros as long as Docker has a version for it.

    echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
    Screenshot

    New Repo

  7. Update the packages with the new repo.

    sudo apt update
    
    Screenshot

    Repo List Update

  8. Install the docker binaries from the official repo

    sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git -y
    
    Screenshot

    install binaries

  9. Configure Docker to run at startup

    sudo systemctl enable docker
    
  10. Start the Docker Service

    sudo systemctl start docker
    
    Screenshot

    Docker enable and start

  11. Move to Opt directory and clone the latest version of CTFd

    cd /opt
    sudo git clone https://github.com/CTFd/CTFd
    
    Screenshot

    clone of ctfd

  12. Modify the prepare.sh file with Python3

    cd CTFd/
    echo "#!/bin/sh" > prepare.sh
    echo "sudo apt-get update"  >> prepare.shsudo 
    echo "sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential python3-dev python3-pip libffi-dev"  >> prepare.sh
    echo "pip install -r requirements.txt"  >> prepare.sh
    
    Screenshot

    update prepare.sh

  13. Run the prepare.sh

    sudo chmod +x ./prepare.sh
    sudo ./prepare.sh
    
    Screenshot

    prepare.sh run

    pip req install

  14. Build the docker image and start the compose file

    sudo docker compose build
    sudo docker compose up -d
    
    Screenshot

    docker build

    docker compose up

    docker ps

  15. Browse to your VM IP address in a web browser

    Screenshot

    CTFd Setup

Bash CTF Server Install Script
#!/bin/bash
sudo apt update && sudo apt upgrade -y

##### Ubuntu only
sudo snap remove docker
sudo snap remove docker-compose
######

sudo apt-get remove docker docker-engine docker.io containerd runc 
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin git -y
sudo systemctl enable docker
sudo systemctl start docker
cd /opt
sudo git clone https://github.com/CTFd/CTFd
cd CTFd/
echo "#!/bin/sh" > prepare.sh
echo "sudo apt-get update"  >> prepare.shsudo 
echo "sudo DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential python3-dev python3-pip libffi-dev"  >> prepare.sh
echo "pip install -r requirements.txt"  >> prepare.sh
sudo ./prepare.sh
sudo docker compose build
sudo docker compose up -d

Advanced CTF Setup

Up to this point you have a good foundation to get the bare minimum for a CTF event up and running. With this setup you can manually through the web Gui create any and all challenges with hosted files and or text based challenges. Depending on your goal for a CTF this could be all you need.

If you are looking for more that the base setup continue over to Advanced CTF Setup; here we will talk about hosting a secondary server for dockized challenges that players interact with via the web, command line interface, or any other means you deem necessary.

If you are looking for how to create some challenges try this location Basic Challenges