How to use nDPI from CLI to analyse network traffic

Posted · Add Comment

Most people use nDPI indirectly being it part of ntopng and many other non-ntop developed tools. However not many people know that nDPI can also be used from the command line to analyse network traffic. This is useful to create scripts to automate detection of specific issues. ndpiReader is a testing tool used to demonstrate the library features as well run validation tests. With this tool is also possible to generate a report in CSV format that can be analysed with tools such as q.

Below you can find some practical examples of how this technique can be used in real life. Suppose we need to analyse some malware traffic in order to spot anomalies. A good starting point for sample pcap files is the CIC dataset or this website or you can use any pcap you already have collected as those part of the nDPI test set.

From the CIC dataset, support you want to analyse what flows are affected by Slow DoS.

$ ndpiReader -i dos_slow.pcap -C dos_slow.csv

Dumps flow analysis results into CSV file that contains the following fields

$ head -1 ~/Downloads/Ricci/dos_slow.csv

You can now run this query to find out the top 10 slow DoS flows

q -H -d ',' "select src_ip,src_port,dst_ip,dst_port,ndpi_proto,duration from ./dos_slow.csv where dst2src_goodput_ratio<10 order by duration desc limit 10",54240,,80,HTTP,1241.436,53816,,80,HTTP,1239.08,53824,,80,HTTP,1239.078,53834,,80,HTTP,1239.077,53840,,80,HTTP,1239.077,53846,,80,HTTP,1239.076,53852,,80,HTTP,1239.075,53858,,80,HTTP,1239.074,53866,,80,HTTP,1239.073,53872,,80,HTTP,1239.072

Suppose you want to know the amount of traffic the top IPe in netfix.pcap have spent watching NetFlix. First run ndpiReader as follows

$ cd nDPI/tests/pcap
$ ../../example/ndpiReader -i netflix.pcap -C /tmp/netflix.csv

then do

$ q -H -d ',' "select src_ip,SUM(src2dst_bytes+dst2src_bytes) from /tmp/netflix.csv where ndpi_proto like '%NetFlix%' group by src_ip",6151821

Possibilites are basically endless.