Writing challenges
A challenge is a directory in challs/ of the CTF repository, with a docker-compose.yml in it. If you've used Docker Compose before, you already know most of the format: the platform reads the same file, and adds an x-ctf-metadata block with the challenge's name, description and flag.
challs/
my-challenge/ # the directory name is the challenge ID
docker-compose.yml # or docker-compose.yml.plf, see templates
... # everything else your challenge needsThe challenge ID may only contain lowercase letters, digits, - and _.
The simplest challenge: no instance
Many challenges don't need a server: a crypto challenge with a file to download, a forensics image, a reversing binary. Leave out services, and players only get the description and the attachments:
x-ctf-metadata:
name: Baby RSA
authors: [Alice]
description_md: |
We encrypted the flag, but our key generation might be a bit off.
difficulty: easy
categories: [crypto]
flag: ctf{small_primes_are_bad}
attachments:
- output.txt
- chall.pyPut output.txt and chall.py next to the compose file. That's the whole challenge.
A challenge with an instance
Add services, and every team gets its own instance of them, started when they click "Start" in the frontend and stopped automatically after a while:
x-ctf-metadata:
name: Login Bypass
authors: [Alice]
description_md: Can you log in as admin?
difficulty: medium
categories: [web]
flag: ctf{sql_injection}
services:
web:
build: . # built by the platform from the Dockerfile in this directory
environment:
FLAG: ctf{sql_injection}
ports:
- target: 8080
app_protocol: httpPorts are exposed over TLS, each instance under its own domain: with app_protocol: http, players get a link to their instance, otherwise a ncat --ssl command to connect to it. app_protocol: ssh gives them SSH access through the SSH gateway.
Most of Docker Compose works, but not everything: see Compose support. ctfgarden lint tells you when you use something the platform doesn't support.
Per-team flags and templates
With a fixed flag, a team that solved the challenge can give the flag to another team. Give every team its own flag instead:
# docker-compose.yml.plf
x-ctf-metadata:
# ...
actor_flag: "ctf{sql_injection_{token}}"
services:
web:
build: .
environment:
FLAG: "{{ flag() }}"The .plf extension makes the file a template: {{ flag() }} is replaced with the team's flag before the instance starts. If a team submits another team's flag, the platform rejects it and reports it as flag sharing. See flags for all options.
Templates work for every file, not just the compose file: data/config.json.plf becomes data/config.json for the instance.
Workflow
- Write the challenge in
challs/<id>. - Check it with
ctfgarden lint, and run it locally withctfgarden compose up --build(see developing locally). - Push it to the repository. An admin syncs the repository, and the challenge is live from its
release_timeon. Authors and admins can see and test challenges before that.
Reference
- Metadata and flags: everything in
x-ctf-metadata - Compose support: which Compose features work, volumes and the data directory, network policies
- Exposing services: HTTP, TCP and SSH
- Templates:
.plffiles,flag(),canary()and JS extensions - Handouts and attachments
- Virtual machines
- Developing locally: the
ctfgardenCLI and thectfgarden-lintNode.js package