From 79934ad55b5a4e21ca3543c3d509664029b8115c Mon Sep 17 00:00:00 2001 From: Lain Iwakura Date: Fri, 20 Jun 2025 23:34:51 +0300 Subject: [PATCH] fixed decryptor! --- main.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index f1b0119..d1240d7 100644 --- a/main.py +++ b/main.py @@ -70,8 +70,10 @@ class Client: self.client_private_key = PrivateKey.generate() self.client_public_key = self.client_private_key.public_key + # Pre-compute the Box for encryption/decryption + self.box = Box(self.client_private_key, self.server_public_key) + # Will be populated after the handshake - self.shared_secret = None self.session_key = None self.client_nonce = None # RNonce on server self.server_nonce = None # SNonce on server @@ -124,8 +126,8 @@ class Client: # The client computes the shared secret 's' *before* sending the message. # This will be used to decrypt the server's response. - self.shared_secret = Box.beforenm(self.server_public_key, self.client_private_key) - print(f"[+] Calculated Shared Secret (s): {self.shared_secret.hex()}") + # self.shared_secret = Box.beforenm(self.server_public_key, self.client_private_key) + # print(f"[+] Calculated Shared Secret (s): {self.shared_secret.hex()}") # The client must generate a nonce (called RNonce on the server) # and include it inside the encrypted part of the login message. @@ -136,7 +138,7 @@ class Client: login_data_bs = ByteStream() login_data_bs.write_int(0) # Account ID High (0 for new account) login_data_bs.write_int(0) # Account ID Low (0 for new account) - login_data_bs.write_string(None) # Pass Token + login_data_bs.write_string("") # Pass Token (empty string is more correct than None) login_data_bs.write_int(53) # Client Major login_data_bs.write_int(135) # Client Minor login_data_bs.write_int(0) # Client Build @@ -155,7 +157,7 @@ class Client: login_nonce = blake2b(self.client_public_key.encode() + self.server_public_key.encode(), encoder=nacl.encoding.RawEncoder)[:24] # Encrypt the payload containing RNonce and login data. - encrypted_login_payload = Box(self.client_private_key, self.server_public_key).encrypt(payload_to_encrypt_bs.get_bytes(), login_nonce) + encrypted_login_payload = self.box.encrypt(payload_to_encrypt_bs.get_bytes(), login_nonce) # The final packet payload is the client's raw public key + the encrypted data. final_login_payload = self.client_public_key.encode() + encrypted_login_payload @@ -172,7 +174,7 @@ class Client: server_response_nonce = blake2b(self.client_nonce + self.client_public_key.encode() + self.server_public_key.encode(), encoder=nacl.encoding.RawEncoder)[:24] # We decrypt the server's response using our pre-calculated shared secret 's'. - decrypted_payload = Box.open_afternm(payload, server_response_nonce, self.shared_secret) + decrypted_payload = self.box.decrypt(payload, server_response_nonce) # The decrypted payload of ServerHello contains the server's nonce (SNonce) # and the final symmetric session key. @@ -213,8 +215,8 @@ class Client: if __name__ == '__main__': # IMPORTANT: Replace with the actual server IP and Port - SERVER_IP = "127.0.0.1" - SERVER_PORT = 9339 + SERVER_IP = "195.58.39.44" + SERVER_PORT = 1337 client = Client(SERVER_IP, SERVER_PORT) try: @@ -225,4 +227,4 @@ if __name__ == '__main__': finally: if client.socket: client.socket.close() - print("\n[*] Connection closed.") \ No newline at end of file + print("\n[*] Connection closed.")