Compare commits

..
2 Commits
Author SHA1 Message Date
Luca Deri 7759f122a1 Tests update 2018-12-21 17:33:57 +01:00
Alfredo Cardigliano b1abb7b7f2 Version set to 2.6 2018-12-21 10:49:55 +01:00
34 changed files with 903 additions and 841 deletions
-31
View File
@@ -1,36 +1,5 @@
# CHANGELOG
#### nDPI 2.8 (March 2019)
## New Supported Protocols and Services
* Added Modbus over TCP dissector
## Improvements
* Wireshark Lua plugin compatibility with Wireshark 3
* Improved MDNS dissection
* Improved HTTP response code handling
* Full dissection of HTTP responses
## Fixes
* Fixed false positive mining detection
* Fixed invalid TCP DNS dissection
* Releasing buffers upon `realloc` failures
* ndpiReader: Prevents references after free
* Endianness fixes
* Fixed IPv6 HTTP traffic dissection
* Fixed H.323 detection
## Other
* Disabled ookla statistics which need to be improved
* Support for custom protocol files of arbitrary length
* Update radius.c to RFC2865
------------------------------------------------------------------------
#### nDPI 2.6 (December 2018)
## New Supported Protocols and Services
+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/sh
NDPI_MAJOR="2"
NDPI_MINOR="8"
NDPI_MINOR="6"
NDPI_PATCH="0"
NDPI_VERSION_SHORT="$NDPI_MAJOR.$NDPI_MINOR.$NDPI_PATCH"
+1 -4
View File
@@ -3,7 +3,7 @@ CFLAGS=-g -I../src/include @CFLAGS@
LIBNDPI=../src/lib/libndpi.a
LDFLAGS=$(LIBNDPI) @PCAP_LIB@ -lpthread @LDFLAGS@
OBJS=ndpiReader.o ndpi_util.o
PREFIX?=@prefix@
PREFIX?=/usr/local
all: ndpiReader @DPDK_TARGET@
@@ -22,9 +22,6 @@ install:
dpdk:
make -f Makefile.dpdk
check:
cppcheck --template='{file}:{line}:{severity}:{message}' --quiet --enable=all --force -I../src/include -I/usr/local/include/json-c *.c
clean:
/bin/rm -f *.o ndpiReader ndpiReader.dpdk
/bin/rm -f .*.dpdk.cmd .*.o.cmd *.dpdk.map .*.o.d
+8 -13
View File
@@ -913,11 +913,10 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
struct ndpi_flow_info *flow = *(struct ndpi_flow_info **) node;
u_int16_t thread_id = *((u_int16_t *) user_data);
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
if((!flow->detection_completed) && flow->ndpi_flow) {
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
if((!flow->detection_completed) && flow->ndpi_flow)
flow->detected_protocol = ndpi_detection_giveup(ndpi_thread_info[0].workflow->ndpi_struct, flow->ndpi_flow, enable_protocol_guess);
}
process_ndpi_collected_info(ndpi_thread_info[thread_id].workflow, flow);
ndpi_thread_info[thread_id].workflow->stats.protocol_counter[flow->detected_protocol.app_protocol] += flow->src2dst_packets + flow->dst2src_packets;
@@ -1016,6 +1015,7 @@ void freeIpTree(addr_node *root) {
freeIpTree(root->left);
freeIpTree(root->right);
free(root);
root = NULL;
}
/* *********************************************** */
@@ -1459,7 +1459,7 @@ static void setupDetection(u_int16_t thread_id, pcap_t * pcap_handle) {
ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct,
ndpi_pref_http_dont_dissect_response, 0);
ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct,
ndpi_pref_dns_dont_dissect_response, 0);
ndpi_pref_dns_dissect_response, 0);
ndpi_set_detection_preferences(ndpi_thread_info[thread_id].workflow->ndpi_struct,
ndpi_pref_enable_category_substring_match, 1);
@@ -2489,7 +2489,8 @@ static void ndpi_process_packet(u_char *args,
if(memcmp(packet, packet_checked, header->caplen) != 0)
printf("INTERNAL ERROR: ingress packet was modified by nDPI: this should not happen [thread_id=%u, packetId=%lu, caplen=%u]\n",
thread_id, (unsigned long)ndpi_thread_info[thread_id].workflow->stats.raw_packet_count, header->caplen);
free(packet_checked);
if((pcap_end.tv_sec-pcap_start.tv_sec) > pcap_analysis_duration) {
int i;
u_int64_t processing_time_usec, setup_time_usec;
@@ -2513,12 +2514,6 @@ static void ndpi_process_packet(u_char *args,
memcpy(&begin, &end, sizeof(begin));
memcpy(&pcap_start, &pcap_end, sizeof(pcap_start));
}
/*
Leave the free as last statement to avoid crashes when ndpi_detection_giveup()
is called above by printResults()
*/
free(packet_checked);
}
@@ -2906,7 +2901,7 @@ float getAverage(struct json_object *jObj_stat, char *field){
float average;
float sum = 0;
int r;
int j = 0;
int j;
if((r = strcmp(field, "top.scanner.stats")) == 0) {
for(j=0; j<json_object_array_length(jObj_stat); j++) {
+1 -1
View File
@@ -1044,7 +1044,7 @@ iph_check:
static uint32_t crc32_for_byte(uint32_t r) {
int j;
for(j = 0; j < 8; ++j)
r = ((r & 1) ? 0 : (uint32_t)0xEDB88320L) ^ r >> 1;
r = (r & 1? 0: (uint32_t)0xEDB88320L) ^ r >> 1;
return r ^ (uint32_t)0xFF000000L;
}
+1 -1
View File
@@ -1,4 +1,4 @@
plibrary_includedir=$(includedir)/libndpi-@VERSION@/libndpi
library_includedir=$(includedir)/libndpi-@VERSION@/libndpi
library_include_HEADERS = ndpi_api.h \
ndpi_define.h \
+1 -10
View File
@@ -740,11 +740,8 @@ extern "C" {
char *name, ndpi_protocol_category_t category);
int ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_struct);
int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t saddr,
u_int32_t daddr,
const struct ndpi_iphdr *iph,
ndpi_protocol *ret);
int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_struct,
char *name, unsigned long *id);
void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol *ret);
@@ -759,12 +756,6 @@ extern "C" {
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_detection_module_size();
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
/* LRU cache */
struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries);
void ndpi_lru_free_cache(struct ndpi_lru_cache *c);
u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int8_t clean_key_when_found);
void ndpi_lru_add_to_cache(struct ndpi_lru_cache *c, u_int32_t key);
/**
* Add a string to match to an automata
-22
View File
@@ -338,26 +338,4 @@
#define NDPI_MINOR @NDPI_MINOR@
#define NDPI_PATCH @NDPI_PATCH@
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#define htobe16(x) OSSwapHostToBigInt16(x)
#define htole16(x) OSSwapHostToLittleInt16(x)
#define be16toh(x) OSSwapBigToHostInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htobe32(x) OSSwapHostToBigInt32(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define be32toh(x) OSSwapBigToHostInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htobe64(x) OSSwapHostToBigInt64(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define be64toh(x) OSSwapBigToHostInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#endif /* __APPLE__ */
#endif /* __NDPI_DEFINE_INCLUDE_FILE__ */
+2 -2
View File
@@ -78,8 +78,8 @@ typedef enum {
NDPI_PROTOCOL_SMBV23 = 41, /* SMB version 2/3 */
NDPI_PROTOCOL_MINING = 42, /* Bitcoin, Ethereum, ZCash, Monero */
NDPI_PROTOCOL_NEST_LOG_SINK = 43, /* Nest Log Sink (Nest Protect) - Darryl Sokoloski <darryl@egloo.ca> */
NDPI_PROTOCOL_MODBUS = 44, /* Modbus */
NDPI_PROTOCOL_FREE_44 = 44, /* Free */
NDPI_PROTOCOL_FREE_45 = 45, /* Free */
NDPI_PROTOCOL_FREE_46 = 46, /* Free */
-1
View File
@@ -363,5 +363,4 @@ void init_fbzero_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_i
void init_memcached_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_nest_log_sink_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ookla_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_modbus_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
#endif /* __NDPI_PROTOCOLS_H__ */
+225 -222
View File
@@ -29,18 +29,18 @@
/* NDPI_LOG_LEVEL */
typedef enum {
NDPI_LOG_ERROR,
NDPI_LOG_TRACE,
NDPI_LOG_DEBUG,
NDPI_LOG_DEBUG_EXTRA
NDPI_LOG_ERROR,
NDPI_LOG_TRACE,
NDPI_LOG_DEBUG,
NDPI_LOG_DEBUG_EXTRA
} ndpi_log_level_t;
/* NDPI_VISIT */
typedef enum {
ndpi_preorder,
ndpi_postorder,
ndpi_endorder,
ndpi_leaf
ndpi_preorder,
ndpi_postorder,
ndpi_endorder,
ndpi_leaf
} ndpi_VISIT;
/* NDPI_NODE */
@@ -356,21 +356,17 @@ PACK_ON struct tinc_cache_entry {
} PACK_OFF;
typedef enum {
HTTP_METHOD_UNKNOWN = 0,
HTTP_METHOD_OPTIONS,
HTTP_METHOD_GET,
HTTP_METHOD_HEAD,
HTTP_METHOD_POST,
HTTP_METHOD_PUT,
HTTP_METHOD_DELETE,
HTTP_METHOD_TRACE,
HTTP_METHOD_CONNECT
HTTP_METHOD_UNKNOWN = 0,
HTTP_METHOD_OPTIONS,
HTTP_METHOD_GET,
HTTP_METHOD_HEAD,
HTTP_METHOD_POST,
HTTP_METHOD_PUT,
HTTP_METHOD_DELETE,
HTTP_METHOD_TRACE,
HTTP_METHOD_CONNECT
} ndpi_http_method;
struct ndpi_lru_cache {
u_int32_t num_entries, *entries;
};
struct ndpi_id_struct {
/**
detected_protocol_bitmask:
@@ -379,229 +375,229 @@ struct ndpi_id_struct {
to compare this, use:
**/
NDPI_PROTOCOL_BITMASK detected_protocol_bitmask;
/* NDPI_PROTOCOL_RTSP */
/* NDPI_PROTOCOL_RTSP */
ndpi_ip_addr_t rtsp_ip_address;
/* NDPI_PROTOCOL_YAHOO */
/* NDPI_PROTOCOL_YAHOO */
u_int32_t yahoo_video_lan_timer;
/* NDPI_PROTOCOL_IRC_MAXPORT % 2 must be 0 */
/* NDPI_PROTOCOL_IRC */
/* NDPI_PROTOCOL_IRC */
#define NDPI_PROTOCOL_IRC_MAXPORT 8
u_int16_t irc_port[NDPI_PROTOCOL_IRC_MAXPORT];
u_int32_t last_time_port_used[NDPI_PROTOCOL_IRC_MAXPORT];
u_int32_t irc_ts;
/* NDPI_PROTOCOL_GNUTELLA */
/* NDPI_PROTOCOL_GNUTELLA */
u_int32_t gnutella_ts;
/* NDPI_PROTOCOL_BATTLEFIELD */
/* NDPI_PROTOCOL_BATTLEFIELD */
u_int32_t battlefield_ts;
/* NDPI_PROTOCOL_THUNDER */
/* NDPI_PROTOCOL_THUNDER */
u_int32_t thunder_ts;
/* NDPI_PROTOCOL_RTSP */
/* NDPI_PROTOCOL_RTSP */
u_int32_t rtsp_timer;
/* NDPI_PROTOCOL_OSCAR */
/* NDPI_PROTOCOL_OSCAR */
u_int32_t oscar_last_safe_access_time;
/* NDPI_PROTOCOL_ZATTOO */
/* NDPI_PROTOCOL_ZATTOO */
u_int32_t zattoo_ts;
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
u_int32_t jabber_stun_or_ft_ts;
/* NDPI_PROTOCOL_DIRECTCONNECT */
/* NDPI_PROTOCOL_DIRECTCONNECT */
u_int32_t directconnect_last_safe_access_time;
/* NDPI_PROTOCOL_SOULSEEK */
/* NDPI_PROTOCOL_SOULSEEK */
u_int32_t soulseek_last_safe_access_time;
/* NDPI_PROTOCOL_DIRECTCONNECT */
/* NDPI_PROTOCOL_DIRECTCONNECT */
u_int16_t detected_directconnect_port;
u_int16_t detected_directconnect_udp_port;
u_int16_t detected_directconnect_ssl_port;
/* NDPI_PROTOCOL_BITTORRENT */
/* NDPI_PROTOCOL_BITTORRENT */
#define NDPI_BT_PORTS 8
u_int16_t bt_port_t[NDPI_BT_PORTS];
u_int16_t bt_port_u[NDPI_BT_PORTS];
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
#define JABBER_MAX_STUN_PORTS 6
u_int16_t jabber_voice_stun_port[JABBER_MAX_STUN_PORTS];
u_int16_t jabber_file_transfer_port[2];
/* NDPI_PROTOCOL_GNUTELLA */
/* NDPI_PROTOCOL_GNUTELLA */
u_int16_t detected_gnutella_port;
/* NDPI_PROTOCOL_GNUTELLA */
/* NDPI_PROTOCOL_GNUTELLA */
u_int16_t detected_gnutella_udp_port1;
u_int16_t detected_gnutella_udp_port2;
/* NDPI_PROTOCOL_SOULSEEK */
/* NDPI_PROTOCOL_SOULSEEK */
u_int16_t soulseek_listen_port;
/* NDPI_PROTOCOL_IRC */
/* NDPI_PROTOCOL_IRC */
u_int8_t irc_number_of_port;
/* NDPI_PROTOCOL_OSCAR */
/* NDPI_PROTOCOL_OSCAR */
u_int8_t oscar_ssl_session_id[33];
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
u_int8_t jabber_voice_stun_used_ports;
/* NDPI_PROTOCOL_SIP */
/* NDPI_PROTOCOL_YAHOO */
/* NDPI_PROTOCOL_SIP */
/* NDPI_PROTOCOL_YAHOO */
u_int32_t yahoo_video_lan_dir:1;
/* NDPI_PROTOCOL_YAHOO */
/* NDPI_PROTOCOL_YAHOO */
u_int32_t yahoo_conf_logged_in:1;
u_int32_t yahoo_voice_conf_logged_in:1;
/* NDPI_PROTOCOL_RTSP */
/* NDPI_PROTOCOL_RTSP */
u_int32_t rtsp_ts_set:1;
};
/* ************************************************** */
struct ndpi_flow_tcp_struct {
/* NDPI_PROTOCOL_MAIL_SMTP */
/* NDPI_PROTOCOL_MAIL_SMTP */
u_int16_t smtp_command_bitmask;
/* NDPI_PROTOCOL_MAIL_POP */
/* NDPI_PROTOCOL_MAIL_POP */
u_int16_t pop_command_bitmask;
/* NDPI_PROTOCOL_QQ */
/* NDPI_PROTOCOL_QQ */
u_int16_t qq_nxt_len;
/* NDPI_PROTOCOL_WHATSAPP */
u_int8_t wa_matched_so_far;
/* NDPI_PROTOCOL_TDS */
/* NDPI_PROTOCOL_TDS */
u_int8_t tds_login_version;
/* NDPI_PROTOCOL_IRC */
/* NDPI_PROTOCOL_IRC */
u_int8_t irc_stage;
u_int8_t irc_port;
/* NDPI_PROTOCOL_H323 */
/* NDPI_PROTOCOL_H323 */
u_int8_t h323_valid_packets;
/* NDPI_PROTOCOL_GNUTELLA */
/* NDPI_PROTOCOL_GNUTELLA */
u_int8_t gnutella_msg_id[3];
/* NDPI_PROTOCOL_IRC */
/* NDPI_PROTOCOL_IRC */
u_int32_t irc_3a_counter:3;
u_int32_t irc_stage2:5;
u_int32_t irc_direction:2;
u_int32_t irc_0x1000_full:1;
/* NDPI_PROTOCOL_SOULSEEK */
/* NDPI_PROTOCOL_SOULSEEK */
u_int32_t soulseek_stage:2;
/* NDPI_PROTOCOL_TDS */
/* NDPI_PROTOCOL_TDS */
u_int32_t tds_stage:3;
/* NDPI_PROTOCOL_USENET */
/* NDPI_PROTOCOL_USENET */
u_int32_t usenet_stage:2;
/* NDPI_PROTOCOL_IMESH */
/* NDPI_PROTOCOL_IMESH */
u_int32_t imesh_stage:4;
/* NDPI_PROTOCOL_HTTP */
/* NDPI_PROTOCOL_HTTP */
u_int32_t http_setup_dir:2;
u_int32_t http_stage:2;
u_int32_t http_empty_line_seen:1;
u_int32_t http_wait_for_retransmission:1;
/* NDPI_PROTOCOL_GNUTELLA */
/* NDPI_PROTOCOL_GNUTELLA */
u_int32_t gnutella_stage:2; // 0 - 2
/* NDPI_CONTENT_MMS */
/* NDPI_CONTENT_MMS */
u_int32_t mms_stage:2;
/* NDPI_PROTOCOL_YAHOO */
/* NDPI_PROTOCOL_YAHOO */
u_int32_t yahoo_sip_comm:1;
u_int32_t yahoo_http_proxy_stage:2;
/* NDPI_PROTOCOL_MSN */
/* NDPI_PROTOCOL_MSN */
u_int32_t msn_stage:3;
u_int32_t msn_ssl_ft:2;
/* NDPI_PROTOCOL_SSH */
/* NDPI_PROTOCOL_SSH */
u_int32_t ssh_stage:3;
/* NDPI_PROTOCOL_VNC */
/* NDPI_PROTOCOL_VNC */
u_int32_t vnc_stage:2; // 0 - 3
/* NDPI_PROTOCOL_TELNET */
/* NDPI_PROTOCOL_TELNET */
u_int32_t telnet_stage:2; // 0 - 2
/* NDPI_PROTOCOL_SSL */
/* NDPI_PROTOCOL_SSL */
u_int8_t ssl_seen_client_cert:1, ssl_seen_server_cert:1, ssl_stage:2; // 0 - 5
/* NDPI_PROTOCOL_POSTGRES */
/* NDPI_PROTOCOL_POSTGRES */
u_int32_t postgres_stage:3;
/* NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK */
/* NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK */
u_int32_t ddlink_server_direction:1;
u_int32_t seen_syn:1;
u_int32_t seen_syn_ack:1;
u_int32_t seen_ack:1;
/* NDPI_PROTOCOL_ICECAST */
/* NDPI_PROTOCOL_ICECAST */
u_int32_t icecast_stage:1;
/* NDPI_PROTOCOL_DOFUS */
/* NDPI_PROTOCOL_DOFUS */
u_int32_t dofus_stage:1;
/* NDPI_PROTOCOL_FIESTA */
/* NDPI_PROTOCOL_FIESTA */
u_int32_t fiesta_stage:2;
/* NDPI_PROTOCOL_WORLDOFWARCRAFT */
/* NDPI_PROTOCOL_WORLDOFWARCRAFT */
u_int32_t wow_stage:2;
/* NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV */
/* NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV */
u_int32_t veoh_tv_stage:2;
/* NDPI_PROTOCOL_SHOUTCAST */
/* NDPI_PROTOCOL_SHOUTCAST */
u_int32_t shoutcast_stage:2;
/* NDPI_PROTOCOL_RTP */
/* NDPI_PROTOCOL_RTP */
u_int32_t rtp_special_packets_seen:1;
/* NDPI_PROTOCOL_MAIL_POP */
/* NDPI_PROTOCOL_MAIL_POP */
u_int32_t mail_pop_stage:2;
/* NDPI_PROTOCOL_MAIL_IMAP */
/* NDPI_PROTOCOL_MAIL_IMAP */
u_int32_t mail_imap_stage:3, mail_imap_starttls:2;
/* NDPI_PROTOCOL_SKYPE */
/* NDPI_PROTOCOL_SKYPE */
u_int8_t skype_packet_id;
/* NDPI_PROTOCOL_CITRIX */
/* NDPI_PROTOCOL_CITRIX */
u_int8_t citrix_packet_id;
/* NDPI_PROTOCOL_LOTUS_NOTES */
/* NDPI_PROTOCOL_LOTUS_NOTES */
u_int8_t lotus_notes_packet_id;
/* NDPI_PROTOCOL_TEAMVIEWER */
/* NDPI_PROTOCOL_TEAMVIEWER */
u_int8_t teamviewer_stage;
/* NDPI_PROTOCOL_ZMQ */
/* NDPI_PROTOCOL_ZMQ */
u_int8_t prev_zmq_pkt_len;
u_char prev_zmq_pkt[10];
/* NDPI_PROTOCOL_PPSTREAM */
/* NDPI_PROTOCOL_PPSTREAM */
u_int32_t ppstream_stage:3;
/* NDPI_PROTOCOL_MEMCACHED */
/* NDPI_PROTOCOL_MEMCACHED */
u_int8_t memcached_matches;
/* NDPI_PROTOCOL_NEST_LOG_SINK */
/* NDPI_PROTOCOL_NEST_LOG_SINK */
u_int8_t nest_log_sink_matches;
}
#ifndef WIN32
@@ -612,51 +608,51 @@ struct ndpi_flow_tcp_struct {
/* ************************************************** */
struct ndpi_flow_udp_struct {
/* NDPI_PROTOCOL_BATTLEFIELD */
/* NDPI_PROTOCOL_BATTLEFIELD */
u_int32_t battlefield_msg_id;
/* NDPI_PROTOCOL_SNMP */
/* NDPI_PROTOCOL_SNMP */
u_int32_t snmp_msg_id;
/* NDPI_PROTOCOL_BATTLEFIELD */
/* NDPI_PROTOCOL_BATTLEFIELD */
u_int32_t battlefield_stage:3;
/* NDPI_PROTOCOL_SNMP */
/* NDPI_PROTOCOL_SNMP */
u_int32_t snmp_stage:2;
/* NDPI_PROTOCOL_PPSTREAM */
/* NDPI_PROTOCOL_PPSTREAM */
u_int32_t ppstream_stage:3; // 0 - 7
/* NDPI_PROTOCOL_HALFLIFE2 */
/* NDPI_PROTOCOL_HALFLIFE2 */
u_int32_t halflife2_stage:2; // 0 - 2
/* NDPI_PROTOCOL_TFTP */
/* NDPI_PROTOCOL_TFTP */
u_int32_t tftp_stage:1;
/* NDPI_PROTOCOL_AIMINI */
/* NDPI_PROTOCOL_AIMINI */
u_int32_t aimini_stage:5;
/* NDPI_PROTOCOL_XBOX */
/* NDPI_PROTOCOL_XBOX */
u_int32_t xbox_stage:1;
/* NDPI_PROTOCOL_WINDOWS_UPDATE */
/* NDPI_PROTOCOL_WINDOWS_UPDATE */
u_int32_t wsus_stage:1;
/* NDPI_PROTOCOL_SKYPE */
/* NDPI_PROTOCOL_SKYPE */
u_int8_t skype_packet_id;
/* NDPI_PROTOCOL_TEAMVIEWER */
/* NDPI_PROTOCOL_TEAMVIEWER */
u_int8_t teamviewer_stage;
/* NDPI_PROTOCOL_EAQ */
/* NDPI_PROTOCOL_EAQ */
u_int8_t eaq_pkt_id;
u_int32_t eaq_sequence;
/* NDPI_PROTOCOL_RX */
/* NDPI_PROTOCOL_RX */
u_int32_t rx_conn_epoch;
u_int32_t rx_conn_id;
/* NDPI_PROTOCOL_MEMCACHED */
/* NDPI_PROTOCOL_MEMCACHED */
u_int8_t memcached_matches;
}
#ifndef WIN32
@@ -750,87 +746,87 @@ typedef struct {
} ndpi_port_range;
typedef enum {
NDPI_PROTOCOL_SAFE = 0, /* Surely doesn't provide risks for the network. (e.g., a news site) */
NDPI_PROTOCOL_ACCEPTABLE, /* Probably doesn't provide risks, but could be malicious (e.g., Dropbox) */
NDPI_PROTOCOL_FUN, /* Pure fun protocol, which may be prohibited by the user policy (e.g., Netflix) */
NDPI_PROTOCOL_UNSAFE, /* Probably provides risks, but could be a normal traffic. Unencrypted protocols with clear pass should be here (e.g., telnet) */
NDPI_PROTOCOL_POTENTIALLY_DANGEROUS, /* Surely is dangerous (ex. Tor). Be prepared to troubles */
NDPI_PROTOCOL_TRACKER_ADS, /* Trackers, Advertisements... */
NDPI_PROTOCOL_UNRATED /* No idea, not implemented or impossible to classify */
NDPI_PROTOCOL_SAFE = 0, /* Surely doesn't provide risks for the network. (e.g., a news site) */
NDPI_PROTOCOL_ACCEPTABLE, /* Probably doesn't provide risks, but could be malicious (e.g., Dropbox) */
NDPI_PROTOCOL_FUN, /* Pure fun protocol, which may be prohibited by the user policy (e.g., Netflix) */
NDPI_PROTOCOL_UNSAFE, /* Probably provides risks, but could be a normal traffic. Unencrypted protocols with clear pass should be here (e.g., telnet) */
NDPI_PROTOCOL_POTENTIALLY_DANGEROUS, /* Surely is dangerous (ex. Tor). Be prepared to troubles */
NDPI_PROTOCOL_TRACKER_ADS, /* Trackers, Advertisements... */
NDPI_PROTOCOL_UNRATED /* No idea, not implemented or impossible to classify */
} ndpi_protocol_breed_t;
#define NUM_BREEDS (NDPI_PROTOCOL_UNRATED+1)
/* Abstract categories to group the protocols. */
typedef enum {
NDPI_PROTOCOL_CATEGORY_UNSPECIFIED = 0, /* For general services and unknown protocols */
NDPI_PROTOCOL_CATEGORY_MEDIA, /* Multimedia and streaming */
NDPI_PROTOCOL_CATEGORY_VPN, /* Virtual Private Networks */
NDPI_PROTOCOL_CATEGORY_MAIL, /* Protocols to send/receive/sync emails */
NDPI_PROTOCOL_CATEGORY_DATA_TRANSFER, /* AFS/NFS and similar protocols */
NDPI_PROTOCOL_CATEGORY_WEB, /* Web/mobile protocols and services */
NDPI_PROTOCOL_CATEGORY_SOCIAL_NETWORK, /* Social networks */
NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT, /* Download, FTP, file transfer/sharing */
NDPI_PROTOCOL_CATEGORY_GAME, /* Online games */
NDPI_PROTOCOL_CATEGORY_CHAT, /* Instant messaging */
NDPI_PROTOCOL_CATEGORY_VOIP, /* Real-time communications and conferencing */
NDPI_PROTOCOL_CATEGORY_DATABASE, /* Protocols for database communication */
NDPI_PROTOCOL_CATEGORY_REMOTE_ACCESS, /* Remote access and control */
NDPI_PROTOCOL_CATEGORY_CLOUD, /* Online cloud services */
NDPI_PROTOCOL_CATEGORY_NETWORK, /* Network infrastructure protocols */
NDPI_PROTOCOL_CATEGORY_COLLABORATIVE, /* Software for collaborative development, including Webmail */
NDPI_PROTOCOL_CATEGORY_RPC, /* High level network communication protocols */
NDPI_PROTOCOL_CATEGORY_STREAMING, /* Streaming protocols */
NDPI_PROTOCOL_CATEGORY_SYSTEM_OS, /* System/Operating System level applications */
NDPI_PROTOCOL_CATEGORY_SW_UPDATE, /* Software update */
NDPI_PROTOCOL_CATEGORY_UNSPECIFIED = 0, /* For general services and unknown protocols */
NDPI_PROTOCOL_CATEGORY_MEDIA, /* Multimedia and streaming */
NDPI_PROTOCOL_CATEGORY_VPN, /* Virtual Private Networks */
NDPI_PROTOCOL_CATEGORY_MAIL, /* Protocols to send/receive/sync emails */
NDPI_PROTOCOL_CATEGORY_DATA_TRANSFER, /* AFS/NFS and similar protocols */
NDPI_PROTOCOL_CATEGORY_WEB, /* Web/mobile protocols and services */
NDPI_PROTOCOL_CATEGORY_SOCIAL_NETWORK, /* Social networks */
NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT, /* Download, FTP, file transfer/sharing */
NDPI_PROTOCOL_CATEGORY_GAME, /* Online games */
NDPI_PROTOCOL_CATEGORY_CHAT, /* Instant messaging */
NDPI_PROTOCOL_CATEGORY_VOIP, /* Real-time communications and conferencing */
NDPI_PROTOCOL_CATEGORY_DATABASE, /* Protocols for database communication */
NDPI_PROTOCOL_CATEGORY_REMOTE_ACCESS, /* Remote access and control */
NDPI_PROTOCOL_CATEGORY_CLOUD, /* Online cloud services */
NDPI_PROTOCOL_CATEGORY_NETWORK, /* Network infrastructure protocols */
NDPI_PROTOCOL_CATEGORY_COLLABORATIVE, /* Software for collaborative development, including Webmail */
NDPI_PROTOCOL_CATEGORY_RPC, /* High level network communication protocols */
NDPI_PROTOCOL_CATEGORY_STREAMING, /* Streaming protocols */
NDPI_PROTOCOL_CATEGORY_SYSTEM_OS, /* System/Operating System level applications */
NDPI_PROTOCOL_CATEGORY_SW_UPDATE, /* Software update */
/* See #define NUM_CUSTOM_CATEGORIES */
NDPI_PROTOCOL_CATEGORY_CUSTOM_1, /* User custom category 1 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_2, /* User custom category 2 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_3, /* User custom category 3 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_4, /* User custom category 4 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_5, /* User custom category 5 */
/* See #define NUM_CUSTOM_CATEGORIES */
NDPI_PROTOCOL_CATEGORY_CUSTOM_1, /* User custom category 1 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_2, /* User custom category 2 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_3, /* User custom category 3 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_4, /* User custom category 4 */
NDPI_PROTOCOL_CATEGORY_CUSTOM_5, /* User custom category 5 */
/* Payload Content */
NDPI_CONTENT_CATEGORY_AVI,
NDPI_CONTENT_CATEGORY_FLASH,
NDPI_CONTENT_CATEGORY_OGG,
NDPI_CONTENT_CATEGORY_MPEG,
NDPI_CONTENT_CATEGORY_QUICKTIME,
NDPI_CONTENT_CATEGORY_REALMEDIA,
NDPI_CONTENT_CATEGORY_WINDOWSMEDIA,
NDPI_CONTENT_CATEGORY_WEBM,
/* Payload Content */
NDPI_CONTENT_CATEGORY_AVI,
NDPI_CONTENT_CATEGORY_FLASH,
NDPI_CONTENT_CATEGORY_OGG,
NDPI_CONTENT_CATEGORY_MPEG,
NDPI_CONTENT_CATEGORY_QUICKTIME,
NDPI_CONTENT_CATEGORY_REALMEDIA,
NDPI_CONTENT_CATEGORY_WINDOWSMEDIA,
NDPI_CONTENT_CATEGORY_WEBM,
/* Some custom categories */
CUSTOM_CATEGORY_MINING = 99,
CUSTOM_CATEGORY_MALWARE = 100,
CUSTOM_CATEGORY_ADVERTISEMENT = 101,
CUSTOM_CATEGORY_BANNED_SITE = 102,
CUSTOM_CATEGORY_SITE_UNAVAILABLE = 103,
/* Some custom categories */
CUSTOM_CATEGORY_MINING = 99,
CUSTOM_CATEGORY_MALWARE = 100,
CUSTOM_CATEGORY_ADVERTISEMENT = 101,
CUSTOM_CATEGORY_BANNED_SITE = 102,
CUSTOM_CATEGORY_SITE_UNAVAILABLE = 103,
/*
IMPORTANT
/*
IMPORTANT
Please keep in sync with
Please keep in sync with
static const char* categories[] = { ..}
static const char* categories[] = { ..}
in ndpi_main.c
*/
in ndpi_main.c
*/
NDPI_PROTOCOL_NUM_CATEGORIES /*
NOTE: Keep this as last member
Unused as value but useful to getting the number of elements
in this datastructure
*/
NDPI_PROTOCOL_NUM_CATEGORIES /*
NOTE: Keep this as last member
Unused as value but useful to getting the number of elements
in this datastructure
*/
} ndpi_protocol_category_t;
typedef enum {
ndpi_pref_http_dont_dissect_response = 0,
ndpi_pref_dns_dont_dissect_response,
ndpi_pref_direction_detect_disable,
ndpi_pref_disable_metadata_export,
ndpi_pref_enable_category_substring_match
ndpi_pref_http_dont_dissect_response = 0,
ndpi_pref_dns_dissect_response,
ndpi_pref_direction_detect_disable,
ndpi_pref_disable_metadata_export,
ndpi_pref_enable_category_substring_match
} ndpi_detection_preference;
/* ntop extensions */
@@ -879,9 +875,9 @@ typedef struct ndpi_proto {
#include <hs/hs.h>
struct hs_list {
char *expression;
unsigned int id;
struct hs_list *next;
char *expression;
unsigned int id;
struct hs_list *next;
};
struct hs {
@@ -990,25 +986,25 @@ struct ndpi_detection_module_struct {
char ip_string[NDPI_IP_STRING_SIZE];
#endif
u_int8_t ip_version_limit;
/* NDPI_PROTOCOL_BITTORRENT */
/* NDPI_PROTOCOL_BITTORRENT */
struct hash_ip4p_table *bt_ht;
#ifdef NDPI_DETECTION_SUPPORT_IPV6
struct hash_ip4p_table *bt6_ht;
#endif
/* BT_ANNOUNCE */
/* BT_ANNOUNCE */
struct bt_announce *bt_ann;
int bt_ann_len;
/* NDPI_PROTOCOL_OOKLA */
struct ndpi_lru_cache *ookla_cache;
void *ookla_cache;
/* NDPI_PROTOCOL_TINC */
struct cache *tinc_cache;
ndpi_proto_defaults_t proto_defaults[NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS];
u_int8_t http_dont_dissect_response:1, dns_dont_dissect_response:1,
u_int8_t http_dont_dissect_response:1, dns_dissect_response:1,
direction_detect_disable:1, /* disable internal detection of packet direction */
disable_metadata_export:1, /* No metadata is exported */
enable_category_substring_match:1 /* Default is perfect match */
@@ -1071,7 +1067,7 @@ struct ndpi_flow_struct {
char *url, *content_type;
u_int8_t num_request_headers, num_response_headers;
u_int8_t request_version; /* 0=1.0 and 1=1.1. Create an enum for this? */
u_int16_t response_status_code; /* 200, 404, etc. */
u_char response_status_code[5]; /* 200, 404, etc. */
} http;
union {
@@ -1126,7 +1122,7 @@ struct ndpi_flow_struct {
char fingerprint[48];
char class_ident[48];
} dhcp;
} protos;
} protos;
/*** ALL protocol specific 64 bit variables here ***/
@@ -1135,83 +1131,90 @@ struct ndpi_flow_struct {
ndpi_protocol_category_t category;
/* NDPI_PROTOCOL_REDIS */
/* NDPI_PROTOCOL_REDIS */
u_int8_t redis_s2d_first_char, redis_d2s_first_char;
u_int16_t packet_counter; // can be 0 - 65000
u_int16_t packet_direction_counter[2];
u_int16_t byte_counter[2];
/* NDPI_PROTOCOL_BITTORRENT */
/* NDPI_PROTOCOL_BITTORRENT */
u_int8_t bittorrent_stage; // can be 0 - 255
/* NDPI_PROTOCOL_DIRECTCONNECT */
u_int8_t directconnect_stage:2; // 0 - 1
/* NDPI_PROTOCOL_DIRECTCONNECT */
u_int32_t directconnect_stage:2; // 0 - 1
/* NDPI_PROTOCOL_YAHOO */
u_int8_t sip_yahoo_voice:1;
/* NDPI_PROTOCOL_YAHOO */
u_int32_t sip_yahoo_voice:1;
/* NDPI_PROTOCOL_HTTP */
u_int8_t http_detected:1;
u_int16_t http_upper_protocol, http_lower_protocol;
/* NDPI_PROTOCOL_HTTP */
u_int32_t http_detected:1;
/* NDPI_PROTOCOL_RTSP */
u_int32_t rtsprdt_stage:2;
u_int32_t rtsp_control_flow:1;
/* NDPI_PROTOCOL_YAHOO */
u_int32_t yahoo_detection_finished:2;
/* NDPI_PROTOCOL_ZATTOO */
u_int32_t zattoo_stage:3;
/* NDPI_PROTOCOL_QQ */
u_int32_t qq_stage:3;
/* NDPI_PROTOCOL_THUNDER */
u_int32_t thunder_stage:2; // 0 - 3
/* NDPI_PROTOCOL_RTSP */
u_int8_t rtsprdt_stage:2, rtsp_control_flow:1;
/* NDPI_PROTOCOL_OSCAR */
u_int32_t oscar_ssl_voice_stage:3;
u_int32_t oscar_video_voice:1;
/* NDPI_PROTOCOL_YAHOO */
u_int8_t yahoo_detection_finished:2;
/* NDPI_PROTOCOL_FLORENSIA */
u_int32_t florensia_stage:1;
/* NDPI_PROTOCOL_ZATTOO */
u_int8_t zattoo_stage:3;
/* NDPI_PROTOCOL_SOCKS */
u_int32_t socks5_stage:2; // 0 - 3
u_int32_t socks4_stage:2; // 0 - 3
/* NDPI_PROTOCOL_QQ */
u_int8_t qq_stage:3;
/* NDPI_PROTOCOL_EDONKEY */
u_int32_t edonkey_stage:2; // 0 - 3
/* NDPI_PROTOCOL_THUNDER */
u_int8_t thunder_stage:2; // 0 - 3
/* NDPI_PROTOCOL_OSCAR */
u_int8_t oscar_ssl_voice_stage:3, oscar_video_voice:1;
/* NDPI_PROTOCOL_FTP_CONTROL */
u_int32_t ftp_control_stage:2;
/* NDPI_PROTOCOL_FLORENSIA */
u_int8_t florensia_stage:1;
/* NDPI_PROTOCOL_RTMP */
u_int32_t rtmp_stage:2;
/* NDPI_PROTOCOL_SOCKS */
u_int8_t socks5_stage:2, socks4_stage:2; // 0 - 3
/* NDPI_PROTOCOL_PANDO */
u_int32_t pando_stage:3;
/* NDPI_PROTOCOL_EDONKEY */
u_int8_t edonkey_stage:2; // 0 - 3
/* NDPI_PROTOCOL_STEAM */
u_int32_t steam_stage:3;
u_int32_t steam_stage1:3; // 0 - 4
u_int32_t steam_stage2:2; // 0 - 2
u_int32_t steam_stage3:2; // 0 - 2
/* NDPI_PROTOCOL_FTP_CONTROL */
u_int8_t ftp_control_stage:2;
/* NDPI_PROTOCOL_PPLIVE */
u_int32_t pplive_stage1:3; // 0 - 6
u_int32_t pplive_stage2:2; // 0 - 2
u_int32_t pplive_stage3:2; // 0 - 2
/* NDPI_PROTOCOL_RTMP */
u_int8_t rtmp_stage:2;
/* NDPI_PROTOCOL_STARCRAFT */
u_int32_t starcraft_udp_stage : 3; // 0-7
/* NDPI_PROTOCOL_PANDO */
u_int8_t pando_stage:3;
/* NDPI_PROTOCOL_STEAM */
u_int16_t steam_stage:3, steam_stage1:3, steam_stage2:2, steam_stage3:2;
/* NDPI_PROTOCOL_PPLIVE */
u_int8_t pplive_stage1:3, pplive_stage2:2, pplive_stage3:2;
/* NDPI_PROTOCOL_STARCRAFT */
u_int8_t starcraft_udp_stage : 3; // 0-7
/* NDPI_PROTOCOL_OPENVPN */
/* NDPI_PROTOCOL_OPENVPN */
u_int8_t ovpn_session_id[8];
u_int8_t ovpn_counter;
/* NDPI_PROTOCOL_TINC */
/* NDPI_PROTOCOL_TINC */
u_int8_t tinc_state;
struct tinc_cache_entry tinc_cache_entry;
/* NDPI_PROTOCOL_CSGO */
/* NDPI_PROTOCOL_CSGO */
u_int8_t csgo_strid[18],csgo_state,csgo_s2;
u_int32_t csgo_id2;
/* NDPI_PROTOCOL_1KXUN || NDPI_PROTOCOL_IQIYI */
/* NDPI_PROTOCOL_1KXUN || NDPI_PROTOCOL_IQIYI */
u_int16_t kxun_counter, iqiyi_counter;
/* internal structures to save functions calls */
+1 -1
View File
@@ -10,7 +10,7 @@
#
# Installation directories
#
prefix = @prefix@
prefix = /usr/local
libdir = ${prefix}/lib
includedir = ${prefix}/include/ndpi
CC = @CC@
+1 -1
View File
@@ -8550,7 +8550,7 @@ static const char *ndpi_en_impossible_bigrams[] = {
"jl", "jm", "jn", "jp", "jq", "jr", /* "js", */ "jt", "jv", "jw", "jx", "jy", "jz", "kg", "kq", "kv", "kx",
"kz", "lq", "lx", /* "mg" tamgrt.com , */ "mj", "mq", "mx", "mz", "pq", "pv", "px", "qb", "qc", "qd", "qe", "qf", "ii",
"qg", "qh", "qj", "qk", "ql", "qm", "qn", "qo", "qp", "qr", "qs", "qt", "qv", "qw", "qx", "qy", "uu",
"qz", "sx", "sz", "tq", "tx", "vb", "vc", "vd", "vf", "vg", "vh", "vj", "vm", "vn", /* "vp", Removed for vpbank.com */ "bw", /* "vk", "zr" Removed for kavkazr */
"qz", "sx", "sz", "tq", "tx", "vb", "vc", "vd", "vf", "vg", "vh", "vj", "vm", "vn", "vp", "bw", /* "vk", "zr" Removed for kavkazr */
"vq", "vt", "vw", "vx", "vz", "wq", "wv", "wx", "wz", /* "xb", foxbusiness.com */
"xg", "xj", "xk", "xv", "xz", "xw", "yd", /*"yp", Removed for paypal */
"yj", "yq", "yv", "yz", "yw", "zb", "zc", "zg", "zh", "zj", "zn", "zq", "zs", "zx", "wh", "wk",
+67 -178
View File
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include "ahocorasick.h"
#include "libcache.h"
#include "lruc.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
@@ -841,21 +842,21 @@ static int init_hyperscan(struct ndpi_detection_module_struct *ndpi_mod) {
}
need_to_be_free = (unsigned char*)calloc(sizeof(unsigned char), num_patterns + 1);
if(!need_to_be_free) {
if (!need_to_be_free) {
free(expressions);
free(ids);
return(-1);
}
for(i = 0, j = 0; host_match[i].string_to_match != NULL || host_match[i].pattern_to_match != NULL; i++) {
if(host_match[i].pattern_to_match) {
for (i = 0, j = 0; host_match[i].string_to_match != NULL || host_match[i].pattern_to_match != NULL; i++) {
if (host_match[i].pattern_to_match) {
expressions[j] = host_match[i].pattern_to_match;
ids[j] = host_match[i].protocol_id;
need_to_be_free[j] = 0;
++j;
} else {
expressions[j] = string2hex(host_match[i].string_to_match);
if(expressions[j] != NULL) {
if (expressions[j] != NULL) {
ids[j] = host_match[i].protocol_id;
need_to_be_free[j] = 1;
++j;
@@ -870,12 +871,11 @@ static int init_hyperscan(struct ndpi_detection_module_struct *ndpi_mod) {
rc = hyperscan_load_patterns(hs, j, (const char**)expressions, ids);
for(i = 0; i < j; ++i)
if(need_to_be_free[i])
for (i = 0; i < j; ++i)
if (need_to_be_free[i])
free(expressions[i]);
free(expressions), free(ids);
free(need_to_be_free);
return(rc);
}
@@ -942,8 +942,8 @@ int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod
ndpi_mod->http_dont_dissect_response = (u_int8_t)value;
break;
case ndpi_pref_dns_dont_dissect_response:
ndpi_mod->dns_dont_dissect_response = (u_int8_t)value;
case ndpi_pref_dns_dissect_response:
ndpi_mod->dns_dissect_response = (u_int8_t)value;
break;
case ndpi_pref_direction_detect_disable:
@@ -1238,11 +1238,11 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
no_master, "NestLogSink", NDPI_PROTOCOL_CATEGORY_CLOUD,
ndpi_build_default_ports(ports_a, 11095, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_MODBUS,
1 /* no subprotocol */, no_master,
no_master, "Modbus", NDPI_PROTOCOL_CATEGORY_NETWORK, /* Perhaps IoT in the future */
ndpi_build_default_ports(ports_a, 502, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_FREE_44,
0 /* can_have_a_subprotocol */, no_master,
no_master, "Free", NDPI_PROTOCOL_CATEGORY_CUSTOM_1 /* dummy */,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_FREE_45,
0 /* can_have_a_subprotocol */, no_master,
no_master, "Free", NDPI_PROTOCOL_CATEGORY_CUSTOM_1 /* dummy */,
@@ -1699,7 +1699,7 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
0 /* can_have_a_subprotocol */, no_master,
no_master, "UPnP", NDPI_PROTOCOL_CATEGORY_NETWORK,
ndpi_build_default_ports(ports_a, 1780, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 1900, 0, 0, 0, 0) /* UDP */);
ndpi_build_default_ports(ports_b, 1900, 0, 0, 0, 0) /* UDP */); /* Missing dissector: port based only */
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_TELEGRAM,
0 /* can_have_a_subprotocol */, no_master,
no_master, "Telegram", NDPI_PROTOCOL_CATEGORY_CHAT,
@@ -1991,42 +1991,21 @@ static int ac_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, AC_REP_t *match) {
m->match_num, m->patterns->astring);
#endif
{
char *whatfound = strstr(buf, m->patterns->astring);
#ifdef MATCH_DEBUG
printf("[NDPI] %s() [searching=%s][pattern=%s][%s][%c]\n",
__FUNCTION__, buf, m->patterns->astring,
whatfound ? whatfound : "<NULL>",
whatfound[-1]);
#endif
/*
The patch below allows in case of pattern ws.amazon.com
to avoid matching aws.amazon.com whereas a.ws.amazon.com
has to match
*/
if(whatfound && (whatfound != buf)
&& (m->patterns->astring[0] != '.') /* The searched patter does not start with . */
&& strchr(m->patterns->astring, '.') /* The matched pattern has a . (e.g. numeric or sym IPs) */
&& (whatfound[-1] != '.')
)
return(0);
}
/*
Return 1 for stopping to the first match.
We might consider searching for the more
specific match, paying more cpu cycles.
*/
memcpy(match, &m->patterns[0].rep, sizeof(AC_REP_t));
if(((buf_len >= min_len) && (strncmp(&buf[buf_len-min_len], m->patterns->astring, min_len) == 0))
|| (strncmp(buf, m->patterns->astring, min_len) == 0) /* begins with */
) {
)
{
#ifdef MATCH_DEBUG
printf("Found match [%s][%s] [len: %u][proto_id: %u]\n",
buf, m->patterns->astring, min_len , *matching_protocol_id);
buf, m->patterns->astring, min_len, *matching_protocol_id);
#endif
return(1); /* If the pattern found matches the string at the beginning we stop here */
} else
@@ -2322,8 +2301,8 @@ int ndpi_match_string(void *_automa, char *string_to_match) {
int ndpi_match_string_id(void *_automa, char *string_to_match, unsigned long *id) {
AC_TEXT_t ac_input_text;
AC_AUTOMATA_t *automa = (AC_AUTOMATA_t*)_automa;
AC_REP_t match = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED, NDPI_PROTOCOL_UNRATED };
AC_REP_t match = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED, NDPI_PROTOCOL_UNRATED };
*id = -1;
if((automa == NULL)
|| (string_to_match == NULL)
@@ -2359,14 +2338,11 @@ static int hyperscanCustomEventHandler(unsigned int id,
/* *********************************************** */
int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_struct,
static int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_struct,
char *name, unsigned long *id) {
#ifdef DEBUG
printf("[NDPI] %s(%s) [enable_category_substring_match: %u]\n",
__FUNCTION__, name, ndpi_struct->enable_category_substring_match);
#endif
/* printf("[NDPI] %s(%s)\n", __FUNCTION__, name); */
if(ndpi_struct->enable_category_substring_match == 0) {
if(!ndpi_struct->enable_category_substring_match) {
if(ndpi_struct->custom_categories.hostnames_hash == NULL)
return(-1);
else {
@@ -2457,7 +2433,7 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct
cache_free((cache_t)(ndpi_struct->tinc_cache));
if(ndpi_struct->ookla_cache)
ndpi_lru_free_cache(ndpi_struct->ookla_cache);
lruc_free((lruc*)ndpi_struct->ookla_cache);
if(ndpi_struct->protocols_ptree)
ndpi_Destroy_Patricia((patricia_tree_t*)ndpi_struct->protocols_ptree, free_ptree_data);
@@ -2755,8 +2731,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod,
if(sscanf(value, "%u-%u", (u_int32_t *)&range.port_low, (u_int32_t *)&range.port_high) != 2)
range.port_low = range.port_high = atoi(&elem[4]);
if(do_add)
addDefaultPort(ndpi_mod, &range, def, 1 /* Custom user proto */,
is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot, __FUNCTION__,__LINE__);
addDefaultPort(ndpi_mod, &range, def, 1 /* Custom user proto */, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot, __FUNCTION__,__LINE__);
else
removeDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot);
} else if(is_ip) {
@@ -2787,68 +2762,31 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod,
*/
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path) {
FILE *fd;
char *buffer, *old_buffer;
int chunk_len = 512, buffer_len = chunk_len, old_buffer_len;
int i, rc = -1;
fd = fopen(path, "r");
FILE *fd = fopen(path, "r");
int i;
if(fd == NULL) {
NDPI_LOG_ERR(ndpi_mod, "Unable to open file %s [%s]", path, strerror(errno));
goto error;
}
buffer = ndpi_malloc(buffer_len);
if(buffer == NULL) {
NDPI_LOG_ERR(ndpi_mod, "Memory allocation failure");
goto close_fd;
return(-1);
}
while(fd) {
char *line = buffer;
int line_len = buffer_len;
char buffer[512], *line;
while((line = fgets(line, line_len, fd)) != NULL && line[strlen(line)-1] != '\n') {
i = strlen(line);
old_buffer = buffer;
old_buffer_len = buffer_len;
buffer_len += chunk_len;
buffer = ndpi_realloc(old_buffer, old_buffer_len, buffer_len);
if(buffer == NULL) {
NDPI_LOG_ERR(ndpi_mod, "Memory allocation failure");
free(old_buffer);
goto close_fd;
}
line = &buffer[i];
line_len = chunk_len;
}
if(!line) /* safety check */
if(!(line = fgets(buffer, sizeof(buffer), fd)))
break;
i = strlen(buffer);
if((i <= 1) || (buffer[0] == '#'))
if(((i = strlen(line)) <= 1) || (line[0] == '#'))
continue;
else
buffer[i-1] = '\0';
line[i-1] = '\0';
ndpi_handle_rule(ndpi_mod, buffer, 1);
ndpi_handle_rule(ndpi_mod, line, 1);
}
rc = 0;
free(buffer);
close_fd:
fclose(fd);
error:
return(rc);
return(0);
}
/* ******************************************************************** */
@@ -3347,9 +3285,6 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
/* NINTENDO */
init_nintendo_dissector(ndpi_struct, &a, detection_bitmask);
/* MODBUS */
init_modbus_dissector(ndpi_struct, &a, detection_bitmask);
/*** Put false-positive sensitive protocols at the end ***/
/* SKYPE */
@@ -3755,7 +3690,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
if(ndpi_struct->direction_detect_disable) {
packet->packet_direction = flow->packet_direction;
} else {
if(iph != NULL && le32toh(iph->saddr) < le32toh(iph->daddr))
if(iph != NULL && iph->saddr < iph->daddr)
packet->packet_direction = 1;
#ifdef NDPI_DETECTION_SUPPORT_IPV6
@@ -3779,7 +3714,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
packet->num_retried_bytes = 0;
if(!ndpi_struct->direction_detect_disable)
packet->packet_direction = (le16toh(tcph->source) < le16toh(tcph->dest)) ? 1 : 0;
packet->packet_direction = (tcph->source < tcph->dest) ? 1 : 0;
if(tcph->syn != 0 && tcph->ack == 0 && flow->l4.tcp.seen_syn == 0 && flow->l4.tcp.seen_syn_ack == 0
&& flow->l4.tcp.seen_ack == 0) {
@@ -3843,7 +3778,7 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
}
} else if(udph != NULL) {
if(!ndpi_struct->direction_detect_disable)
packet->packet_direction = (le16toh(udph->source) < le16toh(udph->dest)) ? 1 : 0;
packet->packet_direction = (udph->source < udph->dest) ? 1 : 0;
}
if(flow->packet_counter < MAX_PACKET_COUNTER && packet->payload_packet_len) {
@@ -3963,7 +3898,8 @@ void check_ndpi_tcp_flow_func(struct ndpi_detection_module_struct *ndpi_struct,
if((proto_id != NDPI_PROTOCOL_UNKNOWN)
&& NDPI_BITMASK_COMPARE(flow->excluded_protocol_bitmask,
ndpi_struct->callback_buffer[proto_index].excluded_protocol_bitmask) == 0
&& NDPI_BITMASK_COMPARE(ndpi_struct->callback_buffer[proto_index].detection_bitmask, detection_bitmask) != 0
&& NDPI_BITMASK_COMPARE(ndpi_struct->callback_buffer[proto_index].detection_bitmask,
detection_bitmask) != 0
&& (ndpi_struct->callback_buffer[proto_index].ndpi_selection_bitmask & *ndpi_selection_packet) == ndpi_struct->callback_buffer[proto_index].ndpi_selection_bitmask) {
if((flow->guessed_protocol_id != NDPI_PROTOCOL_UNKNOWN)
&& (ndpi_struct->proto_defaults[flow->guessed_protocol_id].func != NULL))
@@ -3981,6 +3917,7 @@ void check_ndpi_tcp_flow_func(struct ndpi_detection_module_struct *ndpi_struct,
detection_bitmask) != 0) {
ndpi_struct->callback_buffer_tcp_payload[a].func(ndpi_struct, flow);
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN)
break; /* Stop after detecting the first protocol */
}
@@ -4383,20 +4320,19 @@ int ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_str)
/* ********************************************************************************* */
int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t saddr,
u_int32_t daddr,
const struct ndpi_iphdr *iph,
ndpi_protocol *ret) {
if(ndpi_struct->custom_categories.categories_loaded) {
prefix_t prefix;
patricia_node_t *node;
/* Make sure all in network byte order otherwise compares wont work */
fill_prefix_v4(&prefix, (struct in_addr *)&saddr,
fill_prefix_v4(&prefix, (struct in_addr *)&iph->saddr,
32, ((patricia_tree_t*)ndpi_struct->protocols_ptree)->maxbits);
node = ndpi_patricia_search_best(ndpi_struct->custom_categories.ipAddresses, &prefix);
if(!node) {
fill_prefix_v4(&prefix, (struct in_addr *)&daddr,
fill_prefix_v4(&prefix, (struct in_addr *)&iph->daddr,
32, ((patricia_tree_t*)ndpi_struct->protocols_ptree)->maxbits);
node = ndpi_patricia_search_best(ndpi_struct->custom_categories.ipAddresses, &prefix);
}
@@ -4411,14 +4347,12 @@ int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_str
return 0;
}
/* ********************************************************************************* */
void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol *ret) {
if(ndpi_struct->custom_categories.categories_loaded) {
if(flow->packet.iph) {
if(ndpi_fill_ip_protocol_category(ndpi_struct, flow->packet.iph->saddr, flow->packet.iph->daddr, ret)) {
if(ndpi_fill_ip_protocol_category(ndpi_struct, flow->packet.iph, ret)) {
flow->category = ret->category;
return;
}
@@ -4463,7 +4397,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
if(ndpi_struct->ndpi_log_level >= NDPI_LOG_TRACE)
NDPI_LOG(flow ? flow->detected_protocol_stack[0]:NDPI_PROTOCOL_UNKNOWN,
ndpi_struct, NDPI_LOG_TRACE, "START packet processing\n");
ndpi_struct, NDPI_LOG_TRACE, "START packet processing\n");
if(flow == NULL)
return(ret);
@@ -4794,13 +4728,14 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
{
u_int32_t a;
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->packet_lines_parsed_complete != 0)
return;
packet->packet_lines_parsed_complete = 1;
packet->parsed_lines = 0;
packet->empty_line_position_set = 0;
packet->host_line.ptr = NULL;
packet->host_line.len = 0;
packet->referer_line.ptr = NULL;
@@ -4841,6 +4776,7 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
packet->line[packet->parsed_lines].len = 0;
for(a = 0; a < packet->payload_packet_len; a++) {
if((a + 1) == packet->payload_packet_len)
return; /* Return if only one byte remains (prevent invalid reads past end-of-buffer) */
@@ -4849,28 +4785,22 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
/* First line of a HTTP response parsing. Expected a "HTTP/1.? ???" */
if(packet->parsed_lines == 0 && packet->line[0].len >= NDPI_STATICSTRING_LEN("HTTP/1.X 200 ") &&
strncasecmp((const char *)packet->line[0].ptr, "HTTP/1.", NDPI_STATICSTRING_LEN("HTTP/1.")) == 0 &&
packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.X ")] > '0' && /* response code between 000 and 699 */
packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.X ")] < '6') {
packet->http_response.ptr = &packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.1 ")];
packet->http_response.len = packet->line[0].len - NDPI_STATICSTRING_LEN("HTTP/1.1 ");
packet->http_num_headers++;
/* Set server HTTP response code */
if(packet->payload_packet_len >= 12) {
char buf[4];
/* Set server HTTP response code */
strncpy(buf, (char*)&packet->payload[9], 3);
buf[3] = '\0';
flow->http.response_status_code = atoi(buf);
/* https://en.wikipedia.org/wiki/List_of_HTTP_status_codes */
if((flow->http.response_status_code < 100) || (flow->http.response_status_code > 509))
flow->http.response_status_code = 0; /* Out of range */
}
strncasecmp((const char *)packet->line[0].ptr, "HTTP/1.", NDPI_STATICSTRING_LEN("HTTP/1.")) == 0 &&
packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.X ")] > '0' && /* response code between 000 and 699 */
packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.X ")] < '6') {
packet->http_response.ptr = &packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.1 ")];
packet->http_response.len = packet->line[0].len - NDPI_STATICSTRING_LEN("HTTP/1.1 ");
packet->http_num_headers++;
/* Set server HTTP response code */
strncpy((char*)flow->http.response_status_code, (char*)packet->http_response.ptr, 3);
flow->http.response_status_code[4]='\0';
NDPI_LOG_DBG2(ndpi_struct,
"ndpi_parse_packet_line_info: HTTP response parsed: \"%.*s\"\n",
packet->http_response.len, packet->http_response.ptr);
}
/* "Server:" header line in HTTP response */
if(packet->line[packet->parsed_lines].len > NDPI_STATICSTRING_LEN("Server:") + 1
&& strncasecmp((const char *)packet->line[packet->parsed_lines].ptr, "Server:", NDPI_STATICSTRING_LEN("Server:")) == 0) {
@@ -5320,8 +5250,9 @@ void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow) {
if(flow) {
int a;
for(a = 0; a < NDPI_PROTOCOL_SIZE; a++)
flow->detected_protocol_stack[a] = NDPI_PROTOCOL_UNKNOWN;
for(a = 0; a < NDPI_PROTOCOL_SIZE; a++) {
flow->detected_protocol_stack[a] = NDPI_PROTOCOL_UNKNOWN;
}
}
}
@@ -6242,48 +6173,6 @@ void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l)
/* ******************************************************************** */
/* LRU cache */
struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries) {
struct ndpi_lru_cache *c = (struct ndpi_lru_cache*)malloc(sizeof(struct ndpi_lru_cache));
if(!c) return(NULL);
c->entries = (u_int32_t*)calloc(num_entries, sizeof(u_int32_t));
if(!c->entries) {
free(c);
return(NULL);
} else
c->num_entries = num_entries;
return(c);
}
void ndpi_lru_free_cache(struct ndpi_lru_cache *c) {
free(c->entries);
free(c);
}
u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int8_t clean_key_when_found) {
u_int32_t slot = key % c->num_entries;
if(c->entries[slot] == key) {
if(clean_key_when_found) c->entries[slot] = 0;
return(1);
} else
return(0);
}
void ndpi_lru_add_to_cache(struct ndpi_lru_cache *c, u_int32_t key) {
u_int32_t slot = key % c->num_entries;
c->entries[slot] = key;
}
/* ******************************************************************** */
/*
NOTE:
- Leave fields empty/zero when information is missing (e.g. with ICMP ports are zero)
+14 -16
View File
@@ -31,22 +31,20 @@ static void ndpi_check_apple_push(struct ndpi_detection_module_struct *ndpi_stru
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->iph) {
/* https://support.apple.com/en-us/HT203609 */
if(((ntohl(packet->iph->saddr) & 0xFF000000 /* 255.0.0.0 */) == 0x11000000 /* 17.0.0.0/8 */)
|| ((ntohl(packet->iph->daddr) & 0xFF000000 /* 255.0.0.0 */) == 0x11000000 /* 17.0.0.0/8 */)) {
u_int16_t apple_push_port = ntohs(5223);
u_int16_t notification_apn_port = ntohs(2195);
u_int16_t apn_feedback_port = ntohs(2196);
if(((packet->tcp->source == apple_push_port) || (packet->tcp->dest == apple_push_port))
|| ((packet->tcp->source == notification_apn_port) || (packet->tcp->dest == notification_apn_port))
|| ((packet->tcp->source == apn_feedback_port) || (packet->tcp->dest == apn_feedback_port))
) {
NDPI_LOG_INFO(ndpi_struct, "found apple_push\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_APPLE_PUSH, NDPI_PROTOCOL_UNKNOWN);
return;
}
/* https://support.apple.com/en-us/HT203609 */
if(((ntohl(packet->iph->saddr) & 0xFF000000 /* 255.0.0.0 */) == 0x11000000 /* 17.0.0.0/8 */)
|| ((ntohl(packet->iph->daddr) & 0xFF000000 /* 255.0.0.0 */) == 0x11000000 /* 17.0.0.0/8 */)) {
u_int16_t apple_push_port = ntohs(5223);
u_int16_t notification_apn_port = ntohs(2195);
u_int16_t apn_feedback_port = ntohs(2196);
if(((packet->tcp->source == apple_push_port) || (packet->tcp->dest == apple_push_port))
|| ((packet->tcp->source == notification_apn_port) || (packet->tcp->dest == notification_apn_port))
|| ((packet->tcp->source == apn_feedback_port) || (packet->tcp->dest == apn_feedback_port))
) {
NDPI_LOG_INFO(ndpi_struct, "found apple_push\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_APPLE_PUSH, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
+1 -1
View File
@@ -129,7 +129,7 @@ void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
// check values in header
if(h->version == 1) {
if(h->type == CON || h->type == NO_CON || h->type == ACK || h->type == RST ) {
if(h->tkl < 8) {
if(h->tkl == 0 || h->tkl < 8) {
if((h->code >= 0 && h->code <= 5) || (h->code >= 65 && h->code <= 69) ||
(h->code >= 128 && h->code <= 134) || (h->code >= 140 && h->code <= 143) ||
(h->code >= 160 && h->code <= 165)) {
+25 -27
View File
@@ -36,9 +36,9 @@
static u_int16_t get16(int *i, const u_int8_t *payload) {
u_int16_t v = *(u_int16_t*)&payload[*i];
(*i) += 2;
return(ntohs(v));
}
@@ -52,7 +52,7 @@ static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
else {
u_int8_t len = payload[i];
u_int8_t off = len + 1;
if(off == 0) /* Bad packet */
return(0);
else
@@ -63,27 +63,25 @@ static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
/* *********************************************** */
void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
int x, payload_offset;
int x;
u_int8_t is_query;
u_int16_t s_port = 0, d_port = 0;
NDPI_LOG_DBG(ndpi_struct, "search DNS\n");
if(flow->packet.udp != NULL) {
s_port = ntohs(flow->packet.udp->source);
d_port = ntohs(flow->packet.udp->dest);
payload_offset = 0;
x = 0;
} else if(flow->packet.tcp != NULL) /* pkt size > 512 bytes */ {
s_port = ntohs(flow->packet.tcp->source);
d_port = ntohs(flow->packet.tcp->dest);
payload_offset = 2;
x = 2;
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
x = payload_offset;
if((s_port == 53 || d_port == 53 || d_port == 5355)
&& (flow->packet.payload_packet_len > sizeof(struct ndpi_dns_packet_header)+x)) {
struct ndpi_dns_packet_header dns_header;
@@ -120,7 +118,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
if(flow->packet.payload[x] == '\0') {
x++;
flow->protos.dns.query_type = get16(&x, flow->packet.payload);
#ifdef DNS_DEBUG
#ifdef DNS_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "query_type=%2d\n", flow->protos.dns.query_type);
#endif
break;
@@ -130,6 +128,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
}
} else
invalid = 1;
} else {
/* DNS Reply */
@@ -141,15 +140,15 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
|| ((dns_header.additional_rrs > 0) && (dns_header.additional_rrs <= NDPI_MAX_DNS_REQUESTS)))
) {
/* This is a good reply */
if(ndpi_struct->dns_dont_dissect_response == 0) {
if(ndpi_struct->dns_dissect_response) {
x++;
if(flow->packet.payload[x] != '\0') {
while((x < flow->packet.payload_packet_len)
&& (flow->packet.payload[x] != '\0')) {
x++;
}
x++;
}
@@ -161,7 +160,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
for(num = 0; num < dns_header.num_answers; num++) {
u_int16_t data_len;
if((x+6) >= flow->packet.payload_packet_len) {
break;
}
@@ -170,7 +169,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
break;
} else
x += data_len;
rsp_type = get16(&x, flow->packet.payload);
flow->protos.dns.rsp_type = rsp_type;
break;
@@ -186,7 +185,8 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
}
/* extract host name server */
int j = 0, max_len = sizeof(flow->host_server_name)-1, off = sizeof(struct ndpi_dns_packet_header) + 1 + payload_offset;
int j = 0, max_len = sizeof(flow->host_server_name)-1, off = sizeof(struct ndpi_dns_packet_header) + 1;
while(off < flow->packet.payload_packet_len && flow->packet.payload[off] != '\0') {
flow->host_server_name[j] = flow->packet.payload[off];
if(j < max_len) {
@@ -199,11 +199,9 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
off++;
}
if(is_query && (ndpi_struct->dns_dont_dissect_response == 0)) {
// dpi_set_detected_protocol(ndpi_struct, flow, (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
return; /* The response will set the verdict */
}
if(is_query && ndpi_struct->dns_dissect_response)
return; /* The response will set the verdict */
flow->host_server_name[j] = '\0';
flow->protos.dns.num_queries = (u_int8_t)dns_header.num_queries,
@@ -211,33 +209,33 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
if(j > 0) {
ndpi_protocol_match_result ret_match;
ndpi_match_host_subprotocol(ndpi_struct, flow,
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
&ret_match,
NDPI_PROTOCOL_DNS);
}
#ifdef DNS_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "[num_queries=%d][num_answers=%d][reply_code=%u][rsp_type=%u][host_server_name=%s]\n",
flow->protos.dns.num_queries, flow->protos.dns.num_answers,
flow->protos.dns.reply_code, flow->protos.dns.rsp_type, flow->host_server_name
);
#endif
if(flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
/**
Do not set the protocol with DNS if ndpi_match_host_subprotocol() has
matched a subprotocol
**/
NDPI_LOG_INFO(ndpi_struct, "found DNS\n");
NDPI_LOG_INFO(ndpi_struct, "found DNS\n");
ndpi_set_detected_protocol(ndpi_struct, flow, (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
}
}
}
}
void init_dns_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+2 -1
View File
@@ -31,7 +31,8 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
/* H323 */
if(packet->payload_packet_len >= 3
&& (packet->payload[0] == 0x03)
&& (packet->payload[1] == 0x00)) {
&& (packet->payload[1] == 0x00)
&& (packet->payload[2] == 0x00)) {
struct tpkt *t = (struct tpkt*)packet->payload;
u_int16_t len = ntohs(t->len);
+132 -164
View File
@@ -26,43 +26,29 @@
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HTTP
#include "ndpi_api.h"
#include <stdlib.h>
#include "lruc.h"
/* global variables used for 1kxun protocol and iqiyi service */
static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t category) {
#ifdef DEBUG
printf("[%s] [http_dont_dissect_response: %u]->> %s\n", __FUNCTION__,
ndpi_struct->http_dont_dissect_response, flow->http.response_status_code);
#endif
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
/* This is HTTP and it is not a sub protocol (e.g. skype or dropbox) */
ndpi_search_tcp_or_udp(ndpi_struct, flow);
/* If no custom protocol has been detected */
if(flow->guessed_host_protocol_id != NDPI_PROTOCOL_UNKNOWN) {
ndpi_int_reset_protocol(flow);
flow->http_upper_protocol = flow->guessed_host_protocol_id, flow->http_lower_protocol = NDPI_PROTOCOL_HTTP;
ndpi_set_detected_protocol(ndpi_struct, flow, flow->guessed_host_protocol_id, NDPI_PROTOCOL_HTTP);
} else
flow->http_upper_protocol = NDPI_PROTOCOL_HTTP, flow->http_lower_protocol = NDPI_PROTOCOL_UNKNOWN;
if(ndpi_struct->http_dont_dissect_response)
ndpi_set_detected_protocol(ndpi_struct, flow, flow->http_upper_protocol, flow->http_lower_protocol);
else {
flow->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
flow->packet.detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->packet.detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
}
} else {
if((!ndpi_struct->http_dont_dissect_response) && (flow->http.response_status_code == 0)) {
flow->http_upper_protocol = flow->detected_protocol_stack[0], flow->http_lower_protocol = flow->detected_protocol_stack[1];
flow->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
flow->packet.detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN, flow->packet.detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
}
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_UNKNOWN);
flow->http_detected = 1, flow->guessed_category = category;
}
flow->http_detected = 1, flow->guessed_category = category;
}
#ifdef NDPI_CONTENT_CATEGORY_FLASH
@@ -93,7 +79,7 @@ static void avi_check_http_payload(struct ndpi_detection_module_struct *ndpi_str
NDPI_LOG_DBG2(ndpi_struct, "called avi_check_http_payload: %u %u %u\n",
packet->empty_line_position_set, flow->l4.tcp.http_empty_line_seen, packet->empty_line_position);
packet->empty_line_position_set, flow->l4.tcp.http_empty_line_seen, packet->empty_line_position);
if(packet->empty_line_position_set == 0 && flow->l4.tcp.http_empty_line_seen == 0)
return;
@@ -139,7 +125,7 @@ static void teamviewer_check_http_payload(struct ndpi_detection_module_struct *n
const u_int8_t *pos;
NDPI_LOG_DBG2(ndpi_struct, "called teamviewer_check_http_payload: %u %u %u\n",
packet->empty_line_position_set, flow->l4.tcp.http_empty_line_seen, packet->empty_line_position);
packet->empty_line_position_set, flow->l4.tcp.http_empty_line_seen, packet->empty_line_position);
if(packet->empty_line_position_set == 0 || (packet->empty_line_position + 5) > (packet->payload_packet_len))
return;
@@ -185,10 +171,10 @@ static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
if((flow->l4.tcp.http_stage == 0) || (flow->http.url && flow->http_detected)) {
char *double_col = strchr((char*)flow->host_server_name, ':');
ndpi_protocol_match_result ret_match;
if(double_col) double_col[0] = '\0';
char *double_col = strchr((char*)flow->host_server_name, ':');
ndpi_protocol_match_result ret_match;
if(double_col) double_col[0] = '\0';
/**
NOTE
@@ -212,14 +198,6 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t a;
if((!ndpi_struct->http_dont_dissect_response) && flow->http_detected && (flow->http.response_status_code != 0)) {
ndpi_set_detected_protocol(ndpi_struct, flow, flow->http_upper_protocol, flow->http_lower_protocol);
#ifdef DEBUG
printf("[%s] [http_dont_dissect_response: %u]->> %s\n",
__FUNCTION__, ndpi_struct->http_dont_dissect_response, flow->http.response_status_code);
#endif
return;
}
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* PPStream */
@@ -299,8 +277,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) {
/**
Format examples:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ....
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ....
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
*/
if(packet->user_agent_line.len > 7) {
char ua[256];
@@ -330,22 +308,22 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token
&& ((strcmp(token, "U") == 0)
|| (strncmp(token, "MSIE", 4) == 0))) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "Update", 6) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "AOL", 3) == 0)) {
&& ((strcmp(token, "U") == 0)
|| (strncmp(token, "MSIE", 4) == 0))) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
}
}
if(token && (strncmp(token, "Update", 6) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "AOL", 3) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
}
}
}
}
@@ -362,7 +340,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
}
NDPI_LOG_DBG2(ndpi_struct, "User Agent Type line found %.*s\n",
packet->user_agent_line.len, packet->user_agent_line.ptr);
packet->user_agent_line.len, packet->user_agent_line.ptr);
}
/* check for host line */
@@ -370,37 +348,37 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
u_int len;
NDPI_LOG_DBG2(ndpi_struct, "HOST line found %.*s\n",
packet->host_line.len, packet->host_line.ptr);
packet->host_line.len, packet->host_line.ptr);
/* call ndpi_match_host_subprotocol to see if there is a match with known-host HTTP subprotocol */
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
ndpi_protocol_match_result ret_match;
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char*)packet->host_line.ptr,
packet->host_line.len,
&ret_match,
NDPI_PROTOCOL_HTTP);
}
/* Copy result for nDPI apps */
if(!ndpi_struct->disable_metadata_export) {
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
flow->host_server_name[len] = '\0';
}
flow->server_id = flow->dst;
if(packet->forwarded_line.ptr) {
len = ndpi_min(packet->forwarded_line.len, sizeof(flow->protos.http.nat_ip)-1);
if(!ndpi_struct->disable_metadata_export) {
strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len);
flow->protos.http.nat_ip[len] = '\0';
}
len = ndpi_min(packet->forwarded_line.len, sizeof(flow->protos.http.nat_ip)-1);
if(!ndpi_struct->disable_metadata_export) {
strncpy((char*)flow->protos.http.nat_ip, (char*)packet->forwarded_line.ptr, len);
flow->protos.http.nat_ip[len] = '\0';
}
}
if(!ndpi_struct->http_dont_dissect_response)
if(ndpi_struct->http_dont_dissect_response)
parseHttpSubprotocol(ndpi_struct, flow);
/**
@@ -425,28 +403,26 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
&& ((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
&& (packet->http_origin.len > 0)) {
ndpi_protocol_match_result ret_match;
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)packet->http_origin.ptr,
packet->http_origin.len,
&ret_match,
NDPI_PROTOCOL_HTTP);
}
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_HTTP) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP/%s\n",
ndpi_get_proto_name(ndpi_struct, packet->detected_protocol_stack[0]));
NDPI_LOG_INFO(ndpi_struct, "found HTTP/%s\n",
ndpi_get_proto_name(ndpi_struct, packet->detected_protocol_stack[0]));
ndpi_int_http_add_connection(ndpi_struct, flow, packet->detected_protocol_stack[0]);
return; /* We have identified a sub-protocol so we're done */
}
}
}
#if 0
if(!ndpi_struct->http_dont_dissect_response && flow->http_detected)
parseHttpSubprotocol(ndpi_struct, flow);
#endif
if(flow->guessed_protocol_id == NDPI_PROTOCOL_UNKNOWN)
flow->guessed_protocol_id = NDPI_PROTOCOL_HTTP;
@@ -454,7 +430,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
/* check for accept line */
if(packet->accept_line.ptr != NULL) {
NDPI_LOG_DBG2(ndpi_struct, "Accept line found %.*s\n",
packet->accept_line.len, packet->accept_line.ptr);
packet->accept_line.len, packet->accept_line.ptr);
if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(ndpi_struct->detection_bitmask,
NDPI_PROTOCOL_RTSP) != 0) {
rtsp_parse_packet_acceptline(ndpi_struct, flow);
@@ -462,28 +438,26 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
}
/* search for line startin with "Icy-MetaData" */
for (a = 0; a < packet->parsed_lines; a++) {
for (a = 0; a < packet->parsed_lines; a++) {
if(packet->line[a].len > 11 && memcmp(packet->line[a].ptr, "Icy-MetaData", 12) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MPEG: Icy-MetaData\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_CATEGORY_MPEG);
return;
}
NDPI_LOG_INFO(ndpi_struct, "found MPEG: Icy-MetaData\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_CATEGORY_MPEG);
return;
}
}
if(packet->content_line.ptr != NULL && packet->content_line.len != 0) {
NDPI_LOG_DBG2(ndpi_struct, "Content Type line found %.*s\n",
packet->content_line.len, packet->content_line.ptr);
packet->content_line.len, packet->content_line.ptr);
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
ndpi_protocol_match_result ret_match;
ndpi_match_content_subprotocol(ndpi_struct, flow,
(char*)packet->content_line.ptr, packet->content_line.len,
&ret_match, NDPI_PROTOCOL_HTTP);
}
}
ndpi_int_http_add_connection(ndpi_struct, flow, packet->detected_protocol_stack[0]);
}
static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -512,22 +486,22 @@ static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct,
#define STATIC_STRING_L(a) {.str=a, .len=sizeof(a)-1 }
static struct l_string {
const char *str;
size_t len;
const char *str;
size_t len;
} http_methods[] = {
STATIC_STRING_L("GET "),
STATIC_STRING_L("POST "),
STATIC_STRING_L("OPTIONS "),
STATIC_STRING_L("HEAD "),
STATIC_STRING_L("PUT "),
STATIC_STRING_L("DELETE "),
STATIC_STRING_L("CONNECT "),
STATIC_STRING_L("PROPFIND "),
STATIC_STRING_L("REPORT ") };
STATIC_STRING_L("GET "),
STATIC_STRING_L("POST "),
STATIC_STRING_L("OPTIONS "),
STATIC_STRING_L("HEAD "),
STATIC_STRING_L("PUT "),
STATIC_STRING_L("DELETE "),
STATIC_STRING_L("CONNECT "),
STATIC_STRING_L("PROPFIND "),
STATIC_STRING_L("REPORT ") };
static const char *http_fs = "CDGHOPR";
static uint8_t non_ctrl(uint8_t c) {
return c < 32 ? '.':c;
return c < 32 ? '.':c;
}
static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -536,9 +510,9 @@ static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *nd
int i;
NDPI_LOG_DBG2(ndpi_struct, "====>>>> HTTP: %c%c%c%c [len: %u]\n",
non_ctrl(packet->payload[0]), non_ctrl(packet->payload[1]),
non_ctrl(packet->payload[2]), non_ctrl(packet->payload[3]),
packet->payload_packet_len);
non_ctrl(packet->payload[0]), non_ctrl(packet->payload[1]),
non_ctrl(packet->payload[2]), non_ctrl(packet->payload[3]),
packet->payload_packet_len);
/* Check first char */
if(!strchr(http_fs,packet->payload[0])) return 0;
@@ -546,11 +520,11 @@ static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *nd
FIRST PAYLOAD PACKET FROM CLIENT
**/
for(i=0; i < sizeof(http_methods)/sizeof(http_methods[0]); i++) {
if(packet->payload_packet_len >= http_methods[i].len &&
memcmp(packet->payload,http_methods[i].str,http_methods[i].len) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "HTTP: %sFOUND\n",http_methods[i].str);
return http_methods[i].len;
}
if(packet->payload_packet_len >= http_methods[i].len &&
memcmp(packet->payload,http_methods[i].str,http_methods[i].len) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "HTTP: %sFOUND\n",http_methods[i].str);
return http_methods[i].len;
}
}
return 0;
}
@@ -582,7 +556,7 @@ static void http_bitmask_exclude_other(struct ndpi_flow_struct *flow)
/*************************************************************************************************/
static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t filename_start; /* the filename in the request method line, e.g., "GET filename_start..."*/
@@ -602,20 +576,6 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(packet->payload_packet_len >= 7 && memcmp(packet->payload, "HTTP/1.", 7) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP response\n");
if(packet->payload_packet_len >= 12) {
char buf[4];
/* Set server HTTP response code */
strncpy(buf, (char*)&packet->payload[9], 3);
buf[3] = '\0';
flow->http.response_status_code = atoi(buf);
/* https://en.wikipedia.org/wiki/List_of_HTTP_status_codes */
if((flow->http.response_status_code < 100) || (flow->http.response_status_code > 509))
flow->http.response_status_code = 0; /* Out of range */
}
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
@@ -626,7 +586,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
flow->l4.tcp.http_stage = 1;
return;
}
if((packet->payload_packet_len == 40) && (flow->l4.tcp.http_stage == 0)) {
/*
-> QR O06L0072-6L91-4O43-857J-K8OO172L6L51
@@ -640,11 +600,11 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
&& (packet->payload[21] == '-')
&& (packet->payload[26] == '-')
&& (packet->payload[39] == 0x0A)
)
flow->l4.tcp.http_stage = 1;
return;
)
flow->l4.tcp.http_stage = 1;
return;
}
if((packet->payload_packet_len == 23) && (memcmp(packet->payload, "<policy-file-request/>", 23) == 0)) {
/*
<policy-file-request/>
@@ -657,31 +617,35 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
if(ndpi_struct->ookla_cache == NULL)
ndpi_struct->ookla_cache = ndpi_lru_cache_init(1024);
ndpi_struct->ookla_cache = lruc_new(4*1024, 1024);
if(packet->iph != NULL && ndpi_struct->ookla_cache != NULL) {
if(packet->tcp->source == htons(8080))
ndpi_lru_add_to_cache(ndpi_struct->ookla_cache, packet->iph->saddr);
else
ndpi_lru_add_to_cache(ndpi_struct->ookla_cache, packet->iph->daddr);
if(ndpi_struct->ookla_cache != NULL) {
u_int8_t *dummy = (u_int8_t*)ndpi_malloc(sizeof(u_int8_t));
if(dummy) {
if(packet->tcp->source == htons(8080))
lruc_set((lruc*)ndpi_struct->ookla_cache, (void*)&packet->iph->saddr, 4, dummy, 1);
else
lruc_set((lruc*)ndpi_struct->ookla_cache, (void*)&packet->iph->daddr, 4, dummy, 1);
}
}
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude_other(flow);
return;
}
NDPI_LOG_DBG2(ndpi_struct,
"Filename HTTP found: %d, we look for line info..\n", filename_start);
"Filename HTTP found: %d, we look for line info..\n", filename_start);
ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->parsed_lines <= 1) {
NDPI_LOG_DBG2(ndpi_struct,
"Found just one line, we will look further for the next packet...\n");
"Found just one line, we will look further for the next packet...\n");
packet->http_method.ptr = packet->line[0].ptr;
packet->http_method.len = filename_start - 1;
@@ -692,10 +656,10 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
}
NDPI_LOG_DBG2(ndpi_struct,
"Found more than one line, we look further for the next packet...\n");
"Found more than one line, we look further for the next packet...\n");
if(packet->line[0].len >= (9 + filename_start)
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) { /* Request line complete. Ex. "GET / HTTP/1.1" */
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) { /* Request line complete. Ex. "GET / HTTP/1.1" */
packet->http_url_name.ptr = &packet->payload[filename_start];
packet->http_url_name.len = packet->line[0].len - (filename_start + 9);
@@ -705,13 +669,14 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
// Set the HTTP requested version: 0=HTTP/1.0 and 1=HTTP/1.1
if(memcmp(&packet->line[0].ptr[packet->line[0].len - 1], "1", 1) == 0)
flow->http.request_version = 1;
flow->http.request_version = 1;
else
flow->http.request_version = 0;
flow->http.request_version = 0;
/* Set the first found headers in request */
flow->http.num_request_headers = packet->http_num_headers;
/* Check for Ookla */
if((packet->referer_line.len > 0)
&& ndpi_strnstr((const char *)packet->referer_line.ptr, "www.speedtest.net", packet->referer_line.len)) {
@@ -721,22 +686,22 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
/* Check for additional field introduced by Steam */
int x = 1;
if(packet->line[x].len >= 11 && (memcmp(packet->line[x].ptr, "x-steam-sid", 11)) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found STEAM\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_STEAM);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
NDPI_LOG_INFO(ndpi_struct, "found STEAM\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_STEAM);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
/* Check for additional field introduced by Facebook */
x = 1;
while(packet->line[x].len != 0) {
if(packet->line[x].len >= 12 && (memcmp(packet->line[x].ptr, "X-FB-SIM-HNI", 12)) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found FACEBOOK\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_FACEBOOK);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
x++;
if(packet->line[x].len >= 12 && (memcmp(packet->line[x].ptr, "X-FB-SIM-HNI", 12)) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found FACEBOOK\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_FACEBOOK);
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
x++;
}
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
@@ -781,23 +746,23 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
}
}
#endif
if((packet->http_url_name.len > 7)
&& (!strncmp((const char*) packet->http_url_name.ptr, "http://", 7))) {
&& (!strncmp((const char*) packet->http_url_name.ptr, "http://", 7))) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP_PROXY\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_PROXY);
check_content_type_and_change_protocol(ndpi_struct, flow);
}
if(filename_start == 8 && (memcmp(packet->payload, "CONNECT ", 8) == 0)) {
/* nathan@getoffmalawn.com */
/* nathan@getoffmalawn.com */
NDPI_LOG_INFO(ndpi_struct, "found HTTP_CONNECT\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_CONNECT);
check_content_type_and_change_protocol(ndpi_struct, flow);
}
NDPI_LOG_DBG2(ndpi_struct,
"HTTP START Found, we will look for sub-protocols (content and host)...\n");
"HTTP START Found, we will look for sub-protocols (content and host)...\n");
if(packet->host_line.ptr != NULL) {
/**
@@ -810,11 +775,11 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(ndpi_struct->http_dont_dissect_response) {
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) /* No subprotocol found */
NDPI_LOG_INFO(ndpi_struct, "found HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
} else {
flow->http_detected = 1;
NDPI_LOG_DBG2(ndpi_struct,
"HTTP START Found, we will look further for the response...\n");
"HTTP START Found, we will look further for the response...\n");
flow->l4.tcp.http_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
}
@@ -825,21 +790,23 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude_other(flow);
} else if((flow->l4.tcp.http_stage == 1) || (flow->l4.tcp.http_stage == 2)) {
NDPI_LOG_DBG2(ndpi_struct, "HTTP stage %u: \n", flow->l4.tcp.http_stage);
} else if((flow->l4.tcp.http_stage == 1) || (flow->l4.tcp.http_stage == 2)) {
NDPI_LOG_DBG2(ndpi_struct, "HTTP stage %u: \n", flow->l4.tcp.http_stage);
if((packet->payload_packet_len == 34) && (flow->l4.tcp.http_stage == 1)) {
if((packet->payload[5] == ' ') && (packet->payload[9] == ' ')) {
goto ookla_found;
}
}
if((packet->payload_packet_len > 6) && memcmp(packet->payload, "HELLO ", 6) == 0) {
/* This looks like Ookla */
/* This looks like Ookla */
goto ookla_found;
} else
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OOKLA);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OOKLA);
/**
At first check, if this is for sure a response packet (in another direction. If not, if HTTP is detected do nothing now and return,
otherwise check the second packet for the HTTP request
@@ -850,7 +817,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
return;
NDPI_LOG_DBG2(ndpi_struct,
" SECOND PAYLOAD TRAFFIC FROM CLIENT, FIRST PACKET MIGHT HAVE BEEN HTTP...UNKNOWN TRAFFIC, HERE FOR HTTP again.. \n");
" SECOND PAYLOAD TRAFFIC FROM CLIENT, FIRST PACKET MIGHT HAVE BEEN HTTP...UNKNOWN TRAFFIC, HERE FOR HTTP again.. \n");
ndpi_parse_packet_line_info(ndpi_struct, flow);
@@ -872,14 +839,14 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
}
// http://www.slideshare.net/DSPIP/rtsp-analysis-wireshark
if(packet->line[0].len >= 9
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) {
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
check_content_type_and_change_protocol(ndpi_struct, flow);
NDPI_LOG_DBG2(ndpi_struct,
"HTTP START Found in 2. packet, we will look further for the response....\n");
"HTTP START Found in 2. packet, we will look further for the response....\n");
flow->http_detected = 1;
}
@@ -912,8 +879,9 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
ndpi_parse_packet_line_info(ndpi_struct, flow);
check_content_type_and_change_protocol(ndpi_struct, flow);
if(packet->packet_direction == 1 /* server -> client */)
flow->http.num_response_headers += packet->http_num_headers; /* flow structs are initialized with zeros */
if(packet->packet_direction == 1 /* server -> client */){
flow->http.num_response_headers += packet->http_num_headers; /* flow structs are initialized with zeros */
}
if(packet->empty_line_position_set != 0 || flow->l4.tcp.http_empty_line_seen == 1) {
NDPI_LOG_DBG2(ndpi_struct, "empty line. check_http_payload\n");
@@ -937,8 +905,8 @@ void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
}
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
return;
}
return;
}
NDPI_LOG_DBG(ndpi_struct, "search HTTP\n");
ndpi_check_http_tcp(ndpi_struct, flow);
@@ -967,7 +935,7 @@ char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod,
/* ********************************* */
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
if((!flow) || (!flow->http.content_type))
return("");
else
+18 -13
View File
@@ -63,19 +63,21 @@ static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
struct ndpi_packet_struct *packet = &flow->packet;
struct mdns_header *h = (struct mdns_header*)packet->payload;
u_int16_t questions = ntohs(h->questions), answers = ntohs(h->answers);
if((questions > NDPI_MAX_MDNS_REQUESTS)
|| (answers > NDPI_MAX_MDNS_REQUESTS))
return(0);
if((packet->payload[2] & 0x80) == 0) {
if(((packet->payload[2] & 0x80) == 0)
&& (questions <= NDPI_MAX_MDNS_REQUESTS)
&& (answers <= NDPI_MAX_MDNS_REQUESTS)) {
NDPI_LOG_INFO(ndpi_struct, "found MDNS with question query\n");
return 1;
} else if((packet->payload[2] & 0x80) != 0) {
}
else if(((packet->payload[2] & 0x80) != 0)
&& (questions == 0)
&& (answers <= NDPI_MAX_MDNS_REQUESTS)
&& (answers != 0)) {
char answer[256];
int i, j, len;
for(i=13, j=0; (i < packet->payload_packet_len) && (i < (sizeof(answer)-1)) && (packet->payload[i] != 0); i++)
for(i=13, j=0; (packet->payload[i] != 0) && (i < packet->payload_packet_len) && (i < (sizeof(answer)-1)); i++)
answer[j++] = (packet->payload[i] < 13) ? '.' : packet->payload[i];
answer[j] = '\0';
@@ -98,6 +100,8 @@ static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t dport;
NDPI_LOG_DBG(ndpi_struct, "search MDNS\n");
/**
@@ -107,13 +111,15 @@ void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct n
/* check if UDP packet */
if(packet->udp != NULL) {
/* read destination port */
u_int16_t sport = ntohs(packet->udp->source);
u_int16_t dport = ntohs(packet->udp->dest);
dport = ntohs(packet->udp->dest);
/* check standard MDNS ON port 5353 */
if(((dport == 5353) || (sport == 5353))
&& (packet->payload_packet_len >= 12)) {
if(packet->iph != NULL) {
if(dport == 5353 && packet->payload_packet_len >= 12) {
/* mdns protocol must have destination address 224.0.0.251 */
if(packet->iph != NULL /* && ntohl(packet->iph->daddr) == 0xe00000fb */) {
NDPI_LOG_INFO(ndpi_struct, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
if(ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow);
return;
@@ -135,7 +141,6 @@ void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct n
#endif
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
+6 -12
View File
@@ -44,12 +44,9 @@ void ndpi_search_mining_tcp(struct ndpi_detection_module_struct *ndpi_struct,
if((*to_match == magic) || (*to_match == magic1)) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, NDPI_PROTOCOL_UNKNOWN);
}
} if(ndpi_strnstr((const char *)packet->payload, "{", packet->payload_packet_len)
&& (
ndpi_strnstr((const char *)packet->payload, "\"eth1.0\"", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "\"worker\":", packet->payload_packet_len)
/* || ndpi_strnstr((const char *)packet->payload, "\"id\":", packet->payload_packet_len) - Removed as too generic */
)) {
} if(ndpi_strnstr((const char *)packet->payload, "\"eth1.0\"", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "\"worker\"", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "\"id\"", packet->payload_packet_len)) {
/*
Ethereum
@@ -58,12 +55,9 @@ void ndpi_search_mining_tcp(struct ndpi_detection_module_struct *ndpi_struct,
{"worker": "", "jsonrpc": "2.0", "params": [], "id": 3, "method": "eth_getWork"}
*/
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, NDPI_PROTOCOL_UNKNOWN);
} else if(ndpi_strnstr((const char *)packet->payload, "{", packet->payload_packet_len)
&& (ndpi_strnstr((const char *)packet->payload, "\"method\":", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "\"blob\":", packet->payload_packet_len)
/* || ndpi_strnstr((const char *)packet->payload, "\"id\":", packet->payload_packet_len) - Removed as too generic */
)
) {
} else if(ndpi_strnstr((const char *)packet->payload, "\"method\"", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "\"blob\"", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "\"id\"", packet->payload_packet_len)) {
/*
ZCash
-72
View File
@@ -1,72 +0,0 @@
/*
* modbus.c
*
* Copyright (C) 2018 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MODBUS
void ndpi_search_modbus_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search Modbus\n");
u_int16_t modbus_port = htons(502); // port used by modbus
/* Check connection over TCP */
if(packet->tcp) {
/* The payload of Modbus-TCP segment must be at least 8 bytes (7 bytes of header application
packet plus 1 byte of minimum payload of application packet)
*/
if((packet->payload_packet_len >= 8)
&&((packet->tcp->dest == modbus_port) || (packet->tcp->source == modbus_port))) {
// Modbus uses the port 502
u_int16_t modbus_len = htons(*((u_int16_t*)&packet->payload[4]));
// the fourth parameter of the payload is the length of the segment
if((modbus_len-1) == (packet->payload_packet_len - 7 /* ModbusTCP header len */)) {
NDPI_LOG_INFO(ndpi_struct, "found MODBUS\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MODBUS, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_modbus_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("Modbus", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_MODBUS,
ndpi_search_modbus_tcp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+9 -6
View File
@@ -22,32 +22,34 @@
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OOKLA
#include "ndpi_api.h"
#include "lruc.h"
void ndpi_search_ookla(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) {
struct ndpi_packet_struct* packet = &flow->packet;
u_int32_t addr = 0;
void *value;
NDPI_LOG_DBG(ndpi_struct, "Ookla detection\n");
if(packet->tcp->source == htons(8080))
addr = packet->iph->saddr;
else if(packet->tcp->dest == htons(8080))
addr = packet->iph->daddr;
else
goto ookla_exclude;
if(ndpi_struct->ookla_cache != NULL) {
if(ndpi_lru_find_cache(ndpi_struct->ookla_cache, addr, 0 /* Don't remove it as it can be used for other connections */)) {
if(lruc_get(ndpi_struct->ookla_cache, &addr, sizeof(addr), &value) == LRUC_NO_ERROR) {
/* Don't remove it as it can be used for other connections */
NDPI_LOG_INFO(ndpi_struct, "found ookla tcp connection\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
}
ookla_exclude:
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_ookla_dissector(struct ndpi_detection_module_struct *ndpi_struct,
@@ -61,3 +63,4 @@ void init_ookla_dissector(struct ndpi_detection_module_struct *ndpi_struct,
*id += 1;
}
+2 -2
View File
@@ -96,8 +96,8 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->payload[i+1] == 'N')
&& (packet->payload[i+2] == 'I')
&& (packet->payload[i+3] == 0)) {
u_int32_t offset = le32toh(*((u_int32_t*)&packet->payload[i+4]));
u_int32_t prev_offset = le32toh(*((u_int32_t*)&packet->payload[i-4]));
u_int32_t offset = *((u_int32_t*)&packet->payload[i+4]);
u_int32_t prev_offset = *((u_int32_t*)&packet->payload[i-4]);
int len = offset-prev_offset;
int sni_offset = i+prev_offset+1;
+1 -4
View File
@@ -39,13 +39,10 @@ static void ndpi_check_radius(struct ndpi_detection_module_struct *ndpi_struct,
if(packet->udp != NULL) {
struct radius_header *h = (struct radius_header*)packet->payload;
/* RFC2865: The minimum length is 20 and maximum length is 4096. */
if((payload_len < 20) || (payload_len > 4096))
return;
if((payload_len > sizeof(struct radius_header))
&& (h->code > 0)
&& (h->code <= 13)
&& (h->code <= 5)
&& (ntohs(h->len) == payload_len)) {
NDPI_LOG_INFO(ndpi_struct, "Found radius\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RADIUS, NDPI_PROTOCOL_UNKNOWN);
+1 -1
View File
@@ -559,7 +559,7 @@ static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct
}
}
if((packet->payload_packet_len > temp) && (packet->payload_packet_len > 100)) {
if((packet->payload_packet_len > temp && packet->payload_packet_len > 100) && packet->payload_packet_len > 9) {
/* the server hello may be split into small packets and the certificate has its own SSL Record
* so temp contains only the length for the first ServerHello block */
u_int32_t cert_start;
+55
View File
@@ -0,0 +1,55 @@
#include <pthread.h>
#include <stdint.h>
#include <time.h>
#ifndef __lruc_header__
#define __lruc_header__
// ------------------------------------------
// errors
// ------------------------------------------
typedef enum {
LRUC_NO_ERROR = 0,
LRUC_MISSING_CACHE,
LRUC_MISSING_KEY,
LRUC_MISSING_VALUE,
LRUC_PTHREAD_ERROR,
LRUC_VALUE_TOO_LARGE
} lruc_error;
// ------------------------------------------
// types
// ------------------------------------------
typedef struct {
void *value;
void *key;
uint32_t value_length;
uint32_t key_length;
uint64_t access_count;
void *next;
} lruc_item;
typedef struct {
lruc_item **items;
uint64_t access_count;
uint64_t free_memory;
uint64_t total_memory;
uint64_t average_item_length;
uint32_t hash_table_size;
time_t seed;
lruc_item *free_items;
pthread_mutex_t *mutex;
} lruc;
// ------------------------------------------
// api
// ------------------------------------------
lruc *lruc_new(uint64_t cache_size, uint32_t average_length);
lruc_error lruc_free(lruc *cache);
lruc_error lruc_set(lruc *cache, void *key, uint32_t key_length, void *value, uint32_t value_length);
lruc_error lruc_get(lruc *cache, void *key, uint32_t key_length, void **value);
lruc_error lruc_delete(lruc *cache, void *key, uint32_t key_length);
#endif
+294
View File
@@ -0,0 +1,294 @@
/* https://github.com/willcannings/C-LRU-Cache */
#include "lruc.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <err.h>
// ------------------------------------------
// private functions
// ------------------------------------------
// MurmurHash2, by Austin Appleby
// http://sites.google.com/site/murmurhash/
uint32_t lruc_hash(lruc *cache, void *key, uint32_t key_length) {
uint32_t m = 0x5bd1e995;
uint32_t r = 24;
uint32_t h = cache->seed ^ key_length;
char* data = (char *)key;
while(key_length >= 4) {
uint32_t k = *(uint32_t *)data;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
key_length -= 4;
}
switch(key_length) {
case 3: h ^= data[2] << 16;
case 2: h ^= data[1] << 8;
case 1: h ^= data[0];
h *= m;
};
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h % cache->hash_table_size;
}
// compare a key against an existing item's key
int lruc_cmp_keys(lruc_item *item, void *key, uint32_t key_length) {
if(key_length != item->key_length)
return 1;
else
return memcmp(key, item->key, key_length);
}
// remove an item and push it to the free items queue
void lruc_remove_item(lruc *cache, lruc_item *prev, lruc_item *item, uint32_t hash_index) {
if(prev)
prev->next = item->next;
else
cache->items[hash_index] = (lruc_item *) item->next;
// free memory and update the free memory counter
cache->free_memory += item->value_length;
free(item->value);
free(item->key);
// push the item to the free items queue
memset(item, 0, sizeof(lruc_item));
item->next = cache->free_items;
cache->free_items = item;
}
// remove the least recently used item
// TODO: we can optimise this by finding the n lru items, where n = required_space / average_length
void lruc_remove_lru_item(lruc *cache) {
lruc_item *min_item = NULL, *min_prev = NULL;
lruc_item *item = NULL, *prev = NULL;
uint32_t i = 0, min_index = -1;
uint64_t min_access_count = -1;
for(; i < cache->hash_table_size; i++) {
item = cache->items[i];
prev = NULL;
while(item) {
if(item->access_count < min_access_count || min_access_count == -1) {
min_access_count = item->access_count;
min_item = item;
min_prev = prev;
min_index = i;
}
prev = item;
item = item->next;
}
}
if(min_item)
lruc_remove_item(cache, min_prev, min_item, min_index);
}
// pop an existing item off the free queue, or create a new one
lruc_item *lruc_pop_or_create_item(lruc *cache) {
lruc_item *item = NULL;
if(cache->free_items) {
item = cache->free_items;
cache->free_items = item->next;
} else {
item = (lruc_item *) calloc(sizeof(lruc_item), 1);
}
return item;
}
// error helpers
#define error_for(conditions, error) if(conditions) {return error;}
#define test_for_missing_cache() error_for(!cache, LRUC_MISSING_CACHE)
#define test_for_missing_key() error_for(!key || key_length == 0, LRUC_MISSING_KEY)
#define test_for_missing_value() error_for(!value || value_length == 0, LRUC_MISSING_VALUE)
#define test_for_value_too_large() error_for(value_length > cache->total_memory, LRUC_VALUE_TOO_LARGE)
// lock helpers
#define lock_cache() if(pthread_mutex_lock(cache->mutex)) {\
perror("LRU Cache unable to obtain mutex lock");\
return LRUC_PTHREAD_ERROR;\
}
#define unlock_cache() if(pthread_mutex_unlock(cache->mutex)) {\
perror("LRU Cache unable to release mutex lock");\
return LRUC_PTHREAD_ERROR;\
}
// ------------------------------------------
// public api
// ------------------------------------------
lruc *lruc_new(uint64_t cache_size, uint32_t average_length) {
// create the cache
lruc *cache = (lruc *) calloc(sizeof(lruc), 1);
if(!cache) {
perror("LRU Cache unable to create cache object");
return NULL;
}
cache->hash_table_size = cache_size / average_length;
cache->average_item_length = average_length;
cache->free_memory = cache_size;
cache->total_memory = cache_size;
cache->seed = time(NULL);
// size the hash table to a guestimate of the number of slots required (assuming a perfect hash)
cache->items = (lruc_item **) calloc(sizeof(lruc_item *), cache->hash_table_size);
if(!cache->items) {
perror("LRU Cache unable to create cache hash table");
free(cache);
return NULL;
}
// all cache calls are guarded by a mutex
cache->mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
if(pthread_mutex_init(cache->mutex, NULL)) {
perror("LRU Cache unable to initialise mutex");
free(cache->items);
free(cache);
return NULL;
}
return cache;
}
lruc_error lruc_free(lruc *cache) {
test_for_missing_cache();
// free each of the cached items, and the hash table
lruc_item *item = NULL, *next = NULL;
uint32_t i = 0;
if(cache->items) {
for(; i < cache->hash_table_size; i++) {
item = cache->items[i];
while(item) {
next = (lruc_item *) item->next;
free(item);
item = next;
}
}
free(cache->items);
}
// free the cache
if(cache->mutex) {
if(pthread_mutex_destroy(cache->mutex)) {
perror("LRU Cache unable to destroy mutex");
return LRUC_PTHREAD_ERROR;
}
}
free(cache);
return LRUC_NO_ERROR;
}
lruc_error lruc_set(lruc *cache, void *key, uint32_t key_length, void *value, uint32_t value_length) {
test_for_missing_cache();
test_for_missing_key();
test_for_missing_value();
test_for_value_too_large();
lock_cache();
// see if the key already exists
uint32_t hash_index = lruc_hash(cache, key, key_length), required = 0;
lruc_item *item = NULL, *prev = NULL;
item = cache->items[hash_index];
while(item && lruc_cmp_keys(item, key, key_length)) {
prev = item;
item = (lruc_item *) item->next;
}
if(item) {
// update the value and value_lengths
required = value_length - item->value_length;
free(item->value);
item->value = value;
item->value_length = value_length;
} else {
// insert a new item
item = lruc_pop_or_create_item(cache);
item->value = value;
item->key = key;
item->value_length = value_length;
item->key_length = key_length;
required = value_length;
if(prev)
prev->next = item;
else
cache->items[hash_index] = item;
}
item->access_count = ++cache->access_count;
// remove as many items as necessary to free enough space
if(required > 0 && required > cache->free_memory) {
while(cache->free_memory < required)
lruc_remove_lru_item(cache);
}
cache->free_memory -= required;
unlock_cache();
return LRUC_NO_ERROR;
}
lruc_error lruc_get(lruc *cache, void *key, uint32_t key_length, void **value) {
test_for_missing_cache();
test_for_missing_key();
lock_cache();
// loop until we find the item, or hit the end of a chain
uint32_t hash_index = lruc_hash(cache, key, key_length);
lruc_item *item = cache->items[hash_index];
while(item && lruc_cmp_keys(item, key, key_length))
item = (lruc_item *) item->next;
if(item) {
*value = item->value;
item->access_count = ++cache->access_count;
} else {
*value = NULL;
}
unlock_cache();
return LRUC_NO_ERROR;
}
lruc_error lruc_delete(lruc *cache, void *key, uint32_t key_length) {
test_for_missing_cache();
test_for_missing_key();
lock_cache();
// loop until we find the item, or hit the end of a chain
lruc_item *item = NULL, *prev = NULL;
uint32_t hash_index = lruc_hash(cache, key, key_length);
item = cache->items[hash_index];
while(item && lruc_cmp_keys(item, key, key_length)) {
prev = item;
item = (lruc_item *) item->next;
}
if(item) {
lruc_remove_item(cache, prev, item, hash_index);
}
unlock_cache();
return LRUC_NO_ERROR;
}
Binary file not shown.
-3
View File
@@ -1,3 +0,0 @@
Modbus 102 6681 1
1 TCP 192.168.110.131:2074 <-> 192.168.110.138:502 [proto: 44/Modbus][cat: Network/14][51 pkts/3366 bytes <-> 51 pkts/3315 bytes]
+4 -3
View File
@@ -1,6 +1,7 @@
Unknown 990 378832 34
HTTP 73 69236 13
HTTP 47 42014 11
SSDP 63 17143 10
HTTP_Download 26 27222 2
Google 2 1093 1
GenericProtocol 1429 1780307 49
@@ -8,7 +9,7 @@ GenericProtocol 1429 1780307 49
2 TCP 192.168.115.8:50778 <-> 223.26.106.20:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/303 bytes <-> 528 pkts/692658 bytes][Host: preimage1.qiyipic.com]
3 TCP 192.168.115.8:50505 <-> 223.26.106.19:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][2 pkts/400 bytes <-> 244 pkts/319633 bytes][Host: static.qiyi.com]
4 TCP 192.168.115.8:50491 <-> 223.26.106.66:80 [proto: 7/HTTP][cat: Web/5][1 pkts/426 bytes <-> 26 pkts/33872 bytes][Host: 223.26.106.66]
5 TCP 192.168.115.8:50486 <-> 77.234.40.96:80 [proto: 7/HTTP][cat: Web/5][11 pkts/11023 bytes <-> 12 pkts/14869 bytes][Host: bcu.ff.avast.com]
5 TCP 192.168.115.8:50486 <-> 77.234.40.96:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][11 pkts/11023 bytes <-> 12 pkts/14869 bytes][Host: bcu.ff.avast.com]
6 UDP 192.168.5.38:1900 -> 239.255.255.250:1900 [proto: 12/SSDP][cat: System/18][18 pkts/9327 bytes -> 0 pkts/0 bytes]
7 TCP 192.168.115.8:50476 <-> 101.227.32.39:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/656 bytes <-> 4 pkts/3897 bytes][Host: cache.video.iqiyi.com]
8 TCP 192.168.115.8:50495 <-> 202.108.14.236:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][3 pkts/2844 bytes <-> 3 pkts/597 bytes][Host: msg.71.am]
@@ -25,7 +26,7 @@ GenericProtocol 1429 1780307 49
19 TCP 192.168.115.8:50464 <-> 123.125.112.49:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/707 bytes <-> 1 pkts/744 bytes][Host: click.hm.baidu.com]
20 TCP 192.168.115.8:50492 <-> 111.206.13.3:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/389 bytes <-> 2 pkts/1034 bytes][Host: pdata.video.qiyi.com]
21 TCP 192.168.115.8:50777 <-> 111.206.22.77:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1186 bytes <-> 1 pkts/194 bytes][Host: msg.iqiyi.com]
22 TCP 192.168.115.8:50494 <-> 223.26.106.66:80 [proto: 7/HTTP][cat: Web/5][2 pkts/887 bytes <-> 1 pkts/443 bytes][Host: 223.26.106.66]
22 TCP 192.168.115.8:50494 <-> 223.26.106.66:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][2 pkts/887 bytes <-> 1 pkts/443 bytes][Host: 223.26.106.66]
23 TCP 192.168.115.8:50497 <-> 123.125.112.49:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1004 bytes <-> 2 pkts/301 bytes][Host: click.hm.baidu.com]
24 TCP 192.168.115.8:50499 <-> 111.206.22.76:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1097 bytes <-> 1 pkts/199 bytes][Host: msg.iqiyi.com]
25 TCP 192.168.115.8:50474 <-> 202.108.14.221:80 [proto: 7.137/HTTP.GenericProtocol][cat: Streaming/17][1 pkts/1100 bytes <-> 1 pkts/194 bytes][Host: msg.iqiyi.com]
+3 -2
View File
@@ -1,6 +1,7 @@
DNS 26 2848 7
HTTP 450 294880 19
HTTP 271 160676 18
SSDP 11 4984 1
HTTP_Download 179 134204 1
WorldOfWarcraft 9 880 1
IGMP 2 120 1
SSL 38 2548 11
@@ -8,7 +9,7 @@ Google 22 2184 5
Github 3 234 1
Starcraft 236 51494 6
1 TCP 192.168.1.100:3508 <-> 87.248.221.254:80 [proto: 7/HTTP][cat: Web/5][90 pkts/5059 bytes <-> 89 pkts/129145 bytes][Host: llnw.blizzard.com]
1 TCP 192.168.1.100:3508 <-> 87.248.221.254:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][90 pkts/5059 bytes <-> 89 pkts/129145 bytes][Host: llnw.blizzard.com]
2 TCP 192.168.1.100:3517 <-> 213.248.127.130:1119 [proto: 213/Starcraft][cat: Game/8][126 pkts/9157 bytes <-> 89 pkts/41021 bytes]
3 TCP 192.168.1.100:3527 <-> 2.228.46.112:80 [proto: 7/HTTP][cat: Web/5][15 pkts/971 bytes <-> 26 pkts/36462 bytes][Host: bnetcmsus-a.akamaihd.net]
4 TCP 192.168.1.100:3528 <-> 2.228.46.112:80 [proto: 7/HTTP][cat: Web/5][11 pkts/755 bytes <-> 18 pkts/24350 bytes][Host: bnetcmsus-a.akamaihd.net]
+3 -2
View File
@@ -1,13 +1,14 @@
Unknown 10 786 1
HTTP 65 64777 8
HTTP 28 1572 7
NTP 2 180 1
HTTP_Download 37 63205 1
SSL 8 432 2
Google 13 2142 1
Waze 484 289335 19
WhatsApp 15 1341 1
1 TCP 10.8.0.1:36100 <-> 46.51.173.182:443 [proto: 91.135/SSL.Waze][cat: Web/5][52 pkts/10860 bytes <-> 55 pkts/74852 bytes][server: *.world.waze.com]
2 TCP 10.8.0.1:54915 <-> 65.39.128.135:80 [proto: 7/HTTP][cat: Web/5][19 pkts/1309 bytes <-> 18 pkts/61896 bytes][Host: xtra1.gpsonextra.net]
2 TCP 10.8.0.1:54915 <-> 65.39.128.135:80 [proto: 7.60/HTTP.HTTP_Download][cat: Download-FileTransfer-FileSharing/7][19 pkts/1309 bytes <-> 18 pkts/61896 bytes][Host: xtra1.gpsonextra.net]
3 TCP 10.8.0.1:39021 <-> 52.17.114.219:443 [proto: 91.135/SSL.Waze][cat: Web/5][17 pkts/1962 bytes <-> 16 pkts/56934 bytes][server: *.world.waze.com]
4 TCP 10.8.0.1:36312 <-> 176.34.186.180:443 [proto: 91.135/SSL.Waze][cat: Web/5][17 pkts/2176 bytes <-> 15 pkts/42443 bytes][server: *.world.waze.com]
5 TCP 10.8.0.1:36316 <-> 176.34.186.180:443 [proto: 91.135/SSL.Waze][cat: Web/5][15 pkts/1540 bytes <-> 13 pkts/26346 bytes][server: *.world.waze.com]
+24 -24
View File
@@ -51,7 +51,7 @@ local f_udp_len = Field.new("udp.length")
local f_tcp_header_len = Field.new("tcp.hdr_len")
local f_ip_len = Field.new("ip.len")
local f_ip_hdr_len = Field.new("ip.hdr_len")
local f_tls_server_name = Field.new("tls.handshake.extensions_server_name")
local f_ssl_server_name = Field.new("ssl.handshake.extensions_server_name")
local f_tcp_flags = Field.new('tcp.flags')
local f_tcp_retrans = Field.new('tcp.analysis.retransmission')
local f_tcp_ooo = Field.new('tcp.analysis.out_of_order')
@@ -59,7 +59,7 @@ local f_tcp_lost_segment = Field.new('tcp.analysis.lost_segment') -- packet dro
local f_rpc_xid = Field.new('rpc.xid')
local f_rpc_msgtyp = Field.new('rpc.msgtyp')
local f_user_agent = Field.new('http.user_agent')
local f_dhcp_request_item = Field.new('dhcp.option.request_list_item')
local f_dhcp_request_item = Field.new('bootp.option.request_list_item')
local ndpi_protos = {}
local ndpi_flows = {}
@@ -88,8 +88,8 @@ local max_num_flows = 50
local num_top_dns_queries = 0
local max_num_dns_queries = 50
local tls_server_names = {}
local tot_tls_flows = 0
local ssl_server_names = {}
local tot_ssl_flows = 0
local http_ua = {}
local tot_http_ua_flows = 0
@@ -329,9 +329,9 @@ function ndpi_proto.init()
syn = {}
synack = {}
-- TLS
tls_server_names = {}
tot_tls_flows = 0
-- SSL
ssl_server_names = {}
tot_ssl_flows = 0
-- HTTP
http_ua = {}
@@ -522,17 +522,17 @@ end
-- ###############################################
function tls_dissector(tvb, pinfo, tree)
local tls_server_name = f_tls_server_name()
if(tls_server_name ~= nil) then
tls_server_name = getval(tls_server_name)
function ssl_dissector(tvb, pinfo, tree)
local ssl_server_name = f_ssl_server_name()
if(ssl_server_name ~= nil) then
ssl_server_name = getval(ssl_server_name)
if(tls_server_names[tls_server_name] == nil) then
tls_server_names[tls_server_name] = 0
if(ssl_server_names[ssl_server_name] == nil) then
ssl_server_names[ssl_server_name] = 0
end
tls_server_names[tls_server_name] = tls_server_names[tls_server_name] + 1
tot_tls_flows = tot_tls_flows + 1
ssl_server_names[ssl_server_name] = ssl_server_names[ssl_server_name] + 1
tot_ssl_flows = tot_ssl_flows + 1
end
end
@@ -989,7 +989,7 @@ function ndpi_proto.dissector(tvb, pinfo, tree)
mac_dissector(tvb, pinfo, tree)
arp_dissector(tvb, pinfo, tree)
vlan_dissector(tvb, pinfo, tree)
tls_dissector(tvb, pinfo, tree)
ssl_dissector(tvb, pinfo, tree)
http_dissector(tvb, pinfo, tree)
dhcp_dissector(tvb, pinfo, tree)
dns_dissector(tvb, pinfo, tree)
@@ -1392,25 +1392,25 @@ end
-- ###############################################
local function tls_dialog_menu()
local win = TextWindow.new("TLS Server Contacts");
local function ssl_dialog_menu()
local win = TextWindow.new("SSL Server Contacts");
local label = ""
local tot = 0
local i
if(tot_tls_flows > 0) then
if(tot_ssl_flows > 0) then
i = 0
label = label .. "TLS Server\t\t\t\t# Flows\n"
for k,v in pairsByValues(tls_server_names, rev) do
label = label .. "SSL Server\t\t\t\t# Flows\n"
for k,v in pairsByValues(ssl_server_names, rev) do
local pctg
v = tonumber(v)
pctg = formatPctg((v * 100) / tot_tls_flows)
pctg = formatPctg((v * 100) / tot_ssl_flows)
label = label .. string.format("%-32s", shortenString(k,32)).."\t"..v.." [".. pctg.." %]\n"
if(i == 50) then break else i = i + 1 end
end
else
label = "No TLS server certificates detected"
label = "No SSL server certificates detected"
end
win:set(label)
@@ -1465,7 +1465,7 @@ register_menu("ntop/DNS", dns_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/HTTP UA", http_ua_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/Flows", flows_ua_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/IP-MAC", ip_mac_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/TLS", tls_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/SSL", ssl_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/TCP Analysis", tcp_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/VLAN", vlan_dialog_menu, MENU_TOOLS_UNSORTED)
register_menu("ntop/Latency/Network", rtt_dialog_menu, MENU_TOOLS_UNSORTED)