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.
-
Update and upgrade the server.
Screenshot
-
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
Screenshot
-
Remove any other remnants of potential docker instances that did not come from the official docker repo
Screenshot
-
Install the required files to add a repository
Screenshot
-
Install Docker GPG Public Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Screenshot
-
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
-
Update the packages with the new repo.
Screenshot
-
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
-
Configure Docker to run at startup
-
Start the Docker Service
Screenshot
-
Move to Opt directory and clone the latest version of CTFd
Screenshot
-
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
-
Run the prepare.sh
Screenshot
-
Build the docker image and start the compose file
Screenshot
-
Browse to your VM IP address in a web browser
Screenshot
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