Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reassembling fragments in a PCAP file

Tags:

python

pcap

We have largish (100 MiB-3 GiB) PCAP files that have huge UDP datagrams that are heavily fragmented, and we need to process them in Python, preferably datagram-by-datagram without reading everything into memory first, due to the potential size of the files. I'm looking for a package that is capable of reading and reassembling IP packets. I've looked at pypcapfile, dpkt, and scapy. Of these, AFAICT only scapy reassembles fragments, but it requires reading the file entirely into memory first, and anyway the GPLv2 license is intolerable in our organization. Are there any other PCAP reading and processing packages out there that will decode and do fragment reassembly, preferably datagram-by-datagram?

Alternatively -- this is not a python question -- is there an OTS command-line tool that will reassemble packets from one PCAP to another? I tried tshark with -r, -w, and -Y ip.flags.mf==0 or -R ip.flags.mf==0 and so far no dice.

like image 881
Vercingatorix Avatar asked Dec 11 '25 04:12

Vercingatorix


1 Answers

Regarding the last part, this may be the solution:

tshark -nlr $infile -qz "follow,tcp,raw,$stream" | tail -n +7 | sed 's/^\s\+//g' | xxd -r -p > ${outfile}.txt 
like image 143
Nagmat Avatar answered Dec 13 '25 22:12

Nagmat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!