Wireshark, tshark or a script: choosing an analyser for DNP3

3 min read188 courses on OnlySecurity

Three kinds of tool read DNP3 captures well enough to learn from: the Wireshark GUI, tshark on the command line, and a script of your own. Each earns its place at a different moment, and the mistake is to use one for everything.

Wireshark is the right first tool. DNP3 has three layers that matter, a link layer, a transport function and an application layer, and the dissector shows all of them in a tree. When you are learning what a request looks like, clicking through the tree teaches faster than any text. It is also the right tool for one-off questions on a small file: which packet is this, what does this flag mean. Use Decode As when traffic runs on a port other than the conventional one, or Wireshark will show only TCP.

tshark is the right tool once you have a question you will ask more than once. A common field-extraction pattern for DNP3 selects packets with a DNP3 display filter and prints the application function code per packet. Pipe that through sort and uniq with a count and you have a function code histogram of a whole file in one line. Repeat it across a folder with a loop and you can compare runs. Run tshark -q -z conv,ip for the conversation table and -z io,stat,1 for a rate series. The advantage is that the command is the record: you can paste it into your notes and rerun it.

A script, in Python or similar, is the right tool when you need logic that a filter cannot express: for example, compute the gap between a request and the next response, or flag a function code seen from a host that never used it before. Scripts also scale to large folders. The cost is that you now trust your own parsing. If you read raw bytes yourself you will get framing wrong, because DNP3 link frames are broken into blocks with checksums and a naive reader miscounts. Let tshark do the dissection and read its output, rather than parsing the capture yourself.

A worked pattern shows how the three combine. Open a small file in Wireshark and click through one poll and its response until you can name every field you will later extract. Move to tshark and produce the function code histogram, the conversation table and a one-second rate series for the whole file. Then write a short script that reads the tshark field output and answers the one question you could not answer with a filter, such as which host first used a function code that no earlier host used. Each step uses the previous step’s output as its check, so errors surface early. The slowest part is usually the first step, and it is the one that makes the other two trustworthy.

Choose by the question. What does this look like? Wireshark. How many of each? tshark. What is unusual compared to the baseline? A script reading tshark output.

Three habits apply to all of them. Record the tool version, because dissectors change between releases and a field name that works in one may not in another. Record the exact command and the file checksum. And check every result against the packet list in the GUI for at least one packet before trusting a count.

Last, none of these tools needs to touch a live network. Everything in this article runs on a downloaded file on your own machine, and none of it requires sending traffic to a device.

For structured practice on this topic, see the OnlySecurity course DNP3 Traffic Analysis: Baseline, Recon and Single-Message Attacks.

More from this author