I built a WLAN sniffer on a Raspberry Pi using python scripts and tshark. Tshark saves the captures in a ring buffer containing 10 files with a length of i.e. one minute per file (I cannot change that, because of the limited memory on the Pi) and it runs in a seperate thread, which works just fine. My problem is that I need to save all management frames (the ones outside the ring buffer window, too) to decrypt the other packets. I had the idea to analyze a .pcap file when tshark is done writing to it. Is there any way to get the information from tshark, when it moved on to the next file, and then trigger a function to analyse a file, filter out everything that's not management related and save it to a seperate file? All this would then be done in yet another thread, so the GUI does not freeze and tshark does not pause/stop capturing. Or is it possible to filter different packet types and write them into two files directly while capturing wihtout losing any of them? Thank you asked 25 May '16, 04:51 Baumi |
3 Answers:
Found a solution (but instead of parsing the stdout I used a timer). Could you tell me how I can parse the stdout from dumpcap? I googled a few hours but did not find a proper way to do it. To me, the timer seems very inelegeant. This part calls the timer and dumpcap and stops it. Dumpcap is stopped by a SIGTERM command.
answered 02 Jun ‘16, 04:50 Baumi |
Note that you should be using dumpcap to do the capturing, tshark retains state and will consume memory and eventually crash. dumpcap takes the same parameters as tshark for interface specification and ring buffers but can't use tshark display filters, only capture filters. If you are discarding a capture after 10 minutes it would seem that you don't need most of the content, only the "management frames", is this correct? If so, why don't you set a filter so that you only capture the management frames, rather than attempt to post-process them out of the captures? answered 25 May '16, 06:11 grahamb ♦ |
Is there a reason why you couldn't run two instances of dumpcap, one capturing only management frames and not using a ring buffer, and one capturing the other frames into a ring buffer? answered 02 Jun '16, 11:34 Guy Harris ♦♦ |
Thanks for your response, I will give dumpcap a try, when I find a solution for the management frames.
The reason I can't only capture management packets is that the sniffer is supposed to be used to debug actual data from other systems in development, the capturing should end, when the user finds an error end presses "Stop". I don't really know what size the ringbuffer will have, or rather need, when the sniffer is ready to be used, it might also be an hour or two. I might even end up limiting it by filesize instead of time, but there is still a risk that the necessary management frames are pushed out of the buffer.
OK, so it seems you have a few tasks:
You should also consider other approaches such as other software already out there that might do something similar, or using tshark you might be able to write a dissector or tap in lua or C that would actively write out the management frames to a new capture file as they are received.
dumpcap really does seem to be a viable option for this.
I will try the "dumpcap -> stdout when a new file is started" approach and come back here, when I have some results.
Thank you for your help!
Now we're really veering off-topic for ask Wireshark, but have a look at the Python subprocess module, and a simple (polling) example here.