Extract dissected fields from a capture with LUA console
The filter function in Wireshark usually provides me the functionality I need, but particularly with protocols that combine different objects in one packet I realize I need something more powerful. Thus I have tried googling and ChatGPT'ing my way into Wireshark LUA scripting, but I'm struggling in getting started with returning any usable information.
The pseudo-code I want to implement is something like this:
For each packet {
For each iec60870_asdu.TypeId==36 {
For each iec60870_asdu.IOA {
Console.write( iec60870_asdu.IOA & ";" & iec60870_asdu.float & ";" & iec60870_asdu.cp56time )
}
}
}
It seems so simple, yet so difficult.
(Sample capture (iec104.pcap IEC 60870-5-104 communication log.) available on Wireshark Wiki - IEC 60870-5-104)
(more)For frame 88, it's one set of fields:
I was not familiar with these sample captures, but those surely helps as a common reference.
You are correct that frame 16 should return multiple sets of fields (ref. "For each iec60870_asdu.IOA" in my pseudo code) which should result in individual lines of console output from my pseudo code.
If it were easy this similar question would be answered. :-)
When parsing hci log with tshark, how to print only the btcommon.eir_ad.entry.uuid_16 associated with the btcommon.eir_ad.entry.type?
This might be something that WSUG - MATE (shudder, shakes head) could be used for. I'll need to experiment.
Have some ideas for doing with Lua but nothing I'm confident enough in to share. :-)
There cannot be two identical AVPs in the same AVPL
So close with MATE then the wheels fall off - will not extract multiple copies of a field with the same value.
Works great for frame 88 with only one set of values. For 16 and 18, only one copy of float and cp56time are extracted since the values are equal. :-( Back to the drawing board.
Thanks for your interest on this challenge!
I did end up using the "Export Packet Dissections" --> "As JSON...", made sure to check "Packet details" only and select "All expanded" to get a JSON export. Then I managed to create a working, yet brittle, bit of Python code to interpret the JSON-data. Including a pretty specific simple JSON decoder returning a list instead of a dict, so that I finally could use the built-in json.loads() to decode each IOA and return a CSV-list of every typeid==36
Python’s json.load() does return a dict, which causes only the last of identical JSON-keys to be returned. Seemingly a similar limitation as you experienced with MATE. For me this turned out to be a limitation on several levels of the Wireshark JSON export. Firstly, there can be several "iec60870_asdu" in one frame, but even after solving that I missed data ...(more)