Host your own CTF for free 💸 (CTFd Setup Guide)
Tags: cybersecurity, cloud, docker, azure
Published: 2024-03-20 01:54:36

## Backstory

During the last weekend, a small cyber security club at my town organized their first online CTF competition. I offered to take care of the infrastructure since I've been tinkering with [CTFd](https://ctfd.io/) for a couple of weeks and surprisingly everything went well! (Except two server outages that didn't last long 😁) That's why I'm here sharing with you the process of how I set up, configured, and monitored a CTF platform that handled **150+ users** simultaneously totally **FOR FREE** 💲

![Statistics](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ao750f69bweyvonmjb5z.png)

---

## Roadmap 🛣️

1. Create and configure a Linux VM on the cloud
2. Deploy CTFd using docker-compose
3. Set up CTFd Admin Panel and settings
4. Get a domain name and link it with the VM
5. Enable HTTPS by generating a certificate

> ⚠️ Before we start make sure you have the [GitHub Student Pack](https://education.github.com/pack) since it's the only way to have all these perks for free. Make sure also to link [Microsoft Azure](https://portal.azure.com/) to your GitHub Student account.

---

## First step: Linux VM on the cloud! ☁️

This step is fairly simple. You just create a new instance/resource/linode/machine/VM whatever your provider calls it. In my case I made an Ubuntu Server VM on Microsoft Azure portal.

![Azure Portal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mbebfp4zb24k1bk3vhz3.png)

**⚠️ The most important things during this step are:**

- Choose a strong SSH password and keep it to yourself
- Enable **inbound ports** 80 and 443 for HTTP and HTTPS

Once you finish this process, you'll have SSH access to your VM. It's time for a quick `apt update && apt upgrade` followed by a nice `apt install docker.io docker-compose`. At this point you're ready for step 2!

---

## Second step: Deploying CTFd with docker 🐋

We start by cloning the CTFd github repo: `git clone https://github.com/CTFd/CTFd.git`

Then, you could add one of the themes in [this repository](https://github.com/CTFd/themes) to your `themes` folder to make your CTF shine in fashion! ✨

![CTFd theme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qhcg3ilam1l2pna8lrq.png)

Finally, go on and build your docker image by running:
`sudo docker-compose up`. It will take some time but by the end of it, you will have CTFd up and running.

---

## Third step: setting up the admin panel 👔

This process is pretty straight-forward. Navigate to your VM IP in your browser and you'll be welcomed by this:

![CTFd Setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hbuqaw2t8dw3zi85mofq.png)

All you gotta do is follow the onscreen instructions and you'll be ready to go. Don't forget to select the theme you uploaded in step 2.

---

## Fourth step: Link the domain name! 🌐

Believe it or not, this is the easiest step in this guide. After claiming your preferred domain name from [namecheap](https://www.namecheap.com/) or any other provider that gives free domains to students, all you need to do is add these records in your DNS settings.

![DNS Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ujguyaeoml2yt19kcwr.png)

Congratulations! Now instead of typing the IP in the address bar, you can type your new domain name instead 💫

---

## Final step: Enabling HTTPS

This article right [here](https://dev.to/roeeyn/how-to-setup-your-ctfd-platform-with-https-and-ssl-3fda) contains a well-explained guide on how to generate a SSL certificate and configure it with your domain name and server. By the end of it you'll have a nice shiny green lock 🔒 next to your domain name.

**_And that's how you host your own CTF for free! 💸_**

---

**Author:** Jihed Kdiss • **My portfolio:** [jihedkdiss.me](https://jihedkdiss.me)
_Feel free to contact me in case you run into some trouble._