def run(self): while self.enable: block_size = self.bytes.get() | self.bytes.get() << 8 opcode = self.bytes.get() | self.bytes.get() << 8 block = Bytes() while block.len() < block_size - 4: block.append(self.bytes.get()) self.msg_queue.put( (datetime.utcnow(), self.direction, opcode, block))
def shift_key(key, n, direction=True): size = len(key) result = Bytes([0] * size) for i in xrange(0, size): if direction: result[(i + n) % size] = key[i] else: result[i] = key[(i + n) % size] return result
def __init__(self): self.computed = 0 self.corrupted = 0 self.length_high = 0 self.length_low = 0 self.message_block = Bytes([0] * 64) self.message_block_index = 0 self.message_digest = [ 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 ]
def __init__(self, server_keys, client_keys): self.client_key1 = client_keys[0] self.client_key2 = client_keys[1] self.server_key1 = server_keys[0] self.server_key2 = server_keys[1] self.tmp_key_1 = shift_key(self.server_key1, 67) self.tmp_key_2 = xor_key(self.tmp_key_1, self.client_key1) self.tmp_key_1 = shift_key(self.client_key2, 29, False) self.decrypt_key = xor_key(self.tmp_key_1, self.tmp_key_2) self.decryptor = Cryptor(self.decrypt_key) self.tmp_key_1 = shift_key(self.server_key2, 41) self.decryptor.apply_cryptor(self.tmp_key_1, 128) self.encrypt_key = Bytes([0] * 128) self.encrypt_key[0:128] = self.tmp_key_1[0:128] self.encryptor = Cryptor(self.encrypt_key)
def __init__(self, data): tcp_header = data[0:20] tcph = unpack('!HHLLHHHH', tcp_header) # self.source_port = tcph[0] # self.destination_port = tcph[1] # self.sequence_number = tcph[2] # self.ack_number = tcph[3] self.offset = tcph[4] >> 12 header_length = self.offset * 4 # self.reserved = (tcph[4] >> 9) & 0b111 # self.ns = (tcph[4] >> 8) & 0b1 # self.cwr = (tcph[4] >> 7) & 0b1 # self.ece = (tcph[4] >> 6) & 0b1 # self.urg = (tcph[4] >> 5) & 0b1 # self.ack = (tcph[4] >> 4) & 0b1 # self.psh = (tcph[4] >> 3) & 0b1 # self.rst = (tcph[4] >> 2) & 0b1 # self.syn = (tcph[4] >> 1) & 0b1 # self.fin = tcph[4] & 0b1 # self.window_size = tcph[5] # self.checksum = tcph[6] # self.urg_pointer = tcph[7] # self.options = None self.data = Bytes(data[header_length:])
def xor_key(key1, key2): menor = min(len(key1), len(key2)) result = Bytes([0] * menor) for i in xrange(0, menor): result[i] = key1[i] ^ key2[i] return result
def fill_key(self, key): result = Bytes([0] * 680) for i in xrange(0, 680): result[i] = key[i % 128] result[0] = 128 return result