GZCTF comes with built-in support for dynamic flag distribution, which will be injected using the GZCTF_FLAG
environment variable when the container is started.
The main reason for using this environment variable is to prevent commercial abuse of GZCTF, so customizing this feature will not be available in the short term.
In dynamic challenge's flag and attachment management page, the flag template will be used to generate dynamic flag with the following rules:
GUID
as the flag[GUID]
placeholder is specified, only this placeholder will be replaced with a random GUID.[TEAM_HASH]
placeholder is specified, it will be replaced with the hash value generated from the team token and related information.[TEAM_HASH]
placeholder is not specified, Leet string functionality will be enabled, and the string inside the curly braces will be transformed based on the template. Make sure that the entropy of the flag template string is high enough.[TEAM_HASH]
, add the [LEET]
marker before the flag template string. In this case, the entropy of the flag template string will not be checked.[CLEET]
marker before the flag template string.flag{1bab71b8-117f-4dea-a047-340b72101d7b}
MyCTF{[GUID]}
can get MyCTF{1bab71b8-117f-4dea-a047-340b72101d7b}
flag{hello world}
will generate flag with Leet and get flag{He1lo_w0r1d}
[CLEET]flag{hello sara}
will generate flag with special characters like flag{He1!o_$@rA}
flag{hello_world_[TEAM_HASH]}
will generate flag with team hash like flag{hello_world_5418ce4d815c}
[LEET]flag{hello world [TEAM_HASH]}
can generate flag{He1lo_w0r1d_5418ce4d815c}
Leet String is a method of replacing characters in a string with numbers or symbols. For example, replacing a
with 4
, e
with 3
, and so on. GZCTF follows the following Leet String rules:
When enabling complex Leet strings, please pay attention to character injection issues. It follows the rules below, as there are more possibilities, the length required to reach the specified entropy will be shorter:
The security level of Leet String depends on the entropy of the flag template string. For each character in the flag template, it can be replaced with multiple characters. We calculate the entropy of the Leet String by taking the logarithm base 2 of the length of the variable character set for each variable character and summing them up.
In GZCTF, this metric is restricted to be no less than 32, otherwise it will result in a decrease in the security of the flag.
Team hash is a method of hashing the team token with related information. It will be used for generating dynamic flags to ensure that each team has a unique flag.
In GZCTF, the team hash is the middle 12 characters of the SHA256 hash, for example 5418ce4d815c
. It will be used to replace the [TEAM_HASH]
placeholder in the flag template.
The calculation of the team hash involves three parameters:
The Python code for generating the Team Hash is as follows:
The game hash salt game_salt
can be obtained by accessing the /api/edit/games/{id}/hashsalt
endpoint with administrator privileges. If you need to use it, please ensure its confidentiality.
One main use case of team hash is for external challenges (challenges where the final container accessed by the players which is not instanced by GZCTF). For example, in cases where deploying and managing complicate web challenges is difficult and complex, there might be only one external instance of the challenge instead of a separate instance for each team. In this case, we can verify the team token and generate a dynamic flag based on the team token, ensuring that each team has a unique dynamic flag.
The competition public key can be obtained directly from the competition management page. It is an ed25519 public key encoded in Base64, for example:
The team token is an ed25519 signature encoded in Base64. Its format is:
You can use the following code to verify the team token, where base64
and nacl
are Python libraries:
PyNaCl is a Python wrapper for libsodium, which is likely pre-installed on common systems.
For more details, refer to: PyNaCl.
You can also use any other language's ed25519 signature verification library to verify if the team token is a valid signature issued by the platform and provide cryptographic assurance for the security of flag distribution.