def serialize(self, binary): self.ts_sec = int(binary_to_hex_string(binary[0:4][::-1]), 16) self.ts_usec = int(binary_to_hex_string(binary[4:8][::-1]), 16) self.incl_len = int(binary_to_hex_string(binary[8:12][::-1]), 16) self.orig_len = int(binary_to_hex_string(binary[12:16][::-1]), 16) return self.__dict__
def serialize(self, binary, source_ip): binary_length = len(binary) j = 0 while binary_length > j: self.content = int(binary_to_hex_string(binary[j]), 16) j += 1 self.tls_version = binary_to_hex_string(binary[j:j + 2]) j += 2 self.tls_length = int(binary_to_hex_string(binary[j:j + 2]), 16) j += 2 # Judge TLS Handshake is interrupted or not try: if self.tls_length == 0: break binary[self.tls_length + (j - 1)] except: # Save remaining packet if self.content == 22: self.remaining_packet.extend( [binary[(j - 5):binary_length], source_ip]) else: self.tls_record += "Continuation_Data " break # TLS Data self.message = binary_to_hex_string(binary[j:(self.tls_length + j)]) j += self.tls_length check_sslv2 = self.make_tls_record() if check_sslv2 is True: flag = binary_to_hex_string(binary[2:4]) if flag == "102": self.tls_access_num += 1 self.tls_record += "ClientHello (SSLv2) " self.remaining_packet = [] break else: self.tls_record += "Unknown_TLS_Record " return self.__dict__
def serialize(self, binary): self.tcp_src = int(binary_to_hex_string(binary[0:2]), 16) self.tcp_dest = int(binary_to_hex_string(binary[2:4]), 16) self.sequence = int(binary_to_hex_string(binary[4:8]), 16) self.acknowledgment = int(binary_to_hex_string(binary[8:12]), 16) temp = binary_to_hex_string(binary[12]) self.header_length = int(temp[0], 16) * 4 self.flags = self.extract_tcp_flags( int(temp[1] + binary_to_hex_string(binary[13]), 16)) self.window_size = int(binary_to_hex_string(binary[14:16]), 16) self.check_sum = binary_to_hex_string(binary[16:18]) self.urgent_pointer = int(binary_to_hex_string(binary[18:20]), 16) return self.__dict__
def serialize(self, binary): self.magic_number = binary_to_hex_string(binary[0:4]) self.major_version = binary_to_hex_string(binary[4:6][::-1]) self.minor_version = binary_to_hex_string(binary[6:8][::-1]) self.thiszone = binary_to_hex_string(binary[8:12][::-1]) self.sigfigs = binary_to_hex_string(binary[12:16][::-1]) self.snaplen = binary_to_hex_string(binary[16:20][::-1]) self.network = binary_to_hex_string(binary[20:24][::-1]) return self.__dict__
def serialize(self, binary): temp = binary_to_hex_string(binary[0]) self.version = temp[0] self.header_length = int(temp[1], 16) * 4 self.diffserv = binary_to_hex_string(binary[1]) self.total_length = int(binary_to_hex_string(binary[2:4]), 16) self.identification = binary_to_hex_string(binary[4:6]) self.flags = binary_to_hex_string(binary[6:8]) self.ttl = int(binary_to_hex_string(binary[8]), 16) self.protocol = int(binary_to_hex_string(binary[9]), 16) self.check_sum = binary_to_hex_string(binary[10:12]) self.ip_src = '.'.join(map(str, list(binary[12:16]))) self.ip_dest = '.'.join(map(str, list(binary[16:20]))) return self.__dict__
def serialize(self, binary): self.mac_dest = binary_to_hex_string(binary[0:6]) self.mac_src = binary_to_hex_string(binary[6:12]) self.type = binary_to_hex_string(binary[12:14]) return self.__dict__