Skip to content

Commit

Permalink
Add checking for leaked flags in distributed files (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdHeat authored Mar 7, 2022
1 parent 5275dcf commit 43be702
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
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

0 comments on commit 43be702

Please sign in to comment.