for packet in pcap[5:]: layers = packet['_source']['layers'] src_port = int(layers['udp']['udp.srcport']) stream_id = int(layers['quic']['quic.frame']['quic.stream.stream_id']) frame_type = int(layers['http3']['http3.frame_type'])
stream = streams.get(stream_id, None) if stream isNone: stream = { 'req_headers': {}, 'res_headers': {}, 'res_data': {} } streams[stream_id] = stream if frame_type == 1: header_payload = binascii.unhexlify(layers['http3']['http3.frame_payload'].replace(':', "")) if src_port == 8443: headers = decoder_srv.feed_header(stream_id, header_payload)[1] for k, v in headers: stream['res_headers'][k.decode('ascii')] = v.decode('ascii') else: headers = decoder_cli.feed_header(stream_id, header_payload)[1] for k, v in headers: stream['req_headers'][k.decode('ascii')] = v.decode('ascii') if frame_type == 0and src_port == 8443: payload = binascii.unhexlify(layers['http3']['http3.frame_payload'].replace(':', "")) pkn = int(layers['quic']['quic.short']['quic.packet_number']) stream['res_data'][pkn] = payload
for i in streams: stream = streams[i] path = "files/" + stream['req_headers'][':path'].replace("/", "_") parts = list(stream['res_data'].keys()) parts.sort() withopen(path, "wb") as f: for part_i in parts: f.write(stream['res_data'][part_i])