Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
Hidde van der Heide
2017-12-20 13:19:24 +01:00
173 changed files with 3455 additions and 3166 deletions
+30
View File
@@ -1,5 +1,35 @@
# CHANGELOG # CHANGELOG
#### nDPI 2.2 (December 2017)
## Main New Features
* Custom protocol categories to allow personalization of protocols-categories mappings
* DHCP fingerprinting
* HTTP User Agent discovery
## New Supported Protocols and Services
* ICQ (instant messaging client)
* YouTube Upload
* LISP
* SoundCloud
* Sony PlayStation
* Nintendo (switch) gaming protocol
## Improvements
* Windows 10 detection from UA and indentation
* Determine STUN flows that turn into RTP
* Fixes for iQIYI and 1kxun
* Android fingerprint
* Added DHCP class identifier support
------------------------------------------------------------------------
#### nDPI 2.0 (May 2017) #### nDPI 2.0 (May 2017)
## Main New Features ## Main New Features
+1 -1
View File
@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
NDPI_MAJOR="2" NDPI_MAJOR="2"
NDPI_MINOR="1" NDPI_MINOR="3"
NDPI_PATCH="0" NDPI_PATCH="0"
NDPI_VERSION_SHORT="$NDPI_MAJOR.$NDPI_MINOR.$NDPI_PATCH" NDPI_VERSION_SHORT="$NDPI_MAJOR.$NDPI_MINOR.$NDPI_PATCH"
+128 -106
View File
@@ -77,7 +77,9 @@ static json_object *jArray_topStats;
static u_int8_t live_capture = 0; static u_int8_t live_capture = 0;
static u_int8_t undetected_flows_deleted = 0; static u_int8_t undetected_flows_deleted = 0;
/** User preferences **/ /** User preferences **/
static u_int8_t enable_protocol_guess = 1, verbose = 0, nDPI_traceLevel = 0, json_flag = 0; static u_int8_t enable_protocol_guess = 1, verbose = 0, json_flag = 0;
int nDPI_LogLevel = 0;
char *_debug_protocols = NULL;
static u_int8_t stats_flag = 0, bpf_filter_flag = 0; static u_int8_t stats_flag = 0, bpf_filter_flag = 0;
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
static u_int8_t file_first_time = 1; static u_int8_t file_first_time = 1;
@@ -107,14 +109,14 @@ static struct flow_info *all_flows;
struct info_pair { struct info_pair {
u_int32_t addr; u_int32_t addr;
u_int8_t version; /* IP version */ u_int8_t version; /* IP version */
char proto[16]; /*app level protocol*/ char proto[16]; /*app level protocol*/
int count; int count;
}; };
typedef struct node_a{ typedef struct node_a{
u_int32_t addr; u_int32_t addr;
u_int8_t version; /* IP version */ u_int8_t version; /* IP version */
char proto[16]; /*app level protocol*/ char proto[16]; /*app level protocol*/
int count; int count;
@@ -151,18 +153,18 @@ struct single_flow_info {
u_int32_t saddr; /* key */ u_int32_t saddr; /* key */
u_int8_t version; /* IP version */ u_int8_t version; /* IP version */
struct port_flow_info *ports; struct port_flow_info *ports;
u_int32_t tot_flows; u_int32_t tot_flows;
UT_hash_handle hh; UT_hash_handle hh;
}; };
struct single_flow_info *scannerHosts = NULL; struct single_flow_info *scannerHosts = NULL;
// struct to hold top receiver hosts // struct to hold top receiver hosts
struct receiver { struct receiver {
u_int32_t addr; /* key */ u_int32_t addr; /* key */
u_int8_t version; /* IP version */ u_int8_t version; /* IP version */
u_int32_t num_pkts; u_int32_t num_pkts;
UT_hash_handle hh; UT_hash_handle hh;
}; };
struct receiver *receivers = NULL, *topReceivers = NULL; struct receiver *receivers = NULL, *topReceivers = NULL;
@@ -251,9 +253,12 @@ static void help(u_int long_help) {
" | 1 = verbose\n" " | 1 = verbose\n"
" | 2 = very verbose\n" " | 2 = very verbose\n"
" | 3 = port stats\n" " | 3 = port stats\n"
" -b <file.json> | Specify a file to write port based diagnose statistics\n" " -V <1-4> | nDPI logging level\n"
" -x <file.json> | Produce bpf filters for specified diagnose file. Use\n" " | 1 - trace, 2 - debug, 3 - full debug\n"
" | this option only for .json files generated with -b flag.\n"); " | >3 - full debug + dbg_proto = all\n"
" -b <file.json> | Specify a file to write port based diagnose statistics\n"
" -x <file.json> | Produce bpf filters for specified diagnose file. Use\n"
" | this option only for .json files generated with -b flag.\n");
#ifndef WIN32 #ifndef WIN32
@@ -267,6 +272,7 @@ static void help(u_int long_help) {
" --extcap-capture-filter\n" " --extcap-capture-filter\n"
" --fifo <path to file or pipe>\n" " --fifo <path to file or pipe>\n"
" --debug\n" " --debug\n"
" --dbg-proto proto|num[,...]\n"
); );
#endif #endif
@@ -289,7 +295,8 @@ static struct option longopts[] = {
{ "capture", no_argument, NULL, '5'}, { "capture", no_argument, NULL, '5'},
{ "extcap-capture-filter", required_argument, NULL, '6'}, { "extcap-capture-filter", required_argument, NULL, '6'},
{ "fifo", required_argument, NULL, '7'}, { "fifo", required_argument, NULL, '7'},
{ "debug", optional_argument, NULL, '8'}, { "debug", no_argument, NULL, '8'},
{ "dbg-proto", required_argument, NULL, 257},
{ "ndpi-proto-filter", required_argument, NULL, '9'}, { "ndpi-proto-filter", required_argument, NULL, '9'},
/* ndpiReader options */ /* ndpiReader options */
@@ -515,8 +522,12 @@ static void parseOptions(int argc, char **argv) {
break; break;
case 'V': case 'V':
printf("%d\n",atoi(optarg) ); nDPI_LogLevel = atoi(optarg);
nDPI_traceLevel = atoi(optarg); if(nDPI_LogLevel < 0) nDPI_LogLevel = 0;
if(nDPI_LogLevel > 3) {
nDPI_LogLevel = 3;
_debug_protocols = strdup("all");
}
break; break;
case 'h': case 'h':
@@ -542,6 +553,7 @@ static void parseOptions(int argc, char **argv) {
case 'q': case 'q':
quiet_mode = 1; quiet_mode = 1;
nDPI_LogLevel = 0;
break; break;
/* Extcap */ /* Extcap */
@@ -570,13 +582,18 @@ static void parseOptions(int argc, char **argv) {
break; break;
case '8': case '8':
nDPI_traceLevel = 9; nDPI_LogLevel = NDPI_LOG_DEBUG_EXTRA;
_debug_protocols = strdup("all");
break; break;
case '9': case '9':
extcap_packet_filter = ndpi_get_proto_by_name(ndpi_info_mod, optarg); extcap_packet_filter = ndpi_get_proto_by_name(ndpi_info_mod, optarg);
if (extcap_packet_filter == NDPI_PROTOCOL_UNKNOWN) extcap_packet_filter = atoi(optarg); if (extcap_packet_filter == NDPI_PROTOCOL_UNKNOWN) extcap_packet_filter = atoi(optarg);
break; break;
case 257:
_debug_protocols = strdup(optarg);
break;
default: default:
help(0); help(0);
@@ -584,7 +601,7 @@ static void parseOptions(int argc, char **argv) {
} }
} }
if(!bpf_filter_flag) { if(!bpf_filter_flag) {
if(do_capture) { if(do_capture) {
quiet_mode = 1; quiet_mode = 1;
extcap_capture(); extcap_capture();
@@ -883,11 +900,11 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
/* *********************************************** */ /* *********************************************** */
void updateScanners(struct single_flow_info **scanners, u_int32_t saddr, void updateScanners(struct single_flow_info **scanners, u_int32_t saddr,
u_int8_t version, u_int32_t dport) { u_int8_t version, u_int32_t dport) {
struct single_flow_info *f; struct single_flow_info *f;
struct port_flow_info *p; struct port_flow_info *p;
HASH_FIND_INT(*scanners, (int *)&saddr, f); HASH_FIND_INT(*scanners, (int *)&saddr, f);
if(f == NULL) { if(f == NULL) {
@@ -899,11 +916,11 @@ void updateScanners(struct single_flow_info **scanners, u_int32_t saddr,
f->ports = NULL; f->ports = NULL;
p = (struct port_flow_info*)malloc(sizeof(struct port_flow_info)); p = (struct port_flow_info*)malloc(sizeof(struct port_flow_info));
if(!p) { if(!p) {
free(f); free(f);
return; return;
} else } else
p->port = dport, p->num_flows = 1; p->port = dport, p->num_flows = 1;
HASH_ADD_INT(f->ports, port, p); HASH_ADD_INT(f->ports, port, p);
@@ -921,13 +938,13 @@ void updateScanners(struct single_flow_info **scanners, u_int32_t saddr,
HASH_ADD_INT(f->ports, port, pp); HASH_ADD_INT(f->ports, port, pp);
} else } else
pp->num_flows++; pp->num_flows++;
} }
} }
/* *********************************************** */ /* *********************************************** */
int updateIpTree(u_int32_t key, u_int8_t version, int updateIpTree(u_int32_t key, u_int8_t version,
addr_node **vrootp, const char *proto) { addr_node **vrootp, const char *proto) {
addr_node *q; addr_node *q;
addr_node **rootp = vrootp; addr_node **rootp = vrootp;
@@ -976,13 +993,12 @@ void freeIpTree(addr_node *root) {
/* *********************************************** */ /* *********************************************** */
void updateTopIpAddress(u_int32_t addr, u_int8_t version, const char *proto, void updateTopIpAddress(u_int32_t addr, u_int8_t version, const char *proto,
int count, struct info_pair top[], int size) { int count, struct info_pair top[], int size) {
struct info_pair pair; struct info_pair pair;
int min = count; int min = count;
int update = 0; int update = 0;
int min_i = 0; int min_i = 0;
int r;
int i; int i;
if(count == 0) return; if(count == 0) return;
@@ -1023,8 +1039,8 @@ void updateTopIpAddress(u_int32_t addr, u_int8_t version, const char *proto,
/* *********************************************** */ /* *********************************************** */
static void updatePortStats(struct port_stats **stats, u_int32_t port, static void updatePortStats(struct port_stats **stats, u_int32_t port,
u_int32_t addr, u_int8_t version, u_int32_t addr, u_int8_t version,
u_int32_t num_pkts, u_int32_t num_bytes, u_int32_t num_pkts, u_int32_t num_bytes,
const char *proto) { const char *proto) {
struct port_stats *s = NULL; struct port_stats *s = NULL;
@@ -1045,7 +1061,7 @@ static void updatePortStats(struct port_stats **stats, u_int32_t port,
free(s); free(s);
return; return;
} }
s->addr_tree->addr = addr; s->addr_tree->addr = addr;
s->addr_tree->version = version; s->addr_tree->version = version;
strncpy(s->addr_tree->proto, proto, sizeof(s->addr_tree->proto)); strncpy(s->addr_tree->proto, proto, sizeof(s->addr_tree->proto));
@@ -1071,7 +1087,7 @@ static void updatePortStats(struct port_stats **stats, u_int32_t port,
/* *********************************************** */ /* *********************************************** */
/* @brief heuristic choice for receiver stats */ /* @brief heuristic choice for receiver stats */
static int acceptable(u_int32_t num_pkts){ static int acceptable(u_int32_t num_pkts){
return num_pkts > 5; return num_pkts > 5;
} }
@@ -1104,8 +1120,8 @@ static struct receiver *cutBackTo(struct receiver **receivers, u_int32_t size, u
int count; int count;
if(size < max) //return the original table if(size < max) //return the original table
return *receivers; return *receivers;
count = size - max; count = size - max;
HASH_ITER(hh, *receivers, r, tmp) { HASH_ITER(hh, *receivers, r, tmp) {
@@ -1116,6 +1132,7 @@ static struct receiver *cutBackTo(struct receiver **receivers, u_int32_t size, u
} }
return(NULL); return(NULL);
} }
/* *********************************************** */ /* *********************************************** */
@@ -1168,12 +1185,12 @@ static void deleteReceivers(struct receiver *receivers) {
* if(table2.size > max1) * if(table2.size > max1)
* cut table2 back to max1 * cut table2 back to max1
* } * }
* } * }
* else * else
* update table1 * update table1
*/ */
static void updateReceivers(struct receiver **receivers, u_int32_t dst_addr, static void updateReceivers(struct receiver **receivers, u_int32_t dst_addr,
u_int8_t version, u_int32_t num_pkts, u_int8_t version, u_int32_t num_pkts,
struct receiver **topReceivers) { struct receiver **topReceivers) {
struct receiver *r; struct receiver *r;
u_int32_t size; u_int32_t size;
@@ -1181,7 +1198,7 @@ static void updateReceivers(struct receiver **receivers, u_int32_t dst_addr,
HASH_FIND_INT(*receivers, (int *)&dst_addr, r); HASH_FIND_INT(*receivers, (int *)&dst_addr, r);
if(r == NULL) { if(r == NULL) {
if(((size = HASH_COUNT(*receivers)) < MAX_TABLE_SIZE_1) if(((size = HASH_COUNT(*receivers)) < MAX_TABLE_SIZE_1)
|| ((a = acceptable(num_pkts)) != 0)){ || ((a = acceptable(num_pkts)) != 0)){
r = (struct receiver *)malloc(sizeof(struct receiver)); r = (struct receiver *)malloc(sizeof(struct receiver));
if(!r) return; if(!r) return;
@@ -1191,7 +1208,7 @@ static void updateReceivers(struct receiver **receivers, u_int32_t dst_addr,
r->num_pkts = num_pkts; r->num_pkts = num_pkts;
HASH_ADD_INT(*receivers, addr, r); HASH_ADD_INT(*receivers, addr, r);
if((size = HASH_COUNT(*receivers)) > MAX_TABLE_SIZE_2){ if((size = HASH_COUNT(*receivers)) > MAX_TABLE_SIZE_2){
HASH_SORT(*receivers, receivers_sort_asc); HASH_SORT(*receivers, receivers_sort_asc);
@@ -1214,8 +1231,8 @@ static void updateReceivers(struct receiver **receivers, u_int32_t dst_addr,
/* *********************************************** */ /* *********************************************** */
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
static void saveReceiverStats(json_object **jObj_group, static void saveReceiverStats(json_object **jObj_group,
struct receiver **receivers, struct receiver **receivers,
u_int64_t total_pkt_count) { u_int64_t total_pkt_count) {
json_object *jArray_stats = json_object_new_array(); json_object *jArray_stats = json_object_new_array();
@@ -1225,12 +1242,12 @@ static void saveReceiverStats(json_object **jObj_group,
HASH_ITER(hh, *receivers, r, tmp) { HASH_ITER(hh, *receivers, r, tmp) {
json_object *jObj_stat = json_object_new_object(); json_object *jObj_stat = json_object_new_object();
char addr_name[48]; char addr_name[48];
if(r->version == IPVERSION) if(r->version == IPVERSION)
inet_ntop(AF_INET, &(r->addr), addr_name, sizeof(addr_name)); inet_ntop(AF_INET, &(r->addr), addr_name, sizeof(addr_name));
else else
inet_ntop(AF_INET6, &(r->addr), addr_name, sizeof(addr_name)); inet_ntop(AF_INET6, &(r->addr), addr_name, sizeof(addr_name));
json_object_object_add(jObj_stat,"ip.address",json_object_new_string(addr_name)); json_object_object_add(jObj_stat,"ip.address",json_object_new_string(addr_name));
json_object_object_add(jObj_stat,"packets.number", json_object_new_int(r->num_pkts)); json_object_object_add(jObj_stat,"packets.number", json_object_new_int(r->num_pkts));
@@ -1241,7 +1258,7 @@ static void saveReceiverStats(json_object **jObj_group,
i++; i++;
if(i >= 10) break; if(i >= 10) break;
} }
json_object_object_add(*jObj_group, "top.receiver.stats", jArray_stats); json_object_object_add(*jObj_group, "top.receiver.stats", jArray_stats);
} }
#endif #endif
@@ -1303,13 +1320,13 @@ static void port_stats_walker(const void *node, ndpi_VISIT which, int depth, voi
updateScanners(&scannerHosts, flow->src_ip, flow->ip_version, dport); updateScanners(&scannerHosts, flow->src_ip, flow->ip_version, dport);
} }
updateReceivers(&receivers, flow->dst_ip, flow->ip_version, updateReceivers(&receivers, flow->dst_ip, flow->ip_version,
flow->src2dst_packets, &topReceivers); flow->src2dst_packets, &topReceivers);
updatePortStats(&srcStats, sport, flow->src_ip, flow->ip_version, updatePortStats(&srcStats, sport, flow->src_ip, flow->ip_version,
flow->src2dst_packets, flow->src2dst_bytes, proto); flow->src2dst_packets, flow->src2dst_bytes, proto);
updatePortStats(&dstStats, dport, flow->dst_ip, flow->ip_version, updatePortStats(&dstStats, dport, flow->dst_ip, flow->ip_version,
flow->dst2src_packets, flow->dst2src_bytes, proto); flow->dst2src_packets, flow->dst2src_bytes, proto);
} }
} }
@@ -1380,7 +1397,7 @@ static void debug_printf(u_int32_t protocol, void *id_struct,
struct tm result; struct tm result;
#endif #endif
if(log_level <= nDPI_traceLevel) { if(log_level <= nDPI_LogLevel) {
char buf[8192], out_buf[8192]; char buf[8192], out_buf[8192];
char theDate[32]; char theDate[32];
const char *extra_msg = ""; const char *extra_msg = "";
@@ -1638,7 +1655,7 @@ static int getTopStats(struct port_stats *stats) {
strncpy(sp->proto, inf.proto, sizeof(sp->proto)); strncpy(sp->proto, inf.proto, sizeof(sp->proto));
} else } else
sp->hasTopHost = 0; sp->hasTopHost = 0;
total_ip_addrs += sp->num_addr; total_ip_addrs += sp->num_addr;
} }
@@ -1652,7 +1669,7 @@ static void saveScannerStats(json_object **jObj_group, struct single_flow_info *
struct port_flow_info *p, *tmp2; struct port_flow_info *p, *tmp2;
char addr_name[48]; char addr_name[48];
int i = 0, j = 0; int i = 0, j = 0;
json_object *jArray_stats = json_object_new_array(); json_object *jArray_stats = json_object_new_array();
HASH_SORT(*scanners, scanners_sort); // FIX HASH_SORT(*scanners, scanners_sort); // FIX
@@ -1665,7 +1682,7 @@ static void saveScannerStats(json_object **jObj_group, struct single_flow_info *
inet_ntop(AF_INET, &(s->saddr), addr_name, sizeof(addr_name)); inet_ntop(AF_INET, &(s->saddr), addr_name, sizeof(addr_name));
else else
inet_ntop(AF_INET6, &(s->saddr), addr_name, sizeof(addr_name)); inet_ntop(AF_INET6, &(s->saddr), addr_name, sizeof(addr_name));
json_object_object_add(jObj_stat,"ip.address",json_object_new_string(addr_name)); json_object_object_add(jObj_stat,"ip.address",json_object_new_string(addr_name));
json_object_object_add(jObj_stat,"total.flows.number",json_object_new_int(s->tot_flows)); json_object_object_add(jObj_stat,"total.flows.number",json_object_new_int(s->tot_flows));
@@ -1685,7 +1702,7 @@ static void saveScannerStats(json_object **jObj_group, struct single_flow_info *
json_object_object_add(jObj_stat,"top.dst.ports",jArray_ports); json_object_object_add(jObj_stat,"top.dst.ports",jArray_ports);
json_object_array_add(jArray_stats, jObj_stat); json_object_array_add(jArray_stats, jObj_stat);
j = 0; j = 0;
i++; i++;
if(i >= 10) break; if(i >= 10) break;
@@ -1705,7 +1722,7 @@ static void saveScannerStats(json_object **jObj_group, struct single_flow_info *
static void saveTopStats(json_object **jObj_group, static void saveTopStats(json_object **jObj_group,
struct port_stats **stats, struct port_stats **stats,
u_int8_t direction, u_int8_t direction,
u_int64_t total_flow_count, u_int64_t total_flow_count,
u_int64_t total_ip_addr) { u_int64_t total_ip_addr) {
struct port_stats *s, *tmp; struct port_stats *s, *tmp;
char addr_name[48]; char addr_name[48];
@@ -1863,7 +1880,7 @@ static void printResults(u_int64_t tot_usec) {
if(cumulative_stats.total_wire_bytes == 0) if(cumulative_stats.total_wire_bytes == 0)
goto free_stats; goto free_stats;
if(!quiet_mode) { if(!quiet_mode) {
printf("\nnDPI Memory statistics:\n"); printf("\nnDPI Memory statistics:\n");
printf("\tnDPI Memory (once): %-13s\n", formatBytes(sizeof(struct ndpi_detection_module_struct), buf, sizeof(buf))); printf("\tnDPI Memory (once): %-13s\n", formatBytes(sizeof(struct ndpi_detection_module_struct), buf, sizeof(buf)));
@@ -2028,7 +2045,7 @@ static void printResults(u_int64_t tot_usec) {
printf("Fatal error: not enough memory\n"); printf("Fatal error: not enough memory\n");
exit(-1); exit(-1);
} }
if(!json_flag) fprintf(out, "\n"); if(!json_flag) fprintf(out, "\n");
num_flows = 0; num_flows = 0;
@@ -2038,10 +2055,10 @@ static void printResults(u_int64_t tot_usec) {
} }
qsort(all_flows, num_flows, sizeof(struct flow_info), cmpFlows); qsort(all_flows, num_flows, sizeof(struct flow_info), cmpFlows);
for(i=0; i<num_flows; i++) for(i=0; i<num_flows; i++)
printFlow(i+1, all_flows[i].flow, all_flows[i].thread_id); printFlow(i+1, all_flows[i].flow, all_flows[i].thread_id);
for(thread_id = 0; thread_id < num_threads; thread_id++) { for(thread_id = 0; thread_id < num_threads; thread_id++) {
if(ndpi_thread_info[thread_id].workflow->stats.protocol_counter[0 /* 0 = Unknown */] > 0) { if(ndpi_thread_info[thread_id].workflow->stats.protocol_counter[0 /* 0 = Unknown */] > 0) {
if(!json_flag) { if(!json_flag) {
@@ -2065,10 +2082,10 @@ static void printResults(u_int64_t tot_usec) {
} }
qsort(all_flows, num_flows, sizeof(struct flow_info), cmpFlows); qsort(all_flows, num_flows, sizeof(struct flow_info), cmpFlows);
for(i=0; i<num_flows; i++) for(i=0; i<num_flows; i++)
printFlow(i+1, all_flows[i].flow, all_flows[i].thread_id); printFlow(i+1, all_flows[i].flow, all_flows[i].thread_id);
free(all_flows); free(all_flows);
} }
@@ -2089,7 +2106,7 @@ static void printResults(u_int64_t tot_usec) {
HASH_SORT(srcStats, port_stats_sort); HASH_SORT(srcStats, port_stats_sort);
HASH_SORT(dstStats, port_stats_sort); HASH_SORT(dstStats, port_stats_sort);
} }
if(verbose == 3) { if(verbose == 3) {
printf("\n\nSource Ports Stats:\n"); printf("\n\nSource Ports Stats:\n");
printPortStats(srcStats); printPortStats(srcStats);
@@ -2097,7 +2114,7 @@ static void printResults(u_int64_t tot_usec) {
printf("\nDestination Ports Stats:\n"); printf("\nDestination Ports Stats:\n");
printPortStats(dstStats); printPortStats(dstStats);
} }
if(stats_flag) { if(stats_flag) {
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
json_object *jObj_stats = json_object_new_object(); json_object *jObj_stats = json_object_new_object();
@@ -2108,7 +2125,7 @@ static void printResults(u_int64_t tot_usec) {
json_object_object_add(jObj_stats, "time", json_object_new_string(timestamp)); json_object_object_add(jObj_stats, "time", json_object_new_string(timestamp));
saveScannerStats(&jObj_stats, &scannerHosts); saveScannerStats(&jObj_stats, &scannerHosts);
if((count = HASH_COUNT(topReceivers)) == 0){ if((count = HASH_COUNT(topReceivers)) == 0){
HASH_SORT(receivers, receivers_sort); HASH_SORT(receivers, receivers_sort);
saveReceiverStats(&jObj_stats, &receivers, cumulative_stats.ip_packet_count); saveReceiverStats(&jObj_stats, &receivers, cumulative_stats.ip_packet_count);
@@ -2126,7 +2143,7 @@ static void printResults(u_int64_t tot_usec) {
saveTopStats(&jObj_stats, &dstStats, DIR_DST, saveTopStats(&jObj_stats, &dstStats, DIR_DST,
cumulative_stats.ndpi_flow_count, total_dst_addr); cumulative_stats.ndpi_flow_count, total_dst_addr);
json_object_array_add(jArray_topStats, jObj_stats); json_object_array_add(jArray_topStats, jObj_stats);
#endif #endif
} }
@@ -2146,12 +2163,12 @@ static void printResults(u_int64_t tot_usec) {
deleteReceivers(topReceivers); deleteReceivers(topReceivers);
topReceivers = NULL; topReceivers = NULL;
} }
if(srcStats) { if(srcStats) {
deletePortsStats(srcStats); deletePortsStats(srcStats);
srcStats = NULL; srcStats = NULL;
} }
if(dstStats) { if(dstStats) {
deletePortsStats(dstStats); deletePortsStats(dstStats);
dstStats = NULL; dstStats = NULL;
@@ -2238,7 +2255,8 @@ static pcap_t * openPcapFileOrDevice(u_int16_t thread_id, const u_char * pcap_fi
pcap_t * pcap_handle = NULL; pcap_t * pcap_handle = NULL;
/* trying to open a live interface */ /* trying to open a live interface */
if((pcap_handle = pcap_open_live((char*)pcap_file, snaplen, promisc, 500, pcap_error_buffer)) == NULL) { if((pcap_handle = pcap_open_live((char*)pcap_file, snaplen, promisc,
500, pcap_error_buffer)) == NULL) {
capture_for = capture_until = 0; capture_for = capture_until = 0;
live_capture = 0; live_capture = 0;
@@ -2246,30 +2264,34 @@ static pcap_t * openPcapFileOrDevice(u_int16_t thread_id, const u_char * pcap_fi
/* trying to open a pcap file */ /* trying to open a pcap file */
if((pcap_handle = pcap_open_offline((char*)pcap_file, pcap_error_buffer)) == NULL) { if((pcap_handle = pcap_open_offline((char*)pcap_file, pcap_error_buffer)) == NULL) {
char filename[256]; char filename[256] = { 0 };
/* trying to open a pcap playlist */ if(strstr((char*)pcap_file, (char*)".pcap"))
if(getNextPcapFileFromPlaylist(thread_id, filename, sizeof(filename)) != 0 || printf("ERROR: could not open pcap file %s: %s\n", pcap_file, pcap_error_buffer);
(pcap_handle = pcap_open_offline(filename, pcap_error_buffer)) == NULL) { else if((getNextPcapFileFromPlaylist(thread_id, filename, sizeof(filename)) != 0)
|| ((pcap_handle = pcap_open_offline(filename, pcap_error_buffer)) == NULL)) {
printf("ERROR: could not open pcap file or playlist: %s\n", pcap_error_buffer); printf("ERROR: could not open playlist %s: %s\n", filename, pcap_error_buffer);
exit(-1); exit(-1);
} else { } else {
if((!json_flag) && (!quiet_mode)) printf("Reading packets from playlist %s...\n", pcap_file); if((!json_flag) && (!quiet_mode))
printf("Reading packets from playlist %s...\n", pcap_file);
} }
} else { } else {
if((!json_flag) && (!quiet_mode)) printf("Reading packets from pcap file %s...\n", pcap_file); if((!json_flag) && (!quiet_mode))
printf("Reading packets from pcap file %s...\n", pcap_file);
} }
} else { } else {
live_capture = 1; live_capture = 1;
if((!json_flag) && (!quiet_mode)) printf("Capturing live traffic from device %s...\n", pcap_file); if((!json_flag) && (!quiet_mode))
printf("Capturing live traffic from device %s...\n", pcap_file);
} }
configurePcapHandle(pcap_handle); configurePcapHandle(pcap_handle);
if(capture_for > 0) { if(capture_for > 0) {
if((!json_flag) && (!quiet_mode)) printf("Capturing traffic up to %u seconds\n", (unsigned int)capture_for); if((!json_flag) && (!quiet_mode))
printf("Capturing traffic up to %u seconds\n", (unsigned int)capture_for);
#ifndef WIN32 #ifndef WIN32
alarm(capture_for); alarm(capture_for);
@@ -2542,10 +2564,10 @@ void automataUnitTest() {
*/ */
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter, void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
int port_array[], int p_size, int port_array[], int p_size,
const char *src_host_array[16], const char *src_host_array[16],
int sh_size, int sh_size,
const char *dst_host_array[16], const char *dst_host_array[16],
int dh_size) { int dh_size) {
char filter[2048]; char filter[2048];
int produced = 0; int produced = 0;
@@ -2553,12 +2575,12 @@ void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
if(port_array[0] != INIT_VAL) { if(port_array[0] != INIT_VAL) {
int l; int l;
strcpy(filter, "not (src port "); strcpy(filter, "not (src port ");
while(i < p_size && port_array[i] != INIT_VAL) { while(i < p_size && port_array[i] != INIT_VAL) {
l = strlen(filter); l = strlen(filter);
if(i+1 == p_size || port_array[i+1] == INIT_VAL) if(i+1 == p_size || port_array[i+1] == INIT_VAL)
snprintf(&filter[l], sizeof(filter)-l, "%d", port_array[i]); snprintf(&filter[l], sizeof(filter)-l, "%d", port_array[i]);
else else
@@ -2574,17 +2596,17 @@ void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
if(src_host_array[0] != NULL) { if(src_host_array[0] != NULL) {
int l; int l;
if(port_array[0] != INIT_VAL) if(port_array[0] != INIT_VAL)
strncat(filter, " and not (src ", sizeof(" and not (src ")); strncat(filter, " and not (src ", sizeof(" and not (src "));
else else
strcpy(filter, "not (src "); strcpy(filter, "not (src ");
i=0; i=0;
while(i < sh_size && src_host_array[i] != NULL) { while(i < sh_size && src_host_array[i] != NULL) {
l = strlen(filter); l = strlen(filter);
if(i+1 == sh_size || src_host_array[i+1] == NULL) if(i+1 == sh_size || src_host_array[i+1] == NULL)
snprintf(&filter[l], sizeof(filter)-l, "%s", src_host_array[i]); snprintf(&filter[l], sizeof(filter)-l, "%s", src_host_array[i]);
else else
@@ -2592,7 +2614,7 @@ void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
i++; i++;
} }
l = strlen(filter); l = strlen(filter);
snprintf(&filter[l], sizeof(filter)-l, "%s", ")"); snprintf(&filter[l], sizeof(filter)-l, "%s", ")");
produced = 1; produced = 1;
@@ -2601,17 +2623,17 @@ void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
if(dst_host_array[0] != NULL) { if(dst_host_array[0] != NULL) {
int l; int l;
if(port_array[0] != INIT_VAL || src_host_array[0] != NULL) if(port_array[0] != INIT_VAL || src_host_array[0] != NULL)
strncat(filter, " and not (dst ", sizeof(" and not (dst ")); strncat(filter, " and not (dst ", sizeof(" and not (dst "));
else else
strcpy(filter, "not (dst "); strcpy(filter, "not (dst ");
i=0; i=0;
while(i < dh_size && dst_host_array[i] != NULL) { while(i < dh_size && dst_host_array[i] != NULL) {
l = strlen(filter); l = strlen(filter);
if(i+1 == dh_size || dst_host_array[i+1] == NULL) if(i+1 == dh_size || dst_host_array[i+1] == NULL)
snprintf(&filter[l], sizeof(filter)-l, "%s", dst_host_array[i]); snprintf(&filter[l], sizeof(filter)-l, "%s", dst_host_array[i]);
else else
@@ -2619,7 +2641,7 @@ void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
i++; i++;
} }
l = strlen(filter); l = strlen(filter);
snprintf(&filter[l], sizeof(filter)-l, "%s", ")"); snprintf(&filter[l], sizeof(filter)-l, "%s", ")");
produced = 1; produced = 1;
@@ -2641,8 +2663,8 @@ void bpf_filter_pkt_peak_filter(json_object **jObj_bpfFilter,
* addresses. * addresses.
*/ */
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
void bpf_filter_host_peak_filter(json_object **jObj_bpfFilter, void bpf_filter_host_peak_filter(json_object **jObj_bpfFilter,
const char *host_array[16], const char *host_array[16],
int h_size) { int h_size) {
char filter[2048]; char filter[2048];
int produced = 0; int produced = 0;
@@ -2656,7 +2678,7 @@ void bpf_filter_host_peak_filter(json_object **jObj_bpfFilter,
while(i < h_size && host_array[i] != NULL) { while(i < h_size && host_array[i] != NULL) {
l = strlen(filter); l = strlen(filter);
if(i+1 == h_size || host_array[i+1] == NULL) if(i+1 == h_size || host_array[i+1] == NULL)
snprintf(&filter[l], sizeof(filter)-l, "%s", host_array[i]); snprintf(&filter[l], sizeof(filter)-l, "%s", host_array[i]);
else else
@@ -2664,7 +2686,7 @@ void bpf_filter_host_peak_filter(json_object **jObj_bpfFilter,
i++; i++;
} }
l = strlen(filter); l = strlen(filter);
snprintf(&filter[l], sizeof(filter)-l, "%s", ")"); snprintf(&filter[l], sizeof(filter)-l, "%s", ")");
produced = 1; produced = 1;
@@ -2855,8 +2877,8 @@ void getSourcePorts(struct json_object *jObj_stat, int srcPortArray[], int size,
double flows_packets = json_object_get_double(jObj_flows_packets); double flows_packets = json_object_get_double(jObj_flows_packets);
if((flows_packets > FLOWS_PACKETS_THRESHOLD) if((flows_packets > FLOWS_PACKETS_THRESHOLD)
&& (flows_percent >= FLOWS_PERCENT_THRESHOLD) && (flows_percent >= FLOWS_PERCENT_THRESHOLD)
&& packets_number >= threshold) { && packets_number >= threshold) {
if((res = json_object_object_get_ex(src_pkts_stat, "port", &jObj_port)) == 0) { if((res = json_object_object_get_ex(src_pkts_stat, "port", &jObj_port)) == 0) {
fprintf(stderr, "ERROR: can't get \"port\", use -x flag only with .json files generated by ndpiReader -b flag.\n"); fprintf(stderr, "ERROR: can't get \"port\", use -x flag only with .json files generated by ndpiReader -b flag.\n");
@@ -2905,8 +2927,8 @@ void getReceiverHosts(struct json_object *jObj_stat, const char *dstHostArray[16
/* *********************************************** */ /* *********************************************** */
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
void getScannerHosts(struct json_object *jObj_stat, int duration, void getScannerHosts(struct json_object *jObj_stat, int duration,
const char *srcHostArray[48], int size, const char *srcHostArray[48], int size,
float threshold) { float threshold) {
int j; int j;
@@ -2941,7 +2963,7 @@ void getScannerHosts(struct json_object *jObj_stat, int duration,
/* *********************************************** */ /* *********************************************** */
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
void getDestinationHosts(struct json_object *jObj_stat, int duration, void getDestinationHosts(struct json_object *jObj_stat, int duration,
const char *dstHostArray[16], int size) { const char *dstHostArray[16], int size) {
int j; int j;
@@ -2981,10 +3003,10 @@ static void produceBpfFilter(char *filePath) {
json_object *jObj_duration; json_object *jObj_duration;
json_object *jObj_statistics; /* json array */ json_object *jObj_statistics; /* json array */
json_bool res; json_bool res;
int filterSrcPorts[PORT_ARRAY_SIZE]; int filterSrcPorts[PORT_ARRAY_SIZE];
const char *filterSrcHosts[48]; const char *filterSrcHosts[48];
const char *filterDstHosts[48]; const char *filterDstHosts[48];
const char *filterPktDstHosts[48]; const char *filterPktDstHosts[48];
struct stat statbuf; struct stat statbuf;
FILE *fp = NULL; FILE *fp = NULL;
char *fileName; char *fileName;
@@ -2998,7 +3020,7 @@ static void produceBpfFilter(char *filePath) {
int typeCheck; int typeCheck;
int array_len; int array_len;
int i; int i;
if((fsock = open(filePath, O_RDONLY)) == -1) { if((fsock = open(filePath, O_RDONLY)) == -1) {
fprintf(stderr,"error opening file %s\n", filePath); fprintf(stderr,"error opening file %s\n", filePath);
exit(-1); exit(-1);
@@ -3031,7 +3053,7 @@ static void produceBpfFilter(char *filePath) {
fprintf(stderr,"ERROR: can't get \"statistics\", use -x flag only with .json files generated by ndpiReader -b flag.\n"); fprintf(stderr,"ERROR: can't get \"statistics\", use -x flag only with .json files generated by ndpiReader -b flag.\n");
exit(-1); exit(-1);
} }
if((typeCheck = json_object_is_type(jObj_statistics, json_type_array)) == 0) { if((typeCheck = json_object_is_type(jObj_statistics, json_type_array)) == 0) {
fprintf(stderr,"ERROR: invalid json file. Use -x flag only with .json files generated by ndpiReader -b flag.\n"); fprintf(stderr,"ERROR: invalid json file. Use -x flag only with .json files generated by ndpiReader -b flag.\n");
exit(-1); exit(-1);
@@ -3055,7 +3077,7 @@ static void produceBpfFilter(char *filePath) {
if((average = getAverage(val, "top.scanner.stats")) != 0){ if((average = getAverage(val, "top.scanner.stats")) != 0){
deviation = getStdDeviation(val, average, "top.scanner.stats"); deviation = getStdDeviation(val, average, "top.scanner.stats");
getScannerHosts(val, duration, filterSrcHosts, HOST_ARRAY_SIZE, average+deviation); getScannerHosts(val, duration, filterSrcHosts, HOST_ARRAY_SIZE, average+deviation);
} }
@@ -3072,7 +3094,7 @@ static void produceBpfFilter(char *filePath) {
} }
if((average = getAverage(val, "top.src.pkts.stats")) != 0) if((average = getAverage(val, "top.src.pkts.stats")) != 0)
getSourcePorts(val, filterSrcPorts, PORT_ARRAY_SIZE, average); getSourcePorts(val, filterSrcPorts, PORT_ARRAY_SIZE, average);
if((res = json_object_object_get_ex(stats, "top.dst.pkts.stats", &val)) == 0) { if((res = json_object_object_get_ex(stats, "top.dst.pkts.stats", &val)) == 0) {
@@ -3081,7 +3103,7 @@ static void produceBpfFilter(char *filePath) {
} }
getDestinationHosts(val, duration, filterDstHosts, HOST_ARRAY_SIZE); getDestinationHosts(val, duration, filterDstHosts, HOST_ARRAY_SIZE);
} }
fileName = basename(filePath); fileName = basename(filePath);
snprintf(_filterFilePath, sizeof(_filterFilePath), "%s.bpf", filePath); snprintf(_filterFilePath, sizeof(_filterFilePath), "%s.bpf", filePath);
@@ -3089,20 +3111,20 @@ static void produceBpfFilter(char *filePath) {
if((fp = fopen(_filterFilePath,"w")) == NULL) { if((fp = fopen(_filterFilePath,"w")) == NULL) {
printf("Error creating .json file %s\n", _filterFilePath); printf("Error creating .json file %s\n", _filterFilePath);
exit(-1); exit(-1);
} }
jObj_bpfFilter = json_object_new_object(); jObj_bpfFilter = json_object_new_object();
bpf_filter_pkt_peak_filter(&jObj_bpfFilter, filterSrcPorts, PORT_ARRAY_SIZE, bpf_filter_pkt_peak_filter(&jObj_bpfFilter, filterSrcPorts, PORT_ARRAY_SIZE,
filterSrcHosts, HOST_ARRAY_SIZE, filterPktDstHosts, HOST_ARRAY_SIZE/2); filterSrcHosts, HOST_ARRAY_SIZE, filterPktDstHosts, HOST_ARRAY_SIZE/2);
bpf_filter_host_peak_filter(&jObj_bpfFilter, filterDstHosts, HOST_ARRAY_SIZE); bpf_filter_host_peak_filter(&jObj_bpfFilter, filterDstHosts, HOST_ARRAY_SIZE);
fprintf(fp,"%s\n",json_object_to_json_string(jObj_bpfFilter)); fprintf(fp,"%s\n",json_object_to_json_string(jObj_bpfFilter));
fclose(fp); fclose(fp);
printf("created: %s\n", _filterFilePath); printf("created: %s\n", _filterFilePath);
json_object_put(jObj); /* free memory */ json_object_put(jObj); /* free memory */
} }
#endif #endif
+109 -12
View File
@@ -105,6 +105,61 @@ static void free_wrapper(void *freeable) {
/* ***************************************************** */ /* ***************************************************** */
static uint16_t ndpi_get_proto_id(struct ndpi_detection_module_struct *ndpi_mod, const char *name) {
uint16_t proto_id;
char *e;
unsigned long p = strtol(name,&e,0);
if(e && !*e) {
if(p < NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS &&
ndpi_mod->proto_defaults[p].protoName) return (uint16_t)p;
return NDPI_PROTOCOL_UNKNOWN;
}
for(proto_id=NDPI_PROTOCOL_UNKNOWN; proto_id < NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS; proto_id++) {
if(ndpi_mod->proto_defaults[proto_id].protoName &&
!strcasecmp(ndpi_mod->proto_defaults[proto_id].protoName,name))
return proto_id;
}
return NDPI_PROTOCOL_UNKNOWN;
}
static NDPI_PROTOCOL_BITMASK debug_bitmask;
static char _proto_delim[] = " \t,:;";
static int parse_debug_proto(struct ndpi_detection_module_struct *ndpi_mod, char *str) {
char *n;
uint16_t proto;
char op=1;
for(n = strtok(str,_proto_delim); n && *n; n = strtok(NULL,_proto_delim)) {
if(*n == '-') {
op = 0;
n++;
} else if(*n == '+') {
op = 1;
n++;
}
if(!strcmp(n,"all")) {
if(op)
NDPI_BITMASK_SET_ALL(debug_bitmask);
else
NDPI_BITMASK_RESET(debug_bitmask);
continue;
}
proto = ndpi_get_proto_id(ndpi_mod, n);
if(proto == NDPI_PROTOCOL_UNKNOWN && strcmp(n,"unknown") && strcmp(n,"0")) {
fprintf(stderr,"Invalid protocol %s\n",n);
return 1;
}
if(op)
NDPI_BITMASK_ADD(debug_bitmask,proto);
else
NDPI_BITMASK_DEL(debug_bitmask,proto);
}
return 0;
}
/* ***************************************************** */
extern char *_debug_protocols;
static int _debug_protocols_ok = 0;
struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle) { struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle) {
set_ndpi_malloc(malloc_wrapper), set_ndpi_free(free_wrapper); set_ndpi_malloc(malloc_wrapper), set_ndpi_free(free_wrapper);
set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL); set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL);
@@ -121,7 +176,18 @@ struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * pre
NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n"); NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n");
exit(-1); exit(-1);
} }
module->ndpi_log_level = nDPI_LogLevel;
if(_debug_protocols != NULL && ! _debug_protocols_ok) {
if(parse_debug_proto(module,_debug_protocols))
exit(-1);
_debug_protocols_ok = 1;
}
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
NDPI_BITMASK_RESET(module->debug_bitmask);
if(_debug_protocols_ok)
module->debug_bitmask = debug_bitmask;
#endif
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *)); workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
return workflow; return workflow;
} }
@@ -296,6 +362,26 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
idx = hashval % workflow->prefs.num_roots; idx = hashval % workflow->prefs.num_roots;
ret = ndpi_tfind(&flow, &workflow->ndpi_flows_root[idx], ndpi_workflow_node_cmp); ret = ndpi_tfind(&flow, &workflow->ndpi_flows_root[idx], ndpi_workflow_node_cmp);
/* to avoid two nodes in one binary tree for a flow */
int is_changed = 0;
if(ret == NULL)
{
u_int32_t orig_src_ip = flow.src_ip;
u_int16_t orig_src_port = flow.src_port;
u_int32_t orig_dst_ip = flow.dst_ip;
u_int16_t orig_dst_port = flow.dst_port;
flow.src_ip = orig_dst_ip;
flow.src_port = orig_dst_port;
flow.dst_ip = orig_src_ip;
flow.dst_port = orig_src_port;
is_changed = 1;
ret = ndpi_tfind(&flow, &workflow->ndpi_flows_root[idx], ndpi_workflow_node_cmp);
}
if(ret == NULL) { if(ret == NULL) {
if(workflow->stats.ndpi_flow_count == workflow->prefs.max_ndpi_flows) { if(workflow->stats.ndpi_flow_count == workflow->prefs.max_ndpi_flows) {
NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR, NDPI_LOG(0, workflow->ndpi_struct, NDPI_LOG_ERROR,
@@ -359,15 +445,26 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
} else { } else {
struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)ret; struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)ret;
if(flow->src_ip == iph->saddr if (is_changed) {
&& flow->dst_ip == iph->daddr if(flow->src_ip == iph->saddr
&& flow->src_port == htons(*sport) && flow->dst_ip == iph->daddr
&& flow->dst_port == htons(*dport) && flow->src_port == htons(*sport)
) && flow->dst_port == htons(*dport)
*src = flow->src_id, *dst = flow->dst_id, *src_to_dst_direction = 1; )
else *src = flow->dst_id, *dst = flow->src_id, *src_to_dst_direction = 0, flow->bidirectional = 1;
*src = flow->dst_id, *dst = flow->src_id, *src_to_dst_direction = 0, flow->bidirectional = 1; else
*src = flow->src_id, *dst = flow->dst_id, *src_to_dst_direction = 1;
}
else {
if(flow->src_ip == iph->saddr
&& flow->dst_ip == iph->daddr
&& flow->src_port == htons(*sport)
&& flow->dst_port == htons(*dport)
)
*src = flow->src_id, *dst = flow->dst_id, *src_to_dst_direction = 1;
else
*src = flow->dst_id, *dst = flow->src_id, *src_to_dst_direction = 0, flow->bidirectional = 1;
}
return flow; return flow;
} }
} }
@@ -393,7 +490,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
iph.version = IPVERSION; iph.version = IPVERSION;
iph.saddr = iph6->ip6_src.u6_addr.u6_addr32[2] + iph6->ip6_src.u6_addr.u6_addr32[3]; iph.saddr = iph6->ip6_src.u6_addr.u6_addr32[2] + iph6->ip6_src.u6_addr.u6_addr32[3];
iph.daddr = iph6->ip6_dst.u6_addr.u6_addr32[2] + iph6->ip6_dst.u6_addr.u6_addr32[3]; iph.daddr = iph6->ip6_dst.u6_addr.u6_addr32[2] + iph6->ip6_dst.u6_addr.u6_addr32[3];
iph.protocol = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt; iph.protocol = iph6->ip6_hdr.ip6_un1_nxt;
if(iph.protocol == IPPROTO_DSTOPTS /* IPv6 destination option */) { if(iph.protocol == IPPROTO_DSTOPTS /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ipv6hdr); u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ipv6hdr);
@@ -403,7 +500,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
return(get_ndpi_flow_info(workflow, 6, vlan_id, &iph, iph6, ip_offset, return(get_ndpi_flow_info(workflow, 6, vlan_id, &iph, iph6, ip_offset,
sizeof(struct ndpi_ipv6hdr), sizeof(struct ndpi_ipv6hdr),
ntohs(iph6->ip6_ctlun.ip6_un1.ip6_un1_plen), ntohs(iph6->ip6_hdr.ip6_un1_plen),
tcph, udph, sport, dport, tcph, udph, sport, dport,
src, dst, proto, payload, payload_len, src_to_dst_direction)); src, dst, proto, payload, payload_len, src_to_dst_direction));
} }
@@ -815,7 +912,7 @@ struct ndpi_proto ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
} }
} else if(iph->version == 6) { } else if(iph->version == 6) {
iph6 = (struct ndpi_ipv6hdr *)&packet[ip_offset]; iph6 = (struct ndpi_ipv6hdr *)&packet[ip_offset];
proto = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt; proto = iph6->ip6_hdr.ip6_un1_nxt;
ip_len = sizeof(struct ndpi_ipv6hdr); ip_len = sizeof(struct ndpi_ipv6hdr);
if(proto == IPPROTO_DSTOPTS /* IPv6 destination option */) { if(proto == IPPROTO_DSTOPTS /* IPv6 destination option */) {
+3
View File
@@ -179,4 +179,7 @@ int ndpi_workflow_node_cmp(const void *a, const void *b);
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow); void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow);
u_int32_t ethernet_crc32(const void* data, size_t n_bytes); u_int32_t ethernet_crc32(const void* data, size_t n_bytes);
void ndpi_flow_info_freer(void *node); void ndpi_flow_info_freer(void *node);
extern int nDPI_LogLevel;
#endif #endif
+3 -1
View File
@@ -22,6 +22,7 @@ ndpi_init_detection_module
ndpi_get_num_supported_protocols ndpi_get_num_supported_protocols
ndpi_set_proto_defaults ndpi_set_proto_defaults
ndpi_get_protocol_id ndpi_get_protocol_id
ndpi_get_category_id
ndpi_find_port_based_protocol ndpi_find_port_based_protocol
ndpi_get_http_method ndpi_get_http_method
ndpi_get_http_url ndpi_get_http_url
@@ -58,4 +59,5 @@ ndpi_netbios_name_interpret
ndpi_category_set_name ndpi_category_set_name
ndpi_category_get_name ndpi_category_get_name
ndpi_is_custom_category ndpi_is_custom_category
ndpi_is_subprotocol_informative ndpi_is_subprotocol_informative
ndpi_set_proto_category
+27 -2
View File
@@ -383,6 +383,20 @@ extern "C" {
u_int16_t master_protocol_id); u_int16_t master_protocol_id);
/**
* Exclude protocol from search
*
* @par ndpi_struct = the detection module
* @par flow = the flow where match the host
* @par master_protocol_id = value of the ID associated to the master protocol detected
*
*/
void ndpi_exclude_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t master_protocol_id,
const char *_file, const char *_func,int _line);
/** /**
* Check if the string -bigram_to_match- match with a bigram of -automa- * Check if the string -bigram_to_match- match with a bigram of -automa-
* *
@@ -519,13 +533,24 @@ extern "C" {
* Return the ID of the protocol * Return the ID of the protocol
* *
* @par ndpi_mod = the detection module * @par ndpi_mod = the detection module
* @par proto = the ID of the protocol * @par proto = the protocol name
* @return the string name of the breed ID * @return the ID of the protocol
* *
*/ */
int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto); int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto);
/**
* Return the ID of the category
*
* @par ndpi_mod = the detection module
* @par proto = the category name
* @return the ID of the category
*
*/
int ndpi_get_category_id(struct ndpi_detection_module_struct *ndpi_mod, char *cat);
/** /**
* Write the list of the supported protocols * Write the list of the supported protocols
* *
+56 -13
View File
@@ -180,24 +180,67 @@
#define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600 #define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
#define NDPI_LOG(proto, m, log_level, args...) \ #define NDPI_LOG(proto, m, log_level, args...) \
{ \ { \
struct ndpi_detection_module_struct *mod = (struct ndpi_detection_module_struct*) m; \ struct ndpi_detection_module_struct *mod = (struct ndpi_detection_module_struct*) m; \
if(mod != NULL) { \ if(mod != NULL && mod->ndpi_debug_printf != NULL) \
mod->ndpi_debug_print_file=__FILE__; \ (*(mod->ndpi_debug_printf))(proto, mod, log_level, __FILE__, __FUNCTION__, __LINE__, args); \
mod->ndpi_debug_print_function=__FUNCTION__; \
mod->ndpi_debug_print_line=__LINE__; \
(*(mod->ndpi_debug_printf))(proto, mod, log_level, args); \
} \
} }
#else /* NDPI_ENABLE_DEBUG_MESSAGES */
#ifdef WIN32 /* We must define NDPI_CURRENT_PROTO before include ndpi_main.h !!!
#define NDPI_LOG(...) {} *
#else * #include "ndpi_protocol_ids.h"
#define NDPI_LOG(proto, mod, log_level, args...) {} * #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_XXXX
#endif * #include "ndpi_api.h"
*
*/
#ifndef NDPI_CURRENT_PROTO
#define NDPI_CURRENT_PROTO NDPI_PROTO_UNKNOWN
#endif
#define NDPI_LOG_ERR(mod, args...) \
if(mod && mod->ndpi_log_level >= NDPI_LOG_ERROR) { \
if(mod != NULL && mod->ndpi_debug_printf != NULL) \
(*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_ERROR , __FILE__, __FUNCTION__, __LINE__, args); \
}
#define NDPI_LOG_INFO(mod, args...) \
if(mod && mod->ndpi_log_level >= NDPI_LOG_TRACE) { \
if(mod != NULL && mod->ndpi_debug_printf != NULL) \
(*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_TRACE , __FILE__, __FUNCTION__, __LINE__, args); \
}
#define NDPI_LOG_DBG(mod, args...) \
if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG) { \
if(mod != NULL && mod->ndpi_debug_printf != NULL) \
(*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG , __FILE__, __FUNCTION__, __LINE__, args); \
}
#define NDPI_LOG_DBG2(mod, args...) \
if(mod && mod->ndpi_log_level >= NDPI_LOG_DEBUG_EXTRA) { \
if(mod != NULL && mod->ndpi_debug_printf != NULL) \
(*(mod->ndpi_debug_printf))(NDPI_CURRENT_PROTO, mod, NDPI_LOG_DEBUG_EXTRA , __FILE__, __FUNCTION__, __LINE__, args); \
}
#else /* not defined NDPI_ENABLE_DEBUG_MESSAGES */
# ifdef WIN32
# define NDPI_LOG(...) {}
# define NDPI_LOG_ERR(...) {}
# define NDPI_LOG_INFO(...) {}
# define NDPI_LOG_DBG(...) {}
# define NDPI_LOG_DBG2(...) {}
# else
# define NDPI_LOG(proto, mod, log_level, args...) {}
# define NDPI_LOG_ERR(mod, args...) {}
# define NDPI_LOG_INFO(mod, args...) {}
# define NDPI_LOG_DBG(mod, args...) {}
# define NDPI_LOG_DBG2(mod, args...) {}
# endif
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */ #endif /* NDPI_ENABLE_DEBUG_MESSAGES */
#define NDPI_EXCLUDE_PROTO(mod,flow) ndpi_exclude_protocol(mod, flow, NDPI_CURRENT_PROTO, __FILE__, __FUNCTION__, __LINE__)
/** /**
* macro for getting the string len of a static string * macro for getting the string len of a static string
* *
+5 -4
View File
@@ -1,3 +1,4 @@
/* /*
* ndpi_protocol_ids.h * ndpi_protocol_ids.h
* *
@@ -108,7 +109,7 @@
#define NDPI_PROTOCOL_OSCAR 69 #define NDPI_PROTOCOL_OSCAR 69
#define NDPI_PROTOCOL_YAHOO 70 #define NDPI_PROTOCOL_YAHOO 70
#define NDPI_PROTOCOL_BATTLEFIELD 71 #define NDPI_PROTOCOL_BATTLEFIELD 71
#define NDPI_PROTOCOL_QUAKE 72 #define NDPI_PROTOCOL_GOOGLE_PLUS 72
#define NDPI_PROTOCOL_IP_VRRP 73 #define NDPI_PROTOCOL_IP_VRRP 73
#define NDPI_PROTOCOL_STEAM 74 /* Tomasz Bujlow <tomasz@skatnet.dk> */ #define NDPI_PROTOCOL_STEAM 74 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_PROTOCOL_HALFLIFE2 75 #define NDPI_PROTOCOL_HALFLIFE2 75
@@ -172,9 +173,9 @@
#define NDPI_PROTOCOL_NETFLIX 133 #define NDPI_PROTOCOL_NETFLIX 133
#define NDPI_PROTOCOL_LASTFM 134 #define NDPI_PROTOCOL_LASTFM 134
#define NDPI_PROTOCOL_WAZE 135 #define NDPI_PROTOCOL_WAZE 135
#define NDPI_PROTOCOL_SKYFILE_PREPAID 136 /* free for future use */ #define NDPI_PROTOCOL_YOUTUBE_UPLOAD 136 /* Upload files to youtube */
#define NDPI_PROTOCOL_SKYFILE_RUDICS 137 /* free for future use */ #define NDPI_PROTOCOL_ICQ 137
#define NDPI_PROTOCOL_SKYFILE_POSTPAID 138 /* free for future use */ #define NDPI_PROTOCOL_CHECKMK 138
#define NDPI_PROTOCOL_CITRIX_ONLINE 139 #define NDPI_PROTOCOL_CITRIX_ONLINE 139
#define NDPI_PROTOCOL_APPLE 140 #define NDPI_PROTOCOL_APPLE 140
#define NDPI_PROTOCOL_WEBEX 141 #define NDPI_PROTOCOL_WEBEX 141
+2
View File
@@ -140,6 +140,7 @@ void ndpi_search_pptp(struct ndpi_detection_module_struct *ndpi_struct, struct n
void ndpi_search_stealthnet(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_stealthnet(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_dhcpv6_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_dhcpv6_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_afp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_afp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_checkmk(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_florensia(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_florensia(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_maplestory(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); void ndpi_search_maplestory(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
@@ -348,5 +349,6 @@ void init_tinc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int
void init_fix_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_fix_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_nintendo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_nintendo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_csgo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask); void init_csgo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_checkmk_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
#endif /* __NDPI_PROTOCOLS_H__ */ #endif /* __NDPI_PROTOCOLS_H__ */
+16 -20
View File
@@ -36,7 +36,8 @@ typedef enum
{ {
NDPI_LOG_ERROR, NDPI_LOG_ERROR,
NDPI_LOG_TRACE, NDPI_LOG_TRACE,
NDPI_LOG_DEBUG NDPI_LOG_DEBUG,
NDPI_LOG_DEBUG_EXTRA
} ndpi_log_level_t; } ndpi_log_level_t;
/* NDPI_VISIT */ /* NDPI_VISIT */
@@ -205,34 +206,27 @@ struct ndpi_iphdr {
/* +++++++++++++++++++++++ IPv6 header +++++++++++++++++++++++ */ /* +++++++++++++++++++++++ IPv6 header +++++++++++++++++++++++ */
/* rfc3542 */ /* rfc3542 */
struct ndpi_in6_addr struct ndpi_in6_addr {
{ union {
union
{
u_int8_t u6_addr8[16]; u_int8_t u6_addr8[16];
u_int16_t u6_addr16[8]; u_int16_t u6_addr16[8];
u_int32_t u6_addr32[4]; u_int32_t u6_addr32[4];
} u6_addr; /* 128-bit IP6 address */ } u6_addr; /* 128-bit IP6 address */
}; };
PACK_ON struct ndpi_ip6_hdrctl {
struct ndpi_ipv6hdr u_int32_t ip6_un1_flow;
{ u_int16_t ip6_un1_plen;
union u_int8_t ip6_un1_nxt;
{ u_int8_t ip6_un1_hlim;
struct ndpi_ip6_hdrctl };
{
u_int32_t ip6_un1_flow;
u_int16_t ip6_un1_plen;
u_int8_t ip6_un1_nxt;
u_int8_t ip6_un1_hlim;
} ip6_un1;
u_int8_t ip6_un2_vfc;
} ip6_ctlun;
/* PACK_ON */
struct ndpi_ipv6hdr {
struct ndpi_ip6_hdrctl ip6_hdr;
struct ndpi_in6_addr ip6_src; struct ndpi_in6_addr ip6_src;
struct ndpi_in6_addr ip6_dst; struct ndpi_in6_addr ip6_dst;
} PACK_OFF; } /* PACK_OFF */;
/* +++++++++++++++++++++++ TCP header +++++++++++++++++++++++ */ /* +++++++++++++++++++++++ TCP header +++++++++++++++++++++++ */
@@ -859,12 +853,14 @@ struct ndpi_detection_module_struct {
ndpi_default_ports_tree_node_t *tcpRoot, *udpRoot; ndpi_default_ports_tree_node_t *tcpRoot, *udpRoot;
ndpi_log_level_t ndpi_log_level; /* default error */
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
/* debug callback, only set when debug is used */ /* debug callback, only set when debug is used */
ndpi_debug_function_ptr ndpi_debug_printf; ndpi_debug_function_ptr ndpi_debug_printf;
const char *ndpi_debug_print_file; const char *ndpi_debug_print_file;
const char *ndpi_debug_print_function; const char *ndpi_debug_print_function;
u_int32_t ndpi_debug_print_line; u_int32_t ndpi_debug_print_line;
NDPI_PROTOCOL_BITMASK debug_bitmask;
#endif #endif
/* misc parameters */ /* misc parameters */
+9 -1
View File
@@ -24,7 +24,15 @@
#ifndef __NDPI_WIN32_H__ #ifndef __NDPI_WIN32_H__
#define __NDPI_WIN32_H__ #define __NDPI_WIN32_H__
// fix a MinGW build issue "error: multiple storage classes in declaration specifiers" due to MinGW
// defining extern for __forceinline types
#if (defined(__MINGW32__) || defined(__MINGW64__)) && defined(__GNUC__)
#define MINGW_GCC
#define __mingw_forceinline __inline__ __attribute__((__always_inline__,__gnu_inline__))
#endif
#include <winsock2.h> #include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <process.h> #include <process.h>
#include <io.h> #include <io.h>
@@ -40,7 +48,7 @@
#define IPVERSION 4 /* on *nix it is defined in netinet/ip.h */ #define IPVERSION 4 /* on *nix it is defined in netinet/ip.h */
extern char* strsep(char **sp, const char *sep); extern char* strsep(char **sp, char *sep);
typedef unsigned char u_char; typedef unsigned char u_char;
typedef unsigned short u_short; typedef unsigned short u_short;
+1 -1
View File
@@ -27,6 +27,7 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/bgp.c \ protocols/bgp.c \
protocols/bittorrent.c \ protocols/bittorrent.c \
protocols/bjnp.c \ protocols/bjnp.c \
protocols/checkmk.c \
protocols/ciscovpn.c \ protocols/ciscovpn.c \
protocols/citrix.c \ protocols/citrix.c \
protocols/coap.c \ protocols/coap.c \
@@ -104,7 +105,6 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/ppstream.c \ protocols/ppstream.c \
protocols/pptp.c \ protocols/pptp.c \
protocols/qq.c \ protocols/qq.c \
protocols/quake.c \
protocols/quic.c \ protocols/quic.c \
protocols/radius.c \ protocols/radius.c \
protocols/rdp.c \ protocols/rdp.c \
+14 -3
View File
@@ -8044,11 +8044,13 @@ ndpi_protocol_match host_match[] = {
{ "swscan.apple.com", "AppleStore", NDPI_PROTOCOL_APPLESTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE }, { "swscan.apple.com", "AppleStore", NDPI_PROTOCOL_APPLESTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE },
{ "itunes-apple.com", "AppleStore", NDPI_PROTOCOL_APPLESTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE }, { "itunes-apple.com", "AppleStore", NDPI_PROTOCOL_APPLESTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE },
{ "itunes.apple.com", "AppleiTunes", NDPI_PROTOCOL_APPLE_ITUNES, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_FUN }, { "itunes.apple.com", "AppleiTunes", NDPI_PROTOCOL_APPLE_ITUNES, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_FUN },
{ "aaplimg.com", "Apple", NDPI_PROTOCOL_APPLE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE },
{ ".cnn.c", "CNN", NDPI_PROTOCOL_CNN, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE }, { ".cnn.c", "CNN", NDPI_PROTOCOL_CNN, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE },
{ ".cnn.net", "CNN", NDPI_PROTOCOL_CNN, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE }, { ".cnn.net", "CNN", NDPI_PROTOCOL_CNN, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE },
{ ".dropbox.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE }, { ".dropbox.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE },
{ ".dropboxstatic.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE },
{ ".dropbox-dns.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE }, { ".dropbox-dns.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE },
{ "log.getdropbox.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE }, { "log.getdropbox.com", "DropBox", NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_CATEGORY_CLOUD, NDPI_PROTOCOL_ACCEPTABLE },
@@ -8076,6 +8078,8 @@ ndpi_protocol_match host_match[] = {
{ "android.clients.google.com", "PlayStore", NDPI_PROTOCOL_PLAYSTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE }, { "android.clients.google.com", "PlayStore", NDPI_PROTOCOL_PLAYSTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE },
{ "ggpht.com", "PlayStore", NDPI_PROTOCOL_PLAYSTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE }, { "ggpht.com", "PlayStore", NDPI_PROTOCOL_PLAYSTORE, NDPI_PROTOCOL_CATEGORY_SW_UPDATE, NDPI_PROTOCOL_SAFE },
{ "plus.google.com", "GooglePlus", NDPI_PROTOCOL_GOOGLE_PLUS, NDPI_PROTOCOL_CATEGORY_SOCIAL_NETWORK, NDPI_PROTOCOL_FUN },
{ "plus.url.google.com", "GooglePlus", NDPI_PROTOCOL_GOOGLE_PLUS, NDPI_PROTOCOL_CATEGORY_SOCIAL_NETWORK, NDPI_PROTOCOL_FUN },
{ "google.", "Google", NDPI_PROTOCOL_GOOGLE, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE }, { "google.", "Google", NDPI_PROTOCOL_GOOGLE, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE },
{ ".google.", "Google", NDPI_PROTOCOL_GOOGLE, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE }, { ".google.", "Google", NDPI_PROTOCOL_GOOGLE, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE },
{ ".gstatic.com", "Google", NDPI_PROTOCOL_GOOGLE, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE }, { ".gstatic.com", "Google", NDPI_PROTOCOL_GOOGLE, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE },
@@ -8138,6 +8142,8 @@ ndpi_protocol_match host_match[] = {
{ ".yimg.com", "Yahoo", NDPI_PROTOCOL_YAHOO, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE }, { ".yimg.com", "Yahoo", NDPI_PROTOCOL_YAHOO, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_SAFE },
{ "yahooapis.", "Yahoo", NDPI_PROTOCOL_YAHOO, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_ACCEPTABLE }, { "yahooapis.", "Yahoo", NDPI_PROTOCOL_YAHOO, NDPI_PROTOCOL_CATEGORY_WEB, NDPI_PROTOCOL_ACCEPTABLE },
{ "upload.youtube.com", "YouTubeUpload", NDPI_PROTOCOL_YOUTUBE_UPLOAD, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
{ "upload.video.google.com", "YouTubeUpload", NDPI_PROTOCOL_YOUTUBE_UPLOAD, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
{ "youtube.", "YouTube", NDPI_PROTOCOL_YOUTUBE, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN }, { "youtube.", "YouTube", NDPI_PROTOCOL_YOUTUBE, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
{ "youtu.be.", "YouTube", NDPI_PROTOCOL_YOUTUBE, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN }, { "youtu.be.", "YouTube", NDPI_PROTOCOL_YOUTUBE, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
{ "yt3.ggpht.com", "YouTube", NDPI_PROTOCOL_YOUTUBE, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN }, { "yt3.ggpht.com", "YouTube", NDPI_PROTOCOL_YOUTUBE, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
@@ -8308,7 +8314,12 @@ ndpi_protocol_match host_match[] = {
{ ".soundcloud.com", "SoundCloud", NDPI_PROTOCOL_SOUNDCLOUD, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN }, { ".soundcloud.com", "SoundCloud", NDPI_PROTOCOL_SOUNDCLOUD, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
{ "getrockerbox.com", "SoundCloud", NDPI_PROTOCOL_SOUNDCLOUD, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN }, { "getrockerbox.com", "SoundCloud", NDPI_PROTOCOL_SOUNDCLOUD, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
{ "web.telegram.org", "Telegram", NDPI_PROTOCOL_TELEGRAM, NDPI_PROTOCOL_CATEGORY_CHAT, NDPI_PROTOCOL_ACCEPTABLE }, { "web.telegram.org", "Telegram", NDPI_PROTOCOL_TELEGRAM, NDPI_PROTOCOL_CATEGORY_CHAT, NDPI_PROTOCOL_ACCEPTABLE },
{ "tdesktop.com", "Telegram", NDPI_PROTOCOL_TELEGRAM, NDPI_PROTOCOL_CATEGORY_CHAT, NDPI_PROTOCOL_ACCEPTABLE },
{ "tupdate.com", "Telegram", NDPI_PROTOCOL_TELEGRAM, NDPI_PROTOCOL_CATEGORY_CHAT, NDPI_PROTOCOL_ACCEPTABLE },
{ ".icq.", "ICQ", NDPI_PROTOCOL_ICQ, NDPI_PROTOCOL_CATEGORY_CHAT, NDPI_PROTOCOL_ACCEPTABLE },
{ "icq.", "ICQ", NDPI_PROTOCOL_ICQ, NDPI_PROTOCOL_CATEGORY_CHAT, NDPI_PROTOCOL_ACCEPTABLE },
{ NULL, 0 } { NULL, 0 }
}; };
@@ -8439,8 +8450,8 @@ static const char *ndpi_en_impossible_bigrams[] = {
"jl", "jm", "jn", "jp", "jq", "jr", /* "js", */ "jt", "jv", "jw", "jx", "jy", "jz", "kg", "kq", "kv", "kx", "jl", "jm", "jn", "jp", "jq", "jr", /* "js", */ "jt", "jv", "jw", "jx", "jy", "jz", "kg", "kq", "kv", "kx",
"kz", "lq", "lx", "mg", "mj", "mq", "mx", "mz", "pq", "pv", "px", "qb", "qc", "qd", "qe", "qf", "ii", "kz", "lq", "lx", "mg", "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", "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", "vk", "vm", "vn", "vp", "bw", "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", "xg", "xj", "xk", "xv", "xz", "xw", "yd", /*"yp", Removed for paypal */ "vq", "vt", "vw", "vx", "vz", "wq", "wv", "wx", "wz", "xb", "xg", "xj", "xk", "xv", "xz", "xw", "yd", /*"yp", Removed for paypal */
"yj", "yq", "yv", "yz", "yw", "zb", "zc", "zg", "zh", "zj", "zn", "zq", "zr", "zs", "zx", "wh", "wk", "yj", "yq", "yv", "yz", "yw", "zb", "zc", "zg", "zh", "zj", "zn", "zq", "zs", "zx", "wh", "wk",
"wb", "zk", "kp", "zk", "xy", "wb", "zk", "kp", "zk", "xy",
NULL }; NULL };
+180 -200
View File
@@ -24,6 +24,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "ahocorasick.h" #include "ahocorasick.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
#include "ndpi_api.h" #include "ndpi_api.h"
#include "../../config.h" #include "../../config.h"
@@ -36,6 +39,7 @@
#include "third_party/include/ndpi_patricia.h" #include "third_party/include/ndpi_patricia.h"
#include "third_party/src/ndpi_patricia.c" #include "third_party/src/ndpi_patricia.c"
static int _ndpi_debug_callbacks = 0;
/* implementation of the punycode check function */ /* implementation of the punycode check function */
int check_punycode_string(char * buffer , int len) int check_punycode_string(char * buffer , int len)
@@ -301,10 +305,12 @@ int strncasecmp(s1, s2, n)
/* ****************************************** */ /* ****************************************** */
/* Forward */ /* Forward */
static void addDefaultPort(ndpi_port_range *range, static void addDefaultPort(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_port_range *range,
ndpi_proto_defaults_t *def, ndpi_proto_defaults_t *def,
u_int8_t customUserProto, u_int8_t customUserProto,
ndpi_default_ports_tree_node_t **root); ndpi_default_ports_tree_node_t **root,
const char *_func, int _line);
static int removeDefaultPort(ndpi_port_range *range, static int removeDefaultPort(ndpi_port_range *range,
ndpi_proto_defaults_t *def, ndpi_proto_defaults_t *def,
@@ -477,6 +483,27 @@ u_int8_t ndpi_is_subprotocol_informative(struct ndpi_detection_module_struct *nd
return(0); return(0);
} }
} }
/* ********************************************************************************** */
void ndpi_exclude_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t protocol_id,
const char *_file, const char *_func,int _line) {
if(protocol_id < NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS) {
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
if ( ndpi_struct &&
ndpi_struct->ndpi_log_level >= NDPI_LOG_DEBUG &&
ndpi_struct->ndpi_debug_printf != NULL) {
(*(ndpi_struct->ndpi_debug_printf))(protocol_id, ndpi_struct, NDPI_LOG_DEBUG,
_file, _func, _line, "exclude %s\n",ndpi_get_proto_name(ndpi_struct, protocol_id));
}
#endif
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, protocol_id);
}
}
/* ********************************************************************************** */ /* ********************************************************************************** */
@@ -490,14 +517,14 @@ void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
if(protoId >= NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS) { if(protoId >= NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS) {
#ifdef DEBUG #ifdef DEBUG
printf("[NDPI] %s(%s/protoId=%d): INTERNAL ERROR\n", __FUNCTION__, protoName, protoId); NDPI_LOG_ERR(ndpi_mod, "[NDPI] %s/protoId=%d: INTERNAL ERROR\n", protoName, protoId);
#endif #endif
return; return;
} }
if(ndpi_mod->proto_defaults[protoId].protoName != NULL) { if(ndpi_mod->proto_defaults[protoId].protoName != NULL) {
#ifdef DEBUG #ifdef DEBUG
printf("[NDPI] %s(%s/protoId=%d): already initialized. Ignoring it\n", __FUNCTION__, protoName, protoId); NDPI_LOG_ERR(ndpi_mod, "[NDPI] %s/protoId=%d: already initialized. Ignoring it\n", protoName, protoId);
#endif #endif
return; return;
} }
@@ -513,8 +540,8 @@ void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
memcpy(&ndpi_mod->proto_defaults[protoId].master_udp_protoId, udp_master_protoId, 2*sizeof(u_int16_t)); memcpy(&ndpi_mod->proto_defaults[protoId].master_udp_protoId, udp_master_protoId, 2*sizeof(u_int16_t));
for(j=0; j<MAX_DEFAULT_PORTS; j++) { for(j=0; j<MAX_DEFAULT_PORTS; j++) {
if(udpDefPorts[j].port_low != 0) addDefaultPort(&udpDefPorts[j], &ndpi_mod->proto_defaults[protoId], 0, &ndpi_mod->udpRoot); if(udpDefPorts[j].port_low != 0) addDefaultPort(ndpi_mod, &udpDefPorts[j], &ndpi_mod->proto_defaults[protoId], 0, &ndpi_mod->udpRoot, __FUNCTION__,__LINE__);
if(tcpDefPorts[j].port_low != 0) addDefaultPort(&tcpDefPorts[j], &ndpi_mod->proto_defaults[protoId], 0, &ndpi_mod->tcpRoot); if(tcpDefPorts[j].port_low != 0) addDefaultPort(ndpi_mod, &tcpDefPorts[j], &ndpi_mod->proto_defaults[protoId], 0, &ndpi_mod->tcpRoot, __FUNCTION__,__LINE__);
} }
} }
@@ -536,7 +563,6 @@ void ndpi_default_ports_tree_node_t_walker(const void *node, const ndpi_VISIT wh
{ {
ndpi_default_ports_tree_node_t *f = *(ndpi_default_ports_tree_node_t **)node; ndpi_default_ports_tree_node_t *f = *(ndpi_default_ports_tree_node_t **)node;
printf("<%d>Walk on node %s (%u)\n", printf("<%d>Walk on node %s (%u)\n",
depth, depth,
which == ndpi_preorder?"ndpi_preorder": which == ndpi_preorder?"ndpi_preorder":
@@ -548,10 +574,12 @@ void ndpi_default_ports_tree_node_t_walker(const void *node, const ndpi_VISIT wh
/* ******************************************************************** */ /* ******************************************************************** */
static void addDefaultPort(ndpi_port_range *range, static void addDefaultPort(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_port_range *range,
ndpi_proto_defaults_t *def, ndpi_proto_defaults_t *def,
u_int8_t customUserProto, u_int8_t customUserProto,
ndpi_default_ports_tree_node_t **root) ndpi_default_ports_tree_node_t **root,
const char *_func, int _line)
{ {
ndpi_default_ports_tree_node_t *ret; ndpi_default_ports_tree_node_t *ret;
u_int16_t port; u_int16_t port;
@@ -560,7 +588,7 @@ static void addDefaultPort(ndpi_port_range *range,
ndpi_default_ports_tree_node_t *node = (ndpi_default_ports_tree_node_t*)ndpi_malloc(sizeof(ndpi_default_ports_tree_node_t)); ndpi_default_ports_tree_node_t *node = (ndpi_default_ports_tree_node_t*)ndpi_malloc(sizeof(ndpi_default_ports_tree_node_t));
if(!node) { if(!node) {
printf("[NDPI] %s(): not enough memory\n", __FUNCTION__); NDPI_LOG_ERR(ndpi_mod, "%s:%d not enough memory\n", _func, _line);
break; break;
} }
@@ -568,7 +596,8 @@ static void addDefaultPort(ndpi_port_range *range,
ret = *(ndpi_default_ports_tree_node_t**)ndpi_tsearch(node, (void*)root, ndpi_default_ports_tree_node_t_cmp); /* Add it to the tree */ ret = *(ndpi_default_ports_tree_node_t**)ndpi_tsearch(node, (void*)root, ndpi_default_ports_tree_node_t_cmp); /* Add it to the tree */
if(ret != node) { if(ret != node) {
/* printf("[NDPI] %s(): found duplicate for port %u: overwriting it with new value\n", __FUNCTION__, port); */ NDPI_LOG_DBG(ndpi_mod, "[NDPI] %s:%d found duplicate for port %u: overwriting it with new value\n",
_func, _line, port);
ret->proto = def; ret->proto = def;
ndpi_free(node); ndpi_free(node);
@@ -616,7 +645,7 @@ static int ndpi_string_to_automa(struct ndpi_detection_module_struct *ndpi_struc
AC_PATTERN_t ac_pattern; AC_PATTERN_t ac_pattern;
if(protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS)) { if(protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS)) {
printf("[NDPI] %s(protoId=%d): INTERNAL ERROR\n", __FUNCTION__, protocol_id); NDPI_LOG_ERR(ndpi_struct, "[NDPI] protoId=%d: INTERNAL ERROR\n", protocol_id);
return(-1); return(-1);
} }
@@ -640,7 +669,7 @@ static int ndpi_add_host_url_subprotocol(struct ndpi_detection_module_struct *nd
ndpi_protocol_breed_t breed) ndpi_protocol_breed_t breed)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("[NDPI] Adding [%s][%d]\n", value, protocol_id); NDPI_LOG_DEBUG2(ndpi_struct, "[NDPI] Adding [%s][%d]\n", value, protocol_id);
#endif #endif
return(ndpi_string_to_automa(ndpi_struct, &ndpi_struct->host_automa, return(ndpi_string_to_automa(ndpi_struct, &ndpi_struct->host_automa,
@@ -668,7 +697,7 @@ int ndpi_add_content_subprotocol(struct ndpi_detection_module_struct *ndpi_struc
static int ndpi_remove_host_url_subprotocol(struct ndpi_detection_module_struct *ndpi_struct, static int ndpi_remove_host_url_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
char *value, int protocol_id) char *value, int protocol_id)
{ {
printf("[NDPI] Missing implementation of %s()\n", __FUNCTION__); NDPI_LOG_ERR(ndpi_struct, "[NDPI] Missing implementation for proto %s/%d\n",value,protocol_id);
return(-1); return(-1);
} }
@@ -1103,11 +1132,6 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
no_master, "BattleField", NDPI_PROTOCOL_CATEGORY_GAME, no_master, "BattleField", NDPI_PROTOCOL_CATEGORY_GAME,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, 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_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_FUN, NDPI_PROTOCOL_QUAKE,
no_master,
no_master, "Quake", NDPI_PROTOCOL_CATEGORY_GAME,
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_ACCEPTABLE, NDPI_PROTOCOL_IP_VRRP, ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_IP_VRRP,
no_master, no_master,
no_master, "VRRP", NDPI_PROTOCOL_CATEGORY_NETWORK, no_master, "VRRP", NDPI_PROTOCOL_CATEGORY_NETWORK,
@@ -1140,7 +1164,7 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */); ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
custom_master[0] = NDPI_PROTOCOL_SIP, custom_master[1] = NDPI_PROTOCOL_H323; custom_master[0] = NDPI_PROTOCOL_SIP, custom_master[1] = NDPI_PROTOCOL_H323;
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_POTENTIALLY_DANGEROUS, NDPI_PROTOCOL_STUN, ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_STUN,
no_master, no_master,
custom_master, "STUN", NDPI_PROTOCOL_CATEGORY_NETWORK, custom_master, "STUN", NDPI_PROTOCOL_CATEGORY_NETWORK,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */, ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
@@ -1242,6 +1266,11 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
no_master, "AFP", NDPI_PROTOCOL_CATEGORY_DATA_TRANSFER, no_master, "AFP", NDPI_PROTOCOL_CATEGORY_DATA_TRANSFER,
ndpi_build_default_ports(ports_a, 548, 0, 0, 0, 0) /* TCP */, ndpi_build_default_ports(ports_a, 548, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 548, 0, 0, 0, 0) /* UDP */); ndpi_build_default_ports(ports_b, 548, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_CHECKMK,
no_master,
no_master, "CHECKMK", NDPI_PROTOCOL_CATEGORY_DATA_TRANSFER,
ndpi_build_default_ports(ports_a, 6556, 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_POTENTIALLY_DANGEROUS, NDPI_PROTOCOL_STEALTHNET, ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_POTENTIALLY_DANGEROUS, NDPI_PROTOCOL_STEALTHNET,
no_master, no_master,
no_master, "Stealthnet", NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT, no_master, "Stealthnet", NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT,
@@ -1372,21 +1401,6 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
no_master, "Citrix", NDPI_PROTOCOL_CATEGORY_NETWORK, no_master, "Citrix", NDPI_PROTOCOL_CATEGORY_NETWORK,
ndpi_build_default_ports(ports_a, 1494, 2598, 0, 0, 0) /* TCP */, ndpi_build_default_ports(ports_a, 1494, 2598, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */); ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_SKYFILE_PREPAID,
no_master,
no_master, "SkyFile_PrePaid", NDPI_PROTOCOL_CATEGORY_MAIL,
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_ACCEPTABLE, NDPI_PROTOCOL_SKYFILE_RUDICS,
no_master,
no_master, "SkyFile_Rudics", NDPI_PROTOCOL_CATEGORY_MAIL,
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_ACCEPTABLE, NDPI_PROTOCOL_SKYFILE_POSTPAID,
no_master,
no_master, "SkyFile_PostPaid", NDPI_PROTOCOL_CATEGORY_MAIL,
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_ACCEPTABLE, NDPI_PROTOCOL_CITRIX_ONLINE, ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_CITRIX_ONLINE,
no_master, no_master,
no_master, "Citrix_Online", NDPI_PROTOCOL_CATEGORY_REMOTE_ACCESS, no_master, "Citrix_Online", NDPI_PROTOCOL_CATEGORY_REMOTE_ACCESS,
@@ -1686,9 +1700,8 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
if((ndpi_mod->proto_defaults[i].protoName == NULL) if((ndpi_mod->proto_defaults[i].protoName == NULL)
|| ((i != NDPI_PROTOCOL_UNKNOWN) || ((i != NDPI_PROTOCOL_UNKNOWN)
&& (ndpi_mod->proto_defaults[i].protoCategory == NDPI_PROTOCOL_CATEGORY_UNSPECIFIED))) { && (ndpi_mod->proto_defaults[i].protoCategory == NDPI_PROTOCOL_CATEGORY_UNSPECIFIED))) {
printf("[NDPI] %s(missing protoId=%d/%s) INTERNAL ERROR: not all protocols have been initialized\n", NDPI_LOG_ERR(ndpi_mod, "[NDPI] missing protoId=%d/%s: INTERNAL ERROR: not all protocols have been initialized\n",
__FUNCTION__, i, i, ndpi_mod->proto_defaults[i].protoName ? ndpi_mod->proto_defaults[i].protoName : "???");
ndpi_mod->proto_defaults[i].protoName ? ndpi_mod->proto_defaults[i].protoName : "???");
} }
} }
} }
@@ -1837,22 +1850,26 @@ void set_ndpi_flow_malloc(void* (*__ndpi_flow_malloc)(size_t size)) { _ndpi_flow
void set_ndpi_free(void (*__ndpi_free)(void *ptr)) { _ndpi_free = __ndpi_free; } void set_ndpi_free(void (*__ndpi_free)(void *ptr)) { _ndpi_free = __ndpi_free; }
void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr)) { _ndpi_flow_free = __ndpi_flow_free; } void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr)) { _ndpi_flow_free = __ndpi_flow_free; }
void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level, const char * format, ...) void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str,
ndpi_log_level_t log_level, const char *file_name, const char *func_name, int line_number,
const char * format, ...)
{ {
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
va_list args; va_list args;
#define MAX_STR_LEN 120 #define MAX_STR_LEN 120
char str[MAX_STR_LEN]; char str[MAX_STR_LEN];
if(ndpi_str != NULL && log_level > NDPI_LOG_ERROR &&
proto > 0 && proto < NDPI_MAX_SUPPORTED_PROTOCOLS &&
!NDPI_ISSET(&ndpi_str->debug_bitmask,proto)) return;
va_start(args, format); va_start(args, format);
vsprintf(str, format, args); vsprintf(str, format, args);
va_end(args); va_end(args);
if (ndpi_str != NULL) { if (ndpi_str != NULL) {
char proto_name[64]; printf("%s:%s:%-3u - [%s]: %s",
snprintf(proto_name, sizeof(proto_name), "%s", ndpi_get_proto_name(ndpi_str, proto)); file_name, func_name, line_number, ndpi_get_proto_name(ndpi_str, proto), str);
printf("%s:%s:%u - Proto: %s, %s\n", ndpi_str->ndpi_debug_print_file, ndpi_str->ndpi_debug_print_function, ndpi_str->ndpi_debug_print_line, proto_name, str);
} else { } else {
printf("Proto: %u, %s\n", proto, str); printf("Proto: %u, %s", proto, str);
} }
#endif #endif
} }
@@ -1871,7 +1888,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) {
if(ndpi_str == NULL) { if(ndpi_str == NULL) {
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
NDPI_LOG(0, ndpi_str, NDPI_LOG_DEBUG, "ndpi_init_detection_module initial malloc failed for ndpi_str\n"); NDPI_LOG_ERR(ndpi_str, "ndpi_init_detection_module initial malloc failed for ndpi_str\n");
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */ #endif /* NDPI_ENABLE_DEBUG_MESSAGES */
return NULL; return NULL;
} }
@@ -2166,7 +2183,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule,
at = strrchr(rule, '@'); at = strrchr(rule, '@');
if(at == NULL) { if(at == NULL) {
printf("Invalid rule '%s'\n", rule); NDPI_LOG_ERR(ndpi_mod, "Invalid rule '%s'\n", rule);
return(-1); return(-1);
} else } else
at[0] = 0, proto = &at[1]; at[0] = 0, proto = &at[1];
@@ -2197,14 +2214,14 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule,
if(def == NULL) { if(def == NULL) {
if(!do_add) { if(!do_add) {
/* We need to remove a rule */ /* We need to remove a rule */
printf("Unable to find protocol '%s': skipping rule '%s'\n", proto, rule); NDPI_LOG_ERR(ndpi_mod, "Unable to find protocol '%s': skipping rule '%s'\n", proto, rule);
return(-3); return(-3);
} else { } else {
ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS]; ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO }; u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO };
if(ndpi_mod->ndpi_num_custom_protocols >= (NDPI_MAX_NUM_CUSTOM_PROTOCOLS-1)) { if(ndpi_mod->ndpi_num_custom_protocols >= (NDPI_MAX_NUM_CUSTOM_PROTOCOLS-1)) {
printf("Too many protocols defined (%u): skipping protocol %s\n", NDPI_LOG_ERR(ndpi_mod, "Too many protocols defined (%u): skipping protocol %s\n",
ndpi_mod->ndpi_num_custom_protocols, proto); ndpi_mod->ndpi_num_custom_protocols, proto);
return(-2); return(-2);
} }
@@ -2245,7 +2262,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod, char* rule,
if(sscanf(value, "%u-%u", (u_int32_t *)&range.port_low, (u_int32_t *)&range.port_high) != 2) 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]); range.port_low = range.port_high = atoi(&elem[4]);
if(do_add) if(do_add)
addDefaultPort(&range, def, 1 /* Custom user proto */, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot); addDefaultPort(ndpi_mod, &range, def, 1 /* Custom user proto */, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot, __FUNCTION__,__LINE__);
else else
removeDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot); removeDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot);
} else if(is_ip) { } else if(is_ip) {
@@ -2280,7 +2297,7 @@ int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char
int i; int i;
if(fd == NULL) { if(fd == NULL) {
printf("Unable to open file %s [%s]", path, strerror(errno)); NDPI_LOG_ERR(ndpi_mod, "Unable to open file %s [%s]", path, strerror(errno));
return(-1); return(-1);
} }
@@ -2320,14 +2337,18 @@ void ndpi_set_bitmask_protocol_detection(char * label,
*/ */
if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, ndpi_protocol_id) != 0) { if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(*detection_bitmask, ndpi_protocol_id) != 0) {
#ifdef DEBUG #ifdef DEBUG
NDPI_LOG(0, ndpi_struct, NDPI_LOG_DEBUG,"[NDPI] ndpi_set_bitmask_protocol_detection: %s : [callback_buffer] idx= %u, [proto_defaults] protocol_id=%u\n", label, idx, ndpi_protocol_id); NDPI_LOG_DBG2(ndpi_struct
"[NDPI] ndpi_set_bitmask_protocol_detection: %s : [callback_buffer] idx= %u, [proto_defaults] protocol_id=%u\n",
label, idx, ndpi_protocol_id);
#endif #endif
if(ndpi_struct->proto_defaults[ndpi_protocol_id].protoIdx != 0) if(ndpi_struct->proto_defaults[ndpi_protocol_id].protoIdx != 0) {
printf("[NDPI] Internal error: protocol %s/%u has been already registered\n", label, ndpi_protocol_id); NDPI_LOG_DBG2(ndpi_struct,
else { "[NDPI] Internal error: protocol %s/%u has been already registered\n", label, ndpi_protocol_id);
#ifdef DEBUG #ifdef DEBUG
printf("[NDPI] Adding %s with protocol id %d\n", label, ndpi_protocol_id); } else {
NDPI_LOG_DBG2(ndpi_struct,
"[NDPI] Adding %s with protocol id %d\n", label, ndpi_protocol_id);
#endif #endif
} }
@@ -2549,9 +2570,6 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
/* BGP */ /* BGP */
init_bgp_dissector(ndpi_struct, &a, detection_bitmask); init_bgp_dissector(ndpi_struct, &a, detection_bitmask);
/* QUAKE */
init_quake_dissector(ndpi_struct, &a, detection_bitmask);
/* BATTLEFIELD */ /* BATTLEFIELD */
init_battlefield_dissector(ndpi_struct, &a, detection_bitmask); init_battlefield_dissector(ndpi_struct, &a, detection_bitmask);
@@ -2618,6 +2636,9 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
/* AFP */ /* AFP */
init_afp_dissector(ndpi_struct, &a, detection_bitmask); init_afp_dissector(ndpi_struct, &a, detection_bitmask);
/* check_mk */
init_checkmk_dissector(ndpi_struct, &a, detection_bitmask);
/* AIMINI */ /* AIMINI */
init_aimini_dissector(ndpi_struct, &a, detection_bitmask); init_aimini_dissector(ndpi_struct, &a, detection_bitmask);
@@ -2810,7 +2831,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
ndpi_struct->callback_buffer_size = a; ndpi_struct->callback_buffer_size = a;
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"callback_buffer_size is %u\n", ndpi_struct->callback_buffer_size); "callback_buffer_size is %u\n", ndpi_struct->callback_buffer_size);
/* now build the specific buffer for tcp, udp and non_tcp_udp */ /* now build the specific buffer for tcp, udp and non_tcp_udp */
@@ -2821,7 +2842,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
& (NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP | & (NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP |
NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP | NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP |
NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC)) != 0) { NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC)) != 0) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_struct,
"callback_buffer_tcp_payload, adding buffer %u as entry %u\n", a, "callback_buffer_tcp_payload, adding buffer %u as entry %u\n", a,
ndpi_struct->callback_buffer_size_tcp_payload); ndpi_struct->callback_buffer_size_tcp_payload);
@@ -2831,7 +2852,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
if((ndpi_struct-> if((ndpi_struct->
callback_buffer[a].ndpi_selection_bitmask & NDPI_SELECTION_BITMASK_PROTOCOL_HAS_PAYLOAD) == 0) { callback_buffer[a].ndpi_selection_bitmask & NDPI_SELECTION_BITMASK_PROTOCOL_HAS_PAYLOAD) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_struct,
"\tcallback_buffer_tcp_no_payload, additional adding buffer %u to no_payload process\n", a); "\tcallback_buffer_tcp_no_payload, additional adding buffer %u to no_payload process\n", a);
memcpy(&ndpi_struct->callback_buffer_tcp_no_payload memcpy(&ndpi_struct->callback_buffer_tcp_no_payload
@@ -2848,7 +2869,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP | NDPI_SELECTION_BITMASK_PROTOCOL_INT_TCP_OR_UDP |
NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC)) NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC))
!= 0) { != 0) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_struct,
"callback_buffer_size_udp: adding buffer : %u as entry %u\n", a, ndpi_struct->callback_buffer_size_udp); "callback_buffer_size_udp: adding buffer : %u as entry %u\n", a, ndpi_struct->callback_buffer_size_udp);
memcpy(&ndpi_struct->callback_buffer_udp[ndpi_struct->callback_buffer_size_udp], memcpy(&ndpi_struct->callback_buffer_udp[ndpi_struct->callback_buffer_size_udp],
@@ -2865,7 +2886,7 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
== 0 == 0
|| (ndpi_struct-> || (ndpi_struct->
callback_buffer[a].ndpi_selection_bitmask & NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC) != 0) { callback_buffer[a].ndpi_selection_bitmask & NDPI_SELECTION_BITMASK_PROTOCOL_COMPLETE_TRAFFIC) != 0) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_struct,
"callback_buffer_non_tcp_udp: adding buffer : %u as entry %u\n", a, ndpi_struct->callback_buffer_size_non_tcp_udp); "callback_buffer_non_tcp_udp: adding buffer : %u as entry %u\n", a, ndpi_struct->callback_buffer_size_non_tcp_udp);
memcpy(&ndpi_struct->callback_buffer_non_tcp_udp[ndpi_struct->callback_buffer_size_non_tcp_udp], memcpy(&ndpi_struct->callback_buffer_non_tcp_udp[ndpi_struct->callback_buffer_size_non_tcp_udp],
@@ -2955,11 +2976,11 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru
iph = (const struct ndpi_iphdr *) l3; iph = (const struct ndpi_iphdr *) l3;
if(iph->version == IPVERSION && iph->ihl >= 5) { if(iph->version == IPVERSION && iph->ihl >= 5) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header\n"); NDPI_LOG_DBG2(ndpi_struct, "ipv4 header\n");
} }
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
else if(iph->version == 6 && l3_len >= sizeof(struct ndpi_ipv6hdr)) { else if(iph->version == 6 && l3_len >= sizeof(struct ndpi_ipv6hdr)) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv6 header\n"); NDPI_LOG_DBG2(ndpi_struct, "ipv6 header\n");
iph_v6 = (const struct ndpi_ipv6hdr *) iph; iph_v6 = (const struct ndpi_ipv6hdr *) iph;
iph = NULL; iph = NULL;
} }
@@ -2969,12 +2990,12 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru
} }
if((flags & NDPI_DETECTION_ONLY_IPV6) && iph != NULL) { if((flags & NDPI_DETECTION_ONLY_IPV6) && iph != NULL) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header found but excluded by flag\n"); NDPI_LOG_DBG2(ndpi_struct, "ipv4 header found but excluded by flag\n");
return 1; return 1;
} }
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
else if((flags & NDPI_DETECTION_ONLY_IPV4) && iph_v6 != NULL) { else if((flags & NDPI_DETECTION_ONLY_IPV4) && iph_v6 != NULL) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv6 header found but excluded by flag\n"); NDPI_LOG_DBG2(ndpi_struct, "ipv6 header found but excluded by flag\n");
return 1; return 1;
} }
#endif #endif
@@ -2991,10 +3012,10 @@ static u_int8_t ndpi_detection_get_l4_internal(struct ndpi_detection_module_stru
l4protocol = iph->protocol; l4protocol = iph->protocol;
} }
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
else if(iph_v6 != NULL && (l3_len - sizeof(struct ndpi_ipv6hdr)) >= ntohs(iph_v6->ip6_ctlun.ip6_un1.ip6_un1_plen)) { else if(iph_v6 != NULL && (l3_len - sizeof(struct ndpi_ipv6hdr)) >= ntohs(iph_v6->ip6_hdr.ip6_un1_plen)) {
l4ptr = (((const u_int8_t *) iph_v6) + sizeof(struct ndpi_ipv6hdr)); l4ptr = (((const u_int8_t *) iph_v6) + sizeof(struct ndpi_ipv6hdr));
l4len = ntohs(iph_v6->ip6_ctlun.ip6_un1.ip6_un1_plen); l4len = ntohs(iph_v6->ip6_hdr.ip6_un1_plen);
l4protocol = iph_v6->ip6_ctlun.ip6_un1.ip6_un1_nxt; l4protocol = iph_v6->ip6_hdr.ip6_un1_nxt;
// we need to handle IPv6 extension headers if present // we need to handle IPv6 extension headers if present
if(ndpi_handle_ipv6_extension_headers(ndpi_struct, &l4ptr, &l4len, &l4protocol) != 0) { if(ndpi_handle_ipv6_extension_headers(ndpi_struct, &l4ptr, &l4len, &l4protocol) != 0) {
@@ -3073,12 +3094,12 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
#endif /* NDPI_DETECTION_SUPPORT_IPV6 */ #endif /* NDPI_DETECTION_SUPPORT_IPV6 */
if(decaps_iph && decaps_iph->version == IPVERSION && decaps_iph->ihl >= 5) { if(decaps_iph && decaps_iph->version == IPVERSION && decaps_iph->ihl >= 5) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv4 header\n"); NDPI_LOG_DBG2(ndpi_struct, "ipv4 header\n");
} }
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
else if(decaps_iph && decaps_iph->version == 6 && l3len >= sizeof(struct ndpi_ipv6hdr) && else if(decaps_iph && decaps_iph->version == 6 && l3len >= sizeof(struct ndpi_ipv6hdr) &&
(ndpi_struct->ip_version_limit & NDPI_DETECTION_ONLY_IPV4) == 0) { (ndpi_struct->ip_version_limit & NDPI_DETECTION_ONLY_IPV4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "ipv6 header\n"); NDPI_LOG_DBG2(ndpi_struct, "ipv6 header\n");
flow->packet.iphv6 = (struct ndpi_ipv6hdr *)flow->packet.iph; flow->packet.iphv6 = (struct ndpi_ipv6hdr *)flow->packet.iph;
flow->packet.iph = NULL; flow->packet.iph = NULL;
} }
@@ -3130,9 +3151,8 @@ static int ndpi_init_packet_header(struct ndpi_detection_module_struct *ndpi_str
&& flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) { && flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
memset(flow, 0, sizeof(*(flow))); memset(flow, 0, sizeof(*(flow)));
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DBG(ndpi_struct,
NDPI_LOG_DEBUG, "tcp syn packet for unknown protocol, reset detection state\n");
"%s:%u: tcp syn packet for unknown protocol, reset detection state\n", __FUNCTION__, __LINE__);
} }
} else { } else {
@@ -3172,7 +3192,8 @@ void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_struct,
packet->packet_direction = 1; packet->packet_direction = 1;
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
if(iphv6 != NULL && NDPI_COMPARE_IPV6_ADDRESS_STRUCTS(&iphv6->ip6_src, &iphv6->ip6_dst) != 0) if(iphv6 != NULL && NDPI_COMPARE_IPV6_ADDRESS_STRUCTS(&iphv6->ip6_src,
&iphv6->ip6_dst) != 0)
packet->packet_direction = 1; packet->packet_direction = 1;
#endif #endif
} }
@@ -3351,11 +3372,11 @@ void check_ndpi_udp_flow_func(struct ndpi_detection_module_struct *ndpi_struct,
&& NDPI_BITMASK_COMPARE(ndpi_struct->callback_buffer_udp[a].detection_bitmask, && NDPI_BITMASK_COMPARE(ndpi_struct->callback_buffer_udp[a].detection_bitmask,
detection_bitmask) != 0) { detection_bitmask) != 0) {
ndpi_struct->callback_buffer_udp[a].func(ndpi_struct, flow); ndpi_struct->callback_buffer_udp[a].func(ndpi_struct, flow);
// NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, "[UDP,CALL] dissector of protocol as callback_buffer idx = %d\n",a); // NDPI_LOG_DBG(ndpi_struct, "[UDP,CALL] dissector of protocol as callback_buffer idx = %d\n",a);
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN)
break; /* Stop after detecting the first protocol */ break; /* Stop after detecting the first protocol */
} else } else
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, if(_ndpi_debug_callbacks) NDPI_LOG_DBG2(ndpi_struct,
"[UDP,SKIP] dissector of protocol as callback_buffer idx = %d\n",a); "[UDP,SKIP] dissector of protocol as callback_buffer idx = %d\n",a);
} }
} }
@@ -3560,6 +3581,9 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
u_int32_t a; u_int32_t a;
ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN }; ndpi_protocol ret = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_UNKNOWN };
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");
if(flow == NULL) if(flow == NULL)
return(ret); return(ret);
@@ -3628,7 +3652,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
#ifdef NDPI_DETECTION_SUPPORT_IPV6 #ifdef NDPI_DETECTION_SUPPORT_IPV6
if(flow->packet.iphv6 != NULL) { if(flow->packet.iphv6 != NULL) {
protocol = flow->packet.iphv6->ip6_ctlun.ip6_un1.ip6_un1_nxt; protocol = flow->packet.iphv6->ip6_hdr.ip6_un1_nxt;
} else } else
#endif #endif
{ {
@@ -3911,7 +3935,7 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struc
flow->http.response_status_code[4]='\0'; flow->http.response_status_code[4]='\0';
NDPI_LOG(NDPI_PROTOCOL_UNKNOWN, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"ndpi_parse_packet_line_info: HTTP response parsed: \"%.*s\"\n", "ndpi_parse_packet_line_info: HTTP response parsed: \"%.*s\"\n",
packet->http_response.len, packet->http_response.ptr); packet->http_response.len, packet->http_response.ptr);
} }
@@ -4138,13 +4162,13 @@ u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "called ndpi_check_for_email_address\n"); NDPI_LOG_DBG2(ndpi_struct, "called ndpi_check_for_email_address\n");
if(packet->payload_packet_len > counter && ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z') if(packet->payload_packet_len > counter && ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z')
|| (packet->payload[counter] >= 'A' && packet->payload[counter] <= 'Z') || (packet->payload[counter] >= 'A' && packet->payload[counter] <= 'Z')
|| (packet->payload[counter] >= '0' && packet->payload[counter] <= '9') || (packet->payload[counter] >= '0' && packet->payload[counter] <= '9')
|| packet->payload[counter] == '-' || packet->payload[counter] == '_')) { || packet->payload[counter] == '-' || packet->payload[counter] == '_')) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "first letter\n"); NDPI_LOG_DBG2(ndpi_struct, "first letter\n");
counter++; counter++;
while (packet->payload_packet_len > counter while (packet->payload_packet_len > counter
&& ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z') && ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z')
@@ -4152,44 +4176,44 @@ u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi
|| (packet->payload[counter] >= '0' && packet->payload[counter] <= '9') || (packet->payload[counter] >= '0' && packet->payload[counter] <= '9')
|| packet->payload[counter] == '-' || packet->payload[counter] == '_' || packet->payload[counter] == '-' || packet->payload[counter] == '_'
|| packet->payload[counter] == '.')) { || packet->payload[counter] == '.')) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "further letter\n"); NDPI_LOG_DBG2(ndpi_struct, "further letter\n");
counter++; counter++;
if(packet->payload_packet_len > counter && packet->payload[counter] == '@') { if(packet->payload_packet_len > counter && packet->payload[counter] == '@') {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "@\n"); NDPI_LOG_DBG2(ndpi_struct, "@\n");
counter++; counter++;
while (packet->payload_packet_len > counter while (packet->payload_packet_len > counter
&& ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z') && ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z')
|| (packet->payload[counter] >= 'A' && packet->payload[counter] <= 'Z') || (packet->payload[counter] >= 'A' && packet->payload[counter] <= 'Z')
|| (packet->payload[counter] >= '0' && packet->payload[counter] <= '9') || (packet->payload[counter] >= '0' && packet->payload[counter] <= '9')
|| packet->payload[counter] == '-' || packet->payload[counter] == '_')) { || packet->payload[counter] == '-' || packet->payload[counter] == '_')) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "letter\n"); NDPI_LOG_DBG2(ndpi_struct, "letter\n");
counter++; counter++;
if(packet->payload_packet_len > counter && packet->payload[counter] == '.') { if(packet->payload_packet_len > counter && packet->payload[counter] == '.') {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, ".\n"); NDPI_LOG_DBG2(ndpi_struct, ".\n");
counter++; counter++;
if(packet->payload_packet_len > counter + 1 if(packet->payload_packet_len > counter + 1
&& ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z') && ((packet->payload[counter] >= 'a' && packet->payload[counter] <= 'z')
&& (packet->payload[counter + 1] >= 'a' && packet->payload[counter + 1] <= 'z'))) { && (packet->payload[counter + 1] >= 'a' && packet->payload[counter + 1] <= 'z'))) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "two letters\n"); NDPI_LOG_DBG2(ndpi_struct, "two letters\n");
counter += 2; counter += 2;
if(packet->payload_packet_len > counter if(packet->payload_packet_len > counter
&& (packet->payload[counter] == ' ' || packet->payload[counter] == ';')) { && (packet->payload[counter] == ' ' || packet->payload[counter] == ';')) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "whitespace1\n"); NDPI_LOG_DBG2(ndpi_struct, "whitespace1\n");
return counter; return counter;
} else if(packet->payload_packet_len > counter && packet->payload[counter] >= 'a' } else if(packet->payload_packet_len > counter && packet->payload[counter] >= 'a'
&& packet->payload[counter] <= 'z') { && packet->payload[counter] <= 'z') {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "one letter\n"); NDPI_LOG_DBG2(ndpi_struct, "one letter\n");
counter++; counter++;
if(packet->payload_packet_len > counter if(packet->payload_packet_len > counter
&& (packet->payload[counter] == ' ' || packet->payload[counter] == ';')) { && (packet->payload[counter] == ' ' || packet->payload[counter] == ';')) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "whitespace2\n"); NDPI_LOG_DBG2(ndpi_struct, "whitespace2\n");
return counter; return counter;
} else if(packet->payload_packet_len > counter && packet->payload[counter] >= 'a' } else if(packet->payload_packet_len > counter && packet->payload[counter] >= 'a'
&& packet->payload[counter] <= 'z') { && packet->payload[counter] <= 'z') {
counter++; counter++;
if(packet->payload_packet_len > counter if(packet->payload_packet_len > counter
&& (packet->payload[counter] == ' ' || packet->payload[counter] == ';')) { && (packet->payload[counter] == ' ' || packet->payload[counter] == ';')) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "whitespace3\n"); NDPI_LOG_DBG2(ndpi_struct, "whitespace3\n");
return counter; return counter;
} else { } else {
return 0; return 0;
@@ -4515,25 +4539,6 @@ u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_ch
/* ****************************************************** */ /* ****************************************************** */
ndpi_protocol ndpi_find_port_based_protocol(struct ndpi_detection_module_struct *ndpi_struct /* NOTUSED */,
/* u_int8_t proto, */
u_int32_t shost, u_int16_t sport,
u_int32_t dhost, u_int16_t dport) {
ndpi_protocol proto = NDPI_PROTOCOL_NULL;
/* Skyfile (host 193.252.234.246 or host 10.10.102.80) */
if((shost == 0xC1FCEAF6) || (dhost == 0xC1FCEAF6)
|| (shost == 0x0A0A6650) || (dhost == 0x0A0A6650)) {
if((sport == 4708) || (dport == 4708)) proto.app_protocol = NDPI_PROTOCOL_SKYFILE_PREPAID;
else if((sport == 4709) || (dport == 4709)) proto.app_protocol = NDPI_PROTOCOL_SKYFILE_RUDICS;
else if((sport == 4710) || (dport == 4710)) proto.app_protocol = NDPI_PROTOCOL_SKYFILE_POSTPAID;
}
return(proto);
}
/* ****************************************************** */
u_int8_t ndpi_is_proto(ndpi_protocol proto, u_int16_t p) { u_int8_t ndpi_is_proto(ndpi_protocol proto, u_int16_t p) {
return(((proto.app_protocol == p) || (proto.master_protocol == p)) ? 1 : 0); return(((proto.app_protocol == p) || (proto.master_protocol == p)) ? 1 : 0);
} }
@@ -4579,10 +4584,6 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
return(ret); return(ret);
} }
ret = ndpi_find_port_based_protocol(ndpi_struct/* , proto */, shost, sport, dhost, dport);
if(ret.app_protocol != NDPI_PROTOCOL_UNKNOWN)
return(ret);
check_guessed_skype: check_guessed_skype:
addr.s_addr = htonl(shost); addr.s_addr = htonl(shost);
if(ndpi_network_ptree_match(ndpi_struct, &addr) == NDPI_PROTOCOL_SKYPE) { if(ndpi_network_ptree_match(ndpi_struct, &addr) == NDPI_PROTOCOL_SKYPE) {
@@ -4667,93 +4668,59 @@ void ndpi_category_set_name(struct ndpi_detection_module_struct *ndpi_mod,
/* ****************************************************** */ /* ****************************************************** */
/* Keep it in order and in sync with ndpi_protocol_category_t in ndpi_typedefs.h */
static const char* categories[] = {
"Unspecified",
"Media",
"VPN",
"Email",
"DataTransfer",
"Web",
"SocialNetwork",
"Download-FileTransfer-FileSharing",
"Game",
"Chat",
"VoIP",
"Database",
"RemoteAccess",
"Cloud",
"Network",
"Collaborative",
"RPC",
"NetworkTool",
"System",
"SoftwareUpdate",
"",
"",
"",
"",
""
};
const char* ndpi_category_get_name(struct ndpi_detection_module_struct *ndpi_mod, const char* ndpi_category_get_name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_category_t category) { ndpi_protocol_category_t category) {
if(!ndpi_mod) return(NULL); if(!ndpi_mod) return(NULL);
switch(category) {
case NDPI_PROTOCOL_CATEGORY_MEDIA:
return("Media");
break;
case NDPI_PROTOCOL_CATEGORY_VPN:
return("VPN");
break;
case NDPI_PROTOCOL_CATEGORY_DATA_TRANSFER:
return("DataTransfer");
break;
case NDPI_PROTOCOL_CATEGORY_MAIL:
return("Email");
break;
case NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT:
return("Download-FileTransfer-FileSharing");
break;
case NDPI_PROTOCOL_CATEGORY_WEB:
return("Web");
break;
case NDPI_PROTOCOL_CATEGORY_SOCIAL_NETWORK:
return("SocialNetwork");
break;
case NDPI_PROTOCOL_CATEGORY_GAME:
return("Game");
break;
case NDPI_PROTOCOL_CATEGORY_CHAT:
return("Chat");
break;
case NDPI_PROTOCOL_CATEGORY_VOIP:
return("VoIP");
break;
case NDPI_PROTOCOL_CATEGORY_DATABASE:
return("Database");
break;
case NDPI_PROTOCOL_CATEGORY_REMOTE_ACCESS:
return("RemoteAccess");
break;
case NDPI_PROTOCOL_CATEGORY_CLOUD:
return("Cloud");
break;
case NDPI_PROTOCOL_CATEGORY_NETWORK:
return("Network");
break;
case NDPI_PROTOCOL_CATEGORY_COLLABORATIVE:
return("Collaborative");
break;
case NDPI_PROTOCOL_CATEGORY_RPC:
return("RPC");
break;
case NDPI_PROTOCOL_CATEGORY_NETWORK_TOOL:
return("NetworkTool");
break;
case NDPI_PROTOCOL_CATEGORY_SYSTEM_OS:
return("System");
break;
case NDPI_PROTOCOL_CATEGORY_UNSPECIFIED:
return("Unspecified");
break;
case NDPI_PROTOCOL_CATEGORY_SW_UPDATE:
return("SoftwareUpdate");
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_1:
return(ndpi_mod->custom_category_labels[0]);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_2:
return(ndpi_mod->custom_category_labels[1]);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_3:
return(ndpi_mod->custom_category_labels[2]);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_4:
return(ndpi_mod->custom_category_labels[3]);
break;
case NDPI_PROTOCOL_CATEGORY_CUSTOM_5:
return(ndpi_mod->custom_category_labels[4]);
break;
case NDPI_PROTOCOL_NUM_CATEGORIES:
return("Code should not use this internal constant");
break;
}
return("Unspecified"); if(category < NDPI_PROTOCOL_CATEGORY_CUSTOM_1)
return(categories[category]);
else {
switch(category) {
case NDPI_PROTOCOL_CATEGORY_CUSTOM_1:
return(ndpi_mod->custom_category_labels[0]);
case NDPI_PROTOCOL_CATEGORY_CUSTOM_2:
return(ndpi_mod->custom_category_labels[1]);
case NDPI_PROTOCOL_CATEGORY_CUSTOM_3:
return(ndpi_mod->custom_category_labels[2]);
case NDPI_PROTOCOL_CATEGORY_CUSTOM_4:
return(ndpi_mod->custom_category_labels[3]);
case NDPI_PROTOCOL_CATEGORY_CUSTOM_5:
return(ndpi_mod->custom_category_labels[4]);
case NDPI_PROTOCOL_NUM_CATEGORIES:
return("Code should not use this internal constant");
default:
return("Unspecified");
}
}
} }
/* ****************************************************** */ /* ****************************************************** */
@@ -4833,9 +4800,23 @@ int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *pr
/* ****************************************************** */ /* ****************************************************** */
int ndpi_get_category_id(struct ndpi_detection_module_struct *ndpi_mod, char *cat) {
int i;
const char *name;
for(i = 0; i < NDPI_PROTOCOL_NUM_CATEGORIES; i++) {
name = ndpi_category_get_name(ndpi_mod, i);
if(strcasecmp(cat, name) == 0)
return(i);
}
return(-1);
}
/* ****************************************************** */
void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_mod) { void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_mod) {
int i; int i;
for(i=0; i<(int)ndpi_mod->ndpi_num_supported_protocols; i++) for(i=0; i<(int)ndpi_mod->ndpi_num_supported_protocols; i++)
printf("[%3d] %s\n", i, ndpi_mod->proto_defaults[i].protoName); printf("[%3d] %s\n", i, ndpi_mod->proto_defaults[i].protoName);
} }
@@ -4941,7 +4922,7 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
strncpy(m, string_to_match, len); strncpy(m, string_to_match, len);
m[len] = '\0'; m[len] = '\0';
printf("[NDPI] ndpi_match_host_subprotocol(%s): %s\n", NDPI_LOG_DBG2(ndpi_struct, "[NDPI] ndpi_match_host_subprotocol(%s): %s\n",
m, ndpi_struct->proto_defaults[matching_protocol_id].protoName); m, ndpi_struct->proto_defaults[matching_protocol_id].protoName);
} }
#endif #endif
@@ -4959,7 +4940,7 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
#ifdef DEBUG #ifdef DEBUG
string_to_match[string_to_match_len] = '\0'; string_to_match[string_to_match_len] = '\0';
printf("[NTOP] Unable to find a match for '%s'\n", string_to_match); NDPI_LOG_DBG2(ndpi_struct, "[NTOP] Unable to find a match for '%s'\n", string_to_match);
#endif #endif
return(NDPI_PROTOCOL_UNKNOWN); return(NDPI_PROTOCOL_UNKNOWN);
@@ -5073,7 +5054,6 @@ int NDPI_BITMASK_IS_EMPTY(NDPI_PROTOCOL_BITMASK a) {
void NDPI_DUMP_BITMASK(NDPI_PROTOCOL_BITMASK a) { void NDPI_DUMP_BITMASK(NDPI_PROTOCOL_BITMASK a) {
int i; int i;
for(i=0; i<NDPI_NUM_FDS_BITS; i++) for(i=0; i<NDPI_NUM_FDS_BITS; i++)
printf("[%d=%u]", i, a.fds_bits[i]); printf("[%d=%u]", i, a.fds_bits[i]);
+10 -5
View File
@@ -23,10 +23,14 @@
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_AFP #ifdef NDPI_PROTOCOL_AFP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_AFP
#include "ndpi_api.h"
struct afpHeader { struct afpHeader {
u_int8_t flags, command; u_int8_t flags, command;
u_int16_t requestId; u_int16_t requestId;
@@ -43,6 +47,8 @@ void ndpi_search_afp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search AFP\n");
if (packet->payload_packet_len >= sizeof(struct afpHeader)) { if (packet->payload_packet_len >= sizeof(struct afpHeader)) {
struct afpHeader *h = (struct afpHeader*)packet->payload; struct afpHeader *h = (struct afpHeader*)packet->payload;
@@ -64,7 +70,7 @@ void ndpi_search_afp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
get_u_int32_t(packet->payload, 8) == htonl(packet->payload_packet_len - 16) && get_u_int32_t(packet->payload, 8) == htonl(packet->payload_packet_len - 16) &&
get_u_int32_t(packet->payload, 12) == 0 && get_u_int16_t(packet->payload, 16) == htons(0x0104)) { get_u_int32_t(packet->payload, 12) == 0 && get_u_int16_t(packet->payload, 16) == htons(0x0104)) {
NDPI_LOG(NDPI_PROTOCOL_AFP, ndpi_struct, NDPI_LOG_DEBUG, "AFP: DSI OpenSession detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found AFP: DSI OpenSession\n");
ndpi_int_afp_add_connection(ndpi_struct, flow); ndpi_int_afp_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -73,14 +79,13 @@ void ndpi_search_afp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
&& ((h->command >= 1) && (h->command <= 8)) && ((h->command >= 1) && (h->command <= 8))
&& (h->reserved == 0) && (h->reserved == 0)
&& (packet->payload_packet_len >= (sizeof(struct afpHeader)+ntohl(h->length)))) { && (packet->payload_packet_len >= (sizeof(struct afpHeader)+ntohl(h->length)))) {
NDPI_LOG(NDPI_PROTOCOL_AFP, ndpi_struct, NDPI_LOG_DEBUG, "AFP: DSI detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found AFP: DSI\n");
ndpi_int_afp_add_connection(ndpi_struct, flow); ndpi_int_afp_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_AFP, ndpi_struct, NDPI_LOG_DEBUG, "AFP excluded.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_AFP);
} }
+37 -37
View File
@@ -23,10 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_AIMINI #ifdef NDPI_PROTOCOL_AIMINI
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_AIMINI
#include "ndpi_api.h"
static void ndpi_int_aimini_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow/* , */ static void ndpi_int_aimini_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow/* , */
/* ndpi_protocol_type_t protocol_type */) /* ndpi_protocol_type_t protocol_type */)
@@ -50,43 +54,40 @@ static u_int8_t is_special_aimini_host(struct ndpi_int_one_line_struct host_line
void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG_DBG(ndpi_struct, "search aimini\n");
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "search aimini.\n");
if (packet->udp != NULL) { if (packet->udp != NULL) {
if (flow->l4.udp.aimini_stage == 0) { if (flow->l4.udp.aimini_stage == 0) {
if (packet->payload_packet_len == 64 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010b) { if (packet->payload_packet_len == 64 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010b) {
flow->l4.udp.aimini_stage = 1; flow->l4.udp.aimini_stage = 1;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 1.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 1\n");
return; return;
} }
if (packet->payload_packet_len == 136 if (packet->payload_packet_len == 136
&& (ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9 || ntohs(get_u_int16_t(packet->payload, 0)) == 0x0165)) { && (ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9 || ntohs(get_u_int16_t(packet->payload, 0)) == 0x0165)) {
flow->l4.udp.aimini_stage = 4; flow->l4.udp.aimini_stage = 4;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 4.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 4\n");
return; return;
} }
if (packet->payload_packet_len == 88 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101) { if (packet->payload_packet_len == 88 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101) {
flow->l4.udp.aimini_stage = 7; flow->l4.udp.aimini_stage = 7;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 7.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 7\n");
return; return;
} }
if (packet->payload_packet_len == 104 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102) { if (packet->payload_packet_len == 104 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102) {
flow->l4.udp.aimini_stage = 10; flow->l4.udp.aimini_stage = 10;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 10.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 10\n");
return; return;
} }
if (packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca) { if (packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca) {
flow->l4.udp.aimini_stage = 13; flow->l4.udp.aimini_stage = 13;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 13.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 13\n");
return; return;
} }
if (packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c) { if (packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c) {
flow->l4.udp.aimini_stage = 16; flow->l4.udp.aimini_stage = 16;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 16.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 16\n");
return; return;
} }
} }
@@ -96,7 +97,7 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
if (flow->l4.udp.aimini_stage == 1 && packet->payload_packet_len > 100 if (flow->l4.udp.aimini_stage == 1 && packet->payload_packet_len > 100
&& ntohs(get_u_int16_t(packet->payload, 0)) == 0x0115) { && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0115) {
flow->l4.udp.aimini_stage = 2; flow->l4.udp.aimini_stage = 2;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 2.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 2\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 2 && if (flow->l4.udp.aimini_stage == 2 &&
@@ -104,14 +105,14 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
(packet->payload_packet_len == 64 && get_u_int16_t(packet->payload, 0) == htons(0x010b)) || (packet->payload_packet_len == 64 && get_u_int16_t(packet->payload, 0) == htons(0x010b)) ||
(packet->payload_packet_len == 88 && get_u_int16_t(packet->payload, 0) == ntohs(0x0115)))) { (packet->payload_packet_len == 88 && get_u_int16_t(packet->payload, 0) == ntohs(0x0115)))) {
flow->l4.udp.aimini_stage = 3; flow->l4.udp.aimini_stage = 3;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 3.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 3\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 3 if (flow->l4.udp.aimini_stage == 3
&& ((packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c) && ((packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c)
|| (packet->payload_packet_len == 64 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010b) || (packet->payload_packet_len == 64 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010b)
|| (packet->payload_packet_len > 100 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0115))) { || (packet->payload_packet_len > 100 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0115))) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "found aimini (64, 0x010b), (>300, 0x0115), " NDPI_LOG_INFO(ndpi_struct, "found aimini (64, 0x010b), (>300, 0x0115), "
"(16, 0x010c || 64, 0x010b), (16, 0x010c || 64, 0x010b || >100, 0x0115).\n"); "(16, 0x010c || 64, 0x010b), (16, 0x010c || 64, 0x010b || >100, 0x0115).\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
@@ -122,14 +123,14 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
if (flow->l4.udp.aimini_stage == 4 && packet->payload_packet_len == 136 if (flow->l4.udp.aimini_stage == 4 && packet->payload_packet_len == 136
&& (ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9 || ntohs(get_u_int16_t(packet->payload, 0)) == 0x0165)) { && (ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9 || ntohs(get_u_int16_t(packet->payload, 0)) == 0x0165)) {
flow->l4.udp.aimini_stage = 5; flow->l4.udp.aimini_stage = 5;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 5.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 5\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 5 && (packet->payload_packet_len == 136 if (flow->l4.udp.aimini_stage == 5 && (packet->payload_packet_len == 136
&& (ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9 && (ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9
|| ntohs(get_u_int16_t(packet->payload, 0)) == 0x0165))) { || ntohs(get_u_int16_t(packet->payload, 0)) == 0x0165))) {
flow->l4.udp.aimini_stage = 6; flow->l4.udp.aimini_stage = 6;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 6.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 6\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 6 && ((packet->payload_packet_len == 136 if (flow->l4.udp.aimini_stage == 6 && ((packet->payload_packet_len == 136
@@ -137,7 +138,7 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
|| ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9)) || ntohs(get_u_int16_t(packet->payload, 0)) == 0x01c9))
|| (packet->payload_packet_len == 32 || (packet->payload_packet_len == 32
&& ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca))) { && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca))) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found aimini (136, 0x01c9), (136, 0x01c9)," "(136, 0x01c9),(136, 0x01c9 || 32, 0x01ca).\n"); "found aimini (136, 0x01c9), (136, 0x01c9)," "(136, 0x01c9),(136, 0x01c9 || 32, 0x01ca).\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
@@ -148,18 +149,18 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
if (flow->l4.udp.aimini_stage == 7 && packet->payload_packet_len == 88 if (flow->l4.udp.aimini_stage == 7 && packet->payload_packet_len == 88
&& ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101) { && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101) {
flow->l4.udp.aimini_stage = 8; flow->l4.udp.aimini_stage = 8;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 8.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 8\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 8 if (flow->l4.udp.aimini_stage == 8
&& (packet->payload_packet_len == 88 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101)) { && (packet->payload_packet_len == 88 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101)) {
flow->l4.udp.aimini_stage = 9; flow->l4.udp.aimini_stage = 9;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 9.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 9\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 9 if (flow->l4.udp.aimini_stage == 9
&& (packet->payload_packet_len == 88 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101)) { && (packet->payload_packet_len == 88 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0101)) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found aimini (88, 0x0101), (88, 0x0101)," "(88, 0x0101),(88, 0x0101).\n"); "found aimini (88, 0x0101), (88, 0x0101)," "(88, 0x0101),(88, 0x0101).\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
@@ -170,19 +171,19 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
if (flow->l4.udp.aimini_stage == 10 && packet->payload_packet_len == 104 if (flow->l4.udp.aimini_stage == 10 && packet->payload_packet_len == 104
&& ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102) { && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102) {
flow->l4.udp.aimini_stage = 11; flow->l4.udp.aimini_stage = 11;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 11.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 11\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 11 if (flow->l4.udp.aimini_stage == 11
&& (packet->payload_packet_len == 104 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102)) { && (packet->payload_packet_len == 104 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102)) {
flow->l4.udp.aimini_stage = 12; flow->l4.udp.aimini_stage = 12;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 12.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 12\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 12 if (flow->l4.udp.aimini_stage == 12
&& ((packet->payload_packet_len == 104 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102) && ((packet->payload_packet_len == 104 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0102)
|| (packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca))) { || (packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca))) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found aimini (104, 0x0102), (104, 0x0102), " "(104, 0x0102), (104, 0x0102).\n"); "found aimini (104, 0x0102), (104, 0x0102), " "(104, 0x0102), (104, 0x0102).\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
@@ -193,20 +194,20 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
if (flow->l4.udp.aimini_stage == 13 && packet->payload_packet_len == 32 if (flow->l4.udp.aimini_stage == 13 && packet->payload_packet_len == 32
&& ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca) { && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca) {
flow->l4.udp.aimini_stage = 14; flow->l4.udp.aimini_stage = 14;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 14.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 14\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 14 if (flow->l4.udp.aimini_stage == 14
&& ((packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca) && ((packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca)
|| (packet->payload_packet_len == 136 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0166))) { || (packet->payload_packet_len == 136 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0166))) {
flow->l4.udp.aimini_stage = 15; flow->l4.udp.aimini_stage = 15;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 15.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 15\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 15 if (flow->l4.udp.aimini_stage == 15
&& ((packet->payload_packet_len == 136 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0166) && ((packet->payload_packet_len == 136 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x0166)
|| (packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca))) { || (packet->payload_packet_len == 32 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x01ca))) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found aimini (32,0x01ca), (32,0x01ca), (32,0x01ca), ((136, 0x0166)||(32,0x01ca)).\n"); "found aimini (32,0x01ca), (32,0x01ca), (32,0x01ca), ((136, 0x0166)||(32,0x01ca)).\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
@@ -217,18 +218,18 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
if (flow->l4.udp.aimini_stage == 16 && packet->payload_packet_len == 16 if (flow->l4.udp.aimini_stage == 16 && packet->payload_packet_len == 16
&& ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c) { && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c) {
flow->l4.udp.aimini_stage = 17; flow->l4.udp.aimini_stage = 17;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 17.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 17\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 17 if (flow->l4.udp.aimini_stage == 17
&& (packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c)) { && (packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c)) {
flow->l4.udp.aimini_stage = 18; flow->l4.udp.aimini_stage = 18;
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "stage = 18.\n"); NDPI_LOG_DBG2(ndpi_struct, "stage = 18\n");
return; return;
} }
if (flow->l4.udp.aimini_stage == 18 if (flow->l4.udp.aimini_stage == 18
&& (packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c)) { && (packet->payload_packet_len == 16 && ntohs(get_u_int16_t(packet->payload, 0)) == 0x010c)) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found aimini (16, 0x010c), (16, 0x010c), (16, 0x010c), (16, 0x010c).\n"); "found aimini (16, 0x010c), (16, 0x010c), (16, 0x010c), (16, 0x010c).\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
@@ -238,11 +239,11 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
(memcmp(packet->payload, "GET /player/", NDPI_STATICSTRING_LEN("GET /player/")) == 0)) || (memcmp(packet->payload, "GET /player/", NDPI_STATICSTRING_LEN("GET /player/")) == 0)) ||
(packet->payload_packet_len > NDPI_STATICSTRING_LEN("GET /play/?fid=") && (packet->payload_packet_len > NDPI_STATICSTRING_LEN("GET /play/?fid=") &&
(memcmp(packet->payload, "GET /play/?fid=", NDPI_STATICSTRING_LEN("GET /play/?fid=")) == 0))) { (memcmp(packet->payload, "GET /play/?fid=", NDPI_STATICSTRING_LEN("GET /play/?fid=")) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "HTTP packet detected.\n"); NDPI_LOG_DBG2(ndpi_struct, "HTTP packet detected\n");
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->host_line.ptr != NULL && packet->host_line.len > 11 if (packet->host_line.ptr != NULL && packet->host_line.len > 11
&& (memcmp(&packet->host_line.ptr[packet->host_line.len - 11], ".aimini.net", 11) == 0)) { && (memcmp(&packet->host_line.ptr[packet->host_line.len - 11], ".aimini.net", 11) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "AIMINI HTTP traffic detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found AIMINI HTTP traffic\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -255,8 +256,8 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
NDPI_STATICSTRING_LEN("download/")) == 0) { NDPI_STATICSTRING_LEN("download/")) == 0) {
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (is_special_aimini_host(packet->host_line) == 1) { if (is_special_aimini_host(packet->host_line) == 1) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"AIMINI HTTP traffic detected.\n"); "found AIMINI HTTP traffic\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -266,8 +267,8 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
NDPI_STATICSTRING_LEN("upload/")) == 0) { NDPI_STATICSTRING_LEN("upload/")) == 0) {
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (is_special_aimini_host(packet->host_line) == 1) { if (is_special_aimini_host(packet->host_line) == 1) {
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"AIMINI HTTP traffic detected.\n"); "found AIMINI HTTP traffic detected.\n");
ndpi_int_aimini_add_connection(ndpi_struct, flow); ndpi_int_aimini_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -276,8 +277,7 @@ void ndpi_search_aimini(struct ndpi_detection_module_struct *ndpi_struct, struct
} }
} }
NDPI_LOG(NDPI_PROTOCOL_AIMINI, ndpi_struct, NDPI_LOG_DEBUG, "exclude aimini.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_AIMINI);
} }
+10 -3
View File
@@ -18,10 +18,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_AMQP #ifdef NDPI_PROTOCOL_AMQP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_AMQP
#include "ndpi_api.h"
PACK_ON PACK_ON
struct amqp_header { struct amqp_header {
u_int8_t ptype; u_int8_t ptype;
@@ -39,7 +44,7 @@ static void ndpi_int_amqp_add_connection(struct ndpi_detection_module_struct *nd
void ndpi_search_amqp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_amqp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_AMQP, ndpi_struct, NDPI_LOG_DEBUG, "search amqp. \n"); NDPI_LOG_DBG(ndpi_struct, "search amqp\n");
if (packet->tcp != NULL) { if (packet->tcp != NULL) {
if(packet->payload_packet_len > sizeof(struct amqp_header)) { if(packet->payload_packet_len > sizeof(struct amqp_header)) {
@@ -57,7 +62,7 @@ void ndpi_search_amqp(struct ndpi_detection_module_struct *ndpi_struct, struct n
u_int16_t method = htons(h->method); u_int16_t method = htons(h->method);
if(method <= 120 /* Method basic NACK */) { if(method <= 120 /* Method basic NACK */) {
NDPI_LOG(NDPI_PROTOCOL_AMQP, ndpi_struct, NDPI_LOG_DEBUG, "found amqp over tcp. \n"); NDPI_LOG_INFO(ndpi_struct, "found amqp over tcp\n");
ndpi_int_amqp_add_connection(ndpi_struct, flow); ndpi_int_amqp_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -65,6 +70,8 @@ void ndpi_search_amqp(struct ndpi_detection_module_struct *ndpi_struct, struct n
} }
} }
} }
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
} }
+8 -7
View File
@@ -22,10 +22,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_APPLEJUICE #ifdef NDPI_PROTOCOL_APPLEJUICE
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_APPLEJUICE
#include "ndpi_api.h"
static void ndpi_int_applejuice_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_applejuice_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
@@ -37,21 +41,18 @@ void ndpi_search_applejuice_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; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_APPLEJUICE, ndpi_struct, NDPI_LOG_DEBUG, "search applejuice.\n"); NDPI_LOG_DBG(ndpi_struct, "search applejuice\n");
if ((packet->payload_packet_len > 7) && (packet->payload[6] == 0x0d) if ((packet->payload_packet_len > 7) && (packet->payload[6] == 0x0d)
&& (packet->payload[7] == 0x0a) && (packet->payload[7] == 0x0a)
&& (memcmp(packet->payload, "ajprot", 6) == 0)) { && (memcmp(packet->payload, "ajprot", 6) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_APPLEJUICE, ndpi_struct, NDPI_LOG_DEBUG, "detected applejuice.\n"); NDPI_LOG_INFO(ndpi_struct, "found applejuice\n");
ndpi_int_applejuice_add_connection(ndpi_struct, flow); ndpi_int_applejuice_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_APPLEJUICE, ndpi_struct, NDPI_LOG_DEBUG, "exclude applejuice.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_APPLEJUICE);
} }
+10 -12
View File
@@ -22,27 +22,26 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_ARMAGETRON #ifdef NDPI_PROTOCOL_ARMAGETRON
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_ARMAGETRON
#include "ndpi_api.h"
static void ndpi_int_armagetron_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_armagetron_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ARMAGETRON, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ARMAGETRON, NDPI_PROTOCOL_UNKNOWN);
} }
void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_ARMAGETRON, ndpi_struct, NDPI_LOG_DEBUG, "search armagetron.\n");
NDPI_LOG_DBG(ndpi_struct, "search armagetron\n");
if (packet->payload_packet_len > 10) { if (packet->payload_packet_len > 10) {
/* login request */ /* login request */
@@ -52,7 +51,7 @@ void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct
goto exclude; goto exclude;
if (get_u_int16_t(packet->payload, 6) == htons(0x0008) if (get_u_int16_t(packet->payload, 6) == htons(0x0008)
&& get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == 0) { && get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == 0) {
NDPI_LOG(NDPI_PROTOCOL_ARMAGETRON, ndpi_struct, NDPI_LOG_DEBUG, "detected armagetron.\n"); NDPI_LOG_INFO(ndpi_struct, "found armagetron\n");
ndpi_int_armagetron_add_connection(ndpi_struct, flow); ndpi_int_armagetron_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -65,7 +64,7 @@ void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct
goto exclude; goto exclude;
if (get_u_int32_t(packet->payload, 6) == htonl(0x00000500) && get_u_int32_t(packet->payload, 6 + 4) == htonl(0x00010000) if (get_u_int32_t(packet->payload, 6) == htonl(0x00000500) && get_u_int32_t(packet->payload, 6 + 4) == htonl(0x00010000)
&& get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == 0) { && get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == 0) {
NDPI_LOG(NDPI_PROTOCOL_ARMAGETRON, ndpi_struct, NDPI_LOG_DEBUG, "detected armagetron.\n"); NDPI_LOG_INFO(ndpi_struct, "found armagetron\n");
ndpi_int_armagetron_add_connection(ndpi_struct, flow); ndpi_int_armagetron_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -85,7 +84,7 @@ void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct
&& (get_u_int32_t(packet->payload, 6 + 10 + val) == htonl(0x00010000) && (get_u_int32_t(packet->payload, 6 + 10 + val) == htonl(0x00010000)
|| get_u_int32_t(packet->payload, 6 + 10 + val) == htonl(0x00000001)) || get_u_int32_t(packet->payload, 6 + 10 + val) == htonl(0x00000001))
&& get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == 0) { && get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == 0) {
NDPI_LOG(NDPI_PROTOCOL_ARMAGETRON, ndpi_struct, NDPI_LOG_DEBUG, "detected armagetron.\n"); NDPI_LOG_INFO(ndpi_struct, "found armagetron\n");
ndpi_int_armagetron_add_connection(ndpi_struct, flow); ndpi_int_armagetron_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -94,8 +93,7 @@ void ndpi_search_armagetron_udp(struct ndpi_detection_module_struct *ndpi_struct
} }
exclude: exclude:
NDPI_LOG(NDPI_PROTOCOL_ARMAGETRON, ndpi_struct, NDPI_LOG_DEBUG, "exclude armagetron.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_ARMAGETRON);
} }
+7
View File
@@ -43,6 +43,8 @@ static void ndpi_int_ftp_add_connection(struct ndpi_detection_module_struct *ndp
*/ */
#if !defined(WIN32) #if !defined(WIN32)
static inline static inline
#elif defined(MINGW_GCC)
__mingw_forceinline static
#else #else
__forceinline static __forceinline static
#endif #endif
@@ -78,8 +80,11 @@ u_int8_t ndpi_int_check_possible_ftp_command(const struct ndpi_packet_struct *pa
/** /**
* ftp replies are are 3-digit number followed by space or hyphen * ftp replies are are 3-digit number followed by space or hyphen
*/ */
#if !defined(WIN32) #if !defined(WIN32)
static inline static inline
#elif defined(MINGW_GCC)
__mingw_forceinline static
#else #else
__forceinline static __forceinline static
#endif #endif
@@ -108,6 +113,8 @@ u_int8_t ndpi_int_check_possible_ftp_reply(const struct ndpi_packet_struct *pack
*/ */
#if !defined(WIN32) #if !defined(WIN32)
static inline static inline
#elif defined(MINGW_GCC)
__mingw_forceinline static
#else #else
__forceinline static __forceinline static
#endif #endif
+11 -3
View File
@@ -26,10 +26,14 @@
http://tools.ietf.org/html/rfc4891 http://tools.ietf.org/html/rfc4891
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_AYIYA #ifdef NDPI_PROTOCOL_AYIYA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_AYIYA
#include "ndpi_api.h"
struct ayiya { struct ayiya {
u_int8_t flags[3]; u_int8_t flags[3];
u_int8_t next_header; u_int8_t next_header;
@@ -42,6 +46,8 @@ void ndpi_search_ayiya(struct ndpi_detection_module_struct *ndpi_struct, struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search AYIYA\n");
if(packet->udp && (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)) { if(packet->udp && (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)) {
/* Ayiya is udp based, port 5072 */ /* Ayiya is udp based, port 5072 */
if ((packet->udp->source == htons(5072) || packet->udp->dest == htons(5072)) if ((packet->udp->source == htons(5072) || packet->udp->dest == htons(5072))
@@ -55,13 +61,15 @@ void ndpi_search_ayiya(struct ndpi_detection_module_struct *ndpi_struct, struct
now = flow->packet.tick_timestamp; now = flow->packet.tick_timestamp;
if((epoch >= (now - fiveyears)) && (epoch <= (now+86400 /* 1 day */))) if((epoch >= (now - fiveyears)) && (epoch <= (now+86400 /* 1 day */))) {
NDPI_LOG_INFO(ndpi_struct, "found AYIYA\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_AYIYA, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_AYIYA, NDPI_PROTOCOL_UNKNOWN);
}
return; return;
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_AYIYA); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
} }
+11 -11
View File
@@ -22,10 +22,13 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_BATTLEFIELD #ifdef NDPI_PROTOCOL_BATTLEFIELD
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BATTLEFIELD
#include "ndpi_api.h"
static void ndpi_int_battlefield_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_battlefield_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -53,12 +56,12 @@ void ndpi_search_battlefield(struct ndpi_detection_module_struct *ndpi_struct, s
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_BATTLEFIELD) { if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_BATTLEFIELD) {
if (src != NULL && ((u_int32_t) if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->battlefield_ts) < ndpi_struct->battlefield_timeout)) { (packet->tick_timestamp - src->battlefield_ts) < ndpi_struct->battlefield_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_BATTLEFIELD, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"battlefield : save src connection packet detected\n"); "battlefield : save src connection packet detected\n");
src->battlefield_ts = packet->tick_timestamp; src->battlefield_ts = packet->tick_timestamp;
} else if (dst != NULL && ((u_int32_t) } else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->battlefield_ts) < ndpi_struct->battlefield_timeout)) { (packet->tick_timestamp - dst->battlefield_ts) < ndpi_struct->battlefield_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_BATTLEFIELD, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"battlefield : save dst connection packet detected\n"); "battlefield : save dst connection packet detected\n");
dst->battlefield_ts = packet->tick_timestamp; dst->battlefield_ts = packet->tick_timestamp;
} }
@@ -74,8 +77,7 @@ void ndpi_search_battlefield(struct ndpi_detection_module_struct *ndpi_struct, s
} }
} else if (flow->l4.udp.battlefield_stage == 2 - packet->packet_direction) { } else if (flow->l4.udp.battlefield_stage == 2 - packet->packet_direction) {
if (packet->payload_packet_len > 8 && get_u_int32_t(packet->payload, 0) == flow->l4.udp.battlefield_msg_id) { if (packet->payload_packet_len > 8 && get_u_int32_t(packet->payload, 0) == flow->l4.udp.battlefield_msg_id) {
NDPI_LOG(NDPI_PROTOCOL_BATTLEFIELD, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found Battlefield message and reply detected\n");
NDPI_LOG_DEBUG, "Battlefield message and reply detected.\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow); ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -91,28 +93,26 @@ void ndpi_search_battlefield(struct ndpi_detection_module_struct *ndpi_struct, s
} else if (flow->l4.udp.battlefield_stage == 4 - packet->packet_direction) { } else if (flow->l4.udp.battlefield_stage == 4 - packet->packet_direction) {
if (packet->payload_packet_len == 7 if (packet->payload_packet_len == 7
&& (packet->payload[0] == 0x02 || packet->payload[packet->payload_packet_len - 1] == 0xe0)) { && (packet->payload[0] == 0x02 || packet->payload[packet->payload_packet_len - 1] == 0xe0)) {
NDPI_LOG(NDPI_PROTOCOL_BATTLEFIELD, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct, "found Battlefield message and reply detected\n");
"Battlefield message and reply detected.\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow); ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return; return;
} }
} }
if (packet->payload_packet_len == 18 && memcmp(&packet->payload[5], "battlefield2\x00", 13) == 0) { if (packet->payload_packet_len == 18 && memcmp(&packet->payload[5], "battlefield2\x00", 13) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BATTLEFIELD, ndpi_struct, NDPI_LOG_DEBUG, "Battlefield 2 hello packet detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found Battlefield 2 hello packet detected\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow); ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return; return;
} else if (packet->payload_packet_len > 10 && } else if (packet->payload_packet_len > 10 &&
(memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\x50\xb9\x10\x11", 10) == 0 (memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\x50\xb9\x10\x11", 10) == 0
|| memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\x30\xb9\x10\x11", 10) == 0 || memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\x30\xb9\x10\x11", 10) == 0
|| memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\xa0\x98\x00\x11", 10) == 0)) { || memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\xa0\x98\x00\x11", 10) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_BATTLEFIELD, ndpi_struct, NDPI_LOG_DEBUG, "Battlefield safe pattern detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found Battlefield safe pattern detected\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow); ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BATTLEFIELD); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
} }
+12 -4
View File
@@ -20,16 +20,24 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocols.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_BGP #ifdef NDPI_PROTOCOL_BGP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BGP
#include "ndpi_api.h"
/* this detection also works asymmetrically */ /* this detection also works asymmetrically */
void ndpi_search_bgp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_bgp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t bgp_port = htons(179); u_int16_t bgp_port = htons(179);
NDPI_LOG_DBG(ndpi_struct, "search BGP\n");
if(packet->tcp) { if(packet->tcp) {
if(packet->payload_packet_len > 18 if(packet->payload_packet_len > 18
&& packet->payload[18] < 5 && packet->payload[18] < 5
@@ -38,13 +46,13 @@ void ndpi_search_bgp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
&& (get_u_int64_t(packet->payload, 8) == 0xffffffffffffffffULL) && (get_u_int64_t(packet->payload, 8) == 0xffffffffffffffffULL)
&& (ntohs(get_u_int16_t(packet->payload, 16)) <= packet->payload_packet_len)) { && (ntohs(get_u_int16_t(packet->payload, 16)) <= packet->payload_packet_len)) {
NDPI_LOG(NDPI_PROTOCOL_BGP, ndpi_struct, NDPI_LOG_DEBUG, "BGP detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found BGP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BGP, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BGP, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
/* exclude BGP */
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BGP); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+38 -46
View File
@@ -23,8 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_BITTORRENT #ifdef NDPI_PROTOCOL_BITTORRENT
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BITTORRENT
#include "ndpi_api.h"
#define NDPI_PROTOCOL_UNSAFE_DETECTION 0 #define NDPI_PROTOCOL_UNSAFE_DETECTION 0
#define NDPI_PROTOCOL_SAFE_DETECTION 1 #define NDPI_PROTOCOL_SAFE_DETECTION 1
@@ -87,10 +93,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
if(flow->packet_counter == 2 && packet->payload_packet_len > 20) { if(flow->packet_counter == 2 && packet->payload_packet_len > 20) {
if(memcmp(&packet->payload[0], "BitTorrent protocol", 19) == 0) { if(memcmp(&packet->payload[0], "BitTorrent protocol", 19) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, NDPI_LOG_INFO(ndpi_struct, "found BT: plain\n");
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, 19, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, 19, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
} }
@@ -99,19 +104,18 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
/* test for match 0x13+"BitTorrent protocol" */ /* test for match 0x13+"BitTorrent protocol" */
if(packet->payload[0] == 0x13) { if(packet->payload[0] == 0x13) {
if(memcmp(&packet->payload[1], "BitTorrent protocol", 19) == 0) { if(memcmp(&packet->payload[1], "BitTorrent protocol", 19) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n"); NDPI_LOG_INFO(ndpi_struct, "found BT: plain\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, 20, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, 20, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
} }
} }
if(packet->payload_packet_len > 23 && memcmp(packet->payload, "GET /webseed?info_hash=", 23) == 0) { if(packet->payload_packet_len > 23 && memcmp(packet->payload, "GET /webseed?info_hash=", 23) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found BT: plain webseed\n");
NDPI_LOG_TRACE, "BT: plain webseed BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
return 1; return 1;
} }
/* seen Azureus as server for webseed, possibly other servers existing, to implement */ /* seen Azureus as server for webseed, possibly other servers existing, to implement */
@@ -119,10 +123,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
/* no asymmetric detection possible for answer of pattern "GET /data?fid=". */ /* no asymmetric detection possible for answer of pattern "GET /data?fid=". */
if(packet->payload_packet_len > 60 if(packet->payload_packet_len > 60
&& memcmp(packet->payload, "GET /data?fid=", 14) == 0 && memcmp(&packet->payload[54], "&size=", 6) == 0) { && memcmp(packet->payload, "GET /data?fid=", 14) == 0 && memcmp(&packet->payload[54], "&size=", 6) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found BT: plain Bitcomet persistent seed\n");
NDPI_LOG_TRACE, "BT: plain Bitcomet persistent seed protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
return 1; return 1;
} }
@@ -140,10 +143,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& ((packet->user_agent_line.len > 8 && memcmp(packet->user_agent_line.ptr, "Azureus ", 8) == 0) && ((packet->user_agent_line.len > 8 && memcmp(packet->user_agent_line.ptr, "Azureus ", 8) == 0)
|| (packet->user_agent_line.len >= 10 && memcmp(packet->user_agent_line.ptr, "BitTorrent", 10) == 0) || (packet->user_agent_line.len >= 10 && memcmp(packet->user_agent_line.ptr, "BitTorrent", 10) == 0)
|| (packet->user_agent_line.len >= 11 && memcmp(packet->user_agent_line.ptr, "BTWebClient", 11) == 0))) { || (packet->user_agent_line.len >= 11 && memcmp(packet->user_agent_line.ptr, "BTWebClient", 11) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found BT: Azureus /Bittorrent user agent\n");
NDPI_LOG_TRACE, "Azureus /Bittorrent user agent line detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
return 1; return 1;
} }
@@ -151,10 +153,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& (packet->user_agent_line.len >= 9 && memcmp(packet->user_agent_line.ptr, "Shareaza ", 9) == 0) && (packet->user_agent_line.len >= 9 && memcmp(packet->user_agent_line.ptr, "Shareaza ", 9) == 0)
&& (packet->parsed_lines > 8 && packet->line[8].ptr != 0 && (packet->parsed_lines > 8 && packet->line[8].ptr != 0
&& packet->line[8].len >= 9 && memcmp(packet->line[8].ptr, "X-Queue: ", 9) == 0)) { && packet->line[8].len >= 9 && memcmp(packet->line[8].ptr, "X-Queue: ", 9) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found BT: Shareaza detected\n");
NDPI_LOG_TRACE, "Bittorrent Shareaza detected.\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
return 1; return 1;
} }
@@ -186,9 +187,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& packet->line[8].ptr != NULL && packet->line[8].ptr != NULL
&& packet->line[8].len > 22 && memcmp(packet->line[8].ptr, "Cache-Control: no-cache", 23) == 0) { && packet->line[8].len > 22 && memcmp(packet->line[8].ptr, "Cache-Control: no-cache", 23) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_TRACE, "Bitcomet LTS detected\n"); NDPI_LOG_INFO(ndpi_struct, "found BT: Bitcomet LTS\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
@@ -211,9 +212,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& packet->line[6].ptr != NULL && packet->line[6].ptr != NULL
&& packet->line[6].len > 21 && memcmp(packet->line[6].ptr, "Connection: Keep-Alive", 22) == 0) { && packet->line[6].len > 21 && memcmp(packet->line[6].ptr, "Connection: Keep-Alive", 22) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_TRACE, "FlashGet detected\n"); NDPI_LOG_INFO(ndpi_struct, "found BT: FlashGet\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
@@ -232,9 +233,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& packet->line[5].ptr != NULL && packet->line[5].ptr != NULL
&& packet->line[5].len > 21 && memcmp(packet->line[5].ptr, "Connection: Keep-Alive", 22) == 0) { && packet->line[5].len > 21 && memcmp(packet->line[5].ptr, "Connection: Keep-Alive", 22) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_TRACE, "FlashGet detected\n"); NDPI_LOG_INFO(ndpi_struct, "found BT: FlashGet\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
@@ -250,8 +251,7 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
ptr++; ptr++;
} }
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, " BT stat: tracker info hash found\n");
NDPI_LOG_TRACE, " BT stat: tracker info hash found\n");
/* len is > 50, so save operation here */ /* len is > 50, so save operation here */
len -= 10; len -= 10;
@@ -300,10 +300,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
} }
} }
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found BT: tracker info hash parsed\n");
NDPI_LOG_TRACE, " BT stat: tracker info hash parsed\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
@@ -329,10 +328,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
/* did not see this pattern anywhere */ /* did not see this pattern anywhere */
if((memcmp(&packet->payload[0], pattern_20_bytes, 20) == 0) if((memcmp(&packet->payload[0], pattern_20_bytes, 20) == 0)
&& (memcmp(&packet->payload[52], pattern_12_bytes, 12) == 0)) { && (memcmp(&packet->payload[52], pattern_12_bytes, 12) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found BT: Warez - Plain\n");
NDPI_LOG_TRACE, "BT: Warez - Plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return 1; return 1;
} }
} }
@@ -344,11 +342,9 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
/* haven't fount this pattern anywhere */ /* haven't fount this pattern anywhere */
if(packet->host_line.ptr != NULL if(packet->host_line.ptr != NULL
&& packet->host_line.len >= 9 && memcmp(packet->host_line.ptr, "ip2p.com:", 9) == 0) { && packet->host_line.len >= 9 && memcmp(packet->host_line.ptr, "ip2p.com:", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, NDPI_LOG_INFO(ndpi_struct, "found BT: Warez - Plain Host: ip2p.com: pattern\n");
ndpi_struct, NDPI_LOG_TRACE,
"BT: Warez - Plain BitTorrent protocol detected due to Host: ip2p.com: pattern\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
return 1; return 1;
} }
} }
@@ -370,13 +366,11 @@ static void ndpi_int_search_bittorrent_tcp(struct ndpi_detection_module_struct *
/* exclude stage 0 detection from next run */ /* exclude stage 0 detection from next run */
flow->bittorrent_stage = 1; flow->bittorrent_stage = 1;
if(ndpi_int_search_bittorrent_tcp_zero(ndpi_struct, flow) != 0) { if(ndpi_int_search_bittorrent_tcp_zero(ndpi_struct, flow) != 0) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "stage 0 has detected something, returning\n");
"stage 0 has detected something, returning\n");
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "stage 0 has no direct detection, fall through\n");
"stage 0 has no direct detection, fall through\n");
} }
return; return;
} }
@@ -392,7 +386,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
|| (packet->udp || (packet->udp
&& ((ntohs(packet->udp->source) == 3544) /* teredo.c */ && ((ntohs(packet->udp->source) == 3544) /* teredo.c */
|| (ntohs(packet->udp->dest) == 3544))))) { || (ntohs(packet->udp->dest) == 3544))))) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BITTORRENT); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
@@ -481,18 +475,16 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
if(bt_proto && (packet->payload_packet_len > 47)) if(bt_proto && (packet->payload_packet_len > 47))
memcpy(flow->protos.bittorrent.hash, &bt_proto[27], 20); memcpy(flow->protos.bittorrent.hash, &bt_proto[27], 20);
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, NDPI_LOG_INFO(ndpi_struct, "found BT: plain\n");
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 0, ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 0,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION); NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return; return;
} }
} }
return; return;
} }
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BITTORRENT);
} }
} }
} }
+7 -5
View File
@@ -1,7 +1,10 @@
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_BJNP #ifdef NDPI_PROTOCOL_BJNP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BJNP
#include "ndpi_api.h"
static void ndpi_int_bjnp_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_bjnp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
@@ -23,22 +26,21 @@ static void ndpi_check_bjnp(struct ndpi_detection_module_struct *ndpi_struct, st
|| (memcmp((const char *)packet->payload, "BJNB", 4) == 0) || (memcmp((const char *)packet->payload, "BJNB", 4) == 0)
|| (memcmp((const char *)packet->payload, "MFNP", 4) == 0) || (memcmp((const char *)packet->payload, "MFNP", 4) == 0)
) { ) {
NDPI_LOG(NDPI_PROTOCOL_BJNP, ndpi_struct, NDPI_LOG_DEBUG, "Found bjnp.\n"); NDPI_LOG_INFO(ndpi_struct, "found bjnp\n");
ndpi_int_bjnp_add_connection(ndpi_struct, flow, 0); ndpi_int_bjnp_add_connection(ndpi_struct, flow, 0);
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_BJNP, ndpi_struct, NDPI_LOG_DEBUG, "exclude bjnp.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BJNP);
} }
void ndpi_search_bjnp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_bjnp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_BJNP, ndpi_struct, NDPI_LOG_DEBUG, "bjnp detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search bjnp\n");
/* skip marked packets */ /* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BJNP) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BJNP) {
+1 -1
View File
@@ -181,8 +181,8 @@ static void _print_safe_str(char *msg,char *k,const u_int8_t *s,size_t l) {
static void print_safe_str(char *msg,bt_parse_data_cb_t *cbd) { static void print_safe_str(char *msg,bt_parse_data_cb_t *cbd) {
_print_safe_str(msg,cbd->buf,cbd->v.s.s,cbd->v.s.l); _print_safe_str(msg,cbd->buf,cbd->v.s.s,cbd->v.s.l);
} }
#define DEBUG_TRACE(cmd) { if(bt_parse_debug) cmd; } #define DEBUG_TRACE(cmd) { if(bt_parse_debug) cmd; }
#define STREQ(a,b) !strcmp(a,b) #define STREQ(a,b) !strcmp(a,b)
+83
View File
@@ -0,0 +1,83 @@
/*
* checkmk.c
*
* Copyright (C) 2011-17 - 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_protocols.h"
#ifdef NDPI_PROTOCOL_CHECKMK
static void ndpi_int_checkmk_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CHECKMK, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_checkmk(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if (packet->payload_packet_len >= 15) {
if(packet->payload_packet_len > 128) {
/*
When we transfer a large data chunk, unless we have observed
the initial connection, we need to discard these packets
as they are not an indication that this flow is not AFP
*/
return;
}
/*
* this will detect the OpenSession command of the Data Stream Interface (DSI) protocol
* which is exclusively used by the Apple Filing Protocol (AFP) on TCP/IP networks
*/
if (packet->payload_packet_len >= 15 && packet->payload_packet_len < 100
&& memcmp(packet->payload, "<<<check_mk>>>", 14) == 0) {
NDPI_LOG(NDPI_PROTOCOL_CHECKMK, ndpi_struct, NDPI_LOG_DEBUG, "Check_MK: Flow detected.\n");
ndpi_int_checkmk_add_connection(ndpi_struct, flow);
return;
}
}
NDPI_LOG(NDPI_PROTOCOL_CHECKMK, ndpi_struct, NDPI_LOG_DEBUG, "Check_MK excluded.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CHECKMK);
}
void init_checkmk_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("CHECKMK", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_CHECKMK,
ndpi_search_checkmk,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+13 -8
View File
@@ -4,10 +4,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_CISCOVPN #ifdef NDPI_PROTOCOL_CISCOVPN
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CISCOVPN
#include "ndpi_api.h"
static void ndpi_int_ciscovpn_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_ciscovpn_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CISCOVPN, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CISCOVPN, NDPI_PROTOCOL_UNKNOWN);
@@ -20,15 +25,15 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
u_int16_t tdport = 0, tsport = 0; u_int16_t tdport = 0, tsport = 0;
NDPI_LOG(NDPI_PROTOCOL_CISCOVPN, ndpi_struct, NDPI_LOG_DEBUG, "search CISCOVPN.\n"); NDPI_LOG_DBG(ndpi_struct, "search CISCOVPN\n");
if(packet->tcp != NULL) { if(packet->tcp != NULL) {
tsport = ntohs(packet->tcp->source), tdport = ntohs(packet->tcp->dest); tsport = ntohs(packet->tcp->source), tdport = ntohs(packet->tcp->dest);
NDPI_LOG(NDPI_PROTOCOL_CISCOVPN, ndpi_struct, NDPI_LOG_DEBUG, "calculated CISCOVPN over tcp ports.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculated CISCOVPN over tcp ports\n");
} }
if(packet->udp != NULL) { if(packet->udp != NULL) {
usport = ntohs(packet->udp->source), udport = ntohs(packet->udp->dest); usport = ntohs(packet->udp->source), udport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_CISCOVPN, ndpi_struct, NDPI_LOG_DEBUG, "calculated CISCOVPN over udp ports.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculated CISCOVPN over udp ports\n");
} }
if((tdport == 10000 && tsport == 10000) || if((tdport == 10000 && tsport == 10000) ||
@@ -42,8 +47,9 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
{ {
/* This is a good query 17010000*/ /* This is a good query 17010000*/
NDPI_LOG(NDPI_PROTOCOL_CISCOVPN, ndpi_struct, NDPI_LOG_DEBUG, "found CISCOVPN.\n"); NDPI_LOG_INFO(ndpi_struct, "found CISCOVPN\n");
ndpi_int_ciscovpn_add_connection(ndpi_struct, flow); ndpi_int_ciscovpn_add_connection(ndpi_struct, flow);
return;
} }
else if( else if(
( (
@@ -59,11 +65,10 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
/* This is a good query fe577e2b */ /* This is a good query fe577e2b */
NDPI_LOG(NDPI_PROTOCOL_CISCOVPN, ndpi_struct, NDPI_LOG_DEBUG, "found CISCOVPN.\n"); NDPI_LOG_INFO(ndpi_struct, "found CISCOVPN\n");
ndpi_int_ciscovpn_add_connection(ndpi_struct, flow); ndpi_int_ciscovpn_add_connection(ndpi_struct, flow);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_CISCOVPN, ndpi_struct, NDPI_LOG_DEBUG, "exclude CISCOVPN.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CISCOVPN);
} }
} }
+12 -9
View File
@@ -21,10 +21,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_CITRIX
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CITRIX
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_CITRIX
/* ************************************ */ /* ************************************ */
@@ -45,26 +49,25 @@ static void ndpi_check_citrix(struct ndpi_detection_module_struct *ndpi_struct,
char citrix_header[] = { 0x07, 0x07, 0x49, 0x43, 0x41, 0x00 }; char citrix_header[] = { 0x07, 0x07, 0x49, 0x43, 0x41, 0x00 };
if(memcmp(packet->payload, citrix_header, sizeof(citrix_header)) == 0) { if(memcmp(packet->payload, citrix_header, sizeof(citrix_header)) == 0) {
NDPI_LOG(NDPI_PROTOCOL_CITRIX, ndpi_struct, NDPI_LOG_DEBUG, "Found citrix.\n"); NDPI_LOG_INFO(ndpi_struct, "found citrix\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CITRIX, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CITRIX, NDPI_PROTOCOL_UNKNOWN);
} }
return; return;
} else if(payload_len > 4) { } else if(payload_len > 4) {
char citrix_header[] = { 0x1a, 0x43, 0x47, 0x50, 0x2f, 0x30, 0x31 }; char citrix_header[] = { 0x1a, 0x43, 0x47, 0x50, 0x2f, 0x30, 0x31 };
if((memcmp(packet->payload, citrix_header, sizeof(citrix_header)) == 0) if((memcmp(packet->payload, citrix_header, sizeof(citrix_header)) == 0)
|| (ndpi_strnstr((const char *)packet->payload, "Citrix.TcpProxyService", payload_len) != NULL)) { || (ndpi_strnstr((const char *)packet->payload, "Citrix.TcpProxyService", payload_len) != NULL)) {
NDPI_LOG(NDPI_PROTOCOL_CITRIX, ndpi_struct, NDPI_LOG_DEBUG, "Found citrix.\n"); NDPI_LOG_INFO(ndpi_struct, "found citrix\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CITRIX, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CITRIX, NDPI_PROTOCOL_UNKNOWN);
} }
return; return;
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CITRIX); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} else if(flow->l4.tcp.citrix_packet_id > 3) } else if(flow->l4.tcp.citrix_packet_id > 3) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CITRIX); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
return; return;
} }
@@ -74,7 +77,7 @@ void ndpi_search_citrix(struct ndpi_detection_module_struct *ndpi_struct, struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_CITRIX, ndpi_struct, NDPI_LOG_DEBUG, "citrix detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search citrix\n");
/* skip marked packets */ /* skip marked packets */
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_CITRIX) if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_CITRIX)
+11 -9
View File
@@ -21,10 +21,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_COAP #ifdef NDPI_PROTOCOL_COAP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_COAP
#include "ndpi_api.h"
#define CON 0 #define CON 0
#define NO_CON 1 #define NO_CON 1
#define ACK 2 #define ACK 2
@@ -116,14 +121,12 @@ void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
u_int16_t d_port = ntohs(flow->packet.udp->dest); u_int16_t d_port = ntohs(flow->packet.udp->dest);
if((!isCoAPport(s_port) && !isCoAPport(d_port)) if((!isCoAPport(s_port) && !isCoAPport(d_port))
|| (packet->payload_packet_len < 4) // header too short || (packet->payload_packet_len < 4) ) { // header too short
) { NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_COAP, ndpi_struct, NDPI_LOG_DEBUG, "excluding Coap\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_COAP);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_COAP, ndpi_struct, NDPI_LOG_DEBUG, "calculating coap over udp.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculating coap over udp\n");
// check values in header // check values in header
if(h->version == 1) { if(h->version == 1) {
@@ -133,7 +136,7 @@ void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
(h->code >= 128 && h->code <= 134) || (h->code >= 140 && h->code <= 143) || (h->code >= 128 && h->code <= 134) || (h->code >= 140 && h->code <= 143) ||
(h->code >= 160 && h->code <= 165)) { (h->code >= 160 && h->code <= 165)) {
NDPI_LOG(NDPI_PROTOCOL_COAP, ndpi_struct, NDPI_LOG_DEBUG, "Coap found...\n"); NDPI_LOG_INFO(ndpi_struct, "found Coap\n");
ndpi_int_coap_add_connection(ndpi_struct,flow); ndpi_int_coap_add_connection(ndpi_struct,flow);
return; return;
} }
@@ -142,8 +145,7 @@ void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
} }
} }
NDPI_LOG(NDPI_PROTOCOL_COAP, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Coap ...\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_COAP);
return; return;
} }
+9 -5
View File
@@ -19,16 +19,21 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_COLLECTD #ifdef NDPI_PROTOCOL_COLLECTD
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_COLLECTD
#include "ndpi_api.h"
void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int len = 0; u_int len = 0;
NDPI_LOG(NDPI_PROTOCOL_COLLECTD, ndpi_struct, NDPI_LOG_DEBUG, "search collectd.\n"); NDPI_LOG_DBG(ndpi_struct, "search collectd\n");
if (packet->udp == NULL) return; if (packet->udp == NULL) return;
@@ -43,11 +48,10 @@ void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struct, stru
} }
if(len == packet->payload_packet_len) { if(len == packet->payload_packet_len) {
NDPI_LOG(NDPI_PROTOCOL_COLLECTD, ndpi_struct, NDPI_LOG_DEBUG, "found COLLECTD.\n"); NDPI_LOG_INFO(ndpi_struct, "found COLLECTD\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_COLLECTD, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_COLLECTD, NDPI_PROTOCOL_UNKNOWN);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_COLLECTD, ndpi_struct, NDPI_LOG_DEBUG, "exclude COLLECTD.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_COLLECTD);
} }
} }
+9 -6
View File
@@ -18,10 +18,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_CORBA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CORBA
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_CORBA
static void ndpi_int_corba_add_connection(struct ndpi_detection_module_struct static void ndpi_int_corba_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -31,18 +35,17 @@ void ndpi_search_corba(struct ndpi_detection_module_struct *ndpi_struct, struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_CORBA, ndpi_struct, NDPI_LOG_DEBUG, "search for CORBA.\n"); NDPI_LOG_DBG(ndpi_struct, "search for CORBA\n");
if(packet->tcp != NULL) { if(packet->tcp != NULL) {
NDPI_LOG(NDPI_PROTOCOL_CORBA, ndpi_struct, NDPI_LOG_DEBUG, "calculating CORBA over tcp.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculating CORBA over tcp\n");
/* Corba General Inter-ORB Protocol -> GIOP */ /* Corba General Inter-ORB Protocol -> GIOP */
if ((packet->payload_packet_len >= 24 && packet->payload_packet_len <= 144) && if ((packet->payload_packet_len >= 24 && packet->payload_packet_len <= 144) &&
memcmp(packet->payload, "GIOP", 4) == 0) { memcmp(packet->payload, "GIOP", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_CORBA, ndpi_struct, NDPI_LOG_DEBUG, "found corba.\n"); NDPI_LOG_INFO(ndpi_struct, "found corba\n");
ndpi_int_corba_add_connection(ndpi_struct, flow); ndpi_int_corba_add_connection(ndpi_struct, flow);
} }
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_CORBA, ndpi_struct, NDPI_LOG_DEBUG, "exclude CORBA.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CORBA);
} }
} }
+16 -18
View File
@@ -21,11 +21,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
/* include files */
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_CROSSFIRE #ifdef NDPI_PROTOCOL_CROSSFIRE
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CROSSFIRE
#include "ndpi_api.h"
static void ndpi_int_crossfire_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_crossfire_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow/* , ndpi_protocol_type_t protocol_type */) struct ndpi_flow_struct *flow/* , ndpi_protocol_type_t protocol_type */)
@@ -37,21 +40,17 @@ static void ndpi_int_crossfire_add_connection(struct ndpi_detection_module_struc
void ndpi_search_crossfire_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_crossfire_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_CROSSFIRE, ndpi_struct, NDPI_LOG_DEBUG, "search crossfire.\n");
NDPI_LOG_DBG(ndpi_struct, "search crossfire\n");
if (packet->udp != 0) { if (packet->udp != 0) {
if (packet->payload_packet_len == 25 && get_u_int32_t(packet->payload, 0) == ntohl(0xc7d91999) if (packet->payload_packet_len == 25
&& get_u_int32_t(packet->payload, 0) == ntohl(0xc7d91999)
&& get_u_int16_t(packet->payload, 4) == ntohs(0x0200) && get_u_int16_t(packet->payload, 4) == ntohs(0x0200)
&& get_u_int16_t(packet->payload, 22) == ntohs(0x7d00) && get_u_int16_t(packet->payload, 22) == ntohs(0x7d00)) {
) { NDPI_LOG_INFO(ndpi_struct, "found Crossfire: udp packet\n");
NDPI_LOG(NDPI_PROTOCOL_CROSSFIRE, ndpi_struct, NDPI_LOG_DEBUG, "Crossfire: found udp packet.\n"); ndpi_int_crossfire_add_connection(ndpi_struct, flow);
ndpi_int_crossfire_add_connection(ndpi_struct, flow); return;
return;
} }
} else if (packet->tcp != 0) { } else if (packet->tcp != 0) {
@@ -67,16 +66,15 @@ void ndpi_search_crossfire_tcp_udp(struct ndpi_detection_module_struct *ndpi_str
&& (memcmp(packet->host_line.ptr, "crossfire", 9) == 0 && (memcmp(packet->host_line.ptr, "crossfire", 9) == 0
|| memcmp(packet->host_line.ptr, "www.crossfire", 13) == 0)) || memcmp(packet->host_line.ptr, "www.crossfire", 13) == 0))
) { ) {
NDPI_LOG(NDPI_PROTOCOL_CROSSFIRE, ndpi_struct, NDPI_LOG_DEBUG, "Crossfire: found HTTP request.\n"); NDPI_LOG_DBG(ndpi_struct, "found Crossfire: HTTP request\n");
ndpi_int_crossfire_add_connection(ndpi_struct, flow); ndpi_int_crossfire_add_connection(ndpi_struct, flow);
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_CROSSFIRE, ndpi_struct, NDPI_LOG_DEBUG, "exclude crossfire.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CROSSFIRE);
} }
+19 -17
View File
@@ -20,49 +20,51 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_CSGO #ifdef NDPI_PROTOCOL_CSGO
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CSGO
#include "ndpi_api.h"
void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) { void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) {
struct ndpi_packet_struct* packet = &flow->packet; struct ndpi_packet_struct* packet = &flow->packet;
if (packet->udp != NULL) { if (packet->udp != NULL) {
uint32_t w = htonl(get_u_int32_t(packet->payload, 0)); uint32_t w = htonl(get_u_int32_t(packet->payload, 0));
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "CSGO: word %08x\n", w); NDPI_LOG_DBG2(ndpi_struct, "CSGO: word %08x\n", w);
if (!flow->csgo_state && packet->payload_packet_len == 23 && w == 0xfffffffful) { if (!flow->csgo_state && packet->payload_packet_len == 23 && w == 0xfffffffful) {
if (!memcmp(packet->payload + 5, "connect0x", 9)) { if (!memcmp(packet->payload + 5, "connect0x", 9)) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo connect0x.\n");
flow->csgo_state++; flow->csgo_state++;
memcpy(flow->csgo_strid, packet->payload + 5, 18); memcpy(flow->csgo_strid, packet->payload + 5, 18);
NDPI_LOG_DBG2(ndpi_struct, "Found csgo connect0x\n");
return; return;
} }
} }
if (flow->csgo_state == 1 && packet->payload_packet_len >= 42 && w == 0xfffffffful) { if (flow->csgo_state == 1 && packet->payload_packet_len >= 42 && w == 0xfffffffful) {
if (!memcmp(packet->payload + 24, flow->csgo_strid, 18)) { if (!memcmp(packet->payload + 24, flow->csgo_strid, 18)) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo connect0x reply.\n");
flow->csgo_state++; flow->csgo_state++;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_INFO( ndpi_struct, "found csgo connect0x reply\n");
return; return;
} }
} }
if (packet->payload_packet_len == 8 && ( w == 0x3a180000 || w == 0x39180000) ) { if (packet->payload_packet_len == 8 && ( w == 0x3a180000 || w == 0x39180000) ) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 8b.\n"); NDPI_LOG_INFO( ndpi_struct, "found csgo udp 8b\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
if (packet->payload_packet_len >= 36 && w == 0x56533031ul) { if (packet->payload_packet_len >= 36 && w == 0x56533031ul) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp.\n"); NDPI_LOG_INFO( ndpi_struct, "found csgo udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
if (packet->payload_packet_len >= 36 && w == 0x01007364) { if (packet->payload_packet_len >= 36 && w == 0x01007364) {
uint32_t w2 = htonl(get_u_int32_t(packet->payload, 4)); uint32_t w2 = htonl(get_u_int32_t(packet->payload, 4));
if (w2 == 0x70696e67) { if (w2 == 0x70696e67) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp ping.\n"); NDPI_LOG_INFO( ndpi_struct, "found csgo udp ping\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
@@ -73,11 +75,11 @@ void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct n
if (!flow->csgo_s2) { if (!flow->csgo_s2) {
flow->csgo_id2 = w2; flow->csgo_id2 = w2;
flow->csgo_s2 = 1; flow->csgo_s2 = 1;
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 0d1d step1.\n"); NDPI_LOG_DBG2( ndpi_struct, "Found csgo udp 0d1d step1\n");
return; return;
} }
if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) { if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 0d1d step1 DUP.\n"); NDPI_LOG_DBG2( ndpi_struct, "Found csgo udp 0d1d step1 DUP\n");
return; return;
} }
flow->csgo_s2 = 3; flow->csgo_s2 = 3;
@@ -85,7 +87,7 @@ void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct n
} }
if (packet->payload_packet_len == 15) { if (packet->payload_packet_len == 15) {
if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) { if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo udp 0d1d.\n"); NDPI_LOG_INFO( ndpi_struct, "found csgo udp 0d1d\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
@@ -94,23 +96,23 @@ void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct n
} }
if (packet->payload_packet_len >= 140 && (w == 0x02124c6c || w == 0x02125c6c) && if (packet->payload_packet_len >= 140 && (w == 0x02124c6c || w == 0x02125c6c) &&
!memcmp(&packet->payload[3], "lta\000mob\000tpc\000bhj\000bxd\000tae\000urg\000gkh\000", 32)) { !memcmp(&packet->payload[3], "lta\000mob\000tpc\000bhj\000bxd\000tae\000urg\000gkh\000", 32)) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo dictionary udp.\n"); NDPI_LOG_INFO( ndpi_struct, "found csgo dictionary udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
if (packet->payload_packet_len >= 33 && packet->iph && packet->iph->daddr == 0xffffffff && if (packet->payload_packet_len >= 33 && packet->iph && packet->iph->daddr == 0xffffffff &&
!memcmp(&packet->payload[17], "LanSearch", 9)) { !memcmp(&packet->payload[17], "LanSearch", 9)) {
NDPI_LOG(NDPI_PROTOCOL_CSGO, ndpi_struct, NDPI_LOG_DEBUG, "Found csgo LanSearch udp.\n"); NDPI_LOG_INFO( ndpi_struct, "found csgo LanSearch udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
if (flow->packet_counter > 20) if (flow->packet_counter > 20)
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CSGO); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
void init_csgo_dissector(struct ndpi_detection_module_struct *ndpi_struct, void init_csgo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) { {
ndpi_set_bitmask_protocol_detection("CSGO", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("CSGO", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_CSGO,
ndpi_search_csgo, ndpi_search_csgo,
+10 -5
View File
@@ -21,10 +21,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_DCERPC
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DCERPC
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_DCERPC
static void ndpi_int_dcerpc_add_connection(struct ndpi_detection_module_struct static void ndpi_int_dcerpc_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -36,20 +40,21 @@ void ndpi_search_dcerpc(struct ndpi_detection_module_struct *ndpi_struct, struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search DCERPC\n");
if((packet->tcp != NULL) if((packet->tcp != NULL)
&& (packet->payload_packet_len >= 64) && (packet->payload_packet_len >= 64)
&& (packet->payload[0] == 0x05) /* version 5 */ && (packet->payload[0] == 0x05) /* version 5 */
&& (packet->payload[2] < 16) /* Packet type */ && (packet->payload[2] < 16) /* Packet type */
&& (((packet->payload[9]<<8) | packet->payload[8]) == packet->payload_packet_len) /* Packet Length */ && (((packet->payload[9]<<8) | packet->payload[8]) == packet->payload_packet_len) /* Packet Length */
) { ) {
NDPI_LOG(NDPI_PROTOCOL_DCERPC, ndpi_struct, NDPI_LOG_DEBUG, "DCERPC match\n"); NDPI_LOG_INFO(ndpi_struct, "found DCERPC\n");
ndpi_int_dcerpc_add_connection(ndpi_struct, flow); ndpi_int_dcerpc_add_connection(ndpi_struct, flow);
return; return;
} }
if(packet->payload_packet_len>1){ if(packet->payload_packet_len>1)
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DCERPC); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
} }
+12 -12
View File
@@ -18,11 +18,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_DHCP #ifdef NDPI_PROTOCOL_DHCP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DHCP
#include "ndpi_api.h"
/* freeradius/src/lib/dhcp.c */ /* freeradius/src/lib/dhcp.c */
#define DHCP_CHADDR_LEN 16 #define DHCP_CHADDR_LEN 16
#define DHCP_SNAME_LEN 64 #define DHCP_SNAME_LEN 64
@@ -61,8 +64,7 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search DHCP\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
/* this detection also works for asymmetric dhcp traffic */ /* this detection also works for asymmetric dhcp traffic */
@@ -87,7 +89,7 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
if(len == 0) break; if(len == 0) break;
#ifdef DHCP_DEBUG #ifdef DHCP_DEBUG
printf("[DHCP] Id=%d [len=%d]\n", id, len); NDPI_LOG_DBG2(ndpi_struct, "[DHCP] Id=%d [len=%d]\n", id, len);
#endif #endif
if(id == 53 /* DHCP Message Type */) { if(id == 53 /* DHCP Message Type */) {
@@ -95,8 +97,7 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
if(msg_type <= 8) foundValidMsgType = 1; if(msg_type <= 8) foundValidMsgType = 1;
} else if(id == 55 /* Parameter Request List / Fingerprint */) { } else if(id == 55 /* Parameter Request List / Fingerprint */) {
u_int idx, offset = 0, u_int idx, offset = 0;
hex_len = ndpi_min(len * 2, sizeof(flow->protos.dhcp.fingerprint));
for(idx=0; idx<len; idx++) { for(idx=0; idx<len; idx++) {
snprintf((char*)&flow->protos.dhcp.fingerprint[offset], snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
@@ -116,9 +117,8 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
int j = 0; int j = 0;
#ifdef DHCP_DEBUG #ifdef DHCP_DEBUG
printf("[DHCP] "); NDPI_LOG_DBG2(ndpi_struct, "[DHCP] '%.*s'\n",name,len);
while(j < len) { printf("%c", name[j]); j++; } // while(j < len) { printf( "%c", name[j]); j++; }; printf("\n");
printf("\n");
#endif #endif
j = ndpi_min(len, sizeof(flow->host_server_name)-1); j = ndpi_min(len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, name, j); strncpy((char*)flow->host_server_name, name, j);
@@ -132,14 +132,14 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
//get_u_int16_t(packet->payload, 240) == htons(0x3501)) { //get_u_int16_t(packet->payload, 240) == htons(0x3501)) {
if(foundValidMsgType) { if(foundValidMsgType) {
NDPI_LOG(NDPI_PROTOCOL_DHCP, ndpi_struct, NDPI_LOG_DEBUG, "DHCP found\n"); NDPI_LOG_INFO(ndpi_struct, "found DHCP\n");
ndpi_int_dhcp_add_connection(ndpi_struct, flow); ndpi_int_dhcp_add_connection(ndpi_struct, flow);
} }
return; return;
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DHCP); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+9 -9
View File
@@ -22,13 +22,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
/* include files */
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_DHCPV6 #ifdef NDPI_PROTOCOL_DHCPV6
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DHCPV6
#include "ndpi_api.h"
static void ndpi_int_dhcpv6_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_dhcpv6_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
@@ -40,21 +42,19 @@ void ndpi_search_dhcpv6_udp(struct ndpi_detection_module_struct *ndpi_struct, st
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search DHCPv6\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (packet->payload_packet_len >= 4 && if (packet->payload_packet_len >= 4 &&
(packet->udp->source == htons(546) || packet->udp->source == htons(547)) && (packet->udp->source == htons(546) || packet->udp->source == htons(547)) &&
(packet->udp->dest == htons(546) || packet->udp->dest == htons(547)) && (packet->udp->dest == htons(546) || packet->udp->dest == htons(547)) &&
packet->payload[0] >= 1 && packet->payload[0] <= 13) { packet->payload[0] >= 1 && packet->payload[0] <= 13) {
NDPI_LOG(NDPI_PROTOCOL_DHCPV6, ndpi_struct, NDPI_LOG_DEBUG, "DHCPv6 detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found DHCPv6\n");
ndpi_int_dhcpv6_add_connection(ndpi_struct, flow); ndpi_int_dhcpv6_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_DHCPV6, ndpi_struct, NDPI_LOG_DEBUG, "DHCPv6 excluded.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DHCPV6);
} }
+47 -84
View File
@@ -23,9 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_DIRECTCONNECT #ifdef NDPI_PROTOCOL_DIRECTCONNECT
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DIRECTCONNECT
#include "ndpi_api.h"
//#define NDPI_DEBUG_DIRECTCONNECT //#define NDPI_DEBUG_DIRECTCONNECT
//#define NDPI_DIRECTCONNECT_PORT_DEBUG //#define NDPI_DIRECTCONNECT_PORT_DEBUG
//#define NDPI_DEBUG_DIRECTCONNECT_CONN //#define NDPI_DEBUG_DIRECTCONNECT_CONN
@@ -58,9 +64,7 @@ static u_int16_t parse_binf_message(struct ndpi_detection_module_struct
if (memcmp(&payload[i], "DCTM", 4) == 0) { if (memcmp(&payload[i], "DCTM", 4) == 0) {
if (memcmp(&payload[i + 15], "ADCS", 4) == 0) { if (memcmp(&payload[i + 15], "ADCS", 4) == 0) {
ssl_port = ntohs_ndpi_bytestream_to_number(&payload[i + 25], 5, &bytes_read); ssl_port = ntohs_ndpi_bytestream_to_number(&payload[i + 25], 5, &bytes_read);
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "DC ssl port parsed %d\n", ssl_port);
NDPI_LOG_DEBUG, "directconnect ssl port parsed %d", ssl_port);
} }
} }
} else { } else {
@@ -89,13 +93,11 @@ static void ndpi_int_directconnect_add_connection(struct ndpi_detection_module_s
if (packet->tcp != NULL if (packet->tcp != NULL
&& flow->setup_packet_direction != packet->packet_direction && src->detected_directconnect_port == 0) { && flow->setup_packet_direction != packet->packet_direction && src->detected_directconnect_port == 0) {
src->detected_directconnect_port = packet->tcp->source; src->detected_directconnect_port = packet->tcp->source;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "DC tcp PORT %u for src\n", ntohs(src->detected_directconnect_port));
NDPI_LOG_DEBUG, "directconnect tcp PORT %u for src\n", ntohs(src->detected_directconnect_port));
} }
if (packet->udp != NULL && src->detected_directconnect_udp_port == 0) { if (packet->udp != NULL && src->detected_directconnect_udp_port == 0) {
src->detected_directconnect_udp_port = packet->udp->source; src->detected_directconnect_udp_port = packet->udp->source;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "DC udp PORT %u for src\n", ntohs(src->detected_directconnect_port));
NDPI_LOG_DEBUG, "directconnect udp PORT %u for src\n", ntohs(src->detected_directconnect_port));
} }
} }
@@ -113,9 +115,9 @@ static void ndpi_int_directconnect_add_connection(struct ndpi_detection_module_s
/* /*
dst->detected_directconnect_port = packet->tcp->dest; dst->detected_directconnect_port = packet->tcp->dest;
NDPI_LOG (NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct,
NDPI_LOG_DEBUG, "directconnect tcp PORT %u for dst\n", "DC tcp PORT %u for dst\n",
ntohs (dst->detected_directconnect_port)); ntohs (dst->detected_directconnect_port));
*/ */
} }
} }
@@ -148,14 +150,12 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if (dst != NULL) { if (dst != NULL) {
dst->detected_directconnect_ssl_port = dst->detected_directconnect_ssl_port =
ntohs_ndpi_bytestream_to_number(&packet->payload[25], 5, &bytes_read); ntohs_ndpi_bytestream_to_number(&packet->payload[25], 5, &bytes_read);
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "DC ssl port parsed %d\n", ntohs(dst->detected_directconnect_ssl_port));
NDPI_LOG_DEBUG, "directconnect ssl port parsed %d", ntohs(dst->detected_directconnect_ssl_port));
} }
if (src != NULL) { if (src != NULL) {
src->detected_directconnect_ssl_port = src->detected_directconnect_ssl_port =
ntohs_ndpi_bytestream_to_number(&packet->payload[25], 5, &bytes_read); ntohs_ndpi_bytestream_to_number(&packet->payload[25], 5, &bytes_read);
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "DC ssl port parsed %d\n", ntohs(src->detected_directconnect_ssl_port));
NDPI_LOG_DEBUG, "directconnect ssl port parsed %d", ntohs(src->detected_directconnect_ssl_port));
} }
@@ -168,15 +168,13 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if ((u_int32_t) if ((u_int32_t)
(packet->tick_timestamp - (packet->tick_timestamp -
src->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) { src->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
src->directconnect_last_safe_access_time = packet->tick_timestamp; src->directconnect_last_safe_access_time = packet->tick_timestamp;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC using port %d\n", ntohs(src->detected_directconnect_port));
NDPI_LOG_DEBUG, "marking using dc port\n %d", ntohs(src->detected_directconnect_port)); ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} else { } else {
src->detected_directconnect_port = 0; src->detected_directconnect_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "resetting src port due to timeout\n");
NDPI_LOG_DEBUG, "resetting src port due to timeout");
return; return;
} }
} }
@@ -184,15 +182,13 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if ((u_int32_t) if ((u_int32_t)
(packet->tick_timestamp - (packet->tick_timestamp -
src->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) { src->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
src->directconnect_last_safe_access_time = packet->tick_timestamp; src->directconnect_last_safe_access_time = packet->tick_timestamp;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC using port %d\n", ntohs(src->detected_directconnect_ssl_port));
NDPI_LOG_DEBUG, "marking using dc port\n %d", ntohs(src->detected_directconnect_ssl_port)); ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} else { } else {
src->detected_directconnect_ssl_port = 0; src->detected_directconnect_ssl_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "resetting src port due to timeout\n");
NDPI_LOG_DEBUG, "resetting src port due to timeout");
return; return;
} }
} }
@@ -204,15 +200,13 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if ((u_int32_t) if ((u_int32_t)
(packet->tick_timestamp - (packet->tick_timestamp -
dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) { dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
dst->directconnect_last_safe_access_time = packet->tick_timestamp; dst->directconnect_last_safe_access_time = packet->tick_timestamp;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC using port %d\n", ntohs(dst->detected_directconnect_port));
NDPI_LOG_DEBUG, "marking using dc port\n %d", ntohs(dst->detected_directconnect_port)); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} else { } else {
dst->detected_directconnect_port = 0; dst->detected_directconnect_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG(ndpi_struct, "resetting dst port due to timeout\n");
NDPI_LOG_DEBUG, "resetting dst port due to timeout");
return; return;
} }
} }
@@ -220,16 +214,13 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if ((u_int32_t) if ((u_int32_t)
(packet->tick_timestamp - (packet->tick_timestamp -
dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) { dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
dst->directconnect_last_safe_access_time = packet->tick_timestamp; dst->directconnect_last_safe_access_time = packet->tick_timestamp;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG(ndpi_struct, "found DC using port %d\n", ntohs(dst->detected_directconnect_ssl_port));
NDPI_LOG_DEBUG, "marking using dc port\n %d", ntohs(dst->detected_directconnect_ssl_port)); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} else { } else {
dst->detected_directconnect_ssl_port = 0; dst->detected_directconnect_ssl_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "resetting dst port due to timeout\n");
NDPI_LOG_DEBUG, "resetting dst port due to timeout");
return; return;
} }
} }
@@ -242,8 +233,7 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if (packet->payload[0] == '$' if (packet->payload[0] == '$'
&& packet->payload[packet->payload_packet_len - 1] == '|' && packet->payload[packet->payload_packet_len - 1] == '|'
&& (memcmp(&packet->payload[1], "Lock ", 5) == 0)) { && (memcmp(&packet->payload[1], "Lock ", 5) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "maybe first dc connect to hub detected\n");
NDPI_LOG_DEBUG, "maybe first dc connect to hub detected\n");
flow->directconnect_stage = 1; flow->directconnect_stage = 1;
return; return;
} }
@@ -251,8 +241,7 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
&& packet->payload[0] == '$' && packet->payload[0] == '$'
&& packet->payload[packet->payload_packet_len - 1] == '|' && packet->payload[packet->payload_packet_len - 1] == '|'
&& (memcmp(&packet->payload[1], "MyNick ", 7) == 0)) { && (memcmp(&packet->payload[1], "MyNick ", 7) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "maybe first dc connect between peers detected\n");
NDPI_LOG_DEBUG, "maybe first dc connect between peers detected\n");
flow->directconnect_stage = 2; flow->directconnect_stage = 2;
return; return;
} }
@@ -262,15 +251,13 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
/* did not see this pattern in any trace */ /* did not see this pattern in any trace */
if (memcmp(&packet->payload[0], "HSUP ADBAS0", 11) == 0 if (memcmp(&packet->payload[0], "HSUP ADBAS0", 11) == 0
|| memcmp(&packet->payload[0], "HSUP ADBASE", 11) == 0) { || memcmp(&packet->payload[0], "HSUP ADBASE", 11) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC HSUP ADBAS0 E\n");
NDPI_LOG_DEBUG, "found directconnect HSUP ADBAS0 E\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_HUB); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_HUB);
return; return;
/* did not see this pattern in any trace */ /* did not see this pattern in any trace */
} else if (memcmp(&packet->payload[0], "CSUP ADBAS0", 11) == 0 || } else if (memcmp(&packet->payload[0], "CSUP ADBAS0", 11) == 0 ||
memcmp(&packet->payload[0], "CSUP ADBASE", 11) == 0) { memcmp(&packet->payload[0], "CSUP ADBASE", 11) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC CSUP ADBAS0 E\n");
NDPI_LOG_DEBUG, "found directconnect CSUP ADBAS0 E\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_ADC_PEER); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_ADC_PEER);
return; return;
@@ -283,19 +270,14 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
/* did not see this pattern in any trace */ /* did not see this pattern in any trace */
if (memcmp(&packet->payload[0], "HSUP ADBAS0", 11) == 0 if (memcmp(&packet->payload[0], "HSUP ADBAS0", 11) == 0
|| memcmp(&packet->payload[0], "HSUP ADBASE", 11) == 0) { || memcmp(&packet->payload[0], "HSUP ADBASE", 11) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC HSUP ADBAS E in second packet\n");
NDPI_LOG_DEBUG, "found directconnect HSUP ADBAS E in second packet\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_HUB); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_HUB);
return; return;
/* did not see this pattern in any trace */ /* did not see this pattern in any trace */
} else if (memcmp(&packet->payload[0], "CSUP ADBAS0", 11) == 0 || } else if (memcmp(&packet->payload[0], "CSUP ADBAS0", 11) == 0 ||
memcmp(&packet->payload[0], "CSUP ADBASE", 11) == 0) { memcmp(&packet->payload[0], "CSUP ADBASE", 11) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC HSUP ADBAS0 E in second packet\n");
NDPI_LOG_DEBUG, "found directconnect HSUP ADBAS0 E in second packet\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_ADC_PEER); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_ADC_PEER);
return; return;
} }
@@ -304,12 +286,11 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if (packet->payload_packet_len > 6) { if (packet->payload_packet_len > 6) {
if ((packet->payload[0] == '$' || packet->payload[0] == '<') if ((packet->payload[0] == '$' || packet->payload[0] == '<')
&& packet->payload[packet->payload_packet_len - 1] == '|') { && packet->payload[packet->payload_packet_len - 1] == '|') {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DEBUG, "second dc detected\n"); NDPI_LOG_INFO(ndpi_struct, "found DC second\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_HUB); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_HUB);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DEBUG, "second dc not detected\n"); NDPI_LOG_DBG2(ndpi_struct, "second dc not detected\n");
} }
} }
@@ -317,23 +298,17 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
/* get client hello answer or server message */ /* get client hello answer or server message */
if (packet->payload_packet_len > 6) { if (packet->payload_packet_len > 6) {
if (packet->payload[0] == '$' && packet->payload[packet->payload_packet_len - 1] == '|') { if (packet->payload[0] == '$' && packet->payload[packet->payload_packet_len - 1] == '|') {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC between peers\n");
NDPI_LOG_DEBUG, "second dc between peers detected\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_PEER); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_PEER);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "second dc between peers not detected\n");
NDPI_LOG_DEBUG, "second dc between peers not detected\n");
} }
} }
} }
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DIRECTCONNECT);
} }
@@ -352,15 +327,13 @@ static void ndpi_search_directconnect_udp(struct ndpi_detection_module_struct
(packet->tick_timestamp - (packet->tick_timestamp -
dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) { dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
dst->directconnect_last_safe_access_time = packet->tick_timestamp; dst->directconnect_last_safe_access_time = packet->tick_timestamp;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found DC using udp port %d\n", ntohs(dst->detected_directconnect_udp_port));
NDPI_LOG_DEBUG, "marking using dc udp port\n %d", ntohs(dst->detected_directconnect_udp_port)); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} else { } else {
dst->detected_directconnect_udp_port = 0; dst->detected_directconnect_udp_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "resetting dst udp port due to timeout\n");
NDPI_LOG_DEBUG, "resetting dst udp port due to timeout");
return; return;
} }
} }
@@ -380,20 +353,15 @@ static void ndpi_search_directconnect_udp(struct ndpi_detection_module_struct
if (packet->payload[pos] == '(') { if (packet->payload[pos] == '(') {
pos = pos - 44; pos = pos - 44;
if (pos > 2 && memcmp(&packet->payload[pos], "TTH:", 4) == 0) { if (pos > 2 && memcmp(&packet->payload[pos], "TTH:", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DEBUG, "dc udp detected\n"); NDPI_LOG_INFO(ndpi_struct, "found DC udp\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_PEER); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_PEER);
return; return;
} }
} }
} }
flow->directconnect_stage++; flow->directconnect_stage++;
if (flow->directconnect_stage < 3)
if (flow->directconnect_stage < 3) {
return; return;
}
} }
} }
@@ -411,7 +379,7 @@ static void ndpi_search_directconnect_udp(struct ndpi_detection_module_struct
if (packet->payload[pos] == '(') { if (packet->payload[pos] == '(') {
pos = pos - 44; pos = pos - 44;
if (pos > 2 && memcmp(&packet->payload[pos], "TTH:", 4) == 0) { if (pos > 2 && memcmp(&packet->payload[pos], "TTH:", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DEBUG, "dc udp detected\n"); NDPI_LOG_INFO(ndpi_struct, "found DC udp\n");
ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_PEER); ndpi_int_directconnect_add_connection(ndpi_struct, flow, DIRECT_CONNECT_TYPE_PEER);
return; return;
} }
@@ -420,15 +388,11 @@ static void ndpi_search_directconnect_udp(struct ndpi_detection_module_struct
flow->directconnect_stage++; flow->directconnect_stage++;
if (flow->directconnect_stage < 3) if (flow->directconnect_stage < 3)
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG(ndpi_struct, "excluded DC at stage %d \n", flow->directconnect_stage);
"excluded at stage %d \n", flow->directconnect_stage);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DIRECTCONNECT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DIRECTCONNECT);
@@ -442,7 +406,7 @@ void ndpi_search_directconnect(struct ndpi_detection_module_struct
struct ndpi_id_struct *src = flow->src; struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst; struct ndpi_id_struct *dst = flow->dst;
NDPI_LOG_DBG(ndpi_struct, "search DC\n");
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_DIRECTCONNECT) { if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_DIRECTCONNECT) {
if (src != NULL && ((u_int32_t) if (src != NULL && ((u_int32_t)
@@ -458,8 +422,7 @@ void ndpi_search_directconnect(struct ndpi_detection_module_struct
dst->directconnect_last_safe_access_time = packet->tick_timestamp; dst->directconnect_last_safe_access_time = packet->tick_timestamp;
} else { } else {
packet->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN; packet->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN;
NDPI_LOG(NDPI_PROTOCOL_DIRECTCONNECT, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "skipping as unknown due to timeout\n");
NDPI_LOG_DEBUG, "directconnect: skipping as unknown due to timeout\n");
} }
return; return;
} }
+17 -19
View File
@@ -23,9 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK #ifdef NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK
#include "ndpi_api.h"
#ifdef NDPI_DEBUG_DIRECT_DOWNLOAD_LINK #ifdef NDPI_DEBUG_DIRECT_DOWNLOAD_LINK
//#define NDPI_DEBUG_DIRECT_DOWNLOAD_LINK_NOTHING_FOUND //#define NDPI_DEBUG_DIRECT_DOWNLOAD_LINK_NOTHING_FOUND
@@ -52,15 +57,12 @@ static void ndpi_int_direct_download_link_add_connection(struct ndpi_detection_m
u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
u_int16_t filename_start = 0; u_int16_t filename_start = 0;
u_int8_t i = 1; u_int8_t i = 1;
u_int16_t host_line_len_without_port; u_int16_t host_line_len_without_port;
if (packet->payload_packet_len < 100) { if (packet->payload_packet_len < 100) {
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: Packet too small.\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: Packet too small\n");
goto end_ddl_nothing_found; goto end_ddl_nothing_found;
} }
@@ -68,10 +70,10 @@ u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, st
if (memcmp(packet->payload, "POST ", 5) == 0) { if (memcmp(packet->payload, "POST ", 5) == 0) {
filename_start = 5; // POST filename_start = 5; // POST
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: POST FOUND\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: POST FOUND\n");
} else if (memcmp(packet->payload, "GET ", 4) == 0) { } else if (memcmp(packet->payload, "GET ", 4) == 0) {
filename_start = 4; // GET filename_start = 4; // GET
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: GET FOUND\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: GET FOUND\n");
} else { } else {
goto end_ddl_nothing_found; goto end_ddl_nothing_found;
} }
@@ -79,16 +81,15 @@ u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, st
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->host_line.ptr == NULL) { if (packet->host_line.ptr == NULL) {
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: NO HOST FOUND\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: NO HOST FOUND\n");
goto end_ddl_nothing_found; goto end_ddl_nothing_found;
} }
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: Host: found\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: Host: found\n");
if (packet->line[0].len < 9 + filename_start if (packet->line[0].len < 9 + filename_start
|| 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(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "DDL: PACKET NOT HTTP CONFORM.\nXXX%.*sXXX\n",
NDPI_LOG_DEBUG, "DDL: PACKET NOT HTTP CONFORM.\nXXX%.*sXXX\n",
8, &packet->line[0].ptr[packet->line[0].len - 9]); 8, &packet->line[0].ptr[packet->line[0].len - 9]);
goto end_ddl_nothing_found; goto end_ddl_nothing_found;
} }
@@ -100,11 +101,11 @@ u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, st
i = 2; i = 2;
while (host_line_len_without_port >= i && packet->host_line.ptr[host_line_len_without_port - i] >= '0' while (host_line_len_without_port >= i && packet->host_line.ptr[host_line_len_without_port - i] >= '0'
&& packet->host_line.ptr[host_line_len_without_port - i] <= '9') { && packet->host_line.ptr[host_line_len_without_port - i] <= '9') {
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: number found\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: number found\n");
i++; i++;
} }
if (host_line_len_without_port >= i && packet->host_line.ptr[host_line_len_without_port - i] == ':') { if (host_line_len_without_port >= i && packet->host_line.ptr[host_line_len_without_port - i] == ':') {
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: ':' found\n"); NDPI_LOG_DBG2(ndpi_struct, "DDL: ':' found\n");
host_line_len_without_port = host_line_len_without_port - i; host_line_len_without_port = host_line_len_without_port - i;
} }
} }
@@ -694,12 +695,12 @@ u_int8_t search_ddl_domains(struct ndpi_detection_module_struct *ndpi_struct, st
*/ */
end_ddl_nothing_found: end_ddl_nothing_found:
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"Nothing Found\n"); "Nothing Found\n");
return 0; return 0;
end_ddl_found: end_ddl_found:
NDPI_LOG(NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK, ndpi_struct, NDPI_LOG_DEBUG, "DDL: DIRECT DOWNLOAD LINK FOUND\n"); NDPI_LOG_INFO(ndpi_struct, "found DIRECT DOWNLOAD LINK\n");
ndpi_int_direct_download_link_add_connection(ndpi_struct, flow); ndpi_int_direct_download_link_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -709,15 +710,12 @@ void ndpi_search_direct_download_link_tcp(struct ndpi_detection_module_struct *n
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
/* struct ndpi_id_struct *src=ndpi_struct->src; */
/* struct ndpi_id_struct *dst=ndpi_struct->dst; */
/* do not detect again if it is already ddl */ /* do not detect again if it is already ddl */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK) {
if (search_ddl_domains(ndpi_struct, flow) != 0) { if (search_ddl_domains(ndpi_struct, flow) != 0) {
return; return;
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
} }
+18 -16
View File
@@ -21,10 +21,15 @@
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_DNS #ifdef NDPI_PROTOCOL_DNS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNS
#include "ndpi_api.h"
#define FLAGS_MASK 0x8000 #define FLAGS_MASK 0x8000
/* #define DNS_DEBUG 1 */ /* #define DNS_DEBUG 1 */
@@ -64,7 +69,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
u_int8_t is_query; u_int8_t is_query;
u_int16_t s_port = 0, d_port = 0; u_int16_t s_port = 0, d_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "search DNS.\n"); NDPI_LOG_DBG(ndpi_struct, "search DNS\n");
if(flow->packet.udp != NULL) { if(flow->packet.udp != NULL) {
s_port = ntohs(flow->packet.udp->source); s_port = ntohs(flow->packet.udp->source);
@@ -75,8 +80,8 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
d_port = ntohs(flow->packet.tcp->dest); d_port = ntohs(flow->packet.tcp->dest);
x = 2; x = 2;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS); return;
} }
if((s_port == 53 || d_port == 53 || d_port == 5355) if((s_port == 53 || d_port == 53 || d_port == 5355)
@@ -116,7 +121,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
x++; x++;
flow->protos.dns.query_type = get16(&x, flow->packet.payload); flow->protos.dns.query_type = get16(&x, flow->packet.payload);
#ifdef DNS_DEBUG #ifdef DNS_DEBUG
printf("[%s:%d] query_type=%2d\n", __FILE__, __LINE__, flow->protos.dns.query_type); NDPI_LOG_DBG2(ndpi_struct, "query_type=%2d\n", flow->protos.dns.query_type);
#endif #endif
break; break;
} else } else
@@ -177,8 +182,7 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
} }
if(invalid) { if(invalid) {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
return; return;
} }
@@ -197,6 +201,9 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
off++; off++;
} }
if(is_query && ndpi_struct->dns_dissect_response)
return; /* The response will set the verdict */
flow->host_server_name[j] = '\0'; flow->host_server_name[j] = '\0';
flow->protos.dns.num_queries = (u_int8_t)dns_header.num_queries, flow->protos.dns.num_queries = (u_int8_t)dns_header.num_queries,
@@ -208,27 +215,22 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
strlen((const char*)flow->host_server_name), strlen((const char*)flow->host_server_name),
NDPI_PROTOCOL_DNS); NDPI_PROTOCOL_DNS);
#ifdef DNS_DEBUG #ifdef DNS_DEBUG
printf("[%s:%d] [num_queries=%d][num_answers=%d][reply_code=%u][rsp_type=%u][host_server_name=%s]\n", NDPI_LOG_DBG2(ndpi_struct, "[num_queries=%d][num_answers=%d][reply_code=%u][rsp_type=%u][host_server_name=%s]\n",
__FILE__, __LINE__,
flow->protos.dns.num_queries, flow->protos.dns.num_answers, flow->protos.dns.num_queries, flow->protos.dns.num_answers,
flow->protos.dns.reply_code, flow->protos.dns.rsp_type, flow->host_server_name flow->protos.dns.reply_code, flow->protos.dns.rsp_type, flow->host_server_name
); );
#endif #endif
if(flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) { if(flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
if(is_query && ndpi_struct->dns_dissect_response)
return; /* The response will set the verdict */
/** /**
Do not set the protocol with DNS if ndpi_match_host_subprotocol() has Do not set the protocol with DNS if ndpi_match_host_subprotocol() has
matched a subprotocol matched a subprotocol
**/ **/
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "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); ndpi_set_detected_protocol(ndpi_struct, flow, (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
} }
} }
} }
+48 -54
View File
@@ -22,76 +22,68 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_DOFUS #ifdef NDPI_PROTOCOL_DOFUS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DOFUS
#include "ndpi_api.h"
static void ndpi_dofus_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_dofus_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DOFUS, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DOFUS, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_INFO(ndpi_struct, "found dofus\n");
} }
void ndpi_search_dofus(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_dofus(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG_DBG(ndpi_struct, "search dofus\n");
/* Dofus v 1.x.x */ /* Dofus v 1.x.x */
if (packet->payload_packet_len == 13 && get_u_int16_t(packet->payload, 1) == ntohs(0x0508) if (packet->payload_packet_len == 13 && get_u_int16_t(packet->payload, 1) == ntohs(0x0508)
&& get_u_int16_t(packet->payload, 5) == ntohs(0x04a0) && get_u_int16_t(packet->payload, 5) == ntohs(0x04a0)
&& get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == ntohs(0x0194)) { && get_u_int16_t(packet->payload, packet->payload_packet_len - 2) == ntohs(0x0194)) {
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "found dofus.\n");
ndpi_dofus_add_connection(ndpi_struct, flow); ndpi_dofus_add_connection(ndpi_struct, flow);
return; return;
} }
if (flow->l4.tcp.dofus_stage == 0 && packet->payload_packet_len == 3 && memcmp(packet->payload, "HG", 2) == 0 if (flow->l4.tcp.dofus_stage == 0) {
&& packet->payload[packet->payload_packet_len - 1] == 0) { if (packet->payload_packet_len == 3 && memcmp(packet->payload, "HG", 2) == 0
flow->l4.tcp.dofus_stage = 1; && packet->payload[packet->payload_packet_len - 1] == 0)
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "maybe dofus.\n"); goto maybe_dofus;
return;
if (packet->payload_packet_len == 12 && memcmp(packet->payload, "Af", 2) == 0
&& packet->payload[packet->payload_packet_len - 1] == 0)
goto maybe_dofus;
if (packet->payload_packet_len == 35 && memcmp(packet->payload, "HC", 2) == 0
&& packet->payload[packet->payload_packet_len - 1] == 0)
goto maybe_dofus;
if (packet->payload_packet_len > 2 && packet->payload[0] == 'A'
&& (packet->payload[1] == 'x' || packet->payload[1] == 'X')
&& packet->payload[packet->payload_packet_len - 1] == 0)
goto maybe_dofus;
if (packet->payload_packet_len > 2 && memcmp(packet->payload, "Ad", 2)
&& packet->payload[packet->payload_packet_len - 1] == 0)
goto maybe_dofus;
} }
if (flow->l4.tcp.dofus_stage == 0 && packet->payload_packet_len == 35 && memcmp(packet->payload, "HC", 2) == 0 if (flow->l4.tcp.dofus_stage == 1) {
&& packet->payload[packet->payload_packet_len - 1] == 0) { if (packet->payload_packet_len == 11 && memcmp(packet->payload, "AT", 2) == 0
flow->l4.tcp.dofus_stage = 1; && packet->payload[10] == 0x00) {
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "maybe dofus.\n"); ndpi_dofus_add_connection(ndpi_struct, flow);
return; return;
} }
if (flow->l4.tcp.dofus_stage == 0 && packet->payload_packet_len > 2 && packet->payload[0] == 'A' if (packet->payload_packet_len == 5
&& (packet->payload[1] == 'x' || packet->payload[1] == 'X') && packet->payload[0] == 'A' && packet->payload[4] == 0x00
&& packet->payload[packet->payload_packet_len - 1] == 0) { && (packet->payload[1] == 'T' || packet->payload[1] == 'k')) {
flow->l4.tcp.dofus_stage = 1;
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "maybe dofus.\n");
return;
}
if (flow->l4.tcp.dofus_stage == 0 && packet->payload_packet_len == 12 && memcmp(packet->payload, "Af", 2) == 0
&& packet->payload[packet->payload_packet_len - 1] == 0) {
flow->l4.tcp.dofus_stage = 1;
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "maybe dofus.\n");
return;
}
if (flow->l4.tcp.dofus_stage == 0 && packet->payload_packet_len > 2 && memcmp(packet->payload, "Ad", 2)
&& packet->payload[packet->payload_packet_len - 1] == 0) {
flow->l4.tcp.dofus_stage = 1;
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "maybe dofus.\n");
return;
}
if (packet->payload_packet_len == 11 && memcmp(packet->payload, "AT", 2) == 0 && packet->payload[10] == 0x00) {
if (flow->l4.tcp.dofus_stage == 1) {
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "found dofus.\n");
ndpi_dofus_add_connection(ndpi_struct, flow); ndpi_dofus_add_connection(ndpi_struct, flow);
return; return;
} }
}
if (flow->l4.tcp.dofus_stage == 1 && packet->payload_packet_len == 5
&& packet->payload[0] == 'A' && packet->payload[4] == 0x00 && (packet->payload[1] == 'T'
|| packet->payload[1] == 'k')) {
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "found dofus asym.\n");
ndpi_dofus_add_connection(ndpi_struct, flow);
return;
} }
/* end Dofus 1.x.x */ /* end Dofus 1.x.x */
@@ -109,7 +101,6 @@ void ndpi_search_dofus(struct ndpi_detection_module_struct *ndpi_struct, struct
if (packet->payload_packet_len == 49 && ntohs(get_u_int16_t(packet->payload, 15)) + 17 != packet->payload_packet_len) { if (packet->payload_packet_len == 49 && ntohs(get_u_int16_t(packet->payload, 15)) + 17 != packet->payload_packet_len) {
goto exclude; goto exclude;
} }
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "found dofus.\n");
ndpi_dofus_add_connection(ndpi_struct, flow); ndpi_dofus_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -120,7 +111,6 @@ void ndpi_search_dofus(struct ndpi_detection_module_struct *ndpi_struct, struct
goto exclude; goto exclude;
len2 = ntohs(get_u_int16_t(packet->payload, 5 + len)); len2 = ntohs(get_u_int16_t(packet->payload, 5 + len));
if (5 + len + 2 + len2 == packet->payload_packet_len) { if (5 + len + 2 + len2 == packet->payload_packet_len) {
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "found dofus.\n");
ndpi_dofus_add_connection(ndpi_struct, flow); ndpi_dofus_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -135,16 +125,20 @@ void ndpi_search_dofus(struct ndpi_detection_module_struct *ndpi_struct, struct
if ((12 + len + 2 + len2 + 1) > packet->payload_packet_len) if ((12 + len + 2 + len2 + 1) > packet->payload_packet_len)
goto exclude; goto exclude;
if (12 + len + 2 + len2 + 1 == packet->payload_packet_len && packet->payload[12 + len + 2 + len2] == 0x01) { if (12 + len + 2 + len2 + 1 == packet->payload_packet_len && packet->payload[12 + len + 2 + len2] == 0x01) {
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "found dofus.\n");
ndpi_dofus_add_connection(ndpi_struct, flow); ndpi_dofus_add_connection(ndpi_struct, flow);
return; return;
} }
} }
exclude: exclude:
NDPI_LOG(NDPI_PROTOCOL_DOFUS, ndpi_struct, NDPI_LOG_DEBUG, "exclude dofus.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DOFUS); return;
}
maybe_dofus:
flow->l4.tcp.dofus_stage = 1;
NDPI_LOG_DBG2(ndpi_struct, "maybe dofus\n");
return;
}
void init_dofus_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_dofus_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{ {
+9 -4
View File
@@ -17,10 +17,14 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_DRDA #ifdef NDPI_PROTOCOL_DRDA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DRDA
#include "ndpi_api.h"
struct ndpi_drda_hdr { struct ndpi_drda_hdr {
u_int16_t length; u_int16_t length;
u_int8_t magic; u_int8_t magic;
@@ -37,6 +41,8 @@ void ndpi_search_drda(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_packet_struct * packet = &flow->packet; struct ndpi_packet_struct * packet = &flow->packet;
u_int16_t payload_len = packet->payload_packet_len; u_int16_t payload_len = packet->payload_packet_len;
u_int count = 0; // prevent integer overflow u_int count = 0; // prevent integer overflow
NDPI_LOG_DBG(ndpi_struct, "search DRDA\n");
if(packet->tcp != NULL) { if(packet->tcp != NULL) {
@@ -71,15 +77,14 @@ void ndpi_search_drda(struct ndpi_detection_module_struct *ndpi_struct,
} }
if(count != payload_len) goto no_drda; if(count != payload_len) goto no_drda;
} }
NDPI_LOG(NDPI_PROTOCOL_DRDA, ndpi_struct, NDPI_LOG_DEBUG, "found DRDA.\n"); NDPI_LOG_INFO(ndpi_struct, "found DRDA\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DRDA, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DRDA, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
no_drda: no_drda:
NDPI_LOG(NDPI_PROTOCOL_DRDA, ndpi_struct, NDPI_LOG_DEBUG, "exclude DRDA.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DRDA);
} }
+8 -5
View File
@@ -21,10 +21,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_DROPBOX
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DROPBOX
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_DROPBOX
#define DB_LSP_PORT 17500 #define DB_LSP_PORT 17500
@@ -51,7 +55,7 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
if(payload_len > 2) { if(payload_len > 2) {
if(strncmp((const char *)packet->payload, "{\"host_int\"", 11) == 0) { if(strncmp((const char *)packet->payload, "{\"host_int\"", 11) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DROPBOX, ndpi_struct, NDPI_LOG_DEBUG, "Found dropbox.\n"); NDPI_LOG_INFO(ndpi_struct, "found dropbox\n");
ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0); ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0);
return; return;
} }
@@ -59,15 +63,14 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
} }
} }
NDPI_LOG(NDPI_PROTOCOL_DROPBOX, ndpi_struct, NDPI_LOG_DEBUG, "exclude dropbox.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DROPBOX);
} }
void ndpi_search_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_dropbox(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_DROPBOX, ndpi_struct, NDPI_LOG_DEBUG, "dropbox detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search dropbox\n");
/* skip marked packets */ /* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_DROPBOX) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_DROPBOX) {
+32 -25
View File
@@ -24,12 +24,18 @@
http://www.brasilbandalarga.com.br http://www.brasilbandalarga.com.br
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_EAQ
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_EAQ
#include "ndpi_api.h" #include "ndpi_api.h"
#define EAQ_DEFAULT_PORT 6000 #define EAQ_DEFAULT_PORT 6000
#define EAQ_DEFAULT_SIZE 16 #define EAQ_DEFAULT_SIZE 16
#ifdef NDPI_PROTOCOL_EAQ
static void ndpi_int_eaq_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_eaq_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_EAQ, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_EAQ, NDPI_PROTOCOL_UNKNOWN);
@@ -40,33 +46,34 @@ void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct nd
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest); u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
if((packet->payload_packet_len != EAQ_DEFAULT_SIZE) NDPI_LOG_DBG(ndpi_struct, "search eaq\n");
|| ((sport != EAQ_DEFAULT_PORT) && (dport != EAQ_DEFAULT_PORT))) {
exclude_eaq:
NDPI_LOG(NDPI_PROTOCOL_EAQ, ndpi_struct, NDPI_LOG_DEBUG, "Exclude eaq.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_EAQ);
return;
}
if(packet->udp != NULL) { do {
u_int32_t seq = (packet->payload[0] * 1000) + (packet->payload[1] * 100) + (packet->payload[2] * 10) + packet->payload[3]; if( (packet->payload_packet_len != EAQ_DEFAULT_SIZE) ||
((sport != EAQ_DEFAULT_PORT) && (dport != EAQ_DEFAULT_PORT)) )
if(flow->l4.udp.eaq_pkt_id == 0) break;
flow->l4.udp.eaq_sequence = seq;
else { if(packet->udp != NULL) {
if((flow->l4.udp.eaq_sequence == seq) || ((flow->l4.udp.eaq_sequence+1) == seq)) { u_int32_t seq = (packet->payload[0] * 1000) + (packet->payload[1] * 100) + (packet->payload[2] * 10) + packet->payload[3];
; /* Looks good */
} else if(flow->l4.udp.eaq_pkt_id == 0)
goto exclude_eaq; flow->l4.udp.eaq_sequence = seq;
} else {
if( (flow->l4.udp.eaq_sequence != seq) &&
((flow->l4.udp.eaq_sequence+1) != seq)) break;
}
if(++flow->l4.udp.eaq_pkt_id == 4) { if(++flow->l4.udp.eaq_pkt_id == 4) {
/* We have collected enough packets so we assume it's EAQ */ /* We have collected enough packets so we assume it's EAQ */
NDPI_LOG(NDPI_PROTOCOL_EAQ, ndpi_struct, NDPI_LOG_DEBUG, "found eaq.\n"); NDPI_LOG_INFO(ndpi_struct, "found eaq\n");
ndpi_int_eaq_add_connection(ndpi_struct, flow); ndpi_int_eaq_add_connection(ndpi_struct, flow);
return;
}
} }
} else } while(0);
goto exclude_eaq;
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+13 -9
View File
@@ -23,10 +23,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_EDONKEY
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_EDONKEY
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_EDONKEY
static void ndpi_int_edonkey_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_int_edonkey_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_EDONKEY, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_EDONKEY, NDPI_PROTOCOL_UNKNOWN);
} }
@@ -159,24 +164,23 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
/* Break after 20 packets. */ /* Break after 20 packets. */
if (flow->packet_counter > 20) { if (flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "Exclude EDONKEY.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_EDONKEY);
return; return;
} }
/* Check if we so far detected the protocol in the request or not. */ /* Check if we so far detected the protocol in the request or not. */
if (flow->edonkey_stage == 0) { if (flow->edonkey_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "EDONKEY stage 0: \n"); NDPI_LOG_DBG2(ndpi_struct, "EDONKEY stage 0: \n");
if (ndpi_edonkey_payload_check(packet->payload, payload_len)) { if (ndpi_edonkey_payload_check(packet->payload, payload_len)) {
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "Possible EDONKEY request detected, we will look further for the response...\n"); NDPI_LOG_DBG2(ndpi_struct, "Possible EDONKEY request detected, we will look further for the response\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */ /* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->edonkey_stage = packet->packet_direction + 1; flow->edonkey_stage = packet->packet_direction + 1;
} }
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "EDONKEY stage %u: \n", flow->edonkey_stage); NDPI_LOG_DBG2(ndpi_struct, "EDONKEY stage %u: \n", flow->edonkey_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */ /* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->edonkey_stage - packet->packet_direction) == 1) { if ((flow->edonkey_stage - packet->packet_direction) == 1) {
@@ -185,10 +189,10 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
/* This is a packet in another direction. Check if we find the proper response. */ /* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 0) || (ndpi_edonkey_payload_check(packet->payload, payload_len))) { if ((payload_len == 0) || (ndpi_edonkey_payload_check(packet->payload, payload_len))) {
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "Found EDONKEY.\n"); NDPI_LOG_INFO(ndpi_struct, "found EDONKEY\n");
ndpi_int_edonkey_add_connection(ndpi_struct, flow); ndpi_int_edonkey_add_connection(ndpi_struct, flow);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to EDONKEY, resetting the stage to 0...\n"); NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to EDONKEY, resetting the stage to 0\n");
flow->edonkey_stage = 0; flow->edonkey_stage = 0;
} }
@@ -198,7 +202,7 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_EDONKEY, ndpi_struct, NDPI_LOG_DEBUG, "EDONKEY detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search EDONKEY\n");
/* skip marked packets */ /* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_EDONKEY) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_EDONKEY) {
+11 -11
View File
@@ -22,11 +22,13 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_FASTTRACK #ifdef NDPI_PROTOCOL_FASTTRACK
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FASTTRACK
#include "ndpi_api.h"
static void ndpi_int_fasttrack_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_fasttrack_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -39,13 +41,12 @@ void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct,
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search FASTTRACK\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if ( (packet->payload != NULL) if ( (packet->payload != NULL)
&& (packet->payload_packet_len > 6) && (packet->payload_packet_len > 6)
&& (ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)) { && (ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)) {
NDPI_LOG(NDPI_PROTOCOL_FASTTRACK, ndpi_struct, NDPI_LOG_TRACE, "detected 0d0a at the end of the packet.\n"); NDPI_LOG_DBG2(ndpi_struct, "detected 0d0a at the end of the packet\n");
if (memcmp(packet->payload, "GIVE ", 5) == 0 && packet->payload_packet_len >= 8) { if (memcmp(packet->payload, "GIVE ", 5) == 0 && packet->payload_packet_len >= 8) {
u_int16_t i; u_int16_t i;
@@ -56,20 +57,20 @@ void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} }
} }
NDPI_LOG(NDPI_PROTOCOL_FASTTRACK, ndpi_struct, NDPI_LOG_TRACE, "FASTTRACK GIVE DETECTED\n"); NDPI_LOG_INFO(ndpi_struct, "found FASTTRACK\n");
ndpi_int_fasttrack_add_connection(ndpi_struct, flow); ndpi_int_fasttrack_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len > 50 && memcmp(packet->payload, "GET /", 5) == 0) { if (packet->payload_packet_len > 50 && memcmp(packet->payload, "GET /", 5) == 0) {
u_int8_t a = 0; u_int8_t a = 0;
NDPI_LOG(NDPI_PROTOCOL_FASTTRACK, ndpi_struct, NDPI_LOG_TRACE, "detected GET /. \n"); NDPI_LOG_DBG2(ndpi_struct, "detected GET /. \n");
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
for (a = 0; a < packet->parsed_lines; a++) { for (a = 0; a < packet->parsed_lines; a++) {
if ((packet->line[a].len > 17 && memcmp(packet->line[a].ptr, "X-Kazaa-Username: ", 18) == 0) if ((packet->line[a].len > 17 && memcmp(packet->line[a].ptr, "X-Kazaa-Username: ", 18) == 0)
|| (packet->line[a].len > 23 && memcmp(packet->line[a].ptr, "User-Agent: PeerEnabler/", 24) == 0)) { || (packet->line[a].len > 23 && memcmp(packet->line[a].ptr, "User-Agent: PeerEnabler/", 24) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_FASTTRACK, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct,
"detected X-Kazaa-Username: || User-Agent: PeerEnabler/\n"); "found FASTTRACK X-Kazaa-Username: || User-Agent: PeerEnabler/\n");
ndpi_int_fasttrack_add_connection(ndpi_struct, flow); ndpi_int_fasttrack_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -78,8 +79,7 @@ void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} }
exclude_fasttrack: exclude_fasttrack:
NDPI_LOG(NDPI_PROTOCOL_FASTTRACK, ndpi_struct, NDPI_LOG_TRACE, "fasttrack/kazaa excluded.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FASTTRACK);
} }
+12 -12
View File
@@ -22,10 +22,14 @@
* *
*/ */
/* include files */ #include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_FIESTA #ifdef NDPI_PROTOCOL_FIESTA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FIESTA
#include "ndpi_api.h"
static void ndpi_int_fiesta_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_fiesta_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -35,18 +39,15 @@ static void ndpi_int_fiesta_add_connection(struct ndpi_detection_module_struct *
void ndpi_search_fiesta(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_fiesta(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_FIESTA, ndpi_struct, NDPI_LOG_DEBUG, "search fiesta.\n"); NDPI_LOG_DBG(ndpi_struct, "search fiesta\n");
if (flow->l4.tcp.fiesta_stage == 0 && packet->payload_packet_len == 5 if (flow->l4.tcp.fiesta_stage == 0 && packet->payload_packet_len == 5
&& get_u_int16_t(packet->payload, 0) == ntohs(0x0407) && get_u_int16_t(packet->payload, 0) == ntohs(0x0407)
&& (packet->payload[2] == 0x08) && (packet->payload[2] == 0x08)
&& (packet->payload[4] == 0x00 || packet->payload[4] == 0x01)) { && (packet->payload[4] == 0x00 || packet->payload[4] == 0x01)) {
NDPI_LOG(NDPI_PROTOCOL_FIESTA, ndpi_struct, NDPI_LOG_DEBUG, "maybe fiesta symmetric, first packet.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe fiesta symmetric, first packet\n");
flow->l4.tcp.fiesta_stage = 1 + packet->packet_direction; flow->l4.tcp.fiesta_stage = 1 + packet->packet_direction;
goto maybe_fiesta; goto maybe_fiesta;
} }
@@ -54,7 +55,7 @@ void ndpi_search_fiesta(struct ndpi_detection_module_struct *ndpi_struct, struct
&& ((packet->payload_packet_len > 1 && packet->payload_packet_len - 1 == packet->payload[0]) && ((packet->payload_packet_len > 1 && packet->payload_packet_len - 1 == packet->payload[0])
|| (packet->payload_packet_len > 3 && packet->payload[0] == 0 || (packet->payload_packet_len > 3 && packet->payload[0] == 0
&& get_l16(packet->payload, 1) == packet->payload_packet_len - 3))) { && get_l16(packet->payload, 1) == packet->payload_packet_len - 3))) {
NDPI_LOG(NDPI_PROTOCOL_FIESTA, ndpi_struct, NDPI_LOG_DEBUG, "Maybe fiesta.\n"); NDPI_LOG_DBG2(ndpi_struct, "Maybe fiesta\n");
goto maybe_fiesta; goto maybe_fiesta;
} }
if (flow->l4.tcp.fiesta_stage == (1 + packet->packet_direction)) { if (flow->l4.tcp.fiesta_stage == (1 + packet->packet_direction)) {
@@ -79,16 +80,15 @@ void ndpi_search_fiesta(struct ndpi_detection_module_struct *ndpi_struct, struct
} }
} }
NDPI_LOG(NDPI_PROTOCOL_FIESTA, ndpi_struct, NDPI_LOG_DEBUG, "exclude fiesta.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FIESTA);
return; return;
maybe_fiesta: maybe_fiesta:
NDPI_LOG(NDPI_PROTOCOL_FIESTA, ndpi_struct, NDPI_LOG_DEBUG, "Stage is set to %d.\n", flow->l4.tcp.fiesta_stage); NDPI_LOG_DBG2(ndpi_struct, "Stage is set to %d\n", flow->l4.tcp.fiesta_stage);
return; return;
add_fiesta: add_fiesta:
NDPI_LOG(NDPI_PROTOCOL_FIESTA, ndpi_struct, NDPI_LOG_DEBUG, "detected fiesta.\n"); NDPI_LOG_INFO(ndpi_struct, "found fiesta\n");
ndpi_int_fiesta_add_connection(ndpi_struct, flow); ndpi_int_fiesta_add_connection(ndpi_struct, flow);
return; return;
} }
+10 -7
View File
@@ -22,10 +22,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_FILETOPIA #ifdef NDPI_PROTOCOL_FILETOPIA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FILETOPIA
#include "ndpi_api.h"
static void ndpi_int_filetopia_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_filetopia_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -36,14 +40,13 @@ void ndpi_search_filetopia_tcp(struct ndpi_detection_module_struct *ndpi_struct,
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search Filetopia\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (flow->l4.tcp.filetopia_stage == 0) { if (flow->l4.tcp.filetopia_stage == 0) {
if (packet->payload_packet_len >= 50 && packet->payload_packet_len <= 70 if (packet->payload_packet_len >= 50 && packet->payload_packet_len <= 70
&& packet->payload[0] == 0x03 && packet->payload[1] == 0x9a && packet->payload[0] == 0x03 && packet->payload[1] == 0x9a
&& packet->payload[3] == 0x22 && packet->payload[packet->payload_packet_len - 1] == 0x2b) { && packet->payload[3] == 0x22 && packet->payload[packet->payload_packet_len - 1] == 0x2b) {
NDPI_LOG(NDPI_PROTOCOL_FILETOPIA, ndpi_struct, NDPI_LOG_DEBUG, "Filetopia stage 1 detected\n"); NDPI_LOG_DBG2(ndpi_struct, "Filetopia stage 1 detected\n");
flow->l4.tcp.filetopia_stage = 1; flow->l4.tcp.filetopia_stage = 1;
return; return;
} }
@@ -59,7 +62,7 @@ void ndpi_search_filetopia_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} }
} }
NDPI_LOG(NDPI_PROTOCOL_FILETOPIA, ndpi_struct, NDPI_LOG_DEBUG, "Filetopia stage 2 detected\n"); NDPI_LOG_DBG2(ndpi_struct, "Filetopia stage 2 detected\n");
flow->l4.tcp.filetopia_stage = 2; flow->l4.tcp.filetopia_stage = 2;
return; return;
} }
@@ -69,7 +72,7 @@ void ndpi_search_filetopia_tcp(struct ndpi_detection_module_struct *ndpi_struct,
if (packet->payload_packet_len >= 4 && packet->payload_packet_len <= 100 if (packet->payload_packet_len >= 4 && packet->payload_packet_len <= 100
&& packet->payload[0] == 0x03 && packet->payload[1] == 0x9a && packet->payload[0] == 0x03 && packet->payload[1] == 0x9a
&& (packet->payload[3] == 0x22 || packet->payload[3] == 0x23)) { && (packet->payload[3] == 0x22 || packet->payload[3] == 0x23)) {
NDPI_LOG(NDPI_PROTOCOL_FILETOPIA, ndpi_struct, NDPI_LOG_DEBUG, "Filetopia detected\n"); NDPI_LOG_INFO(ndpi_struct, "found Filetopia\n");
ndpi_int_filetopia_add_connection(ndpi_struct, flow); ndpi_int_filetopia_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -77,7 +80,7 @@ void ndpi_search_filetopia_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} }
end_filetopia_nothing_found: end_filetopia_nothing_found:
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FILETOPIA); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+12 -5
View File
@@ -20,14 +20,21 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocols.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_FIX #ifdef NDPI_PROTOCOL_FIX
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FIX
#include "ndpi_api.h"
void ndpi_search_fix(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_fix(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search FIX\n");
if(packet->tcp) { if(packet->tcp) {
// 8= // 8=
if(packet->payload[0] == 0x38 && packet->payload[1] == 0x3d) { if(packet->payload[0] == 0x38 && packet->payload[1] == 0x3d) {
@@ -37,7 +44,7 @@ void ndpi_search_fix(struct ndpi_detection_module_struct *ndpi_struct, struct nd
packet->payload[4] == 0x58 && packet->payload[4] == 0x58 &&
packet->payload[5] == 0x2e) { packet->payload[5] == 0x2e) {
NDPI_LOG(NDPI_PROTOCOL_FIX, ndpi_struct, NDPI_LOG_DEBUG, "FIX detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found FIX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FIX, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FIX, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
@@ -47,14 +54,14 @@ void ndpi_search_fix(struct ndpi_detection_module_struct *ndpi_struct, struct nd
packet->payload[4] == 0x39 && packet->payload[4] == 0x39 &&
packet->payload[5] == 0x3d) { packet->payload[5] == 0x3d) {
NDPI_LOG(NDPI_PROTOCOL_FIX, ndpi_struct, NDPI_LOG_DEBUG, "FIX detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found FIX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FIX, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FIX, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
} }
/* exclude FIX */
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FIX); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+18 -20
View File
@@ -22,11 +22,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_FLORENSIA #ifdef NDPI_PROTOCOL_FLORENSIA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FLORENSIA
#include "ndpi_api.h"
static void ndpi_florensia_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_florensia_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -37,44 +40,40 @@ void ndpi_search_florensia(struct ndpi_detection_module_struct *ndpi_struct, str
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search florensia\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "search florensia.\n");
if (packet->tcp != NULL) { if (packet->tcp != NULL) {
if (packet->payload_packet_len == 5 && get_l16(packet->payload, 0) == packet->payload_packet_len if (packet->payload_packet_len == 5 && get_l16(packet->payload, 0) == packet->payload_packet_len
&& packet->payload[2] == 0x65 && packet->payload[4] == 0xff) { && packet->payload[2] == 0x65 && packet->payload[4] == 0xff) {
if (flow->florensia_stage == 1) { if (flow->florensia_stage == 1) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "found florensia.\n"); NDPI_LOG_INFO(ndpi_struct, "found florensia\n");
ndpi_florensia_add_connection(ndpi_struct, flow); ndpi_florensia_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "maybe florensia -> stage is set to 1.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe florensia -> stage is set to 1\n");
flow->florensia_stage = 1; flow->florensia_stage = 1;
return; return;
} }
if (packet->payload_packet_len > 8 && get_l16(packet->payload, 0) == packet->payload_packet_len if (packet->payload_packet_len > 8 && get_l16(packet->payload, 0) == packet->payload_packet_len
&& get_u_int16_t(packet->payload, 2) == htons(0x0201) && get_u_int32_t(packet->payload, 4) == htonl(0xFFFFFFFF)) { && get_u_int16_t(packet->payload, 2) == htons(0x0201) && get_u_int32_t(packet->payload, 4) == htonl(0xFFFFFFFF)) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "maybe florensia -> stage is set to 1.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe florensia -> stage is set to 1\n");
flow->florensia_stage = 1; flow->florensia_stage = 1;
return; return;
} }
if (packet->payload_packet_len == 406 && get_l16(packet->payload, 0) == packet->payload_packet_len if (packet->payload_packet_len == 406 && get_l16(packet->payload, 0) == packet->payload_packet_len
&& packet->payload[2] == 0x63) { && packet->payload[2] == 0x63) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "maybe florensia -> stage is set to 1.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe florensia -> stage is set to 1\n");
flow->florensia_stage = 1; flow->florensia_stage = 1;
return; return;
} }
if (packet->payload_packet_len == 12 && get_l16(packet->payload, 0) == packet->payload_packet_len if (packet->payload_packet_len == 12 && get_l16(packet->payload, 0) == packet->payload_packet_len
&& get_u_int16_t(packet->payload, 2) == htons(0x0301)) { && get_u_int16_t(packet->payload, 2) == htons(0x0301)) {
if (flow->florensia_stage == 1) { if (flow->florensia_stage == 1) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "found florensia.\n"); NDPI_LOG_INFO(ndpi_struct, "found florensia\n");
ndpi_florensia_add_connection(ndpi_struct, flow); ndpi_florensia_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "maybe florensia -> stage is set to 1.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe florensia -> stage is set to 1\n");
flow->florensia_stage = 1; flow->florensia_stage = 1;
return; return;
} }
@@ -82,19 +81,19 @@ void ndpi_search_florensia(struct ndpi_detection_module_struct *ndpi_struct, str
if (flow->florensia_stage == 1) { if (flow->florensia_stage == 1) {
if (packet->payload_packet_len == 8 && get_l16(packet->payload, 0) == packet->payload_packet_len if (packet->payload_packet_len == 8 && get_l16(packet->payload, 0) == packet->payload_packet_len
&& get_u_int16_t(packet->payload, 2) == htons(0x0302) && get_u_int32_t(packet->payload, 4) == htonl(0xFFFFFFFF)) { && get_u_int16_t(packet->payload, 2) == htons(0x0302) && get_u_int32_t(packet->payload, 4) == htonl(0xFFFFFFFF)) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "found florensia asymmetrically.\n"); NDPI_LOG_INFO(ndpi_struct, "found florensia asymmetrically\n");
ndpi_florensia_add_connection(ndpi_struct, flow); ndpi_florensia_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 24 && get_l16(packet->payload, 0) == packet->payload_packet_len if (packet->payload_packet_len == 24 && get_l16(packet->payload, 0) == packet->payload_packet_len
&& get_u_int16_t(packet->payload, 2) == htons(0x0202) && get_u_int16_t(packet->payload, 2) == htons(0x0202)
&& get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0xFFFFFFFF)) { && get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0xFFFFFFFF)) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "found florensia.\n"); NDPI_LOG_INFO(ndpi_struct, "found florensia\n");
ndpi_florensia_add_connection(ndpi_struct, flow); ndpi_florensia_add_connection(ndpi_struct, flow);
return; return;
} }
if (flow->packet_counter < 10 && get_l16(packet->payload, 0) == packet->payload_packet_len) { if (flow->packet_counter < 10 && get_l16(packet->payload, 0) == packet->payload_packet_len) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "maybe florensia.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe florensia\n");
return; return;
} }
} }
@@ -103,20 +102,19 @@ void ndpi_search_florensia(struct ndpi_detection_module_struct *ndpi_struct, str
if (packet->udp != NULL) { if (packet->udp != NULL) {
if (flow->florensia_stage == 0 && packet->payload_packet_len == 6 if (flow->florensia_stage == 0 && packet->payload_packet_len == 6
&& get_u_int16_t(packet->payload, 0) == ntohs(0x0503) && get_u_int32_t(packet->payload, 2) == htonl(0xFFFF0000)) { && get_u_int16_t(packet->payload, 0) == ntohs(0x0503) && get_u_int32_t(packet->payload, 2) == htonl(0xFFFF0000)) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "maybe florensia -> stage is set to 1.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe florensia -> stage is set to 1\n");
flow->florensia_stage = 1; flow->florensia_stage = 1;
return; return;
} }
if (flow->florensia_stage == 1 && packet->payload_packet_len == 8 if (flow->florensia_stage == 1 && packet->payload_packet_len == 8
&& get_u_int16_t(packet->payload, 0) == ntohs(0x0500) && get_u_int16_t(packet->payload, 4) == htons(0x4191)) { && get_u_int16_t(packet->payload, 0) == ntohs(0x0500) && get_u_int16_t(packet->payload, 4) == htons(0x4191)) {
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "found florensia.\n"); NDPI_LOG_INFO(ndpi_struct, "found florensia\n");
ndpi_florensia_add_connection(ndpi_struct, flow); ndpi_florensia_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_FLORENSIA, ndpi_struct, NDPI_LOG_DEBUG, "exclude florensia.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FLORENSIA);
} }
+13 -11
View File
@@ -21,10 +21,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_FTP_CONTROL
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FTP_CONTROL
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_FTP_CONTROL
static void ndpi_int_ftp_control_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_int_ftp_control_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FTP_CONTROL, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FTP_CONTROL, NDPI_PROTOCOL_UNKNOWN);
@@ -944,31 +948,29 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
/* Exclude SMTP, which uses similar commands. */ /* Exclude SMTP, which uses similar commands. */
if (packet->tcp->dest == htons(25) || packet->tcp->source == htons(25)) { if (packet->tcp->dest == htons(25) || packet->tcp->source == htons(25)) {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "Exclude FTP_CONTROL.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FTP_CONTROL);
return; return;
} }
/* Break after 20 packets. */ /* Break after 20 packets. */
if (flow->packet_counter > 20) { if (flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "Exclude FTP_CONTROL.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FTP_CONTROL);
return; return;
} }
/* Check if we so far detected the protocol in the request or not. */ /* Check if we so far detected the protocol in the request or not. */
if (flow->ftp_control_stage == 0) { if (flow->ftp_control_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "FTP_CONTROL stage 0: \n"); NDPI_LOG_DBG2(ndpi_struct, "FTP_CONTROL stage 0: \n");
if ((payload_len > 0) && ndpi_ftp_control_check_request(packet->payload, payload_len)) { if ((payload_len > 0) && ndpi_ftp_control_check_request(packet->payload, payload_len)) {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "Possible FTP_CONTROL request detected, we will look further for the response...\n"); NDPI_LOG_DBG2(ndpi_struct, "Possible FTP_CONTROL request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */ /* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->ftp_control_stage = packet->packet_direction + 1; flow->ftp_control_stage = packet->packet_direction + 1;
} }
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "FTP_CONTROL stage %u: \n", flow->ftp_control_stage); NDPI_LOG_DBG2(ndpi_struct, "FTP_CONTROL stage %u: \n", flow->ftp_control_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */ /* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->ftp_control_stage - packet->packet_direction) == 1) { if ((flow->ftp_control_stage - packet->packet_direction) == 1) {
@@ -977,10 +979,10 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
/* This is a packet in another direction. Check if we find the proper response. */ /* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len > 0) && ndpi_ftp_control_check_response(packet->payload, payload_len)) { if ((payload_len > 0) && ndpi_ftp_control_check_response(packet->payload, payload_len)) {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "Found FTP_CONTROL.\n"); NDPI_LOG_INFO(ndpi_struct, "found FTP_CONTROL\n");
ndpi_int_ftp_control_add_connection(ndpi_struct, flow); ndpi_int_ftp_control_add_connection(ndpi_struct, flow);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to FTP_CONTROL, resetting the stage to 0...\n"); NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to FTP_CONTROL, resetting the stage to 0\n");
flow->ftp_control_stage = 0; flow->ftp_control_stage = 0;
} }
} }
@@ -990,7 +992,7 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
void ndpi_search_ftp_control(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_ftp_control(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_FTP_CONTROL, ndpi_struct, NDPI_LOG_DEBUG, "FTP_CONTROL detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search FTP_CONTROL\n");
/* skip marked packets */ /* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_FTP_CONTROL) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_FTP_CONTROL) {
+10 -6
View File
@@ -23,9 +23,14 @@
* *
*/ */
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_FTP_DATA #ifdef NDPI_PROTOCOL_FTP_DATA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_FTP_DATA
#include "ndpi_api.h"
static void ndpi_int_ftp_data_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_int_ftp_data_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FTP_DATA, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FTP_DATA, NDPI_PROTOCOL_UNKNOWN);
} }
@@ -223,22 +228,21 @@ static void ndpi_check_ftp_data(struct ndpi_detection_module_struct *ndpi_struct
|| ndpi_match_ftp_data_port(ndpi_struct, flow) || ndpi_match_ftp_data_port(ndpi_struct, flow)
) )
) { ) {
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "Possible FTP_DATA request detected...\n"); NDPI_LOG_INFO(ndpi_struct, "found FTP_DATA request\n");
ndpi_int_ftp_data_add_connection(ndpi_struct, flow); ndpi_int_ftp_data_add_connection(ndpi_struct, flow);
} else } else
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FTP_DATA); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
/* Break after 20 packets. */ /* Break after 20 packets. */
if(flow->packet_counter > 20) { if(flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "Exclude FTP_DATA.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_FTP_DATA);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_FTP_DATA, ndpi_struct, NDPI_LOG_DEBUG, "FTP_DATA detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search FTP_DATA\n");
ndpi_check_ftp_data(ndpi_struct, flow); ndpi_check_ftp_data(ndpi_struct, flow);
} }
+11 -4
View File
@@ -17,10 +17,16 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_GIT
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_GIT
#include <stdlib.h> #include <stdlib.h>
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_GIT
#define GIT_PORT 9418 #define GIT_PORT 9418
@@ -29,6 +35,8 @@ void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct,
{ {
struct ndpi_packet_struct * packet = &flow->packet; struct ndpi_packet_struct * packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search Git\n");
if((packet->tcp != NULL) && (packet->payload_packet_len > 4)) { if((packet->tcp != NULL) && (packet->payload_packet_len > 4)) {
if((ntohs(packet->tcp->source) == GIT_PORT) if((ntohs(packet->tcp->source) == GIT_PORT)
|| (ntohs(packet->tcp->dest) == GIT_PORT)) { || (ntohs(packet->tcp->dest) == GIT_PORT)) {
@@ -52,15 +60,14 @@ void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct,
} }
if(found_git) { if(found_git) {
NDPI_LOG(NDPI_PROTOCOL_GIT, ndpi_struct, NDPI_LOG_DEBUG, "found Git.\n"); NDPI_LOG_INFO(ndpi_struct, "found Git\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GIT, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GIT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_GIT, ndpi_struct, NDPI_LOG_DEBUG, "exclude Git.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GIT);
} }
+37 -51
View File
@@ -22,13 +22,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
/* include files */
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_GNUTELLA #ifdef NDPI_PROTOCOL_GNUTELLA
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_GNUTELLA
#include "ndpi_api.h"
static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow/* , */ struct ndpi_flow_struct *flow/* , */
/* ndpi_protocol_type_t protocol_type */) /* ndpi_protocol_type_t protocol_type */)
@@ -38,22 +40,21 @@ static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct
struct ndpi_id_struct *dst = flow->dst; struct ndpi_id_struct *dst = flow->dst;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GNUTELLA, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GNUTELLA, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_INFO(ndpi_struct, "found GNUTELLA\n");
if (src != NULL) { if (src != NULL) {
src->gnutella_ts = packet->tick_timestamp; src->gnutella_ts = packet->tick_timestamp;
if (packet->udp != NULL) { if (packet->udp != NULL) {
if (!src->detected_gnutella_udp_port1) { if (!src->detected_gnutella_udp_port1) {
src->detected_gnutella_udp_port1 = (packet->udp->source); src->detected_gnutella_udp_port1 = (packet->udp->source);
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct,
NDPI_LOG_DEBUG, "GNUTELLA UDP PORT1 DETECTED as %u\n", "GNUTELLA UDP PORT1 DETECTED as %u\n", src->detected_gnutella_udp_port1);
src->detected_gnutella_udp_port1);
} else if ((ntohs(packet->udp->source) != src->detected_gnutella_udp_port1) } else if ((ntohs(packet->udp->source) != src->detected_gnutella_udp_port1)
&& !src->detected_gnutella_udp_port2) { && !src->detected_gnutella_udp_port2) {
src->detected_gnutella_udp_port2 = (packet->udp->source); src->detected_gnutella_udp_port2 = (packet->udp->source);
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct,
NDPI_LOG_DEBUG, "GNUTELLA UDP PORT2 DETECTED as %u\n", "GNUTELLA UDP PORT2 DETECTED as %u\n", src->detected_gnutella_udp_port2);
src->detected_gnutella_udp_port2);
} }
} }
@@ -71,16 +72,17 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
struct ndpi_id_struct *dst = flow->dst; struct ndpi_id_struct *dst = flow->dst;
u_int16_t c; u_int16_t c;
NDPI_LOG_DBG(ndpi_struct, "search GNUTELLA\n");
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_GNUTELLA) { if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_GNUTELLA) {
if (src != NULL && ((u_int32_t) if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout)) { (packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "save src connection packet detected\n");
NDPI_LOG_DEBUG, "gnutella : save src connection packet detected\n");
src->gnutella_ts = packet->tick_timestamp; src->gnutella_ts = packet->tick_timestamp;
} else if (dst != NULL && ((u_int32_t) } else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->gnutella_ts) < ndpi_struct->gnutella_timeout)) { (packet->tick_timestamp - dst->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "save dst connection packet detected\n");
NDPI_LOG_DEBUG, "gnutella : save dst connection packet detected\n");
dst->gnutella_ts = packet->tick_timestamp; dst->gnutella_ts = packet->tick_timestamp;
} }
if (src != NULL && (packet->tick_timestamp - src->gnutella_ts) > ndpi_struct->gnutella_timeout) { if (src != NULL && (packet->tick_timestamp - src->gnutella_ts) > ndpi_struct->gnutella_timeout) {
@@ -102,13 +104,11 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->tcp != NULL) { if (packet->tcp != NULL) {
/* this case works asymmetrically */ /* this case works asymmetrically */
if (packet->payload_packet_len > 10 && memcmp(packet->payload, "GNUTELLA/", 9) == 0) { if (packet->payload_packet_len > 10 && memcmp(packet->payload, "GNUTELLA/", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "GNUTELLA DETECTED\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
/* this case works asymmetrically */ /* this case works asymmetrically */
if (packet->payload_packet_len > 17 && memcmp(packet->payload, "GNUTELLA CONNECT/", 17) == 0) { if (packet->payload_packet_len > 17 && memcmp(packet->payload, "GNUTELLA CONNECT/", 17) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "GNUTELLA DETECTED\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -123,7 +123,6 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
|| (packet->line[c].len > 7 && memcmp(packet->line[c].ptr, "X-Queue:", 8) == 0) || (packet->line[c].len > 7 && memcmp(packet->line[c].ptr, "X-Queue:", 8) == 0)
|| (packet->line[c].len > 36 && memcmp(packet->line[c].ptr, || (packet->line[c].len > 36 && memcmp(packet->line[c].ptr,
"Content-Type: application/x-gnutella-", 37) == 0)) { "Content-Type: application/x-gnutella-", 37) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, "DETECTED GNUTELLA GET.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -135,7 +134,6 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& memcmp(packet->user_agent_line.ptr, "BearShare Lite ", 15) == 0) && memcmp(packet->user_agent_line.ptr, "BearShare Lite ", 15) == 0)
|| (packet->accept_line.ptr != NULL && packet->accept_line.len > 24 || (packet->accept_line.ptr != NULL && packet->accept_line.len > 24
&& memcmp(packet->accept_line.ptr, "application n/x-gnutella", 24) == 0)) { && memcmp(packet->accept_line.ptr, "application n/x-gnutella", 24) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, "DETECTED GNUTELLA GET.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
} }
@@ -151,8 +149,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
} }
if (c < (packet->payload_packet_len - 9) && memcmp(&packet->payload[c], "urn:sha1:", 9) == 0) { if (c < (packet->payload_packet_len - 9) && memcmp(&packet->payload[c], "urn:sha1:", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "detected GET /get/ or GET /uri-res/\n");
"detected GET /get/ or GET /uri-res/.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
} }
@@ -161,14 +158,14 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
/* answer to this packet is HTTP/1.1 ..... Content-Type: application/x-gnutella-packets, /* answer to this packet is HTTP/1.1 ..... Content-Type: application/x-gnutella-packets,
* it is searched in the upper paragraph. */ * it is searched in the upper paragraph. */
if (packet->payload_packet_len > 30 && memcmp(packet->payload, "HEAD /gnutella/push-proxy?", 26) == 0) { if (packet->payload_packet_len > 30 && memcmp(packet->payload, "HEAD /gnutella/push-proxy?", 26) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected HEAD /gnutella/push-proxy?\n"); NDPI_LOG_DBG2(ndpi_struct, "detected HEAD /gnutella/push-proxy?\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
/* haven't found any trace with this pattern */ /* haven't found any trace with this pattern */
if (packet->payload_packet_len == 46 if (packet->payload_packet_len == 46
&& memcmp(packet->payload, "\x50\x55\x53\x48\x20\x67\x75\x69\x64\x3a", 10) == 0) { && memcmp(packet->payload, "\x50\x55\x53\x48\x20\x67\x75\x69\x64\x3a", 10) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct,
"detected \x50\x55\x53\x48\x20\x67\x75\x69\x64\x3a\n"); "detected \x50\x55\x53\x48\x20\x67\x75\x69\x64\x3a\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
@@ -189,8 +186,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
44) == 0) || (end - c > 10 && memcmp(&packet->payload[c], "\r\nX-Queue:", 10) == 0) 44) == 0) || (end - c > 10 && memcmp(&packet->payload[c], "\r\nX-Queue:", 10) == 0)
|| (end - c > 13 && memcmp(&packet->payload[c], "\r\nX-Features:", 13) == 0)) { || (end - c > 13 && memcmp(&packet->payload[c], "\r\nX-Features:", 13) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, NDPI_LOG_DBG2(ndpi_struct, "FOXY :: GNUTELLA GET 2 DETECTED\n");
ndpi_struct, NDPI_LOG_TRACE, "FOXY :: GNUTELLA GET 2 DETECTED\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -202,7 +198,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == 0x0a if (packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == 0x0a
&& packet->payload[packet->payload_packet_len - 2] == 0x0a) { && packet->payload[packet->payload_packet_len - 2] == 0x0a) {
if (packet->payload_packet_len > 3 && memcmp(packet->payload, "GIV", 3) == 0) { if (packet->payload_packet_len > 3 && memcmp(packet->payload, "GIV", 3) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "MORPHEUS GIV DETECTED\n"); NDPI_LOG_DBG2(ndpi_struct, "MORPHEUS GIV DETECTED\n");
/* Not Excluding the flow now.. We shall Check the next Packet too for Gnutella Patterns */ /* Not Excluding the flow now.. We shall Check the next Packet too for Gnutella Patterns */
return; return;
} }
@@ -211,21 +207,21 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->payload_packet_len == 46 && get_u_int32_t(packet->payload, 0) == htonl(0x802c0103) && if (packet->payload_packet_len == 46 && get_u_int32_t(packet->payload, 0) == htonl(0x802c0103) &&
get_u_int32_t(packet->payload, 4) == htonl(0x01000300) && get_u_int32_t(packet->payload, 8) == htonl(0x00002000) && get_u_int32_t(packet->payload, 4) == htonl(0x01000300) && get_u_int32_t(packet->payload, 8) == htonl(0x00002000) &&
get_u_int16_t(packet->payload, 12) == htons(0x0034)) { get_u_int16_t(packet->payload, 12) == htons(0x0034)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected gnutella len == 46.\n"); NDPI_LOG_DBG2(ndpi_struct, "detected gnutella len == 46\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 49 && if (packet->payload_packet_len == 49 &&
memcmp(packet->payload, "\x80\x2f\x01\x03\x01\x00\x06\x00\x00\x00\x20\x00\x00\x34\x00\x00\xff\x4d\x6c", memcmp(packet->payload, "\x80\x2f\x01\x03\x01\x00\x06\x00\x00\x00\x20\x00\x00\x34\x00\x00\xff\x4d\x6c",
19) == 0) { 19) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected gnutella len == 49.\n"); NDPI_LOG_DBG2(ndpi_struct, "detected gnutella len == 49\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 89 && memcmp(&packet->payload[43], "\x20\x4d\x6c", 3) == 0 && if (packet->payload_packet_len == 89 && memcmp(&packet->payload[43], "\x20\x4d\x6c", 3) == 0 &&
memcmp(packet->payload, "\x16\x03\x01\x00\x54\x01\x00\x00\x50\x03\x01\x4d\x6c", 13) == 0 && memcmp(packet->payload, "\x16\x03\x01\x00\x54\x01\x00\x00\x50\x03\x01\x4d\x6c", 13) == 0 &&
memcmp(&packet->payload[76], "\x00\x02\x00\x34\x01\x00\x00\x05", 8) == 0) { memcmp(&packet->payload[76], "\x00\x02\x00\x34\x01\x00\x00\x05", 8) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct,
"detected gnutella asymmetrically len == 388.\n"); "detected gnutella asymmetrically len == 388.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
@@ -235,7 +231,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& get_u_int16_t(packet->payload, 8) == htons(0x4903) && get_u_int16_t(packet->payload, 8) == htons(0x4903)
&& get_u_int16_t(packet->payload, 76) == htons(0x0002) && get_u_int16_t(packet->payload, 76) == htons(0x0002)
&& get_u_int32_t(packet->payload, 78) == htonl(0x00340100)) { && get_u_int32_t(packet->payload, 78) == htonl(0x00340100)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_TRACE, "detected len == 82.\n"); NDPI_LOG_DBG2(ndpi_struct, "detected len == 82\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -244,7 +240,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (src != NULL && (packet->udp->source == src->detected_gnutella_udp_port1 || if (src != NULL && (packet->udp->source == src->detected_gnutella_udp_port1 ||
packet->udp->source == src->detected_gnutella_udp_port2) && packet->udp->source == src->detected_gnutella_udp_port2) &&
(packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout) { (packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, "port based detection\n\n"); NDPI_LOG_DBG2(ndpi_struct, "port based detection\n\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
} }
/* observations: /* observations:
@@ -257,8 +253,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& packet->payload[16] == 0x41 && packet->payload[17] == 0x01 && packet->payload[16] == 0x41 && packet->payload[17] == 0x01
&& packet->payload[18] == 0x00 && packet->payload[19] == 0x00 && packet->payload[18] == 0x00 && packet->payload[19] == 0x00
&& packet->payload[20] == 0x00 && packet->payload[21] == 0x00 && packet->payload[22] == 0x00) { && packet->payload[20] == 0x00 && packet->payload[21] == 0x00 && packet->payload[22] == 0x00) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 23\n");
"detected gnutella udp, len = 23.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
@@ -267,29 +262,25 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& packet->payload[26] == 0x50 && packet->payload[27] == 0x40 && packet->payload[26] == 0x50 && packet->payload[27] == 0x40
&& packet->payload[28] == 0x83 && packet->payload[29] == 0x53 && packet->payload[28] == 0x83 && packet->payload[29] == 0x53
&& packet->payload[30] == 0x43 && packet->payload[31] == 0x50 && packet->payload[32] == 0x41) { && packet->payload[30] == 0x43 && packet->payload[31] == 0x50 && packet->payload[32] == 0x41) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 35\n");
"detected gnutella udp, len = 35.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 32 if (packet->payload_packet_len == 32
&& (memcmp(&packet->payload[16], "\x31\x01\x00\x09\x00\x00\x00\x4c\x49\x4d\x45", 11) == 0)) { && (memcmp(&packet->payload[16], "\x31\x01\x00\x09\x00\x00\x00\x4c\x49\x4d\x45", 11) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 32\n");
"detected gnutella udp, len = 32.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 34 && (memcmp(&packet->payload[25], "SCP@", 4) == 0) if (packet->payload_packet_len == 34 && (memcmp(&packet->payload[25], "SCP@", 4) == 0)
&& (memcmp(&packet->payload[30], "DNA@", 4) == 0)) { && (memcmp(&packet->payload[30], "DNA@", 4) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 34\n");
"detected gnutella udp, len = 34.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
if ((packet->payload_packet_len == 73 || packet->payload_packet_len == 96) if ((packet->payload_packet_len == 73 || packet->payload_packet_len == 96)
&& memcmp(&packet->payload[32], "urn:sha1:", 9) == 0) { && memcmp(&packet->payload[32], "urn:sha1:", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 73,96\n");
"detected gnutella udp, len = 73,96.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -308,8 +299,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& (memcmp(&packet->payload[6], "\x01\x01\x5c\x1b\x50\x55\x53\x48\x48\x10", 10) == 0)) && (memcmp(&packet->payload[6], "\x01\x01\x5c\x1b\x50\x55\x53\x48\x48\x10", 10) == 0))
|| (packet->payload_packet_len > 200 && packet->payload_packet_len < 300 && packet->payload[3] == 0x03) || (packet->payload_packet_len > 200 && packet->payload_packet_len < 300 && packet->payload[3] == 0x03)
|| (packet->payload_packet_len > 300 && (packet->payload[3] == 0x01 || packet->payload[3] == 0x03))) { || (packet->payload_packet_len > 300 && (packet->payload[3] == 0x01 || packet->payload[3] == 0x03))) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, GND\n");
"detected gnutella udp, GND.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -317,15 +307,13 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if ((packet->payload_packet_len == 32) if ((packet->payload_packet_len == 32)
&& memcmp(&packet->payload[16], "\x31\x01\x00\x09\x00\x00\x00", 7) == 0) { && memcmp(&packet->payload[16], "\x31\x01\x00\x09\x00\x00\x00", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 32 ii\n");
"detected gnutella udp, len = 32 ii.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
if ((packet->payload_packet_len == 23) if ((packet->payload_packet_len == 23)
&& memcmp(&packet->payload[16], "\x00\x01\x00\x00\x00\x00\x00", 7) == 0) { && memcmp(&packet->payload[16], "\x00\x01\x00\x00\x00\x00\x00", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "detected gnutella udp, len = 23 ii\n");
"detected gnutella udp, len = 23 ii.\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -350,8 +338,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& flow->l4.tcp.gnutella_msg_id[1] == packet->payload[2] && flow->l4.tcp.gnutella_msg_id[1] == packet->payload[2]
&& flow->l4.tcp.gnutella_msg_id[2] == packet->payload[4] && flow->l4.tcp.gnutella_msg_id[2] == packet->payload[4]
&& NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_GNUTELLA)) { && NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_GNUTELLA)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
NDPI_LOG_TRACE, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -361,15 +348,14 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
&& flow->l4.tcp.gnutella_msg_id[1] == packet->payload[2] && flow->l4.tcp.gnutella_msg_id[1] == packet->payload[2]
&& flow->l4.tcp.gnutella_msg_id[2] == packet->payload[4] && flow->l4.tcp.gnutella_msg_id[2] == packet->payload[4]
&& NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_GNUTELLA)) { && NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_GNUTELLA)) {
NDPI_LOG(NDPI_PROTOCOL_GNUTELLA, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
NDPI_LOG_TRACE, "GNUTELLA DETECTED due to message ID match (NEONet protocol)\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow); ndpi_int_gnutella_add_connection(ndpi_struct, flow);
return; return;
} }
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GNUTELLA); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+8 -4
View File
@@ -18,10 +18,14 @@
* *
*/ */
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_GTP #ifdef NDPI_PROTOCOL_GTP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_GTP
#include "ndpi_api.h"
struct gtp_header_generic { struct gtp_header_generic {
u_int8_t flags, message_type; u_int8_t flags, message_type;
u_int16_t message_len; u_int16_t message_len;
@@ -50,7 +54,7 @@ static void ndpi_check_gtp(struct ndpi_detection_module_struct *ndpi_struct, str
u_int16_t message_len = ntohs(gtp->message_len); u_int16_t message_len = ntohs(gtp->message_len);
if(message_len <= (payload_len-sizeof(struct gtp_header_generic))) { if(message_len <= (payload_len-sizeof(struct gtp_header_generic))) {
NDPI_LOG(NDPI_PROTOCOL_GTP, ndpi_struct, NDPI_LOG_DEBUG, "Found gtp.\n"); NDPI_LOG_INFO(ndpi_struct, "found gtp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GTP, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GTP, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
@@ -58,7 +62,7 @@ static void ndpi_check_gtp(struct ndpi_detection_module_struct *ndpi_struct, str
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GTP); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
@@ -66,7 +70,7 @@ void ndpi_search_gtp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_GTP, ndpi_struct, NDPI_LOG_DEBUG, "gtp detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search gtp\n");
/* skip marked packets */ /* skip marked packets */
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_GTP) if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_GTP)
+10 -10
View File
@@ -22,10 +22,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_GUILDWARS #ifdef NDPI_PROTOCOL_GUILDWARS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_GUILDWARS
#include "ndpi_api.h"
static void ndpi_int_guildwars_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_guildwars_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -35,35 +39,31 @@ static void ndpi_int_guildwars_add_connection(struct ndpi_detection_module_struc
void ndpi_search_guildwars_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_guildwars_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_GUILDWARS, ndpi_struct, NDPI_LOG_DEBUG, "search guildwars.\n"); NDPI_LOG_DBG(ndpi_struct, "search guildwars\n");
if (packet->payload_packet_len == 64 && get_u_int16_t(packet->payload, 1) == ntohs(0x050c) if (packet->payload_packet_len == 64 && get_u_int16_t(packet->payload, 1) == ntohs(0x050c)
&& memcmp(&packet->payload[50], "@2&P", 4) == 0) { && memcmp(&packet->payload[50], "@2&P", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_GUILDWARS, ndpi_struct, NDPI_LOG_DEBUG, "GuildWars version 29.350: found.\n"); NDPI_LOG_INFO(ndpi_struct, "found GuildWars version 29.350\n");
ndpi_int_guildwars_add_connection(ndpi_struct, flow); ndpi_int_guildwars_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 16 && get_u_int16_t(packet->payload, 1) == ntohs(0x040c) if (packet->payload_packet_len == 16 && get_u_int16_t(packet->payload, 1) == ntohs(0x040c)
&& get_u_int16_t(packet->payload, 4) == ntohs(0xa672) && get_u_int16_t(packet->payload, 4) == ntohs(0xa672)
&& packet->payload[8] == 0x01 && packet->payload[12] == 0x04) { && packet->payload[8] == 0x01 && packet->payload[12] == 0x04) {
NDPI_LOG(NDPI_PROTOCOL_GUILDWARS, ndpi_struct, NDPI_LOG_DEBUG, "GuildWars version 29.350: found.\n"); NDPI_LOG_INFO(ndpi_struct, "found GuildWars version 29.350\n");
ndpi_int_guildwars_add_connection(ndpi_struct, flow); ndpi_int_guildwars_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 21 && get_u_int16_t(packet->payload, 0) == ntohs(0x0100) if (packet->payload_packet_len == 21 && get_u_int16_t(packet->payload, 0) == ntohs(0x0100)
&& get_u_int32_t(packet->payload, 5) == ntohl(0xf1001000) && get_u_int32_t(packet->payload, 5) == ntohl(0xf1001000)
&& packet->payload[9] == 0x01) { && packet->payload[9] == 0x01) {
NDPI_LOG(NDPI_PROTOCOL_GUILDWARS, ndpi_struct, NDPI_LOG_DEBUG, "GuildWars version 216.107.245.50: found.\n"); NDPI_LOG_INFO(ndpi_struct, "found GuildWars version 216.107.245.50\n");
ndpi_int_guildwars_add_connection(ndpi_struct, flow); ndpi_int_guildwars_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_GUILDWARS, ndpi_struct, NDPI_LOG_DEBUG, "exclude guildwars.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GUILDWARS);
} }
+17 -10
View File
@@ -7,10 +7,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_H323 #ifdef NDPI_PROTOCOL_H323
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_H323
#include "ndpi_api.h"
struct tpkt { struct tpkt {
u_int8_t version, reserved; u_int8_t version, reserved;
u_int16_t len; u_int16_t len;
@@ -21,10 +26,10 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t dport = 0, sport = 0; u_int16_t dport = 0, sport = 0;
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "search H323.\n"); NDPI_LOG_DBG(ndpi_struct, "search H323\n");
if(packet->tcp != NULL) { if(packet->tcp != NULL) {
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over tcp.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculated dport over tcp\n");
/* H323 */ /* H323 */
if(packet->payload_packet_len >= 3 if(packet->payload_packet_len >= 3
@@ -44,6 +49,7 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
/* ISO 8073/X.224 */ /* ISO 8073/X.224 */
if((packet->payload[5] == 0xE0 /* CC Connect Request */) if((packet->payload[5] == 0xE0 /* CC Connect Request */)
|| (packet->payload[5] == 0xD0 /* CC Connect Confirm */)) { || (packet->payload[5] == 0xD0 /* CC Connect Confirm */)) {
NDPI_LOG_INFO(ndpi_struct, "found RDP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
@@ -52,23 +58,24 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
flow->l4.tcp.h323_valid_packets++; flow->l4.tcp.h323_valid_packets++;
if(flow->l4.tcp.h323_valid_packets >= 2) { if(flow->l4.tcp.h323_valid_packets >= 2) {
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n"); NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
} }
} else { } else {
/* This is not H.323 */ /* This is not H.323 */
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_H323); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
} }
} }
} else if(packet->udp != NULL) { } else if(packet->udp != NULL) {
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest); sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over udp.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculated dport over udp\n");
if(packet->payload_packet_len >= 6 && packet->payload[0] == 0x80 && packet->payload[1] == 0x08 && if(packet->payload_packet_len >= 6 && packet->payload[0] == 0x80 && packet->payload[1] == 0x08 &&
(packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) && (packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) &&
packet->payload[4] == 0x00 && packet->payload[5] == 0x00) packet->payload[4] == 0x00 && packet->payload[5] == 0x00)
{ {
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n"); NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
@@ -77,19 +84,19 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
{ {
if(packet->payload[0] == 0x16 && packet->payload[1] == 0x80 && packet->payload[4] == 0x06 && packet->payload[5] == 0x00) if(packet->payload[0] == 0x16 && packet->payload[1] == 0x80 && packet->payload[4] == 0x06 && packet->payload[5] == 0x00)
{ {
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n"); NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
else if(packet->payload_packet_len >= 20 && packet->payload_packet_len <= 117) else if(packet->payload_packet_len >= 20 && packet->payload_packet_len <= 117)
{ {
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n"); NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
else else
{ {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_H323); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
} }
+10 -7
View File
@@ -23,9 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_HALFLIFE2 #ifdef NDPI_PROTOCOL_HALFLIFE2
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HALFLIFE2
#include "ndpi_api.h"
static void ndpi_int_halflife2_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_halflife2_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -36,15 +41,14 @@ void ndpi_search_halflife2(struct ndpi_detection_module_struct *ndpi_struct, str
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search halflife2\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (flow->l4.udp.halflife2_stage == 0) { if (flow->l4.udp.halflife2_stage == 0) {
if (packet->payload_packet_len >= 20 if (packet->payload_packet_len >= 20
&& get_u_int32_t(packet->payload, 0) == 0xFFFFFFFF && get_u_int32_t(packet->payload, 0) == 0xFFFFFFFF
&& get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0x30303000)) { && get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0x30303000)) {
flow->l4.udp.halflife2_stage = 1 + packet->packet_direction; flow->l4.udp.halflife2_stage = 1 + packet->packet_direction;
NDPI_LOG(NDPI_PROTOCOL_HALFLIFE2, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"halflife2 client req detected, waiting for server reply\n"); "halflife2 client req detected, waiting for server reply\n");
return; return;
} }
@@ -53,13 +57,12 @@ void ndpi_search_halflife2(struct ndpi_detection_module_struct *ndpi_struct, str
&& get_u_int32_t(packet->payload, 0) == 0xFFFFFFFF && get_u_int32_t(packet->payload, 0) == 0xFFFFFFFF
&& get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0x30303000)) { && get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0x30303000)) {
ndpi_int_halflife2_add_connection(ndpi_struct, flow); ndpi_int_halflife2_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_HALFLIFE2, ndpi_struct, NDPI_LOG_DEBUG, "halflife2 server reply detected\n"); NDPI_LOG_INFO(ndpi_struct, "found halflife2\n");
return; return;
} }
} }
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HALFLIFE2);
} }
+11 -4
View File
@@ -17,10 +17,16 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_api.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_HANGOUT #ifdef NDPI_PROTOCOL_HANGOUT
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HANGOUT
#include "ndpi_api.h"
/* https://support.google.com/a/answer/1279090?hl=en */ /* https://support.google.com/a/answer/1279090?hl=en */
#define HANGOUT_UDP_LOW_PORT 19302 #define HANGOUT_UDP_LOW_PORT 19302
#define HANGOUT_UDP_HIGH_PORT 19309 #define HANGOUT_UDP_HIGH_PORT 19309
@@ -73,19 +79,20 @@ void ndpi_search_hangout(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct * packet = &flow->packet; struct ndpi_packet_struct * packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search Hangout\n");
if((packet->payload_packet_len > 24) && is_google_flow(ndpi_struct, flow)) { if((packet->payload_packet_len > 24) && is_google_flow(ndpi_struct, flow)) {
if( if(
((packet->udp != NULL) && (isHangoutUDPPort(ntohs(packet->udp->source)) || isHangoutUDPPort(ntohs(packet->udp->dest)))) ((packet->udp != NULL) && (isHangoutUDPPort(ntohs(packet->udp->source)) || isHangoutUDPPort(ntohs(packet->udp->dest))))
|| ||
((packet->tcp != NULL) && (isHangoutTCPPort(ntohs(packet->tcp->source)) || isHangoutTCPPort(ntohs(packet->tcp->dest))))) { ((packet->tcp != NULL) && (isHangoutTCPPort(ntohs(packet->tcp->source)) || isHangoutTCPPort(ntohs(packet->tcp->dest))))) {
NDPI_LOG(NDPI_PROTOCOL_HANGOUT, ndpi_struct, NDPI_LOG_DEBUG, "Found Hangout.\n"); NDPI_LOG_INFO(ndpi_struct, "found Hangout\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HANGOUT, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HANGOUT, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_HANGOUT, ndpi_struct, NDPI_LOG_DEBUG, "No Hangout.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HANGOUT);
} }
/* ***************************************************************** */ /* ***************************************************************** */
+10 -5
View File
@@ -24,9 +24,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_HEP #ifdef NDPI_PROTOCOL_HEP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HEP
#include "ndpi_api.h"
static void ndpi_int_hep_add_connection(struct ndpi_detection_module_struct static void ndpi_int_hep_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -39,17 +45,16 @@ void ndpi_search_hep(struct ndpi_detection_module_struct *ndpi_struct, struct nd
const u_int8_t *packet_payload = packet->payload; const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
NDPI_LOG(NDPI_PROTOCOL_HEP, ndpi_struct, NDPI_LOG_DEBUG, "searching for HEP.\n"); NDPI_LOG_DBG(ndpi_struct, "searching HEP\n");
if (payload_len > 10) { if (payload_len > 10) {
if (memcmp(packet_payload, "HEP3", 4) == 0) { if (memcmp(packet_payload, "HEP3", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HEP, ndpi_struct, NDPI_LOG_DEBUG, "found HEP3.\n"); NDPI_LOG_INFO(ndpi_struct, "found HEP3\n");
ndpi_int_hep_add_connection(ndpi_struct, flow); ndpi_int_hep_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_HEP, ndpi_struct, NDPI_LOG_DEBUG, "exclude HEP.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HEP);
} }
+132 -102
View File
@@ -20,10 +20,15 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocols.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_HTTP #ifdef NDPI_PROTOCOL_HTTP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HTTP
#include "ndpi_api.h"
/* global variables used for 1kxun protocol and iqiyi service */ /* global variables used for 1kxun protocol and iqiyi service */
@@ -63,7 +68,7 @@ static void flash_check_http_payload(struct ndpi_detection_module_struct
if(memcmp(pos, "FLV", 3) == 0 && pos[3] == 0x01 && (pos[4] == 0x01 || pos[4] == 0x04 || pos[4] == 0x05) if(memcmp(pos, "FLV", 3) == 0 && pos[3] == 0x01 && (pos[4] == 0x01 || pos[4] == 0x04 || pos[4] == 0x05)
&& pos[5] == 0x00 && pos[6] == 0x00 && pos[7] == 0x00 && pos[8] == 0x09) { && pos[5] == 0x00 && pos[6] == 0x00 && pos[7] == 0x00 && pos[8] == 0x09) {
NDPI_LOG(NDPI_CONTENT_FLASH, ndpi_struct, NDPI_LOG_DEBUG, "Flash content in HTTP detected\n"); NDPI_LOG_INFO(ndpi_struct, "found Flash content in HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_FLASH); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_FLASH);
} }
} }
@@ -75,7 +80,7 @@ static void avi_check_http_payload(struct ndpi_detection_module_struct *ndpi_str
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_CONTENT_AVI, ndpi_struct, NDPI_LOG_DEBUG, "called avi_check_http_payload: %u %u %u\n", 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) if(packet->empty_line_position_set == 0 && flow->l4.tcp.http_empty_line_seen == 0)
@@ -90,7 +95,7 @@ static void avi_check_http_payload(struct ndpi_detection_module_struct *ndpi_str
if(flow->l4.tcp.http_empty_line_seen == 1) { if(flow->l4.tcp.http_empty_line_seen == 1) {
if(packet->payload_packet_len > 20 && memcmp(packet->payload, "RIFF", 4) == 0 if(packet->payload_packet_len > 20 && memcmp(packet->payload, "RIFF", 4) == 0
&& memcmp(packet->payload + 8, "AVI LIST", 8) == 0) { && memcmp(packet->payload + 8, "AVI LIST", 8) == 0) {
NDPI_LOG(NDPI_CONTENT_AVI, ndpi_struct, NDPI_LOG_DEBUG, "Avi content in HTTP detected\n"); NDPI_LOG_INFO(ndpi_struct, "found Avi content in HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_AVI); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_AVI);
} }
flow->l4.tcp.http_empty_line_seen = 0; flow->l4.tcp.http_empty_line_seen = 0;
@@ -105,11 +110,11 @@ static void avi_check_http_payload(struct ndpi_detection_module_struct *ndpi_str
u_int32_t p = packet->empty_line_position + 2; u_int32_t p = packet->empty_line_position + 2;
// check for avi header // check for avi header
NDPI_LOG(NDPI_CONTENT_AVI, ndpi_struct, NDPI_LOG_DEBUG, "p = %u\n", p); NDPI_LOG_DBG2(ndpi_struct, "p = %u\n", p);
if((p + 16) <= packet->payload_packet_len && memcmp(&packet->payload[p], "RIFF", 4) == 0 if((p + 16) <= packet->payload_packet_len && memcmp(&packet->payload[p], "RIFF", 4) == 0
&& memcmp(&packet->payload[p + 8], "AVI LIST", 8) == 0) { && memcmp(&packet->payload[p + 8], "AVI LIST", 8) == 0) {
NDPI_LOG(NDPI_CONTENT_AVI, ndpi_struct, NDPI_LOG_DEBUG, "Avi content in HTTP detected\n"); NDPI_LOG_INFO(ndpi_struct, "found Avi content in HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_AVI); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_AVI);
} }
} }
@@ -122,7 +127,7 @@ static void teamviewer_check_http_payload(struct ndpi_detection_module_struct *n
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
const u_int8_t *pos; const u_int8_t *pos;
NDPI_LOG(NDPI_PROTOCOL_TEAMVIEWER, ndpi_struct, NDPI_LOG_DEBUG, "called teamviewer_check_http_payload: %u %u %u\n", 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)) if(packet->empty_line_position_set == 0 || (packet->empty_line_position + 5) > (packet->payload_packet_len))
@@ -131,7 +136,7 @@ static void teamviewer_check_http_payload(struct ndpi_detection_module_struct *n
pos = &packet->payload[packet->empty_line_position] + 2; pos = &packet->payload[packet->empty_line_position] + 2;
if(pos[0] == 0x17 && pos[1] == 0x24) { if(pos[0] == 0x17 && pos[1] == 0x24) {
NDPI_LOG(NDPI_PROTOCOL_TEAMVIEWER, ndpi_struct, NDPI_LOG_DEBUG, "TeamViewer content in HTTP detected\n"); NDPI_LOG_INFO(ndpi_struct, "found TeamViewer content in HTTP\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_TEAMVIEWER); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_TEAMVIEWER);
} }
} }
@@ -145,7 +150,7 @@ static void rtsp_parse_packet_acceptline(struct ndpi_detection_module_struct
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
if(packet->accept_line.len >= 28 && memcmp(packet->accept_line.ptr, "application/x-rtsp-tunnelled", 28) == 0) { if(packet->accept_line.len >= 28 && memcmp(packet->accept_line.ptr, "application/x-rtsp-tunnelled", 28) == 0) {
NDPI_LOG(NDPI_PROTOCOL_RTSP, ndpi_struct, NDPI_LOG_DEBUG, "RTSP accept line detected\n"); NDPI_LOG_INFO(ndpi_struct, "found RTSP accept line\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_RTSP); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_RTSP);
} }
} }
@@ -199,12 +204,12 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI) #if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* PPStream */ /* PPStream */
if(flow->l4.tcp.ppstream_stage > 0 && flow->iqiyi_counter == 0) { if(flow->l4.tcp.ppstream_stage > 0 && flow->iqiyi_counter == 0) {
NDPI_LOG(NDPI_PROTOCOL_PPSTREAM, ndpi_struct, NDPI_LOG_DEBUG, "PPStream found.\n"); NDPI_LOG_INFO(ndpi_struct, "found PPStream\n");
/* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM); */ /* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM); */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM, NDPI_PROTOCOL_HTTP); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM, NDPI_PROTOCOL_HTTP);
} }
else if(flow->iqiyi_counter > 0) { else if(flow->iqiyi_counter > 0) {
NDPI_LOG(NDPI_PROTOCOL_IQIYI, ndpi_struct, NDPI_LOG_DEBUG, "iQiyi found.\n"); NDPI_LOG_INFO(ndpi_struct, "found iQiyi\n");
/* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI); */ /* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI); */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI, NDPI_PROTOCOL_HTTP); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI, NDPI_PROTOCOL_HTTP);
} }
@@ -213,7 +218,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI) #if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* 1KXUN */ /* 1KXUN */
if(flow->kxun_counter > 0) { if(flow->kxun_counter > 0) {
NDPI_LOG(NDPI_PROTOCOL_1KXUN, ndpi_struct, NDPI_LOG_DEBUG, "1kxun found.\n"); NDPI_LOG_INFO(ndpi_struct, "found 1kxun\n");
/* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN); */ /* ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN); */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN, NDPI_PROTOCOL_HTTP); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN, NDPI_PROTOCOL_HTTP);
} }
@@ -330,12 +335,13 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
} }
} }
else if(memcmp(ua, "netflix-ios-app", 15) == 0) { else if(memcmp(ua, "netflix-ios-app", 15) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found netflix\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_NETFLIX); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_NETFLIX);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "User Agent Type line found %.*s\n", 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);
} }
@@ -343,7 +349,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(packet->host_line.ptr != NULL) { if(packet->host_line.ptr != NULL) {
u_int len; u_int len;
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HOST line found %.*s\n", 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 */ /* call ndpi_match_host_subprotocol to see if there is a match with known-host HTTP subprotocol */
@@ -395,6 +401,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) { if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_HTTP) { 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_int_http_add_connection(ndpi_struct, flow, 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 */ return; /* We have identified a sub-protocol so we're done */
} }
@@ -409,7 +417,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
/* check for accept line */ /* check for accept line */
if(packet->accept_line.ptr != NULL) { if(packet->accept_line.ptr != NULL) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "Accept line found %.*s\n", 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);
#ifdef NDPI_PROTOCOL_RTSP #ifdef NDPI_PROTOCOL_RTSP
if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(ndpi_struct->detection_bitmask, NDPI_PROTOCOL_RTSP) != 0) { if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(ndpi_struct->detection_bitmask, NDPI_PROTOCOL_RTSP) != 0) {
@@ -422,7 +430,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
#ifdef NDPI_CONTENT_MPEG #ifdef NDPI_CONTENT_MPEG
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) { if(packet->line[a].len > 11 && memcmp(packet->line[a].ptr, "Icy-MetaData", 12) == 0) {
NDPI_LOG(NDPI_CONTENT_MPEG, ndpi_struct, NDPI_LOG_DEBUG, "MPEG: Icy-MetaData found.\n"); NDPI_LOG_INFO(ndpi_struct, "found MPEG: Icy-MetaData\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_MPEG); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_CONTENT_MPEG);
return; return;
} }
@@ -432,7 +440,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
#endif #endif
if(packet->content_line.ptr != NULL && packet->content_line.len != 0) { if(packet->content_line.ptr != NULL && packet->content_line.len != 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "Content Type line found %.*s\n", 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) if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
@@ -444,7 +452,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "called check_http_payload.\n"); NDPI_LOG_DBG2(ndpi_struct, "called check_http_payload\n");
#ifdef NDPI_CONTENT_FLASH #ifdef NDPI_CONTENT_FLASH
if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(ndpi_struct->detection_bitmask, NDPI_CONTENT_FLASH) != 0) if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(ndpi_struct->detection_bitmask, NDPI_CONTENT_FLASH) != 0)
@@ -466,54 +474,55 @@ static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct,
* @returnvalue 0 if no valid request has been found * @returnvalue 0 if no valid request has been found
* @returnvalue >0 indicates start of filename but not necessarily in packet limit * @returnvalue >0 indicates start of filename but not necessarily in packet limit
*/ */
#define STATIC_STRING_L(a) {.str=a, .len=sizeof(a)-1 }
static struct l_string {
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 const char *http_fs = "CDGHOPR";
static uint8_t non_ctrl(uint8_t 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) static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
int i;
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "====>>>> HTTP: %c%c%c%c [len: %u]\n", NDPI_LOG_DBG2(ndpi_struct, "====>>>> HTTP: %c%c%c%c [len: %u]\n",
packet->payload[0], packet->payload[1], packet->payload[2], packet->payload[3], non_ctrl(packet->payload[0]), non_ctrl(packet->payload[1]),
non_ctrl(packet->payload[2]), non_ctrl(packet->payload[3]),
packet->payload_packet_len); packet->payload_packet_len);
/* Check first char */
if(!strchr(http_fs,packet->payload[0])) return 0;
/** /**
FIRST PAYLOAD PACKET FROM CLIENT FIRST PAYLOAD PACKET FROM CLIENT
**/ **/
for(i=0; i < sizeof(http_methods)/sizeof(http_methods[0]); i++) {
/* check if the packet starts with POST or GET */ if(packet->payload_packet_len >= http_methods[i].len &&
if(packet->payload_packet_len >= 4 && memcmp(packet->payload, "GET ", 4) == 0) { memcmp(packet->payload,http_methods[i].str,http_methods[i].len) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: GET FOUND\n"); NDPI_LOG_DBG2(ndpi_struct, "HTTP: %sFOUND\n",http_methods[i].str);
return 4; return http_methods[i].len;
} else if(packet->payload_packet_len >= 5 && memcmp(packet->payload, "POST ", 5) == 0) { }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: POST FOUND\n");
return 5;
} else if(packet->payload_packet_len >= 8 && memcmp(packet->payload, "OPTIONS ", 8) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: OPTIONS FOUND\n");
return 8;
} else if(packet->payload_packet_len >= 5 && memcmp(packet->payload, "HEAD ", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: HEAD FOUND\n");
return 5;
} else if(packet->payload_packet_len >= 4 && memcmp(packet->payload, "PUT ", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: PUT FOUND\n");
return 4;
} else if(packet->payload_packet_len >= 7 && memcmp(packet->payload, "DELETE ", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: DELETE FOUND\n");
return 7;
} else if(packet->payload_packet_len >= 8 && memcmp(packet->payload, "CONNECT ", 8) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: CONNECT FOUND\n");
return 8;
} else if(packet->payload_packet_len >= 9 && memcmp(packet->payload, "PROPFIND ", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: PROFIND FOUND\n");
return 9;
} else if(packet->payload_packet_len >= 7 && memcmp(packet->payload, "REPORT ", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: REPORT FOUND\n");
return 7;
} }
return 0; return 0;
} }
static void http_bitmask_exclude(struct ndpi_flow_struct *flow) static void http_bitmask_exclude_other(struct ndpi_flow_struct *flow)
{ {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HTTP);
#ifdef NDPI_CONTENT_MPEG #ifdef NDPI_CONTENT_MPEG
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_CONTENT_MPEG); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_CONTENT_MPEG);
#endif #endif
@@ -543,40 +552,55 @@ static void http_bitmask_exclude(struct ndpi_flow_struct *flow)
/*************************************************************************************************/ /*************************************************************************************************/
static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct, 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; struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t filename_start; /* the filename in the request method line, e.g., "GET filename_start..."*/ u_int16_t filename_start; /* the filename in the request method line, e.g., "GET filename_start..."*/
packet->packet_lines_parsed_complete = 0; packet->packet_lines_parsed_complete = 0;
/* Check if we so far detected the protocol in the request or not. */ /* Check if we so far detected the protocol in the request or not. */
if(flow->l4.tcp.http_stage == 0) { /* Expected a request */ if(flow->l4.tcp.http_stage == 0) {
/* Expected a request */
flow->http_detected = 0; flow->http_detected = 0;
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP stage %d: \n", NDPI_LOG_DBG2(ndpi_struct, "HTTP stage %d: \n", flow->l4.tcp.http_stage);
flow->l4.tcp.http_stage);
filename_start = http_request_url_offset(ndpi_struct, flow); filename_start = http_request_url_offset(ndpi_struct, flow);
if(filename_start == 0) { /* not a regular request. In the HTTP first stage, may be a truncated flow or other protocols */ if(filename_start == 0) { /* not a regular request. In the HTTP first stage, may be a truncated flow or other protocols */
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "Filename HTTP not found, we look for possible truncate flow..\n");
"Filename HTTP not found, we look for possible truncate flow...\n");
if(packet->payload_packet_len >= 7 && memcmp(packet->payload, "HTTP/1.", 7) == 0) { if(packet->payload_packet_len >= 7 && memcmp(packet->payload, "HTTP/1.", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct, "found HTTP response\n");
"HTTP response found (truncated flow ?)\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
return; return;
} }
if((packet->payload_packet_len == 3) && memcmp(packet->payload, "HI\n", 3) == 0) { if((packet->payload_packet_len == 3) && memcmp(packet->payload, "HI\n", 3) == 0) {
/* This looks like Ookla: we don't give up with HTTP yet */ /* This looks like Ookla: we don't give up with HTTP yet */
flow->l4.tcp.http_stage = 1; flow->l4.tcp.http_stage = 1;
return; return;
} }
if((packet->payload_packet_len == 40) && (flow->l4.tcp.http_stage == 0)) {
/*
-> QR O06L0072-6L91-4O43-857J-K8OO172L6L51
<- QNUUX 2.5 2017-08-15.1314.4jn12m5
-> MXFWUXJM 31625365
*/
if((packet->payload[2] == ' ')
&& (packet->payload[11] == '-')
&& (packet->payload[16] == '-')
&& (packet->payload[21] == '-')
&& (packet->payload[26] == '-')
&& (packet->payload[39] == 0x0A)
)
flow->l4.tcp.http_stage = 1;
return;
}
if((packet->payload_packet_len == 23) && (memcmp(packet->payload, "<policy-file-request/>", 23) == 0)) { if((packet->payload_packet_len == 23) && (memcmp(packet->payload, "<policy-file-request/>", 23) == 0)) {
/* /*
<policy-file-request/> <policy-file-request/>
@@ -589,18 +613,18 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "Exclude HTTP\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude(flow); http_bitmask_exclude_other(flow);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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); ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->parsed_lines <= 1) { if(packet->parsed_lines <= 1) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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.ptr = packet->line[0].ptr;
@@ -611,7 +635,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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) if(packet->line[0].len >= (9 + filename_start)
@@ -643,6 +667,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
/* Check for additional field introduced by Steam */ /* Check for additional field introduced by Steam */
int x = 1; int x = 1;
if((memcmp(packet->line[x].ptr, "x-steam-sid", 11)) == 0) { if((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); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_STEAM);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
return; return;
@@ -652,6 +677,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
x = 1; x = 1;
while(packet->line[x].len != 0) { while(packet->line[x].len != 0) {
if(packet->line[x].len >= 12 && (memcmp(packet->line[x].ptr, "X-FB-SIM-HNI", 12)) == 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); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_FACEBOOK);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
return; return;
@@ -704,19 +730,19 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if((packet->http_url_name.len > 7) 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(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP_PROXY Found.\n"); NDPI_LOG_INFO(ndpi_struct, "found HTTP_PROXY\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_PROXY); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_PROXY);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
} }
if(filename_start == 8 && (memcmp(packet->payload, "CONNECT ", 8) == 0)) { if(filename_start == 8 && (memcmp(packet->payload, "CONNECT ", 8) == 0)) {
/* nathan@getoffmalawn.com */ /* nathan@getoffmalawn.com */
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP_CONNECT Found.\n"); NDPI_LOG_INFO(ndpi_struct, "found HTTP_CONNECT\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_CONNECT); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_CONNECT);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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) { if(packet->host_line.ptr != NULL) {
@@ -729,10 +755,11 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(ndpi_struct->http_dont_dissect_response) { if(ndpi_struct->http_dont_dissect_response) {
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) /* No subprotocol found */ 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 { } else {
flow->http_detected = 1; flow->http_detected = 1;
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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 flow->l4.tcp.http_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
} }
@@ -742,24 +769,27 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
} }
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP: REQUEST NOT HTTP CONFORM\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude(flow); http_bitmask_exclude_other(flow);
} else if((flow->l4.tcp.http_stage == 1) || (flow->l4.tcp.http_stage == 2)) { } else if((flow->l4.tcp.http_stage == 1) || (flow->l4.tcp.http_stage == 2)) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP stage %u: \n", NDPI_LOG_DBG2(ndpi_struct, "HTTP stage %u: \n", flow->l4.tcp.http_stage);
flow->l4.tcp.http_stage);
if((packet->payload_packet_len == 34) && (flow->l4.tcp.http_stage == 1)) {
if((packet->payload[5] == ' ') && (packet->payload[9] == ' ')) {
if(flow->l4.tcp.http_stage == 1) { ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA);
if((packet->payload_packet_len > 6) && memcmp(packet->payload, "HELLO ", 6) == 0) { return;
/* This looks like Ookla */ }
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
return;
} else
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OOKLA);
} }
if((packet->payload_packet_len > 6) && memcmp(packet->payload, "HELLO ", 6) == 0) {
/* This looks like Ookla */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_UNKNOWN);
return;
} else
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, 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 otherwise check the second packet for the HTTP request
@@ -769,7 +799,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(flow->http_detected) if(flow->http_detected)
return; return;
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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); ndpi_parse_packet_line_info(ndpi_struct, flow);
@@ -780,14 +810,13 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(packet->parsed_lines <= 1) { if(packet->parsed_lines <= 1) {
/* wait some packets in case request is split over more than 2 packets */ /* wait some packets in case request is split over more than 2 packets */
if(flow->packet_counter < 5) { if(flow->packet_counter < 5) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "line still not finished, search next packet\n");
"line still not finished, search next packet\n");
return; return;
} else { } else {
/* stop parsing here */ /* stop parsing here */
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "exclude HTTP: PACKET DOES NOT HAVE A LINE STRUCTURE\n");
"HTTP: PACKET DOES NOT HAVE A LINE STRUCTURE\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude(flow); http_bitmask_exclude_other(flow);
return; return;
} }
} }
@@ -795,11 +824,11 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(packet->line[0].len >= 9 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(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "Found HTTP.\n"); 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);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, 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; flow->http_detected = 1;
} }
@@ -817,15 +846,17 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
*/ */
if((packet->parsed_lines == 1) && (packet->packet_direction == 1 /* server -> client */)) { if((packet->parsed_lines == 1) && (packet->packet_direction == 1 /* server -> client */)) {
/* In Apache if you do "GET /\n\n" the response comes without any header */ /* In Apache if you do "GET /\n\n" the response comes without any header */
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "Found HTTP. (apache)\n"); NDPI_LOG_INFO(ndpi_struct, "found HTTP. (apache)\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP); ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_HTTP);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
return; return;
} }
/* If we already detected the HTTP request, we can add the connection and then check for the sub-protocol */ /* If we already detected the HTTP request, we can add the connection and then check for the sub-protocol */
if(flow->http_detected) if(flow->http_detected) {
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);
}
/* Parse packet line and we look for the subprotocols */ /* Parse packet line and we look for the subprotocols */
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
@@ -836,14 +867,13 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
} }
if(packet->empty_line_position_set != 0 || flow->l4.tcp.http_empty_line_seen == 1) { if(packet->empty_line_position_set != 0 || flow->l4.tcp.http_empty_line_seen == 1) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "empty line. check_http_payload.\n"); NDPI_LOG_DBG2(ndpi_struct, "empty line. check_http_payload\n");
check_http_payload(ndpi_struct, flow); check_http_payload(ndpi_struct, flow);
} }
flow->l4.tcp.http_stage = 0; flow->l4.tcp.http_stage = 0;
return; return;
} }
} }
void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct, void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
@@ -852,8 +882,8 @@ void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
/* Break after 20 packets. */ /* Break after 20 packets. */
if(flow->packet_counter > 20) { if(flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "Exclude HTTP.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude(flow); http_bitmask_exclude_other(flow);
return; return;
} }
@@ -861,7 +891,7 @@ void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "HTTP detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search HTTP\n");
ndpi_check_http_tcp(ndpi_struct, flow); ndpi_check_http_tcp(ndpi_struct, flow);
} }
+10 -5
View File
@@ -24,8 +24,14 @@
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC #ifdef NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC
#include "ndpi_api.h"
static void ndpi_int_activesync_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_activesync_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC, NDPI_PROTOCOL_HTTP); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC, NDPI_PROTOCOL_HTTP);
@@ -35,20 +41,19 @@ void ndpi_search_activesync(struct ndpi_detection_module_struct *ndpi_struct, st
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search activesync\n");
if (packet->tcp != NULL) { if (packet->tcp != NULL) {
if (packet->payload_packet_len > 150 if (packet->payload_packet_len > 150
&& ((memcmp(packet->payload, "OPTIONS /Microsoft-Server-ActiveSync?", 37) == 0) && ((memcmp(packet->payload, "OPTIONS /Microsoft-Server-ActiveSync?", 37) == 0)
|| (memcmp(packet->payload, "POST /Microsoft-Server-ActiveSync?", 34) == 0))) { || (memcmp(packet->payload, "POST /Microsoft-Server-ActiveSync?", 34) == 0))) {
ndpi_int_activesync_add_connection(ndpi_struct, flow); ndpi_int_activesync_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct, "found ActiveSync \n");
" flow marked as ActiveSync \n");
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC, ndpi_struct, NDPI_LOG_DEBUG, "exclude activesync\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC);
} }
+9 -7
View File
@@ -23,10 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_IAX #ifdef NDPI_PROTOCOL_IAX
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IAX
#include "ndpi_api.h"
#define NDPI_IAX_MAX_INFORMATION_ELEMENTS 15 #define NDPI_IAX_MAX_INFORMATION_ELEMENTS 15
static void ndpi_int_iax_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_iax_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -58,7 +63,7 @@ static void ndpi_search_setup_iax(struct ndpi_detection_module_struct *ndpi_stru
&& packet->payload[11] <= 15) { && packet->payload[11] <= 15) {
if (packet->payload_packet_len == 12) { if (packet->payload_packet_len == 12) {
NDPI_LOG(NDPI_PROTOCOL_IAX, ndpi_struct, NDPI_LOG_DEBUG, "found IAX.\n"); NDPI_LOG_INFO(ndpi_struct, "found IAX\n");
ndpi_int_iax_add_connection(ndpi_struct, flow); ndpi_int_iax_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -66,7 +71,7 @@ static void ndpi_search_setup_iax(struct ndpi_detection_module_struct *ndpi_stru
for (i = 0; i < NDPI_IAX_MAX_INFORMATION_ELEMENTS; i++) { for (i = 0; i < NDPI_IAX_MAX_INFORMATION_ELEMENTS; i++) {
packet_len = packet_len + 2 + packet->payload[packet_len + 1]; packet_len = packet_len + 2 + packet->payload[packet_len + 1];
if (packet_len == packet->payload_packet_len) { if (packet_len == packet->payload_packet_len) {
NDPI_LOG(NDPI_PROTOCOL_IAX, ndpi_struct, NDPI_LOG_DEBUG, "found IAX.\n"); NDPI_LOG_INFO(ndpi_struct, "found IAX\n");
ndpi_int_iax_add_connection(ndpi_struct, flow); ndpi_int_iax_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -77,16 +82,13 @@ static void ndpi_search_setup_iax(struct ndpi_detection_module_struct *ndpi_stru
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IAX); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
void ndpi_search_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_iax(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_flow_struct *flow=ndpi_struct->flow;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if(packet->udp if(packet->udp
&& (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)) && (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN))
+10 -8
View File
@@ -22,11 +22,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_ICECAST #ifdef NDPI_PROTOCOL_ICECAST
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_ICECAST
#include "ndpi_api.h"
static void ndpi_int_icecast_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_icecast_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ICECAST, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ICECAST, NDPI_PROTOCOL_UNKNOWN);
@@ -37,17 +40,17 @@ void ndpi_search_icecast_tcp(struct ndpi_detection_module_struct *ndpi_struct, s
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t i; u_int8_t i;
NDPI_LOG(NDPI_PROTOCOL_ICECAST, ndpi_struct, NDPI_LOG_DEBUG, "search icecast.\n"); NDPI_LOG_DBG(ndpi_struct, "search icecast\n");
if ((packet->payload_packet_len < 500 && if ((packet->payload_packet_len < 500 &&
packet->payload_packet_len >= 7 && memcmp(packet->payload, "SOURCE ", 7) == 0) packet->payload_packet_len >= 7 && memcmp(packet->payload, "SOURCE ", 7) == 0)
|| flow->l4.tcp.icecast_stage) { || flow->l4.tcp.icecast_stage) {
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_ICECAST, ndpi_struct, NDPI_LOG_DEBUG, "Icecast lines=%d\n", packet->parsed_lines); NDPI_LOG_DBG2(ndpi_struct, "Icecast lines=%d\n", packet->parsed_lines);
for (i = 0; i < packet->parsed_lines; i++) { for (i = 0; i < packet->parsed_lines; i++) {
if (packet->line[i].ptr != NULL && packet->line[i].len > 4 if (packet->line[i].ptr != NULL && packet->line[i].len > 4
&& memcmp(packet->line[i].ptr, "ice-", 4) == 0) { && memcmp(packet->line[i].ptr, "ice-", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_ICECAST, ndpi_struct, NDPI_LOG_DEBUG, "Icecast detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found Icecast\n");
ndpi_int_icecast_add_connection(ndpi_struct, flow); ndpi_int_icecast_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -75,18 +78,17 @@ void ndpi_search_icecast_tcp(struct ndpi_detection_module_struct *ndpi_struct, s
if (packet->server_line.ptr != NULL && packet->server_line.len > NDPI_STATICSTRING_LEN("Icecast") && if (packet->server_line.ptr != NULL && packet->server_line.len > NDPI_STATICSTRING_LEN("Icecast") &&
memcmp(packet->server_line.ptr, "Icecast", NDPI_STATICSTRING_LEN("Icecast")) == 0) { memcmp(packet->server_line.ptr, "Icecast", NDPI_STATICSTRING_LEN("Icecast")) == 0) {
NDPI_LOG(NDPI_PROTOCOL_ICECAST, ndpi_struct, NDPI_LOG_DEBUG, "Icecast detected.\n");
/* TODO maybe store the previous protocol type as subtype? /* TODO maybe store the previous protocol type as subtype?
* e.g. ogg or mpeg * e.g. ogg or mpeg
*/ */
NDPI_LOG_INFO(ndpi_struct, "found Icecast\n");
ndpi_int_icecast_add_connection(ndpi_struct, flow); ndpi_int_icecast_add_connection(ndpi_struct, flow);
return; return;
} }
} }
icecast_exclude: icecast_exclude:
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_ICECAST); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_ICECAST, ndpi_struct, NDPI_LOG_DEBUG, "Icecast excluded.\n");
} }
+18 -17
View File
@@ -22,11 +22,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_IPP #ifdef NDPI_PROTOCOL_IPP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IPP
#include "ndpi_api.h"
static void ndpi_int_ipp_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_ipp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow/* , ndpi_protocol_type_t protocol_type */) struct ndpi_flow_struct *flow/* , ndpi_protocol_type_t protocol_type */)
{ {
@@ -36,22 +40,20 @@ static void ndpi_int_ipp_add_connection(struct ndpi_detection_module_struct *ndp
void ndpi_search_ipp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_ipp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
u_int8_t i; u_int8_t i;
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "search ipp\n"); NDPI_LOG_DBG(ndpi_struct, "search ipp\n");
if (packet->payload_packet_len > 20) { if (packet->payload_packet_len > 20) {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"searching for a payload with a pattern like 'number(1to8)blanknumber(1to3)ipp://.\n"); "searching for a payload with a pattern like 'number(1to8)blanknumber(1to3)ipp://.\n");
/* this pattern means that there is a printer saying that his state is idle, /* this pattern means that there is a printer saying that his state is idle,
* means that he is not printing anything at the moment */ * means that he is not printing anything at the moment */
i = 0; i = 0;
if (packet->payload[i] < '0' || packet->payload[i] > '9') { if (packet->payload[i] < '0' || packet->payload[i] > '9') {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "payload does not begin with a number.\n"); NDPI_LOG_DBG2(ndpi_struct, "payload does not begin with a number\n");
goto search_for_next_pattern; goto search_for_next_pattern;
} }
@@ -60,37 +62,37 @@ void ndpi_search_ipp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
if (!((packet->payload[i] >= '0' && packet->payload[i] <= '9') || if (!((packet->payload[i] >= '0' && packet->payload[i] <= '9') ||
(packet->payload[i] >= 'a' && packet->payload[i] <= 'f') || (packet->payload[i] >= 'a' && packet->payload[i] <= 'f') ||
(packet->payload[i] >= 'A' && packet->payload[i] <= 'F')) || i > 8) { (packet->payload[i] >= 'A' && packet->payload[i] <= 'F')) || i > 8) {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"read symbols while the symbol is a number.\n"); "read symbols while the symbol is a number.\n");
break; break;
} }
} }
if (packet->payload[i++] != ' ') { if (packet->payload[i++] != ' ') {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "there is no blank following the number.\n"); NDPI_LOG_DBG2(ndpi_struct, "there is no blank following the number\n");
goto search_for_next_pattern; goto search_for_next_pattern;
} }
if (packet->payload[i] < '0' || packet->payload[i] > '9') { if (packet->payload[i] < '0' || packet->payload[i] > '9') {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "no number following the blank.\n"); NDPI_LOG_DBG2(ndpi_struct, "no number following the blank\n");
goto search_for_next_pattern; goto search_for_next_pattern;
} }
for (;;) { for (;;) {
i++; i++;
if (packet->payload[i] < '0' || packet->payload[i] > '9' || i > 12) { if (packet->payload[i] < '0' || packet->payload[i] > '9' || i > 12) {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"read symbols while the symbol is a number.\n"); "read symbols while the symbol is a number.\n");
break; break;
} }
} }
if (memcmp(&packet->payload[i], " ipp://", 7) != 0) { if (memcmp(&packet->payload[i], " ipp://", 7) != 0) {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "the string ' ipp://' does not follow.\n"); NDPI_LOG_DBG2(ndpi_struct, "the string ' ipp://' does not follow\n");
goto search_for_next_pattern; goto search_for_next_pattern;
} }
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "found ipp\n"); NDPI_LOG_INFO(ndpi_struct, "found ipp\n");
ndpi_int_ipp_add_connection(ndpi_struct, flow); ndpi_int_ipp_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -101,13 +103,12 @@ void ndpi_search_ipp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->content_line.ptr != NULL && packet->content_line.len > 14 if (packet->content_line.ptr != NULL && packet->content_line.len > 14
&& memcmp(packet->content_line.ptr, "application/ipp", 15) == 0) { && memcmp(packet->content_line.ptr, "application/ipp", 15) == 0) {
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "found ipp via POST ... application/ipp.\n"); NDPI_LOG_INFO(ndpi_struct, "found ipp via POST ... application/ipp\n");
ndpi_int_ipp_add_connection(ndpi_struct, flow); ndpi_int_ipp_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_IPP, ndpi_struct, NDPI_LOG_DEBUG, "no ipp detected.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IPP);
} }
+68 -91
View File
@@ -23,9 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_IRC #ifdef NDPI_PROTOCOL_IRC
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IRC
#include "ndpi_api.h"
#define NDPI_IRC_FIND_LESS(time_err,less) {int t1 = 0; \ #define NDPI_IRC_FIND_LESS(time_err,less) {int t1 = 0; \
u_int32_t timestamp = time_err[0]; \ u_int32_t timestamp = time_err[0]; \
for(t1=0;t1 < NDPI_PROTOCOL_IRC_MAXPORT;t1++) { \ for(t1=0;t1 < NDPI_PROTOCOL_IRC_MAXPORT;t1++) { \
@@ -39,8 +44,11 @@ static void ndpi_int_irc_add_connection(struct ndpi_detection_module_struct *ndp
} }
#if !defined(WIN32) #if !defined(WIN32)
static inline static inline
#elif defined(MINGW_GCC)
__mingw_forceinline static
#else #else
__forceinline static __forceinline static
#endif #endif
@@ -65,7 +73,7 @@ static u_int8_t ndpi_check_for_NOTICE_or_PRIVMSG(struct ndpi_detection_module_st
for (i = 0; i < packet->payload_packet_len - 7; i++) { for (i = 0; i < packet->payload_packet_len - 7; i++) {
if (packet->payload[i] == 'N' || packet->payload[i] == 'P') { if (packet->payload[i] == 'N' || packet->payload[i] == 'P') {
if (memcmp(&packet->payload[i + 1], "OTICE ", 6) == 0 || memcmp(&packet->payload[i + 1], "RIVMSG ", 7) == 0) { if (memcmp(&packet->payload[i + 1], "OTICE ", 6) == 0 || memcmp(&packet->payload[i + 1], "RIVMSG ", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "found NOTICE or PRIVMSG\n"); NDPI_LOG_DBG2(ndpi_struct, "found NOTICE or PRIVMSG\n");
return 1; return 1;
} }
} }
@@ -94,7 +102,7 @@ static u_int8_t ndpi_check_for_Nickname(struct ndpi_detection_module_struct *ndp
if ((((packetl - (i + 1)) >= 4) && memcmp(&packet->payload[i + 1], "ick=", 4) == 0) if ((((packetl - (i + 1)) >= 4) && memcmp(&packet->payload[i + 1], "ick=", 4) == 0)
|| (((packetl - (i + 1)) >= 8) && (memcmp(&packet->payload[i + 1], "ickname=", 8) == 0)) || (((packetl - (i + 1)) >= 8) && (memcmp(&packet->payload[i + 1], "ickname=", 8) == 0))
|| (((packetl - (i + 1)) >= 8) && (memcmp(&packet->payload[i + 1], "ickName=", 8) == 0))) { || (((packetl - (i + 1)) >= 8) && (memcmp(&packet->payload[i + 1], "ickName=", 8) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "found HTTP IRC Nickname pattern\n"); NDPI_LOG_DBG2(ndpi_struct, "found HTTP IRC Nickname pattern\n");
return 1; return 1;
} }
} }
@@ -114,7 +122,7 @@ static u_int8_t ndpi_check_for_cmd(struct ndpi_detection_module_struct *ndpi_str
for (i = 0; i < packet->payload_packet_len - 4; i++) { for (i = 0; i < packet->payload_packet_len - 4; i++) {
if (packet->payload[i] == 'c') { if (packet->payload[i] == 'c') {
if (memcmp(&packet->payload[i + 1], "md=", 3) == 0) { if (memcmp(&packet->payload[i + 1], "md=", 3) == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "found HTTP IRC cmd pattern \n"); NDPI_LOG_DBG2(ndpi_struct, "found HTTP IRC cmd pattern \n");
return 1; return 1;
} }
} }
@@ -147,8 +155,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG(ndpi_struct, "start fast detect\n");
"called ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast\n");
/* case 1: len 1460, len 1460, len 1176 several times in one direction, than len = 4, 4096, 8192 in the other direction */ /* case 1: len 1460, len 1460, len 1176 several times in one direction, than len = 4, 4096, 8192 in the other direction */
if (packet->payload_packet_len == 1460 if (packet->payload_packet_len == 1460
@@ -174,7 +181,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 0x1000 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 0x1000
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
0x2000)) { 0x2000)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1460,1460,1176,<-4096||8192"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1460,1460,1176,<-4096||8192");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -185,27 +192,27 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
1 + packet->packet_direction))) { 1 + packet->packet_direction))) {
flow->l4.tcp.irc_stage2 = 4; flow->l4.tcp.irc_stage2 = 4;
flow->l4.tcp.irc_direction = 1 + packet->packet_direction; flow->l4.tcp.irc_direction = 1 + packet->packet_direction;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "len = 1448 first\n"); NDPI_LOG_DBG2(ndpi_struct, "len = 1448 first\n");
return 1; return 1;
} }
if (packet->payload_packet_len == 1448 && flow->l4.tcp.irc_stage2 == 4 if (packet->payload_packet_len == 1448 && flow->l4.tcp.irc_stage2 == 4
&& flow->l4.tcp.irc_direction == 1 + packet->packet_direction) { && flow->l4.tcp.irc_direction == 1 + packet->packet_direction) {
flow->l4.tcp.irc_stage2 = 5; flow->l4.tcp.irc_stage2 = 5;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "len = 1448 second \n"); NDPI_LOG_DBG2(ndpi_struct, "len = 1448 second \n");
return 1; return 1;
} }
if (packet->payload_packet_len == 1200 && flow->l4.tcp.irc_stage2 == 5 if (packet->payload_packet_len == 1200 && flow->l4.tcp.irc_stage2 == 5
&& flow->l4.tcp.irc_direction == 1 + packet->packet_direction) { && flow->l4.tcp.irc_direction == 1 + packet->packet_direction) {
flow->l4.tcp.irc_stage2 = 6; flow->l4.tcp.irc_stage2 = 6;
flow->l4.tcp.irc_0x1000_full = 1; flow->l4.tcp.irc_0x1000_full = 1;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "len = 1200 \n"); NDPI_LOG_DBG2(ndpi_struct, "len = 1200 \n");
return 1; return 1;
} }
if (packet->payload_packet_len == 4 && (flow->l4.tcp.irc_stage2 == 6 || flow->l4.tcp.irc_0x1000_full == 1) if (packet->payload_packet_len == 4 && (flow->l4.tcp.irc_stage2 == 6 || flow->l4.tcp.irc_0x1000_full == 1)
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 0x1000 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 0x1000
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
0x2000)) { 0x2000)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1448,1448,1200,<-4096||8192"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1448,1448,1200,<-4096||8192");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -222,7 +229,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1380 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1380
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
2760)) { 2760)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1380,<-1380||2760"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1380,<-1380||2760");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -237,7 +244,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1200 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1200
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
2400)) { 2400)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1200,<-1200||2400"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1200,<-1200||2400");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -252,7 +259,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1024 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1024
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
2048)) { 2048)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1024,<-1024||2048"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1024,<-1024||2048");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -267,7 +274,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1248 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1248
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
2496)) { 2496)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1248,<-1248||2496"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1248,<-1248||2496");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -282,7 +289,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1448 && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && (ntohs(get_u_int16_t(packet->payload, 2)) == 1448
|| ntohs(get_u_int16_t(packet->payload, 2)) == || ntohs(get_u_int16_t(packet->payload, 2)) ==
2896)) { 2896)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1448,<-1448||2896"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1448,<-1448||2896");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -305,8 +312,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
if (packet->payload_packet_len == 4 if (packet->payload_packet_len == 4
&& flow->l4.tcp.irc_stage2 == 14 && flow->l4.tcp.irc_stage2 == 14
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && ntohs(get_u_int16_t(packet->payload, 2)) == 8192) { && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && ntohs(get_u_int16_t(packet->payload, 2)) == 8192) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1448,1448,1448,1448,1448,952,<-8192");
"IRC SSL detected: ->1448,1448,1448,1448,1448,952,<-8192");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -339,8 +345,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
if (packet->payload_packet_len == 4 if (packet->payload_packet_len == 4
&& flow->l4.tcp.irc_stage2 == 19 && flow->l4.tcp.irc_stage2 == 19
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && ntohs(get_u_int16_t(packet->payload, 2)) == 7168) { && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && ntohs(get_u_int16_t(packet->payload, 2)) == 7168) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1024,1448,1448,1200,1448,600,<-7168");
"IRC SSL detected: ->1024,1448,1448,1200,1448,600,<-7168");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
} }
@@ -353,7 +358,7 @@ u_int8_t ndpi_search_irc_ssl_detect_ninety_percent_but_very_fast(struct ndpi_det
if (packet->payload_packet_len == 4 if (packet->payload_packet_len == 4
&& flow->l4.tcp.irc_stage2 == 20 && flow->l4.tcp.irc_stage2 == 20
&& flow->l4.tcp.irc_direction == 2 - packet->packet_direction && ntohs(get_u_int16_t(packet->payload, 2)) == 2404) { && flow->l4.tcp.irc_direction == 2 - packet->packet_direction && ntohs(get_u_int16_t(packet->payload, 2)) == 2404) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC SSL detected: ->1024,1380 <-2404"); NDPI_LOG_INFO(ndpi_struct, "found IRC SSL: ->1024,1380 <-2404");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return 1; return 1;
@@ -382,26 +387,26 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
u_int16_t http_content_ptr_len = 0; u_int16_t http_content_ptr_len = 0;
u_int8_t space = 0; u_int8_t space = 0;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "irc : search irc\n"); NDPI_LOG_DBG(ndpi_struct, "search irc\n");
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_IRC && flow->packet_counter > 70) { if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_IRC && flow->packet_counter > 70) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "exclude irc, packet_counter > 70\n"); NDPI_LOG_DBG(ndpi_struct, "exclude irc, packet_counter > 70\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IRC); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IRC);
return; return;
} }
if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_IRC && flow->packet_counter > 30 && if (flow->detected_protocol_stack[0] != NDPI_PROTOCOL_IRC && flow->packet_counter > 30 &&
flow->l4.tcp.irc_stage2 == 0) { flow->l4.tcp.irc_stage2 == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "packet_counter > 30, exclude irc.\n"); NDPI_LOG_DBG(ndpi_struct, "exclude irc, packet_counter > 30\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IRC); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_IRC);
return; return;
} }
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_IRC) { if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_IRC) {
if (src != NULL && ((u_int32_t) if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->irc_ts) < ndpi_struct->irc_timeout)) { (packet->tick_timestamp - src->irc_ts) < ndpi_struct->irc_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "irc : save src connection packet detected\n"); NDPI_LOG_DBG2(ndpi_struct, "irc : save src connection packet detected\n");
src->irc_ts = packet->tick_timestamp; src->irc_ts = packet->tick_timestamp;
} else if (dst != NULL && ((u_int32_t) } else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->irc_ts) < ndpi_struct->irc_timeout)) { (packet->tick_timestamp - dst->irc_ts) < ndpi_struct->irc_timeout)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "irc : save dst connection packet detected\n"); NDPI_LOG_DBG2(ndpi_struct, "irc : save dst connection packet detected\n");
dst->irc_ts = packet->tick_timestamp; dst->irc_ts = packet->tick_timestamp;
} }
} }
@@ -423,8 +428,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
for (counter = 0; counter < dst->irc_number_of_port; counter++) { for (counter = 0; counter < dst->irc_number_of_port; counter++) {
if (dst->irc_port[counter] == sport || dst->irc_port[counter] == dport) { if (dst->irc_port[counter] == sport || dst->irc_port[counter] == dport) {
dst->last_time_port_used[counter] = packet->tick_timestamp; dst->last_time_port_used[counter] = packet->tick_timestamp;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found IRC: dest port matched with the DCC port");
"dest port matched with the DCC port and the flow is marked as IRC");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -434,9 +438,8 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
for (counter = 0; counter < src->irc_number_of_port; counter++) { for (counter = 0; counter < src->irc_number_of_port; counter++) {
if (src->irc_port[counter] == sport || src->irc_port[counter] == dport) { if (src->irc_port[counter] == sport || src->irc_port[counter] == dport) {
src->last_time_port_used[counter] = packet->tick_timestamp; src->last_time_port_used[counter] = packet->tick_timestamp;
NDPI_LOG_INFO(ndpi_struct, "found IRC: Source port matched with the DCC port");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE,
"Source port matched with the DCC port and the flow is marked as IRC");
return; return;
} }
} }
@@ -465,8 +468,8 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|| (memcmp(&packet->payload[c1], "irc.discostars.de1", 18) || (memcmp(&packet->payload[c1], "irc.discostars.de1", 18)
== 0) == 0)
|| (memcmp(&packet->payload[c1], "irc.rizon.net", 13) == 0)) { || (memcmp(&packet->payload[c1], "irc.rizon.net", 13) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct,
"IRC SSL detected with :- irc.hackthissite.org0 | irc.gamepad.ca1 | dungeon.axenet.org0 " "found IRC SSL: - irc.hackthissite.org0 | irc.gamepad.ca1 | dungeon.axenet.org0 "
"| dazed.nuggethaus.net | irc.indymedia.org | irc.discostars.de1 "); "| dazed.nuggethaus.net | irc.indymedia.org | irc.discostars.de1 ");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
break; break;
@@ -496,14 +499,14 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (packet->line[i].ptr[0] == ':') { if (packet->line[i].ptr[0] == ':') {
flow->l4.tcp.irc_3a_counter++; flow->l4.tcp.irc_3a_counter++;
if (flow->l4.tcp.irc_3a_counter == 7) { /* ':' == 0x3a */ if (flow->l4.tcp.irc_3a_counter == 7) { /* ':' == 0x3a */
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "0x3a. seven times. found irc."); NDPI_LOG_INFO(ndpi_struct, "found irc. 0x3a. seven times.");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
goto detected_irc; goto detected_irc;
} }
} }
} }
if (flow->l4.tcp.irc_3a_counter == 7) { /* ':' == 0x3a */ if (flow->l4.tcp.irc_3a_counter == 7) { /* ':' == 0x3a */
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "0x3a. seven times. found irc."); NDPI_LOG_INFO(ndpi_struct, "found irc. 0x3a. seven times.");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
goto detected_irc; goto detected_irc;
} }
@@ -518,19 +521,19 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|| (memcmp(packet->payload, "NOTICE ", 7) == 0) || (memcmp(packet->payload, "NOTICE ", 7) == 0)
|| (memcmp(packet->payload, "PRIVMSG ", 8) == 0) || (memcmp(packet->payload, "PRIVMSG ", 8) == 0)
|| (memcmp(packet->payload, "VERSION ", 8) == 0)) { || (memcmp(packet->payload, "VERSION ", 8) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct,
"USER, NICK, PASS, NOTICE, PRIVMSG one time"); "USER, NICK, PASS, NOTICE, PRIVMSG one time");
if (flow->l4.tcp.irc_stage == 2) { if (flow->l4.tcp.irc_stage == 2) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "found irc"); NDPI_LOG_INFO(ndpi_struct, "found irc");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
flow->l4.tcp.irc_stage = 3; flow->l4.tcp.irc_stage = 3;
} }
if (flow->l4.tcp.irc_stage == 1) { if (flow->l4.tcp.irc_stage == 1) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "second time, stage=2"); NDPI_LOG_DBG2(ndpi_struct, "second time, stage=2");
flow->l4.tcp.irc_stage = 2; flow->l4.tcp.irc_stage = 2;
} }
if (flow->l4.tcp.irc_stage == 0) { if (flow->l4.tcp.irc_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "first time, stage=1"); NDPI_LOG_DBG2(ndpi_struct, "first time, stage=1");
flow->l4.tcp.irc_stage = 1; flow->l4.tcp.irc_stage = 1;
} }
/* irc packets can have either windows line breaks (0d0a) or unix line breaks (0a) */ /* irc packets can have either windows line breaks (0d0a) or unix line breaks (0a) */
@@ -538,13 +541,11 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
&& packet->payload[packet->payload_packet_len - 1] == 0x0a) { && packet->payload[packet->payload_packet_len - 1] == 0x0a) {
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->parsed_lines > 1) { if (packet->parsed_lines > 1) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "packet contains more than one line");
"packet contains more than one line");
for (c = 1; c < packet->parsed_lines; c++) { for (c = 1; c < packet->parsed_lines; c++) {
if (packet->line[c].len > 4 && (memcmp(packet->line[c].ptr, "NICK ", 5) == 0 if (packet->line[c].len > 4 && (memcmp(packet->line[c].ptr, "NICK ", 5) == 0
|| memcmp(packet->line[c].ptr, "USER ", 5) == 0)) { || memcmp(packet->line[c].ptr, "USER ", 5) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found IRC: two icq signal words in the same packet");
NDPI_LOG_TRACE, "two icq signal words in the same packet");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
flow->l4.tcp.irc_stage = 3; flow->l4.tcp.irc_stage = 3;
return; return;
@@ -555,14 +556,12 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
} else if (packet->payload[packet->payload_packet_len - 1] == 0x0a) { } else if (packet->payload[packet->payload_packet_len - 1] == 0x0a) {
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct, flow);
if (packet->parsed_lines > 1) { if (packet->parsed_lines > 1) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "packet contains more than one line");
"packet contains more than one line");
for (c = 1; c < packet->parsed_lines; c++) { for (c = 1; c < packet->parsed_lines; c++) {
if (packet->line[c].len > 4 && (memcmp(packet->line[c].ptr, "NICK ", 5) == 0 if (packet->line[c].len > 4 && (memcmp(packet->line[c].ptr, "NICK ", 5) == 0
|| memcmp(packet->line[c].ptr, "USER ", || memcmp(packet->line[c].ptr, "USER ",
5) == 0)) { 5) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found IRC: two icq signal words in the same packet");
"two icq signal words in the same packet");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
flow->l4.tcp.irc_stage = 3; flow->l4.tcp.irc_stage = 3;
return; return;
@@ -594,7 +593,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
&& (ndpi_check_for_IRC_traces(packet->http_url_name.ptr, packet->http_url_name.len))) && (ndpi_check_for_IRC_traces(packet->http_url_name.ptr, packet->http_url_name.len)))
|| ((packet->referer_line.ptr) || ((packet->referer_line.ptr)
&& (ndpi_check_for_IRC_traces(packet->referer_line.ptr, packet->referer_line.len)))) { && (ndpi_check_for_IRC_traces(packet->referer_line.ptr, packet->referer_line.len)))) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct,
"IRC detected from the Http URL/ Referer header "); "IRC detected from the Http URL/ Referer header ");
flow->l4.tcp.irc_stage = 1; flow->l4.tcp.irc_stage = 1;
// HTTP POST Request body is not in the same packet. // HTTP POST Request body is not in the same packet.
@@ -613,22 +612,21 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|| (((packet->payload_packet_len - http_content_ptr_len) > 5) || (((packet->payload_packet_len - http_content_ptr_len) > 5)
&& (memcmp(packet->payload + http_content_ptr_len, "item=", 5) == 0) && (memcmp(packet->payload + http_content_ptr_len, "item=", 5) == 0)
&& (ndpi_check_for_cmd(ndpi_struct, flow) != 0))) { && (ndpi_check_for_cmd(ndpi_struct, flow) != 0))) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "IRC Nickname, cmd, one time"); NDPI_LOG_INFO(ndpi_struct, "found IRC: Nickname, cmd, one time");
ndpi_int_irc_add_connection(ndpi_struct, flow); ndpi_int_irc_add_connection(ndpi_struct, flow);
return; return;
} }
} }
detected_irc: detected_irc:
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "detected_irc:"); NDPI_LOG_DBG2(ndpi_struct, "detected_irc:");
if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_IRC) { if (flow->detected_protocol_stack[0] == NDPI_PROTOCOL_IRC) {
/* maybe this can be deleted at the end */ /* maybe this can be deleted at the end */
if (packet->payload[packet->payload_packet_len - 2] != 0x0d if (packet->payload[packet->payload_packet_len - 2] != 0x0d
&& packet->payload[packet->payload_packet_len - 1] == 0x0a) { && packet->payload[packet->payload_packet_len - 1] == 0x0a) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "ndpi_parse_packet_line_info_any(ndpi_struct, flow);");
"ndpi_parse_packet_line_info_any(ndpi_struct, flow);");
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct, flow);
} else if (packet->payload[packet->payload_packet_len - 2] == 0x0d) { } else if (packet->payload[packet->payload_packet_len - 2] == 0x0d) {
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
@@ -637,27 +635,27 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
} }
for (i = 0; i < packet->parsed_lines; i++) { for (i = 0; i < packet->parsed_lines; i++) {
if (packet->line[i].len > 6 && memcmp(packet->line[i].ptr, "NOTICE ", 7) == 0) { if (packet->line[i].len > 6 && memcmp(packet->line[i].ptr, "NOTICE ", 7) == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "NOTICE"); NDPI_LOG_DBG2(ndpi_struct, "NOTICE");
for (j = 7; j < packet->line[i].len - 8; j++) { for (j = 7; j < packet->line[i].len - 8; j++) {
if (packet->line[i].ptr[j] == ':') { if (packet->line[i].ptr[j] == ':') {
if (memcmp(&packet->line[i].ptr[j + 1], "DCC SEND ", 9) == 0 if (memcmp(&packet->line[i].ptr[j + 1], "DCC SEND ", 9) == 0
|| memcmp(&packet->line[i].ptr[j + 1], "DCC CHAT ", 9) == 0) { || memcmp(&packet->line[i].ptr[j + 1], "DCC CHAT ", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct,
"found NOTICE and DCC CHAT or DCC SEND."); "found NOTICE and DCC CHAT or DCC SEND.");
} }
} }
} }
} }
if (packet->payload_packet_len > 0 && packet->payload[0] == 0x3a /* 0x3a = ':' */ ) { if (packet->payload_packet_len > 0 && packet->payload[0] == 0x3a /* 0x3a = ':' */ ) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "3a"); NDPI_LOG_DBG2(ndpi_struct, "3a");
for (j = 1; j < packet->line[i].len - 9; j++) { for (j = 1; j < packet->line[i].len - 9; j++) {
if (packet->line[i].ptr[j] == ' ') { if (packet->line[i].ptr[j] == ' ') {
j++; j++;
if (packet->line[i].ptr[j] == 'P') { if (packet->line[i].ptr[j] == 'P') {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "P"); NDPI_LOG_DBG2(ndpi_struct, "P");
j++; j++;
if (memcmp(&packet->line[i].ptr[j], "RIVMSG ", 7) == 0) if (memcmp(&packet->line[i].ptr[j], "RIVMSG ", 7) == 0)
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "RIVMSG"); NDPI_LOG_DBG2(ndpi_struct, "RIVMSG");
h = j + 7; h = j + 7;
goto read_privmsg; goto read_privmsg;
} }
@@ -665,25 +663,24 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
} }
} }
if (packet->line[i].len > 7 && (memcmp(packet->line[i].ptr, "PRIVMSG ", 8) == 0)) { if (packet->line[i].len > 7 && (memcmp(packet->line[i].ptr, "PRIVMSG ", 8) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG, "PRIVMSG "); NDPI_LOG_DBG2(ndpi_struct, "PRIVMSG ");
h = 7; h = 7;
read_privmsg: read_privmsg:
for (j = h; j < packet->line[i].len - 9; j++) { for (j = h; j < packet->line[i].len - 9; j++) {
if (packet->line[i].ptr[j] == ':') { if (packet->line[i].ptr[j] == ':') {
if (memcmp(&packet->line[i].ptr[j + 1], "xdcc ", 5) == 0) { if (memcmp(&packet->line[i].ptr[j + 1], "xdcc ", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "xdcc should match."); NDPI_LOG_DBG2(ndpi_struct, "xdcc should match.");
} }
j += 2; j += 2;
if (memcmp(&packet->line[i].ptr[j], "DCC ", 4) == 0) { if (memcmp(&packet->line[i].ptr[j], "DCC ", 4) == 0) {
j += 4; j += 4;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "found DCC."); NDPI_LOG_DBG2(ndpi_struct, "found DCC.");
if (memcmp(&packet->line[i].ptr[j], "SEND ", 5) == 0 if (memcmp(&packet->line[i].ptr[j], "SEND ", 5) == 0
|| (memcmp(&packet->line[i].ptr[j], "CHAT", 4) == 0) || (memcmp(&packet->line[i].ptr[j], "CHAT", 4) == 0)
|| (memcmp(&packet->line[i].ptr[j], "chat", 4) == 0) || (memcmp(&packet->line[i].ptr[j], "chat", 4) == 0)
|| (memcmp(&packet->line[i].ptr[j], "sslchat", 7) == 0) || (memcmp(&packet->line[i].ptr[j], "sslchat", 7) == 0)
|| (memcmp(&packet->line[i].ptr[j], "TSEND", 5) == 0)) { || (memcmp(&packet->line[i].ptr[j], "TSEND", 5) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "found CHAT,chat,sslchat,TSEND.");
"found CHAT,chat,sslchat,TSEND.");
j += 4; j += 4;
while (packet->line[i].len > j && while (packet->line[i].len > j &&
@@ -696,35 +693,29 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (packet->line[i].ptr[j] == ' ') { if (packet->line[i].ptr[j] == ' ') {
space++; space++;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "space %u.", space); NDPI_LOG_DBG2(ndpi_struct, "space %u.", space);
} }
if (space == 3) { if (space == 3) {
j++; j++;
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "read port."); NDPI_LOG_DBG2(ndpi_struct, "read port.");
if (src != NULL) { if (src != NULL) {
k = j; k = j;
port = port =
ntohs_ndpi_bytestream_to_number ntohs_ndpi_bytestream_to_number
(&packet->line[i].ptr[j], packet->payload_packet_len - j, &j); (&packet->line[i].ptr[j], packet->payload_packet_len - j, &j);
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "port %u.", NDPI_LOG_DBG2(ndpi_struct, "port %u.",
port); port);
j = k; j = k;
// hier jetzt überlegen, wie die ports abgespeichert werden sollen // hier jetzt überlegen, wie die ports abgespeichert werden sollen
if (src->irc_number_of_port < NDPI_PROTOCOL_IRC_MAXPORT) if (src->irc_number_of_port < NDPI_PROTOCOL_IRC_MAXPORT)
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "src->irc_number_of_port < NDPI_PROTOCOL_IRC_MAXPORT.");
"src->irc_number_of_port < NDPI_PROTOCOL_IRC_MAXPORT.");
if (src->irc_number_of_port < NDPI_PROTOCOL_IRC_MAXPORT && port != 0) { if (src->irc_number_of_port < NDPI_PROTOCOL_IRC_MAXPORT && port != 0) {
if (!ndpi_is_duplicate(src, port)) { if (!ndpi_is_duplicate(src, port)) {
src->irc_port[src->irc_number_of_port] src->irc_port[src->irc_number_of_port]
= port; = port;
src->irc_number_of_port++; src->irc_number_of_port++;
NDPI_LOG NDPI_LOG_DBG2(ndpi_struct, "found port=%d jjeeeeeeeeeeeeeeeeeeeeeeeee",
(NDPI_PROTOCOL_IRC,
ndpi_struct,
NDPI_LOG_DEBUG, "found port=%d",
ntohs(get_u_int16_t(src->irc_port, 0))); ntohs(get_u_int16_t(src->irc_port, 0)));
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG,
"jjeeeeeeeeeeeeeeeeeeeeeeeee");
} }
src->irc_ts = packet->tick_timestamp; src->irc_ts = packet->tick_timestamp;
} else if (port != 0 && src->irc_number_of_port == NDPI_PROTOCOL_IRC_MAXPORT) { } else if (port != 0 && src->irc_number_of_port == NDPI_PROTOCOL_IRC_MAXPORT) {
@@ -732,11 +723,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
less = 0; less = 0;
NDPI_IRC_FIND_LESS(src->last_time_port_used, less); NDPI_IRC_FIND_LESS(src->last_time_port_used, less);
src->irc_port[less] = port; src->irc_port[less] = port;
NDPI_LOG NDPI_LOG_DBG2(ndpi_struct, "found port=%d", ntohs(get_u_int16_t(src->irc_port, 0)));
(NDPI_PROTOCOL_IRC,
ndpi_struct,
NDPI_LOG_DEBUG, "found port=%d",
ntohs(get_u_int16_t(src->irc_port, 0)));
} }
src->irc_ts = packet->tick_timestamp; src->irc_ts = packet->tick_timestamp;
} }
@@ -747,8 +734,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (dst != NULL) { if (dst != NULL) {
port = ntohs_ndpi_bytestream_to_number port = ntohs_ndpi_bytestream_to_number
(&packet->line[i].ptr[j], packet->payload_packet_len - j, &j); (&packet->line[i].ptr[j], packet->payload_packet_len - j, &j);
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_TRACE, "port %u.", NDPI_LOG_DBG2(ndpi_struct, "port %u.", port);
port);
// hier das gleiche wie oben. // hier das gleiche wie oben.
/* hier werden NDPI_PROTOCOL_IRC_MAXPORT ports pro irc flows mitgespeichert. könnte man denn nicht ein- /* hier werden NDPI_PROTOCOL_IRC_MAXPORT ports pro irc flows mitgespeichert. könnte man denn nicht ein-
* fach an die dst oder src einen flag setzten, dass dieser port für eine bestimmte * fach an die dst oder src einen flag setzten, dass dieser port für eine bestimmte
@@ -759,13 +745,8 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
dst->irc_port[dst->irc_number_of_port] dst->irc_port[dst->irc_number_of_port]
= port; = port;
dst->irc_number_of_port++; dst->irc_number_of_port++;
NDPI_LOG NDPI_LOG_DBG2(ndpi_struct, "found port=%d", ntohs(get_u_int16_t(dst->irc_port, 0)));
(NDPI_PROTOCOL_IRC, NDPI_LOG_DBG2(ndpi_struct, "juuuuuuuuuuuuuuuu");
ndpi_struct,
NDPI_LOG_DEBUG, "found port=%d",
ntohs(get_u_int16_t(dst->irc_port, 0)));
NDPI_LOG(NDPI_PROTOCOL_IRC, ndpi_struct, NDPI_LOG_DEBUG,
"juuuuuuuuuuuuuuuu");
} }
dst->irc_ts = packet->tick_timestamp; dst->irc_ts = packet->tick_timestamp;
} else if (port != 0 && dst->irc_number_of_port == NDPI_PROTOCOL_IRC_MAXPORT) { } else if (port != 0 && dst->irc_number_of_port == NDPI_PROTOCOL_IRC_MAXPORT) {
@@ -774,11 +755,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
NDPI_IRC_FIND_LESS(dst->last_time_port_used, less); NDPI_IRC_FIND_LESS(dst->last_time_port_used, less);
dst->irc_port[less] = port; dst->irc_port[less] = port;
NDPI_LOG NDPI_LOG_DBG2(ndpi_struct, "found port=%d", ntohs(get_u_int16_t(dst->irc_port, 0)));
(NDPI_PROTOCOL_IRC,
ndpi_struct,
NDPI_LOG_DEBUG, "found port=%d",
ntohs(get_u_int16_t(dst->irc_port, 0)));
} }
dst->irc_ts = packet->tick_timestamp; dst->irc_ts = packet->tick_timestamp;
} }
+42 -52
View File
@@ -22,10 +22,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_UNENCRYPTED_JABBER
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNENCRYPTED_JABBER
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_UNENCRYPTED_JABBER
struct jabber_string { struct jabber_string {
char *string; char *string;
u_int ndpi_protocol; u_int ndpi_protocol;
@@ -70,51 +74,47 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
u_int16_t x; u_int16_t x;
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_TRACE, "JABBER detection....\n"); NDPI_LOG_DBG(ndpi_struct, "search JABBER\n");
/* search for jabber file transfer */ /* search for jabber file transfer */
/* this part is working asymmetrically */ /* this part is working asymmetrically */
if (packet->tcp != NULL && packet->tcp->syn != 0 && packet->payload_packet_len == 0) { if (packet->tcp != NULL && packet->tcp->syn != 0 && packet->payload_packet_len == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "check jabber syn\n"); NDPI_LOG_DBG2(ndpi_struct, "check jabber syn\n");
if (src != NULL && src->jabber_file_transfer_port[0] != 0) { if (src != NULL && src->jabber_file_transfer_port[0] != 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "src jabber ft port set, ports are: %u, %u\n",
"src jabber ft port set, ports are: %u, %u\n", ntohs(src->jabber_file_transfer_port[0]), ntohs(src->jabber_file_transfer_port[0]),
ntohs(src->jabber_file_transfer_port[1])); ntohs(src->jabber_file_transfer_port[1]));
if (((u_int32_t) if (((u_int32_t)
(packet->tick_timestamp - src->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) { (packet->tick_timestamp - src->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "JABBER src stun timeout %u %u\n",
NDPI_LOG_DEBUG, "JABBER src stun timeout %u %u\n", src->jabber_stun_or_ft_ts, src->jabber_stun_or_ft_ts, packet->tick_timestamp);
packet->tick_timestamp);
src->jabber_file_transfer_port[0] = 0; src->jabber_file_transfer_port[0] = 0;
src->jabber_file_transfer_port[1] = 0; src->jabber_file_transfer_port[1] = 0;
} else if (src->jabber_file_transfer_port[0] == packet->tcp->dest } else if (src->jabber_file_transfer_port[0] == packet->tcp->dest
|| src->jabber_file_transfer_port[0] == packet->tcp->source || src->jabber_file_transfer_port[0] == packet->tcp->source
|| src->jabber_file_transfer_port[1] == packet->tcp->dest || src->jabber_file_transfer_port[1] == packet->tcp->dest
|| src->jabber_file_transfer_port[1] == packet->tcp->source) { || src->jabber_file_transfer_port[1] == packet->tcp->source) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct, "found jabber file transfer\n");
"found jabber file transfer.\n");
ndpi_int_jabber_add_connection(ndpi_struct, flow, ndpi_int_jabber_add_connection(ndpi_struct, flow,
NDPI_PROTOCOL_UNENCRYPTED_JABBER); NDPI_PROTOCOL_UNENCRYPTED_JABBER);
} }
} }
if (dst != NULL && dst->jabber_file_transfer_port[0] != 0) { if (dst != NULL && dst->jabber_file_transfer_port[0] != 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "dst jabber ft port set, ports are: %u, %u\n",
"dst jabber ft port set, ports are: %u, %u\n", ntohs(dst->jabber_file_transfer_port[0]), ntohs(dst->jabber_file_transfer_port[0]),
ntohs(dst->jabber_file_transfer_port[1])); ntohs(dst->jabber_file_transfer_port[1]));
if (((u_int32_t) if (((u_int32_t)
(packet->tick_timestamp - dst->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) { (packet->tick_timestamp - dst->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "JABBER dst stun timeout %u %u\n",
NDPI_LOG_DEBUG, "JABBER dst stun timeout %u %u\n", dst->jabber_stun_or_ft_ts, dst->jabber_stun_or_ft_ts, packet->tick_timestamp);
packet->tick_timestamp);
dst->jabber_file_transfer_port[0] = 0; dst->jabber_file_transfer_port[0] = 0;
dst->jabber_file_transfer_port[1] = 0; dst->jabber_file_transfer_port[1] = 0;
} else if (dst->jabber_file_transfer_port[0] == packet->tcp->dest } else if (dst->jabber_file_transfer_port[0] == packet->tcp->dest
|| dst->jabber_file_transfer_port[0] == packet->tcp->source || dst->jabber_file_transfer_port[0] == packet->tcp->source
|| dst->jabber_file_transfer_port[1] == packet->tcp->dest || dst->jabber_file_transfer_port[1] == packet->tcp->dest
|| dst->jabber_file_transfer_port[1] == packet->tcp->source) { || dst->jabber_file_transfer_port[1] == packet->tcp->source) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct, "found jabber file transfer\n");
"found jabber file transfer.\n");
ndpi_int_jabber_add_connection(ndpi_struct, flow, ndpi_int_jabber_add_connection(ndpi_struct, flow,
NDPI_PROTOCOL_UNENCRYPTED_JABBER); NDPI_PROTOCOL_UNENCRYPTED_JABBER);
@@ -135,17 +135,17 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
/* check for google jabber voip connections ... */ /* check for google jabber voip connections ... */
/* need big packet */ /* need big packet */
if (packet->payload_packet_len < 100) { if (packet->payload_packet_len < 100) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "packet too small, return.\n"); NDPI_LOG_DBG2(ndpi_struct, "packet too small, return\n");
return; return;
} }
/* need message to or type for file-transfer */ /* need message to or type for file-transfer */
if (memcmp(packet->payload, "<iq from=\"", 8) == 0 || memcmp(packet->payload, "<iq from=\'", 8) == 0) { if (memcmp(packet->payload, "<iq from=\"", 8) == 0 || memcmp(packet->payload, "<iq from=\'", 8) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "JABBER <iq from=\".\n"); NDPI_LOG_DBG2(ndpi_struct, "JABBER <iq from=\"\n");
lastlen = packet->payload_packet_len - 11; lastlen = packet->payload_packet_len - 11;
for (x = 10; x < lastlen; x++) { for (x = 10; x < lastlen; x++) {
if (packet->payload[x] == 'p') { if (packet->payload[x] == 'p') {
if (memcmp(&packet->payload[x], "port=", 5) == 0) { if (memcmp(&packet->payload[x], "port=", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "port=\n"); NDPI_LOG_DBG2(ndpi_struct, "port=\n");
if (src != NULL) { if (src != NULL) {
src->jabber_stun_or_ft_ts = packet->tick_timestamp; src->jabber_stun_or_ft_ts = packet->tick_timestamp;
} }
@@ -155,30 +155,25 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
} }
x += 6; x += 6;
j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x); j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x);
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "JABBER port : %u\n", ntohs(j_port));
NDPI_LOG_DEBUG, "JABBER port : %u\n", ntohs(j_port));
if (src != NULL) { if (src != NULL) {
if (src->jabber_file_transfer_port[0] == 0 || src->jabber_file_transfer_port[0] == j_port) { if (src->jabber_file_transfer_port[0] == 0 || src->jabber_file_transfer_port[0] == j_port) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[0] = j_port = %u;\n",
NDPI_LOG_DEBUG, "src->jabber_file_transfer_port[0] = j_port = %u;\n",
ntohs(j_port)); ntohs(j_port));
src->jabber_file_transfer_port[0] = j_port; src->jabber_file_transfer_port[0] = j_port;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
NDPI_LOG_DEBUG, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
ntohs(j_port)); ntohs(j_port));
src->jabber_file_transfer_port[1] = j_port; src->jabber_file_transfer_port[1] = j_port;
} }
} }
if (dst != NULL) { if (dst != NULL) {
if (dst->jabber_file_transfer_port[0] == 0 || dst->jabber_file_transfer_port[0] == j_port) { if (dst->jabber_file_transfer_port[0] == 0 || dst->jabber_file_transfer_port[0] == j_port) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[0] = j_port = %u;\n",
NDPI_LOG_DEBUG, "dst->jabber_file_transfer_port[0] = j_port = %u;\n",
ntohs(j_port)); ntohs(j_port));
dst->jabber_file_transfer_port[0] = j_port; dst->jabber_file_transfer_port[0] = j_port;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
NDPI_LOG_DEBUG, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
ntohs(j_port)); ntohs(j_port));
dst->jabber_file_transfer_port[1] = j_port; dst->jabber_file_transfer_port[1] = j_port;
} }
@@ -191,7 +186,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
} else if (memcmp(packet->payload, "<iq to=\"", 8) == 0 || memcmp(packet->payload, "<iq to=\'", 8) == 0 } else if (memcmp(packet->payload, "<iq to=\"", 8) == 0 || memcmp(packet->payload, "<iq to=\'", 8) == 0
|| memcmp(packet->payload, "<iq type=", 9) == 0) { || memcmp(packet->payload, "<iq type=", 9) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "JABBER <iq to=\"/type=\"\n"); NDPI_LOG_DBG2(ndpi_struct, "JABBER <iq to=\"/type=\"\n");
lastlen = packet->payload_packet_len - 21; lastlen = packet->payload_packet_len - 21;
for (x = 8; x < lastlen; x++) { for (x = 8; x < lastlen; x++) {
/* invalid character */ /* invalid character */
@@ -199,7 +194,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
return; return;
} }
if (packet->payload[x] == '@') { if (packet->payload[x] == '@') {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "JABBER @\n"); NDPI_LOG_DBG2(ndpi_struct, "JABBER @\n");
break; break;
} }
} }
@@ -211,7 +206,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
for (; x < lastlen; x++) { for (; x < lastlen; x++) {
if (packet->payload[x] == 'p') { if (packet->payload[x] == 'p') {
if (memcmp(&packet->payload[x], "port=", 5) == 0) { if (memcmp(&packet->payload[x], "port=", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, "port=\n"); NDPI_LOG_DBG2(ndpi_struct, "port=\n");
if (src != NULL) { if (src != NULL) {
src->jabber_stun_or_ft_ts = packet->tick_timestamp; src->jabber_stun_or_ft_ts = packet->tick_timestamp;
} }
@@ -222,8 +217,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
x += 6; x += 6;
j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x); j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x);
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "JABBER port : %u\n", ntohs(j_port));
NDPI_LOG_DEBUG, "JABBER port : %u\n", ntohs(j_port));
if (src != NULL && src->jabber_voice_stun_used_ports < JABBER_MAX_STUN_PORTS - 1) { if (src != NULL && src->jabber_voice_stun_used_ports < JABBER_MAX_STUN_PORTS - 1) {
if (packet->payload[5] == 'o') { if (packet->payload[5] == 'o') {
@@ -232,13 +226,12 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
} else { } else {
if (src->jabber_file_transfer_port[0] == 0 if (src->jabber_file_transfer_port[0] == 0
|| src->jabber_file_transfer_port[0] == j_port) { || src->jabber_file_transfer_port[0] == j_port) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[0] = j_port = %u;\n",
"src->jabber_file_transfer_port[0] = j_port = %u;\n", ntohs(j_port)); ntohs(j_port));
src->jabber_file_transfer_port[0] = j_port; src->jabber_file_transfer_port[0] = j_port;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "src->jabber_file_transfer_port[1] = j_port = %u;\n",
NDPI_LOG_DEBUG, "src->jabber_file_transfer_port[1] = j_port = %u;\n", ntohs(j_port));
ntohs(j_port));
src->jabber_file_transfer_port[1] = j_port; src->jabber_file_transfer_port[1] = j_port;
} }
} }
@@ -251,13 +244,12 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
} else { } else {
if (dst->jabber_file_transfer_port[0] == 0 if (dst->jabber_file_transfer_port[0] == 0
|| dst->jabber_file_transfer_port[0] == j_port) { || dst->jabber_file_transfer_port[0] == j_port) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[0] = j_port = %u;\n",
"dst->jabber_file_transfer_port[0] = j_port = %u;\n", ntohs(j_port)); ntohs(j_port));
dst->jabber_file_transfer_port[0] = j_port; dst->jabber_file_transfer_port[0] = j_port;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "dst->jabber_file_transfer_port[1] = j_port = %u;\n",
NDPI_LOG_DEBUG, "dst->jabber_file_transfer_port[1] = j_port = %u;\n", ntohs(j_port));
ntohs(j_port));
dst->jabber_file_transfer_port[1] = j_port; dst->jabber_file_transfer_port[1] = j_port;
} }
} }
@@ -291,16 +283,14 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
} }
if (flow->packet_counter < 3) { if (flow->packet_counter < 3) {
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "packet_counter: %u\n", flow->packet_counter);
NDPI_LOG_DEBUG, "packet_counter: %u\n", flow->packet_counter);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_UNENCRYPTED_JABBER, ndpi_struct, NDPI_LOG_TRACE, "JABBER Excluded.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_UNENCRYPTED_JABBER);
#ifdef NDPI_PROTOCOL_TRUPHONE #ifdef NDPI_PROTOCOL_TRUPHONE
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_TRUPHONE); ndpi_exclude_protocol(ndpi_struct, flow, NDPI_PROTOCOL_TRUPHONE,__FILE__,__FUNCTION__,__LINE__);
#endif #endif
} }
+10 -3
View File
@@ -24,13 +24,20 @@
http://www.kakao.com/services/talk/voices http://www.kakao.com/services/talk/voices
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_KAKAOTALK_VOICE
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_KAKAOTALK_VOICE
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_KAKAOTALK_VOICE
void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search kakaotalk_voice\n");
if(packet->iph if(packet->iph
&& packet->udp && packet->udp
&& (packet->payload_packet_len >= 4) && (packet->payload_packet_len >= 4)
@@ -48,14 +55,14 @@ void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struc
if(((ntohl(packet->iph->saddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0x01C90000 /* 1.201.0.0/16 */) if(((ntohl(packet->iph->saddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0x01C90000 /* 1.201.0.0/16 */)
|| ((ntohl(packet->iph->daddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0x01C90000 /* 1.201.0.0/16 */)) { || ((ntohl(packet->iph->daddr) & 0xFFFF0000 /* 255.255.0.0 */) == 0x01C90000 /* 1.201.0.0/16 */)) {
NDPI_LOG_INFO(ndpi_struct, "found kakaotalk_voice\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KAKAOTALK_VOICE, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KAKAOTALK_VOICE, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_KAKAOTALK_VOICE, ndpi_struct, NDPI_LOG_DEBUG, "Exclude kakaotalk_voice.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_KAKAOTALK_VOICE);
} }
+10 -13
View File
@@ -22,24 +22,28 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_KERBEROS #ifdef NDPI_PROTOCOL_KERBEROS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_KERBEROS
#include "ndpi_api.h"
static void ndpi_int_kerberos_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_kerberos_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KERBEROS, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KERBEROS, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_DBG(ndpi_struct, "trace KERBEROS\n");
} }
void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG_DBG(ndpi_struct, "search KERBEROS\n");
/* I have observed 0a,0c,0d,0e at packet->payload[19/21], maybe there are other possibilities */ /* I have observed 0a,0c,0d,0e at packet->payload[19/21], maybe there are other possibilities */
if (packet->payload_packet_len >= 4 && ntohl(get_u_int32_t(packet->payload, 0)) == packet->payload_packet_len - 4) { if (packet->payload_packet_len >= 4 && ntohl(get_u_int32_t(packet->payload, 0)) == packet->payload_packet_len - 4) {
@@ -47,7 +51,6 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct, stru
packet->payload[14] == 0x05 && packet->payload[14] == 0x05 &&
(packet->payload[19] == 0x0a || (packet->payload[19] == 0x0a ||
packet->payload[19] == 0x0c || packet->payload[19] == 0x0d || packet->payload[19] == 0x0e)) { packet->payload[19] == 0x0c || packet->payload[19] == 0x0d || packet->payload[19] == 0x0e)) {
NDPI_LOG(NDPI_PROTOCOL_KERBEROS, ndpi_struct, NDPI_LOG_DEBUG, "found KERBEROS\n");
ndpi_int_kerberos_add_connection(ndpi_struct, flow); ndpi_int_kerberos_add_connection(ndpi_struct, flow);
return; return;
@@ -56,18 +59,12 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct, stru
packet->payload[16] == 0x05 && packet->payload[16] == 0x05 &&
(packet->payload[21] == 0x0a || (packet->payload[21] == 0x0a ||
packet->payload[21] == 0x0c || packet->payload[21] == 0x0d || packet->payload[21] == 0x0e)) { packet->payload[21] == 0x0c || packet->payload[21] == 0x0d || packet->payload[21] == 0x0e)) {
NDPI_LOG(NDPI_PROTOCOL_KERBEROS, ndpi_struct, NDPI_LOG_DEBUG, "found KERBEROS\n");
ndpi_int_kerberos_add_connection(ndpi_struct, flow); ndpi_int_kerberos_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_KERBEROS, ndpi_struct, NDPI_LOG_DEBUG, "no KERBEROS detected.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_KERBEROS);
} }
+10 -8
View File
@@ -23,44 +23,46 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_KONTIKI #ifdef NDPI_PROTOCOL_KONTIKI
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_KONTIKI
#include "ndpi_api.h"
static void ndpi_int_kontiki_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_kontiki_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KONTIKI, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_KONTIKI, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_INFO(ndpi_struct, "found Kontiki UDP\n");
} }
void ndpi_search_kontiki(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_kontiki(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search Kontiki\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (packet->payload_packet_len == 4 && (get_u_int32_t(packet->payload, 0) == htonl(0x02010100))) { if (packet->payload_packet_len == 4 && (get_u_int32_t(packet->payload, 0) == htonl(0x02010100))) {
NDPI_LOG(NDPI_PROTOCOL_KONTIKI, ndpi_struct, NDPI_LOG_DEBUG, "Kontiki UDP detected.\n");
ndpi_int_kontiki_add_connection(ndpi_struct, flow); ndpi_int_kontiki_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len > 0 && packet->payload[0] == 0x02) { if (packet->payload_packet_len > 0 && packet->payload[0] == 0x02) {
if (packet->payload_packet_len == 20 && (get_u_int32_t(packet->payload, 16) == htonl(0x02040100))) { if (packet->payload_packet_len == 20 && (get_u_int32_t(packet->payload, 16) == htonl(0x02040100))) {
NDPI_LOG(NDPI_PROTOCOL_KONTIKI, ndpi_struct, NDPI_LOG_DEBUG, "Kontiki UDP detected.\n");
ndpi_int_kontiki_add_connection(ndpi_struct, flow); ndpi_int_kontiki_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len == 16 && (get_u_int32_t(packet->payload, 12) == htonl(0x000004e4))) { if (packet->payload_packet_len == 16 && (get_u_int32_t(packet->payload, 12) == htonl(0x000004e4))) {
NDPI_LOG(NDPI_PROTOCOL_KONTIKI, ndpi_struct, NDPI_LOG_DEBUG, "Kontiki UDP detected.\n");
ndpi_int_kontiki_add_connection(ndpi_struct, flow); ndpi_int_kontiki_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_KONTIKI); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+12 -17
View File
@@ -22,11 +22,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_LDAP #ifdef NDPI_PROTOCOL_LDAP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_LDAP
#include "ndpi_api.h"
static void ndpi_int_ldap_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_ldap_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
@@ -37,15 +41,7 @@ void ndpi_search_ldap(struct ndpi_detection_module_struct *ndpi_struct, struct n
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search ldap\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
// u_int16_t dport;
NDPI_LOG(NDPI_PROTOCOL_LDAP, ndpi_struct, NDPI_LOG_DEBUG, "search ldap\n");
if (packet->payload_packet_len >= 14 && packet->payload[0] == 0x30) { if (packet->payload_packet_len >= 14 && packet->payload[0] == 0x30) {
@@ -55,14 +51,14 @@ void ndpi_search_ldap(struct ndpi_detection_module_struct *ndpi_struct, struct n
if (packet->payload[3] == 0x01 && if (packet->payload[3] == 0x01 &&
(packet->payload[5] == 0x60 || packet->payload[5] == 0x61) && packet->payload[6] == 0x07) { (packet->payload[5] == 0x60 || packet->payload[5] == 0x61) && packet->payload[6] == 0x07) {
NDPI_LOG(NDPI_PROTOCOL_LDAP, ndpi_struct, NDPI_LOG_DEBUG, "found ldap simple type 1\n"); NDPI_LOG_INFO(ndpi_struct, "found ldap simple type 1\n");
ndpi_int_ldap_add_connection(ndpi_struct, flow); ndpi_int_ldap_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload[3] == 0x02 && if (packet->payload[3] == 0x02 &&
(packet->payload[6] == 0x60 || packet->payload[6] == 0x61) && packet->payload[7] == 0x07) { (packet->payload[6] == 0x60 || packet->payload[6] == 0x61) && packet->payload[7] == 0x07) {
NDPI_LOG(NDPI_PROTOCOL_LDAP, ndpi_struct, NDPI_LOG_DEBUG, "found ldap simple type 2\n"); NDPI_LOG_INFO(ndpi_struct, "found ldap simple type 2\n");
ndpi_int_ldap_add_connection(ndpi_struct, flow); ndpi_int_ldap_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -75,7 +71,7 @@ void ndpi_search_ldap(struct ndpi_detection_module_struct *ndpi_struct, struct n
(packet->payload[9] == 0x60 || packet->payload[9] == 0x61 || packet->payload[9] == 0x63 || (packet->payload[9] == 0x60 || packet->payload[9] == 0x61 || packet->payload[9] == 0x63 ||
packet->payload[9] == 0x64) && packet->payload[10] == 0x84) { packet->payload[9] == 0x64) && packet->payload[10] == 0x84) {
NDPI_LOG(NDPI_PROTOCOL_LDAP, ndpi_struct, NDPI_LOG_DEBUG, "found ldap type 1\n"); NDPI_LOG_INFO(ndpi_struct, "found ldap type 1\n");
ndpi_int_ldap_add_connection(ndpi_struct, flow); ndpi_int_ldap_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -84,7 +80,7 @@ void ndpi_search_ldap(struct ndpi_detection_module_struct *ndpi_struct, struct n
(packet->payload[10] == 0x60 || packet->payload[10] == 0x61 || packet->payload[10] == 0x63 || (packet->payload[10] == 0x60 || packet->payload[10] == 0x61 || packet->payload[10] == 0x63 ||
packet->payload[10] == 0x64) && packet->payload[11] == 0x84) { packet->payload[10] == 0x64) && packet->payload[11] == 0x84) {
NDPI_LOG(NDPI_PROTOCOL_LDAP, ndpi_struct, NDPI_LOG_DEBUG, "found ldap type 2\n"); NDPI_LOG_INFO(ndpi_struct, "found ldap type 2\n");
ndpi_int_ldap_add_connection(ndpi_struct, flow); ndpi_int_ldap_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -92,8 +88,7 @@ void ndpi_search_ldap(struct ndpi_detection_module_struct *ndpi_struct, struct n
} }
NDPI_LOG(NDPI_PROTOCOL_LDAP, ndpi_struct, NDPI_LOG_DEBUG, "ldap excluded.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_LDAP);
} }
+10 -7
View File
@@ -1,6 +1,11 @@
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_LISP #ifdef NDPI_PROTOCOL_LISP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_LISP
#include "ndpi_api.h"
#define LISP_PORT 4341 #define LISP_PORT 4341
#define LISP_PORT1 4342 #define LISP_PORT1 4342
@@ -16,9 +21,8 @@ static void ndpi_check_lisp(struct ndpi_detection_module_struct *ndpi_struct, st
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
if(packet->udp != NULL) { if(packet->udp != NULL) {
u_int16_t lisp_port = htons(LISP_PORT); u_int16_t lisp_port = htons(LISP_PORT);
u_int16_t lisp_port1 = htons(LISP_PORT1); u_int16_t lisp_port1 = htons(LISP_PORT1);
@@ -28,22 +32,21 @@ static void ndpi_check_lisp(struct ndpi_detection_module_struct *ndpi_struct, st
((packet->udp->source == lisp_port1) ((packet->udp->source == lisp_port1)
&& (packet->udp->dest == lisp_port1)) ) { && (packet->udp->dest == lisp_port1)) ) {
NDPI_LOG(NDPI_PROTOCOL_LISP, ndpi_struct, NDPI_LOG_DEBUG, "Found lisp.\n"); NDPI_LOG_INFO(ndpi_struct, "found lisp\n");
ndpi_int_lisp_add_connection(ndpi_struct, flow, 0); ndpi_int_lisp_add_connection(ndpi_struct, flow, 0);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_LISP, ndpi_struct, NDPI_LOG_DEBUG, "exclude lisp.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_LISP);
} }
void ndpi_search_lisp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_lisp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_LISP, ndpi_struct, NDPI_LOG_DEBUG, "lisp detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search lisp\n");
/* skip marked packets */ /* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_LISP) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_LISP) {
+25 -24
View File
@@ -18,10 +18,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_LOTUS_NOTES
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_LOTUS_NOTES
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_LOTUS_NOTES
/* ************************************ */ /* ************************************ */
@@ -32,38 +36,35 @@ static void ndpi_check_lotus_notes(struct ndpi_detection_module_struct *ndpi_str
// const u_int8_t *packet_payload = packet->payload; // const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
if(packet->tcp != NULL) { if(packet->tcp == NULL) return;
flow->l4.tcp.lotus_notes_packet_id++;
if((flow->l4.tcp.lotus_notes_packet_id == 1)
/* We have seen the 3-way handshake */
&& flow->l4.tcp.seen_syn
&& flow->l4.tcp.seen_syn_ack
&& flow->l4.tcp.seen_ack) {
if(payload_len > 16) {
char lotus_notes_header[] = { 0x00, 0x00, 0x02, 0x00, 0x00, 0x40, 0x02, 0x0F };
if(memcmp(&packet->payload[6], lotus_notes_header, sizeof(lotus_notes_header)) == 0) {
NDPI_LOG(NDPI_PROTOCOL_LOTUS_NOTES, ndpi_struct, NDPI_LOG_DEBUG, "Found lotus_notes.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_LOTUS_NOTES, NDPI_PROTOCOL_UNKNOWN);
}
return; flow->l4.tcp.lotus_notes_packet_id++;
if((flow->l4.tcp.lotus_notes_packet_id == 1)
/* We have seen the 3-way handshake */
&& flow->l4.tcp.seen_syn
&& flow->l4.tcp.seen_syn_ack
&& flow->l4.tcp.seen_ack) {
if(payload_len > 16) {
char lotus_notes_header[] = { 0x00, 0x00, 0x02, 0x00, 0x00, 0x40, 0x02, 0x0F };
if(memcmp(&packet->payload[6], lotus_notes_header, sizeof(lotus_notes_header)) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found lotus_notes\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_LOTUS_NOTES, NDPI_PROTOCOL_UNKNOWN);
} }
return;
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_LOTUS_NOTES); } else if(flow->l4.tcp.lotus_notes_packet_id <= 3) return;
} else if(flow->l4.tcp.lotus_notes_packet_id > 3)
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_LOTUS_NOTES); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
} }
void ndpi_search_lotus_notes(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_lotus_notes(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_LOTUS_NOTES, ndpi_struct, NDPI_LOG_DEBUG, "lotus_notes detection...\n"); NDPI_LOG_DBG(ndpi_struct, "search lotus_notes\n");
/* skip marked packets */ /* skip marked packets */
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_LOTUS_NOTES) if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_LOTUS_NOTES)
+12 -8
View File
@@ -22,10 +22,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MAIL_IMAP #ifdef NDPI_PROTOCOL_MAIL_IMAP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MAIL_IMAP
#include "ndpi_api.h"
static void ndpi_int_mail_imap_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_mail_imap_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MAIL_IMAP, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MAIL_IMAP, NDPI_PROTOCOL_UNKNOWN);
@@ -40,11 +45,11 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t saw_command = 0; u_int8_t saw_command = 0;
/* const u_int8_t *command = 0; */ /* const u_int8_t *command = 0; */
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, "search IMAP.\n"); NDPI_LOG_DBG(ndpi_struct, "search IMAP_IMAP\n");
if (flow->l4.tcp.mail_imap_starttls == 2) { if (flow->l4.tcp.mail_imap_starttls == 2) {
#ifdef NDPI_PROTOCOL_SSL #ifdef NDPI_PROTOCOL_SSL
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, "starttls detected\n"); NDPI_LOG_DBG2(ndpi_struct, "starttls detected\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_IMAP); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_IMAP);
NDPI_DEL_PROTOCOL_FROM_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SSL); NDPI_DEL_PROTOCOL_FROM_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SSL);
return; return;
@@ -275,7 +280,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
if (saw_command == 1) { if (saw_command == 1) {
if (flow->l4.tcp.mail_imap_stage == 3 || flow->l4.tcp.mail_imap_stage == 5) { if (flow->l4.tcp.mail_imap_stage == 3 || flow->l4.tcp.mail_imap_stage == 5) {
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, "mail imap identified\n"); NDPI_LOG_INFO(ndpi_struct, "found MAIL_IMAP\n");
ndpi_int_mail_imap_add_connection(ndpi_struct, flow); ndpi_int_mail_imap_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -283,7 +288,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} }
if (packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == ' ') { if (packet->payload_packet_len > 1 && packet->payload[packet->payload_packet_len - 1] == ' ') {
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"maybe a split imap command -> need next packet and imap_stage is set to 4.\n"); "maybe a split imap command -> need next packet and imap_stage is set to 4.\n");
flow->l4.tcp.mail_imap_stage = 4; flow->l4.tcp.mail_imap_stage = 4;
return; return;
@@ -295,13 +300,12 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
// if the packet count is low enough and at least one command or response was seen before // if the packet count is low enough and at least one command or response was seen before
if ((packet->payload_packet_len >= 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) if ((packet->payload_packet_len >= 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)
&& flow->packet_counter < 6 && flow->l4.tcp.mail_imap_stage >= 1) { && flow->packet_counter < 6 && flow->l4.tcp.mail_imap_stage >= 1) {
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"no imap command or response but packet count < 6 and imap stage >= 1 -> skip\n"); "no imap command or response but packet count < 6 and imap stage >= 1 -> skip\n");
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_MAIL_IMAP, ndpi_struct, NDPI_LOG_DEBUG, "exclude IMAP.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_IMAP);
} }
+12 -14
View File
@@ -23,10 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MAIL_POP #ifdef NDPI_PROTOCOL_MAIL_POP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MAIL_POP
#include "ndpi_api.h"
#define POP_BIT_AUTH 0x0001 #define POP_BIT_AUTH 0x0001
#define POP_BIT_APOP 0x0002 #define POP_BIT_APOP 0x0002
#define POP_BIT_USER 0x0004 #define POP_BIT_USER 0x0004
@@ -52,9 +57,6 @@ static int ndpi_int_mail_pop_check_for_client_commands(struct ndpi_detection_mod
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (packet->payload_packet_len > 4) { if (packet->payload_packet_len > 4) {
if ((packet->payload[0] == 'A' || packet->payload[0] == 'a') if ((packet->payload[0] == 'A' || packet->payload[0] == 'a')
&& (packet->payload[1] == 'U' || packet->payload[1] == 'u') && (packet->payload[1] == 'U' || packet->payload[1] == 'u')
@@ -133,13 +135,10 @@ void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
u_int8_t a = 0; u_int8_t a = 0;
u_int8_t bit_count = 0; u_int8_t bit_count = 0;
NDPI_LOG(NDPI_PROTOCOL_MAIL_POP, ndpi_struct, NDPI_LOG_DEBUG, "search mail_pop\n"); NDPI_LOG_DBG(ndpi_struct, "search mail_pop\n");
@@ -165,12 +164,12 @@ void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MAIL_POP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"mail_pop +OK/-ERR responses: %u, unique commands: %u\n", flow->l4.tcp.mail_pop_stage, bit_count); "mail_pop +OK/-ERR responses: %u, unique commands: %u\n", flow->l4.tcp.mail_pop_stage, bit_count);
if ((bit_count + flow->l4.tcp.mail_pop_stage) >= 3) { if ((bit_count + flow->l4.tcp.mail_pop_stage) >= 3) {
if (flow->l4.tcp.mail_pop_stage > 0) { if (flow->l4.tcp.mail_pop_stage > 0) {
NDPI_LOG(NDPI_PROTOCOL_MAIL_POP, ndpi_struct, NDPI_LOG_DEBUG, "mail_pop identified\n"); NDPI_LOG_INFO(ndpi_struct, "mail_pop identified\n");
ndpi_int_mail_pop_add_connection(ndpi_struct, flow); ndpi_int_mail_pop_add_connection(ndpi_struct, flow);
return; return;
} else { } else {
@@ -182,7 +181,7 @@ void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct
} else { } else {
// first part of a split packet // first part of a split packet
NDPI_LOG(NDPI_PROTOCOL_MAIL_POP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"mail_pop command without line ending -> skip\n"); "mail_pop command without line ending -> skip\n");
return; return;
} }
@@ -193,13 +192,12 @@ void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct
if (((packet->payload_packet_len > 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) if (((packet->payload_packet_len > 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a)
|| flow->l4.tcp.pop_command_bitmask != 0 || flow->l4.tcp.mail_pop_stage != 0) && flow->packet_counter < 12) { || flow->l4.tcp.pop_command_bitmask != 0 || flow->l4.tcp.mail_pop_stage != 0) && flow->packet_counter < 12) {
// maybe part of a split pop packet // maybe part of a split pop packet
NDPI_LOG(NDPI_PROTOCOL_MAIL_POP, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"maybe part of split mail_pop packet -> skip\n"); "maybe part of split mail_pop packet -> skip\n");
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_MAIL_POP, ndpi_struct, NDPI_LOG_DEBUG, "exclude mail_pop\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_POP);
} }
+11 -12
View File
@@ -23,10 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MAIL_SMTP #ifdef NDPI_PROTOCOL_MAIL_SMTP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MAIL_SMTP
#include "ndpi_api.h"
#define SMTP_BIT_220 0x01 #define SMTP_BIT_220 0x01
#define SMTP_BIT_250 0x02 #define SMTP_BIT_250 0x02
#define SMTP_BIT_235 0x04 #define SMTP_BIT_235 0x04
@@ -53,12 +58,7 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search mail_smtp\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
NDPI_LOG(NDPI_PROTOCOL_MAIL_SMTP, ndpi_struct, NDPI_LOG_DEBUG, "search mail_smtp.\n");
if (packet->payload_packet_len > 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) { if (packet->payload_packet_len > 2 && ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a) {
u_int8_t a; u_int8_t a;
@@ -152,11 +152,11 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct
bit_count += (flow->l4.tcp.smtp_command_bitmask >> a) & 0x01; bit_count += (flow->l4.tcp.smtp_command_bitmask >> a) & 0x01;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MAIL_SMTP, ndpi_struct, NDPI_LOG_DEBUG, "seen smtp commands and responses: %u.\n", NDPI_LOG_DBG2(ndpi_struct, "seen smtp commands and responses: %u\n",
bit_count); bit_count);
if (bit_count >= 3) { if (bit_count >= 3) {
NDPI_LOG(NDPI_PROTOCOL_MAIL_SMTP, ndpi_struct, NDPI_LOG_DEBUG, "mail smtp identified\n"); NDPI_LOG_INFO(ndpi_struct, "mail smtp identified\n");
ndpi_int_mail_smtp_add_connection(ndpi_struct, flow); ndpi_int_mail_smtp_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -169,12 +169,11 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct
packet->payload_packet_len >= 4 && packet->payload_packet_len >= 4 &&
(ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a (ntohs(get_u_int16_t(packet->payload, packet->payload_packet_len - 2)) == 0x0d0a
|| memcmp(packet->payload, "220", 3) == 0 || memcmp(packet->payload, "EHLO", 4) == 0)) { || memcmp(packet->payload, "220", 3) == 0 || memcmp(packet->payload, "EHLO", 4) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_MAIL_SMTP, ndpi_struct, NDPI_LOG_DEBUG, "maybe SMTP, need next packet.\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe SMTP, need next packet\n");
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_MAIL_SMTP, ndpi_struct, NDPI_LOG_DEBUG, "exclude smtp\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAIL_SMTP);
} }
+10 -10
View File
@@ -22,10 +22,14 @@
* *
*/ */
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MAPLESTORY #ifdef NDPI_PROTOCOL_MAPLESTORY
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MAPLESTORY
#include "ndpi_api.h"
static void ndpi_int_maplestory_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_maplestory_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MAPLESTORY, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MAPLESTORY, NDPI_PROTOCOL_UNKNOWN);
@@ -36,16 +40,13 @@ void ndpi_search_maplestory(struct ndpi_detection_module_struct *ndpi_struct, st
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search maplestory\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (packet->payload_packet_len == 16 if (packet->payload_packet_len == 16
&& (ntohl(get_u_int32_t(packet->payload, 0)) == 0x0e003a00 || ntohl(get_u_int32_t(packet->payload, 0)) == 0x0e003b00 && (ntohl(get_u_int32_t(packet->payload, 0)) == 0x0e003a00 || ntohl(get_u_int32_t(packet->payload, 0)) == 0x0e003b00
|| ntohl(get_u_int32_t(packet->payload, 0)) == 0x0e004200) || ntohl(get_u_int32_t(packet->payload, 0)) == 0x0e004200)
&& ntohs(get_u_int16_t(packet->payload, 4)) == 0x0100 && (packet->payload[6] == 0x32 || packet->payload[6] == 0x33)) { && ntohs(get_u_int16_t(packet->payload, 4)) == 0x0100 && (packet->payload[6] == 0x32 || packet->payload[6] == 0x33)) {
NDPI_LOG(NDPI_PROTOCOL_MAPLESTORY, ndpi_struct, NDPI_LOG_DEBUG, "found maplestory.\n"); NDPI_LOG_INFO(ndpi_struct, "found maplestory\n");
ndpi_int_maplestory_add_connection(ndpi_struct, flow); ndpi_int_maplestory_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -63,7 +64,7 @@ void ndpi_search_maplestory(struct ndpi_detection_module_struct *ndpi_struct, st
NDPI_STATICSTRING_LEN("patch")) == 0 NDPI_STATICSTRING_LEN("patch")) == 0
&& memcmp(packet->user_agent_line.ptr, "Patcher", NDPI_STATICSTRING_LEN("Patcher")) == 0 && memcmp(packet->user_agent_line.ptr, "Patcher", NDPI_STATICSTRING_LEN("Patcher")) == 0
&& memcmp(packet->host_line.ptr, "patch.", NDPI_STATICSTRING_LEN("patch.")) == 0) { && memcmp(packet->host_line.ptr, "patch.", NDPI_STATICSTRING_LEN("patch.")) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MAPLESTORY, ndpi_struct, NDPI_LOG_DEBUG, "found maplestory update.\n"); NDPI_LOG_INFO(ndpi_struct, "found maplestory update\n");
ndpi_int_maplestory_add_connection(ndpi_struct, flow); ndpi_int_maplestory_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -71,14 +72,13 @@ void ndpi_search_maplestory(struct ndpi_detection_module_struct *ndpi_struct, st
&& memcmp(&packet->payload[NDPI_STATICSTRING_LEN("GET /maple")], "story/", && memcmp(&packet->payload[NDPI_STATICSTRING_LEN("GET /maple")], "story/",
NDPI_STATICSTRING_LEN("story/")) == 0 NDPI_STATICSTRING_LEN("story/")) == 0
&& memcmp(packet->user_agent_line.ptr, "AspINet", NDPI_STATICSTRING_LEN("AspINet")) == 0) { && memcmp(packet->user_agent_line.ptr, "AspINet", NDPI_STATICSTRING_LEN("AspINet")) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MAPLESTORY, ndpi_struct, NDPI_LOG_DEBUG, "found maplestory update.\n"); NDPI_LOG_INFO(ndpi_struct, "found maplestory update\n");
ndpi_int_maplestory_add_connection(ndpi_struct, flow); ndpi_int_maplestory_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MAPLESTORY, ndpi_struct, NDPI_LOG_DEBUG, "exclude maplestory.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MAPLESTORY);
} }
+12 -8
View File
@@ -20,10 +20,14 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MDNS #ifdef NDPI_PROTOCOL_MDNS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MDNS
#include "ndpi_api.h"
#define NDPI_MAX_MDNS_REQUESTS 128 #define NDPI_MAX_MDNS_REQUESTS 128
PACK_ON PACK_ON
@@ -65,7 +69,7 @@ static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
if(((packet->payload[2] & 0x80) == 0) if(((packet->payload[2] & 0x80) == 0)
&& (questions <= NDPI_MAX_MDNS_REQUESTS) && (questions <= NDPI_MAX_MDNS_REQUESTS)
&& (answers <= NDPI_MAX_MDNS_REQUESTS)) { && (answers <= NDPI_MAX_MDNS_REQUESTS)) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with question query.\n"); NDPI_LOG_INFO(ndpi_struct, "found MDNS with question query\n");
return 1; return 1;
} }
else if(((packet->payload[2] & 0x80) != 0) else if(((packet->payload[2] & 0x80) != 0)
@@ -86,7 +90,7 @@ static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
strncpy(flow->protos.mdns.answer, (const char *)answer, len); strncpy(flow->protos.mdns.answer, (const char *)answer, len);
flow->protos.mdns.answer[len] = '\0'; flow->protos.mdns.answer[len] = '\0';
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with answer query.\n"); NDPI_LOG_INFO(ndpi_struct, "found MDNS with answer query\n");
return 1; return 1;
} }
@@ -98,6 +102,8 @@ void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct n
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t dport; u_int16_t dport;
NDPI_LOG_DBG(ndpi_struct, "search MDNS\n");
/** /**
information from http://www.it-administrator.de/lexikon/multicast-dns.html information from http://www.it-administrator.de/lexikon/multicast-dns.html
*/ */
@@ -112,8 +118,7 @@ void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct n
/* mdns protocol must have destination address 224.0.0.251 */ /* mdns protocol must have destination address 224.0.0.251 */
if(packet->iph != NULL /* && ntohl(packet->iph->daddr) == 0xe00000fb */) { if(packet->iph != NULL /* && ntohl(packet->iph->daddr) == 0xe00000fb */) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
NDPI_LOG_DEBUG, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
if(ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) { if(ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow); ndpi_int_mdns_add_connection(ndpi_struct, flow);
@@ -125,8 +130,7 @@ void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct n
const u_int32_t *daddr = packet->iphv6->ip6_dst.u6_addr.u6_addr32; const u_int32_t *daddr = packet->iphv6->ip6_dst.u6_addr.u6_addr32;
if(daddr[0] == htonl(0xff020000) /* && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb) */) { if(daddr[0] == htonl(0xff020000) /* && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb) */) {
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found MDNS with destination address ff02::fb\n");
NDPI_LOG_DEBUG, "found MDNS with destination address ff02::fb\n");
if(ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) { if(ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
ndpi_int_mdns_add_connection(ndpi_struct, flow); ndpi_int_mdns_add_connection(ndpi_struct, flow);
@@ -137,7 +141,7 @@ void ndpi_search_mdns(struct ndpi_detection_module_struct *ndpi_struct, struct n
#endif #endif
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MDNS); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+8 -5
View File
@@ -18,16 +18,20 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MEGACO
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MEGACO
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_MEGACO
void ndpi_search_megaco(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_megaco(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_MEGACO, ndpi_struct, NDPI_LOG_DEBUG, "search for MEGACO.\n"); NDPI_LOG_DBG(ndpi_struct, "search for MEGACO\n");
if(packet->udp != NULL) { if(packet->udp != NULL) {
if((packet->payload_packet_len > 4 && packet->payload[0] == '!' && packet->payload[1] == '/' && if((packet->payload_packet_len > 4 && packet->payload[0] == '!' && packet->payload[1] == '/' &&
@@ -36,14 +40,13 @@ void ndpi_search_megaco(struct ndpi_detection_module_struct *ndpi_struct, struct
packet->payload[2] == 'G' && packet->payload[3] == 'A' && packet->payload[4] == 'C' && packet->payload[2] == 'G' && packet->payload[3] == 'A' && packet->payload[4] == 'C' &&
packet->payload[5] == 'O' && packet->payload[6] == '/' && packet->payload[5] == 'O' && packet->payload[6] == '/' &&
packet->payload[7] == '1' && packet->payload[8] == ' ' && packet->payload[9] == '[')) { packet->payload[7] == '1' && packet->payload[8] == ' ' && packet->payload[9] == '[')) {
NDPI_LOG(NDPI_PROTOCOL_MEGACO, ndpi_struct, NDPI_LOG_DEBUG, "found MEGACO.\n"); NDPI_LOG_INFO(ndpi_struct, "found MEGACO\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MEGACO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MEGACO, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MEGACO, ndpi_struct, NDPI_LOG_DEBUG, "exclude MEGACO.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MEGACO);
} }
+36 -31
View File
@@ -20,10 +20,16 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocols.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MGCP #ifdef NDPI_PROTOCOL_MGCP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MGCP
#include "ndpi_api.h"
static void ndpi_int_mgcp_add_connection(struct ndpi_detection_module_struct static void ndpi_int_mgcp_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -39,40 +45,39 @@ void ndpi_search_mgcp(struct ndpi_detection_module_struct *ndpi_struct, struct n
u_int16_t pos = 5; u_int16_t pos = 5;
if (packet->payload_packet_len < 8) { NDPI_LOG_DBG(ndpi_struct, "search MGCP\n");
goto mgcp_excluded;
}
/* packet must end with 0x0d0a or with 0x0a */ do {
if (packet->payload[packet->payload_packet_len - 1] != 0x0a) { if (packet->payload_packet_len < 8) break;
goto mgcp_excluded;
}
if (packet->payload[0] != 'A' && packet->payload[0] != 'C' && packet->payload[0] != 'D' && /* packet must end with 0x0d0a or with 0x0a */
packet->payload[0] != 'E' && packet->payload[0] != 'M' && packet->payload[0] != 'N' && if (packet->payload[packet->payload_packet_len - 1] != 0x0a) break;
packet->payload[0] != 'R') {
goto mgcp_excluded; if (packet->payload[0] != 'A' && packet->payload[0] != 'C' && packet->payload[0] != 'D' &&
} packet->payload[0] != 'E' && packet->payload[0] != 'M' && packet->payload[0] != 'N' &&
if (memcmp(packet->payload, "AUEP ", 5) != 0 && memcmp(packet->payload, "AUCX ", 5) != 0 && packet->payload[0] != 'R')
memcmp(packet->payload, "CRCX ", 5) != 0 && memcmp(packet->payload, "DLCX ", 5) != 0 && break;
memcmp(packet->payload, "EPCF ", 5) != 0 && memcmp(packet->payload, "MDCX ", 5) != 0 &&
memcmp(packet->payload, "NTFY ", 5) != 0 && memcmp(packet->payload, "RQNT ", 5) != 0 && if (memcmp(packet->payload, "AUEP ", 5) != 0 && memcmp(packet->payload, "AUCX ", 5) != 0 &&
memcmp(packet->payload, "RSIP ", 5) != 0) { memcmp(packet->payload, "CRCX ", 5) != 0 && memcmp(packet->payload, "DLCX ", 5) != 0 &&
goto mgcp_excluded; memcmp(packet->payload, "EPCF ", 5) != 0 && memcmp(packet->payload, "MDCX ", 5) != 0 &&
} memcmp(packet->payload, "NTFY ", 5) != 0 && memcmp(packet->payload, "RQNT ", 5) != 0 &&
// now search for string "MGCP " in the rest of the message memcmp(packet->payload, "RSIP ", 5) != 0)
while ((pos + 4) < packet->payload_packet_len) { break;
if (memcmp(&packet->payload[pos], "MGCP ", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MGCP, ndpi_struct, NDPI_LOG_DEBUG, "MGCP match.\n"); // now search for string "MGCP " in the rest of the message
ndpi_int_mgcp_add_connection(ndpi_struct, flow); while ((pos + 4) < packet->payload_packet_len) {
return; if (memcmp(&packet->payload[pos], "MGCP ", 5) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MGCP\n");
ndpi_int_mgcp_add_connection(ndpi_struct, flow);
return;
}
pos++;
} }
pos++;
}
mgcp_excluded: } while(0);
NDPI_LOG(NDPI_PROTOCOL_MGCP, ndpi_struct, NDPI_LOG_DEBUG, "exclude MGCP.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MGCP); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+10 -9
View File
@@ -23,10 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_CONTENT_MMS #ifdef NDPI_CONTENT_MMS
#define NDPI_CURRENT_PROTO NDPI_CONTENT_MMS
#include "ndpi_api.h"
static void ndpi_int_mms_add_connection(struct ndpi_detection_module_struct static void ndpi_int_mms_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -39,9 +43,7 @@ void ndpi_search_mms_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search MMS\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
/* search MSMMS packets */ /* search MSMMS packets */
if (packet->payload_packet_len >= 20) { if (packet->payload_packet_len >= 20) {
@@ -49,7 +51,7 @@ void ndpi_search_mms_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
&& packet->payload[5] == 0xfa && packet->payload[6] == 0x0b && packet->payload[5] == 0xfa && packet->payload[6] == 0x0b
&& packet->payload[7] == 0xb0 && packet->payload[12] == 0x4d && packet->payload[7] == 0xb0 && packet->payload[12] == 0x4d
&& packet->payload[13] == 0x4d && packet->payload[14] == 0x53 && packet->payload[15] == 0x20) { && packet->payload[13] == 0x4d && packet->payload[14] == 0x53 && packet->payload[15] == 0x20) {
NDPI_LOG(NDPI_CONTENT_MMS, ndpi_struct, NDPI_LOG_DEBUG, "MMS: MSMMS Request found \n"); NDPI_LOG_INFO(ndpi_struct, "found MMS: MSMMS Request \n");
flow->l4.tcp.mms_stage = 1 + packet->packet_direction; flow->l4.tcp.mms_stage = 1 + packet->packet_direction;
return; return;
} }
@@ -59,7 +61,7 @@ void ndpi_search_mms_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
&& packet->payload[6] == 0x0b && packet->payload[7] == 0xb0 && packet->payload[6] == 0x0b && packet->payload[7] == 0xb0
&& packet->payload[12] == 0x4d && packet->payload[13] == 0x4d && packet->payload[12] == 0x4d && packet->payload[13] == 0x4d
&& packet->payload[14] == 0x53 && packet->payload[15] == 0x20) { && packet->payload[14] == 0x53 && packet->payload[15] == 0x20) {
NDPI_LOG(NDPI_CONTENT_MMS, ndpi_struct, NDPI_LOG_DEBUG, "MMS: MSMMS Response found \n"); NDPI_LOG_INFO(ndpi_struct, "found MMS: MSMMS Response \n");
ndpi_int_mms_add_connection(ndpi_struct, flow); ndpi_int_mms_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -67,12 +69,11 @@ void ndpi_search_mms_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
#ifdef NDPI_PROTOCOL_HTTP #ifdef NDPI_PROTOCOL_HTTP
if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HTTP) != 0) { if (NDPI_COMPARE_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HTTP) != 0) {
#endif /* NDPI_PROTOCOL_HTTP */ #endif /* NDPI_PROTOCOL_HTTP */
NDPI_LOG(NDPI_CONTENT_MMS, ndpi_struct, NDPI_LOG_DEBUG, "MMS: exclude\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_CONTENT_MMS);
#ifdef NDPI_PROTOCOL_HTTP #ifdef NDPI_PROTOCOL_HTTP
} else { } else {
NDPI_LOG(NDPI_CONTENT_MMS, ndpi_struct, NDPI_LOG_DEBUG, "MMS avoid early exclude from http\n"); NDPI_LOG_DBG(ndpi_struct, "MMS avoid early exclude from http\n");
} }
#endif /* NDPI_PROTOCOL_HTTP */ #endif /* NDPI_PROTOCOL_HTTP */
+8 -5
View File
@@ -19,16 +19,19 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_MPEGTS #ifdef NDPI_PROTOCOL_MPEGTS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MPEGTS
#include "ndpi_api.h"
void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_MPEGTS, ndpi_struct, NDPI_LOG_DEBUG, "search for MPEGTS.\n"); NDPI_LOG_DBG(ndpi_struct, "search MPEGTS\n");
if((packet->udp != NULL) && ((packet->payload_packet_len % 188) == 0)) { if((packet->udp != NULL) && ((packet->payload_packet_len % 188) == 0)) {
u_int i, num_chunks = packet->payload_packet_len / 188; u_int i, num_chunks = packet->payload_packet_len / 188;
@@ -40,13 +43,13 @@ void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct
} }
/* This looks MPEG TS */ /* This looks MPEG TS */
NDPI_LOG_INFO(ndpi_struct, "found MPEGTS\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MPEGTS, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MPEGTS, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
no_mpegts: no_mpegts:
NDPI_LOG(NDPI_PROTOCOL_MPEGTS, ndpi_struct, NDPI_LOG_DEBUG, "Excluded MPEGTS.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MPEGTS);
} }
+47 -42
View File
@@ -21,9 +21,15 @@
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MQTT #ifdef NDPI_PROTOCOL_MQTT
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MQTT
#include "ndpi_api.h"
/** /**
* The type of control messages in mqtt version 3.1.1 * The type of control messages in mqtt version 3.1.1
* see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1 * see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1
@@ -52,7 +58,7 @@ static void ndpi_int_mqtt_add_connection (struct ndpi_detection_module_struct *n
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct,flow,NDPI_PROTOCOL_MQTT,NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct,flow,NDPI_PROTOCOL_MQTT,NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found.\n"); NDPI_LOG_INFO(ndpi_struct, "found Mqtt\n");
} }
/** /**
@@ -61,95 +67,96 @@ static void ndpi_int_mqtt_add_connection (struct ndpi_detection_module_struct *n
void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct, void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt search called...\n"); u_int8_t rl,pt,flags;
NDPI_LOG_DBG(ndpi_struct, "search Mqtt\n");
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt detection...\n");
if (flow->packet_counter > 10) { if (flow->packet_counter > 10) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. mandatory header not found!\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. mandatory header not found!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "====>>>> Mqtt header: %4x%4x%4x%4x [len: %u]\n", NDPI_LOG_DBG2(ndpi_struct, "====>>>> Mqtt header: %4x%4x%4x%4x [len: %u]\n",
packet->payload[0], packet->payload[1], packet->payload[2], packet->payload[3], packet->payload_packet_len); packet->payload[0], packet->payload[1], packet->payload[2], packet->payload[3], packet->payload_packet_len);
if (packet->payload_packet_len < 2) { if (packet->payload_packet_len < 2) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. mandatory header not found!\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. mandatory header not found!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
if (packet->payload_packet_len > 258) { if (packet->payload_packet_len > 258) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. maximum packet size exceeded!\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. maximum packet size exceeded!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
// we extract the remaining length // we extract the remaining length
u_int8_t rl = (u_int8_t) (packet->payload[1]); rl = (u_int8_t) (packet->payload[1]);
if (packet->payload_packet_len != (rl + 2)) { if (packet->payload_packet_len != (rl + 2)) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. packet size exceeded!\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. packet size exceeded!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
// we extract the packet type // we extract the packet type
u_int8_t pt = (u_int8_t) ((packet->payload[0] & 0xF0) >> 4); pt = (u_int8_t) ((packet->payload[0] & 0xF0) >> 4);
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Mqtt packet type: [%d]\n",pt); NDPI_LOG_DBG2(ndpi_struct,"====>>>> Mqtt packet type: [%d]\n",pt);
if ((pt == 0) || (pt == 15)) { if ((pt == 0) || (pt == 15)) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. invalid packet type!\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. invalid packet type!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
// we extract the flags // we extract the flags
u_int8_t flags = (u_int8_t) (packet->payload[0] & 0x0F); flags = (u_int8_t) (packet->payload[0] & 0x0F);
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Mqtt flags type: [%d]\n",flags); NDPI_LOG_DBG2(ndpi_struct,"====>>>> Mqtt flags type: [%d]\n",flags);
// first stage verification // first stage verification
if (((pt == CONNECT) || (pt == CONNACK) || (pt == PUBACK) || (pt == PUBREC) || if (((pt == CONNECT) || (pt == CONNACK) || (pt == PUBACK) || (pt == PUBREC) ||
(pt == PUBCOMP) || (pt == SUBACK) || (pt == UNSUBACK) || (pt == PINGREQ) || (pt == PUBCOMP) || (pt == SUBACK) || (pt == UNSUBACK) || (pt == PINGREQ) ||
(pt == PINGRESP) || (pt == DISCONNECT)) && (flags > 0)) { (pt == PINGRESP) || (pt == DISCONNECT)) && (flags > 0)) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Flag combination flag!=0\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid Packet-Flag combination flag!=0\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
if (((pt == PUBREL) || (pt == SUBSCRIBE) || (pt == UNSUBSCRIBE)) && (flags != 2)) { if (((pt == PUBREL) || (pt == SUBSCRIBE) || (pt == UNSUBSCRIBE)) && (flags != 2)) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Flag combination flag!=2\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid Packet-Flag combination flag!=2\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed first stage of identification\n"); NDPI_LOG_DBG2(ndpi_struct,"====>>>> Passed first stage of identification\n");
// second stage verification (no payload, just variable headers) // second stage verification (no payload, just variable headers)
if ((pt == CONNACK) || (pt == PUBACK) || (pt == PUBREL) || if ((pt == CONNACK) || (pt == PUBACK) || (pt == PUBREL) ||
(pt == PUBREC) || (pt == PUBCOMP) || (pt == UNSUBACK)) { (pt == PUBREC) || (pt == PUBCOMP) || (pt == UNSUBACK)) {
if (packet->payload_packet_len != 4) { // these packets are always 4 bytes long if (packet->payload_packet_len != 4) { // these packets are always 4 bytes long
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Length < 4 \n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid Packet-Length < 4 \n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found CONNACK/PUBACK/PUBREL/PUBREC/PUBCOMP/UNSUBACK\n"); NDPI_LOG_INFO(ndpi_struct, "found Mqtt CONNACK/PUBACK/PUBREL/PUBREC/PUBCOMP/UNSUBACK\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} }
} }
if ((pt == PINGREQ) || (pt == PINGRESP) || (pt == DISCONNECT)) { if ((pt == PINGREQ) || (pt == PINGRESP) || (pt == DISCONNECT)) {
if (packet->payload_packet_len != 2) { // these packets are always 2 bytes long if (packet->payload_packet_len != 2) { // these packets are always 2 bytes long
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid Packet-Length <2 \n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid Packet-Length <2 \n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found PING/PINGRESP/DISCONNECT\n"); NDPI_LOG_INFO(ndpi_struct, "found Mqtt PING/PINGRESP/DISCONNECT\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed second stage of identification\n"); NDPI_LOG_DBG2(ndpi_struct,"====>>>> Passed second stage of identification\n");
// third stage verification (payload) // third stage verification (payload)
if (pt == CONNECT) { if (pt == CONNECT) {
if (packet->payload_packet_len >= 8 && memcmp(&(packet->payload[4]),"MQTT",4) == 0) { if (packet->payload_packet_len >= 8 && memcmp(&(packet->payload[4]),"MQTT",4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found CONNECT\n"); NDPI_LOG_DBG(ndpi_struct, "found Mqtt CONNECT\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid CONNECT\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid CONNECT\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
@@ -160,79 +167,78 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t retain = (u_int8_t) (flags & 0x01); u_int8_t retain = (u_int8_t) (flags & 0x01);
u_int8_t dup = (u_int8_t) (flags & 0x04); u_int8_t dup = (u_int8_t) (flags & 0x04);
if (qos > 2) { // qos values possible are 0,1,2 if (qos > 2) { // qos values possible are 0,1,2
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH qos\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid PUBLISH qos\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
if (retain > 1) { // retain flag possible 0,1 if (retain > 1) { // retain flag possible 0,1
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH retain\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid PUBLISH retain\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
if (dup > 1) { // dup flag possible 0,1 if (dup > 1) { // dup flag possible 0,1
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH dup\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid PUBLISH dup\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
if (qos == 0) { if (qos == 0) {
if (dup != 0) { if (dup != 0) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH qos0 and dup combination\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid PUBLISH qos0 and dup combination\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
if (packet->payload_packet_len < 5) { // at least topic (3Bytes + 2Bytes fixed header) if (packet->payload_packet_len < 5) { // at least topic (3Bytes + 2Bytes fixed header)
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH qos0 size\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid PUBLISH qos0 size\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
} }
if ((qos == 1) || (qos == 2)) { if ((qos == 1) || (qos == 2)) {
if (packet->payload_packet_len < 7 ) { // at least topic + pkt identifier (3Bytes + 2Bytes + 2Bytes fixed header) if (packet->payload_packet_len < 7 ) { // at least topic + pkt identifier (3Bytes + 2Bytes + 2Bytes fixed header)
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH qos1&2\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid PUBLISH qos1&2\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found PUBLISH\n"); NDPI_LOG_INFO(ndpi_struct, "found Mqtt PUBLISH\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} }
if (pt == SUBSCRIBE) { if (pt == SUBSCRIBE) {
if (packet->payload_packet_len < 8) { // at least one topic+filter is required in the payload if (packet->payload_packet_len < 8) { // at least one topic+filter is required in the payload
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid SUBSCRIBE\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid SUBSCRIBE\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found SUBSCRIBE\n"); NDPI_LOG_INFO(ndpi_struct, "found Mqtt SUBSCRIBE\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} }
} }
if (pt == SUBACK ) { if (pt == SUBACK ) {
if (packet->payload_packet_len <5 ) { // must have at least a response code if (packet->payload_packet_len <5 ) { // must have at least a response code
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid SUBACK\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid SUBACK\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found SUBACK\n"); NDPI_LOG_INFO(ndpi_struct, "found Mqtt SUBACK\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} }
} }
if (pt == UNSUBSCRIBE) { if (pt == UNSUBSCRIBE) {
if (packet->payload_packet_len < 7) { // at least a topic if (packet->payload_packet_len < 7) { // at least a topic
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid UNSUBSCRIBE\n"); NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt invalid UNSUBSCRIBE\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found UNSUBSCRIBE\n",pt); NDPI_LOG_INFO(ndpi_struct, "found Mqtt UNSUBSCRIBE\n",pt);
ndpi_int_mqtt_add_connection(ndpi_struct,flow); ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed third stage of identification"); NDPI_LOG_DBG2(ndpi_struct,"====>>>> Passed third stage of identification");
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Reached the end excluding Mqtt ...\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return; return;
} }
/** /**
@@ -241,7 +247,6 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
void init_mqtt_dissector (struct ndpi_detection_module_struct *ndpi_struct, void init_mqtt_dissector (struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{ {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt dissector init...\n");
ndpi_set_bitmask_protocol_detection ("MQTT", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection ("MQTT", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_MQTT, NDPI_PROTOCOL_MQTT,
ndpi_search_mqtt, ndpi_search_mqtt,
+45 -51
View File
@@ -21,10 +21,16 @@
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_api.h"
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MSN #ifdef NDPI_PROTOCOL_MSN
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MSN
#include "ndpi_api.h"
#define MAX_PACKETS_FOR_MSN 100 #define MAX_PACKETS_FOR_MSN 100
static void ndpi_int_msn_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static void ndpi_int_msn_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -59,17 +65,16 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
u_int16_t plen; u_int16_t plen;
u_int16_t status = 0; u_int16_t status = 0;
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN tcp detection...\n");
#ifdef NDPI_PROTOCOL_SSL #ifdef NDPI_PROTOCOL_SSL
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL) { if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "msn ssl ft test\n"); NDPI_LOG_DBG2(ndpi_struct, "msn ssl ft test\n");
if(flow->packet_counter < 10) { if(flow->packet_counter < 10) {
if(flow->packet_counter == 7 && packet->payload_packet_len > 300) { if(flow->packet_counter == 7 && packet->payload_packet_len > 300) {
if(memcmp(packet->payload + 24, "MSNSLP", 6) == 0 if(memcmp(packet->payload + 24, "MSNSLP", 6) == 0
|| (get_u_int32_t(packet->payload, 0) == htonl(0x30000000) && get_u_int32_t(packet->payload, 4) == 0x00000000)) { || (get_u_int32_t(packet->payload, 0) == htonl(0x30000000) && get_u_int32_t(packet->payload, 4) == 0x00000000)) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "detected MSN File Transfer, ifdef ssl.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer, ifdef ssl\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -77,12 +82,12 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(flow->packet_counter >= 5 && flow->packet_counter <= 10 && (get_u_int32_t(packet->payload, 0) == htonl(0x18000000) if(flow->packet_counter >= 5 && flow->packet_counter <= 10 && (get_u_int32_t(packet->payload, 0) == htonl(0x18000000)
&& get_u_int32_t(packet->payload, 4) == 0x00000000)) { && get_u_int32_t(packet->payload, 4) == 0x00000000)) {
flow->l4.tcp.msn_ssl_ft++; flow->l4.tcp.msn_ssl_ft++;
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct,
"increased msn ft ssl stage to: %u at packet nr: %u\n", flow->l4.tcp.msn_ssl_ft, "increased msn ft ssl stage to: %u at packet nr: %u\n", flow->l4.tcp.msn_ssl_ft,
flow->packet_counter); flow->packet_counter);
if (flow->l4.tcp.msn_ssl_ft == 2) { if (flow->l4.tcp.msn_ssl_ft == 2) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct,
"detected MSN File Transfer, ifdef ssl 2.\n"); "found MSN File Transfer, ifdef ssl 2.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
} }
return; return;
@@ -109,18 +114,13 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
&& ((ntohl(get_u_int32_t(packet->payload, 24)) == 0x000f0004 && ntohl(get_u_int32_t(packet->payload, 28)) == 0x72c64bc6) && ((ntohl(get_u_int32_t(packet->payload, 24)) == 0x000f0004 && ntohl(get_u_int32_t(packet->payload, 28)) == 0x72c64bc6)
|| (ntohl(get_u_int32_t(packet->payload, 20)) == 0x000f0004 || (ntohl(get_u_int32_t(packet->payload, 20)) == 0x000f0004
&& ntohl(get_u_int32_t(packet->payload, 24)) == 0x72c64bc6))) { && ntohl(get_u_int32_t(packet->payload, 24)) == 0x72c64bc6))) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct,
"found MSN in packets that also contain voice.messenger.live.com.\n"); "found MSN in packets that also contain voice.messenger.live.com.\n");
/* TODO this is an alternative pattern for video detection */ /* TODO this is an alternative pattern for video detection */
/* if (packet->payload_packet_len > 100 && /* if (packet->payload_packet_len > 100 &&
get_u_int16_t(packet->payload, 86) == htons(0x05dc)) { */ get_u_int16_t(packet->payload, 86) == htons(0x05dc)) { */
if(packet->payload_packet_len > 101 && packet->payload[101] == 0x02) { ndpi_int_msn_add_connection(ndpi_struct, flow);
ndpi_int_msn_add_connection(ndpi_struct, flow);
} else {
ndpi_int_msn_add_connection(ndpi_struct, flow);
}
return; return;
} }
@@ -133,14 +133,12 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
if (memcmp(&packet->payload[packet->payload_packet_len - 6], "CVR", if (memcmp(&packet->payload[packet->payload_packet_len - 6], "CVR",
3) == 0 || memcmp(&packet->payload[packet->payload_packet_len - 8], "MSNP", 4) == 0) { 3) == 0 || memcmp(&packet->payload[packet->payload_packet_len - 8], "MSNP", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found MSN by pattern VER...CVR/MSNP ODOA\n");
"found MSN by pattern VER...CVR/MSNP ODOA.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
if (ndpi_match_strprefix(&packet->payload[4], packet->payload_packet_len-4, "MSNFT")) { if (ndpi_match_strprefix(&packet->payload[4], packet->payload_packet_len-4, "MSNFT")) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found MSN FT by pattern VER MSNFT...0d0a\n");
"found MSN FT by pattern VER MSNFT...0d0a.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -157,6 +155,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
if (packet->user_agent_line.ptr != NULL && if (packet->user_agent_line.ptr != NULL &&
packet->user_agent_line.len > NDPI_STATICSTRING_LEN("Messenger/") && packet->user_agent_line.len > NDPI_STATICSTRING_LEN("Messenger/") &&
memcmp(packet->user_agent_line.ptr, "Messenger/", NDPI_STATICSTRING_LEN("Messenger/")) == 0) { memcmp(packet->user_agent_line.ptr, "Messenger/", NDPI_STATICSTRING_LEN("Messenger/")) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MSN Messenger/\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -184,8 +183,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
(packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") && (packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") &&
memcmp(packet->content_line.ptr, "text/x-msnmsgr", memcmp(packet->content_line.ptr, "text/x-msnmsgr",
NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) { NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct, "found MSN POST application/x-msn-messenger\n");
"found MSN by pattern POST http:// .... application/x-msn-messenger.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -209,16 +207,14 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
for(c = 13; c < 50; c++) { for(c = 13; c < 50; c++) {
if(memcmp(&packet->payload[c], "/", 1) == 0) { if(memcmp(&packet->payload[c], "/", 1) == 0) {
if(memcmp(&packet->payload[c], "/gateway/gateway.dll", 20) == 0) { if(memcmp(&packet->payload[c], "/gateway/gateway.dll", 20) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "found pattern http://.../gateway/gateway.ddl\n");
"found pattern http://.../gateway/gateway.ddl.\n");
status = 1; status = 1;
break; break;
} }
} }
} }
} else if((memcmp(&packet->payload[5], "/gateway/gateway.dll", 20) == 0)) { } else if((memcmp(&packet->payload[5], "/gateway/gateway.dll", 20) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "found pattern http://.../gateway/gateway.ddl\n");
"found pattern http://.../gateway/gateway.ddl.\n");
status = 1; status = 1;
} }
} }
@@ -239,7 +235,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
if ((src != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0) if ((src != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)
|| (dst != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)) { || (dst != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "found MSN with pattern text/xml; charset=utf-8.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN with pattern text/xml; charset=utf-8\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -248,10 +244,8 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
|| memcmp(packet->line[a].ptr, "VER ", 4) == 0 || || memcmp(packet->line[a].ptr, "VER ", 4) == 0 ||
memcmp(packet->line[a].ptr, "ANS ", 4) == 0)) { memcmp(packet->line[a].ptr, "ANS ", 4) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_DBG2(ndpi_struct, "found MSN with pattern text/sml; charset0utf-8\n");
"found MSN with pattern text/sml; charset0utf-8.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN xml CVS / VER / ANS found\n");
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct,
NDPI_LOG_TRACE, "MSN xml CVS / VER / ANS found\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -280,13 +274,13 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
(packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") && (packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") &&
memcmp(packet->content_line.ptr, "text/x-msnmsgr", NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) { memcmp(packet->content_line.ptr, "text/x-msnmsgr", NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, NDPI_LOG_INFO(ndpi_struct,
"HTTP/1.0 200 OK .... application/x-msn-messenger.\n"); "found MSN application/x-msn-messenger.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
if(ndpi_int_find_xmsn(ndpi_struct, flow) == 1) { if(ndpi_int_find_xmsn(ndpi_struct, flow) == 1) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "HTTP/1.0 200 OK .... X-MSN.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN X-MSN\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -296,7 +290,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
/* now block proxy connection */ /* now block proxy connection */
if(packet->payload_packet_len >= 42) { if(packet->payload_packet_len >= 42) {
if(memcmp(packet->payload, "CONNECT messenger.hotmail.com:1863 HTTP/1.", 42) == 0) { if(memcmp(packet->payload, "CONNECT messenger.hotmail.com:1863 HTTP/1.", 42) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "found MSN with pattern CONNECT messenger.hotmail.com:1863 HTTP/1..\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN with pattern CONNECT messenger.hotmail.com:1863 HTTP/1.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -322,7 +316,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
while (plen < endlen) { while (plen < endlen) {
if (ndpi_check_for_email_address(ndpi_struct, flow, plen) != 0) { if (ndpi_check_for_email_address(ndpi_struct, flow, plen) != 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "found mail address\n"); NDPI_LOG_DBG2(ndpi_struct, "found mail address\n");
break; break;
} }
if (packet->payload_packet_len > plen + 1 if (packet->payload_packet_len > plen + 1
@@ -334,7 +328,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
goto ndpi_msn_exclude; goto ndpi_msn_exclude;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "found MSN with pattern USR/ANS ...mail_address.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN with pattern USR/ANS ...mail_address\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -362,12 +356,12 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
(packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") && (packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") &&
memcmp(packet->content_line.ptr, "text/x-msnmsgr", NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) { memcmp(packet->content_line.ptr, "text/x-msnmsgr", NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "HTTP/1.0 200 OK .... application/x-msn-messenger.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN application/x-msn-messenger\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
if(ndpi_int_find_xmsn(ndpi_struct, flow) == 1) { if(ndpi_int_find_xmsn(ndpi_struct, flow) == 1) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "HTTP/1.0 200 OK .... X-MSN.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN X-MSN\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -381,7 +375,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
&& NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)) { && NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)) {
if (flow->packet_counter == 1 && if (flow->packet_counter == 1 &&
packet->payload_packet_len > 12 && memcmp(packet->payload, "recipientid=", 12) == 0) { packet->payload_packet_len > 12 && memcmp(packet->payload, "recipientid=", 12) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "detected file transfer.\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN file transfer\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -396,7 +390,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
if((packet->payload_packet_len == 4 || packet->payload_packet_len == 8) if((packet->payload_packet_len == 4 || packet->payload_packet_len == 8)
&& get_u_int32_t(packet->payload, 0) == htonl(0x04000000)) { && get_u_int32_t(packet->payload, 0) == htonl(0x04000000)) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "maybe first TCP MSN detected\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe first TCP MSN detected\n");
if(packet->payload_packet_len == 8 && get_u_int32_t(packet->payload, 4) == htonl(0x666f6f00)) { if(packet->payload_packet_len == 8 && get_u_int32_t(packet->payload, 4) == htonl(0x666f6f00)) {
flow->l4.tcp.msn_stage = 5 + packet->packet_direction; flow->l4.tcp.msn_stage = 5 + packet->packet_direction;
@@ -409,12 +403,12 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
} else if (flow->l4.tcp.msn_stage == 1 + packet->packet_direction) { } else if (flow->l4.tcp.msn_stage == 1 + packet->packet_direction) {
if (packet->payload_packet_len > 10 && get_u_int32_t(packet->payload, 0) == htonl(0x666f6f00)) { if (packet->payload_packet_len > 10 && get_u_int32_t(packet->payload, 0) == htonl(0x666f6f00)) {
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN File Transfer detected 1\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 1\n");
return; return;
} }
/* did not see this pattern in any trace */ /* did not see this pattern in any trace */
if (packet->payload_packet_len == 56 && get_u_int32_t(packet->payload, 16) == 0) { if (packet->payload_packet_len == 56 && get_u_int32_t(packet->payload, 16) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "maybe Second TCP MSN detected\n"); NDPI_LOG_DBG2(ndpi_struct, "maybe Second TCP MSN detected\n");
flow->l4.tcp.msn_stage = 3 + packet->packet_direction; flow->l4.tcp.msn_stage = 3 + packet->packet_direction;
return; return;
} }
@@ -423,30 +417,30 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
} else if (flow->l4.tcp.msn_stage == 2 - packet->packet_direction } else if (flow->l4.tcp.msn_stage == 2 - packet->packet_direction
&& packet->payload_packet_len == 4 && get_u_int32_t(packet->payload, 0) == htonl(0x30000000)) { && packet->payload_packet_len == 4 && get_u_int32_t(packet->payload, 0) == htonl(0x30000000)) {
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN File Transfer detected 2\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 2\n");
return; return;
} else if ((flow->l4.tcp.msn_stage == 3 + packet->packet_direction) } else if ((flow->l4.tcp.msn_stage == 3 + packet->packet_direction)
|| (flow->l4.tcp.msn_stage == 4 - packet->packet_direction)) { || (flow->l4.tcp.msn_stage == 4 - packet->packet_direction)) {
if (packet->payload_packet_len == 4 && get_u_int32_t(packet->payload, 0) == htonl(0x30000000)) { if (packet->payload_packet_len == 4 && get_u_int32_t(packet->payload, 0) == htonl(0x30000000)) {
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN File Transfer detected 2\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 2\n");
return; return;
} }
} else if (flow->l4.tcp.msn_stage == 6 - packet->packet_direction) { } else if (flow->l4.tcp.msn_stage == 6 - packet->packet_direction) {
if ((packet->payload_packet_len == 4) && if ((packet->payload_packet_len == 4) &&
(get_u_int32_t(packet->payload, 0) == htonl(0x10000000) || get_u_int32_t(packet->payload, 0) == htonl(0x30000000))) { (get_u_int32_t(packet->payload, 0) == htonl(0x10000000) || get_u_int32_t(packet->payload, 0) == htonl(0x30000000))) {
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN File Transfer detected 3\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 3\n");
return; return;
} }
} else if (flow->l4.tcp.msn_stage == 5 + packet->packet_direction) { } else if (flow->l4.tcp.msn_stage == 5 + packet->packet_direction) {
if ((packet->payload_packet_len == 20) && get_u_int32_t(packet->payload, 0) == htonl(0x10000000)) { if ((packet->payload_packet_len == 20) && get_u_int32_t(packet->payload, 0) == htonl(0x10000000)) {
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN File Transfer detected 3\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 3\n");
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_DEBUG, "msn 7.\n"); NDPI_LOG_DBG(ndpi_struct, "msn 7\n");
if (flow->packet_counter <= MAX_PACKETS_FOR_MSN) { if (flow->packet_counter <= MAX_PACKETS_FOR_MSN) {
if (memcmp(&packet->payload[0], "MSG ", 4) == 0 if (memcmp(&packet->payload[0], "MSG ", 4) == 0
@@ -459,13 +453,12 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
|| memcmp(&packet->payload[0], "XFR ", 4) == 0) { || memcmp(&packet->payload[0], "XFR ", 4) == 0) {
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN detected\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN\n");
return; return;
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "MSN tcp excluded.\n");
ndpi_msn_exclude: ndpi_msn_exclude:
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSN); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
/* search over UDP */ /* search over UDP */
@@ -482,7 +475,7 @@ static void ndpi_search_msn_udp_misc(struct ndpi_detection_module_struct
if ((src == NULL || NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0) if ((src == NULL || NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0)
&& (dst == NULL && (dst == NULL
|| NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0)) { || NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0)) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSN); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
@@ -490,7 +483,7 @@ static void ndpi_search_msn_udp_misc(struct ndpi_detection_module_struct
if (packet->payload_packet_len == 20 if (packet->payload_packet_len == 20
&& get_u_int32_t(packet->payload, 4) == 0 && packet->payload[9] == 0 && get_u_int32_t(packet->payload, 4) == 0 && packet->payload[9] == 0
&& get_u_int16_t(packet->payload, 10) == htons(0x0100)) { && get_u_int16_t(packet->payload, 10) == htons(0x0100)) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE, "msn udp misc data connection detected\n"); NDPI_LOG_INFO(ndpi_struct, "found MSN udp misc data connection\n");
ndpi_int_msn_add_connection(ndpi_struct, flow); ndpi_int_msn_add_connection(ndpi_struct, flow);
} }
@@ -504,6 +497,7 @@ void ndpi_search_msn(struct ndpi_detection_module_struct *ndpi_struct, struct nd
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search msn\n");
/* this if request should always be true */ /* this if request should always be true */
if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0) { if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0) {
/* we deal with tcp now */ /* we deal with tcp now */
+11 -6
View File
@@ -22,10 +22,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MSSQL_TDS #ifdef NDPI_PROTOCOL_MSSQL_TDS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MSSQL_TDS
#include "ndpi_api.h"
struct tds_packet_header { struct tds_packet_header {
u_int8_t type; u_int8_t type;
u_int8_t status; u_int8_t status;
@@ -46,24 +51,24 @@ void ndpi_search_mssql_tds(struct ndpi_detection_module_struct *ndpi_struct, str
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
struct tds_packet_header *h = (struct tds_packet_header*) packet->payload; struct tds_packet_header *h = (struct tds_packet_header*) packet->payload;
NDPI_LOG_DBG(ndpi_struct, "search mssql_tds\n");
if(packet->payload_packet_len < sizeof(struct tds_packet_header)) { if(packet->payload_packet_len < sizeof(struct tds_packet_header)) {
NDPI_LOG(NDPI_PROTOCOL_MSSQL_TDS, ndpi_struct, NDPI_LOG_DEBUG, "exclude mssql_tds\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSSQL_TDS);
return; return;
} }
if((h->type >= 1 && h->type <= 8) || (h->type >= 14 && h->type <= 18)) { if((h->type >= 1 && h->type <= 8) || (h->type >= 14 && h->type <= 18)) {
if(h->status == 0x00 || h->status == 0x01 || h->status == 0x02 || h->status == 0x04 || h->status == 0x08 || h->status == 0x09 || h->status == 0x10) { if(h->status == 0x00 || h->status == 0x01 || h->status == 0x02 || h->status == 0x04 || h->status == 0x08 || h->status == 0x09 || h->status == 0x10) {
if(ntohs(h->length) == packet->payload_packet_len && h->window == 0x00) { if(ntohs(h->length) == packet->payload_packet_len && h->window == 0x00) {
NDPI_LOG(NDPI_PROTOCOL_MSSQL_TDS, ndpi_struct, NDPI_LOG_DEBUG, "found mssql_tds\n"); NDPI_LOG_INFO(ndpi_struct, "found mssql_tds\n");
ndpi_int_mssql_tds_add_connection(ndpi_struct, flow); ndpi_int_mssql_tds_add_connection(ndpi_struct, flow);
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_MSSQL_TDS, ndpi_struct, NDPI_LOG_DEBUG, "exclude mssql_tds\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSSQL_TDS);
} }
+10 -5
View File
@@ -23,10 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_MYSQL #ifdef NDPI_PROTOCOL_MYSQL
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MYSQL
#include "ndpi_api.h"
static void ndpi_int_mysql_add_connection(struct ndpi_detection_module_struct static void ndpi_int_mysql_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -36,9 +41,9 @@ static void ndpi_int_mysql_add_connection(struct ndpi_detection_module_struct
void ndpi_search_mysql_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_mysql_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search MySQL\n");
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if(packet->tcp) { if(packet->tcp) {
if (packet->payload_packet_len > 38 //min length if (packet->payload_packet_len > 38 //min length
&& get_u_int16_t(packet->payload, 0) == packet->payload_packet_len - 4 //first 3 bytes are length && get_u_int16_t(packet->payload, 0) == packet->payload_packet_len - 4 //first 3 bytes are length
@@ -55,7 +60,7 @@ void ndpi_search_mysql_tcp(struct ndpi_detection_module_struct *ndpi_struct, str
&& get_u_int64_t(packet->payload, a + 19) == 0x0ULL //13 more && get_u_int64_t(packet->payload, a + 19) == 0x0ULL //13 more
&& get_u_int32_t(packet->payload, a + 27) == 0x0 //filler bytes && get_u_int32_t(packet->payload, a + 27) == 0x0 //filler bytes
&& get_u_int8_t(packet->payload, a + 31) == 0x0) { && get_u_int8_t(packet->payload, a + 31) == 0x0) {
NDPI_LOG(NDPI_PROTOCOL_MYSQL, ndpi_struct, NDPI_LOG_DEBUG, "MySQL detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found MySQL\n");
ndpi_int_mysql_add_connection(ndpi_struct, flow); ndpi_int_mysql_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -65,7 +70,7 @@ void ndpi_search_mysql_tcp(struct ndpi_detection_module_struct *ndpi_struct, str
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MYSQL); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+38 -51
View File
@@ -23,10 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_NETBIOS #ifdef NDPI_PROTOCOL_NETBIOS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NETBIOS
#include "ndpi_api.h"
struct netbios_header { struct netbios_header {
u_int16_t transaction_id, flags, questions, answer_rrs, authority_rrs, additional_rrs; u_int16_t transaction_id, flags, questions, answer_rrs, authority_rrs, additional_rrs;
}; };
@@ -81,10 +86,10 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
u_int16_t dport; u_int16_t dport;
char name[64]; char name[64];
NDPI_LOG_DBG(ndpi_struct, "search netbios\n");
if(packet->udp != NULL) { if(packet->udp != NULL) {
dport = ntohs(packet->udp->dest); dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, "netbios udp start\n");
/*check standard NETBIOS over udp to port 137 */ /*check standard NETBIOS over udp to port 137 */
if((dport == 137 || 0) && packet->payload_packet_len >= 50) { if((dport == 137 || 0) && packet->payload_packet_len >= 50) {
@@ -95,16 +100,14 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.questions = ntohs(h.questions), h.answer_rrs = ntohs(h.answer_rrs), h.questions = ntohs(h.questions), h.answer_rrs = ntohs(h.answer_rrs),
h.authority_rrs = ntohs(h.authority_rrs), h.additional_rrs = ntohs(h.additional_rrs); h.authority_rrs = ntohs(h.authority_rrs), h.additional_rrs = ntohs(h.additional_rrs);
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DBG(ndpi_struct, "found netbios port 137 and payload_packet_len 50\n");
NDPI_LOG_DEBUG, "found netbios port 137 and payload_packet_len 50\n");
if(h.flags == 0 && if(h.flags == 0 &&
h.questions == 1 && h.questions == 1 &&
h.answer_rrs == 0 && h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 0) { h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers = 0, authority = 0 \n");
NDPI_LOG_DEBUG, "found netbios with questions = 1 and answers = 0, authority = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -114,8 +117,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 0 && h.answer_rrs == 0 &&
h.authority_rrs == 0) { h.authority_rrs == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers = 0, authority = 0 and broadcast \n");
NDPI_LOG_DEBUG, "found netbios with questions = 1 and answers = 0, authority = 0 and broadcast \n");
if(ndpi_netbios_name_interpret((char*)&packet->payload[12], name, sizeof(name)) > 0) if(ndpi_netbios_name_interpret((char*)&packet->payload[12], name, sizeof(name)) > 0)
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name); snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name);
@@ -128,8 +130,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 0 && h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) { h.authority_rrs == 0 && h.additional_rrs == 1) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers, authority, additional = 0 \n");
NDPI_LOG_DEBUG, "found netbios with questions = 1 and answers, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -139,8 +140,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 0 && h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) { h.authority_rrs == 0 && h.additional_rrs == 1) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers = 0, authority = 0 \n");
NDPI_LOG_DEBUG, "found netbios with questions = 1 and answers = 0, authority = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -150,8 +150,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 1 && h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) { h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct,
NDPI_LOG_DEBUG,
"found netbios with flag 8400 questions = 0 and answers = 1, authority, additional = 0 \n"); "found netbios with flag 8400 questions = 0 and answers = 1, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
@@ -162,8 +161,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 1 && h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) { h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct,
NDPI_LOG_DEBUG,
"found netbios with flag 8500 questions = 0 and answers = 1, authority, additional = 0 \n"); "found netbios with flag 8500 questions = 0 and answers = 1, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
@@ -174,8 +172,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 0 && h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) { h.authority_rrs == 0 && h.additional_rrs == 1) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct,
NDPI_LOG_DEBUG,
"found netbios with flag 2910, questions = 1 and answers, authority=0, additional = 1 \n"); "found netbios with flag 2910, questions = 1 and answers, authority=0, additional = 1 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
@@ -186,8 +183,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 1 && h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) { h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct,
NDPI_LOG_DEBUG,
"found netbios with flag ad86 questions = 0 and answers = 1, authority, additional = 0 \n"); "found netbios with flag ad86 questions = 0 and answers = 1, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
@@ -198,8 +194,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
h.answer_rrs == 0 && h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 0) { h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct,
NDPI_LOG_DEBUG,
"found netbios with flag 0110 questions = 1 and answers = 0, authority, additional = 0 \n"); "found netbios with flag 0110 questions = 1 and answers = 0, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
@@ -208,7 +203,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
if((h.flags & 0xf800) == 0) { if((h.flags & 0xf800) == 0) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, "possible netbios name query request\n"); NDPI_LOG_DBG2(ndpi_struct, "possible netbios name query request\n");
if(get_u_int16_t(packet->payload, 4) == htons(1) && if(get_u_int16_t(packet->payload, 4) == htons(1) &&
get_u_int16_t(packet->payload, 6) == 0 && get_u_int16_t(packet->payload, 6) == 0 &&
@@ -217,12 +212,12 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
/* name is encoded as described in rfc883 */ /* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12]; u_int8_t name_length = packet->payload[12];
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query request, one question\n"); "possible netbios name query request, one question\n");
if(packet->payload_packet_len == 12 + 1 + name_length + 1 + 2 + 2) { if(packet->payload_packet_len == 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query request, length matches\n"); "possible netbios name query request, length matches\n");
/* null terminated? */ /* null terminated? */
@@ -230,7 +225,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) && get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) { get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found netbios name query request\n"); "found netbios name query request\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -238,7 +233,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
} }
} }
} else if((h.flags & 0xf800) == 0x8000) { } else if((h.flags & 0xf800) == 0x8000) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response\n"); "possible netbios name query response\n");
if(get_u_int16_t(packet->payload, 4) == 0 && if(get_u_int16_t(packet->payload, 4) == 0 &&
@@ -248,12 +243,12 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
/* name is encoded as described in rfc883 */ /* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12]; u_int8_t name_length = packet->payload[12];
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios positive name query response, one answer\n"); "possible netbios positive name query response, one answer\n");
if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) { if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response, length matches\n"); "possible netbios name query response, length matches\n");
/* null terminated? */ /* null terminated? */
@@ -261,7 +256,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) && get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) { get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found netbios name query response\n"); "found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -274,12 +269,12 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
/* name is encoded as described in rfc883 */ /* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12]; u_int8_t name_length = packet->payload[12];
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios negative name query response, one answer\n"); "possible netbios negative name query response, one answer\n");
if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) { if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response, length matches\n"); "possible netbios name query response, length matches\n");
/* null terminated? */ /* null terminated? */
@@ -287,7 +282,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x000A) && get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x000A) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) { get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found netbios name query response\n"); "found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -300,12 +295,12 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
/* name is encoded as described in rfc883 */ /* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12]; u_int8_t name_length = packet->payload[12];
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios redirect name query response, one answer\n"); "possible netbios redirect name query response, one answer\n");
if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) { if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response, length matches\n"); "possible netbios name query response, length matches\n");
/* null terminated? */ /* null terminated? */
@@ -313,7 +308,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0002) && get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0002) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) { get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"found netbios name query response\n"); "found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
return; return;
@@ -332,17 +327,14 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
packet->payload_packet_len >= 14 && packet->payload_packet_len >= 14 &&
ntohs(get_u_int16_t(packet->payload, 10)) == packet->payload_packet_len - 14) { ntohs(get_u_int16_t(packet->payload, 10)) == packet->payload_packet_len - 14) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "found netbios port 138 and payload length >= 112 \n");
NDPI_LOG_DEBUG, "found netbios port 138 and payload length >= 112 \n");
if(packet->payload[0] >= 0x11 && packet->payload[0] <= 0x16) { if(packet->payload[0] >= 0x11 && packet->payload[0] <= 0x16) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "found netbios with MSG-type 0x11,0x12,0x13,0x14,0x15 or 0x16\n");
NDPI_LOG_DEBUG, "found netbios with MSG-type 0x11,0x12,0x13,0x14,0x15 or 0x16\n");
if(ntohl(get_u_int32_t(packet->payload, 4)) == ntohl(packet->iph->saddr)) { if(ntohl(get_u_int32_t(packet->payload, 4)) == ntohl(packet->iph->saddr)) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct, "found netbios with checked ip-address\n");
NDPI_LOG_DEBUG, "found netbios with checked ip-address.\n");
if(ndpi_netbios_name_interpret((char*)&packet->payload[12], name, sizeof(name)) > 0) if(ndpi_netbios_name_interpret((char*)&packet->payload[12], name, sizeof(name)) > 0)
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name); snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name);
@@ -357,21 +349,17 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
if(packet->tcp != NULL) { if(packet->tcp != NULL) {
dport = ntohs(packet->tcp->dest); dport = ntohs(packet->tcp->dest);
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, "netbios tcp start\n");
/* destination port must be 139 */ /* destination port must be 139 */
if(dport == 139) { if(dport == 139) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, "found netbios with destination port 139\n"); NDPI_LOG_DBG2(ndpi_struct, "found netbios with destination port 139\n");
/* payload_packet_len must be 72 */ /* payload_packet_len must be 72 */
if(packet->payload_packet_len == 72) { if(packet->payload_packet_len == 72) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DBG2(ndpi_struct, "found netbios with payload_packen_len = 72. \n");
NDPI_LOG_DEBUG, "found netbios with payload_packen_len = 72. \n");
if(packet->payload[0] == 0x81 && packet->payload[1] == 0 && ntohs(get_u_int16_t(packet->payload, 2)) == 68) { if(packet->payload[0] == 0x81 && packet->payload[1] == 0 && ntohs(get_u_int16_t(packet->payload, 2)) == 68) {
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_INFO(ndpi_struct,
NDPI_LOG_DEBUG,
"found netbios with session request = 81, flags=0 and length od following bytes = 68. \n"); "found netbios with session request = 81, flags=0 and length od following bytes = 68. \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow); ndpi_int_netbios_add_connection(ndpi_struct, flow);
@@ -382,8 +370,7 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
} }
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct, NDPI_LOG_DEBUG, "exclude netbios\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NETBIOS);
} }
void init_netbios_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_netbios_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+10 -11
View File
@@ -18,10 +18,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_NETFLOW
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NETFLOW
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_NETFLOW
#ifdef WIN32 #ifdef WIN32
extern int gettimeofday(struct timeval * tp, struct timezone * tzp); extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
@@ -95,7 +99,7 @@ struct flow_ver7_rec {
u_int32_t router_sc; /* Router which is shortcut by switch */ u_int32_t router_sc; /* Router which is shortcut by switch */
}; };
static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// const u_int8_t *packet_payload = packet->payload; // const u_int8_t *packet_payload = packet->payload;
@@ -103,6 +107,8 @@ static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct,
time_t now; time_t now;
struct timeval now_tv; struct timeval now_tv;
NDPI_LOG_DBG(ndpi_struct, "search netflow\n");
if((packet->udp != NULL) && (payload_len >= 24)) { if((packet->udp != NULL) && (payload_len >= 24)) {
u_int16_t version = (packet->payload[0] << 8) + packet->payload[1], uptime_offset; u_int16_t version = (packet->payload[0] << 8) + packet->payload[1], uptime_offset;
u_int32_t when, *_when; u_int32_t when, *_when;
@@ -132,7 +138,7 @@ static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct,
} }
if((expected_len > 0) && (expected_len != payload_len)) { if((expected_len > 0) && (expected_len != payload_len)) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NETFLOW); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
@@ -159,20 +165,13 @@ static void ndpi_check_netflow(struct ndpi_detection_module_struct *ndpi_struct,
if(((version == 1) && (when == 0)) if(((version == 1) && (when == 0))
|| ((when >= 946684800 /* 1/1/2000 */) && (when <= now))) { || ((when >= 946684800 /* 1/1/2000 */) && (when <= now))) {
NDPI_LOG(NDPI_PROTOCOL_NETFLOW, ndpi_struct, NDPI_LOG_DEBUG, "Found netflow.\n"); NDPI_LOG_INFO(ndpi_struct, "found netflow\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETFLOW, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETFLOW, NDPI_PROTOCOL_UNKNOWN);
return; return;
} }
} }
} }
void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
NDPI_LOG(NDPI_PROTOCOL_NETFLOW, ndpi_struct, NDPI_LOG_DEBUG, "netflow detection...\n");
ndpi_check_netflow(ndpi_struct, flow);
}
void init_netflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) void init_netflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{ {
ndpi_set_bitmask_protocol_detection("NetFlow", ndpi_struct, detection_bitmask, *id, ndpi_set_bitmask_protocol_detection("NetFlow", ndpi_struct, detection_bitmask, *id,
+14 -10
View File
@@ -23,10 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_NFS #ifdef NDPI_PROTOCOL_NFS
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NFS
#include "ndpi_api.h"
static void ndpi_int_nfs_add_connection(struct ndpi_detection_module_struct static void ndpi_int_nfs_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -37,8 +42,7 @@ void ndpi_search_nfs(struct ndpi_detection_module_struct *ndpi_struct, struct nd
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src; NDPI_LOG_DBG(ndpi_struct, "search NFS\n");
// struct ndpi_id_struct *dst=ndpi_struct->dst;
u_int8_t offset = 0; u_int8_t offset = 0;
if (packet->tcp != NULL) if (packet->tcp != NULL)
@@ -47,41 +51,41 @@ void ndpi_search_nfs(struct ndpi_detection_module_struct *ndpi_struct, struct nd
if (packet->payload_packet_len < (40 + offset)) if (packet->payload_packet_len < (40 + offset))
goto exclude_nfs; goto exclude_nfs;
NDPI_LOG(NDPI_PROTOCOL_NFS, ndpi_struct, NDPI_LOG_DEBUG, "NFS user match stage 1\n"); NDPI_LOG_DBG2(ndpi_struct, "NFS user match stage 1\n");
if (offset != 0 && get_u_int32_t(packet->payload, 0) != htonl(0x80000000 + packet->payload_packet_len - 4)) if (offset != 0 && get_u_int32_t(packet->payload, 0) != htonl(0x80000000 + packet->payload_packet_len - 4))
goto exclude_nfs; goto exclude_nfs;
NDPI_LOG(NDPI_PROTOCOL_NFS, ndpi_struct, NDPI_LOG_DEBUG, "NFS user match stage 2\n"); NDPI_LOG_DBG2(ndpi_struct, "NFS user match stage 2\n");
if (get_u_int32_t(packet->payload, 4 + offset) != 0) if (get_u_int32_t(packet->payload, 4 + offset) != 0)
goto exclude_nfs; goto exclude_nfs;
NDPI_LOG(NDPI_PROTOCOL_NFS, ndpi_struct, NDPI_LOG_DEBUG, "NFS user match stage 3\n"); NDPI_LOG_DBG2(ndpi_struct, "NFS user match stage 3\n");
if (get_u_int32_t(packet->payload, 8 + offset) != htonl(0x02)) if (get_u_int32_t(packet->payload, 8 + offset) != htonl(0x02))
goto exclude_nfs; goto exclude_nfs;
NDPI_LOG(NDPI_PROTOCOL_NFS, ndpi_struct, NDPI_LOG_DEBUG, "NFS match stage 3\n"); NDPI_LOG_DBG2(ndpi_struct, "NFS match stage 3\n");
if (get_u_int32_t(packet->payload, 12 + offset) != htonl(0x000186a5) if (get_u_int32_t(packet->payload, 12 + offset) != htonl(0x000186a5)
&& get_u_int32_t(packet->payload, 12 + offset) != htonl(0x000186a3) && get_u_int32_t(packet->payload, 12 + offset) != htonl(0x000186a3)
&& get_u_int32_t(packet->payload, 12 + offset) != htonl(0x000186a0)) && get_u_int32_t(packet->payload, 12 + offset) != htonl(0x000186a0))
goto exclude_nfs; goto exclude_nfs;
NDPI_LOG(NDPI_PROTOCOL_NFS, ndpi_struct, NDPI_LOG_DEBUG, "NFS match stage 4\n"); NDPI_LOG_DBG2(ndpi_struct, "NFS match stage 4\n");
if (ntohl(get_u_int32_t(packet->payload, 16 + offset)) > 4) if (ntohl(get_u_int32_t(packet->payload, 16 + offset)) > 4)
goto exclude_nfs; goto exclude_nfs;
NDPI_LOG(NDPI_PROTOCOL_NFS, ndpi_struct, NDPI_LOG_DEBUG, "NFS match\n"); NDPI_LOG_INFO(ndpi_struct, "found NFS\n");
ndpi_int_nfs_add_connection(ndpi_struct, flow); ndpi_int_nfs_add_connection(ndpi_struct, flow);
return; return;
exclude_nfs: exclude_nfs:
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NFS); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+7 -5
View File
@@ -21,11 +21,14 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_NINTENDO #ifdef NDPI_PROTOCOL_NINTENDO
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NINTENDO
#include "ndpi_api.h"
static void ndpi_int_nintendo_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_nintendo_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
u_int8_t due_to_correlation) { u_int8_t due_to_correlation) {
@@ -43,15 +46,14 @@ void ndpi_search_nintendo(struct ndpi_detection_module_struct *ndpi_struct, stru
const char nintendo_pattern[] = { 0x32, 0xab, 0x98, 0x64, 0x02 }; const char nintendo_pattern[] = { 0x32, 0xab, 0x98, 0x64, 0x02 };
if(memcmp(payload, nintendo_pattern, 5) == 0) { if(memcmp(payload, nintendo_pattern, 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_NINTENDO, ndpi_struct, NDPI_LOG_DEBUG, "Found nintendo.\n"); NDPI_LOG_INFO(ndpi_struct, "found nintendo\n");
ndpi_int_nintendo_add_connection(ndpi_struct, flow, 0); ndpi_int_nintendo_add_connection(ndpi_struct, flow, 0);
return; return;
} }
} }
} }
NDPI_LOG(NDPI_PROTOCOL_NINTENDO, ndpi_struct, NDPI_LOG_DEBUG, "Exclude Nintendo.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NINTENDO);
} }
void init_nintendo_dissector(struct ndpi_detection_module_struct *ndpi_struct, void init_nintendo_dissector(struct ndpi_detection_module_struct *ndpi_struct,
+11 -8
View File
@@ -5,28 +5,32 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_NOE
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NOE
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_NOE
static void ndpi_int_noe_add_connection(struct ndpi_detection_module_struct static void ndpi_int_noe_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NOE, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NOE, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_INFO(ndpi_struct, "found noe\n");
} }
void ndpi_search_noe(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_noe(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_NOE, ndpi_struct, NDPI_LOG_DEBUG, "search for NOE.\n"); NDPI_LOG_DBG(ndpi_struct, "search NOE\n");
if(packet->udp != NULL) { if(packet->udp != NULL) {
NDPI_LOG(NDPI_PROTOCOL_NOE, ndpi_struct, NDPI_LOG_DEBUG, "calculating dport over udp.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculating dport over udp\n");
if (packet->payload_packet_len == 1 && ( packet->payload[0] == 0x05 || packet->payload[0] == 0x04 )) { if (packet->payload_packet_len == 1 && ( packet->payload[0] == 0x05 || packet->payload[0] == 0x04 )) {
NDPI_LOG(NDPI_PROTOCOL_NOE, ndpi_struct, NDPI_LOG_DEBUG, "found noe.\n");
ndpi_int_noe_add_connection(ndpi_struct, flow); ndpi_int_noe_add_connection(ndpi_struct, flow);
return; return;
} else if((packet->payload_packet_len == 5 || packet->payload_packet_len == 12) && } else if((packet->payload_packet_len == 5 || packet->payload_packet_len == 12) &&
@@ -34,19 +38,18 @@ void ndpi_search_noe(struct ndpi_detection_module_struct *ndpi_struct, struct nd
(packet->payload[1] == 0x00 ) && (packet->payload[1] == 0x00 ) &&
(packet->payload[2] != 0x00 ) && (packet->payload[2] != 0x00 ) &&
(packet->payload[3] == 0x00 )) { (packet->payload[3] == 0x00 )) {
NDPI_LOG(NDPI_PROTOCOL_NOE, ndpi_struct, NDPI_LOG_DEBUG, "found noe.\n");
ndpi_int_noe_add_connection(ndpi_struct, flow); ndpi_int_noe_add_connection(ndpi_struct, flow);
return;
} else if((packet->payload_packet_len >= 25) && } else if((packet->payload_packet_len >= 25) &&
(packet->payload[0] == 0x00 && (packet->payload[0] == 0x00 &&
packet->payload[1] == 0x06 && packet->payload[1] == 0x06 &&
packet->payload[2] == 0x62 && packet->payload[2] == 0x62 &&
packet->payload[3] == 0x6c)) { packet->payload[3] == 0x6c)) {
NDPI_LOG(NDPI_PROTOCOL_NOE, ndpi_struct, NDPI_LOG_DEBUG, "found noe.\n");
ndpi_int_noe_add_connection(ndpi_struct, flow); ndpi_int_noe_add_connection(ndpi_struct, flow);
return;
} }
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_NOE, ndpi_struct, NDPI_LOG_DEBUG, "exclude NOE.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NOE);
} }
} }
+20 -20
View File
@@ -22,10 +22,13 @@
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_NTP #ifdef NDPI_PROTOCOL_NTP
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NTP
#include "ndpi_api.h"
static void ndpi_int_ntp_add_connection(struct ndpi_detection_module_struct static void ndpi_int_ntp_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -37,31 +40,28 @@ void ndpi_search_ntp_udp(struct ndpi_detection_module_struct *ndpi_struct, struc
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
if (!(packet->udp->dest == htons(123) || packet->udp->source == htons(123))) NDPI_LOG_DBG(ndpi_struct, "search NTP\n");
goto exclude_ntp;
if (packet->udp->dest == htons(123) || packet->udp->source == htons(123)) {
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP port detected\n"); NDPI_LOG_DBG2(ndpi_struct, "NTP port and length detected\n");
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP length detected\n"); if ((((packet->payload[0] & 0x38) >> 3) <= 4)) {
if ((((packet->payload[0] & 0x38) >> 3) <= 4)) {
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "detected NTP.");
// 38 in binary representation is 00111000 // 38 in binary representation is 00111000
flow->protos.ntp.version = (packet->payload[0] & 0x38) >> 3; flow->protos.ntp.version = (packet->payload[0] & 0x38) >> 3;
if (flow->protos.ntp.version == 2) { if (flow->protos.ntp.version == 2) {
flow->protos.ntp.request_code = packet->payload[3]; flow->protos.ntp.request_code = packet->payload[3];
}
NDPI_LOG_INFO(ndpi_struct, "found NTP\n");
ndpi_int_ntp_add_connection(ndpi_struct, flow);
return;
} }
ndpi_int_ntp_add_connection(ndpi_struct, flow);
return;
} }
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
exclude_ntp:
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP excluded.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_NTP);
} }
+8 -7
View File
@@ -22,9 +22,13 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_OPENFT
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OPENFT
#include "ndpi_protocols.h" #include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_OPENFT
static void ndpi_int_openft_add_connection(struct ndpi_detection_module_struct static void ndpi_int_openft_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -37,21 +41,18 @@ void ndpi_search_openft_tcp(struct ndpi_detection_module_struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (packet->payload_packet_len > 5 && memcmp(packet->payload, "GET /", 5) == 0) { if (packet->payload_packet_len > 5 && memcmp(packet->payload, "GET /", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OPENFT, ndpi_struct, NDPI_LOG_DEBUG, "HTTP packet detected.\n"); NDPI_LOG_DBG2(ndpi_struct, "HTTP packet detected\n");
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->parsed_lines >= 2 if (packet->parsed_lines >= 2
&& packet->line[1].len > 13 && memcmp(packet->line[1].ptr, "X-OpenftAlias:", 14) == 0) { && packet->line[1].len > 13 && memcmp(packet->line[1].ptr, "X-OpenftAlias:", 14) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OPENFT, ndpi_struct, NDPI_LOG_DEBUG, "OpenFT detected.\n"); NDPI_LOG_INFO(ndpi_struct, "found OpenFT\n");
ndpi_int_openft_add_connection(ndpi_struct, flow); ndpi_int_openft_add_connection(ndpi_struct, flow);
return; return;
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OPENFT); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+15 -7
View File
@@ -21,10 +21,15 @@
* *
*/ */
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_OPENVPN #ifdef NDPI_PROTOCOL_OPENVPN
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OPENVPN
#include "ndpi_api.h"
#define P_CONTROL_HARD_RESET_CLIENT_V1 (0x01 << 3) #define P_CONTROL_HARD_RESET_CLIENT_V1 (0x01 << 3)
#define P_CONTROL_HARD_RESET_CLIENT_V2 (0x07 << 3) #define P_CONTROL_HARD_RESET_CLIENT_V2 (0x07 << 3)
#define P_CONTROL_HARD_RESET_SERVER_V1 (0x02 << 3) #define P_CONTROL_HARD_RESET_SERVER_V1 (0x02 << 3)
@@ -81,7 +86,7 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
if (check_pkid_and_detect_hmac_size(ovpn_payload) > 0) { if (check_pkid_and_detect_hmac_size(ovpn_payload) > 0) {
memcpy(flow->ovpn_session_id, ovpn_payload+1, 8); memcpy(flow->ovpn_session_id, ovpn_payload+1, 8);
NDPI_LOG(NDPI_PROTOCOL_OPENVPN, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"session key: %02x%02x%02x%02x%02x%02x%02x%02x\n", "session key: %02x%02x%02x%02x%02x%02x%02x%02x\n",
flow->ovpn_session_id[0], flow->ovpn_session_id[1], flow->ovpn_session_id[2], flow->ovpn_session_id[3], flow->ovpn_session_id[0], flow->ovpn_session_id[1], flow->ovpn_session_id[2], flow->ovpn_session_id[3],
flow->ovpn_session_id[4], flow->ovpn_session_id[5], flow->ovpn_session_id[6], flow->ovpn_session_id[7]); flow->ovpn_session_id[4], flow->ovpn_session_id[5], flow->ovpn_session_id[6], flow->ovpn_session_id[7]);
@@ -95,10 +100,12 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
alen = ovpn_payload[P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size)]; alen = ovpn_payload[P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size)];
session_remote = ovpn_payload + P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size) + 1 + alen * 4; session_remote = ovpn_payload + P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size) + 1 + alen * 4;
if (memcmp(flow->ovpn_session_id, session_remote, 8) == 0) if (memcmp(flow->ovpn_session_id, session_remote, 8) == 0) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OPENVPN, NDPI_PROTOCOL_UNKNOWN); NDPI_LOG_INFO(ndpi_struct,"found openvpn\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OPENVPN, NDPI_PROTOCOL_UNKNOWN);
}
else { else {
NDPI_LOG(NDPI_PROTOCOL_OPENVPN, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_DBG2(ndpi_struct,
"key mismatch: %02x%02x%02x%02x%02x%02x%02x%02x\n", "key mismatch: %02x%02x%02x%02x%02x%02x%02x%02x\n",
session_remote[0], session_remote[1], session_remote[2], session_remote[3], session_remote[0], session_remote[1], session_remote[2], session_remote[3],
session_remote[4], session_remote[5], session_remote[6], session_remote[7]); session_remote[4], session_remote[5], session_remote[6], session_remote[7]);
@@ -111,8 +118,9 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
flow->ovpn_counter++; flow->ovpn_counter++;
if (failed) if (failed) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OPENVPN); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
} }
} }
+10 -7
View File
@@ -18,11 +18,15 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_ORACLE
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_ORACLE
#include "ndpi_api.h" #include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_ORACLE
static void ndpi_int_oracle_add_connection(struct ndpi_detection_module_struct static void ndpi_int_oracle_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -34,11 +38,11 @@ void ndpi_search_oracle(struct ndpi_detection_module_struct *ndpi_struct, struct
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t dport = 0, sport = 0; u_int16_t dport = 0, sport = 0;
NDPI_LOG(NDPI_PROTOCOL_ORACLE, ndpi_struct, NDPI_LOG_DEBUG, "search for ORACLE.\n"); NDPI_LOG_DBG(ndpi_struct, "search ORACLE\n");
if(packet->tcp != NULL) { if(packet->tcp != NULL) {
sport = ntohs(packet->tcp->source), dport = ntohs(packet->tcp->dest); sport = ntohs(packet->tcp->source), dport = ntohs(packet->tcp->dest);
NDPI_LOG(NDPI_PROTOCOL_ORACLE, ndpi_struct, NDPI_LOG_DEBUG, "calculating ORACLE over tcp.\n"); NDPI_LOG_DBG2(ndpi_struct, "calculating ORACLE over tcp\n");
/* Oracle Database 9g,10g,11g */ /* Oracle Database 9g,10g,11g */
if ((dport == 1521 || sport == 1521) if ((dport == 1521 || sport == 1521)
&& (((packet->payload[0] == 0x07) && (packet->payload[1] == 0xff) && (packet->payload[2] == 0x00)) && (((packet->payload[0] == 0x07) && (packet->payload[1] == 0xff) && (packet->payload[2] == 0x00))
@@ -46,17 +50,16 @@ void ndpi_search_oracle(struct ndpi_detection_module_struct *ndpi_struct, struct
&& (packet->payload[1] != 0x00) && (packet->payload[1] != 0x00)
&& (packet->payload[2] == 0x00) && (packet->payload[2] == 0x00)
&& (packet->payload[3] == 0x00)))) { && (packet->payload[3] == 0x00)))) {
NDPI_LOG(NDPI_PROTOCOL_ORACLE, ndpi_struct, NDPI_LOG_DEBUG, "found oracle.\n"); NDPI_LOG_INFO(ndpi_struct, "found oracle\n");
ndpi_int_oracle_add_connection(ndpi_struct, flow); ndpi_int_oracle_add_connection(ndpi_struct, flow);
} else if (packet->payload_packet_len == 213 && packet->payload[0] == 0x00 && } else if (packet->payload_packet_len == 213 && packet->payload[0] == 0x00 &&
packet->payload[1] == 0xd5 && packet->payload[2] == 0x00 && packet->payload[1] == 0xd5 && packet->payload[2] == 0x00 &&
packet->payload[3] == 0x00 ) { packet->payload[3] == 0x00 ) {
NDPI_LOG(NDPI_PROTOCOL_ORACLE, ndpi_struct, NDPI_LOG_DEBUG, "found oracle.\n"); NDPI_LOG_INFO(ndpi_struct, "found oracle\n");
ndpi_int_oracle_add_connection(ndpi_struct, flow); ndpi_int_oracle_add_connection(ndpi_struct, flow);
} }
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_ORACLE, ndpi_struct, NDPI_LOG_DEBUG, "exclude ORACLE.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_ORACLE);
} }
} }
+39 -36
View File
@@ -22,6 +22,11 @@
* *
*/ */
#include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_OSCAR
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OSCAR
#include "ndpi_api.h" #include "ndpi_api.h"
@@ -69,7 +74,6 @@
#define EMAIL 0x0018 #define EMAIL 0x0018
#define IS_EXT 0x0085 #define IS_EXT 0x0085
#ifdef NDPI_PROTOCOL_OSCAR
static void ndpi_int_oscar_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_oscar_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
@@ -146,28 +150,28 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
/* No TLVs */ /* No TLVs */
if(packet->payload_packet_len == 10) if(packet->payload_packet_len == 10)
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Sign In \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Sign In \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
/* /\* SCREEN_NAME *\/ */ /* /\* SCREEN_NAME *\/ */
/* if (get_u_int16_t(packet->payload, 10) == htons(SCREEN_NAME)) /\* packet->payload[10] == 0x00 && packet->payload[11] == 0x01 *\/ */ /* if (get_u_int16_t(packet->payload, 10) == htons(SCREEN_NAME)) /\* packet->payload[10] == 0x00 && packet->payload[11] == 0x01 *\/ */
/* { */ /* { */
/* NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Screen Name \n"); */ /* NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Screen Name \n"); */
/* ndpi_int_oscar_add_connection(ndpi_struct, flow); */ /* ndpi_int_oscar_add_connection(ndpi_struct, flow); */
/* return; */ /* return; */
/* } */ /* } */
/* /\* PASSWD *\/ */ /* /\* PASSWD *\/ */
/* if (get_u_int16_t(packet->payload, 10) == htons(PASSWD)) /\* packet->payload[10] == 0x00 && packet->payload[11] == 0x02 *\/ */ /* if (get_u_int16_t(packet->payload, 10) == htons(PASSWD)) /\* packet->payload[10] == 0x00 && packet->payload[11] == 0x02 *\/ */
/* { */ /* { */
/* NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Password (roasted) \n"); */ /* NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Password (roasted) \n"); */
/* ndpi_int_oscar_add_connection(ndpi_struct, flow); */ /* ndpi_int_oscar_add_connection(ndpi_struct, flow); */
/* return; */ /* return; */
/* } */ /* } */
/* CLIENT_NAME */ /* CLIENT_NAME */
if (get_u_int16_t(packet->payload, 10) == htons(CLIENT_NAME)) /* packet->payload[10] == 0x00 && packet->payload[11] == 0x03 */ if (get_u_int16_t(packet->payload, 10) == htons(CLIENT_NAME)) /* packet->payload[10] == 0x00 && packet->payload[11] == 0x03 */
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Client Name \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Client Name \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -182,7 +186,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
(get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x01) || (get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x01) ||
(get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x03)) (get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x03))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Login \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Login \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -191,35 +195,35 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
/* MAJOR_VERSION */ /* MAJOR_VERSION */
if (get_u_int16_t(packet->payload, 10) == htons(MAJOR_VERSION)) if (get_u_int16_t(packet->payload, 10) == htons(MAJOR_VERSION))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Major_Version \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Major_Version \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
/* MINOR_VERSION */ /* MINOR_VERSION */
if (get_u_int16_t(packet->payload, 10) == htons(MINOR_VERSION)) if (get_u_int16_t(packet->payload, 10) == htons(MINOR_VERSION))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Minor_Version \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Minor_Version \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
/* POINT_VERSION */ /* POINT_VERSION */
if (get_u_int16_t(packet->payload, 10) == htons(POINT_VERSION)) if (get_u_int16_t(packet->payload, 10) == htons(POINT_VERSION))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Point_Version \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Point_Version \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
/* BUILD_NUM */ /* BUILD_NUM */
if (get_u_int16_t(packet->payload, 10) == htons(BUILD_NUM)) if (get_u_int16_t(packet->payload, 10) == htons(BUILD_NUM))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Build_Num \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Build_Num \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
/* CLIENT_RECONNECT */ /* CLIENT_RECONNECT */
if (get_u_int16_t(packet->payload, 10) == htons(CLIENT_RECONNECT)) if (get_u_int16_t(packet->payload, 10) == htons(CLIENT_RECONNECT))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR - Client_Reconnect \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Client_Reconnect \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -254,7 +258,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
type = 0; type = 0;
if (family == 0 || type == 0) if (family == 0 || type == 0)
{ {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OSCAR); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
@@ -565,8 +569,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
if(excluded == 1) if(excluded == 1)
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "exclude oscar.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OSCAR);
} }
/* flag */ /* flag */
@@ -581,7 +584,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
req_ID = get_u_int32_t(packet->payload, 12); req_ID = get_u_int32_t(packet->payload, 12);
if((req_ID <= ((u_int32_t)-1))) if((req_ID <= ((u_int32_t)-1)))
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -595,7 +598,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
*/ */
if (channel == O_ERROR) if (channel == O_ERROR)
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected - Error frame \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Error frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -605,7 +608,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
*/ */
if (channel == SIGNOFF) if (channel == SIGNOFF)
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected - Signoff frame \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Signoff frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -615,7 +618,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
*/ */
if (channel == KEEP_ALIVE) if (channel == KEEP_ALIVE)
{ {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected - Keep Alive frame \n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Keep Alive frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -628,8 +631,8 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
NDPI_PARSE_PACKET_LINE_INFO(ndpi_struct, flow, packet); NDPI_PARSE_PACKET_LINE_INFO(ndpi_struct, flow, packet);
if (packet->host_line.len >= 18 && packet->host_line.ptr != NULL) { if (packet->host_line.len >= 18 && packet->host_line.ptr != NULL) {
if (memcmp(packet->host_line.ptr, "lifestream.aol.com", 18) == 0) { if (memcmp(packet->host_line.ptr, "lifestream.aol.com", 18) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"OSCAR over HTTP found, POST method\n"); "found OSCAR over HTTP, POST method\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -643,7 +646,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
(memcmp(&packet->payload[5], "aim/gromit/aim_express", 22) == 0) || (memcmp(&packet->payload[5], "aim/gromit/aim_express", 22) == 0) ||
(memcmp(&packet->payload[5], "b/ss/aolwpaim", 13) == 0) || (memcmp(&packet->payload[5], "b/ss/aolwpaim", 13) == 0) ||
(memcmp(&packet->payload[5], "hss/storage/aimtmpshare", 23) == 0)) { (memcmp(&packet->payload[5], "hss/storage/aimtmpshare", 23) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR over HTTP found, GET /aim/\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR over HTTP, GET /aim/\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -656,7 +659,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
(memcmp(packet->user_agent_line.ptr, "mobileICQ/", 10) == 0) || (memcmp(packet->user_agent_line.ptr, "mobileICQ/", 10) == 0) ||
(memcmp(packet->user_agent_line.ptr, "AIM%20Free/", NDPI_STATICSTRING_LEN("AIM%20Free/")) == 0) || (memcmp(packet->user_agent_line.ptr, "AIM%20Free/", NDPI_STATICSTRING_LEN("AIM%20Free/")) == 0) ||
(memcmp(packet->user_agent_line.ptr, "AIM/", 4) == 0))) { (memcmp(packet->user_agent_line.ptr, "AIM/", 4) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR over HTTP found\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR over HTTP\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -670,8 +673,8 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
for (i = 0; i < (packet->referer_line.len - 22); i++) { for (i = 0; i < (packet->referer_line.len - 22); i++) {
if (packet->referer_line.ptr[i] == 'a') { if (packet->referer_line.ptr[i] == 'a') {
if (memcmp(&packet->referer_line.ptr[i + 1], "im/gromit/aim_express", 21) == 0) { if (memcmp(&packet->referer_line.ptr[i + 1], "im/gromit/aim_express", 21) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct,
"OSCAR over HTTP found : aim/gromit/aim_express\n"); "found OSCAR over HTTP : aim/gromit/aim_express\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -682,12 +685,12 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
} }
if (memcmp(packet->payload, "CONNECT ", 8) == 0) { if (memcmp(packet->payload, "CONNECT ", 8) == 0) {
if (memcmp(packet->payload, "CONNECT login.icq.com:443 HTTP/1.", 33) == 0) { if (memcmp(packet->payload, "CONNECT login.icq.com:443 HTTP/1.", 33) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR ICQ-HTTP FOUND\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR ICQ-HTTP\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
if (memcmp(packet->payload, "CONNECT login.oscar.aol.com:5190 HTTP/1.", 40) == 0) { if (memcmp(packet->payload, "CONNECT login.oscar.aol.com:5190 HTTP/1.", 40) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR AIM-HTTP FOUND\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR AIM-HTTP\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -697,33 +700,33 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
if (packet->payload_packet_len > 43 if (packet->payload_packet_len > 43
&& memcmp(packet->payload, "GET http://http.proxy.icq.com/hello HTTP/1.", 43) == 0) { && memcmp(packet->payload, "GET http://http.proxy.icq.com/hello HTTP/1.", 43) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR ICQ-HTTP PROXY FOUND\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR ICQ-HTTP PROXY\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len > 46 if (packet->payload_packet_len > 46
&& memcmp(packet->payload, "GET http://aimhttp.oscar.aol.com/hello HTTP/1.", 46) == 0) { && memcmp(packet->payload, "GET http://aimhttp.oscar.aol.com/hello HTTP/1.", 46) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR AIM-HTTP PROXY FOUND\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR AIM-HTTP PROXY\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
if (packet->payload_packet_len > 5 && get_u_int32_t(packet->payload, 0) == htonl(0x05010003)) { if (packet->payload_packet_len > 5 && get_u_int32_t(packet->payload, 0) == htonl(0x05010003)) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "Maybe OSCAR Picturetransfer\n"); NDPI_LOG_DBG2(ndpi_struct, "Maybe OSCAR Picturetransfer\n");
return; return;
} }
if (packet->payload_packet_len == 10 && get_u_int32_t(packet->payload, 0) == htonl(0x05000001) && if (packet->payload_packet_len == 10 && get_u_int32_t(packet->payload, 0) == htonl(0x05000001) &&
get_u_int32_t(packet->payload, 4) == 0) { get_u_int32_t(packet->payload, 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "Maybe OSCAR Picturetransfer\n"); NDPI_LOG_DBG2(ndpi_struct, "Maybe OSCAR Picturetransfer\n");
return; return;
} }
if (packet->payload_packet_len >= 70 && if (packet->payload_packet_len >= 70 &&
memcmp(&packet->payload[packet->payload_packet_len - 26], memcmp(&packet->payload[packet->payload_packet_len - 26],
"\x67\x00\x65\x00\x74\x00\x43\x00\x61\x00\x74\x00\x61\x00\x6c\x00\x6f\x00\x67", 19) == 0) { "\x67\x00\x65\x00\x74\x00\x43\x00\x61\x00\x74\x00\x61\x00\x6c\x00\x6f\x00\x67", 19) == 0) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR PICTURE TRANSFER\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR PICTURE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -751,7 +754,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
== 0) == 0)
)))) { )))) {
// FILE TRANSFER PATTERN:: OFT3 or OFT2 // FILE TRANSFER PATTERN:: OFT3 or OFT2
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR FILE TRANSFER\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR FILE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -759,7 +762,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
if (memcmp(packet->payload, "ODC2", 4) == 0 && memcmp(&packet->payload[6], "\x00\x01\x00\x06", 4) == 0) { if (memcmp(packet->payload, "ODC2", 4) == 0 && memcmp(&packet->payload[6], "\x00\x01\x00\x06", 4) == 0) {
//PICTURE TRANSFER PATTERN EXMAPLE:: //PICTURE TRANSFER PATTERN EXMAPLE::
//4f 44 43 32 00 4c 00 01 00 06 00 00 00 00 00 00 ODC2.L.......... //4f 44 43 32 00 4c 00 01 00 06 00 00 00 00 00 00 ODC2.L..........
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR PICTURE TRANSFER\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR PICTURE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -770,7 +773,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
&& packet->payload[packet->payload_packet_len - 12] == 'L' && packet->payload[packet->payload_packet_len - 12] == 'L'
&& (memcmp(&packet->payload[packet->payload_packet_len - 6], "DEST", 4) == 0) && (memcmp(&packet->payload[packet->payload_packet_len - 6], "DEST", 4) == 0)
&& (memcmp(&packet->payload[packet->payload_packet_len - 2], "\x00\x00", 2) == 0)) { && (memcmp(&packet->payload[packet->payload_packet_len - 2], "\x00\x00", 2) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR PICTURE TRANSFER\n"); NDPI_LOG_INFO(ndpi_struct, "found OSCAR PICTURE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow); ndpi_int_oscar_add_connection(ndpi_struct, flow);
if (ntohs(packet->tcp->dest) == 443 || ntohs(packet->tcp->source) == 443) { if (ntohs(packet->tcp->dest) == 443 || ntohs(packet->tcp->source) == 443) {
flow->oscar_ssl_voice_stage = 1; flow->oscar_ssl_voice_stage = 1;
@@ -787,7 +790,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_OSCAR) { if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_OSCAR) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_OSCAR); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return; return;
} }
} }
@@ -795,8 +798,8 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
void ndpi_search_oscar(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) void ndpi_search_oscar(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search OSCAR\n");
if (packet->tcp != NULL) { if (packet->tcp != NULL) {
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR :: TCP\n");
ndpi_search_oscar_tcp_connect(ndpi_struct, flow); ndpi_search_oscar_tcp_connect(ndpi_struct, flow);
} }
} }
+19 -18
View File
@@ -23,9 +23,14 @@
* *
*/ */
#include "ndpi_api.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_PANDO #ifdef NDPI_PROTOCOL_PANDO
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_PANDO
#include "ndpi_api.h"
static void ndpi_int_pando_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static void ndpi_int_pando_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PANDO, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PANDO, NDPI_PROTOCOL_UNKNOWN);
} }
@@ -35,7 +40,7 @@ static void ndpi_check_pando_tcp(struct ndpi_detection_module_struct *ndpi_struc
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
if (ndpi_match_strprefix(packet->payload, payload_len, "\x0ePan")) { if (ndpi_match_strprefix(packet->payload, payload_len, "\x0ePan")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n"); NDPI_LOG_INFO(ndpi_struct, "Found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow); ndpi_int_pando_add_connection(ndpi_struct, flow);
} }
} }
@@ -45,11 +50,11 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
/* Check if we so far detected the protocol in the request or not. */ /* Check if we so far detected the protocol in the request or not. */
NDPI_LOG_DBG2(ndpi_struct, "PANDO stage %u: \n", flow->pando_stage);
if (flow->pando_stage == 0) { if (flow->pando_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "PANDO stage 0: \n");
if ((payload_len >= 4) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x09)) { if ((payload_len >= 4) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x09)) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Possible PANDO request detected, we will look further for the response...\n"); NDPI_LOG_DBG2(ndpi_struct, "Possible PANDO request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */ /* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->pando_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2 flow->pando_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
@@ -57,7 +62,7 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
} }
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) { if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Possible PANDO request detected, we will look further for the response...\n"); NDPI_LOG_DBG2(ndpi_struct, "Possible PANDO request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */ /* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->pando_stage = packet->packet_direction + 3; // packet_direction 0: stage 3, packet_direction 1: stage 4 flow->pando_stage = packet->packet_direction + 3; // packet_direction 0: stage 3, packet_direction 1: stage 4
@@ -65,7 +70,7 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
} }
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE")) { if (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Possible PANDO request detected, we will look further for the response...\n"); NDPI_LOG_DBG2(ndpi_struct, "Possible PANDO request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */ /* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->pando_stage = packet->packet_direction + 5; // packet_direction 0: stage 5, packet_direction 1: stage 6 flow->pando_stage = packet->packet_direction + 5; // packet_direction 0: stage 5, packet_direction 1: stage 6
@@ -73,7 +78,6 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
} }
} else if ((flow->pando_stage == 1) || (flow->pando_stage == 2)) { } else if ((flow->pando_stage == 1) || (flow->pando_stage == 2)) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "PANDO stage %u: \n", flow->pando_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */ /* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pando_stage - packet->packet_direction) == 1) { if ((flow->pando_stage - packet->packet_direction) == 1) {
@@ -82,15 +86,14 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
/* This is a packet in another direction. Check if we find the proper response. */ /* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 0) || ((payload_len >= 4) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x09))) { if ((payload_len == 0) || ((payload_len >= 4) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x09))) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n"); NDPI_LOG_INFO(ndpi_struct, "found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow); ndpi_int_pando_add_connection(ndpi_struct, flow);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to PANDO, resetting the stage to 0...\n"); NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PANDO, resetting the stage to 0..\n");
flow->pando_stage = 0; flow->pando_stage = 0;
} }
} else if ((flow->pando_stage == 3) || (flow->pando_stage == 4)) { } else if ((flow->pando_stage == 3) || (flow->pando_stage == 4)) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "PANDO stage %u: \n", flow->pando_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */ /* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pando_stage - packet->packet_direction) == 3) { if ((flow->pando_stage - packet->packet_direction) == 3) {
@@ -99,15 +102,14 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
/* This is a packet in another direction. Check if we find the proper response. */ /* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 0) || (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE"))) { if ((payload_len == 0) || (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE"))) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n"); NDPI_LOG_INFO(ndpi_struct, "found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow); ndpi_int_pando_add_connection(ndpi_struct, flow);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to PANDO, resetting the stage to 0...\n"); NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PANDO, resetting the stage to 0..\n");
flow->pando_stage = 0; flow->pando_stage = 0;
} }
} else if ((flow->pando_stage == 5) || (flow->pando_stage == 6)) { } else if ((flow->pando_stage == 5) || (flow->pando_stage == 6)) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "PANDO stage %u: \n", flow->pando_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */ /* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pando_stage - packet->packet_direction) == 5) { if ((flow->pando_stage - packet->packet_direction) == 5) {
@@ -116,10 +118,10 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
/* This is a packet in another direction. Check if we find the proper response. */ /* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) { if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n"); NDPI_LOG_INFO(ndpi_struct, "found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow); ndpi_int_pando_add_connection(ndpi_struct, flow);
} else { } else {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to PANDO, resetting the stage to 0...\n"); NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PANDO, resetting the stage to 0\n");
flow->pando_stage = 0; flow->pando_stage = 0;
} }
} }
@@ -128,10 +130,10 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
void ndpi_search_pando(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { void ndpi_search_pando(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search PANDO\n");
/* Break after 20 packets. */ /* Break after 20 packets. */
if (flow->packet_counter > 20) { if (flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_TRACE, "PANDO excluded.\n"); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_PANDO);
return; return;
} }
@@ -144,7 +146,6 @@ void ndpi_search_pando(struct ndpi_detection_module_struct *ndpi_struct, struct
return; return;
} }
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_TRACE, "PANDO detection...\n");
ndpi_check_pando_tcp(ndpi_struct, flow); ndpi_check_pando_tcp(ndpi_struct, flow);
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PANDO) { if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PANDO) {
+9 -7
View File
@@ -23,9 +23,15 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_PCANYWHERE #ifdef NDPI_PROTOCOL_PCANYWHERE
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_PCANYWHERE
#include "ndpi_api.h"
static void ndpi_int_pcanywhere_add_connection(struct ndpi_detection_module_struct static void ndpi_int_pcanywhere_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
@@ -37,19 +43,15 @@ void ndpi_search_pcanywhere(struct ndpi_detection_module_struct
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (packet->udp != NULL && packet->udp->dest == htons(5632) if (packet->udp != NULL && packet->udp->dest == htons(5632)
&& packet->payload_packet_len == 2 && packet->payload_packet_len == 2
&& (memcmp(packet->payload, "NQ", 2) == 0 || memcmp(packet->payload, "ST", 2) == 0)) { && (memcmp(packet->payload, "NQ", 2) == 0 || memcmp(packet->payload, "ST", 2) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_PCANYWHERE, ndpi_struct, NDPI_LOG_DEBUG, NDPI_LOG_INFO(ndpi_struct, "PC Anywhere name or status query detected\n");
"PC Anywhere name or status query detected.\n");
ndpi_int_pcanywhere_add_connection(ndpi_struct, flow); ndpi_int_pcanywhere_add_connection(ndpi_struct, flow);
return; return;
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_PCANYWHERE); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }
+14 -13
View File
@@ -23,9 +23,14 @@
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocol_ids.h"
#ifdef NDPI_PROTOCOL_POSTGRES #ifdef NDPI_PROTOCOL_POSTGRES
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_POSTGRES
#include "ndpi_api.h"
static void ndpi_int_postgres_add_connection(struct ndpi_detection_module_struct static void ndpi_int_postgres_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
@@ -37,10 +42,6 @@ void ndpi_search_postgres_tcp(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) *ndpi_struct, struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
u_int16_t size; u_int16_t size;
if (flow->l4.tcp.postgres_stage == 0) { if (flow->l4.tcp.postgres_stage == 0) {
@@ -65,13 +66,13 @@ void ndpi_search_postgres_tcp(struct ndpi_detection_module_struct
if (flow->l4.tcp.postgres_stage == 2 - packet->packet_direction) { if (flow->l4.tcp.postgres_stage == 2 - packet->packet_direction) {
//SSL accepted //SSL accepted
if (packet->payload_packet_len == 1 && packet->payload[0] == 'S') { if (packet->payload_packet_len == 1 && packet->payload[0] == 'S') {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "PostgreSQL detected, SSL accepted.\n"); NDPI_LOG_INFO(ndpi_struct, "PostgreSQL detected, SSL accepted\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
//SSL denied //SSL denied
if (packet->payload_packet_len == 1 && packet->payload[0] == 'N') { if (packet->payload_packet_len == 1 && packet->payload[0] == 'N') {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "PostgreSQL detected, SSL denied.\n"); NDPI_LOG_INFO(ndpi_struct, "PostgreSQL detected, SSL denied\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -81,40 +82,40 @@ void ndpi_search_postgres_tcp(struct ndpi_detection_module_struct
if (packet->payload_packet_len > 8 && if (packet->payload_packet_len > 8 &&
ntohl(get_u_int32_t(packet->payload, 5)) < 10 && ntohl(get_u_int32_t(packet->payload, 5)) < 10 &&
ntohl(get_u_int32_t(packet->payload, 1)) == packet->payload_packet_len - 1 && packet->payload[0] == 0x52) { ntohl(get_u_int32_t(packet->payload, 1)) == packet->payload_packet_len - 1 && packet->payload[0] == 0x52) {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "PostgreSQL detected, no SSL.\n"); NDPI_LOG_INFO(ndpi_struct, "PostgreSQL detected, no SSL\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
if (flow->l4.tcp.postgres_stage == 6 if (flow->l4.tcp.postgres_stage == 6
&& ntohl(get_u_int32_t(packet->payload, 1)) == packet->payload_packet_len - 1 && packet->payload[0] == 'p') { && ntohl(get_u_int32_t(packet->payload, 1)) == packet->payload_packet_len - 1 && packet->payload[0] == 'p') {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "found postgres asymmetrically.\n"); NDPI_LOG_INFO(ndpi_struct, "found postgres asymmetrically\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
if (flow->l4.tcp.postgres_stage == 5 && packet->payload[0] == 'R') { if (flow->l4.tcp.postgres_stage == 5 && packet->payload[0] == 'R') {
if (ntohl(get_u_int32_t(packet->payload, 1)) == packet->payload_packet_len - 1) { if (ntohl(get_u_int32_t(packet->payload, 1)) == packet->payload_packet_len - 1) {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "found postgres asymmetrically.\n"); NDPI_LOG_INFO(ndpi_struct, "found postgres asymmetrically\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
size = (u_int16_t)ntohl(get_u_int32_t(packet->payload, 1)) + 1; size = (u_int16_t)ntohl(get_u_int32_t(packet->payload, 1)) + 1;
if (packet->payload[size - 1] == 'S') { if (packet->payload[size - 1] == 'S') {
if ((size + get_u_int32_t(packet->payload, (size + 1))) == packet->payload_packet_len) { if ((size + get_u_int32_t(packet->payload, (size + 1))) == packet->payload_packet_len) {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "found postgres asymmetrically.\n"); NDPI_LOG_INFO(ndpi_struct, "found postgres asymmetrically\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
} }
size += get_u_int32_t(packet->payload, (size + 1)) + 1; size += get_u_int32_t(packet->payload, (size + 1)) + 1;
if (packet->payload[size - 1] == 'S') { if (packet->payload[size - 1] == 'S') {
NDPI_LOG(NDPI_PROTOCOL_POSTGRES, ndpi_struct, NDPI_LOG_DEBUG, "found postgres asymmetrically.\n"); NDPI_LOG_INFO(ndpi_struct, "found postgres asymmetrically\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow); ndpi_int_postgres_add_connection(ndpi_struct, flow);
return; return;
} }
} }
} }
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_POSTGRES); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} }

Some files were not shown because too many files have changed in this diff Show More