nDPI icon indicating copy to clipboard operation
nDPI copied to clipboard

Telegram Application detection failed in FORWARD chain of iptables

Open TaranehKhalili opened this issue 9 years ago • 8 comments

I want to detect telegram protocol for web and it's application. I could detect and drop web.telegram. But the telegram application can not detect by ndpi. HTTP_DOWNLOAD is the protocol which is detected by the ndpi. How is the process of detecting a protocol? first protocol checked by files in /src/lib/protocols OR by entries in ndpi_content_match.c.inc (IP addresses and FQDNs) ? @kYroL01
why telegram is detect in INPUT chain but in FORWARD chain http_download is detect instead of telegram??

TaranehKhalili avatar Sep 06 '17 10:09 TaranehKhalili

First of all nDPI check IP address and Port range and THEN check eventually dissectors in protocols directory. I tested with your pcap and everything is working correctly. So, did u tried to update and recompile all ?

kYroL01 avatar Sep 14 '17 07:09 kYroL01

I close because IMHO now the bug is fixed (as I said above). Reopen if necessary

kYroL01 avatar Sep 18 '17 16:09 kYroL01

I think telegram dissector cannot detect telegram flows between the application and server because of the protocol which telegram used for transferring data (MTproto). IMHO the telegram dissector code is not complete.

TaranehKhalili avatar Sep 20 '17 04:09 TaranehKhalili

Ok I'll check asap

kYroL01 avatar Sep 20 '17 07:09 kYroL01

Thanx I think the matter is when you detect a protocol based on ip address (for example 149.154.166.120 for telegram) you should not continue the detection process. because of this problem http_download is the protocol which is detected instead of telegram.

TaranehKhalili avatar Sep 20 '17 09:09 TaranehKhalili

well I could solve the problem by this change in ndpi_detection_process_packet function. flow->guessed_protocol_id = (int16_t)ndpi_guess_protocol_id(ndpi_struct, protocol, sport, dport, &user_defined_proto); if(flow->packet.iph) { if((flow->guessed_host_protocol_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->saddr)) == NDPI_PROTOCOL_UNKNOWN) flow->guessed_host_protocol_id = ndpi_network_ptree_match(ndpi_struct, (struct in_addr *)&flow->packet.iph->daddr); if (flow->guessed_host_protocol_id == NDPI_PROTOCOL_TELEGRAM){ ret.master_protocol = flow->guessed_host_protocol_id, ret.protocol = flow->guessed_host_protocol_id; return(ret); } } if(user_defined_proto && (flow->guessed_protocol_id != NDPI_PROTOCOL_UNKNOWN)) { ret.master_protocol = NDPI_PROTOCOL_UNKNOWN, ret.protocol = flow->guessed_protocol_id; return(ret); }

Actually I place the detection based on ip upon the detection based on port.

TaranehKhalili avatar Sep 25 '17 04:09 TaranehKhalili

You could also send a pull request and then I'll check it. I also try to see better, because i try telegram-desktop.pcap you sent me and I detect it correctly. I see

kYroL01 avatar Sep 25 '17 06:09 kYroL01

OK. thanx. I send a pull request. 1a6546850652acdd12570345a1ec71a13ad5405d

TaranehKhalili avatar Sep 25 '17 08:09 TaranehKhalili