TExcelTAD
Home › Security Projects, Study Plan, Certifications & Careers › CTFs and Wargames: Formats, Etiquette and the Law

CTFs and Wargames: Formats, Etiquette and the Law

A capture-the-flag (CTF) competition hides a secret string, the flag, behind a puzzle or a vulnerable service, and awards points for submitting it. A wargame is the same idea without the clock: a fixed ladder of levels you climb at your own pace. Both are among the best ways to practise, because every challenge was built to be broken, by people who gave you permission. They are also easy to get wrong: a flag is not a lesson until you can explain the bug and its fix, and the permission only covers what the organisers say it covers. This lesson explains the formats, solves a small challenge end to end with its defensive lesson, shows how platforms check flags, and lists the etiquette and the legal line.

Formats

Format How it works What it trains
Jeopardy a board of challenges by category and points; teams solve them in mostly any order (some unlock only after others), often over 24–48 hours breadth, speed, knowing which category is yours
Attack-defence every team gets the same vulnerable services on a game network; you patch yours and attack the others' to steal flags that rotate every few minutes the full loop: find, exploit, patch, monitor, under time pressure
King of the hill teams compete for control of shared machines, scored by time held persistence and hardening, in a game setting
Wargame a permanent ladder of levels (OverTheWire, pwn.college, Exploit Education) depth, without the clock
Mixed events that combine formats, for example a jeopardy board alongside an attack-defence round whatever the parts train

Attack-defence is the format closest to real work, because half of the score is defensive: a service you don't patch loses flags every round. It is also the only format where attacking other teams is part of the rules, and only on the game network, only against the game's services.

Categories and where the track teaches them

Category Typical challenge Course
web an app with an injection, an access-control flaw or a logic bug Web Application Security
crypto a homemade cipher, a reused nonce, small RSA parameters Applied Cryptography
forensics a pcap, a disk image or a memory dump with something hidden in it Networking, Malware & Forensics
reversing a binary that checks a password; find the password Reverse Engineering
pwn a binary with a memory-safety bug and a flag file next to it Memory Safety
misc / OSINT encodings, scripting, or finding facts in public sources Programming; OSINT only on the CTF's own fictional targets

A warm-up challenge, solved

Here is a typical first crypto challenge: "We XORed the flag with a short repeating key. Flags look like flag{...}." The weakness is that XOR with a known plaintext gives the key back: c⊕p=kc \oplus p = k. The first five bytes of every flag are known.

python · try it yourself
# The challenge as a player sees it: "We XORed the flag with a short repeating key. Flags look like flag{...}."
ciphertext = bytes.fromhex("0a0d030b1a1a03134f05124f020e1641004f0f081204041011")

# Step 1: the known prefix gives the first key bytes (c XOR p = k)
prefix = b"flag{"
key_start = bytes(c ^ p for c, p in zip(ciphertext, prefix))
print("key bytes from the prefix:", key_start)

# Step 2: the key repeats; try each length that fits the bytes we recovered
for n in range(1, len(key_start) + 1):
    key = key_start[:n]
    if all(key_start[i] == key[i % n] for i in range(len(key_start))):
        break
plain = bytes(c ^ key[i % n] for i, c in enumerate(ciphertext))
print(f"key length {n}, key {key!r}")
print("flag:", plain.decode())
key bytes from the prefix: b'labla'
key length 3, key b'lab'
flag: flag{xor-is-not-a-cipher}

The five known bytes give labla, which is a 3-byte key repeating; the rest follows. The defensive lesson is the point: a repeating-key XOR is a one-time pad used many times, and any known or guessable plaintext (file headers, protocol fields, a flag format) breaks it. The detection, in a code review, is any XOR "encryption" with a key shorter than the data; the fix is an authenticated cipher such as AES-GCM or ChaCha20-Poly1305 with a fresh nonce per message (AEAD). A write-up that ends at the flag misses this; one that ends with the fix is a portfolio piece.

How the platform checks your flag

The other side of the challenge is a small piece of secure design. A platform must not keep flags in a file that a web bug could leak, and must not leak them through timing. A common approach is to store a hash of each flag and compare in constant time (real platforms often add a per-challenge secret, and dynamic flags that differ per team so that shared flags can be detected):

python · try it yourself
import hashlib, hmac

# What a CTF platform stores: a hash of each flag, never the flag in a readable file
STORED = {"xor-warmup": hashlib.sha256(b"flag{xor-is-not-a-cipher}").hexdigest()}

def submit(challenge, attempt):
    digest = hashlib.sha256(attempt.strip().encode()).hexdigest()
    return hmac.compare_digest(digest, STORED[challenge])   # constant-time comparison

for attempt in ["flag{xor-is-a-cipher}", "  flag{xor-is-not-a-cipher}\n", "FLAG{xor-is-not-a-cipher}"]:
    print(f"{attempt.strip()!r:32} correct={submit('xor-warmup', attempt)}")
print("stored:", STORED["xor-warmup"][:16] + "...")
'flag{xor-is-a-cipher}'          correct=False
'flag{xor-is-not-a-cipher}'      correct=True
'FLAG{xor-is-not-a-cipher}'      correct=False
stored: bf8ced557279dd86...

Whitespace is stripped, so a pasted flag with a trailing newline still counts; case is not folded, so FLAG{...} is wrong. hmac.compare_digest takes the same time whether the first or the last character differs, so the comparison leaks nothing about how close an attempt was.

Etiquette

  • Read the rules page first. It defines the scope (which hosts, which ports), the flag format, and what is forbidden.
  • Don't attack the infrastructure. The scoreboard, the registration site and the organisers' servers are never targets unless a challenge explicitly says so. Breaking them ruins the event for everyone and is unauthorised access.
  • No flag sharing between teams, and no brute-forcing the flag submission form.
  • No denial of service, against challenges or other teams, unless the format explicitly includes it (it almost never does).
  • Write-ups after the event ends, never during it, and only within the organisers' rules. Credit the authors.
  • Report unintended bugs to the organisers instead of using them to win; many events reward this.

The legal line

A CTF is a permission slip with a very precise scope: these hosts, this time window, these rules. Outside it, everything from the law lessons applies as usual. Three situations people get wrong:

  1. A challenge mentions a real company or website. OSINT challenges sometimes use fictional organisations; if one seems to point to a real organisation's systems, it is out of scope until the organisers confirm otherwise.
  2. The event is over. The permission ends with the event. A challenge server still running the next day is not an invitation.
  3. Practising "the same technique" elsewhere. A trick that worked in a CTF is only legal against your own lab, a platform's assigned targets, or a system whose owner gave written permission.

Pitfalls

  • Only playing your strongest category. Pick one challenge per event from a category you know least.
  • Reading write-ups before trying. Time-box yourself (an hour on a warm-up, a day on a hard one), then read, then solve it again without the write-up.
  • Keeping no notes. A CTF solved without a journal entry will be forgotten by the next event.

Practice

1. A second challenge uses the same scheme with a 4-byte key and the flag format tad{...}. Why is it harder, and what would you try?

The prefix tad{ is only 4 bytes, so it gives the whole 4-byte key with nothing left over to confirm that the key length really is 4. Try key lengths 1 to 4, decrypt with each, and keep the one whose output is printable and ends in }. With a key longer than the known prefix, use statistics instead: the classic repeating-key attack splits the ciphertext into columns and finds each key byte by frequency analysis.

2. Why doesn't the flag checker fold case, and should it?

Flags are secrets with an exact value; folding case would accept strings that are not the flag and halve the work of guessing each letter. It strips surrounding whitespace only because copy and paste adds it. Platforms that accept case-insensitive flags say so in their rules.

Test yourself

In which CTF format is attacking other teams part of the rules?

  1. Jeopardy
  2. Attack-defence, on the game network against the game services
  3. Wargames
  4. None, ever

Why does a known flag prefix break repeating-key XOR?

  1. XOR is slow
  2. c XOR p = k, so known plaintext bytes give the key bytes directly
  3. The flag is too short
  4. Python's XOR is weak

When may you publish a write-up of a CTF challenge?

  1. Whenever you solve it
  2. After the event ends, within the organisers' rules
  3. Never
  4. Only before the event, as a hint

Why does the flag checker use hmac.compare_digest?

  1. It is faster
  2. It compares in constant time, so response timing reveals nothing about partial matches
  3. It hashes the flag
  4. It folds case