nDPI icon indicating copy to clipboard operation
nDPI copied to clipboard

Flow detection time limit

Open NatashaR4in opened this issue 9 years ago • 10 comments

Hi, as other flow analysis manages new flow detection through new unique 5-tuples , I'm having a problem with DNS responses , am sniffing on my ubuntu desktop , I'v noticed that some dns requests initialized from the same random source port , with time difference between the two requests about 40 seconds. NDPI did not detect the second request , I think it handles it as the same flow with the first request having the same 5-tuples . Is their an option for maximum flow time limit like the one exists in NSM-Argus ? is ther any solution for this problem , or am missing something obvious here ?

NatashaR4in avatar Nov 22 '17 19:11 NatashaR4in

A flow is detected with a 5-tuple, as u correctly said. A flow is "alive" for a certain period, after that expired. From what you say it's strange that nDPI does not properly detect that request, maybe yes, it consider in the same flow, but every packet is analized. Can u share the pcap of this traffic to understand better ? Thanks

kYroL01 avatar Nov 22 '17 22:11 kYroL01

Hi, sorry for late response, I was trying to figure the problem my self , no luck till now , I attached a pcap containing 2 dns queries with their responses, with 25 second in between , having the same 5-tuples , the output from ndpi is : Using nDPI (2.1.0-1011-83104eb) [1 thread(s)] Reading packets from pcap file /home/ubt/Desktop/dns_dissection/dns_problem.pcap... Running thread 0...

nDPI Memory statistics: nDPI Memory (once): 114.65 KB
Flow Memory (per flow): 1.92 KB
Actual Memory: 2.42 MB
Peak Memory: 2.42 MB

Traffic statistics: Ethernet bytes: 876 (includes ethernet CRC/IFC/trailer) Discarded bytes: 0
IP packets: 6 of 6 packets total IP bytes: 732 (avg pkt size 122 bytes) Unique flows: 1
TCP Packets: 0
UDP Packets: 6
VLAN Packets: 0
MPLS Packets: 0
PPPoE Packets: 0
Fragmented Packets: 0
Max Packet size: 171
Packet Len < 64: 3
Packet Len 64-128: 2
Packet Len 128-256: 1
Packet Len 256-1024: 0
Packet Len 1024-1500: 0
Packet Len > 1500: 0
nDPI throughput: 12.50 K pps / 13.92 Mb/sec Analysis begin: 24/Nov/2017 18:51:18 Analysis end: 24/Nov/2017 18:51:44 Traffic throughput: 0.23 pps / 269 b/sec Traffic duration: 25.963 sec Guessed flow protos: 0

Detected protocols: Google packets: 6 bytes: 732 flows: 1

Protocol statistics: Safe 732 bytes

1	UDP 10.10.10.252:51125 <-> 8.8.8.8:53 [proto: 5.126/DNS.Google][3 pkts/259 bytes <-> 3 pkts/473 bytes][Host: googleads.g.doubleclick.net]

dns_problem.zip

NatashaR4in avatar Nov 24 '17 17:11 NatashaR4in

So IMHO the problem is that the detection is only for Google and not for the other server name written in the query, isn't it ? This is because the flow is unique (same IP addresses, same Ports, same transport protocol) and the application protocol detected is considered Google (the first matched). This is the question u say, right ?

kYroL01 avatar Nov 24 '17 17:11 kYroL01

In the pcap their is 3 dns requests with their responces , the first query for "googleads.g.doubleclick.net" type A , the second for the same domain but of type AAA , the third request that comes after 25 sec is for "assets.bounceexchange.com" type A, this third request is not detected by ndpi , because it have the same 5-tuples , the problem is that the first request is detected but the third request does not appear at all , as if it does not exist , is that a normal behavior, shouldn't ndpi process the third request as a new flow after 25 sec of having the same 5-tuples .

NatashaR4in avatar Nov 24 '17 23:11 NatashaR4in

@kYroL01 nDPI merge the flows with the same 5-tuples in one flow even if those flows are different, and this is not good for this situations!! in @NatashaR4in pcap file there is two different dns flow one for google and the other for bounceexchange, but the nDPI detected one DNS flow Even after passing ~25 sec from the first flow.

so Does nDPI still cached the 5-tuples from the first flow and join the second flow to the first ???? because it's only detect one dns flow. ??

androuxx avatar Nov 27 '17 21:11 androuxx

I think @NatashaR4in and @androuxx you're right. I have to investigate better but yes, that's two different flows, not only one.

kYroL01 avatar Nov 27 '17 21:11 kYroL01

Can you test after this commit https://github.com/ntop/nDPI/commit/e5546eb988842b05c31fae38a8167fdc6c8fed0d ? Thanks

kYroL01 avatar Nov 30 '17 21:11 kYroL01

I don't think the commit e5546eb will fix this issue. I'm seeing the same problem as described above. I will investigate tomorrow and let everyone know if I determine the issue (cached? discarded? etc.)

dsokoloski avatar Dec 01 '17 05:12 dsokoloski

FWIW, I spent several hours on this yesterday and came to the conclusion that this is not a bug in the nDPI engine. It's doing exactly what it's supposed to do. This is really an upper-level implementation issue (ndpiReader for example). The implementation needs to manage DNS flows more closely in order to keep track of multiple requests from the same host that chooses to rebind the same local port address. I have done the following in our implementation (which requires commit e5546eb to properly dissect DNS responses):

Don't forget to enable: ndpi_mod->dns_dissect_response = 1;

For each DNS response packet (master_protocol == NDPI_PROTOCOL_DNS): Re-hash this flow using 6-tuple, where the host_server_name is the additional key.

This logic results in distinct DNS query questions (host_server_name) being tracked/stored as individual flows. I forget how ndpiReader stores flows (I think it uses a custom hash table), but in our implementation we store flows in an unordered map that is keyed with a SHA1 digest (hash). If we rehash a flow with additional unique data, subsequent packets with the same 5-tuples will be stored as a new flow for each unique DNS query.

It works great now -- we're now seeing and detecting all DNS traffic.

dsokoloski avatar Dec 02 '17 16:12 dsokoloski

If we rehash a flow with additional unique data, subsequent packets with the same 5-tuples will be stored as a new flow for each unique DNS query

@dsokoloski exactly! Anyway i close the issue, and keep in mind that ndpiReader is just a demo proto to test library. BTW if someone think to change the code in a better way, send a pull request.

Thank you

kYroL01 avatar Dec 02 '17 16:12 kYroL01