Skip to content
Snippets Groups Projects
changeme.py 1.05 KiB
Newer Older
Ruben Anthony Gonzalez's avatar
Ruben Anthony Gonzalez committed
"""
These are ctf dependent functions.
They have to be aligned.
"""


MESSAGES = [
        "SUCCESS",
        "INVALID",
        "ALREADY_SUBMITTED",
        "ERROR"
]

RES_FILE_PATH = "results.txt"
RES_FILE = None


# TODO: Change these values
# list of team ids
Ruben Anthony Gonzalez's avatar
Ruben Anthony Gonzalez committed
all_teams = [i for i in range(16)]
# Has to be byte string since wre looking through byte output (STDOUT)
flag_regex = b"flag{[A-Za-z0-9_.]+}"

exploit_dir = "exploits"
wait_between_runs = 30
# Number of exploit workers
proc_num = 4
Ruben Anthony Gonzalez's avatar
Ruben Anthony Gonzalez committed


def team_id_to_ip(team_id):
    """
    Somehow map team id to ip adress
    """
    return "10.13.37.{}".format(team_id)


def submit_flag(team_id, flag):
    """
    Submit individual flag.
    """
    global RES_FILE
    if RES_FILE is None:
        RES_FILE = open(RES_FILE_PATH, "a")

    # TODO: submission logic
    # e.g. requests.put(...)
    # set return val to index of appropriate message code
    return_val = 0


    RES_FILE.write("{} {} {}\n".format(return_val, team_id, flag))
    RES_FILE.flush()  # dirty but works for now

    return MESSAGES[return_val]