Пример #1
0
def login():
    print "\033[32mWelcome to the \033[33mHack The Vote 2016 \033[32mSession system\033[0m"
    print "You are requesting a session for 'ballot return'"
    print
    print "Please enter your team password to continue (found in the challenge description):"
    print ">>",
    pw = raw_input()

    try:
        teamid = Signer(SECRET_KEY).unsign(pw)
    except Exception as e:
        print "\033[31mInvalid password!"
        exit()

    username = teamid.replace('/', '')

    # Create user if not exist
    try:
        pwd.getpwnam(username)
        print "\033[32mUser already exists",
    except KeyError:
        if not makeuser(username, pw):
            print "Error creating user. ping @clarkb7"
            exit()
        print "\033[32mYou may now",
    print "\033[33m`ssh ballot{}@ballotreturn.pwn.democrat` \033[32mwith your secret to cast your vote\033[0m".format(
        username)
Пример #2
0
def login():
    print "\033[32mWelcome to the \033[33mHack The Vote 2016 \033[32mVM system\033[0m"
    print "You are requesting a VM for '/dev/vote'"
    print
    print "Please enter your team password to continue (found in the challenge description):"
    print ">>",
    pw = raw_input()

    try:
        teamid = Signer(SECRET_KEY).unsign(pw)
    except Exception as e:
        print "\033[31mInvalid password!"
        exit()

    dirname = os.path.join('vms', teamid.replace('/', ''))

    if not os.path.exists(dirname):
        os.makedirs(dirname)

    vmname = os.path.join('vms', teamid.replace('/', ''), 'vm.qcow2')
    meta = os.path.join('vms', teamid.replace('/', ''), 'meta')

    if not os.path.isfile(vmname):
        copyvm(vmname)
        with open(meta, 'w') as f:
            f.write(str(int(time.time())))

    while True:
        print "\n\033[33mVM Menu:\033[0m"
        print " 1: Boot VM"
        print " 2: Repair VM"
        print " 3: Kill QEMU Instance"
        print ">>",
        pw = raw_input()
        if pw == '1':
            if getsession(vmname) != None:
                print "\033[31mYou already have a session running.\033[0m"
                print "Do you want to kill it? [y/n]",
                if raw_input() != 'y':
                    exit()
                killsession(vmname)
            bootvm(vmname)
            exit()
        elif pw == '2':
            with open(meta, 'r') as f:
                old = int(f.read())
            if time.time() - old < MIN_TIME_COPY:
                print "\033[31mYou copied too recently. Please wait %u seconds" % int(
                    old + MIN_TIME_COPY - time.time())
            else:
                if getsession(vmname) != None:
                    print "\033[31mYou currently have a session running.\033[0m"
                    print "Do you want to kill it? [y/n]",
                    if raw_input() != 'y':
                        exit()
                    killsession(vmname)
                with open(meta, 'w') as f:
                    f.write(str(int(time.time())))
                copyvm(vmname)
        elif pw == '3':
            killsession(vmname)
        else:
            exit()