def handle(self):
        global email
        global password

        conn = challenge34_shared.Conn(self)

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

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

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

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

        print('S: writing B...')
        conn.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 = conn.readbytes()

        if client_hmac == server_hmac:
            print('S: writing success...')
            conn.writeline(b'OK')
        else:
            conn.writeline(b'NOT OK')
Exemple #2
0
    def handle(self):
        global email
        global password

        conn = challenge34_shared.Conn(self)

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

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

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

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

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

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

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

        print('A:', A)
        print('client_hmac:', base64.b64encode(client_hmac))
    def handle(self):
        conn = challenge34_shared.Conn(self)

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

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

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

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

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

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

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

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

        print('S: reading encrypted message...')
        encrypted_message = conn.readbytes()

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

        message = challenge34_shared.decrypt(key, iv, encrypted_message)
        print('S: message:', message)

        encrypted_message2 = challenge34_shared.encrypt(key, iv, message)
        if encrypted_message2 != encrypted_message:
            raise Exception(encrypted_message2 + b' != ' + encrypted_message)

        print('S: writing encrypted message...')
        conn.writebytes(encrypted_message2)
    def handle(self):
        global targethost
        global targetport
        global targetg

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect((targethost, targetport))
            serverconn = challenge34_shared.Conn(sock)
            clientconn = challenge34_shared.Conn(self)

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

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

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

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

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

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

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

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

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

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

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

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

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

            print('C->A: reading encrypted message...')
            encrypted_message = clientconn.readbytes()

            print('A->S: writing encrypted message...')
            serverconn.writebytes(encrypted_message)

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

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

            print('S->A: reading encrypted message...')
            encrypted_message2 = serverconn.readbytes()

            print('A->C: writing encrypted message...')
            clientconn.writebytes(encrypted_message2)

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

            print('A->C: writing iv...')
            clientconn.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 = challenge34_shared.derivekey(s)
            message = challenge34_shared.decrypt(key, iv, encrypted_message)

            print('A: message: ' + message)

        finally:
            sock.close()
Exemple #5
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))
    conn = challenge34_shared.Conn(sock)

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

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

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

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

    print('C: reading u...')
    u = conn.readnum()
Exemple #6
0
    def handle(self):
        global targethost
        global targetport

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect((targethost, targetport))
            serverconn = challenge34_shared.Conn(sock)
            clientconn = challenge34_shared.Conn(self)

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

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

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

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

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

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

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

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

            print('C->A: reading encrypted message...')
            encrypted_message = clientconn.readbytes()

            print('A->S: writing encrypted message...')
            serverconn.writebytes(encrypted_message)

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

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

            print('S->A: reading encrypted message...')
            encrypted_message2 = serverconn.readbytes()

            print('A->C: writing encrypted message...')
            clientconn.writebytes(encrypted_message2)

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

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

            key = challenge34_shared.derivekey(0)
            message = challenge34_shared.decrypt(key, iv, encrypted_message)

            print('A: message: ' + message)

        finally:
            sock.close()