Skip to content
Snippets Groups Projects
Commit 66abfa1f authored by Ruben Anthony Gonzalez's avatar Ruben Anthony Gonzalez
Browse files

minor refactoring

parent e424f575
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
These are ctf dependent functions.
They have to be aligned.
"""
from random import randint
MESSAGES = [
......@@ -11,9 +12,6 @@ MESSAGES = [
"ERROR"
]
RES_FILE_PATH = "results.txt"
RES_FILE = None
# TODO: Change these values
# list of team ids
......@@ -22,10 +20,15 @@ all_teams = [i for i in range(16)]
flag_regex = b"flag{[A-Za-z0-9_.]+}"
exploit_dir = "exploits"
wait_between_runs = 30
wait_between_runs = 10
# Number of exploit workers
proc_num = 4
res_file_path = "results.txt"
def submission_logic(flag):
# TODO: Add actual submission logic
return randint(0, len(MESSAGES) - 1)
def team_id_to_ip(team_id):
"""
......@@ -34,22 +37,3 @@ def team_id_to_ip(team_id):
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]
......@@ -5,8 +5,8 @@ import changeme
import time
from runner import runner
from submitter import do_submissions
from changeme import submit_flag, all_teams
from submitter import do_submissions, submit_flag
from changeme import all_teams
REMAINING_FILE = "remaining_flags.json"
EXPLOIT_DIR = changeme.exploit_dir
......
import changeme
import logging as log
RES_FILE_PATH = changeme.res_file_path
RES_FILE = None
def submit_flag(team_id, flag):
"""
Submit individual flag.
"""
global RES_FILE
if RES_FILE is None:
RES_FILE = open(RES_FILE_PATH, "a")
return_val = changeme.submission_logic(flag)
RES_FILE.write("{} {} {}\n".format(return_val, team_id, flag))
RES_FILE.flush() # dirty but works for now
return changeme.MESSAGES[return_val]
def do_submissions(flag_queue):
while True:
answer = flag_queue.get()
flag = answer['flag']
team_id = answer['team_id']
result = changeme.submit_flag(team_id, flag)
result = submit_flag(team_id, flag)
log.info("[SUBMITTER] Flag submission %s [team %d] returned %s", flag, team_id, result)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment