import pyshark defget_code(): captures = pyshark.FileCapture("question_1564353677_modbus1.pcap") func_codes = {} for c in captures: for pkt in c: if pkt.layer_name == "modbus": func_code = int(pkt.func_code) if func_code in func_codes: func_codes[func_code] += 1 else: func_codes[func_code] = 1 print(func_codes) if __name__ == '__main__': get_code()
deffind_flag(): cap = pyshark.FileCapture("question_1564353677_modbus1.pcap") idx = 1 for c in cap: for pkt in c: func_code = int(pkt.func_code) if pkt.layer_name == "modbus"andif func_code == 16: payload = str(c["TCP"].payload).replace(":", "") print(hex_to_ascii(payload)) print("{0} *".format(idx)) idx += 1 defhex_to_ascii(payload): data = payload flags = [] for d in data: _ord = ord(d) if (_ord > 0) and (_ord < 128): flags.append(chr(_ord)) return''.join(flags)