I'm new to scapy and am looking for confirmation that the commands below is a valid approach to dig into (parse) a UDP/NetflowV9 packet.
My reason for asking is that the approach seems valid to me and works for many packets that I've tried. But, it fails for at least one packet that I've encountered. The decode/parsing that fails is for a UDP/Netflow packet that has 4 Flowsets as follows:
- Flowset 1: Data flowset that has 2 flow records
- Flowset 2: Options Template flowset
- Flowset 3: Data flowset that has 1 flow record
- Flowset 4: Data template flowset
Approach
pkt = rdpcap(pcap)
pkt[0][UDP].payload
NetflowHeader(pkt[0][UDP].payload)
NetflowHeader(pkt[0][UDP].payload).payload
NetflowHeaderV9(NetflowHeader(pkt[0][UDP].payload).payload)
NetflowHeaderV9(NetflowHeader(pkt[0][UDP].payload).payload).payload
NetflowDataflowsetV9(NetflowHeaderV9(NetflowHeader(pkt[0][UDP].payload).payload).payload)
NetflowDataflowsetV9(NetflowHeaderV9(NetflowHeader(pkt[0][UDP].payload).payload).payload).payload
NetflowOptionsFlowsetV9(NetflowDataflowsetV9(NetflowHeaderV9(NetflowHeader(pkt[0][UDP].payload).payload).payload).payload)
The commands above seem to work to reveal details about the first 2 flowsets, but the output of the last command has wrong data (doesn't match what Wireshark shows) for flowset 3. In particular, to start off with, for flowset 3 the flowsetID and length are wrong. I haven't even yet tried to look at flowset 4 since the data for flowset 3 is wrong.
So, I'm just looking for confirmation that my appoach is correct. If my approach is correct, then I'll try to find a way to anonymize the pcap file (a single frame) and ask in a separate stackoverflow post(s). I'd like to not reveal IP addresses in the flow records.