Skip to content

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 needs

The 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:

YAML
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.py

Put 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:

YAML
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: http

Ports 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:

YAML
# 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 ​

  1. Write the challenge in challs/<id>.
  2. Check it with ctfgarden lint, and run it locally with ctfgarden compose up --build (see developing locally).
  3. Push it to the repository. An admin syncs the repository, and the challenge is live from its release_time on. Authors and admins can see and test challenges before that.

Reference ​

Imprint