learntocloud / learntocloud/linux-ctfs
Generate cryptographically unique, less predictable flags per lab
Open
Nobody has claimed this yet.
enhancement
python
question
- Dominant language
- Python
- Stars
- 284
- Forks
- 379
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Goal
Make every lab instance use flags that are effectively unique and harder to predict, while keeping the learner-facing CTF{...} format.
Current observations
setup/flags.pyuses one randomsecrets.token_hex(4)suffix for most challenge flags. That is 32 bits of randomness shared across challenges.- Challenge 12 currently uses only the first 4 hex characters, which is 16 bits of randomness.
- Flag bases such as
hidden_files,file_search, andlog_analysisreveal the challenge identity. MASTER_SECRETis hard-coded in the repo and is used for completion-token signing throughderive_verification_secret.
Proposed direction
Use a per-instance random secret and derive each challenge flag with HMAC-SHA256 or another standard keyed derivation. For example, derive each flag from instance_secret, challenge number, and purpose string, then encode a sufficiently long prefix into CTF{...}. This gives each challenge its own value and avoids a shared suffix pattern.
Questions to answer
- Should flags include challenge numbers for supportability, for example
CTF{01_<random>}, or should they contain no challenge hint at all? - What entropy target should each flag have? A practical target could be at least 96 or 128 bits per flag.
- Should the completion-token signing secret be generated per lab instead of derived from a hard-coded repository constant?
- How should test tooling retrieve expected answers without reintroducing predictable flags?
Acceptance criteria
- Every non-example challenge flag has independent cryptographic randomness.
- No challenge uses a very short suffix such as 16 bits.
- Flag values no longer expose challenge names unless we intentionally keep a small challenge number prefix.
- Verify still stores only hashes for flag checking.
- Completion-token signing does not rely on a repository hard-coded production secret.
- The ctf-testing suite still solves flags from the VM artifacts, not from checked-in answer strings.
Links
- HMAC background and secret handling guidance: https://blog.gitguardian.com/hmac-secrets-explained-authentication
- OWASP Juice Shop CTF mode notes using generated flag codes: https://pwning.owasp-juice.shop/companion-guide/latest/part4/ctf.html
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.