BitTorrent detection improvements

This commit is contained in:
Luca Deri
2021-10-31 18:45:13 +01:00
parent a9aa46287d
commit 9f8c1e8630
+11 -2
View File
@@ -405,6 +405,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
} }
} }
} }
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
/* check for tcp retransmission here */ /* check for tcp retransmission here */
@@ -412,7 +413,8 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
ndpi_int_search_bittorrent_tcp(ndpi_struct, flow); ndpi_int_search_bittorrent_tcp(ndpi_struct, flow);
} else if(packet->udp != NULL) { } else if(packet->udp != NULL) {
/* UDP */ /* UDP */
char *bt_search = "BT-SEARCH * HTTP/1.1\r\n"; const char *bt_search = "BT-SEARCH * HTTP/1.1\r\n";
const char *bt_search1 = "d1:ad2:id20:";
if((ntohs(packet->udp->source) < 1024) if((ntohs(packet->udp->source) < 1024)
|| (ntohs(packet->udp->dest) < 1024) /* High ports only */) { || (ntohs(packet->udp->dest) < 1024) /* High ports only */) {
@@ -427,7 +429,10 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
*/ */
if(packet->payload_packet_len >= 23 /* min header size */) { if(packet->payload_packet_len >= 23 /* min header size */) {
if(strncmp((const char*)packet->payload, bt_search, strlen(bt_search)) == 0) { if(
(strncmp((const char*)packet->payload, bt_search, strlen(bt_search)) == 0)
|| (strncmp((const char*)packet->payload, bt_search1, strlen(bt_search1)) == 0)
) {
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return; return;
@@ -458,7 +463,11 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20); bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found; goto bittorrent_found;
} }
} else if(ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20)
) {
goto bittorrent_found;
} }
} }
} }