fixed decryptor!

This commit is contained in:
Lain Iwakura 2025-06-20 23:34:51 +03:00
parent 3143003dfd
commit 79934ad55b
No known key found for this signature in database
GPG Key ID: C7C18257F2ADC6F8

20
main.py
View File

@ -70,8 +70,10 @@ class Client:
self.client_private_key = PrivateKey.generate() self.client_private_key = PrivateKey.generate()
self.client_public_key = self.client_private_key.public_key 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 # Will be populated after the handshake
self.shared_secret = None
self.session_key = None self.session_key = None
self.client_nonce = None # RNonce on server self.client_nonce = None # RNonce on server
self.server_nonce = None # SNonce 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. # The client computes the shared secret 's' *before* sending the message.
# This will be used to decrypt the server's response. # This will be used to decrypt the server's response.
self.shared_secret = Box.beforenm(self.server_public_key, self.client_private_key) # self.shared_secret = Box.beforenm(self.server_public_key, self.client_private_key)
print(f"[+] Calculated Shared Secret (s): {self.shared_secret.hex()}") # print(f"[+] Calculated Shared Secret (s): {self.shared_secret.hex()}")
# The client must generate a nonce (called RNonce on the server) # The client must generate a nonce (called RNonce on the server)
# and include it inside the encrypted part of the login message. # and include it inside the encrypted part of the login message.
@ -136,7 +138,7 @@ class Client:
login_data_bs = ByteStream() 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 High (0 for new account)
login_data_bs.write_int(0) # Account ID Low (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(53) # Client Major
login_data_bs.write_int(135) # Client Minor login_data_bs.write_int(135) # Client Minor
login_data_bs.write_int(0) # Client Build 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] 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. # 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. # 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 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] 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'. # 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) # The decrypted payload of ServerHello contains the server's nonce (SNonce)
# and the final symmetric session key. # and the final symmetric session key.
@ -213,8 +215,8 @@ class Client:
if __name__ == '__main__': if __name__ == '__main__':
# IMPORTANT: Replace with the actual server IP and Port # IMPORTANT: Replace with the actual server IP and Port
SERVER_IP = "127.0.0.1" SERVER_IP = "195.58.39.44"
SERVER_PORT = 9339 SERVER_PORT = 1337
client = Client(SERVER_IP, SERVER_PORT) client = Client(SERVER_IP, SERVER_PORT)
try: try:
@ -225,4 +227,4 @@ if __name__ == '__main__':
finally: finally:
if client.socket: if client.socket:
client.socket.close() client.socket.close()
print("\n[*] Connection closed.") print("\n[*] Connection closed.")