Skip to content

Conversation

@madebygps
Copy link
Collaborator

This pull request introduces a dynamic flag generation system for the CTF setup, ensuring that each VM instance receives unique flag values for every challenge. This prevents answer sharing between users and enhances the integrity of the CTF environment. The system generates random flag suffixes at setup time, stores hashes for verification, and updates both the setup script and the documentation accordingly.

Dynamic flag generation and verification:

  • Added logic in ctf_setup.sh to generate unique flags for each challenge per VM instance, using random hex suffixes, and to store their SHA256 hashes for later verification.
  • Updated the flag placement in all challenge setup steps to use dynamically generated flags instead of static values, including writing flags to files, environment variables, and service scripts. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Verification script improvements:

  • Modified the verify script to load flag hashes from a root-owned file (/etc/ctf/flag_hashes) generated at setup time, removing hardcoded hash values and ensuring correct validation for dynamic flags.

Documentation updates:

  • Updated tests/CHALLENGE_REFERENCE.md to describe the new dynamic flag system, removing static flag values and explaining the new flag format and validation process. Challenge references now specify the flag pattern instead of actual flag values.

These changes make the CTF more secure and robust by eliminating static answers and documenting the new process for both maintainers and automated testing.

- Generate unique 8-char hex suffix for flags at setup time
- Store flag hashes in /etc/ctf/flag_hashes (read by verify script)
- Update verify script to load hashes from file instead of hardcoded
- Update test script to capture flags dynamically and verify them
- Services now read flags from /etc/ctf/flag_X files
- Example flag (CTF{example}) remains static for documentation

Benefits:
- Students cannot share answers between VM instances
- Looking at GitHub repo reveals no flag values
- Each deployment has unique flags

Flag format: CTF{descriptive_text_XXXXXXXX}
- Change verify check from UTF-8 ✓ to ASCII 'Correct|verified' for reliable matching
- Add grep -a flag to handle binary log files (challenge 3)
- Use grep -ao for binary file handling in flag capture
- Capture verify output before grepping (more reliable)
- Use ASCII pattern matching (Correct|verified) instead of UTF-8 checkmark
- All 69 tests now pass on Azure
@madebygps madebygps merged commit 2adada0 into main Jan 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants