Beispiel #1
0
def fetch(team, issue_no, config, token=None):
    repo_owner = config['repo_owner']
    repo_name = config['teams'][team]['repo_name']
    github = Github(config["player"], token)

    _, submitter, create_time, content = \
        get_github_issue(repo_owner, repo_name, issue_no, github)

    # Write the fetched issue content to temp file
    tmpfile = "/tmp/gitctf_%s.issue" % random_string(6)
    with open(tmpfile, "w") as f:
        f.write(content)

    # Decrypt the exploit
    out_dir = "exploit-%s-%s" % (submitter, create_time)
    prompt_rmdir_warning(out_dir)
    rmdir(out_dir)
    mkdir(out_dir)
    team = config["player_team"]
    out_dir = decrypt_exploit(tmpfile, config, team, out_dir, submitter)
    if out_dir is not None:
        print "Exploit fetched into %s" % out_dir

    # Clean up
    rmfile(tmpfile)
Beispiel #2
0
def clone(repo_owner, repo_name, prompt=False, target_dir=None):
    target = repo_name if target_dir is None else target_dir
    if prompt:
        prompt_rmdir_warning(target)
    rmdir(target)
    url = '[email protected]:%s/%s' % (repo_owner, repo_name)
    _, err, r = run_command("git clone %s %s" % (url, target), os.getcwd())
    if r!= 0:
        print '[*] Failed to clone: "%s"' % url
        print err
        sys.exit()
Beispiel #3
0
def local_setup(repo_owner, scoreboard_name, problems):
    print '[*] Start local setup'
    # Create root directory for CTF env.
    prompt_rmdir_warning(repo_owner)
    rmdir(repo_owner)
    mkdir(repo_owner)

    # Setup local scoreboard repo
    scoreboard_dir_path = os.path.join(repo_owner, scoreboard_name)
    if create_local_repo(scoreboard_dir_path):
        open(os.path.join(scoreboard_dir_path, 'score.csv'), 'w').close()

    # Setup local problems repo
    for problem in problems:
        problem_info = problems[problem]
        repo_dir_path = os.path.join(repo_owner, \
                problem_info['repo_name'])
        if create_local_repo(repo_dir_path):
            print '[*] Copy binary'
            copy(problem_info['bin_src_path'], repo_dir_path)
            print '[*] Create flag file'
            create_flag(repo_dir_path)
            print '[*] Make Dockerfile'
            create_dockerfile(problem_info, repo_dir_path)
Beispiel #4
0
def create_or_empty_folder(folder):
    if os.path.isdir(folder):
        prompt_rmdir_warning(folder)
        rmdir(folder)

    mkdir(folder)