Exemplo n.º 1
0
def submit_flags(flags, config):
    flags_list = []
    for item in flags:
        flags_list.append(item.flag)

    flags_dict = {'flags': flags_list}

    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Basic T21hdmlhdDpyQzNrYk5iRFYzUTg='
    }

    r = requests.post('https://scoreboard.ctf.cinsects.de/ctf/submit_flag/',
                      headers=headers,
                      json=flags_dict)

    unknown_responses = set()
    json_answer = json.loads(r.text)

    for item in json_answer:
        for in_item in json_answer[item]:
            response = item
            for status, substrings in RESPONSES.items():
                if any(s in response for s in substrings):
                    found_status = status
                    break
            else:
                found_status = FlagStatus.QUEUED
                if response not in unknown_responses:
                    unknown_responses.add(response)
                    app.logger.warning(
                        'Unknown checksystem response (flag will be resent): %s',
                        response)
            yield SubmitResult(in_item, found_status, response)
Exemplo n.º 2
0
def submit_flags(flags, config):
    sock = socket.create_connection(
        (config["SYSTEM_HOST"], config["SYSTEM_PORT"]), READ_TIMEOUT
    )

    unknown_responses = set()
    for item in flags:
        sock.sendall(item.flag.encode() + b"\n")
        response = recvall(sock).decode().strip()
        response_lower = response.upper()
        for status, substrings in RESPONSES.items():
            if any(s in response_lower for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED
            if response not in unknown_responses:
                unknown_responses.add(response)
                app.logger.warning(
                    "Unknown checksystem response (flag will be resent): %s", response
                )

        yield SubmitResult(item.flag, found_status, response)

    sock.close()
Exemplo n.º 3
0
def submit_flags(flags, config):
    r = requests.put(config['SYSTEM_URL'],
                     headers={'X-Team-Token': config['SYSTEM_TOKEN']},
                     json=[item.flag for item in flags],
                     timeout=TIMEOUT)

    unknown_responses = set()
    for item in r.json():
        response = item['msg'].strip()
        response = response.replace('[{}] '.format(item['flag']), '')

        response_lower = response.lower()
        for status, substrings in RESPONSES.items():
            if any(s in response_lower for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED
            if response not in unknown_responses:
                unknown_responses.add(response)
                app.logger.warning(
                    'Unknown checksystem response (flag will be resent): %s',
                    response)

        yield SubmitResult(item['flag'], found_status, response)
Exemplo n.º 4
0
def submit_flags(flags, config):
    sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
                                    READ_TIMEOUT)

    greeting = recvall(sock)
    if b'Flag submission server' not in greeting:
        raise Exception('Flagserver does not greet us: {}'.format(greeting))

    unknown_responses = set()
    for item in flags:
        sock.sendall(item.flag.encode() + b'\n')
        response = recvall(sock).decode().strip()
        response_lower = response.lower()
        for status, substrings in RESPONSES.items():
            if any(s in response_lower for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED
            if response not in unknown_responses:
                unknown_responses.add(response)
                app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)

        yield SubmitResult(item.flag, found_status, response)

    sock.close()
Exemplo n.º 5
0
def submit_flags(flags, config):
    module = importlib.import_module('server.protocols.' + config['SYSTEM_PROTOCOL'])

    try:
        return list(module.submit_flags(flags, config))
    except Exception as e:
        message = '{}: {}'.format(type(e).__name__, str(e))
        app.logger.error('Exception on submitting flags: %s', message)
        return [SubmitResult(item.flag, FlagStatus.QUEUED, message) for item in flags]
Exemplo n.º 6
0
def submit_flags(flags, config):
    h = Helper(config['SYSTEM_HOST'])
    codes = h.attack(*[item.flag for item in flags])

    for item, code in zip(flags, codes):
        for status, possible_codes in RESPONSES.items():
            if code in possible_codes:
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED

        yield SubmitResult(item.flag, found_status, code.name)
Exemplo n.º 7
0
def submit_flags(flags, config):
    codes = send_flags(flags, config)

    unknown_responses = set()
    for item in codes:
        found_status = None
        try:
            found_status = RESPONSES[item[1]]
        except KeyError:
            unknown_responses.add(item[1])
            found_status = FlagStatus.QUEUED
            unknown_responses.add(item[1])
            app.logger.warning('Unknown checksystem response: %s - %s',
                               item[1], item[2])
        yield SubmitResult(item[0], found_status, item[1])
Exemplo n.º 8
0
def submit_flags(flags, config):

    flags_to_send = [item.flag for item in flags]
    resps = requests.put(f"http://{config['SYSTEM_HOST']}/unict/flagsrv",
                         headers={"X-Team-Token": "unict"},
                         json=flags_to_send)
    resps = resps.json()
    for result in resps:
        app.logger.warning(result)
        for status, substrings in RESPONSES.items():
            if any(s in result["msg"] for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED

        yield SubmitResult(result["flag"], found_status, result["msg"])
Exemplo n.º 9
0
def submit_flags(flags, config):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        sock.connect((config['SYSTEM_HOST'], config['SYSTEM_PORT']))
        for item in flags:
            sock.send(item.flag.encode())
            response = sock.recv(4096).decode(errors="ignore").lower()

            for status, substrings in RESPONSES.items():
                if any(s in response for s in substrings):
                    found_status = status
                    break
            else:
                found_status = FlagStatus.QUEUED
                app.logger.warning(
                    'Unknown checksystem response (flag will be resent): %s',
                    response)

            yield SubmitResult(item.flag, found_status, response)
Exemplo n.º 10
0
def submit_flags(flags, config):
    sock = socket.create_connection((config['SYSTEM_HOST'], config['SYSTEM_PORT']),
                                    READ_TIMEOUT)

    greeting = recvall(sock)
    # print('ENABLE_TOKEN_SUBMIT:', config['ENABLE_TOKEN_SUBMIT'])
    if config['ENABLE_TOKEN_SUBMIT']:
        if config['TOKEN_SUBMIT_MESSAGE'] not in greeting.decode():
            raise Exception('Tokensystem does not greet us: {}'.format(greeting))

        # print('TOKEN_SUBMIT:', config["TOKEN_SUBMIT"])
        sendall(sock, config["TOKEN_SUBMIT"])

    greeting = recvall(sock)
    if config['ENTER_FLAGS_MESSAGE'] not in greeting.decode():
        raise Exception('Checksystem does not greet us: {}'.format(greeting))

    unknown_responses = set()
    for item in flags:
        #print('item.flag:', item.flag)
        sendall(sock, item.flag)
        response = recvall(sock).decode().strip()
        if response:
            response = response.splitlines()[0]
        response = response.replace('[{}] '.format(item.flag), '')

        response_lower = response.lower()
        for status, substrings in RESPONSES.items():
            if any(s in response_lower for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED
            if response not in unknown_responses:
                unknown_responses.add(response)
                app.logger.warning('Unknown checksystem response (flag will be resent): %s', response)

        yield SubmitResult(item.flag, found_status, response)

    sock.close()
Exemplo n.º 11
0
def submit_flags(flags, config):

    flags_to_send = [item.flag for item in flags]
    # app.logger.warning(flags_to_send)
    resps = requests.put(f"http://{config['SYSTEM_HOST']}/flags",
                         headers={"X-Team-Token": "fe56ef438aa1377c"},
                         json=flags_to_send)
    #app.logger.warning(resps.text)
    resps = resps.json()
    for result in resps:
        app.logger.warning(result)
        for status, substrings in RESPONSES.items():
            if any(s in result["msg"] for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED
            app.logger.warning(
                'Unknown checksystem response (flag will be resent): %s',
                result)

        yield SubmitResult(result["flag"], found_status, result["msg"])
Exemplo n.º 12
0
def submit_flags(flags, config):
    sock = socket.create_connection((192.168.1.255,5671),
                                    READ_TIMEOUT)
    greeting = recvall(sock)
    unknown_responses = set()
    for item in flags:
        sock.sendall(item.flag.encode() + b'\n')
        response = recvall(sock).decode().strip()
        if response:
            response = response.splitlines()[0]
        response = response.replace('[{}] '.format(item.flag), '')

        response_lower = response.lower()
        for status, substrings in RESPONSES.items():
            if any(s in response_lower for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED

        yield SubmitResult(item.flag, found_status, response)

    sock.close()
Exemplo n.º 13
0
def submit_flags(flags, config):
    sock = socket.create_connection(
        (config['SYSTEM_HOST'], config['SYSTEM_PORT']), READ_TIMEOUT)

    greeting = recvall(sock)
    if b'Welcome' not in greeting:
        raise Exception('Checksystem does not greet us: {}'.format(greeting))

    sock.sendall(config['TEAM_TOKEN'].encode() + b'\n')
    invite = recvall(sock)
    if b'enter your flags' not in invite:
        raise Exception('Team token seems to be invalid: {}'.format(invite))

    unknown_responses = set()
    for item in flags:
        sock.sendall(item.flag.encode() + b'\n')
        response = recvall(sock).decode().strip()
        if response:
            response = response.splitlines()[0]
        response = response.replace('[{}] '.format(item.flag), '')

        response_lower = response.lower()
        for status, substrings in RESPONSES.items():
            if any(s in response_lower for s in substrings):
                found_status = status
                break
        else:
            found_status = FlagStatus.QUEUED
            if response not in unknown_responses:
                unknown_responses.add(response)
                app.logger.warning(
                    'Unknown checksystem response (flag will be resent): %s',
                    response)

        yield SubmitResult(item.flag, found_status, response)

    sock.close()
Exemplo n.º 14
0
def submit_flags(flags, config):

    for item in flags:
        status = random.choice([FlagStatus.ACCEPTED, FlagStatus.REJECTED])
        yield SubmitResult(item.flag, status, str(status))