ManInTheMiddleAmongUs/handler.py

43 lines
1.1 KiB
Python

import binascii
"""
import hashlib
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
IV_SEED = b'IVDERIV'
KEY_1 = bytes([
(x + 0xFF) % 0xFF for x in [31, -102, -128, 60, -103, 38, 10, -117, -105, -50, 2, 116, -83, 57, 39, -76]
])
KEY_2 = bytes([
(x + 0xFF) % 0xFF for x in [63, 24, -15, 98, 114, 7, 68, 24, -12, 109, -111, -105, 66, -96, -2, -55]
])
def get_iv(key):
m = hashlib.sha256()
m.update(IV_SEED)
m.update(key)
m.update(IV_SEED)
return m.digest()[:16]
backend = default_backend()
CIPHER_1 = Cipher(algorithms.AES(KEY_1), modes.CTR(get_iv(KEY_1)), backend=backend)
CIPHER_2 = Cipher(algorithms.AES(KEY_2), modes.CTR(get_iv(KEY_2)), backend=backend)
dec_1 = CIPHER_1.decryptor()
dec_2 = CIPHER_2.decryptor()
"""
def handle(tag: str, data: bytes):
if tag == 'server':
return
print(binascii.hexlify(data).decode())
# print(binascii.hexlify(data[0:2] + dec_1.update(data[2:-3])).decode())
# print(binascii.hexlify(data[0:2] + dec_2.update(data[2:-3])).decode())
print('\n')