1
I have some. CAP files originated from catching packages with tcpdump. When trying to open with wireshark, the machine gets very slow, because I imagine he tries to load everything to RAM.
I would like to write a program in Python to work more efficiently with dumps. The first question is: what is the difference between . CAP and . PCAP?
I don’t need to read the entire file at once. Imagine you want to read the file. CAP only from time(time) = 9h15 to 11h12 , instead of loading it whole in memory. How to do this in Python? Remembering that files are . CAP and no. PCAP.
Follow the exit from: "tcpdump -r /path/to/ficehiro.cap | Less"
09:32:20.107281 IP iskcon.interactivedns.com.http > 192.168.91.34.47651: Flags [S.], seq 63
8820025, ack 2476676485, win 28960, options [mss 1380,sackOK,TS val 3245680284 ecr 42949413
64,nop,wscale 7], length 0
09:32:20.107308 IP 192.168.91.34.47651 > iskcon.interactivedns.com.http: Flags [.], ack 1,
win 229, options [nop,nop,TS val 4294941466 ecr 3245680284], length 0
09:32:20.107357 IP 192.168.91.34.47651 > iskcon.interactivedns.com.http: Flags [P.], seq 1:
181, ack 1, win 229, options [nop,nop,TS val 4294941466 ecr 3245680284], length 180: HTTP:
GET / HTTP/1.1
09:32:20.144075 IP ec2-52-73-252-184.compute-1.amazonaws.com.http > 192.168.91.34.47570: Fl
ags [.], seq 831563414:831564782, ack 387706135, win 75, options [nop,nop,TS val 499391566
ecr 4294941090], length 1368: HTTP
09:32:20.144094 IP 192.168.91.34.47570 > ec2-52-73-252-184.compute-1.amazonaws.com.http: Fl
ags [.], ack 1368, win 816, options [nop,nop,TS val 4294941475 ecr 499391566], length 0
09:32:20.144368 IP ec2-52-73-252-184.compute-1.amazonaws.com.http > 192.168.91.34.47570: Fl
ags [.], seq 1368:2736, ack 1, win 75, options [nop,nop,TS val 499391566 ecr 4294941090], l
ength 1368: HTTP
09:32:20.144376 IP 192.168.91.34.47570 > ec2-52-73-252-184.compute-1.amazonaws.com.http: Fl
ags [.], ack 2736, win 838, options [nop,nop,TS val 4294941475 ecr 499391566], length 0
09:32:20.145197 IP ec2-52-73-252-184.compute-1.amazonaws.com.http > 192.168.91.34.47570: Fl
ags [.], seq 2736:4104, ack 1, win 75, options [nop,nop,TS val 499391566 ecr 4294941090], l
ength 1368: HTTP
09:32:20.145204 IP 192.168.91.34.47570 > ec2-52-73-252-184.compute-1.amazonaws.com.http: Fl
ags [.], ack 4104, win 861, options [nop,nop,TS val 4294941475 ecr 499391566], length 0
09:32:20.145214 IP ec2-52-73-252-184.compute-1.amazonaws.com.http > 192.168.91.34.47570: Fl
ength 1368: HTTP
09:32:20.145218 IP 192.168.91.34.47570 > ec2-52-73-252-184.compute-1.amazonaws.com.http: Fl
ags [.], ack 5472, win 883, options [nop,nop,TS val 4294941475 ecr 499391566], length 0
09:32:20.148032 IP ec2-52-73-252-184.compute-1.amazonaws.com.http > 192.168.91.34.47570: Fl
ags [.], seq 5472:6840, ack 1, win 75, options [nop,nop,TS val 499391566 ecr 4294941090],
Wireshark memory consumption when opening a 1GB CAP:
Try "tcpdump -r /path/to/ficehiro.cap | Less" at the terminal
– Miguel
Thanks @Miguel. I need it in Python, because I will process the file later!
– Ed S
You can put an example of the internal file format, the first 10 lines for example: "head -10.cap file" in the sff terminal
– Miguel
Dear @Miguel, head -10.cap file -> the output were strange characters. The command is that same? used from Ubuntu terminal
– Ed S
is to print the first 10 lines of a file
– Miguel
@Miguel:�ò���T�X�JJ�H���g��E<@*�ϋ�
���["P�#&������q zd
�u&�����T�X,�BB�g����H��E4@@����["��
��#P���&����Y
����u&�T�X]����g����H��E�@@����["��
��#P���&�����! u& GET / HTTP/1.1 User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:50.1.0) Gecko/20100101 Firefox/50.1.0 Accept: / Host: www.iskconbangalore.org
– Ed S
http://www.linfo.org/head.html. This may help: https://www.google.pt/search?cli=ms-android-huawei&ei=Jy63WL2mGYmtU7Kho4gC&q=read+cap+cap+file+with+python&oq=read+cap+file+with+python&gs_l=mobile-gws-Serp.12...13514.14049.0.15132.4.4.0.0.0.291.702.0j3j1.4.0....0...1c.1j4.64.mobile-gws-Serp..1.0.0.Yxlkol3wsai
– Miguel
I will try to make a print of wireshark (open file) and post the link.
– Ed S
More than 30 minutes charging on wireshark. The dump is 2.6 GB
– Ed S
You are best followed by https://www.google.pt/search?cli=ms-android-huawei&ei=Jy63WL2mGYmtU7Kho4gC&q=read+cap+with+python&oq=read+cap+cap+file+with+python&gs_l=mobile-gws-serp.12...13514.14049.0.15132.4.0.0.0.0.291.702.0j3j1.4.0.......0..1j4.4.64.mobile-gws-Serp..1.0.0.Yxlkol3wsai, for example: https://jon.oberheide.org/blog/2008/10/15/dpkt-tutorial-2-parsing-a-pcap-file/. I’ve never worked with this, I don’t think I’ll be able to help you with this
– Miguel
@Miguel: I put the output of tcpdump -r /path/to/ficehiro.cap | Less in question.
– Ed S
@Miguel: I placed the image of another CAP file
– Ed S
Apparently Wireshark has its own API for Lua integration: https://www.wireshark.org/docs/wsdg_html_chunked/wsluarm_modules.html That is, maybe Python is not the best for you. :)
– Luiz Vieira
take a look at my answer, it will help you process giant acquisitions...
– ederwander