|
| 1 | +# Challenge Import |
| 2 | + |
| 3 | +You can import challenges into your CTF platform directly by using the challenge import tool. |
| 4 | + |
| 5 | +## Format |
| 6 | + |
| 7 | +The tool should be run from the root directory of all challenges. Each subdirectory of that directory will be considered a challenge, so if you want some extra files that are not considered to be part of a challenge, put a `.` before the name to hide the directory. The directory name is used as a **unique identifier** for this challenge, and will be stored in the database. |
| 8 | + |
| 9 | +**Note:** on subsequent runs of the import tool, if a challenge exists in the database with the same name as the challenge directory, any scores for that challenge will not be wiped; instead, the problem data will simply be overwritten. If you'd like to wipe the scores as well, you must manually delete them. |
| 10 | + |
| 11 | +Each directory *must* have a `problem.toml` that contains metadata about the problem. This must contain a minimum of these fields: |
| 12 | + |
| 13 | +* `title: str` - The title of your challenge. |
| 14 | +* `description: str | description_file: path` - Specifying either of these provides a description. `description_file` will read the description from the file. |
| 15 | +* `grader: path` - The path to the grader file. |
| 16 | + |
| 17 | +As an example, a full configuration for an automatically generated Caesar cipher challenge is provided here: |
| 18 | + |
| 19 | +```toml |
| 20 | +title: "Caesar cipher" |
| 21 | +description: """ |
| 22 | +""" |
| 23 | +grader: "grader.py" |
| 24 | +``` |
| 25 | + |
| 26 | +## Grader |
| 27 | + |
| 28 | +The grader is an executable which receives information about the submission and must return information about the correctness of the submission. It will receive the problem nonce and team ID through command-line arguments, and then the user's flag submission through standard input. It should print some feedback about the submission to standard output, and then exit with 1 (incorrect), or 0 (correct) to indicate whether the submission was correct or not. |
| 29 | + |
| 30 | +**Note:** The grader file must be an *executable*. If you wish to use a scripting language such as Python or Perl, make sure you add the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)) (`#!`) line at the top of the file to indicate the means by which to run this file. |
| 31 | + |
| 32 | +As an example, the grader for a basic string flag is provided here: |
| 33 | + |
| 34 | +```py |
| 35 | +#!/usr/bin/env python3 |
| 36 | +import sys |
| 37 | +user_flag = input().strip() |
| 38 | +if user_flag != "flag{congratulations}": |
| 39 | + print("Incorrect.") |
| 40 | + sys.exit(1) |
| 41 | +print("Correct.") |
| 42 | +# automatically exits with status 0 |
| 43 | +``` |
| 44 | + |
| 45 | +Also, the grader for an automatically generated Caesar cipher challenge is provided here: |
| 46 | + |
| 47 | +```py |
| 48 | +#!/usr/bin/env python3 |
| 49 | +import sys |
| 50 | +import random |
| 51 | + |
| 52 | +# for brevity, we'll just assume that these arguments exist without checking |
| 53 | +nonce = sys.argv[1] |
| 54 | +tid = sys.argv[2] |
| 55 | + |
| 56 | +# seed the random generator |
| 57 | +rng = random.SystemRandom("{}_{}".format(nonce, tid)) |
| 58 | +actual_flag = "flag{congratulations_%s}" % rng.token_hex(6) |
| 59 | + |
| 60 | +# check correctness |
| 61 | +user_flag = input().strip() |
| 62 | +if user_flag != actual_flag: |
| 63 | + print("Incorrect.") |
| 64 | + sys.exit(1) |
| 65 | +print("Correct.") |
| 66 | +# automatically exits with status 0 |
| 67 | +``` |
| 68 | + |
| 69 | +## Problem build dependencies |
| 70 | + |
| 71 | +Sometimes, there may be extra steps you'd like to take before you import the challenges, such as building binaries or generating files. Perhaps you are storing all of your challenges in a code repository and don't want to commit build artifacts. In order to cater to this need, OpenCTF will check for the existence of a `Makefile` in the challenge directory and run it before anything else happens. |
| 72 | + |
| 73 | +Make sure that wherever you're running this import tool, you also have all the dependencies required to run the Makefiles. Don't put anything user- or team-specific in these Makefiles, since they are only run *once* during import. If you'd like to generate files that are specific to a user or team, set the challenge to `autogen` in `problem.toml`. |
0 commit comments