Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ctfcli/utils/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import yaml

from .config import generate_session
from .tools import strings


class Yaml(dict):
Expand Down Expand Up @@ -387,4 +388,19 @@ def lint_challenge(path):
if errored:
exit(1)

# Check that files don't have a flag in them
files = challenge.get("files", [])
errored = False
for f in files:
fpath = Path(path).parent / f
for s in strings(fpath):
# TODO make flag format customizable
if "flag" in s:
print(
f"Potential flag {s} found in distributed file {fpath.absolute()}"
)
errored = True
if errored:
exit(1)

exit(0)
19 changes: 19 additions & 0 deletions ctfcli/utils/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import string


def strings(filename, min=4):
"""
Python implementation of strings
https://stackoverflow.com/a/17197027
"""
with open(filename, errors="ignore") as f:
result = ""
for c in f.read():
if c in string.printable:
result += c
continue
if len(result) >= min:
yield result
result = ""
if len(result) >= min: # catch result at EOF
yield result