feat: add seeded flag generation
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
FLAG_LEN=32
|
FLAG_LEN=32
|
||||||
FLAG_FORMAT=ctf{FLAG_GOES_HERE}
|
FLAG_FORMAT=ctf{FLAG_GOES_HERE}
|
||||||
|
FLAG_SEED=false
|
||||||
ENCRYPTOR_VENDOR_ID=GenuineIntel
|
ENCRYPTOR_VENDOR_ID=GenuineIntel
|
||||||
ENCRYPTOR_MODEL_NAME=Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
|
ENCRYPTOR_MODEL_NAME=Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz
|
||||||
ENCRYPTOR_OS_VERSION=7.0.3-arch1-2
|
ENCRYPTOR_OS_VERSION=7.0.3-arch1-2
|
||||||
|
|||||||
3
Makefile
3
Makefile
@@ -8,6 +8,7 @@ endif
|
|||||||
# Default configuration
|
# Default configuration
|
||||||
FLAG_LEN ?= 32
|
FLAG_LEN ?= 32
|
||||||
FLAG_FORMAT ?= ctf{FLAG_GOES_HERE}
|
FLAG_FORMAT ?= ctf{FLAG_GOES_HERE}
|
||||||
|
FLAG_SEED ?= false
|
||||||
|
|
||||||
# Compilation variables
|
# Compilation variables
|
||||||
RISCV_CC ?= riscv64-unknown-elf-gcc
|
RISCV_CC ?= riscv64-unknown-elf-gcc
|
||||||
@@ -105,7 +106,7 @@ endif
|
|||||||
|
|
||||||
$(GENERATED): .FORCE
|
$(GENERATED): .FORCE
|
||||||
mkdir -p $(dir $@)
|
mkdir -p $(dir $@)
|
||||||
python codegen/generate.py $(FLAG_FORMAT) $(FLAG_LEN) > $@
|
python codegen/generate.py $(FLAG_FORMAT) $(FLAG_LEN) $(FLAG_SEED) > $@
|
||||||
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ The provided `.env.example` file contains a sample configuration.
|
|||||||
|
|
||||||
- `FLAG_LEN`: Number, the length of the flag
|
- `FLAG_LEN`: Number, the length of the flag
|
||||||
- `FLAG_FORMAT`: String, containing the constant `FLAG_GOES_HERE` to be replaced by the flag
|
- `FLAG_FORMAT`: String, containing the constant `FLAG_GOES_HERE` to be replaced by the flag
|
||||||
|
- `FLAG_SEED`: String, the seed used to generate the flag, or `false` if it should be random
|
||||||
- `ENCRYPTOR_VENDOR_ID`: String, overwrite CPU vendor id. Will use system information if unset
|
- `ENCRYPTOR_VENDOR_ID`: String, overwrite CPU vendor id. Will use system information if unset
|
||||||
- `ENCRYPTOR_MODEL_NAME`: String, overwrite CPU model name. Will use system information if unset
|
- `ENCRYPTOR_MODEL_NAME`: String, overwrite CPU model name. Will use system information if unset
|
||||||
- `ENCRYPTOR_OS_VERSION`: String, overwrite OS version. Will use system information if unset
|
- `ENCRYPTOR_OS_VERSION`: String, overwrite OS version. Will use system information if unset
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import random
|
import random
|
||||||
import secrets
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
def generate_flag(length):
|
||||||
|
characters = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
|
||||||
|
return "".join([random.choice(characters) for _ in range(length)])
|
||||||
|
|
||||||
def eprint(*args, **kwargs):
|
def eprint(*args, **kwargs):
|
||||||
print("[Codegen]", *args, file=sys.stderr, **kwargs)
|
print("[Codegen]", *args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
@@ -47,16 +50,22 @@ def get_check_code(flag_part, user_part, c_mangler):
|
|||||||
return random.choice(variations)
|
return random.choice(variations)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3 and len(sys.argv) != 4:
|
||||||
eprint(f"Usage: {sys.argv[0]} <flag_format> <flag_length>")
|
eprint(f"Usage: {sys.argv[0]} <flag_format> <flag_length> [flag_seed]")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Flag prefix is not used, currently the flag is just used as-is
|
# Flag prefix is not used, currently the flag is just used as-is
|
||||||
flag_format = sys.argv[1]
|
flag_format = sys.argv[1]
|
||||||
flag_len = int(sys.argv[2])
|
flag_len = int(sys.argv[2])
|
||||||
|
|
||||||
|
if len(sys.argv) >= 4:
|
||||||
|
# We might have a seed
|
||||||
|
flag_seed = sys.argv[3]
|
||||||
|
if flag_seed.lower() != "false":
|
||||||
|
random.seed(flag_seed)
|
||||||
|
|
||||||
# Generate a secret
|
# Generate a secret
|
||||||
secret = secrets.token_urlsafe(flag_len)
|
secret = generate_flag(flag_len)
|
||||||
secret = flag_format.replace("FLAG_GOES_HERE", secret)
|
secret = flag_format.replace("FLAG_GOES_HERE", secret)
|
||||||
|
|
||||||
eprint(f"Generated Flag: {secret}")
|
eprint(f"Generated Flag: {secret}")
|
||||||
|
|||||||
Reference in New Issue
Block a user