- panel/teams.py: create/start/stop teams with isolated ports+creds, per-team receivers with CHALLENGE_PORT/CONTAINER env, flag randomization, submit validation + leaderboard
- panel/main.py: /api/teams, /api/teams/{idx}/randomize, /api/flag/submit, /api/leaderboard, /api/public/teams, /submit page
- panel/static/submit.html: public flag submission UI for teams
- receiver: _ch_port/_ch_container read .env per team, container name overrides
- .gitignore: exclude teams/, .venv, __pycache__
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from .Challenge import Challenge
|
|
|
|
import os
|
|
import io
|
|
import requests
|
|
import random
|
|
import subprocess
|
|
|
|
class Warmup(Challenge):
|
|
flag_location = 'flags/warmup.txt'
|
|
history_location = 'history/warmup.txt'
|
|
|
|
def distribute(self, flag):
|
|
try:
|
|
with open(self.flag_location, 'w') as f:
|
|
f.write(flag)
|
|
with open(self.history_location, 'a') as f:
|
|
f.write(flag + '\n')
|
|
self.logger.info(f'Flag {flag} written to {self.flag_location}')
|
|
return True
|
|
except Exception as e:
|
|
self.logger.error(f'Could not write flag to {self.flag_location}: {e}')
|
|
return False
|
|
|
|
def check(self):
|
|
try:
|
|
url = f'http://localhost:{self.port}/'
|
|
r = requests.get(url, timeout=5)
|
|
assert "Simple file viewing application" in r.text, 'Warmup app not available'
|
|
|
|
with open(self.flag_location, 'r') as f:
|
|
host_flag = f.read().strip()
|
|
container_flag = subprocess.run([
|
|
"docker", "exec", os.environ.get("CHALLENGE_CONTAINER_WARMUP", "warmup_container"), "cat", "/flag.txt"
|
|
], capture_output=True, text=True).stdout.strip()
|
|
assert host_flag == container_flag, 'Flag mismatch between host and container'
|
|
|
|
self.logger.info('Check passed for warmup')
|
|
return True
|
|
except Exception as e:
|
|
self.logger.error(f'Could not check warmup: {e}')
|
|
return False |