I created a tool called packetseq that outputs a packet sequence diagram in PNG format from a file that was simultaneously captured by Wireshark or tcpdump on multiple nodes on the network. For the language, I used Python and Seqdiag, a library that creates sequence diagrams.
In order to investigate the network delay of the customer environment at the company, the packets collected at each communication node were matched. Since the packet is in pcap format, I browsed it with wireshark, and at first I opened multiple Wiresharks and matched them with my eyes, but it was impossible. Wireshark has a flow diagram, a tool that displays a specific connection, but I gave up because it cannot be used to match packets collected at multiple locations. Since there is no help for it, I decided to create a packet sequence on Excel. I narrowed down the capture file to a specific port communication from the client, exported the packet, converted it to CSV format, and created a sequence diagram by hand on Excel. It was useful for the team to discuss, but it took too long and I didn't want to repeat the same thing again, so I created the tool.
Environment at that time (reference)
Http Client --- Internet --- LLB --- FW --- SLB --- Http Server
"No.","Time","Source","Destination","Protocol","Length","Info"
Date and time format (1973-06-14 01: 02: 03.123456)
$ curl -L -O https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz $ tar zxvf Python-2.7.12.tgz $ cd Python-2.7.12 $ ./configure $ make && make altinstall
$ curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
$ vi /usr/bin/yum Example) Corrected as follows !/usr/bin/python2.6
$ pip install packetseq
--When using only the program Save to the environment where packetseq.py is executed
This time I will explain how to use it based on the following environment
Client (Windows 7) --- Proxy (Squid) --- Server (nifty.com, etc.)
Run wireshark and save when communication is complete File name is arbitrary, save as client.pcap
Example) Packet capture on a proxy server
$ tcpdump -i eth1 -w proxy.pcap File name is arbitrary, save as proxy.pcap
tcp.port == port number
File name is arbitrary, save as client.csv
Example) Packet capture on a proxy server
File name is arbitrary, save as proxy.csv
$ packetseq client.csv proxy.csv
--When executing from saved packetseq.py
$ python packetseq.py client.csv proxy.csv
\######################################## file_name:client.csv \######################################## src ip:192.168.1.3 -> src name: ??? input src name> Client (★ standard input) dst ip:192.168.1.62 -> dst name: ??? input dst name> Proxy (★ standard input)
Next, input is required between proxy servers, so I chose "Proxy" and "Sever".
\######################################## file_name:proxy.csv \######################################## src ip:192.168.1.3 -> src name: ??? input src name> Proxy (★ standard input) dst ip:192.168.1.62 -> dst name: ??? input dst name> Server (★ standard input)
$ file out.* out.diag: ASCII text, with very long lines out.png: PNG image data, 1856 x 31706, 8-bit/color RGBA, non-interlaced
From the left, it is a sequence diagram of "Client", "Proxy", "Web".
With this, you can see the sequence of packets at multiple locations.
See packetseq.py
option | Description | Remarks |
---|---|---|
-h, --help | Show help message | - |
-o, --out output file name | Specify the output destination file name | - |
-i, --info Output type | Select to output packet information on the sequence | Output type is summary, info,Choose from 3 defaults |
-t, --type | Select png or svg as the output format | - |
Css color keyword can be specified Example) Specification on the source code
tcp flag | color |
---|---|
SYN | blue |
SYN ACK | red |
ACK | green |
FIN | navy |
FIN ACK | maroon |
RST | purple |
RST ACK | fuchsia |
URG | olive |
PSH | orange |
Other | gray |
Color settings are specified in self.color_dict of the \ __ init__ function
#Dictionary of color information self.color_dict = { 'SYN': "blue", 'SYN ACK': "red", 'ACK': "green", 'FIN': "navy", 'FIN ACK': "maroon", 'RST': "purple", 'RST ACK': "fuchsia", 'URG': "olive", 'PSH': "orange", 'Other': "gray", }
Recommended Posts