def handle(self):
        global email
        global password

        util = challenge34_util.Util(self)

        print('S: reading email...')
        readEmail = util.readline()

        print('S: reading A...')
        A = util.readnum()

        print('S: writing salt...')
        util.writenum(salt)

        print('S: writing B...')
        util.writenum(B)

        print('S: writing u...')
        util.writenum(u)

        print('S: reading hmac...')
        client_hmac = util.readbytes()

        print('S: writing success...')
        util.writeline(b'OK')

        print('A:', A)
        print('client_hmac:', base64.b64encode(client_hmac))
示例#2
0
    def handle(self):
        global email
        global password

        util = challenge34_util.Util(self)

        print('S: reading email...')
        readEmail = util.readline()

        print('S: reading A...')
        A = util.readnum()

        print('S: writing salt...')
        util.writenum(salt)

        b = random.randint(0, N)
        B = (pow(g, b, N) + k * v) % N

        print('S: writing B...')
        util.writenum(B)

        u = challenge36_util.hashToInt(str(A) + str(B))

        S = pow(pow(v, u, N) * A, b, N)
        K = challenge36_util.hashToBytes(str(S))
        server_hmac = challenge36_util.hmac(salt, K)

        print('S: reading hmac...')
        client_hmac = util.readbytes()

        if client_hmac == server_hmac:
            print('S: writing success...')
            util.writeline(b'OK')
        else:
            util.writeline(b'NOT OK')
示例#3
0
    def handle(self):
        util = challenge34_util.Util(self)

        print('S: reading p...')
        p = util.readnum()

        print('S: reading g...')
        g = util.readnum()

        print('S: writing p...')
        util.writenum(p)

        print('S: writing g...')
        util.writenum(g)

        print('S: reading A...')
        A = util.readnum()

        b = random.randint(0, p)
        B = pow(g, b, p)

        print('S: writing B...')
        util.writenum(B)

        s = pow(A, b, p)
        key = util.derivekey(s)

        print('S: reading encrypted message...')
        encryptedMessage = util.readbytes()

        print('S: reading iv...')
        iv = util.readbytes()

        message = util.decrypt(key, iv, encryptedMessage)
        print('S: message:', message)

        encryptedMessage2 = util.encrypt(key, iv, message)
        if encryptedMessage2 != encryptedMessage:
            raise Exception(encryptedMessage2 + b' != ' + encryptedMessage)

        print('S: writing encrypted message...')
        util.writebytes(encryptedMessage2)
示例#4
0
host = sys.argv[1]
port = int(sys.argv[2])
email = sys.argv[3]
password = sys.argv[4]

N = 0xffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff
g = 2
k = 3

a = random.randint(0, N)
A = pow(g, a, N)

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    sock.connect((host, port))
    util = challenge34_util.Util(sock)

    print('C: writing email...')
    util.writeline(email.encode('ascii'))

    print('C: writing A...')
    util.writenum(A)

    print('C: reading salt...')
    salt = util.readnum()

    print('C: reading B...')
    B = util.readnum()

    print('C: reading u...')
    u = util.readnum()
示例#5
0
    def handle(self):
        global targethost
        global targetport
        global targetg

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect((targethost, targetport))
            serverutil = challenge34_util.Util(sock)
            clientutil = challenge34_util.Util(self)

            print('C->A: reading p...')
            p = clientutil.readnum()

            print('C->A: reading g...')
            g = clientutil.readnum()

            print('A->S: writing p...')
            serverutil.writenum(p)

            if targetg > 0:
                fakeg = 1
            elif targetg < 0:
                fakeg = p - 1
            else:
                fakeg = p

            print('A->S: writing fake g...')
            serverutil.writenum(fakeg)

            print('S->A: reading p...')
            serverutil.readnum()

            print('S->A: reading g...')
            serverutil.readnum()

            print('A->C: writing p...')
            clientutil.writenum(p)

            print('A->C: writing fake g...')
            clientutil.writenum(fakeg)

            print('C->A: reading A...')
            A = clientutil.readnum()

            print('A->S: writing A...')
            serverutil.writenum(A)

            print('S->A: reading B...')
            B = serverutil.readnum()

            print('A->C: writing B...')
            clientutil.writenum(B)

            print('C->A: reading encrypted message...')
            encryptedMessage = clientutil.readbytes()

            print('A->S: writing encrypted message...')
            serverutil.writebytes(encryptedMessage)

            print('C->A: reading iv...')
            iv = clientutil.readbytes()

            print('A->S: writing iv...')
            serverutil.writebytes(iv)

            print('S->A: reading encrypted message...')
            encryptedMessage2 = serverutil.readbytes()

            print('A->C: writing encrypted message...')
            clientutil.writebytes(encryptedMessage2)

            print('S->A: reading iv...')
            iv2 = serverutil.readbytes()

            print('A->C: writing iv...')
            clientutil.writebytes(iv2)

            if targetg > 0:
                s = 1
            elif targetg < 0:
                if A == p - 1 and B == p - 1:
                    s = p - 1
                else:
                    s = 1
            else:
                s = 0
            key = serverutil.derivekey(s)
            message = serverutil.decrypt(key, iv, encryptedMessage)

            print('A: message: ' + message)

        finally:
            sock.close()
    def handle(self):
        global targethost
        global targetport

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect((targethost, targetport))
            serverutil = challenge34_util.Util(sock)
            clientutil = challenge34_util.Util(self)

            print('C->A: reading p...')
            p = clientutil.readnum()

            print('C->A: reading g...')
            g = clientutil.readnum()

            print('C->A: reading A...')
            A = clientutil.readnum()

            print('A->S: writing p...')
            serverutil.writenum(p)

            print('A->S: writing g...')
            serverutil.writenum(g)

            print('A->S: writing p...')
            serverutil.writenum(p)

            print('S->A: reading B...')
            B = serverutil.readnum()

            print('A->C: writing p...')
            clientutil.writenum(p)

            print('C->A: reading encrypted message...')
            encryptedMessage = clientutil.readbytes()

            print('A->S: writing encrypted message...')
            serverutil.writebytes(encryptedMessage)

            print('C->A: reading iv...')
            iv = clientutil.readbytes()

            print('A->S: writing iv...')
            serverutil.writebytes(iv)

            print('S->A: reading encrypted message...')
            encryptedMessage2 = serverutil.readbytes()

            print('A->C: writing encrypted message...')
            clientutil.writebytes(encryptedMessage2)

            print('S->A: reading iv...')
            iv2 = serverutil.readbytes()

            print('A->C: writing iv...')
            clientutil.writebytes(iv2)

            key = serverutil.derivekey(0)
            message = serverutil.decrypt(key, iv, encryptedMessage)

            print('A: message: ' + message)

        finally:
            sock.close()