Compare commits

..
12 Commits
Author SHA1 Message Date
Michele Campus 625ed3d4e4 Merge pull request #478 from hvanderheide/1.7-stable
Add ndpi_includes.h to include headers
2017-10-23 11:57:13 +02:00
Hidde van der Heide 16fc15fba2 Add ndpi_includes.h to include headers
Add this header file to the proper variable so it gets installed to the
system
2017-10-19 17:12:16 +02:00
Michele Campus 5b140565b1 Merge pull request #285 from vpiserchia/1.7-stable
Fix KAKAOTALK VOICE MACRO name
2016-11-03 15:11:10 +01:00
Vito Piserchia cc83d808de Fix KAKAOTALK VOICE MACRO name 2016-11-03 15:06:46 +01:00
Luca Deri a121161480 Added missing HEP initialization 2015-12-04 21:34:26 +01:00
Luca Deri e4fd4bc9f9 Typedef refresh 2015-11-30 18:46:52 +01:00
Luca Deri ff04ff42fe Merge pull request #105 from vel21ripn/1.7-stable
ndpi_search_dns: fix potential buffer overflow
2015-10-09 14:59:25 +02:00
Vitaly Lavrov 8c4fada42f ndpi_search_mail_smtp_tcp: minor fix for starttls command 2015-10-09 15:15:34 +03:00
Vitaly Lavrov 4e5b7f625d ndpi_search_dns: fix potential buffer overflow 2015-10-09 14:45:16 +03:00
Luca Deri a3d66b0777 Fixes #83. Critical fix: due to an invalid endianess conversion some protocol were not properly indetified 2015-08-26 16:15:54 +02:00
Luca Deri 49983c07b8 Updated formula for 1.7 release 2015-08-18 11:57:36 +02:00
Luca Deri 431b139e44 Sync formula with homebrew 2015-08-18 11:32:34 +02:00
131 changed files with 4056 additions and 6023 deletions
+7 -11
View File
@@ -1,13 +1,8 @@
![ntop][ntopng_logo] ![ntop][ntop_logo]
# nDPI
[![Build Status](https://travis-ci.org/ntop/nDPI.png?branch=dev)](https://travis-ci.org/ntop/nDPI)
## What is nDPI ?
# What is nDPI ?
nDPI is an open source LGPLv3 library for deep-packet inspection. Based on OpenDPI it includes ntop extensions. We have tried to push them into the OpenDPI source tree but nobody answered emails so we have decided to create our own source tree
### How To Compile nDPI
# How To Compile nDPI
In order to compile this library do
@@ -19,7 +14,7 @@ Please note that the pre-requisites for compilation include:
- GNU tools (autogen, automake, autoconf, libtool)
- GNU C compiler (gcc)
### How To Add A New Protocol Dissector
# How To Add A New Protocol Dissector
The entire procedure of adding new protocols in detail:
@@ -35,12 +30,13 @@ The entire procedure of adding new protocols in detail:
10. ./configure
11. make
### Creating A Source File Tar Ball
# Creating A Source File Tar Ball
If you want to distribute a source tar file of nDPI do:
- make dist
[ntopng_logo]: https://camo.githubusercontent.com/0f789abcef232035c05e0d2e82afa3cc3be46485/687474703a2f2f7777772e6e746f702e6f72672f77702d636f6e74656e742f75706c6f6164732f323031312f30382f6e746f706e672d69636f6e2d313530783135302e706e67
[ntop_logo]: https://camo.githubusercontent.com/58e2a1ecfff62d8ecc9d74633bd1013f26e06cba/687474703a2f2f7777772e6e746f702e6f72672f77702d636f6e74656e742f75706c6f6164732f323031352f30352f6e746f702e706e67
# Acknowledgements
Many thanks to <A HREF=http://www.radcom.com>Radcom</A> Ltd for supporting the development of nDPI.
+1 -1
View File
@@ -8,7 +8,7 @@ TCP 172.16.253.130:2021 <-> 75.147.140.249:443 [VLAN: 0][proto: 91/SSL][28 pkts/
TCP 172.16.253.130:2077 <-> 77.247.181.163:443 [VLAN: 0][proto: 91/SSL][136 pkts/94329 bytes][SSL client: www.fk4pprq42hsvl2wey.com]
It can be detected by analyzing the SSL client certificate and checking the name that does not match to a real host in
addition of being a bit weird. As doing DNS resolution is not a task for nDPI we let applications do and then recognize
addition of begin a bit weird. As doing DNS resolution is not a task for nDPI we let applications do and then recognize
SSL-tunnelled connections.
See http://www.netresec.com/?page=Blog&month=2013-04&post=Detecting-TOR-Communication-in-Network-Traffic
+1 -1
View File
@@ -30,4 +30,4 @@ if test -z $AUTORECONF; then
fi
autoreconf -ivf
./configure $*
./configure
+13 -15
View File
@@ -1,4 +1,4 @@
AC_INIT([libndpi], [1.8.0])
AC_INIT([libndpi], [1.7.0])
AC_CONFIG_MACRO_DIR([m4])
@@ -46,7 +46,7 @@ fi
if test -f $PCAP_HOME/libpcap/libpcap.a; then :
echo "Using libpcap from $PCAP_HOME"
PCAP_INC="-I $PCAP_HOME/libpcap"
PCAP_LIB="$PCAP_HOME/libpcap/libpcap.a $PCAP_HOME/lib/libpfring.a $LIBNUMA `$PCAP_HOME/lib/pfring_config --libs`"
PCAP_LIB="$PCAP_HOME/libpcap/libpcap.a $PCAP_HOME/lib/libpfring.a $LIBNUMA"
AC_CHECK_LIB([rt], [clock_gettime], [PCAP_LIB="$PCAP_LIB -lrt"])
AC_CHECK_LIB([nl], [nl_handle_alloc], [PCAP_LIB="$PCAP_LIB -lnl"])
@@ -61,20 +61,17 @@ else
fi
fi
AC_ARG_ENABLE([json-c],
AS_HELP_STRING([--disable-json-c], [Disable json-c support]))
PKG_CONFIG=$(which pkg-config)
AS_IF([test "x$enable_json_c" != "xno"], [
PKG_CONFIG_PATH=/usr/local/share/pkgconfig:$PKG_CONFIG_PATH
pkg-config --exists json-c
AS_IF([test "$?" == "0"],
[
CFLAGS="$CFLAGS $(pkg-config --cflags json-c)"
LDFLAGS="$LDFLAGS $(pkg-config --libs json-c)"
AC_CHECK_LIB(json-c, json_object_new_object, AC_DEFINE_UNQUOTED(HAVE_JSON_C, 1, [The JSON-C library is present]))
],
[])
])
if test -d /usr/local/include/json-c/; then :
CFLAGS="$CFLAGS -I/usr/local/include/json-c/"
LDFLAGS="$LDFLAGS -L/usr/local/lib -ljson-c"
else
if ! test -z "$PKG_CONFIG"; then :
CFLAGS="$CFLAGS $(pkg-config --cflags json-c)"
LDFLAGS="$LDFLAGS $(pkg-config --libs json-c)"
fi
fi
OLD_LIBS=$LIBS
LIBS="-L/opt/napatech3/lib $LIBS"
@@ -84,6 +81,7 @@ AC_CHECK_LIB([ntapi],
[], [] )
LIBS=$OLD_LIBS
AC_CHECK_LIB(json-c, json_object_new_object, AC_DEFINE_UNQUOTED(HAVE_JSON_C, 1, [The JSON-C library is present]))
AC_CHECK_LIB(pthread, pthread_setaffinity_np, AC_DEFINE_UNQUOTED(HAVE_PTHREAD_SETAFFINITY_NP, 1, [libc has pthread_setaffinity_np]))
+1 -1
View File
@@ -6,7 +6,7 @@ AM_CFLAGS = @PTHREAD_CFLAGS@
LDADD = $(top_builddir)/src/lib/libndpi.la @JSON_C_LIB@ @PTHREAD_LIBS@ @PCAP_LIB@
AM_LDFLAGS = -static
ndpiReader_SOURCES = ndpiReader.c ndpi_util.c
ndpiReader_SOURCES = ndpiReader.c
ndpiReader.o: ndpiReader.c
+1220 -534
View File
File diff suppressed because it is too large Load Diff
-847
View File
@@ -1,847 +0,0 @@
/*
* ndpi_util.c
*
* Copyright (C) 2011-16 - 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 <stdlib.h>
#ifdef WIN32
#include <winsock2.h> /* winsock.h is included automatically */
#include <process.h>
#include <io.h>
#else
#include <unistd.h>
#include <netinet/in.h>
#endif
#ifndef ETH_P_IP
#define ETH_P_IP 0x0800 /* IPv4 */
#endif
#ifndef ETH_P_IPv6
#define ETH_P_IPV6 0x86dd /* IPv6 */
#endif
#define SLARP 0x8035 /* Cisco Slarp */
#define CISCO_D_PROTO 0x2000 /* Cisco Discovery Protocol */
#define VLAN 0x8100
#define MPLS_UNI 0x8847
#define MPLS_MULTI 0x8848
#define PPPoE 0x8864
#define SNAP 0xaa
/* mask for FCF */
#define WIFI_DATA 0x2 /* 0000 0010 */
#define FCF_TYPE(fc) (((fc) >> 2) & 0x3) /* 0000 0011 = 0x3 */
#define FCF_SUBTYPE(fc) (((fc) >> 4) & 0xF) /* 0000 1111 = 0xF */
#define FCF_TO_DS(fc) ((fc) & 0x0100)
#define FCF_FROM_DS(fc) ((fc) & 0x0200)
/* mask for Bad FCF presence */
#define BAD_FCS 0x50 /* 0101 0000 */
#define GTP_U_V1_PORT 2152
#define TZSP_PORT 37008
#define SIZEOF_ID_STRUCT (sizeof(struct ndpi_id_struct))
#define SIZEOF_FLOW_STRUCT (sizeof(struct ndpi_flow_struct))
#include "ndpi_main.h"
#include "ndpi_util.h"
/* ***************************************************** */
void ndpi_free_flow_info_half(struct ndpi_flow_info *flow) {
if(flow->ndpi_flow) { ndpi_free_flow(flow->ndpi_flow); flow->ndpi_flow = NULL; }
if(flow->src_id) { ndpi_free(flow->src_id); flow->src_id = NULL; }
if(flow->dst_id) { ndpi_free(flow->dst_id); flow->dst_id = NULL; }
}
/* ***************************************************** */
static const u_int8_t nDPI_traceLevel = 0;
/* ***************************************************** */
extern u_int32_t current_ndpi_memory, max_ndpi_memory;
/**
* @brief malloc wrapper function
*/
static void *malloc_wrapper(size_t size) {
current_ndpi_memory += size;
if(current_ndpi_memory > max_ndpi_memory)
max_ndpi_memory = current_ndpi_memory;
return malloc(size);
}
/* ***************************************************** */
/**
* @brief free wrapper function
*/
static void free_wrapper(void *freeable) {
free(freeable);
}
/* ***************************************************** */
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);
/* TODO: just needed here to init ndpi malloc wrapper */
struct ndpi_detection_module_struct * module = ndpi_init_detection_module();
struct ndpi_workflow * workflow = ndpi_calloc(1, sizeof(struct ndpi_workflow));
workflow->pcap_handle = pcap_handle;
workflow->prefs = *prefs;
workflow->ndpi_struct = module;
if(workflow->ndpi_struct == NULL) {
NDPI_LOG(0, NULL, NDPI_LOG_ERROR, "global structure initialization failed\n");
exit(-1);
}
workflow->ndpi_flows_root = ndpi_calloc(workflow->prefs.num_roots, sizeof(void *));
return workflow;
}
/* ***************************************************** */
static void ndpi_flow_info_freer(void *node) {
struct ndpi_flow_info *flow = (struct ndpi_flow_info*)node;
ndpi_free_flow_info_half(flow);
ndpi_free(flow);
}
/* ***************************************************** */
void ndpi_workflow_free(struct ndpi_workflow * workflow) {
int i;
for(i=0; i<workflow->prefs.num_roots; i++)
ndpi_tdestroy(workflow->ndpi_flows_root[i], ndpi_flow_info_freer);
ndpi_exit_detection_module(workflow->ndpi_struct);
free(workflow->ndpi_flows_root);
free(workflow);
}
/* ***************************************************** */
int ndpi_workflow_node_cmp(const void *a, const void *b) {
struct ndpi_flow_info *fa = (struct ndpi_flow_info*)a;
struct ndpi_flow_info *fb = (struct ndpi_flow_info*)b;
if(fa->vlan_id < fb->vlan_id ) return(-1); else { if(fa->vlan_id > fb->vlan_id ) return(1); }
if(fa->lower_ip < fb->lower_ip ) return(-1); else { if(fa->lower_ip > fb->lower_ip ) return(1); }
if(fa->lower_port < fb->lower_port) return(-1); else { if(fa->lower_port > fb->lower_port) return(1); }
if(fa->upper_ip < fb->upper_ip ) return(-1); else { if(fa->upper_ip > fb->upper_ip ) return(1); }
if(fa->upper_port < fb->upper_port) return(-1); else { if(fa->upper_port > fb->upper_port) return(1); }
if(fa->protocol < fb->protocol ) return(-1); else { if(fa->protocol > fb->protocol ) return(1); }
return(0);
}
/* ***************************************************** */
static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow,
const u_int8_t version,
u_int16_t vlan_id,
const struct ndpi_iphdr *iph,
const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize,
u_int16_t l4_packet_len,
struct ndpi_tcphdr **tcph,
struct ndpi_udphdr **udph,
u_int16_t *sport, u_int16_t *dport,
struct ndpi_id_struct **src,
struct ndpi_id_struct **dst,
u_int8_t *proto,
u_int8_t **payload,
u_int16_t *payload_len,
u_int8_t *src_to_dst_direction) {
u_int32_t idx, l4_offset;
u_int32_t lower_ip;
u_int32_t upper_ip;
u_int16_t lower_port;
u_int16_t upper_port;
struct ndpi_flow_info flow;
void *ret;
u_int8_t *l3, *l4;
/*
Note: to keep things simple (ndpiReader is just a demo app)
we handle IPv6 a-la-IPv4.
*/
if(version == 4) {
if(ipsize < 20)
return NULL;
if((iph->ihl * 4) > ipsize || ipsize < ntohs(iph->tot_len)
|| (iph->frag_off & htons(0x1FFF)) != 0)
return NULL;
l4_offset = iph->ihl * 4;
l3 = (u_int8_t*)iph;
} else {
l4_offset = sizeof(struct ndpi_ipv6hdr);
l3 = (u_int8_t*)iph6;
}
if(l4_packet_len < 64)
workflow->stats.packet_len[0]++;
else if(l4_packet_len >= 64 && l4_packet_len < 128)
workflow->stats.packet_len[1]++;
else if(l4_packet_len >= 128 && l4_packet_len < 256)
workflow->stats.packet_len[2]++;
else if(l4_packet_len >= 256 && l4_packet_len < 1024)
workflow->stats.packet_len[3]++;
else if(l4_packet_len >= 1024 && l4_packet_len < 1500)
workflow->stats.packet_len[4]++;
else if(l4_packet_len >= 1500)
workflow->stats.packet_len[5]++;
if(l4_packet_len > workflow->stats.max_packet_len)
workflow->stats.max_packet_len = l4_packet_len;
if(iph->saddr < iph->daddr) {
lower_ip = iph->saddr;
upper_ip = iph->daddr;
} else {
lower_ip = iph->daddr;
upper_ip = iph->saddr;
}
*proto = iph->protocol;
l4 = ((u_int8_t *) l3 + l4_offset);
if(iph->protocol == 6 && l4_packet_len >= 20) {
u_int tcp_len;
workflow->stats.tcp_count++;
// tcp
*tcph = (struct ndpi_tcphdr *)l4;
*sport = ntohs((*tcph)->source), *dport = ntohs((*tcph)->dest);
if(iph->saddr < iph->daddr) {
lower_port = (*tcph)->source, upper_port = (*tcph)->dest;
*src_to_dst_direction = 1;
} else {
lower_port = (*tcph)->dest;
upper_port = (*tcph)->source;
*src_to_dst_direction = 0;
if(iph->saddr == iph->daddr) {
if(lower_port > upper_port) {
u_int16_t p = lower_port;
lower_port = upper_port;
upper_port = p;
}
}
}
tcp_len = ndpi_min(4*(*tcph)->doff, l4_packet_len);
*payload = &l4[tcp_len];
*payload_len = ndpi_max(0, l4_packet_len-4*(*tcph)->doff);
} else if(iph->protocol == 17 && l4_packet_len >= 8) {
// udp
workflow->stats.udp_count++;
*udph = (struct ndpi_udphdr *)l4;
*sport = ntohs((*udph)->source), *dport = ntohs((*udph)->dest);
*payload = &l4[sizeof(struct ndpi_udphdr)];
*payload_len = ndpi_max(0, l4_packet_len-sizeof(struct ndpi_udphdr));
if(iph->saddr < iph->daddr) {
lower_port = (*udph)->source, upper_port = (*udph)->dest;
*src_to_dst_direction = 1;
} else {
lower_port = (*udph)->dest, upper_port = (*udph)->source;
*src_to_dst_direction = 0;
if(iph->saddr == iph->daddr) {
if(lower_port > upper_port) {
u_int16_t p = lower_port;
lower_port = upper_port;
upper_port = p;
}
}
}
*sport = ntohs(lower_port), *dport = ntohs(upper_port);
} else {
// non tcp/udp protocols
lower_port = 0;
upper_port = 0;
}
flow.protocol = iph->protocol, flow.vlan_id = vlan_id;
flow.lower_ip = lower_ip, flow.upper_ip = upper_ip;
flow.lower_port = lower_port, flow.upper_port = upper_port;
if(0)
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_DEBUG, "[NDPI] [%u][%u:%u <-> %u:%u]\n",
iph->protocol, lower_ip, ntohs(lower_port), upper_ip, ntohs(upper_port));
idx = (vlan_id + lower_ip + upper_ip + iph->protocol + lower_port + upper_port) % workflow->prefs.num_roots;
ret = ndpi_tfind(&flow, &workflow->ndpi_flows_root[idx], ndpi_workflow_node_cmp);
if(ret == NULL) {
if(workflow->stats.ndpi_flow_count == workflow->prefs.max_ndpi_flows) {
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_ERROR, "maximum flow count (%u) has been exceeded\n", workflow->prefs.max_ndpi_flows);
exit(-1);
} else {
struct ndpi_flow_info *newflow = (struct ndpi_flow_info*)malloc(sizeof(struct ndpi_flow_info));
if(newflow == NULL) {
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(1): not enough memory\n", __FUNCTION__);
return(NULL);
}
memset(newflow, 0, sizeof(struct ndpi_flow_info));
newflow->protocol = iph->protocol, newflow->vlan_id = vlan_id;
newflow->lower_ip = lower_ip, newflow->upper_ip = upper_ip;
newflow->lower_port = lower_port, newflow->upper_port = upper_port;
newflow->ip_version = version;
if(version == 4) {
inet_ntop(AF_INET, &lower_ip, newflow->lower_name, sizeof(newflow->lower_name));
inet_ntop(AF_INET, &upper_ip, newflow->upper_name, sizeof(newflow->upper_name));
} else {
inet_ntop(AF_INET6, &iph6->ip6_src, newflow->lower_name, sizeof(newflow->lower_name));
inet_ntop(AF_INET6, &iph6->ip6_dst, newflow->upper_name, sizeof(newflow->upper_name));
}
if((newflow->ndpi_flow = ndpi_malloc(SIZEOF_FLOW_STRUCT)) == NULL) {
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(2): not enough memory\n", __FUNCTION__);
free(newflow);
return(NULL);
} else
memset(newflow->ndpi_flow, 0, SIZEOF_FLOW_STRUCT);
if((newflow->src_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) {
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(3): not enough memory\n", __FUNCTION__);
free(newflow);
return(NULL);
} else
memset(newflow->src_id, 0, SIZEOF_ID_STRUCT);
if((newflow->dst_id = ndpi_malloc(SIZEOF_ID_STRUCT)) == NULL) {
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_ERROR, "[NDPI] %s(4): not enough memory\n", __FUNCTION__);
free(newflow);
return(NULL);
} else
memset(newflow->dst_id, 0, SIZEOF_ID_STRUCT);
ndpi_tsearch(newflow, &workflow->ndpi_flows_root[idx], ndpi_workflow_node_cmp); /* Add */
workflow->stats.ndpi_flow_count++;
*src = newflow->src_id, *dst = newflow->dst_id;
return newflow;
}
} else {
struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)ret;
if(flow->lower_ip == lower_ip && flow->upper_ip == upper_ip
&& flow->lower_port == lower_port && flow->upper_port == upper_port)
*src = flow->src_id, *dst = flow->dst_id;
else
*src = flow->dst_id, *dst = flow->src_id;
return flow;
}
}
/* ****************************************************** */
static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflow,
u_int16_t vlan_id,
const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
struct ndpi_tcphdr **tcph,
struct ndpi_udphdr **udph,
u_int16_t *sport, u_int16_t *dport,
struct ndpi_id_struct **src,
struct ndpi_id_struct **dst,
u_int8_t *proto,
u_int8_t **payload,
u_int16_t *payload_len,
u_int8_t *src_to_dst_direction) {
struct ndpi_iphdr iph;
memset(&iph, 0, sizeof(iph));
iph.version = 4;
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.protocol = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
if(iph.protocol == 0x3C /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)iph6 + sizeof(const struct ndpi_ipv6hdr);
iph.protocol = options[0];
}
return(get_ndpi_flow_info(workflow, 6, vlan_id, &iph, iph6, ip_offset,
sizeof(struct ndpi_ipv6hdr),
ntohs(iph6->ip6_ctlun.ip6_un1.ip6_un1_plen),
tcph, udph, sport, dport,
src, dst, proto, payload, payload_len, src_to_dst_direction));
}
/* ****************************************************** */
// ipsize = header->len - ip_offset ; rawsize = header->len
static unsigned int packet_processing(struct ndpi_workflow * workflow,
const u_int64_t time,
u_int16_t vlan_id,
const struct ndpi_iphdr *iph,
struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize, u_int16_t rawsize) {
struct ndpi_id_struct *src, *dst;
struct ndpi_flow_info *flow;
struct ndpi_flow_struct *ndpi_flow = NULL;
u_int8_t proto;
struct ndpi_tcphdr *tcph = NULL;
struct ndpi_udphdr *udph = NULL;
u_int16_t sport, dport, payload_len;
u_int8_t *payload;
u_int8_t src_to_dst_direction= 1;
if(iph)
flow = get_ndpi_flow_info(workflow, 4, vlan_id, iph, NULL,
ip_offset, ipsize,
ntohs(iph->tot_len) - (iph->ihl * 4),
&tcph, &udph, &sport, &dport,
&src, &dst, &proto,
&payload, &payload_len, &src_to_dst_direction);
else
flow = get_ndpi_flow_info6(workflow, vlan_id, iph6, ip_offset,
&tcph, &udph, &sport, &dport,
&src, &dst, &proto,
&payload, &payload_len, &src_to_dst_direction);
if(flow != NULL) {
workflow->stats.ip_packet_count++;
workflow->stats.total_wire_bytes += rawsize + 24 /* CRC etc */, workflow->stats.total_ip_bytes += rawsize;
ndpi_flow = flow->ndpi_flow;
flow->packets++, flow->bytes += rawsize;
flow->last_seen = time;
} else {
return(0);
}
/* Protocol already detected */
if(flow->detection_completed) return(0);
flow->detected_protocol = ndpi_detection_process_packet(workflow->ndpi_struct, ndpi_flow,
iph ? (uint8_t *)iph : (uint8_t *)iph6,
ipsize, time, src, dst);
if((flow->detected_protocol.protocol != NDPI_PROTOCOL_UNKNOWN)
|| ((proto == IPPROTO_UDP) && (flow->packets > 8))
|| ((proto == IPPROTO_TCP) && (flow->packets > 10))) {
/* New protocol detected or give up */
flow->detection_completed = 1;
if((flow->detected_protocol.protocol == NDPI_PROTOCOL_UNKNOWN) && (ndpi_flow->num_stun_udp_pkts > 0))
ndpi_set_detected_protocol(workflow->ndpi_struct, ndpi_flow, NDPI_PROTOCOL_STUN, NDPI_PROTOCOL_UNKNOWN);
snprintf(flow->host_server_name, sizeof(flow->host_server_name), "%s", flow->ndpi_flow->host_server_name);
if(flow->detected_protocol.protocol == NDPI_PROTOCOL_BITTORRENT) {
int i, j, n = 0;
for(i=0, j = 0; i<20; i++) {
sprintf(&flow->bittorent_hash[j], "%02x", flow->ndpi_flow->bittorent_hash[i]);
j += 2, n += flow->ndpi_flow->bittorent_hash[i];
}
if(n == 0) flow->bittorent_hash[0] = '\0';
}
if((proto == IPPROTO_TCP) && (flow->detected_protocol.protocol != NDPI_PROTOCOL_DNS)) {
snprintf(flow->ssl.client_certificate, sizeof(flow->ssl.client_certificate), "%s", flow->ndpi_flow->protos.ssl.client_certificate);
snprintf(flow->ssl.server_certificate, sizeof(flow->ssl.server_certificate), "%s", flow->ndpi_flow->protos.ssl.server_certificate);
}
if(flow->detected_protocol.protocol == NDPI_PROTOCOL_UNKNOWN) {
flow->detected_protocol = ndpi_detection_giveup(workflow->ndpi_struct, flow->ndpi_flow);
if (workflow->__flow_giveup_callback != NULL)
workflow->__flow_giveup_callback(workflow, flow, workflow->__flow_giveup_udata);
} else {
if (workflow->__flow_detected_callback != NULL)
workflow->__flow_detected_callback(workflow, flow, workflow->__flow_detected_udata);
}
ndpi_free_flow_info_half(flow);
}
return 0;
}
/* ****************************************************** */
void ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
const struct pcap_pkthdr *header,
const u_char *packet) {
/*
* Declare pointers to packet headers
*/
/* --- Ethernet header --- */
const struct ndpi_ethhdr *ethernet;
/* --- Ethernet II header --- */
const struct ndpi_ethhdr *ethernet_2;
/* --- LLC header --- */
const struct ndpi_llc_header *llc;
/* --- Cisco HDLC header --- */
const struct ndpi_chdlc *chdlc;
/* --- SLARP frame --- */
struct ndpi_slarp *slarp;
/* --- CDP --- */
struct ndpi_cdp *cdp;
/* --- Radio Tap header --- */
const struct ndpi_radiotap_header *radiotap;
/* --- Wifi header --- */
const struct ndpi_wifi_header *wifi;
/* --- MPLS header --- */
struct ndpi_mpls_header *mpls;
/** --- IP header --- **/
struct ndpi_iphdr *iph;
/** --- IPv6 header --- **/
struct ndpi_ipv6hdr *iph6;
/* lengths and offsets */
u_int16_t eth_offset = 0;
u_int16_t radio_len;
u_int16_t fc;
u_int16_t type;
int wifi_len = 0;
int llc_off;
int pyld_eth_len = 0;
int check;
u_int64_t time;
u_int16_t ip_offset, ip_len, ip6_offset;
u_int16_t frag_off = 0, vlan_id = 0;
u_int8_t proto = 0;
u_int32_t label;
/* counters */
u_int8_t vlan_packet = 0;
/* Increment raw packet counter */
workflow->stats.raw_packet_count++;
/* setting time */
time = ((uint64_t) header->ts.tv_sec) * TICK_RESOLUTION + header->ts.tv_usec / (1000000 / TICK_RESOLUTION);
/* safety check */
if(workflow->last_time > time) {
/* printf("\nWARNING: timestamp bug in the pcap file (ts delta: %llu, repairing)\n", ndpi_thread_info[thread_id].last_time - time); */
time = workflow->last_time;
}
/* update last time value */
workflow->last_time = time;
/*** check Data Link type ***/
const int datalink_type = pcap_datalink(workflow->pcap_handle);
datalink_check:
switch(datalink_type) {
case DLT_NULL :
if(ntohl(*((u_int32_t*)&packet[eth_offset])) == 2)
type = ETH_P_IP;
else
type = ETH_P_IPV6;
ip_offset = 4 + eth_offset;
break;
/* Cisco PPP in HDLC-like framing - 50 */
case DLT_PPP_SERIAL:
chdlc = (struct ndpi_chdlc *) &packet[eth_offset];
ip_offset = sizeof(struct ndpi_chdlc); /* CHDLC_OFF = 4 */
type = ntohs(chdlc->proto_code);
break;
/* Cisco PPP with HDLC framing - 104 */
case DLT_C_HDLC:
chdlc = (struct ndpi_chdlc *) &packet[eth_offset];
ip_offset = sizeof(struct ndpi_chdlc); /* CHDLC_OFF = 4 */
type = ntohs(chdlc->proto_code);
break;
/* IEEE 802.3 Ethernet - 1 */
case DLT_EN10MB :
ethernet = (struct ndpi_ethhdr *) &packet[eth_offset];
ip_offset = sizeof(struct ndpi_ethhdr) + eth_offset;
check = ntohs(ethernet->h_proto);
if(check <= 1500)
pyld_eth_len = check;
else if (check >= 1536)
type = check;
if(pyld_eth_len != 0) {
/* check for LLC layer with SNAP extension */
if(packet[ip_offset] == SNAP) {
llc = (struct ndpi_llc_header *)(&packet[ip_offset]);
type = llc->snap.proto_ID;
ip_offset += + 8;
}
}
break;
/* Linux Cooked Capture - 113 */
case DLT_LINUX_SLL :
type = (packet[eth_offset+14] << 8) + packet[eth_offset+15];
ip_offset = 16 + eth_offset;
break;
/* Radiotap link-layer - 127 */
case DLT_IEEE802_11_RADIO :
radiotap = (struct ndpi_radiotap_header *) &packet[eth_offset];
radio_len = radiotap->len;
/* Check Bad FCS presence */
if((radiotap->flags & BAD_FCS) == BAD_FCS) {
workflow->stats.total_discarded_bytes += header->len;
return;
}
/* Calculate 802.11 header length (variable) */
wifi = (struct ndpi_wifi_header*)( packet + eth_offset + radio_len);
fc = wifi->fc;
/* check wifi data presence */
if(FCF_TYPE(fc) == WIFI_DATA) {
if((FCF_TO_DS(fc) && FCF_FROM_DS(fc) == 0x0) ||
(FCF_TO_DS(fc) == 0x0 && FCF_FROM_DS(fc)))
wifi_len = 26; /* + 4 byte fcs */
} else /* no data frames */
break;
/* Check ether_type from LLC */
llc = (struct ndpi_llc_header*)(packet + eth_offset + wifi_len + radio_len);
if(llc->dsap == SNAP)
type = ntohs(llc->snap.proto_ID);
/* Set IP header offset */
ip_offset = wifi_len + radio_len + sizeof(struct ndpi_llc_header) + eth_offset;
break;
case DLT_RAW:
ip_offset = eth_offset = 0;
break;
default:
/* printf("Unknown datalink %d\n", datalink_type); */
return;
}
/* check ether type */
switch(type) {
case VLAN:
vlan_id = ((packet[ip_offset] << 8) + packet[ip_offset+1]) & 0xFFF;
type = (packet[ip_offset+2] << 8) + packet[ip_offset+3];
ip_offset += 4;
vlan_packet = 1;
break;
case MPLS_UNI:
case MPLS_MULTI:
mpls = (struct ndpi_mpls_header *) &packet[ip_offset];
label = ntohl(mpls->label);
/* label = ntohl(*((u_int32_t*)&packet[ip_offset])); */
workflow->stats.mpls_count++;
type = ETH_P_IP, ip_offset += 4;
while((label & 0x100) != 0x100) {
ip_offset += 4;
label = ntohl(mpls->label);
}
break;
case PPPoE:
workflow->stats.pppoe_count++;
type = ETH_P_IP;
ip_offset += 8;
break;
default:
break;
}
workflow->stats.vlan_count += vlan_packet;
iph_check:
/* Check and set IP header size and total packet length */
iph = (struct ndpi_iphdr *) &packet[ip_offset];
/* just work on Ethernet packets that contain IP */
if(type == ETH_P_IP && header->caplen >= ip_offset) {
frag_off = ntohs(iph->frag_off);
proto = iph->protocol;
if(header->caplen < header->len) {
static u_int8_t cap_warning_used = 0;
if(cap_warning_used == 0) {
if(!workflow->prefs.quiet_mode)
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_DEBUG, "\n\nWARNING: packet capture size is smaller than packet size, DETECTION MIGHT NOT WORK CORRECTLY\n\n");
cap_warning_used = 1;
}
}
}
if(iph->version == 4) {
ip_len = ((u_short)iph->ihl * 4);
iph6 = NULL;
if(iph->protocol == 41) {
ip_offset += ip_len;
goto iph_check;
}
if((frag_off & 0x1FFF) != 0) {
static u_int8_t ipv4_frags_warning_used = 0;
workflow->stats.fragmented_count++;
if(ipv4_frags_warning_used == 0) {
if(!workflow->prefs.quiet_mode)
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_DEBUG, "\n\nWARNING: IPv4 fragments are not handled by this demo (nDPI supports them)\n");
ipv4_frags_warning_used = 1;
}
workflow->stats.total_discarded_bytes += header->len;
return;
}
} else if(iph->version == 6) {
iph6 = (struct ndpi_ipv6hdr *)&packet[ip_offset];
proto = iph6->ip6_ctlun.ip6_un1.ip6_un1_nxt;
ip_len = sizeof(struct ndpi_ipv6hdr);
if(proto == 0x3C /* IPv6 destination option */) {
u_int8_t *options = (u_int8_t*)&packet[ip_offset+ip_len];
proto = options[0];
ip_len += 8 * (options[1] + 1);
}
iph = NULL;
} else {
static u_int8_t ipv4_warning_used = 0;
v4_warning:
if(ipv4_warning_used == 0) {
if(!workflow->prefs.quiet_mode)
NDPI_LOG(0, workflow.ndpi_struct, NDPI_LOG_DEBUG, "\n\nWARNING: only IPv4/IPv6 packets are supported in this demo (nDPI supports both IPv4 and IPv6), all other packets will be discarded\n\n");
ipv4_warning_used = 1;
}
workflow->stats.total_discarded_bytes += header->len;
return;
}
if(workflow->prefs.decode_tunnels && (proto == IPPROTO_UDP)) {
struct ndpi_udphdr *udp = (struct ndpi_udphdr *)&packet[ip_offset+ip_len];
u_int16_t sport = ntohs(udp->source), dport = ntohs(udp->dest);
if((sport == GTP_U_V1_PORT) || (dport == GTP_U_V1_PORT)) {
/* Check if it's GTPv1 */
u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
u_int8_t flags = packet[offset];
u_int8_t message_type = packet[offset+1];
if((((flags & 0xE0) >> 5) == 1 /* GTPv1 */) &&
(message_type == 0xFF /* T-PDU */)) {
ip_offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr)+8; /* GTPv1 header len */
if(flags & 0x04) ip_offset += 1; /* next_ext_header is present */
if(flags & 0x02) ip_offset += 4; /* sequence_number is present (it also includes next_ext_header and pdu_number) */
if(flags & 0x01) ip_offset += 1; /* pdu_number is present */
iph = (struct ndpi_iphdr *) &packet[ip_offset];
if(iph->version != 4) {
// printf("WARNING: not good (packet_id=%u)!\n", (unsigned int)workflow->stats.raw_packet_count);
goto v4_warning;
}
}
} else if((sport == TZSP_PORT) || (dport == TZSP_PORT)) {
/* https://en.wikipedia.org/wiki/TZSP */
u_int offset = ip_offset+ip_len+sizeof(struct ndpi_udphdr);
u_int8_t version = packet[offset];
u_int8_t type = packet[offset+1];
u_int16_t encapsulates = ntohs(*((u_int16_t*)&packet[offset+2]));
if((version == 1) && (type == 0) && (encapsulates == 1)) {
u_int8_t stop = 0;
offset += 4;
while((!stop) && (offset < header->caplen)) {
u_int8_t tag_type = packet[offset];
u_int8_t tag_len;
switch(tag_type) {
case 0: /* PADDING Tag */
tag_len = 1;
break;
case 1: /* END Tag */
tag_len = 1, stop = 1;
break;
default:
tag_len = packet[offset+1];
break;
}
offset += tag_len;
if(offset >= header->caplen)
return; /* Invalid packet */
else {
eth_offset = offset;
goto datalink_check;
}
}
}
}
}
/* process the packet */
packet_processing(workflow, time, vlan_id, iph, iph6,
ip_offset, header->len - ip_offset, header->len);
}
-151
View File
@@ -1,151 +0,0 @@
/*
* ndpi_util.h
*
* Copyright (C) 2011-16 - ntop.org
*
* 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/>.
*
*/
/**
* This module contains routines to help setup a simple nDPI program.
*
* If you concern about performance or have to integrate nDPI in your
* application, you could need to reimplement them yourself.
*
* WARNING: this API is unstable! Use it at your own risk!
*/
#ifndef __NDPI_UTIL_H__
#define __NDPI_UTIL_H__
#include <pcap.h>
#define MAX_NUM_READER_THREADS 16
#define IDLE_SCAN_PERIOD 10 /* msec (use TICK_RESOLUTION = 1000) */
#define MAX_IDLE_TIME 30000
#define IDLE_SCAN_BUDGET 1024
#define NUM_ROOTS 512
#define MAX_NDPI_FLOWS 200000000
#define TICK_RESOLUTION 1000
// flow tracking
typedef struct ndpi_flow_info {
u_int32_t lower_ip;
u_int32_t upper_ip;
u_int16_t lower_port;
u_int16_t upper_port;
u_int8_t detection_completed, protocol;
u_int16_t vlan_id;
struct ndpi_flow_struct *ndpi_flow;
char lower_name[48], upper_name[48];
u_int8_t ip_version;
u_int64_t last_seen;
u_int64_t bytes;
u_int32_t packets;
// result only, not used for flow identification
ndpi_protocol detected_protocol;
char host_server_name[192];
char bittorent_hash[41];
struct {
char client_certificate[48], server_certificate[48];
} ssl;
void *src_id, *dst_id;
} ndpi_flow_info_t;
typedef struct ndpi_stats {
u_int32_t guessed_flow_protocols;
u_int64_t raw_packet_count;
u_int64_t ip_packet_count;
u_int64_t total_wire_bytes, total_ip_bytes, total_discarded_bytes;
u_int64_t protocol_counter[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
u_int64_t protocol_counter_bytes[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
u_int32_t protocol_flows[NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS + 1];
u_int32_t ndpi_flow_count;
u_int64_t tcp_count, udp_count;
u_int64_t mpls_count, pppoe_count, vlan_count, fragmented_count;
u_int64_t packet_len[6];
u_int16_t max_packet_len;
} ndpi_stats_t;
typedef struct ndpi_workflow_prefs {
u_int8_t decode_tunnels;
u_int8_t quiet_mode;
u_int32_t num_roots;
u_int32_t max_ndpi_flows;
} ndpi_workflow_prefs_t;
struct ndpi_workflow;
/** workflow, flow, user data */
typedef void (*ndpi_workflow_callback_ptr) (struct ndpi_workflow *, struct ndpi_flow_info *, void *);
typedef struct ndpi_workflow {
u_int64_t last_time;
struct ndpi_workflow_prefs prefs;
struct ndpi_stats stats;
ndpi_workflow_callback_ptr __flow_detected_callback;
void * __flow_detected_udata;
ndpi_workflow_callback_ptr __flow_giveup_callback;
void * __flow_giveup_udata;
/* outside referencies */
pcap_t *pcap_handle;
/* allocated by prefs */
void **ndpi_flows_root;
struct ndpi_detection_module_struct *ndpi_struct;
} ndpi_workflow_t;
/* TODO: remove wrappers parameters and use ndpi global, when their initialization will be fixed... */
struct ndpi_workflow * ndpi_workflow_init(const struct ndpi_workflow_prefs * prefs, pcap_t * pcap_handle);
void ndpi_workflow_free(struct ndpi_workflow * workflow);
/** Free flow_info ndpi support structures but not the flow_info itself
*
* TODO remove! Half freeing things is bad!
*/
void ndpi_free_flow_info_half(struct ndpi_flow_info *flow);
/** Process a @packet and update the @workflow. */
void ndpi_workflow_process_packet (struct ndpi_workflow * workflow,
const struct pcap_pkthdr *header,
const u_char *packet);
/* flow callbacks: ndpi_flow_info will be freed right after */
static inline void ndpi_workflow_set_flow_detected_callback(struct ndpi_workflow * workflow,
ndpi_workflow_callback_ptr callback,
void * udata) {
workflow->__flow_detected_callback = callback;
workflow->__flow_detected_udata = udata;
}
static inline void ndpi_workflow_set_flow_giveup_callback(struct ndpi_workflow * workflow,
ndpi_workflow_callback_ptr callback,
void * udata) {
workflow->__flow_giveup_callback = callback;
workflow->__flow_giveup_udata = udata;
}
int ndpi_workflow_node_cmp(const void *a, const void *b);
#endif
-18
View File
@@ -1,6 +1,4 @@
ndpi_dump_protocols
ndpi_strnstr
ndpi_detection_giveup
ndpi_get_proto_name
ndpi_free
ndpi_guess_undetected_protocol
@@ -12,7 +10,6 @@ ndpi_detection_get_sizeof_ndpi_flow_struct
ndpi_load_protocols_file
ndpi_tdestroy
ndpi_exit_detection_module
ndpi_l4_detection_process_packet
ndpi_detection_process_packet
ndpi_twalk
ndpi_tdelete
@@ -31,18 +28,3 @@ ndpi_get_proto_breed_name
ndpi_get_proto_by_id
ndpi_get_protocol_id_master_proto
ndpi_guess_protocol_id
ndpi_protocol2name
ndpi_get_lower_proto
ndpi_is_proto
ndpi_malloc
ndpi_calloc
ndpi_set_detected_protocol
ndpi_match_string_subprotocol
ndpi_init_automa
ndpi_free_automa
ndpi_add_string_to_automa
ndpi_finalize_automa
ndpi_match_string
set_ndpi_malloc
set_ndpi_free
set_ndpi_debug_function
+4
View File
@@ -0,0 +1,4 @@
This package is a GPL implementation of an iptables and netfilter module for
nDPI integration into the Linux kernel.
https://github.com/ewildgoose/ndpi-netfilter
+5 -6
View File
@@ -1,15 +1,14 @@
class Ndpi < Formula
desc "Deep Packet Inspection (DPI) library"
homepage "http://www.ntop.org/products/ndpi/"
url "https://downloads.sourceforge.net/project/ntop/nDPI/nDPI-1.8.tgz"
sha256 "f490137a7387b69d0d55e990f2150b86d7b5eaae870e5326e8c2f18c17412443"
url "https://downloads.sourceforge.net/project/ntop/nDPI/nDPI-1.7.tar.gz"
sha256 "714b745103a072462130b0e14cf31b2eb5270f580b7c839da5cf5ea75150262d"
bottle do
cellar :any
sha256 "05053767fc3c70557745c348c7352e7c2716c040ca54c5cf8d5306167c878fcb" => :el_capitan
sha256 "34c0269039a0079820eeed862daa28158d9291f73f640a9415da60746d69a662" => :yosemite
sha256 "a2af4dc62c24313593b3a20e45ca9d2d49f8efc0ea5e52fd064001ea441b93e4" => :mavericks
sha256 "1bb200268a4d9df9bbe5d33bc773ee3bcf4b5d4fa00c76a040f16318438c284f" => :mountain_lion
sha256 "e9464d314479ba3e7a91422e0bc606cfd5f6e72e94d6441cc4fa30e9c925da5c" => :yosemite
sha256 "1d6b1d860669b42766baa276ed948c342e2fa4fd28663ba64a90fd0e200ba9c4" => :mavericks
sha256 "b814918b4fb9588de7126061ce4ac3eb41a5c3eee27c7432b669f6dc6921bfde" => :mountain_lion
end
depends_on "autoconf" => :build
+115 -518
View File
@@ -1,7 +1,8 @@
/*
* ndpi_api.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -31,190 +32,96 @@
extern "C" {
#endif
#define NDPI_DETECTION_ONLY_IPV4 ( 1 << 0 )
#define NDPI_DETECTION_ONLY_IPV6 ( 1 << 1 )
#define ADD_TO_DETECTION_BITMASK 1
#define NO_ADD_TO_DETECTION_BITMASK 0
#define SAVE_DETECTION_BITMASK_AS_UNKNOWN 1
#define NO_SAVE_DETECTION_BITMASK_AS_UNKNOWN 0
/**
* Check if a string is encoded with punycode
* ( https://tools.ietf.org/html/rfc3492 )
*
* @par buff = pointer to the string to ckeck
* @par len = len of the string
* @return 1 if the string is punycoded;
* else 0
*
*/
int check_punycode_string(char * buff , int len);
/**
* Get the size of the flow struct
*
* @return the size of the flow struct
*
/**
* This function returns the size of the flow struct
* @return the size of the flow struct
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_flow_struct(void);
/**
* Get the size of the id struct
*
* @return the size of the id struct
*
/**
* This function returns the size of the id struct
* @return the size of the id struct
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_id_struct(void);
/* Public malloc/free */
void* ndpi_malloc(unsigned long size);
void* ndpi_calloc(unsigned long count, unsigned long size);
void ndpi_free(void *ptr);
void *ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
char *ndpi_strdup(const char *s);
/**
* nDPI personal allocation and free functions
**/
void * ndpi_malloc(size_t size);
void * ndpi_calloc(unsigned long count, size_t size);
void * ndpi_realloc(void *ptr, size_t old_size, size_t new_size);
char * ndpi_strdup(const char *s);
void ndpi_free(void *ptr);
/**
* Search the first occurrence of substring -find- in -s-
* The search is limited to the first -slen- characters of the string
*
* @par s = string to parse
* @par find = string to match with -s-
* @par slen = max length to match between -s- and -find-
* @return a pointer to the beginning of the located substring;
* NULL if the substring is not found
*
* Find the first occurrence of find in s, where the search is limited to the
* first slen characters of s.
*/
char* ndpi_strnstr(const char *s, const char *find, size_t slen);
/**
* Returns the nDPI protocol id for IP-based protocol detection
*
* @par ndpi_struct = the struct created for the protocol detection
* @par pin = IP host address (MUST BE in network byte order):
* See man(7) ip for details
* @return the nDPI protocol ID
*
* This function returns the nDPI protocol id for IP-based protocol detection
*/
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin);
/**
* Same as ndpi_network_ptree_match
*/
u_int16_t ndpi_host_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t host);
/**
* Init single protocol match
*
* @par ndpi_mod = the struct created for the protocol detection
* @par match = the struct passed to match the protocol
*
*/
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol_match *match);
/**
* Returns a new initialized detection module
*
* @return the initialized detection module
*
* This function returns a new initialized detection module.
* @param ticks_per_second the timestamp resolution per second (like 1000 for millisecond resolution)
* @param __ndpi_malloc function pointer to a memory allocator
* @param ndpi_debug_printf a function pointer to a debug output function, use NULL in productive envionments
* @return the initialized detection module
*/
struct ndpi_detection_module_struct *ndpi_init_detection_module();
struct ndpi_detection_module_struct *ndpi_init_detection_module(u_int32_t ticks_per_second,
void* (*__ndpi_malloc)(unsigned long size),
void (*__ndpi_free)(void *ptr),
ndpi_debug_function_ptr ndpi_debug_printf);
/**
* Frees the memory allocated in the specified flow
*
* @par flow = the flow to deallocate
*
* This function frees the memory allocated in the specified flow
* @param flow to free
*/
void ndpi_free_flow(struct ndpi_flow_struct *flow);
/**
* Enables cache support.
* In nDPI is used for some protocol (i.e. Skype)
*
* @par ndpi_mod = the struct created for the protocol detection
* @par host = string for the host name
* @par port = unsigned int for the port number
*
* This function enables cache support in nDPI used for some protocol such as Skype
* @param host host name
* @param port port number
*/
void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod, char* host, u_int port);
/**
* Destroys the detection module
*
* @par ndpi_struct = the struct to clearing for the detection module
*
* This function destroys the detection module
* @param ndpi_struct the to clearing detection module
* @param ndpi_free function pointer to a memory free function
*/
void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct);
void
ndpi_exit_detection_module(struct ndpi_detection_module_struct
*ndpi_struct, void (*ndpi_free) (void *ptr));
/**
* Sets a single protocol bitmask
* This function does not increment the index of the callback_buffer
*
* @par label = string for the protocol name
* @par ndpi_struct = the detection module
* @par detection_bitmask = the protocol bitmask
* @par idx = the index of the callback_buffer
* @par func = function pointer of the protocol search
* @par ndpi_selection_bitmask = the protocol selected bitmask
* @par b_save_bitmask_unknow = if set as "true" save the detection bitmask as unknow
* @par b_add_detection_bitmask = if set as "true" add the protocol bitmask to the detection bitmask
*
* This function sets the protocol bitmask2
* @param ndpi_struct the detection module
* @param detection_bitmask the protocol bitmask
*/
void ndpi_set_bitmask_protocol_detection(char *label, struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK *detection_bitmask,
const u_int32_t idx,
u_int16_t ndpi_protocol_id,
void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow),
const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask,
u_int8_t b_save_bitmask_unknow,
u_int8_t b_add_detection_bitmask);
void
ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
/**
* Sets the protocol bitmask2
*
* @par ndpi_struct = the detection module
* @par detection_bitmask = the protocol bitmask to set
*
*/
void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK * detection_bitmask);
/**
* Function to be called before we give up with detection for a given flow.
* This function reduces the NDPI_UNKNOWN_PROTOCOL detection
*
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module
* @return the detected protocol even if the flow is not completed;
*
*/
ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
/**
* Processes one packet and returns the ID of the detected protocol.
* This is the MAIN PACKET PROCESSING FUNCTION.
*
* @par ndpi_struct = the detection module
* @par flow = pointer to the connection state machine
* @par packet = unsigned char pointer to the Layer 3 (IP header)
* @par packetlen = the length of the packet
* @par current_tick = the current timestamp for the packet
* @par src = pointer to the source subscriber state machine
* @par dst = pointer to the destination subscriber state machine
* @return the detected ID of the protocol
* This function will processes one packet and returns the ID of the detected protocol.
* This is the main packet processing function.
*
* @param ndpi_struct the detection module
* @param flow void pointer to the connection state machine
* @param packet the packet as unsigned char pointer with the length of packetlen. the pointer must point to the Layer 3 (IP header)
* @param packetlen the length of the packet
* @param current_tick the current timestamp for the packet
* @param src void pointer to the source subscriber state machine
* @param dst void pointer to the destination subscriber state machine
* @return returns the detected ID of the protocol
*/
ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
@@ -224,418 +131,108 @@ extern "C" {
struct ndpi_id_struct *src,
struct ndpi_id_struct *dst);
/**
* Processes one packet of L4 and returns the ID of the detected protocol.
* L3 and L4 packet headers are passed in the arguments while payload
* points to the L4 body.
* This function mimics ndpi_detection_process_packet behaviour.
*
* @par ndpi_struct = the detection module
* @par flow = pointer to the connection state machine
* @par iph = IP packet header for IPv4 or NULL
* @par iph6 = IP packet header for IPv6 or NULL
* @par tcp = TCP packet header for TCP or NULL
* @par udp = UDP packet header for UDP or NULL
* @par src_to_dst_direction = order of src/dst state machines in a flow.
* @par l4_proto = L4 protocol of the packet.
* @par src = pointer to the source subscriber state machine
* @par dst = pointer to the destination subscriber state machine
* @par sport = source port of L4 packet, used for protocol guessing.
* @par dport = destination port of L4 packet, used for protocol guessing.
* @par current_tick_l = the current timestamp for the packet
* @par payload = unsigned char pointer to the Layer 4 (TCP/UDP body)
* @par payload_len = the length of the payload
* @return the detected ID of the protocol
*
* NOTE: in a current implementation flow->src and flow->dst are swapped with
* the src_to_dst_direction flag while ndpi_detection_process_packet does not swap
* these values.
*
*/
ndpi_protocol ndpi_l4_detection_process_packet(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const struct ndpi_iphdr *iph,
struct ndpi_ipv6hdr *iph6,
struct ndpi_tcphdr *tcp,
struct ndpi_udphdr *udp,
u_int8_t src_to_dst_direction,
u_int8_t l4_proto,
struct ndpi_id_struct *src,
u_int16_t sport,
struct ndpi_id_struct *dst,
u_int16_t dport,
const u_int64_t current_tick_l,
u_int8_t *payload, u_int16_t payload_len);
/**
* Get the main protocol of the passed flows for the detected module
*
*
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module
* @return the ID of the master protocol detected
*
*/
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
#define NDPI_DETECTION_ONLY_IPV4 ( 1 << 0 )
#define NDPI_DETECTION_ONLY_IPV6 ( 1 << 1 )
/**
* Query the pointer to the layer 4 packet
*
* @par l3 = pointer to the layer 3 data
* @par l3_len = length of the layer 3 data
* @par l4_return = address to the pointer of the layer 4 data if return value == 0, else undefined
* @par l4_len_return = length of the layer 4 data if return value == 0, else undefined
* @par l4_protocol_return = protocol of the layer 4 data if return value == 0, undefined otherwise
* @par flags = limit operation on ipv4 or ipv6 packets. Possible values: NDPI_DETECTION_ONLY_IPV4 - NDPI_DETECTION_ONLY_IPV6 - 0 (any)
* @return 0 if layer 4 data could be found correctly;
else != 0
* query the pointer to the layer 4 packet
*
* @param l3 pointer to the layer 3 data
* @param l3_len length of the layer 3 data
* @param l4_return filled with the pointer the layer 4 data if return value == 0, undefined otherwise
* @param l4_len_return filled with the length of the layer 4 data if return value == 0, undefined otherwise
* @param l4_protocol_return filled with the protocol of the layer 4 data if return value == 0, undefined otherwise
* @param flags limit operation on ipv4 or ipv6 packets, possible values are NDPI_DETECTION_ONLY_IPV4 or NDPI_DETECTION_ONLY_IPV6; 0 means any
* @return 0 if correct layer 4 data could be found, != 0 otherwise
*/
u_int8_t ndpi_detection_get_l4(const u_int8_t *l3, u_int16_t l3_len, const u_int8_t **l4_return, u_int16_t *l4_len_return,
u_int8_t *l4_protocol_return, u_int32_t flags);
u_int8_t ndpi_detection_get_l4(const u_int8_t * l3, u_int16_t l3_len, const u_int8_t ** l4_return, u_int16_t * l4_len_return,
u_int8_t * l4_protocol_return, u_int32_t flags);
#if 0
/**
* returns true if the protocol history of the flow of the last packet given to the detection
* contains the given protocol.
*
* @param ndpi_struct the detection module
* @return 1 if protocol has been found, 0 otherwise
*
*/
u_int8_t ndpi_detection_flow_protocol_history_contains_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t protocol_id);
#endif
/**
* Search and return the protocol based on matched ports
*
* @par ndpi_struct = the detection module
* @par shost = source address in host byte order
* @par sport = source port number
* @par dhost = destination address in host byte order
* @par dport = destination port number
* @return the struct ndpi_protocol that match the port base protocol
*
*/
ndpi_protocol ndpi_find_port_based_protocol(struct ndpi_detection_module_struct *ndpi_struct/* , u_int8_t proto */,
u_int32_t shost,
u_int16_t sport,
u_int32_t dhost,
u_int16_t dport);
/**
* Search and return the protocol guessed that is undetected
*
* @par ndpi_struct = the detection module
* @par proto = the l4 protocol number
* @par shost = source address in host byte order
* @par sport = source port number
* @par dhost = destination address in host byte order
* @par dport = destination port number
* @return the struct ndpi_protocol that match the port base protocol
*
*/
struct ndpi_flow_struct *flow,
u_int16_t protocol_id);
ndpi_protocol ndpi_find_port_based_protocol(struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t proto, u_int32_t shost, u_int16_t sport, u_int32_t dhost, u_int16_t dport);
ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t proto,
u_int32_t shost,
u_int16_t sport,
u_int32_t dhost,
u_int16_t dport);
/**
* Check if the string passed match with a protocol
*
* @par ndpi_struct = the detection module
* @par string_to_match = the string to match
* @par string_to_match_len = the length of the string
* @par is_host_match = value of the second field of struct ndpi_automa
* @return the ID of the matched subprotocol
*
*/
int ndpi_match_string_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
char *string_to_match,
u_int string_to_match_len,
u_int8_t is_host_match);
/**
* Check if the host passed match with a protocol
*
* @par ndpi_struct = the detection module
* @par flow = the flow where match the host
* @par string_to_match = the string to match
* @par string_to_match_len = the length of the string
* @par master_protocol_id = value of the ID associated to the master protocol detected
* @return the ID of the matched subprotocol
*
*/
u_int8_t proto, u_int32_t shost, u_int16_t sport, u_int32_t dhost, u_int16_t dport);
int ndpi_match_host_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
char *string_to_match,
u_int string_to_match_len,
struct ndpi_flow_struct *flow, char *string_to_match, u_int string_to_match_len,
u_int16_t master_protocol_id);
/**
* Check if the string content passed match with a protocol
*
* @par ndpi_struct = the detection module
* @par flow = the flow where match the host
* @par string_to_match = the string to match
* @par string_to_match_len = the length of the string
* @par master_protocol_id = value of the ID associated to the master protocol detected
* @return the ID of the matched subprotocol
*
*/
int ndpi_match_content_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
char *string_to_match,
u_int string_to_match_len,
char *string_to_match, u_int string_to_match_len,
u_int16_t master_protocol_id);
/**
* Check if the string -bigram_to_match- match with a bigram of -automa-
*
* @par ndpi_struct = the detection module
* @par automa = the struct ndpi_automa for the bigram
* @par bigram_to_match = the bigram string to match
* @return 0
*
*/
int ndpi_match_bigram(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_automa *automa,
char *bigram_to_match);
/**
* Write the protocol name in the buffer -buf- as master_protocol.protocol
*
* @par ndpi_mod = the detection module
* @par proto = the struct ndpi_protocol contain the protocols name
* @par buf = the buffer to write the name of the protocols
* @par buf_len = the length of the buffer
* @return the buffer contains the master_protocol and protocol name
*
*/
ndpi_automa *automa, char *bigram_to_match);
char* ndpi_protocol2name(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol proto, char *buf, u_int buf_len);
/**
* Get the protocol name associated to the ID
*
* @par mod = the detection module
* @par proto_id = the ID of the protocol
* @return the buffer contains the master_protocol and protocol name
*
*/
char* ndpi_get_proto_name(struct ndpi_detection_module_struct *mod, u_int16_t proto_id);
/**
* Return the protocol breed ID associated to the protocol
*
* @par ndpi_struct = the detection module
* @par proto = the ID of the protocol
* @return the breed ID associated to the protocol
*
*/
ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t proto);
/**
* Return the string name of the protocol breed
*
* @par ndpi_struct = the detection module
* @par breed_id = the breed ID associated to the protocol
* @return the string name of the breed ID
*
*/
char* ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_struct, ndpi_protocol_breed_t breed_id);
/**
* Return the ID of the protocol
*
* @par ndpi_mod = the detection module
* @par proto = the ID of the protocol
* @return the string name of the breed ID
*
*/
int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto);
/**
* Write the list of the supported protocols
*
* @par ndpi_mod = the detection module
*/
void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod);
int matchStringProtocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
char *string_to_match, u_int string_to_match_len);
/**
* Read a file and load the protocols
*
* Format: <tcp|udp>:<port>,<tcp|udp>:<port>,.....@<proto>
*
* Example:
* tcp:80,tcp:3128@HTTP
* udp:139@NETBIOS
*
* @par ndpi_mod = the detection module
* @par path = the path of the file
* @return 0 if the file is loaded correctly;
* -1 else
*
*/
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path);
/**
* Get the total number of the supported protocols
*
* @par ndpi_mod = the detection module
* @return the number of protocols
*
*/
u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
/**
* Get the nDPI version release
*
* @return the NDPI_GIT_RELEASE
*
*/
char* ndpi_revision(void);
/**
* Set the automa for the protocol search
*
* @par ndpi_struct = the detection module
* @par automa = the automa to match
*
*/
void ndpi_set_automa(struct ndpi_detection_module_struct *ndpi_struct, void* automa);
#define ADD_TO_DETECTION_BITMASK 1
#define NO_ADD_TO_DETECTION_BITMASK 0
#define SAVE_DETECTION_BITMASK_AS_UNKNOWN 1
#define NO_SAVE_DETECTION_BITMASK_AS_UNKNOWN 0
/**
* This function sets a single protocol bitmask
* @param label Protocol name
* @param ndpi_struct the detection module
* @param detection_bitmask the protocol bitmask
* @param idx the index of the callback_buffer
* @param func void function point of the protocol search
* @param ndpi_selection_bitmask the protocol selected bitmask
* @param b_save_bitmask_unknow set true if you want save the detection bitmask as unknow
* @param b_add_detection_bitmask set true if you want add the protocol bitmask to the detection bitmask
* NB: this function does not increment the index of the callback_buffer
*/
void ndpi_set_bitmask_protocol_detection(char * label, struct ndpi_detection_module_struct *ndpi_struct,
const NDPI_PROTOCOL_BITMASK * detection_bitmask,
const u_int32_t idx,
u_int16_t ndpi_protocol_id,
void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow),
const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask,
u_int8_t b_save_bitmask_unknow,
u_int8_t b_add_detection_bitmask);
#ifdef NDPI_PROTOCOL_HTTP
/**
* Retrieve information for HTTP flows
*
* @par ndpi_mod = the detection module
* @par flow = the detected flow
* @return the HTTP method information about the flow
*
/*
API used to retrieve information for HTTP flows
*/
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod, struct ndpi_flow_struct *flow);
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow);
/**
* Get the HTTP url
*
* @par ndpi_mod = the detection module
* @par flow = the detected flow
* @return the HTTP method information about the flow
*
*/
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod, struct ndpi_flow_struct *flow);
/**
* Get the HTTP content-type
*
* @par ndpi_mod = the detection module
* @par flow = the detected flow
* @return the HTTP method information about the flow
*
*/
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod, struct ndpi_flow_struct *flow);
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow);
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow);
#endif
#ifdef NDPI_PROTOCOL_TOR
/**
* Check if the flow could be detected as TOR protocol
*
* @par ndpi_struct = the detection module
* @par flow = the detected flow
* @par certificate = the ssl certificate
* @return 1 if the flow is TOR;
* 0 else
*
*/
int ndpi_is_ssl_tor(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, char *certificate);
#endif
/* Wrappers functions */
/**
* Init Aho-Corasick automata
*
* @return The requested automata, or NULL if an error occurred
*
*/
void* ndpi_init_automa();
/**
* Free Aho-Corasick automata allocated with ndpi_init_automa();
*
* @par The automata initialized with ndpi_init_automa();
*
*/
void ndpi_free_automa(void *_automa);
/**
* Add a string to match to an automata
*
* @par The automata initialized with ndpi_init_automa();
* @par The (sub)string to search
* @return 0 in case of no error, or -1 if an error occurred.
*
*/
int ndpi_add_string_to_automa(void *_automa, char *str);
/**
* Finalize the automa (necessary before start searching)
*
* @par The automata initialized with ndpi_init_automa();
*
*/
void ndpi_finalize_automa(void *_automa);
/**
* Add a string to match to an automata
*
* @par The automata initialized with ndpi_init_automa();
* @par The (sub)string to search
* @return 0 in case of match, or -1 if no match, or -2 if an error occurred.
*
*/
int ndpi_match_string(void *_automa, char *string_to_match);
/* Utility functions to set ndpi malloc/free/print wrappers */
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
void set_ndpi_free(void (*__ndpi_free)(void *ptr));
void set_ndpi_debug_function(ndpi_debug_function_ptr ndpi_debug_printf);
#ifdef __cplusplus
}
#endif
+14 -15
View File
@@ -1,6 +1,7 @@
/*
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -76,7 +77,7 @@
#endif
#define NDPI_USE_ASYMMETRIC_DETECTION 0
#define NDPI_USE_ASYMMETRIC_DETECTION 0
#define NDPI_SELECTION_BITMASK_PROTOCOL_SIZE u_int32_t
#define NDPI_SELECTION_BITMASK_PROTOCOL_IP (1<<0)
@@ -159,24 +160,24 @@
/* TODO: rebuild all memory areas to have a more aligned memory block here */
/* DEFINITION OF MAX LINE NUMBERS FOR line parse algorithm */
#define NDPI_MAX_PARSE_LINES_PER_PACKET 64
#define NDPI_MAX_PARSE_LINES_PER_PACKET 64
#define MAX_PACKET_COUNTER 65000
#define MAX_DEFAULT_PORTS 5
#define NDPI_DIRECTCONNECT_CONNECTION_IP_TICK_TIMEOUT 600
#define NDPI_IRC_CONNECTION_TIMEOUT 120
#define NDPI_GNUTELLA_CONNECTION_TIMEOUT 60
#define NDPI_BATTLEFIELD_CONNECTION_TIMEOUT 60
#define NDPI_THUNDER_CONNECTION_TIMEOUT 30
#define NDPI_RTSP_CONNECTION_TIMEOUT 5
#define NDPI_TVANTS_CONNECTION_TIMEOUT 5
#define NDPI_YAHOO_DETECT_HTTP_CONNECTIONS 1
#define NDPI_YAHOO_LAN_VIDEO_TIMEOUT 30
#define NDPI_GNUTELLA_CONNECTION_TIMEOUT 60
#define NDPI_BATTLEFIELD_CONNECTION_TIMEOUT 60
#define NDPI_THUNDER_CONNECTION_TIMEOUT 30
#define NDPI_RTSP_CONNECTION_TIMEOUT 5
#define NDPI_TVANTS_CONNECTION_TIMEOUT 5
#define NDPI_YAHOO_DETECT_HTTP_CONNECTIONS 1
#define NDPI_YAHOO_LAN_VIDEO_TIMEOUT 30
#define NDPI_ZATTOO_CONNECTION_TIMEOUT 120
#define NDPI_ZATTOO_FLASH_TIMEOUT 5
#define NDPI_JABBER_STUN_TIMEOUT 30
#define NDPI_JABBER_FT_TIMEOUT 5
#define NDPI_ZATTOO_FLASH_TIMEOUT 5
#define NDPI_JABBER_STUN_TIMEOUT 30
#define NDPI_JABBER_FT_TIMEOUT 5
#define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
@@ -291,6 +292,4 @@
#define snprintf _snprintf
#endif
#define NDPI_MAX_DNS_REQUESTS 16
#endif /* __NDPI_DEFINE_INCLUDE_FILE__ */
+1 -2
View File
@@ -1,7 +1,7 @@
/*
* ndpi_includes.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - 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
@@ -35,7 +35,6 @@
#ifdef WIN32
#include "ndpi_win32.h"
#else
#include <sys/types.h>
#include <sys/param.h>
#include <pthread.h>
#include <arpa/inet.h>
+2 -19
View File
@@ -1,7 +1,8 @@
/*
* ndpi_main.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -31,9 +32,6 @@
#include "ndpi_protocols.h"
#include "ndpi_api.h"
#ifdef __cplusplus
extern "C" {
#endif
void *ndpi_tdelete(const void * __restrict, void ** __restrict,
int (*)(const void *, const void *));
@@ -109,19 +107,4 @@ void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct *
const char **file, const char **func, u_int32_t * line);
#endif
/** Checks when the @p payload starts with the string literal @p str.
* When the string is larger than the payload, check fails.
* @return non-zero if check succeeded
*/
int ndpi_match_prefix(const u_int8_t *payload, size_t payload_len,
const char *str, size_t str_len);
/* version of ndpi_match_prefix with string literal */
#define ndpi_match_strprefix(payload, payload_len, str) \
ndpi_match_prefix((payload), (payload_len), (str), (sizeof(str)-1))
#ifdef __cplusplus
}
#endif
#endif /* __NDPI_MAIN_H__ */
+17 -25
View File
@@ -1,7 +1,8 @@
/*
* ndpi_protocol_ids.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-11 - ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -48,14 +49,14 @@
#define NDPI_PROTOCOL_IP_ICMPV6 102
#define NDPI_PROTOCOL_HTTP 7
#define NDPI_PROTOCOL_HTTP_DOWNLOAD 60
#define NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV 60
#define NDPI_PROTOCOL_SSL_NO_CERT 64 /* SSL without certificate (Skype, Ultrasurf?) - ntop.org */
#define NDPI_PROTOCOL_SSL 91
#define NDPI_PROTOCOL_HTTP_APPLICATION_ACTIVESYNC 110
#define NDPI_PROTOCOL_HTTP_CONNECT 130
#define NDPI_PROTOCOL_HTTP_PROXY 131
#define NDPI_PROTOCOL_SOCKS 172 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_PROTOCOL_SOCKS5 172 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_PROTOCOL_SOCKS4 173 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_PROTOCOL_FTP_CONTROL 1 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_PROTOCOL_MAIL_POP 2
@@ -82,7 +83,7 @@
#define NDPI_PROTOCOL_APPLEJUICE 24
#define NDPI_PROTOCOL_DIRECTCONNECT 25
#define NDPI_PROTOCOL_SOCRATES 26
#define NDPI_PROTOCOL_COAP 27
#define NDPI_PROTOCOL_WINMX 27
#define NDPI_PROTOCOL_VMWARE 28
#define NDPI_PROTOCOL_MAIL_SMTPS 29
#define NDPI_PROTOCOL_FILETOPIA 30
@@ -202,7 +203,7 @@
#define NDPI_PROTOCOL_TEREDO 214
#define NDPI_PROTOCOL_HEP 216 /* Sipcapture.org QXIP BV */
#define NDPI_PROTOCOL_UBNTAC2 217 /* Ubiquity UBNT AirControl 2 - Thomas Fjellstrom <thomas+ndpi@fjellstrom.ca> */
#define NDPI_PROTOCOL_MS_LYNC 173
#define NDPI_PROTOCOL_MS_LYNC 218
@@ -231,15 +232,15 @@
#define NDPI_SERVICE_APPLE_ICLOUD 143
#define NDPI_SERVICE_APPLE_ITUNES 145
#define NDPI_SERVICE_TUENTI 149
#define NDPI_SERVICE_WIKIPEDIA 176 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_MSN NDPI_PROTOCOL_MSN /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_AMAZON 178 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_EBAY 179 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_CNN 180 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_WIKIPEDIA 176 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_MSN NDPI_PROTOCOL_MSN /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_AMAZON 178 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_EBAY 179 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_CNN 180 /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_DROPBOX NDPI_PROTOCOL_DROPBOX /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_SKYPE NDPI_PROTOCOL_SKYPE /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_VIBER NDPI_PROTOCOL_VIBER
#define NDPI_SERVICE_YAHOO NDPI_PROTOCOL_YAHOO /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_SKYPE NDPI_PROTOCOL_SKYPE /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_VIBER NDPI_PROTOCOL_VIBER /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_YAHOO NDPI_PROTOCOL_YAHOO /* Tomasz Bujlow <tomasz@skatnet.dk> */
#define NDPI_SERVICE_PANDORA 187
#define NDPI_PROTOCOL_EAQ 190
#define NDPI_SERVICE_TIMMEU 191
@@ -265,18 +266,9 @@
#define NDPI_SERVICE_INSTAGRAM 211 /* Andrea Buscarinu <andrea.buscarinu@gmail.com> */
#define NDPI_SERVICE_MICROSOFT 212
#define NDPI_SERVICE_HOTSPOT_SHIELD 215
#define NDPI_SERVICE_OCS 218
#define NDPI_SERVICE_OFFICE_365 219
#define NDPI_SERVICE_CLOUDFLARE 220
#define NDPI_SERVICE_MS_ONE_DRIVE 221
#define NDPI_PROTOCOL_MQTT 222
#define NDPI_PROTOCOL_RX 223
#define NDPI_SERVICE_WEIBO 224
#define NDPI_SERVICE_OPENDNS 225
#define NDPI_PROTOCOL_GIT 226
#define NDPI_PROTOCOL_DRDA 227
/* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_DRDA
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_PROTOCOL_MS_LYNC
#define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1)
#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL)
+11 -12
View File
@@ -1,7 +1,8 @@
/*
* ndpi_protocols.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -52,9 +53,14 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
/* Applications and other protocols. */
void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_bittorrent_init(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t size,u_int32_t timeout);
void ndpi_bittorrent_done(struct ndpi_detection_module_struct *ndpi_struct);
int ndpi_bittorrent_gc(struct hash_ip4p_table *ht,int key,time_t now);
void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_fasttrack_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_winmx_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_directconnect(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_applejuice_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_i23v5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
@@ -191,11 +197,8 @@ void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struc
void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_starcraft(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_coap(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_rx(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
void ndpi_search_drda(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
/* --- INIT FUNCTIONS --- */
void init_afp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_aimini_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -295,7 +298,6 @@ void init_snmp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int
void init_socrates_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_sopcast_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_soulseek_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_socks_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_spotify_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ssh_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ssl_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -324,6 +326,7 @@ void init_vmware_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_i
void init_vnc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_warcraft3_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_whois_das_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_winmx_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_world_of_warcraft_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_world_of_kung_fu_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_xbox_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -333,9 +336,5 @@ void init_zattoo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_i
void init_zmq_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_stracraft_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ubntac2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_coap_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mqtt_dissector (struct ndpi_detection_module_struct *ndpi_struct,u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_rx_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_git_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_drda_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
#endif /* __NDPI_PROTOCOLS_H__ */
+30 -50
View File
@@ -1,7 +1,8 @@
/*
* ndpi_typedefs.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-11 - ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -269,12 +270,7 @@ struct ndpi_udphdr
PACK_ON
struct ndpi_dns_packet_header {
u_int16_t tr_id;
u_int16_t flags;
u_int16_t num_queries;
u_int16_t num_answers;
u_int16_t authority_rrs;
u_int16_t additional_rrs;
u_int16_t transaction_id, flags, num_queries, answer_rrs, authority_rrs, additional_rrs;
} PACK_OFF;
typedef union
@@ -344,7 +340,7 @@ typedef enum {
HTTP_METHOD_CONNECT
} ndpi_http_method;
struct ndpi_id_struct {
typedef struct ndpi_id_struct {
/**
detected_protocol_bitmask:
access this bitmask to find out whether an id has used skype or not
@@ -440,7 +436,7 @@ struct ndpi_id_struct {
#ifdef NDPI_PROTOCOL_RTSP
u_int32_t rtsp_ts_set:1;
#endif
};
} ndpi_id_struct;
/* ************************************************** */
@@ -473,6 +469,9 @@ struct ndpi_flow_tcp_struct {
u_int32_t irc_direction:2;
u_int32_t irc_0x1000_full:1;
#endif
#ifdef NDPI_PROTOCOL_WINMX
u_int32_t winmx_stage:1; // 0 - 1
#endif
#ifdef NDPI_PROTOCOL_SOULSEEK
u_int32_t soulseek_stage:2;
#endif
@@ -621,10 +620,6 @@ struct ndpi_flow_udp_struct {
u_int8_t eaq_pkt_id;
u_int32_t eaq_sequence;
#endif
#ifdef NDPI_PROTOCOL_RX
u_int32_t rx_conn_epoch;
u_int32_t rx_conn_id;
#endif
}
#ifndef WIN32
__attribute__ ((__packed__))
@@ -633,12 +628,12 @@ struct ndpi_flow_udp_struct {
/* ************************************************** */
struct ndpi_int_one_line_struct {
typedef struct ndpi_int_one_line_struct {
const u_int8_t *ptr;
u_int16_t len;
};
} ndpi_int_one_line_struct_t;
struct ndpi_packet_struct {
typedef struct ndpi_packet_struct {
const struct ndpi_iphdr *iph;
#ifdef NDPI_DETECTION_SUPPORT_IPV6
const struct ndpi_ipv6hdr *iphv6;
@@ -693,22 +688,22 @@ struct ndpi_packet_struct {
u_int8_t packet_lines_parsed_complete:1,
packet_direction:1,
empty_line_position_set:1;
};
} ndpi_packet_struct_t;
struct ndpi_detection_module_struct;
struct ndpi_flow_struct;
struct ndpi_call_function_struct {
typedef struct ndpi_call_function_struct {
NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK excluded_protocol_bitmask;
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask;
void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow);
u_int8_t detection_feature;
};
} ndpi_call_function_struct_t;
struct ndpi_subprotocol_conf_struct {
typedef struct ndpi_subprotocol_conf_struct {
void (*func) (struct ndpi_detection_module_struct *, char *attr, char *value, int protocol_id);
};
} ndpi_subprotocol_conf_struct_t;
typedef struct {
@@ -751,8 +746,7 @@ typedef struct ndpi_proto {
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN }
struct ndpi_detection_module_struct {
typedef struct ndpi_detection_module_struct {
NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask;
@@ -805,7 +799,6 @@ struct ndpi_detection_module_struct {
content_automa, /* Used for HTTP subprotocol_detection */
subprotocol_automa, /* Used for HTTP subprotocol_detection */
bigrams_automa, impossible_bigrams_automa; /* TOR */
/* IP-based protocol detection */
void *protocols_ptree;
@@ -849,11 +842,11 @@ struct ndpi_detection_module_struct {
ndpi_proto_defaults_t proto_defaults[NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS];
u_int8_t http_dont_dissect_response:1, dns_dissect_response:1,
direction_detect_disable:1; /* disable internal detection of packet direction */
};
u_int8_t match_dns_host_names:1, http_dont_dissect_response:1;
u_int8_t direction_detect_disable:1; /* disable internal detection of packet direction */
} ndpi_detection_module_struct_t;
struct ndpi_flow_struct {
typedef struct ndpi_flow_struct {
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_HISTORY_SIZE];
#ifndef WIN32
__attribute__ ((__packed__))
@@ -861,7 +854,7 @@ struct ndpi_flow_struct {
u_int16_t protocol_stack_info;
/* init parameter, internal used to set up timestamp,... */
u_int16_t guessed_protocol_id, guessed_host_protocol_id;
u_int16_t guessed_protocol_id, guessed_host_proto_id;
u_int8_t protocol_id_already_guessed:1, host_already_guessed:1, init_finished:1, setup_packet_direction:1, packet_direction:1;
@@ -887,13 +880,11 @@ struct ndpi_flow_struct {
*/
struct ndpi_id_struct *server_id;
/* HTTP host or DNS query */
u_char host_server_name[192];
u_char host_server_name[256];
/* Via HTTP User-Agent */
u_char detected_os[32];
/* Via HTTP X-Forwarded-For */
u_char nat_ip[24];
/* Bittorrent hash */
u_char bittorent_hash[20];
/*
This structure below will not not stay inside the protos
@@ -908,13 +899,12 @@ struct ndpi_flow_struct {
} http;
union {
/* the only fields useful for nDPI and ntopng */
struct {
u_int8_t num_queries, num_answers, reply_code;
u_int8_t num_queries, num_answers, ret_code;
u_int8_t bad_packet /* the received packet looks bad */;
u_int16_t query_type, query_class, rsp_type;
} dns;
struct {
u_int8_t request_code;
u_int8_t version;
@@ -975,8 +965,10 @@ struct ndpi_flow_struct {
#ifdef NDPI_PROTOCOL_FLORENSIA
u_int32_t florensia_stage:1;
#endif
#ifdef NDPI_PROTOCOL_SOCKS
#ifdef NDPI_PROTOCOL_SOCKS5
u_int32_t socks5_stage:2; // 0 - 3
#endif
#ifdef NDPI_PROTOCOL_SOCKS4
u_int32_t socks4_stage:2; // 0 - 3
#endif
#ifdef NDPI_PROTOCOL_EDONKEY
@@ -1011,18 +1003,6 @@ struct ndpi_flow_struct {
struct ndpi_flow_struct *flow;
struct ndpi_id_struct *src;
struct ndpi_id_struct *dst;
};
typedef struct {
char *string_to_match, *proto_name;
int protocol_id;
ndpi_protocol_breed_t protocol_breed;
} ndpi_protocol_match;
typedef struct {
u_int32_t network;
u_int8_t cidr;
u_int8_t value;
} ndpi_network;
} ndpi_flow_struct_t;
#endif/* __NDPI_TYPEDEFS_H__ */
+2 -1
View File
@@ -1,7 +1,8 @@
/*
* ndpi_unix.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+2 -1
View File
@@ -1,7 +1,8 @@
/*
* ndpi_win32.h
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
+6 -10
View File
@@ -9,10 +9,10 @@ libndpi_la_includedir = $(includedir)/libndpi-@VERSION@/libndpi
libndpi_la_include_HEADERS = ../include/ndpi_api.h \
../include/ndpi_define.h \
../include/ndpi_main.h \
../include/ndpi_includes.h \
../include/ndpi_protocol_ids.h \
../include/ndpi_protocols.h \
../include/ndpi_typedefs.h
../include/ndpi_typedefs.h \
../include/ndpi_includes.h
libndpi_la_SOURCES = ndpi_content_match.c.inc \
ndpi_main.c \
@@ -26,7 +26,6 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/bittorrent.c \
protocols/ciscovpn.c \
protocols/citrix.c \
protocols/coap.c \
protocols/collectd.c \
protocols/corba.c \
protocols/crossfire.c \
@@ -37,7 +36,6 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/directdownloadlink.c \
protocols/dns.c \
protocols/dofus.c \
protocols/drda.c \
protocols/dropbox.c \
protocols/eaq.c \
protocols/edonkey.c \
@@ -47,13 +45,11 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/florensia.c \
protocols/ftp_control.c \
protocols/ftp_data.c \
protocols/git.c \
protocols/gnutella.c \
protocols/gtp.c \
protocols/guildwars.c \
protocols/h323.c \
protocols/halflife2_and_mods.c \
protocols/hep.c \
protocols/http_activesync.c \
protocols/http.c \
protocols/iax.c \
@@ -77,7 +73,6 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/mgcp.c \
protocols/mms.c \
protocols/mpegts.c \
protocols/mqtt.c \
protocols/msn.c \
protocols/mssql.c \
protocols/mysql.c \
@@ -108,7 +103,6 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/rtmp.c \
protocols/rtp.c \
protocols/rtsp.c \
protocols/rx.c \
protocols/sflow.c \
protocols/shoutcast.c \
protocols/sip.c \
@@ -116,7 +110,8 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/skype.c \
protocols/smb.c \
protocols/snmp.c \
protocols/socks45.c \
protocols/socks4.c \
protocols/socks5.c \
protocols/socrates.c \
protocols/sopcast.c \
protocols/soulseek.c \
@@ -142,14 +137,15 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
protocols/tvants.c \
protocols/tvuplayer.c \
protocols/twitter.c \
protocols/ubntac2.c \
protocols/usenet.c \
protocols/veohtv.c \
protocols/viber.c \
protocols/vhua.c \
protocols/vmware.c \
protocols/vnc.c \
protocols/warcraft3.c \
protocols/whoisdas.c \
protocols/winmx.c \
protocols/world_of_kung_fu.c \
protocols/world_of_warcraft.c \
protocols/xbox.c \
+172 -187
View File
@@ -1,7 +1,7 @@
/*
* ndpi_content_match.c
*
* Copyright (C) 2011-16 - ntop.org
* Copyright (C) 2011-15 - ntop.org
*
* 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
@@ -18,98 +18,21 @@
*
*/
typedef struct {
char *string_to_match, *proto_name;
int protocol_id;
ndpi_protocol_breed_t protocol_breed;
} ndpi_protocol_match;
typedef struct {
u_int32_t network;
u_int8_t cidr;
u_int8_t value;
} ndpi_network;
/* ****************************************************** */
static ndpi_network host_protocol_list[] = {
/*
OpenDNS
208.67.216.0/21
*/
{ 0xD043D800 /* 208.67.216.0/21 */, 21, NDPI_SERVICE_OPENDNS },
/*
Microsoft Corporation (MS One Drive)
204.79.195.0/24
204.79.196.0/23
134.170.0.0/16
131.253.12.0/22
131.253.16.0/23
131.253.18.0/24
65.54.191.0/24
*/
{ 0xCC4FC300 /* 204.79.195.0/24 */, 24, NDPI_SERVICE_MS_ONE_DRIVE },
{ 0xCC4FC400 /* 204.79.196.0/23 */, 23, NDPI_SERVICE_MS_ONE_DRIVE },
{ 0x86AA0000 /* 134.170.0.0/16 */, 16, NDPI_SERVICE_MS_ONE_DRIVE },
{ 0x83FD0C00 /* 131.253.12.0/22 */, 22, NDPI_SERVICE_MS_ONE_DRIVE },
{ 0x83FD1000 /* 131.253.16.0/23 */, 23, NDPI_SERVICE_MS_ONE_DRIVE },
{ 0x83FD1200 /* 131.253.18.0/24 */, 24, NDPI_SERVICE_MS_ONE_DRIVE },
{ 0x4136BF00 /* 65.54.191.0/24 */, 24, NDPI_SERVICE_MS_ONE_DRIVE },
/*
Amazon-EU-AWS Elastic Compute Cloud, EC2 (also used by Netflix)
46.137.128.0/18
*/
{ 0x2E898000 /* 46.137.128.0/18 */, 18, NDPI_SERVICE_AMAZON },
/*
Amazon-EU (also used by Netflix)
176.34.184.0/21
*/
{ 0xB022B800 /* 176.34.184.0/21 */, 21, NDPI_SERVICE_AMAZON },
/*
Netflix
23.246.0.0/18
23.21.190.124/32
*/
{ 0x17F60000 /* 23.246.0.0/18 */, 18, NDPI_SERVICE_NETFLIX },
{ 0x1715BE7C /* 23.21.190.124/32 */, 32, NDPI_SERVICE_NETFLIX },
/*
Cloudflare
104.16.0.0/12
173.245.48.0/20
162.158.0.0/15
141.101.125.0/24 CLOUDFLARE-EU CDN network
*/
{ 0x68100000 /* 104.16.0.0/12 */, 12, NDPI_SERVICE_CLOUDFLARE },
{ 0xADF53000 /* 173.245.48.0/20 */, 20, NDPI_SERVICE_CLOUDFLARE },
{ 0xA29E0000 /* 162.158.0.0/15 */, 15, NDPI_SERVICE_CLOUDFLARE },
{ 0x8D657D00 /* 141.101.125.0/24 */, 24, NDPI_SERVICE_CLOUDFLARE },
/*
OFFICE 365
13.107.1.0/24
13.107.3.0/24
13.107.4.0/24
13.107.5.0/24
13.107.6.0/24
13.107.7.0/24
13.107.9.0/24
13.107.12.0/24
13.107.13.0/24
13.107.15.0/24
13.107.16.0/24
*/
{ 0x0D6B0100 /* 13.107.1.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0300 /* 13.107.3.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0400 /* 13.107.4.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0500 /* 13.107.5.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0600 /* 13.107.6.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0700 /* 13.107.7.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0900 /* 13.107.9.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0C00 /* 13.107.12.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0D00 /* 13.107.13.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B0F00 /* 13.107.15.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
{ 0x0D6B1000 /* 13.107.16.0 */, 24 , NDPI_SERVICE_OFFICE_365 },
/*
OCS GO (Orange Cinéma Séries)
178.248.208.0/21
*/
{ 0xB2F8D000 /* 178.248.208.0 */, 21, NDPI_SERVICE_OCS },
/*
Citrix GotoMeeting (AS16815, AS21866)
216.115.208.0/20
@@ -125,16 +48,10 @@ static ndpi_network host_protocol_list[] = {
{ 0x4272A000 /* 66.114.160.0 */, 20, NDPI_PROTOCOL_WEBEX },
/*
Viber Media AWS-VIBER-MEDIA (NET-54-169-63-160-1) 54.169.63.160 - 54.169.63.191
Viber Media S a r l AWS-VIBER-MEDIA-S-A-R-L (NET-54-93-255-64-1) 54.93.255.64 - 54.93.255.127
Crittercism AWS-VIBER-MEDIA (NET-52-0-252-0-1) 52.0.252.0 - 52.0.255.255
54.169.63.160/27
54.93.255.64/26
52.0.252.0/22
Viber
54.171.62.0/24
*/
{ 0x36A93FA0 /* 54.169.63.160 */, 27, NDPI_PROTOCOL_VIBER },
{ 0x365DFF40 /* 54.93.255.64 */, 26, NDPI_PROTOCOL_VIBER },
{ 0x3400FC00 /* 52.0.252.0 */, 22, NDPI_PROTOCOL_VIBER },
{ 0x36AB3E00 /* 54.171.62.0 */, 24, NDPI_PROTOCOL_VIBER },
/*
Apple (FaceTime, iMessage,...)
@@ -146,26 +63,22 @@ static ndpi_network host_protocol_list[] = {
Dropbox
108.160.160.0/20
199.47.216.0/22
45.58.64.0/20
*/
{ 0x6CA0A000 /* 108.160.160.0 */, 20, NDPI_PROTOCOL_DROPBOX },
{ 0xC72FD800 /* 199.47.216.0 */, 22, NDPI_PROTOCOL_DROPBOX },
{ 0x2D3A4000 /* 45.58.64.0 */, 20, NDPI_PROTOCOL_DROPBOX },
{ 0x6CA0A000 /* 108.160.160.0 */, 20, NDPI_PROTOCOL_DROPBOX },
/*
Skype (Microsoft CDN)
157.56.0.0/14, 157.60.0.0/16, 157.54.0.0/15
111.221.64.0 - 111.221.127.255
91.190.216.0/21 (AS198015 Skype Communications Sarl)
40.126.129.109/32
*/
{ 0x9D380000 /* 157.56.0.0 */, 14, NDPI_PROTOCOL_SKYPE },
{ 0x9D3C0000 /* 157.60.0.0 */, 16, NDPI_PROTOCOL_SKYPE },
{ 0x9D360000 /* 157.54.0.0 */, 15, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4000 /* 111.221.64.0 */, 18, NDPI_PROTOCOL_SKYPE },
{ 0x5BBED800 /* 91.190.216.0 */, 21, NDPI_PROTOCOL_SKYPE },
{ 0x287F816D /* 40.126.129.109 */, 32, NDPI_PROTOCOL_SKYPE },
/*
route: 5.42.160.0/19
@@ -177,15 +90,9 @@ static ndpi_network host_protocol_list[] = {
/*
Google
173.194.0.0/16
74.125.0.0/16
64.233.160.0/19
216.58.192.0/19
*/
{ 0xADC20000 /* 173.194.0.0 */, 16, NDPI_SERVICE_GOOGLE },
{ 0x4A7D0000 /* 74.125.0.0 */, 16, NDPI_SERVICE_GOOGLE },
{ 0x40E91600 /* 64.233.160.0 */, 19, NDPI_SERVICE_GOOGLE },
{ 0xD83AC000 /* 216.58.192.0 */, 19, NDPI_SERVICE_GOOGLE },
/*
Ubuntu One
91.189.89.0/21 (255.255.248.0)
@@ -211,7 +118,155 @@ static ndpi_network host_protocol_list[] = {
{ 0x959AA400 /* 149.154.164.0/22 */, 22, NDPI_PROTOCOL_TELEGRAM},
{ 0x959AA800 /* 149.154.168.0/22 */, 22, NDPI_PROTOCOL_TELEGRAM},
/* TOR */
/* Skype */
{ 0x17600000, 14, NDPI_PROTOCOL_SKYPE },
{ 0x17613000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x17614000, 19, NDPI_PROTOCOL_SKYPE },
{ 0x17616000, 19, NDPI_PROTOCOL_SKYPE },
{ 0x17622000, 21, NDPI_PROTOCOL_SKYPE },
{ 0x17622800, 22, NDPI_PROTOCOL_SKYPE },
{ 0x17623800, 21, NDPI_PROTOCOL_SKYPE },
{ 0x17624000, 18, NDPI_PROTOCOL_SKYPE },
{ 0x17640000, 15, NDPI_PROTOCOL_SKYPE },
{ 0x17660000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x17674000, 18, NDPI_PROTOCOL_SKYPE },
{ 0x17678000, 17, NDPI_PROTOCOL_SKYPE },
{ 0x40040000, 18, NDPI_PROTOCOL_SKYPE },
{ 0x41340000, 14, NDPI_PROTOCOL_SKYPE },
{ 0x4134A000, 19, NDPI_PROTOCOL_SKYPE },
{ 0x41362800, 24, NDPI_PROTOCOL_SKYPE },
{ 0x41364200, 23, NDPI_PROTOCOL_SKYPE },
{ 0x41364400, 24, NDPI_PROTOCOL_SKYPE },
{ 0x41365200, 24, NDPI_PROTOCOL_SKYPE },
{ 0x41365500, 24, NDPI_PROTOCOL_SKYPE },
{ 0x41365A00, 23, NDPI_PROTOCOL_SKYPE },
{ 0x41372C00, 24, NDPI_PROTOCOL_SKYPE },
{ 0x41377500, 24, NDPI_PROTOCOL_SKYPE },
{ 0x4137E600, 24, NDPI_PROTOCOL_SKYPE },
{ 0x4137E700, 24, NDPI_PROTOCOL_SKYPE },
{ 0x42779000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x46250000, 17, NDPI_PROTOCOL_SKYPE },
{ 0x46258000, 18, NDPI_PROTOCOL_SKYPE },
{ 0x46259600, 23, NDPI_PROTOCOL_SKYPE },
{ 0x5EF54000, 18, NDPI_PROTOCOL_SKYPE },
{ 0x5EF54C00, 23, NDPI_PROTOCOL_SKYPE },
{ 0x5EF55200, 24, NDPI_PROTOCOL_SKYPE },
{ 0x68280000, 13, NDPI_PROTOCOL_SKYPE },
{ 0x68920000, 19, NDPI_PROTOCOL_SKYPE },
{ 0x68928000, 17, NDPI_PROTOCOL_SKYPE },
{ 0x68D00000, 13, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD1000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD1000, 21, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD1700, 24, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4000, 18, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4000, 21, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4200, 24, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4500, 24, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4600, 24, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD4E00, 23, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD5000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD6000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD7000, 21, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD7800, 22, NDPI_PROTOCOL_SKYPE },
{ 0x6FDD7C00, 22, NDPI_PROTOCOL_SKYPE },
{ 0x83FD0100, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD0500, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD0600, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD0800, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD0C00, 22, NDPI_PROTOCOL_SKYPE },
{ 0x83FD1200, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD1500, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD1800, 21, NDPI_PROTOCOL_SKYPE },
{ 0x83FD2000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x83FD2100, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD2200, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD3D00, 24, NDPI_PROTOCOL_SKYPE },
{ 0x83FD3E00, 23, NDPI_PROTOCOL_SKYPE },
{ 0x83FD8000, 17, NDPI_PROTOCOL_SKYPE },
{ 0x84F50000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x84F59C00, 22, NDPI_PROTOCOL_SKYPE },
{ 0x84F5A000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x86AA0000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x86AA8000, 21, NDPI_PROTOCOL_SKYPE },
{ 0x86AA8800, 21, NDPI_PROTOCOL_SKYPE },
{ 0x86AAD900, 24, NDPI_PROTOCOL_SKYPE },
{ 0x89740000, 15, NDPI_PROTOCOL_SKYPE },
{ 0x89748000, 19, NDPI_PROTOCOL_SKYPE },
{ 0x8974A000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x89870000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x8A5B0000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x8A5B0000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x8A5B1000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x8A5B2000, 20, NDPI_PROTOCOL_SKYPE },
{ 0x9D370000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x9D380000, 16, NDPI_PROTOCOL_SKYPE },
{ 0x9D3C1700, 24, NDPI_PROTOCOL_SKYPE },
{ 0x9D3C1F00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xA7DCF000, 22, NDPI_PROTOCOL_SKYPE },
{ 0xA83D0000, 16, NDPI_PROTOCOL_SKYPE },
{ 0xA83E0000, 15, NDPI_PROTOCOL_SKYPE },
{ 0xA83F8000, 17, NDPI_PROTOCOL_SKYPE },
{ 0xBFE80000, 13, NDPI_PROTOCOL_SKYPE },
{ 0xC030E100, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC0549F00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC054A000, 23, NDPI_PROTOCOL_SKYPE },
{ 0xC0C59D00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC1954000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xC1DD7100, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC6310800, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC6C88200, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC6CEA400, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC71E1000, 20, NDPI_PROTOCOL_SKYPE },
{ 0xC73C1C00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC74AD200, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC7675A00, 23, NDPI_PROTOCOL_SKYPE },
{ 0xC7677A00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xC7F23000, 21, NDPI_PROTOCOL_SKYPE },
{ 0xCA59E000, 21, NDPI_PROTOCOL_SKYPE },
{ 0xCC4F8700, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCC4FB300, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCC4FC300, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCC4FC500, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCC4FFC00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCC5F6000, 20, NDPI_PROTOCOL_SKYPE },
{ 0xCC988C00, 23, NDPI_PROTOCOL_SKYPE },
{ 0xCE8AA800, 21, NDPI_PROTOCOL_SKYPE },
{ 0xCEBFE000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E0000, 16, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E0000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E2000, 20, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E2900, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E3000, 20, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E3A00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E3E00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E4000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E4800, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E4D00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E6000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E6200, 24, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E8000, 17, NDPI_PROTOCOL_SKYPE },
{ 0xCF2E8000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xCF2EE000, 20, NDPI_PROTOCOL_SKYPE },
{ 0xCF448000, 18, NDPI_PROTOCOL_SKYPE },
{ 0xCF52FA00, 23, NDPI_PROTOCOL_SKYPE },
{ 0xD0448800, 21, NDPI_PROTOCOL_SKYPE },
{ 0xD04C2D00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD04C2E00, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD0540000, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD0540100, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD0540200, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD0540300, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD1017000, 23, NDPI_PROTOCOL_SKYPE },
{ 0xD1B98000, 22, NDPI_PROTOCOL_SKYPE },
{ 0xD1B9F000, 22, NDPI_PROTOCOL_SKYPE },
{ 0xD1F0C000, 19, NDPI_PROTOCOL_SKYPE },
{ 0xD5C78000, 18, NDPI_PROTOCOL_SKYPE },
{ 0xD820B400, 22, NDPI_PROTOCOL_SKYPE },
{ 0xD820F000, 22, NDPI_PROTOCOL_SKYPE },
{ 0xD820F200, 24, NDPI_PROTOCOL_SKYPE },
{ 0xD821F000, 22, NDPI_PROTOCOL_SKYPE },
{ 0xD4A10800, 24, NDPI_PROTOCOL_SKYPE },
{ 0x012A1231, 32, NDPI_PROTOCOL_TOR },
{ 0x01E69FA1, 32, NDPI_PROTOCOL_TOR },
{ 0x020DE985, 32, NDPI_PROTOCOL_TOR },
@@ -7258,7 +7313,6 @@ ndpi_protocol_match host_match[] = {
{ "images-amazon.com", "Amazon", NDPI_SERVICE_AMAZON, NDPI_PROTOCOL_ACCEPTABLE },
{ "amazonaws.com", "Amazon", NDPI_SERVICE_AMAZON, NDPI_PROTOCOL_ACCEPTABLE },
{ "amazon-adsystem.com", "Amazon", NDPI_SERVICE_AMAZON, NDPI_PROTOCOL_ACCEPTABLE },
{ ".cloudfront.net", "Amazon", NDPI_SERVICE_AMAZON, NDPI_PROTOCOL_ACCEPTABLE },
{ ".apple.com", "Apple", NDPI_SERVICE_APPLE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".mzstatic.com", "Apple", NDPI_SERVICE_APPLE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".icloud.com", "AppleiCloud", NDPI_SERVICE_APPLE_ICLOUD, NDPI_PROTOCOL_ACCEPTABLE },
@@ -7266,19 +7320,13 @@ ndpi_protocol_match host_match[] = {
{ ".cnn.c", "CNN", NDPI_SERVICE_CNN, NDPI_PROTOCOL_FUN },
{ ".cnn.net", "CNN", NDPI_SERVICE_CNN, NDPI_PROTOCOL_FUN },
{ ".dropbox.com", "DropBox", NDPI_SERVICE_DROPBOX, NDPI_PROTOCOL_SAFE },
{ "log.getdropbox.com", "DropBox", NDPI_SERVICE_DROPBOX, NDPI_PROTOCOL_SAFE },
{ ".ebay.", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ebay.com", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ebaystatic.com", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ebaydesc.com", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ebayrtm.com", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ebaystratus.com", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ebayimg.com", "eBay", NDPI_SERVICE_EBAY, NDPI_PROTOCOL_ACCEPTABLE },
{ ".facebook.com", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ "fbstatic-a.akamaihd.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ ".fbcdn.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ "fbcdn-", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, /* fbcdn-video-a-akamaihd.net */
{ ".facebook.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
{ "fbcdn-", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, /* fbcdn-video-a-akamaihd.net */
{ ".google.", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".gstatic.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".googlesyndication.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
@@ -7291,7 +7339,6 @@ ndpi_protocol_match host_match[] = {
{ "googleadservices.", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ "googleapis.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ "ggpht.com", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ "1e100.net", "Google", NDPI_SERVICE_GOOGLE, NDPI_PROTOCOL_ACCEPTABLE },
{ "maps.google.", "GoogleMaps", NDPI_SERVICE_GOOGLE_MAPS, NDPI_PROTOCOL_ACCEPTABLE },
{ "maps.gstatic.com", "GoogleMaps", NDPI_SERVICE_GOOGLE_MAPS, NDPI_PROTOCOL_ACCEPTABLE },
{ ".gmail.", "GMail", NDPI_SERVICE_GMAIL, NDPI_PROTOCOL_SAFE },
@@ -7302,26 +7349,23 @@ ndpi_protocol_match host_match[] = {
{ "nflxext.com", "NetFlix", NDPI_SERVICE_NETFLIX, NDPI_PROTOCOL_FUN },
{ "nflximg.com", "NetFlix", NDPI_SERVICE_NETFLIX, NDPI_PROTOCOL_FUN },
{ "nflximg.net", "NetFlix", NDPI_SERVICE_NETFLIX, NDPI_PROTOCOL_FUN },
{ "nflxvideo.net", "NetFlix", NDPI_SERVICE_NETFLIX, NDPI_PROTOCOL_FUN },
{ ".skype.", "Skype", NDPI_SERVICE_SKYPE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".skypeassets.", "Skype", NDPI_SERVICE_SKYPE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".skypedata.", "Skype", NDPI_SERVICE_SKYPE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".skypeecs-", /* no final . */ "Skype", NDPI_SERVICE_SKYPE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".skypeforbusiness.", "Skype", NDPI_SERVICE_SKYPE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".lync.com", "Skype", NDPI_SERVICE_SKYPE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".tuenti.com", "Tuenti", NDPI_SERVICE_TUENTI, NDPI_PROTOCOL_ACCEPTABLE },
{ ".twttr.com", "Twitter", NDPI_SERVICE_TWITTER, NDPI_PROTOCOL_ACCEPTABLE },
{ "twitter.", "Twitter", NDPI_SERVICE_TWITTER, NDPI_PROTOCOL_ACCEPTABLE },
{ "twimg.com", "Twitter", NDPI_SERVICE_TWITTER, NDPI_PROTOCOL_ACCEPTABLE },
{ ".viber.com", "Viber", NDPI_SERVICE_VIBER, NDPI_PROTOCOL_ACCEPTABLE },
{ ".cdn.viber.com", "Viber", NDPI_SERVICE_VIBER, NDPI_PROTOCOL_ACCEPTABLE },
{ "wikipedia.", "Wikipedia", NDPI_SERVICE_WIKIPEDIA, NDPI_PROTOCOL_ACCEPTABLE },
{ "wikimedia.", "Wikipedia", NDPI_SERVICE_WIKIPEDIA, NDPI_PROTOCOL_ACCEPTABLE },
{ "mediawiki.", "Wikipedia", NDPI_SERVICE_WIKIPEDIA, NDPI_PROTOCOL_ACCEPTABLE },
{ "wikimediafoundation.", "Wikipedia", NDPI_SERVICE_WIKIPEDIA, NDPI_PROTOCOL_ACCEPTABLE },
{ ".whatsapp.", "WhatsApp", NDPI_SERVICE_WHATSAPP, NDPI_PROTOCOL_ACCEPTABLE },
{ ".whatsapp.net", "WhatsApp", NDPI_SERVICE_WHATSAPP, NDPI_PROTOCOL_ACCEPTABLE },
{ ".yahoo.", "Yahoo", NDPI_SERVICE_YAHOO, NDPI_PROTOCOL_ACCEPTABLE },
{ ".yimg.com", "Yahoo", NDPI_SERVICE_YAHOO, NDPI_PROTOCOL_ACCEPTABLE },
{ "yimg.com", "Yahoo", NDPI_SERVICE_YAHOO, NDPI_PROTOCOL_ACCEPTABLE },
{ "yahooapis.", "Yahoo", NDPI_SERVICE_YAHOO, NDPI_PROTOCOL_ACCEPTABLE },
{ "youtube.", "YouTube", NDPI_SERVICE_YOUTUBE, NDPI_PROTOCOL_FUN },
{ ".googlevideo.com", "YouTube", NDPI_SERVICE_YOUTUBE, NDPI_PROTOCOL_FUN },
@@ -7340,13 +7384,6 @@ ndpi_protocol_match host_match[] = {
{ "quickplay.com", "QuickPlay", NDPI_SERVICE_QUICKPLAY, NDPI_PROTOCOL_FUN },
{ "tim.com.br", "TIM", NDPI_SERVICE_TIM, NDPI_PROTOCOL_ACCEPTABLE },
{ "tim.it", "TIM", NDPI_SERVICE_TIM, NDPI_PROTOCOL_ACCEPTABLE },
{ ".qq.com", "QQ", NDPI_PROTOCOL_QQ, NDPI_PROTOCOL_FUN },
{ ".weibo.com", "Weibo", NDPI_SERVICE_WEIBO, NDPI_PROTOCOL_FUN },
{ ".sinaimg.cn", "Weibo", NDPI_SERVICE_WEIBO, NDPI_PROTOCOL_FUN },
{ ".sinajs.cn", "Weibo", NDPI_SERVICE_WEIBO, NDPI_PROTOCOL_FUN },
{ ".sina.cn", "Weibo", NDPI_SERVICE_WEIBO, NDPI_PROTOCOL_FUN },
{ ".sina.com.cn", "Weibo", NDPI_SERVICE_WEIBO, NDPI_PROTOCOL_FUN },
/* https://support.cipafilter.com/index.php?/Knowledgebase/Article/View/117/0/snapchat---how-to-block */
{ "feelinsonice.appspot.com", "Snapchat", NDPI_SERVICE_SNAPCHAT, NDPI_PROTOCOL_FUN },
@@ -7374,51 +7411,12 @@ ndpi_protocol_match host_match[] = {
{ "tim-geoportal.geoportal3d.com.br", "TIM_PortasAbertas", NDPI_SERVICE_TIMPORTASABERTAS, NDPI_PROTOCOL_ACCEPTABLE },
{ ".m4u.com.br", "TIM_Recarga", NDPI_SERVICE_TIMRECARGA, NDPI_PROTOCOL_ACCEPTABLE },
{ ".deezer.com", "Deezer", NDPI_SERVICE_DEEZER, NDPI_PROTOCOL_ACCEPTABLE },
{ ".microsoft.com", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE },
{ "i-msdn.sec.s-msft.com", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE },
{ "i2-msdn.sec.s-msft.com", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE },
{ ".webtrends.com", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE },
{ ".msecnd.net", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE },
{ ".visualstudio.com", "Microsoft", NDPI_SERVICE_MICROSOFT, NDPI_PROTOCOL_ACCEPTABLE },
{ "bn1301.storage.live.com", "MS_OneDrive", NDPI_SERVICE_MS_ONE_DRIVE, NDPI_PROTOCOL_ACCEPTABLE },
{ "skyapi.live.net", "MS_OneDrive", NDPI_SERVICE_MS_ONE_DRIVE, NDPI_PROTOCOL_ACCEPTABLE },
{ "d.docs.live.net", "MS_OneDrive", NDPI_SERVICE_MS_ONE_DRIVE, NDPI_PROTOCOL_ACCEPTABLE },
{ "update.microsoft.com", "WindowsUpdate", NDPI_SERVICE_WINDOWS_UPDATE, NDPI_PROTOCOL_ACCEPTABLE },
{ ".windowsupdate.com", "WindowsUpdate", NDPI_SERVICE_WINDOWS_UPDATE, NDPI_PROTOCOL_ACCEPTABLE },
{ "worldofwarcraft.com", "WorldOfWarcraft", NDPI_PROTOCOL_WORLDOFWARCRAFT, NDPI_PROTOCOL_FUN },
{ ".anchorfree.", "HotspotShield", NDPI_SERVICE_HOTSPOT_SHIELD, NDPI_PROTOCOL_POTENTIALLY_DANGEROUS },
{ "hotspotshield.com", "HotspotShield", NDPI_SERVICE_HOTSPOT_SHIELD, NDPI_PROTOCOL_POTENTIALLY_DANGEROUS },
{ ".webex.com", "Webex", NDPI_PROTOCOL_WEBEX, NDPI_PROTOCOL_ACCEPTABLE },
{ ".ocsdomain.com", "OCS", NDPI_SERVICE_OCS, NDPI_PROTOCOL_FUN },
{ "ocs.fr", "OCS", NDPI_SERVICE_OCS, NDPI_PROTOCOL_FUN },
{ ".ocs.fr", "OCS", NDPI_SERVICE_OCS, NDPI_PROTOCOL_FUN },
{ ".labgency.ws", "OCS", NDPI_SERVICE_OCS, NDPI_PROTOCOL_FUN },
{ "crl.microsoft.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ "evsecure-ocsp.verisign.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ "evsecure-aia.verisign.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ "evsecure-crl.verisign.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".omniroot.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".verisign.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".symcb.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".symcd.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".verisign.net", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".geotrust.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".entrust.net", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
{ ".public-trust.com", "Office365", NDPI_SERVICE_OFFICE_365, NDPI_PROTOCOL_ACCEPTABLE },
/* http://www.urlquery.net/report.php?id=1453233646161 */
{ "lifedom.top", "Cloudflare", NDPI_SERVICE_CLOUDFLARE, NDPI_PROTOCOL_ACCEPTABLE },
{ "coby.ns.cloudflare.com", "Cloudflare", NDPI_SERVICE_CLOUDFLARE, NDPI_PROTOCOL_ACCEPTABLE },
{ "amanda.ns.cloudflare.com", "Cloudflare", NDPI_SERVICE_CLOUDFLARE, NDPI_PROTOCOL_ACCEPTABLE },
{ "d295hzzivaok4k.cloudfront.net", "OpenDNS", NDPI_SERVICE_OPENDNS, NDPI_PROTOCOL_ACCEPTABLE },
{ ".opendns.com", "OpenDNS", NDPI_SERVICE_OPENDNS, NDPI_PROTOCOL_ACCEPTABLE },
{ NULL, 0 }
};
@@ -7464,18 +7462,6 @@ ndpi_protocol_match content_match[] = {
{ "video/webm", NULL, NDPI_CONTENT_WEBM, NDPI_PROTOCOL_FUN },
{ "application/x-rtsp-tunnelled", NULL, NDPI_PROTOCOL_RTSP, NDPI_PROTOCOL_FUN },
{ "application/vnd.apple.mpegurl", NULL, NDPI_CONTENT_MPEG, NDPI_PROTOCOL_FUN },
{ "application/x-tar", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "application/octet-stream", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "application/mac-binary", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "/x-bzip", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "/x-gzip", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "/x-zip", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "/zip", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "binhex", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "/base64", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "application/gnutar", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ "application/x-compressed", NULL, NDPI_PROTOCOL_HTTP_DOWNLOAD, NDPI_PROTOCOL_ACCEPTABLE },
{ NULL, 0 }
};
@@ -7542,7 +7528,7 @@ static const char *ndpi_en_bigrams[] = {
static const char *ndpi_en_impossible_bigrams[] = {
"bk", "bq", "bx", "cb", "cf", "cg", "cj", "cp", "cv", "cw", "cx", "dx", "fk", "fq", "fv", "fx", "ee",
"fz", "gq", "gv", "gx", "hh", "hk", "hv", "hx", "hz", "iy", "jb", "jc", "jd", "jf", "jg", "jh", "jk",
"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",
"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",
@@ -7550,4 +7536,3 @@ static const char *ndpi_en_impossible_bigrams[] = {
"yj", "yq", "yv", "yz", "yw", "zb", "zc", "zg", "zh", "zj", "zn", "zq", "zr", "zs", "zx", "wh", "wk",
"wb", "zk", "kp", "zk", "xy",
NULL };
+231 -386
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -23,8 +23,8 @@
*
*/
#include "ndpi_protocols.h"
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_AFP
static void ndpi_int_afp_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
+1 -2
View File
@@ -22,9 +22,8 @@
*
*/
/* include files */
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_ARMAGETRON
+15 -15
View File
@@ -35,23 +35,23 @@ static void ndpi_int_bgp_add_connection(struct ndpi_detection_module_struct *ndp
/* this detection also works asymmetrically */
void ndpi_search_bgp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t bgp_port = htons(179);
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->tcp
&& (packet->payload[18] < 5)
&& ((packet->tcp->dest == bgp_port) || (packet->tcp->source == bgp_port))
&& (packet->payload_packet_len > 18)
&& (get_u_int64_t(packet->payload, 0) == 0xffffffffffffffffULL)
&& (get_u_int64_t(packet->payload, 8) == 0xffffffffffffffffULL)
&& (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_int_bgp_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len > 18 &&
get_u_int64_t(packet->payload, 0) == 0xffffffffffffffffULL &&
get_u_int64_t(packet->payload, 8) == 0xffffffffffffffffULL &&
ntohs(get_u_int16_t(packet->payload, 16)) <= packet->payload_packet_len &&
(packet->tcp->dest == htons(179) || packet->tcp->source == htons(179))
&& packet->payload[18] < 5) {
NDPI_LOG(NDPI_PROTOCOL_BGP, ndpi_struct, NDPI_LOG_DEBUG, "BGP detected.\n");
ndpi_int_bgp_add_connection(ndpi_struct, flow);
return;
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BGP);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BGP);
}
+120 -140
View File
@@ -25,52 +25,15 @@
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_BITTORRENT
#define NDPI_PROTOCOL_UNSAFE_DETECTION 0
#define NDPI_PROTOCOL_SAFE_DETECTION 1
#define NDPI_PROTOCOL_PLAIN_DETECTION 0
#define NDPI_PROTOCOL_WEBSEED_DETECTION 2
struct ndpi_utp_hdr {
u_int8_t h_version:4, h_type:4, next_extension;
u_int16_t connection_id;
u_int32_t ts_usec, tdiff_usec, window_size;
u_int16_t sequence_nr, ack_nr;
};
static u_int8_t is_utp_pkt(const u_int8_t *payload, u_int payload_len) {
struct ndpi_utp_hdr *h = (struct ndpi_utp_hdr*)payload;
if(payload_len < sizeof(struct ndpi_utp_hdr)) return(0);
if(h->h_version != 1) return(0);
if(h->h_type > 4) return(0);
if(h->next_extension > 2) return(0);
if(ntohl(h->window_size) > 65565) return(0);
return(1);
}
#define NDPI_PROTOCOL_UNSAFE_DETECTION 0
#define NDPI_PROTOCOL_SAFE_DETECTION 1
#define NDPI_PROTOCOL_PLAIN_DETECTION 0
#define NDPI_PROTOCOL_WEBSEED_DETECTION 2
static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
int bt_offset, int check_hash,
const u_int8_t save_detection, const u_int8_t encrypted_connection)
const u_int8_t save_detection, const u_int8_t encrypted_connection/* , */
/* ndpi_protocol_type_t protocol_type */)
{
if(check_hash) {
const char *bt_hash = NULL; /* 20 bytes long */
const char *peer_id = NULL; /* 20 bytes long */
if(bt_offset == -1) {
const char *bt_magic = ndpi_strnstr((const char *)flow->packet.payload,
"BitTorrent protocol", flow->packet.payload_packet_len);
if(bt_magic)
bt_hash = &bt_magic[19], peer_id = &bt_magic[39];
} else
bt_hash = (const char*)&flow->packet.payload[28], peer_id = (const char*)&flow->packet.payload[48];
if(bt_hash) memcpy(flow->bittorent_hash, bt_hash, 20);
}
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN);
}
@@ -80,87 +43,96 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t a = 0;
if(packet->payload_packet_len == 1 && packet->payload[0] == 0x13) {
if (packet->payload_packet_len == 1 && packet->payload[0] == 0x13) {
/* reset stage back to 0 so we will see the next packet here too */
flow->bittorrent_stage = 0;
return 0;
}
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_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, 19, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_REAL_PROTOCOL */);
return 1;
}
}
if(packet->payload_packet_len > 20) {
if (packet->payload_packet_len > 20) {
/* test for match 0x13+"BitTorrent protocol" */
if(packet->payload[0] == 0x13) {
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_add_connection_as_bittorrent(ndpi_struct, flow, 20, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
if (packet->payload[0] == 0x13) {
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_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_REAL_PROTOCOL */);
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_TRACE, "BT: plain webseed BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
/* seen Azureus as server for webseed, possibly other servers existing, to implement */
/* is Server: hypertracker Bittorrent? */
/* 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) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct,
NDPI_LOG_TRACE, "BT: plain Bitcomet persistent seed protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
if(packet->payload_packet_len > 90 && (memcmp(packet->payload, "GET ", 4) == 0
if (packet->payload_packet_len > 90 && (memcmp(packet->payload, "GET ", 4) == 0
|| memcmp(packet->payload, "POST ", 5) == 0)) {
const u_int8_t *ptr = &packet->payload[4];
u_int16_t len = packet->payload_packet_len - 4;
a = 0;
/* parse complete get packet here into line structure elements */
ndpi_parse_packet_line_info(ndpi_struct, flow);
/* answer to this pattern is HTTP....Server: hypertracker */
if(packet->user_agent_line.ptr != NULL
if (packet->user_agent_line.ptr != NULL
&& ((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 >= 11 && memcmp(packet->user_agent_line.ptr, "BTWebClient", 11) == 0))) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct,
NDPI_LOG_TRACE, "Azureus /Bittorrent user agent line detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
if(packet->user_agent_line.ptr != NULL
&& (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->line[8].len >= 9 && memcmp(packet->line[8].ptr, "X-Queue: ", 9) == 0)) {
if (packet->user_agent_line.ptr != NULL
&& (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->line[8].len >= 9 && memcmp(packet->line[8].ptr, "X-Queue: ", 9) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct,
NDPI_LOG_TRACE, "Bittorrent Shareaza detected.\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
/* this is a self built client, not possible to catch asymmetrically */
if((packet->parsed_lines == 10 || (packet->parsed_lines == 11 && packet->line[11].len == 0))
if ((packet->parsed_lines == 10 || (packet->parsed_lines == 11 && packet->line[11].len == 0))
&& packet->user_agent_line.ptr != NULL
&& packet->user_agent_line.len > 12
&& memcmp(packet->user_agent_line.ptr, "Mozilla/4.0 ",
@@ -188,13 +160,15 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& 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_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
/* FlashGet pattern */
if(packet->parsed_lines == 8
if (packet->parsed_lines == 8
&& packet->user_agent_line.ptr != NULL
&& packet->user_agent_line.len > (sizeof("Mozilla/4.0 (compatible; MSIE 6.0;") - 1)
&& memcmp(packet->user_agent_line.ptr, "Mozilla/4.0 (compatible; MSIE 6.0;",
@@ -213,12 +187,13 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& 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_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
if(packet->parsed_lines == 7
}
if (packet->parsed_lines == 7
&& packet->user_agent_line.ptr != NULL
&& packet->user_agent_line.len > (sizeof("Mozilla/4.0 (compatible; MSIE 6.0;") - 1)
&& memcmp(packet->user_agent_line.ptr, "Mozilla/4.0 (compatible; MSIE 6.0;",
@@ -234,17 +209,19 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
&& 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_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
/* answer to this pattern is not possible to implement asymmetrically */
while (1) {
if(len < 50 || ptr[0] == 0x0d) {
if (len < 50 || ptr[0] == 0x0d) {
goto ndpi_end_bt_tracker_check;
}
if(memcmp(ptr, "info_hash=", 10) == 0) {
if (memcmp(ptr, "info_hash=", 10) == 0) {
break;
}
len--;
@@ -260,40 +237,40 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
/* parse bt hash */
for (a = 0; a < 20; a++) {
if(len < 3) {
if (len < 3) {
goto ndpi_end_bt_tracker_check;
}
if(*ptr == '%') {
if (*ptr == '%') {
u_int8_t x1 = 0xFF;
u_int8_t x2 = 0xFF;
if(ptr[1] >= '0' && ptr[1] <= '9') {
if (ptr[1] >= '0' && ptr[1] <= '9') {
x1 = ptr[1] - '0';
}
if(ptr[1] >= 'a' && ptr[1] <= 'f') {
if (ptr[1] >= 'a' && ptr[1] <= 'f') {
x1 = 10 + ptr[1] - 'a';
}
if(ptr[1] >= 'A' && ptr[1] <= 'F') {
if (ptr[1] >= 'A' && ptr[1] <= 'F') {
x1 = 10 + ptr[1] - 'A';
}
if(ptr[2] >= '0' && ptr[2] <= '9') {
if (ptr[2] >= '0' && ptr[2] <= '9') {
x2 = ptr[2] - '0';
}
if(ptr[2] >= 'a' && ptr[2] <= 'f') {
if (ptr[2] >= 'a' && ptr[2] <= 'f') {
x2 = 10 + ptr[2] - 'a';
}
if(ptr[2] >= 'A' && ptr[2] <= 'F') {
if (ptr[2] >= 'A' && ptr[2] <= 'F') {
x2 = 10 + ptr[2] - 'A';
}
if(x1 == 0xFF || x2 == 0xFF) {
if (x1 == 0xFF || x2 == 0xFF) {
goto ndpi_end_bt_tracker_check;
}
ptr += 3;
len -= 3;
} else if(*ptr >= 32 && *ptr < 127) {
} else if (*ptr >= 32 && *ptr < 127) {
ptr++;
len--;
} else {
@@ -303,14 +280,15 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct,
NDPI_LOG_TRACE, " BT stat: tracker info hash parsed\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
ndpi_end_bt_tracker_check:
if(packet->payload_packet_len == 80) {
if (packet->payload_packet_len == 80) {
/* Warez 80 Bytes Packet
* +----------------+---------------+-----------------+-----------------+
* |20 BytesPattern | 32 Bytes Value| 12 BytesPattern | 16 Bytes Data |
@@ -328,28 +306,30 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
};
/* 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)) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT, ndpi_struct,
NDPI_LOG_TRACE, "BT: Warez - Plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_REAL_PROTOCOL */);
return 1;
}
}
else if(packet->payload_packet_len > 50) {
if(memcmp(packet->payload, "GET", 3) == 0) {
else if (packet->payload_packet_len > 50) {
if (memcmp(packet->payload, "GET", 3) == 0) {
ndpi_parse_packet_line_info(ndpi_struct, flow);
/* 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) {
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT,
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_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
/* NDPI_CORRELATED_PROTOCOL */);
return 1;
}
}
@@ -361,16 +341,17 @@ static u_int8_t ndpi_int_search_bittorrent_tcp_zero(struct ndpi_detection_module
/*Search for BitTorrent commands*/
static void ndpi_int_search_bittorrent_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->payload_packet_len == 0) {
if (packet->payload_packet_len == 0) {
return;
}
if(flow->bittorrent_stage == 0 && packet->payload_packet_len != 0) {
if (flow->bittorrent_stage == 0 && packet->payload_packet_len != 0) {
/* exclude stage 0 detection from next run */
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,
"stage 0 has detected something, returning\n");
return;
@@ -386,7 +367,6 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
{
struct ndpi_packet_struct *packet = &flow->packet;
int no_bittorrent = 0;
char *bt_proto = NULL;
/* This is broadcast */
if(packet->iph
@@ -398,10 +378,10 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
return;
}
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_BITTORRENT) {
/* check for tcp retransmission here */
if((packet->tcp != NULL)
if ((packet->tcp != NULL)
&& (packet->tcp_retransmission == 0 || packet->num_retried_bytes)) {
ndpi_int_search_bittorrent_tcp(ndpi_struct, flow);
}
@@ -420,8 +400,9 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
if(packet->payload_packet_len >= 23 /* min header size */) {
if(strncmp((const char*)packet->payload, bt_search, strlen(bt_search)) == 0) {
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_REAL_PROTOCOL */);
return;
} else {
/* Check if this is protocol v0 */
@@ -433,31 +414,34 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
u_int8_t v1_extension = packet->payload[1];
u_int32_t v1_window_size = *((u_int32_t*)&packet->payload[12]);
if(is_utp_pkt(packet->payload, packet->payload_packet_len))
goto bittorrent_found;
else if((packet->payload[0]== 0x60)
if((packet->payload[0]== 0x60)
&& (packet->payload[1]== 0x0)
&& (packet->payload[2]== 0x0)
&& (packet->payload[3]== 0x0)
&& (packet->payload[4]== 0x0)) {
/* Heuristic */
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found;
} else if(((v1_version & 0x0f) == 1)
&& ((v1_version >> 4) < 5 /* ST_NUM_STATES */)
&& (v1_extension < 3 /* EXT_NUM_EXT */)
&& (v1_window_size < 32768 /* 32k */)
) {
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found;
} else if((v0_flags < 6 /* ST_NUM_STATES */) && (v0_extension < 3 /* EXT_NUM_EXT */)) {
} else if((v0_flags < 6 /* ST_NUM_STATES */)
&& (v0_extension < 3 /* EXT_NUM_EXT */)) {
u_int32_t ts = ntohl(*((u_int32_t*)&(packet->payload[4])));
u_int32_t now;
#ifndef __KERNEL__
now = (u_int32_t)time(NULL);
#else
struct timespec t;
getnstimeofday(&t);
now = t.tv_sec;
#endif
if((ts < (now+86400)) && (ts > (now-86400))) {
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found;
}
}
@@ -467,28 +451,24 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
flow->bittorrent_stage++;
if(flow->bittorrent_stage < 10) {
/* We have detected bittorrent but we need to wait until we get a hash */
if(packet->payload_packet_len > 19 /* min size */) {
if(ndpi_strnstr((const char *)packet->payload, ":target20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":find_node1:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "d1:ad2:id20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":info_hash20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":filter64", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "d1:rd2:id20:", packet->payload_packet_len)
|| (bt_proto = ndpi_strnstr((const char *)packet->payload, "BitTorrent protocol", packet->payload_packet_len))
) {
bittorrent_found:
if(bt_proto && (packet->payload_packet_len > 47))
memcpy(flow->bittorent_hash, &bt_proto[27], 20);
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT,
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 0,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
return;
}
}
if(packet->payload_packet_len > 19 /* min size */) {
if(ndpi_strnstr((const char *)packet->payload, ":target20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":find_node1:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "d1:ad2:id20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":info_hash20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, ":filter64", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "d1:rd2:id20:", packet->payload_packet_len)
|| ndpi_strnstr((const char *)packet->payload, "BitTorrent protocol", packet->payload_packet_len)
) {
bittorrent_found:
NDPI_LOG(NDPI_PROTOCOL_BITTORRENT,
ndpi_struct, NDPI_LOG_TRACE, "BT: plain BitTorrent protocol detected\n");
ndpi_add_connection_as_bittorrent(ndpi_struct, flow,
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
/* NDPI_REAL_PROTOCOL */);
return;
}
}
return;
}
+6 -1
View File
@@ -42,6 +42,8 @@ typedef signed long long int i_int64_t;
#include "btlib.h"
#ifndef __KERNEL__
int bt_parse_debug = 0;
static char *printXb(char *s,const u_int8_t *b,int l) {
@@ -181,8 +183,11 @@ 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) {
_print_safe_str(msg,cbd->buf,cbd->v.s.s,cbd->v.s.l);
}
#define DEBUG_TRACE(cmd) { if(bt_parse_debug) cmd; }
#else
#define DEBUG_TRACE(cmd,args...)
#endif /* __KERNEL */
#define STREQ(a,b) !strcmp(a,b)
+2
View File
@@ -139,7 +139,9 @@ typedef struct bt_parse_data_cb {
} v;
} bt_parse_data_cb_t;
#ifndef __KERNEL__
extern int bt_parse_debug;
void dump_bt_proto_struct(struct bt_parse_protocol *p);
#endif
const u_int8_t *bt_decode(const u_int8_t *b, size_t *l, int *ret, bt_parse_data_cb_t *cbd);
+9
View File
@@ -33,6 +33,14 @@ static void ndpi_check_citrix(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
#if 0
printf("[len=%u][%02X %02X %02X %02X]\n", payload_len,
packet->payload[0] & 0xFF,
packet->payload[1] & 0xFF,
packet->payload[2] & 0xFF,
packet->payload[3] & 0xFF);
#endif
if(packet->tcp != NULL) {
flow->l4.tcp.citrix_packet_id++;
@@ -62,6 +70,7 @@ static void ndpi_check_citrix(struct ndpi_detection_module_struct *ndpi_struct,
return;
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CITRIX);
} else if(flow->l4.tcp.citrix_packet_id > 3)
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_CITRIX);
-165
View File
@@ -1,165 +0,0 @@
/*
* coap.c
*
* Copyright (C) 2016 Sorin Zamfir <sorin.zamfir@yahoo.com>
*
* 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_COAP
#define CON 0
#define NO_CON 1
#define ACK 2
#define RST 3
struct ndpi_coap_hdr
{
#if defined(__BIG_ENDIAN__)
u_int8_t version:2, type:2, tkl:4;
#elif defined(__LITTLE_ENDIAN__)
u_int8_t tkl:4, type:2, version:2;
#endif
u_int8_t code;
u_int16_t message_id; //if needed, remember to convert in host number
};
/**
VALUE OF -CODE- FIELD
[0] = "Empty",
[1] = "GET",
[2] = "POST",
[3] = "PUT",
[4] = "DELETE",
[65] = "2.01 Created",
[66] = "2.02 Deleted",
[67] = "2.03 Valid",
[68] = "2.04 Changed",
[69] = "2.05 Content",
[128] = "4.00 Bad Request",
[129] = "4.01 Unauthorized",
[130] = "4.02 Bad Option",
[131] = "4.03 Forbidden",
[132] = "4.04 Not Found",
[133] = "4.05 Method Not Allowed",
[134] = "4.06 Not Acceptable",
[140] = "4.12 Precondition Failed",
[141] = "4.13 Request Entity Too Large",
[143] = "4.15 Unsupported Content-Format",
[160] = "5.00 Internal Server Error",
[161] = "5.01 Not Implemented",
[162] = "5.02 Bad Gateway",
[163] = "5.03 Service Unavailable",
[164] = "5.04 Gateway Timeout",
[165] = "5.05 Proxying Not Supported"
**/
/**
* Entry point when protocol is identified.
*/
static void ndpi_int_coap_add_connection (struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct,flow,NDPI_PROTOCOL_COAP,NDPI_PROTOCOL_UNKNOWN);
}
/**
* Check if the default port is acceptable
*
* UDP Port 5683 (mandatory)
* UDP Ports 61616-61631 compressed 6lowPAN
*/
static int isCoAPport(u_int16_t port) {
if((port == 5683)
|| ((port >= 61616) && (port <= 61631)))
return(1);
else
return(0);
}
/**
* Dissector function that searches CoAP headers
*/
void ndpi_search_coap (struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_coap_hdr * h = (struct ndpi_coap_hdr*) packet->payload;
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
return;
}
// search for udp packet
if(packet->udp != NULL) {
u_int16_t s_port = ntohs(flow->packet.udp->source);
u_int16_t d_port = ntohs(flow->packet.udp->dest);
if((!isCoAPport(s_port) && !isCoAPport(s_port))
|| (packet->payload_packet_len < 4) // header too short
) {
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;
}
NDPI_LOG(NDPI_PROTOCOL_COAP, ndpi_struct, NDPI_LOG_DEBUG, "calculating coap over udp.\n");
// check values in header
if(h->version == 1) {
if(h->type == CON || h->type == NO_CON || h->type == ACK || h->type == RST ) {
if(h->tkl == 0 || h->tkl < 8) {
if((h->code >= 0 && h->code <= 5) || (h->code >= 65 && h->code <= 69) ||
(h->code >= 128 && h->code <= 134) || (h->code >= 140 && h->code <= 143) ||
(h->code >= 160 && h->code <= 165)) {
NDPI_LOG(NDPI_PROTOCOL_COAP, ndpi_struct, NDPI_LOG_DEBUG, "Coap found...\n");
ndpi_int_coap_add_connection(ndpi_struct,flow);
return;
}
}
}
}
}
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;
}
/**
* Entry point for the ndpi library
*/
void init_coap_dissector (struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection ("COAP", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_COAP,
ndpi_search_coap,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, ADD_TO_DETECTION_BITMASK);
*id +=1;
}
#endif // NDPI_PROTOCOL_COAP
+8 -9
View File
@@ -18,7 +18,7 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
@@ -35,21 +35,20 @@ static void ndpi_int_dcerpc_add_connection(struct ndpi_detection_module_struct
void ndpi_search_dcerpc(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if((packet->tcp != NULL)
&& (packet->payload_packet_len >= 64)
if((packet->tcp != NULL)
&& (packet->payload_packet_len > 64)
&& ((ntohs(packet->tcp->source) == 135) || (ntohs(packet->tcp->dest) == 135))
&& (packet->payload[0] == 0x05) /* version 5 */
&& (packet->payload[2] < 16) /* Packet type */
&& (((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(NDPI_PROTOCOL_DCERPC, ndpi_struct, NDPI_LOG_DEBUG, "DCERPC match\n");
ndpi_int_dcerpc_add_connection(ndpi_struct, flow);
return;
}
if(packet->payload_packet_len>1){
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DCERPC);
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DCERPC);
}
+15 -15
View File
@@ -35,27 +35,27 @@ static void ndpi_int_dhcp_add_connection(struct ndpi_detection_module_struct *nd
void ndpi_search_dhcp_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;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
/* this detection also works for asymmetric dhcp traffic */
/* this detection also works for asymmetric dhcp traffic */
/*check standard DHCP 0.0.0.0:68 -> 255.255.255.255:67 */
if (packet->payload_packet_len >= 244 && (packet->udp->source == htons(67)
|| packet->udp->source == htons(68))
&& (packet->udp->dest == htons(67) || packet->udp->dest == htons(68))
&& get_u_int32_t(packet->payload, 236) == htonl(0x63825363)
&& get_u_int16_t(packet->payload, 240) == htons(0x3501)) {
/*check standard DHCP 0.0.0.0:68 -> 255.255.255.255:67 */
if (packet->payload_packet_len >= 244 && (packet->udp->source == htons(67)
|| packet->udp->source == htons(68))
&& (packet->udp->dest == htons(67) || packet->udp->dest == htons(68))
&& get_u_int32_t(packet->payload, 236) == htonl(0x63825363)
&& get_u_int16_t(packet->payload, 240) == htons(0x3501)) {
NDPI_LOG(NDPI_PROTOCOL_DHCP, ndpi_struct, NDPI_LOG_DEBUG, "DHCP request\n");
NDPI_LOG(NDPI_PROTOCOL_DHCP, ndpi_struct, NDPI_LOG_DEBUG, "DHCP request\n");
ndpi_int_dhcp_add_connection(ndpi_struct, flow);
return;
}
ndpi_int_dhcp_add_connection(ndpi_struct, flow);
return;
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DHCP);
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DHCP);
}
+17 -4
View File
@@ -709,10 +709,23 @@ void ndpi_search_direct_download_link_tcp(struct ndpi_detection_module_struct *n
{
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 */
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
#if 0
if (ndpi_struct->direct_download_link_counter_callback != NULL) {
if (packet->detected_protocol == NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK) {
/* skip packets not requests from the client to the server */
if (packet->packet_direction == flow->l4.tcp.ddlink_server_direction) {
search_ddl_domains(ndpi_struct, flow); // do the detection again in order to get the URL in keep alive streams
} else {
// just count the packet
ndpi_struct->direct_download_link_counter_callback(flow->hash_id_number, packet->l3_packet_len);
}
}
return;
}
#endif
// do not detect again if it is already ddl
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK) {
if (search_ddl_domains(ndpi_struct, flow) != 0) {
return;
+242 -176
View File
@@ -1,7 +1,7 @@
/*
* dns.c
*
* Copyright (C) 2012-16 - ntop.org
* Copyright (C) 2012-15 - 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
@@ -21,26 +21,11 @@
*
*/
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_DNS
#define FLAGS_MASK 0x8000
/* #define DNS_DEBUG 1 */
/* *********************************************** */
static u_int16_t get16(int *i, const u_int8_t *payload) {
u_int16_t v = *(u_int16_t*)&payload[*i];
(*i) += 2;
return(ntohs(v));
}
/* *********************************************** */
static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
if(payload[i] == 0x00)
return(1);
@@ -49,191 +34,272 @@ static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
else {
u_int8_t len = payload[i];
u_int8_t off = len + 1;
if(off == 0) /* Bad packet */
return(0);
else
return(off + getNameLength(i+off, payload, payloadLen));
}
}
}
/* *********************************************** */
void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
int x;
u_int8_t is_query;
u_int16_t s_port = 0, d_port = 0;
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "search DNS.\n");
static char* ndpi_intoa_v4(unsigned int addr, char* buf, u_short bufLen) {
char *cp, *retStr;
uint byte;
int n;
if(flow->packet.udp != NULL) {
s_port = ntohs(flow->packet.udp->source);
d_port = ntohs(flow->packet.udp->dest);
x = 0;
} else if(flow->packet.tcp != NULL) /* pkt size > 512 bytes */ {
s_port = ntohs(flow->packet.tcp->source);
d_port = ntohs(flow->packet.tcp->dest);
x = 2;
} else {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
cp = &buf[bufLen];
*--cp = '\0';
n = 4;
do {
byte = addr & 0xff;
*--cp = byte % 10 + '0';
byte /= 10;
if(byte > 0) {
*--cp = byte % 10 + '0';
byte /= 10;
if(byte > 0)
*--cp = byte + '0';
}
*--cp = '.';
addr >>= 8;
} while (--n > 0);
/* Convert the string to lowercase */
retStr = (char*)(cp+1);
return(retStr);
}
/* *********************************************** */
static u_int16_t get16(int *i, const u_int8_t *payload) {
u_int16_t v = *(u_int16_t*)&payload[*i];
(*i) += 2;
return(ntohs(v));
}
/* *********************************************** */
struct dns_packet_header {
u_int16_t transaction_id, flags, num_queries, answer_rrs, authority_rrs, additional_rrs;
} __attribute__((packed));
void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t dport = 0, sport = 0;
#define NDPI_MAX_DNS_REQUESTS 16
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "search DNS.\n");
if (packet->udp != NULL) {
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over UDP.\n");
} else if(packet->tcp != NULL) {
sport = ntohs(packet->tcp->source), dport = ntohs(packet->tcp->dest);
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over tcp.\n");
}
if((s_port == 53 || d_port == 53 || d_port == 5355)
&& (flow->packet.payload_packet_len > sizeof(struct ndpi_dns_packet_header))) {
struct ndpi_dns_packet_header dns_header;
int invalid = 0;
if(((dport == 53) || (sport == 53) || (dport == 5355))
&& (packet->payload_packet_len > sizeof(struct dns_packet_header))) {
int i = packet->tcp ? 2 : 0;
struct dns_packet_header header, *dns = (struct dns_packet_header*)&packet->payload[i];
u_int8_t is_query, ret_code, is_dns = 0;
u_int32_t a_record[NDPI_MAX_DNS_REQUESTS] = { 0 }, query_offset, num_a_records = 0;
memcpy(&dns_header, (struct ndpi_dns_packet_header*) &flow->packet.payload[x], sizeof(struct ndpi_dns_packet_header));
dns_header.tr_id = ntohs(dns_header.tr_id);
dns_header.flags = ntohs(dns_header.flags);
dns_header.num_queries = ntohs(dns_header.num_queries);
dns_header.num_answers = ntohs(dns_header.num_answers);
dns_header.authority_rrs = ntohs(dns_header.authority_rrs);
dns_header.additional_rrs = ntohs(dns_header.additional_rrs);
x += sizeof(struct ndpi_dns_packet_header);
header.flags = ntohs(dns->flags);
header.transaction_id = ntohs(dns->transaction_id);
header.num_queries = ntohs(dns->num_queries);
header.answer_rrs = ntohs(dns->answer_rrs);
header.authority_rrs = ntohs(dns->authority_rrs);
header.additional_rrs = ntohs(dns->additional_rrs);
is_query = (header.flags & 0x8000) ? 0 : 1;
ret_code = is_query ? 0 : (header.flags & 0x0F);
i += sizeof(struct dns_packet_header);
query_offset = i;
/* 0x0000 QUERY */
if((dns_header.flags & FLAGS_MASK) == 0x0000)
is_query = 1;
/* 0x8000 RESPONSE */
else if((dns_header.flags & FLAGS_MASK) == 0x8000)
is_query = 0;
else
invalid = 1;
if(is_query) {
/* DNS Request */
if((header.num_queries > 0) && (header.num_queries <= NDPI_MAX_DNS_REQUESTS)
&& (((header.flags & 0x2800) == 0x2800 /* Dynamic DNS Update */)
|| ((header.answer_rrs == 0) && (header.authority_rrs == 0)))) {
/* This is a good query */
is_dns = 1;
if(!invalid) {
if(is_query) {
/* DNS Request */
if((dns_header.num_queries > 0) && (dns_header.num_queries <= NDPI_MAX_DNS_REQUESTS)
&& (((dns_header.flags & 0x2800) == 0x2800 /* Dynamic DNS Update */)
|| ((dns_header.num_answers == 0) && (dns_header.authority_rrs == 0)))) {
/* This is a good query */
if(dns_header.num_queries > 0) {
while(x < flow->packet.payload_packet_len) {
if(flow->packet.payload[x] == '\0') {
x++;
flow->protos.dns.query_type = get16(&x, flow->packet.payload);
#ifdef DNS_DEBUG
printf("[%s:%d] query_type=%2d\n", __FILE__, __LINE__, flow->protos.dns.query_type);
#endif
if(header.num_queries > 0) {
while(i < packet->payload_packet_len) {
if(packet->payload[i] == '\0') {
i++;
flow->protos.dns.query_type = get16(&i, packet->payload);
break;
} else
x++;
i++;
}
}
} else
invalid = 1;
}
}
} else {
/* DNS Reply */
flow->server_id = flow->dst;
if((header.num_queries <= NDPI_MAX_DNS_REQUESTS) /* Don't assume that num_queries must be zero */
&& (((header.answer_rrs > 0) && (header.answer_rrs <= NDPI_MAX_DNS_REQUESTS))
|| ((header.authority_rrs > 0) && (header.authority_rrs <= NDPI_MAX_DNS_REQUESTS))
|| ((header.additional_rrs > 0) && (header.additional_rrs <= NDPI_MAX_DNS_REQUESTS)))
) {
/* This is a good reply */
is_dns = 1;
i++;
} else {
/* DNS Reply */
flow->protos.dns.reply_code = dns_header.flags & 0x0F;
if((dns_header.num_queries > 0) && (dns_header.num_queries <= NDPI_MAX_DNS_REQUESTS) /* Don't assume that num_queries must be zero */
&& (((dns_header.num_answers > 0) && (dns_header.num_answers <= NDPI_MAX_DNS_REQUESTS))
|| ((dns_header.authority_rrs > 0) && (dns_header.authority_rrs <= NDPI_MAX_DNS_REQUESTS))
|| ((dns_header.additional_rrs > 0) && (dns_header.additional_rrs <= NDPI_MAX_DNS_REQUESTS)))
) {
/* This is a good reply */
if(ndpi_struct->dns_dissect_response) {
x++;
if(flow->packet.payload[x] != '\0') {
while((x < flow->packet.payload_packet_len)
&& (flow->packet.payload[x] != '\0')) {
x++;
}
x++;
}
x += 4;
if(dns_header.num_answers > 0) {
u_int16_t rsp_type;
u_int16_t num;
for(num = 0; num < dns_header.num_answers; num++) {
u_int16_t data_len;
if((x+6) >= flow->packet.payload_packet_len) {
break;
}
if((data_len = getNameLength(x, flow->packet.payload, flow->packet.payload_packet_len)) == 0) {
break;
} else
x += data_len;
rsp_type = get16(&x, flow->packet.payload);
flow->protos.dns.rsp_type = rsp_type;
break;
}
}
if(packet->payload[i] != '\0') {
while((i < packet->payload_packet_len)
&& (packet->payload[i] != '\0')) {
i++;
}
i++;
}
i += 4;
if(header.answer_rrs > 0) {
u_int16_t rsp_type;
u_int16_t num;
for(num = 0; num < header.answer_rrs; num++) {
u_int16_t data_len;
if((i+6) >= packet->payload_packet_len) {
break;
}
if((data_len = getNameLength(i, packet->payload, packet->payload_packet_len)) == 0) {
break;
} else
i += data_len;
rsp_type = get16(&i, packet->payload);
// Skip past the CLASS (2 octets) and TTL (4 octets) fields.
i += 6;
data_len = get16(&i, packet->payload);
if((data_len <= 1) || (data_len > (packet->payload_packet_len-i))) {
break;
}
flow->protos.dns.rsp_type = rsp_type;
if(rsp_type == 1 /* A */) {
if(data_len == 4) {
u_int32_t v = ntohl(*((u_int32_t*)&packet->payload[i]));
if(num_a_records < (NDPI_MAX_DNS_REQUESTS-1))
a_record[num_a_records++] = v;
else
break; /* One record is enough */
}
}
if(data_len == 0) {
break;
}
i += data_len;
} /* for */
}
}
if(invalid) {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
return;
}
/* extract host name server */
int j = 0, max_len = sizeof(flow->host_server_name)-1, off = sizeof(struct ndpi_dns_packet_header) + 1;
while(flow->packet.payload[off] != '\0' && off < flow->packet.payload_packet_len) {
flow->host_server_name[j] = flow->packet.payload[off];
if(j < max_len) {
if(flow->host_server_name[j] < ' ')
flow->host_server_name[j] = '.';
j++;
} else
break;
off++;
}
flow->host_server_name[j] = '\0';
flow->protos.dns.num_queries = (u_int8_t)dns_header.num_queries,
flow->protos.dns.num_answers = (u_int8_t) (dns_header.num_answers + dns_header.authority_rrs + dns_header.additional_rrs);
if(j > 0)
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
NDPI_PROTOCOL_DNS);
#ifdef DNS_DEBUG
printf("[%s:%d] [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.reply_code, flow->protos.dns.rsp_type, flow->host_server_name
);
#endif
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
matched a subprotocol
**/
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "found DNS.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
} else {
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
if((header.num_queries <= NDPI_MAX_DNS_REQUESTS)
&& ((header.answer_rrs == 0)
|| (header.authority_rrs == 0)
|| (header.additional_rrs == 0))
&& (ret_code != 0 /* 0 == OK */)
) {
/* This is a good reply */
is_dns = 1;
}
}
}
if(is_dns) {
int j = 0;
flow->protos.dns.num_queries = (u_int8_t)header.num_queries,
flow->protos.dns.num_answers = (u_int8_t)(header.answer_rrs+header.authority_rrs+header.additional_rrs),
flow->protos.dns.ret_code = ret_code;
i = query_offset+1;
while((i < packet->payload_packet_len)
&& (j < (sizeof(flow->host_server_name)-1))
&& (packet->payload[i] != '\0')) {
flow->host_server_name[j] = tolower(packet->payload[i]);
if(flow->host_server_name[j] < ' ')
flow->host_server_name[j] = '.';
j++, i++;
}
if(a_record[0] != 0) {
char a_buf[32];
int i;
for(i=0; j < sizeof(flow->host_server_name)-1 && i < num_a_records; i++) {
j += snprintf((char*)&flow->host_server_name[j], sizeof(flow->host_server_name)-1-j, "%s%s",
(i == 0) ? "@" : ";",
ndpi_intoa_v4(a_record[i], a_buf, sizeof(a_buf)));
}
}
flow->host_server_name[j] = '\0';
if(j > 0) {
#ifdef DEBUG
printf("==> %s\n", flow->host_server_name);
#endif
if(ndpi_struct->match_dns_host_names)
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
NDPI_PROTOCOL_DNS);
}
i++;
memcpy(&flow->protos.dns.query_type, &packet->payload[i], 2);
flow->protos.dns.query_type = ntohs(flow->protos.dns.query_type), i += 2;
memcpy(&flow->protos.dns.query_class, &packet->payload[i], 2);
flow->protos.dns.query_class = ntohs(flow->protos.dns.query_class), i += 2;
#ifdef DEBUG
printf("%s [type=%04X][class=%04X]\n", flow->host_server_name, flow->protos.dns.query_type, flow->protos.dns.query_class);
#endif
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
/*
Do not set the protocol with DNS if ndpi_match_host_subprotocol() has
matched a subprotocol
*/
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "found DNS.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, (dport == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS, NDPI_PROTOCOL_UNKNOWN);
}
} else {
flow->protos.dns.bad_packet = 1;
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "exclude DNS.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DNS);
}
}
}
void init_dns_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("DNS", ndpi_struct, detection_bitmask, *id,
-106
View File
@@ -1,106 +0,0 @@
/*
* drda.c
*
* Copyright (C) 2012-16 - ntop.org
*
* This module 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.
*
* This module 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.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_DRDA
#define DRDA_PORT 50000
struct ndpi_drda_hdr {
u_int16_t length;
u_int8_t magic;
u_int8_t format;
u_int16_t correlID;
u_int16_t length2;
u_int16_t code_pnt;
};
void ndpi_search_drda(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct * packet = &flow->packet;
u_int16_t payload_len = packet->payload_packet_len;
u_int16_t count = 0;
if(packet->tcp != NULL) {
/* check port */
if((ntohs(packet->tcp->source) == DRDA_PORT ||
ntohs(packet->tcp->dest) == DRDA_PORT)) {
struct ndpi_drda_hdr * drda = (struct ndpi_drda_hdr *) packet->payload;
u_int16_t len = ntohs(drda->length);
/* check first header */
if(len - 6 != ntohs(drda->length2) &&
drda->magic != 0xd0)
goto no_drda;
/* check if there are more drda headers */
if(payload_len > len) {
count = len;
const u_int8_t * pp = packet->payload + len;
while(count < payload_len)
{
/* update info */
drda = (struct ndpi_drda_hdr *) pp;
len = ntohs(drda->length);
if(len - 6 != ntohs(drda->length2) &&
drda->magic != 0xd0)
goto no_drda;
count += len;
}
if(count != payload_len) goto no_drda;
}
NDPI_LOG(NDPI_PROTOCOL_DRDA, ndpi_struct, NDPI_LOG_DEBUG, "found DRDA.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DRDA, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
no_drda:
NDPI_LOG(NDPI_PROTOCOL_DRDA, ndpi_struct, NDPI_LOG_DEBUG, "exclude DRDA.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DRDA);
}
/* ***************************************************************** */
void init_drda_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("DRDA", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_DRDA,
ndpi_search_drda,
NDPI_SELECTION_BITMASK_PROTOCOL_TCP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif /* NDPI_PROTOCOL_DRDA */
+3 -8
View File
@@ -1,7 +1,7 @@
/*
* dropbox.c
*
* Copyright (C) 2012-16 by ntop.org
* Copyright (C) 2011-13 by 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
@@ -25,10 +25,6 @@
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_DROPBOX
#define DB_LSP_PORT 17500
static void ndpi_int_dropbox_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t due_to_correlation)
@@ -44,13 +40,12 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t payload_len = packet->payload_packet_len;
if(packet->udp != NULL) {
u_int16_t dropbox_port = htons(DB_LSP_PORT);
u_int16_t dropbox_port = htons(17500);
if((packet->udp->source == dropbox_port)
&& (packet->udp->dest == dropbox_port)) {
if(payload_len > 2) {
if(strncmp((const char *)packet->payload, "{\"host_int\"", 11) == 0) {
if(strncmp((const char *)packet->payload, "{\"", 2) == 0) {
NDPI_LOG(NDPI_PROTOCOL_DROPBOX, ndpi_struct, NDPI_LOG_DEBUG, "Found dropbox.\n");
ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0);
return;
File diff suppressed because it is too large Load Diff
+20 -20
View File
@@ -60,14 +60,13 @@ static int ndpi_match_ftp_data_directory(struct ndpi_detection_module_struct *nd
static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
/* A FTP packet is pretty long so 256 is a bit consrvative but it should be OK */
if(packet->payload_packet_len < 256)
return 0;
/* RIFF is a meta-format for storing AVI and WAV files */
if(ndpi_match_strprefix(packet->payload, payload_len, "RIFF"))
if(match_first_bytes(packet->payload, "RIFF"))
return 1;
/* MZ is a .exe file */
@@ -75,7 +74,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* Ogg files */
if(ndpi_match_strprefix(packet->payload, payload_len, "OggS"))
if(match_first_bytes(packet->payload, "OggS"))
return 1;
/* ZIP files */
@@ -87,7 +86,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* RAR files */
if(ndpi_match_strprefix(packet->payload, payload_len, "Rar!"))
if(match_first_bytes(packet->payload, "Rar!"))
return 1;
/* EBML */
@@ -99,7 +98,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* GIF */
if(ndpi_match_strprefix(packet->payload, payload_len, "GIF8"))
if(match_first_bytes(packet->payload, "GIF8"))
return 1;
/* PHP scripts */
@@ -111,7 +110,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* PDFs */
if(ndpi_match_strprefix(packet->payload, payload_len, "%PDF"))
if(match_first_bytes(packet->payload, "%PDF"))
return 1;
/* PNG */
@@ -119,7 +118,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* HTML */
if(ndpi_match_strprefix(packet->payload, payload_len, "<htm"))
if(match_first_bytes(packet->payload, "<htm"))
return 1;
if((packet->payload[0] == 0x0a) && (packet->payload[1] == '<') && (packet->payload[2] == '!') && (packet->payload[3] == 'D'))
return 1;
@@ -133,17 +132,17 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* XML */
if(ndpi_match_strprefix(packet->payload, payload_len, "<!DO"))
if(match_first_bytes(packet->payload, "<!DO"))
return 1;
/* FLAC */
if(ndpi_match_strprefix(packet->payload, payload_len, "fLaC"))
if(match_first_bytes(packet->payload, "fLaC"))
return 1;
/* MP3 */
if((packet->payload[0] == 'I') && (packet->payload[1] == 'D') && (packet->payload[2] == '3') && (packet->payload[3] == 0x03))
return 1;
if(ndpi_match_strprefix(packet->payload, payload_len, "\xff\xfb\x90\xc0"))
if(match_first_bytes(packet->payload, "\xff\xfb\x90\xc0"))
return 1;
/* RPM */
@@ -151,7 +150,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* Wz Patch */
if(ndpi_match_strprefix(packet->payload, payload_len, "WzPa"))
if(match_first_bytes(packet->payload, "WzPa"))
return 1;
/* Flash Video */
@@ -159,7 +158,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* .BKF (Microsoft Tape Format) */
if(ndpi_match_strprefix(packet->payload, payload_len, "TAPE"))
if(match_first_bytes(packet->payload, "TAPE"))
return 1;
/* MS Office Doc file - this is unpleasantly geeky */
@@ -175,23 +174,23 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
/* ar archive, typically .deb files */
if(ndpi_match_strprefix(packet->payload, payload_len, "!<ar"))
if(match_first_bytes(packet->payload, "!<ar"))
return 1;
/* Raw XML (skip jabber-like traffic as this is not FTP but unencrypted jabber) */
if((ndpi_match_strprefix(packet->payload, payload_len, "<?xm"))
if((match_first_bytes(packet->payload, "<?xm"))
&& (ndpi_strnstr((const char *)packet->payload, "jabber", packet->payload_packet_len) == NULL))
return 1;
if(ndpi_match_strprefix(packet->payload, payload_len, "<iq "))
if(match_first_bytes(packet->payload, "<iq "))
return 1;
/* SPF */
if(ndpi_match_strprefix(packet->payload, payload_len, "SPFI"))
if(match_first_bytes(packet->payload, "SPFI"))
return 1;
/* ABIF - Applied Biosystems */
if(ndpi_match_strprefix(packet->payload, payload_len, "ABIF"))
if(match_first_bytes(packet->payload, "ABIF"))
return 1;
/* bzip2 - other digits are also possible instead of 9 */
@@ -204,11 +203,11 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
return 1;
if((packet->payload[0] == '<') && (packet->payload[1] == 'C') && (packet->payload[2] == 'F'))
return 1;
if(ndpi_match_strprefix(packet->payload, payload_len, ".tem"))
if(match_first_bytes(packet->payload, ".tem"))
return 1;
if(ndpi_match_strprefix(packet->payload, payload_len, ".ite"))
if(match_first_bytes(packet->payload, ".ite"))
return 1;
if(ndpi_match_strprefix(packet->payload, payload_len, ".lef"))
if(match_first_bytes(packet->payload, ".lef"))
return 1;
return 0;
@@ -230,6 +229,7 @@ static void ndpi_check_ftp_data(struct ndpi_detection_module_struct *ndpi_struct
}
void ndpi_search_ftp_data(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
/* Break after 20 packets. */
if(flow->packet_counter > 20) {
-83
View File
@@ -1,83 +0,0 @@
/*
* git.c
*
* Copyright (C) 2012-16 - ntop.org
*
* This module 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.
*
* This module 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.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_GIT
#define GIT_PORT 9418
void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct * packet = &flow->packet;
if((packet->tcp != NULL) && (packet->payload_packet_len > 4)) {
if((ntohs(packet->tcp->source) == GIT_PORT)
|| (ntohs(packet->tcp->dest) == GIT_PORT)) {
const u_int8_t * pp = packet->payload;
u_int16_t payload_len = packet->payload_packet_len;
u_int8_t found_git = 1;
u_int16_t git_len = 0, offset = 0;
while((offset+4) < payload_len) {
char len[5];
u_int32_t git_pkt_len;
memcpy(&len, &pp[offset], 4), len[4] = 0;
git_pkt_len = atoi(len);
if((payload_len < git_pkt_len) || (git_pkt_len == 0 /* Bad */)) {
found_git = 0;
break;
} else
offset += git_pkt_len, payload_len -= git_pkt_len;
}
if(found_git) {
NDPI_LOG(NDPI_PROTOCOL_GIT, ndpi_struct, NDPI_LOG_DEBUG, "found Git.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GIT, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
}
NDPI_LOG(NDPI_PROTOCOL_GIT, ndpi_struct, NDPI_LOG_DEBUG, "exclude Git.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_GIT);
}
/* ***************************************************************** */
void init_git_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Git", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_GIT,
ndpi_search_git,
NDPI_SELECTION_BITMASK_PROTOCOL_TCP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif /* NDPI_PROTOCOL_GIT */
+1 -1
View File
@@ -294,7 +294,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
return;
}
if (packet->payload_packet_len >= 3 && memcmp(packet->payload, "GND", 3) == 0) {
if (memcmp(packet->payload, "GND", 3) == 0) {
if ((packet->payload_packet_len == 8 && (memcmp(&packet->payload[6], "\x01\x00", 2) == 0))
|| (packet->payload_packet_len == 11 && (memcmp(&packet->payload[6], "\x01\x01\x08\x50\x49", 5)
== 0)) || (packet->payload_packet_len == 17
+9
View File
@@ -18,6 +18,7 @@
*
*/
#include "ndpi_api.h"
#ifdef NDPI_PROTOCOL_GTP
@@ -34,6 +35,14 @@ static void ndpi_check_gtp(struct ndpi_detection_module_struct *ndpi_struct, str
// const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len;
#if 0
printf("[len=%u][%02X %02X %02X %02X]\n", payload_len,
packet->payload[0] & 0xFF,
packet->payload[1] & 0xFF,
packet->payload[2] & 0xFF,
packet->payload[3] & 0xFF);
#endif
if((packet->udp != NULL) && (payload_len > sizeof(struct gtp_header_generic))) {
u_int32_t gtp_u = ntohs(2152);
u_int32_t gtp_c = ntohs(2123);
+2 -4
View File
@@ -27,8 +27,7 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "calculated dport over tcp.\n");
/* H323 */
if(packet->payload_packet_len >= 3
&& (packet->payload[0] == 0x03)
if((packet->payload[0] == 0x03)
&& (packet->payload[1] == 0x00)
&& (packet->payload[2] == 0x00)) {
struct tpkt *t = (struct tpkt*)packet->payload;
@@ -64,8 +63,7 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
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");
if(packet->payload_packet_len >= 5 && packet->payload[0] == 0x80 && packet->payload[1] == 0x08 &&
(packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) &&
if(packet->payload[0] == 0x80 && packet->payload[1] == 0x08 && (packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) &&
packet->payload[4] == 0x00 && packet->payload[5] == 0x00)
{
NDPI_LOG(NDPI_PROTOCOL_H323, ndpi_struct, NDPI_LOG_DEBUG, "found H323 broadcast.\n");
-68
View File
@@ -1,68 +0,0 @@
/*
* hep.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-15 - ntop.org
* Copyright (C) 2011-15 - QXIP BV
*
* 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_HEP
static void ndpi_int_hep_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HEP, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_hep(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len;
NDPI_LOG(NDPI_PROTOCOL_HEP, ndpi_struct, NDPI_LOG_DEBUG, "searching for HEP.\n");
if (payload_len > 10) {
if (memcmp(packet_payload, "HEP3", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HEP, ndpi_struct, NDPI_LOG_DEBUG, "found HEP3.\n");
ndpi_int_hep_add_connection(ndpi_struct, flow);
return;
}
}
NDPI_LOG(NDPI_PROTOCOL_HEP, ndpi_struct, NDPI_LOG_DEBUG, "exclude HEP.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HEP);
}
void init_hep_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("HEP", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_HEP,
ndpi_search_hep,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+35 -19
View File
@@ -37,14 +37,18 @@ static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *nd
/* If no custom protocol has been detected */
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
if(protocol == NDPI_PROTOCOL_HTTP)
if(protocol != NDPI_PROTOCOL_HTTP) {
ndpi_search_tcp_or_udp(ndpi_struct, flow);
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
} else {
ndpi_int_reset_protocol(flow);
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
}
}
flow->http_detected = 1;
}
}
#ifdef NDPI_CONTENT_FLASH
@@ -198,14 +202,21 @@ static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struc
/*
NOTE
If http_dont_dissect_response = 1 dissection of HTTP response
mime types won't happen
*/
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
strlen((const char *)flow->host_server_name),
NDPI_PROTOCOL_HTTP);
}
mime types won't happen
*/
if(!ndpi_struct->http_dont_dissect_response) {
if(flow->http.url && flow->http_detected)
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)&flow->http.url[7],
strlen((const char *)&flow->http.url[7]),
NDPI_PROTOCOL_HTTP);
} else
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
strlen((const char *)flow->host_server_name),
NDPI_PROTOCOL_HTTP);
}
}
/*
@@ -236,7 +247,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(flow->http.url) {
strncpy(flow->http.url, "http://", 7);
strncpy(&flow->http.url[7], (char*)packet->host_line.ptr, packet->host_line.len);
strncpy(&flow->http.url[7+packet->host_line.len], (char*)packet->http_url_name.ptr,
strncpy(&flow->http.url[7+packet->host_line.len], (char*)packet->http_url_name.ptr,
packet->http_url_name.len);
flow->http.url[len-1] = '\0';
}
@@ -271,8 +282,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
flow->http.content_type = ndpi_malloc(len);
if(flow->http.content_type) {
strncpy(flow->http.content_type, (char*)packet->content_line.ptr,
packet->content_line.len);
strncpy(flow->http.content_type, (char*)packet->content_line.ptr,
packet->content_line.len);
flow->http.content_type[packet->content_line.len] = '\0';
}
}
@@ -338,6 +349,14 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
NDPI_LOG(NDPI_PROTOCOL_HTTP, ndpi_struct, NDPI_LOG_DEBUG, "User Agent Type Line found %.*s\n",
packet->user_agent_line.len, packet->user_agent_line.ptr);
#if 0
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
ndpi_match_content_subprotocol(ndpi_struct, flow,
(char*)packet->user_agent_line.ptr,
packet->user_agent_line.len,
NDPI_PROTOCOL_HTTP);
#endif
}
/* check for host line */
@@ -348,11 +367,11 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
packet->host_line.len, packet->host_line.ptr);
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char*)packet->host_line.ptr,
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char*)packet->host_line.ptr,
packet->host_line.len,
NDPI_PROTOCOL_HTTP);
/* Copy result for nDPI apps */
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
strncpy((char*)flow->host_server_name, (char*)packet->host_line.ptr, len);
@@ -752,8 +771,6 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t filename_start;
packet->packet_lines_parsed_complete = 0;
/* Check if we so far detected the protocol in the request or not. */
if(flow->l4.tcp.http_stage == 0) {
flow->http_detected = 0;
@@ -894,7 +911,6 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
"HTTP START Found in 2. packet, we will look further for the response....\n");
flow->http_detected = 1;
}
return;
}
+1 -1
View File
@@ -585,7 +585,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (memcmp(packet->payload, "POST ", 5) == 0) {
ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->parsed_lines) {
u_int16_t http_header_len = (u_int16_t)((packet->line[packet->parsed_lines - 1].ptr - packet->payload) + 2);
u_int16_t http_header_len = (packet->line[packet->parsed_lines - 1].ptr - packet->payload) + 2;
if (packet->payload_packet_len > http_header_len) {
http_content_ptr_len = packet->payload_packet_len - http_header_len;
}
+3 -1
View File
@@ -30,10 +30,12 @@
#ifdef NDPI_SERVICE_KAKAOTALK_VOICE
void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
unsigned char *vers;
int ver_offs;
if(packet->iph
&& packet->udp
&& (packet->payload_packet_len >= 4)
&& (packet->payload_packet_len > 0)
) {
if((packet->payload[0] == 0x81)
|| (packet->payload[1] == 0xC8)
+14
View File
@@ -35,6 +35,20 @@ static void ndpi_check_lotus_notes(struct ndpi_detection_module_struct *ndpi_str
if(packet->tcp != NULL) {
flow->l4.tcp.lotus_notes_packet_id++;
#if 0
printf("[lotus_notes_packet_id: %u][len=%u][%02X %02X %02X %02X %02X %02X %02X %02X]\n",
flow->l4.tcp.lotus_notes_packet_id, payload_len,
packet->payload[6] & 0xFF,
packet->payload[7] & 0xFF,
packet->payload[8] & 0xFF,
packet->payload[9] & 0xFF,
packet->payload[10] & 0xFF,
packet->payload[11] & 0xFF,
packet->payload[12] & 0xFF,
packet->payload[13] & 0xFF
);
#endif
if((flow->l4.tcp.lotus_notes_packet_id == 1)
/* We have seen the 3-way handshake */
&& flow->l4.tcp.seen_syn
+1
View File
@@ -33,6 +33,7 @@ void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct
if((packet->udp != NULL) && ((packet->payload_packet_len % 188) == 0)) {
u_int i, num_chunks = packet->payload_packet_len / 188;
u_int32_t pkt_id;
for(i=0; i<num_chunks; i++) {
u_int offset = 188 * i;
-254
View File
@@ -1,254 +0,0 @@
/*
* mqtt.c
*
* Copyright (C) 2016 Sorin Zamfir <sorin.zamfir@yahoo.com>
*
* 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_MQTT
/**
* The type of control messages in mqtt version 3.1.1
* see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1
*/
enum MQTT_PACKET_TYPES {
CONNECT = 1,
CONNACK = 2,
PUBLISH = 3,
PUBACK = 4,
PUBREC = 5,
PUBREL = 6,
PUBCOMP = 7,
SUBSCRIBE = 8,
SUBACK = 9,
UNSUBSCRIBE = 10,
UNSUBACK = 11,
PINGREQ = 12,
PINGRESP = 13,
DISCONNECT = 14
};
/**
* Entry point when protocol is identified.
*/
static void ndpi_int_mqtt_add_connection (struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
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");
}
/**
* Dissector function that searches Mqtt headers
*/
void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt search called...\n");
struct ndpi_packet_struct *packet = &flow->packet;
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
return;
}
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt detection...\n");
if (flow->packet_counter > 10) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. mandatory header not found!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "====>>>> 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);
if (packet->payload_packet_len < 2) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. mandatory header not found!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
if (packet->payload_packet_len > 258) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. maximum packet size exceeded!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
// we extract the remaining length
u_int8_t rl = (u_int8_t) (packet->payload[1]);
if (packet->payload_packet_len != (rl + 2)) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. packet size exceeded!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
// we extract the packet type
u_int8_t 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);
if ((pt == 0) || (pt == 15)) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt .. invalid packet type!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
// we extract the flags
u_int8_t flags = (u_int8_t) (packet->payload[0] & 0x0F);
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Mqtt flags type: [%d]\n",flags);
// first stage verification
if (((pt == CONNECT) || (pt == CONNACK) || (pt == PUBACK) || (pt == PUBREC) ||
(pt == PUBCOMP) || (pt == SUBACK) || (pt == UNSUBACK) || (pt == PINGREQ) ||
(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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed first stage of identification\n");
// second stage verification (no payload, just variable headers)
if ((pt == CONNACK) || (pt == PUBACK) || (pt == PUBREL) ||
(pt == PUBREC) || (pt == PUBCOMP) || (pt == UNSUBACK)) {
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
} else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found CONNACK/PUBACK/PUBREL/PUBREC/PUBCOMP/UNSUBACK\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
}
}
if ((pt == PINGREQ) || (pt == PINGRESP) || (pt == DISCONNECT)) {
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
} else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found PING/PINGRESP/DISCONNECT\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
}
}
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed second stage of identification\n");
// third stage verification (payload)
if (pt == CONNECT) {
if (memcmp(&(packet->payload[4]),"MQTT",4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found CONNECT\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
} else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid CONNECT\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
}
if (pt == PUBLISH) {
// payload CAN be zero bytes length (section 3.3.3 of MQTT standard)
u_int8_t qos = (u_int8_t) (flags & 0x06);
u_int8_t retain = (u_int8_t) (flags & 0x01);
u_int8_t dup = (u_int8_t) (flags & 0x04);
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
if (qos == 0) {
if (dup != 0) {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Excluding Mqtt invalid PUBLISH qos0 and dup combination\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
}
if ((qos == 1) || (qos == 2)) {
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
}
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found PUBLISH\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
}
if (pt == SUBSCRIBE) {
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
} else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found SUBSCRIBE\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
}
}
if (pt == SUBACK ) {
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
} else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found SUBACK\n");
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
}
}
if (pt == UNSUBSCRIBE) {
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_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
} else {
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Mqtt found UNSUBSCRIBE\n",pt);
ndpi_int_mqtt_add_connection(ndpi_struct,flow);
return;
}
}
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG,"====>>>> Passed third stage of identification");
NDPI_LOG(NDPI_PROTOCOL_MQTT, ndpi_struct, NDPI_LOG_DEBUG, "Reached the end excluding Mqtt ...\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
return;
}
/**
* Entry point for the ndpi library
*/
void init_mqtt_dissector (struct ndpi_detection_module_struct *ndpi_struct,
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_PROTOCOL_MQTT,
ndpi_search_mqtt,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, ADD_TO_DETECTION_BITMASK);
*id +=1;
}
#endif // NDPI_PROTOCOL_MQTT
+6 -6
View File
@@ -130,7 +130,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
if (get_u_int8_t(packet->payload, packet->payload_packet_len - 2) == 0x0d
&& get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x0a) {
/* The MSNP string is used in XBOX clients. */
if (ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "VER ")) {
if (memcmp(packet->payload, "VER ", 4) == 0) {
if (memcmp(&packet->payload[packet->payload_packet_len - 6], "CVR",
3) == 0 || memcmp(&packet->payload[packet->payload_packet_len - 8], "MSNP", 4) == 0) {
@@ -139,7 +139,7 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
if (ndpi_match_strprefix(&packet->payload[4], packet->payload_packet_len-4, "MSNFT")) {
if (memcmp(&packet->payload[4], "MSNFT", 5) == 0) {
NDPI_LOG(NDPI_PROTOCOL_MSN, ndpi_struct, NDPI_LOG_TRACE,
"found MSN FT by pattern VER MSNFT...0d0a.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
@@ -153,8 +153,8 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
#ifdef NDPI_PROTOCOL_HTTP
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
#endif
ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "GET ") ||
ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "POST ")) {
memcmp(packet->payload, "GET ", NDPI_STATICSTRING_LEN("GET ")) == 0 ||
memcmp(packet->payload, "POST ", NDPI_STATICSTRING_LEN("POST ")) == 0) {
ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->user_agent_line.ptr != NULL &&
packet->user_agent_line.len > NDPI_STATICSTRING_LEN("Messenger/") &&
@@ -277,8 +277,8 @@ static void ndpi_search_msn_tcp(struct ndpi_detection_module_struct *ndpi_struct
#ifdef NDPI_PROTOCOL_HTTP
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
#endif
ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "HTTP/1.0 200 OK") ||
ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "HTTP/1.1 200 OK")
(memcmp(packet->payload, "HTTP/1.0 200 OK", 15) == 0) ||
(memcmp(packet->payload, "HTTP/1.1 200 OK", 15) == 0)
) {
ndpi_parse_packet_line_info(ndpi_struct, flow);
+7 -7
View File
@@ -29,7 +29,7 @@
/* The function below has been inherited by tcpdump */
static int netbios_name_interpret(char *in, char *out, u_int out_len) {
int ret = 0, len;
int ret, len;
char *b;
len = (*in++)/2;
@@ -42,14 +42,14 @@ static int netbios_name_interpret(char *in, char *out, u_int out_len) {
while (len--) {
if(in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
*out = 0;
break;
return(-1);
}
*out = ((in[0]-'A')<<4) + (in[1]-'A');
in += 2;
out++, ret++;
out++;
}
ret = *(--out);
*out = 0;
/* Courtesy of Roberto F. De Luca <deluca@tandar.cnea.gov.ar> */
@@ -318,13 +318,13 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct, struc
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)) {
char name[64];
char name[32];
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct,
NDPI_LOG_DEBUG, "found netbios with checked ip-address.\n");
if(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);
if(netbios_name_interpret((char*)&packet->payload[14], name, sizeof(name)) > 0)
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name), "%s", name);
ndpi_int_netbios_add_connection(ndpi_struct, flow);
return;
+2
View File
@@ -23,10 +23,12 @@
#ifdef NDPI_PROTOCOL_NETFLOW
#ifndef __KERNEL__
#ifdef WIN32
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
#endif
#define do_gettimeofday(a) gettimeofday(a, NULL)
#endif
struct flow_ver1_rec {
u_int32_t srcaddr; /* Source IP Address */
+36 -26
View File
@@ -22,44 +22,54 @@
*
*/
#include "ndpi_protocols.h"
#ifdef NDPI_PROTOCOL_NTP
static void ndpi_int_ntp_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NTP, NDPI_PROTOCOL_UNKNOWN);
}
/* detection also works asymmetrically */
void ndpi_search_ntp_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if (!(packet->udp->dest == htons(123) || packet->udp->source == htons(123)))
goto exclude_ntp;
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP port detected\n");
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP length detected\n");
if ((((packet->payload[0] & 0x38) >> 3) <= 4)) {
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "detected NTP.");
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->dest == htons(123) || packet->udp->source == htons(123)))
goto exclude_ntp;
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP port detected\n");
// It's not correct because packets could be bigger
//if (packet->payload_packet_len != 48)
// goto exclude_ntp;
NDPI_LOG(NDPI_PROTOCOL_NTP, ndpi_struct, NDPI_LOG_DEBUG, "NTP length detected\n");
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
flow->protos.ntp.version = (packet->payload[0] & 0x38) >> 3;
if (flow->protos.ntp.version == 2) {
flow->protos.ntp.request_code = packet->payload[3];
}
ndpi_int_ntp_add_connection(ndpi_struct, flow);
return;
}
exclude_ntp:
// 38 in binary representation is 00111000
flow->protos.ntp.version = (packet->payload[0] & 0x38) >> 3;
if (flow->protos.ntp.version == 2) {
flow->protos.ntp.request_code = packet->payload[3];
}
ndpi_int_ntp_add_connection(ndpi_struct, flow);
return;
}
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);
}
+14 -23
View File
@@ -30,7 +30,7 @@
/* Flap channels */
#define SIGNON 0x01
#define DATA 0x02
#define O_ERROR 0x03
#define ERROR 0x03
#define SIGNOFF 0x04
#define KEEP_ALIVE 0x05
@@ -101,7 +101,7 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
{
int excluded = 0;
// u_int8_t channel;
u_int8_t channel;
u_int16_t family;
u_int16_t type;
u_int16_t flag;
@@ -245,10 +245,9 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
if (channel == DATA)
{
family = get_u_int16_t(packet->payload, 6);
if (packet->payload_packet_len >= 10)
type = get_u_int16_t(packet->payload, 8);
else
type = 0;
type = get_u_int16_t(packet->payload, 8);
flag = get_u_int16_t(packet->payload, 10);
req_ID = get_u_int32_t(packet->payload, 12);
/* Family 0x0001 */
if (family == htons(GE_SE_CTL))
@@ -562,30 +561,22 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
}
/* flag */
if (packet->payload_packet_len >= 12)
{
flag = get_u_int16_t(packet->payload, 10);
if (flag == htons(0x0000)|| flag == htons(0x8000) || flag == htons(0x0001))
{
if (packet->payload_packet_len >= 16)
if (flag == htons(0x0000)|| flag == htons(0x8000) || flag == htons(0x0001))
{
/* request ID */
if((req_ID <= 4294967295))
{
/* request ID */
req_ID = get_u_int32_t(packet->payload, 12);
if((req_ID <= 4294967295))
{
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
}
}
}
/*
ERROR -> FLAP__ERROR_CHANNEL_0x03
A FLAP error - rare
*/
if (channel == O_ERROR)
if (channel == ERROR)
{
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected - Error frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
+5 -5
View File
@@ -34,7 +34,7 @@ static void ndpi_check_pando_tcp(struct ndpi_detection_module_struct *ndpi_struc
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
if (ndpi_match_strprefix(packet->payload, payload_len, "\x0ePan")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\x0ePan")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
}
@@ -56,7 +56,7 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "UDPA")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "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. */
@@ -64,7 +64,7 @@ static void ndpi_check_pando_udp(struct ndpi_detection_module_struct *ndpi_struc
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE")) {
if ((payload_len > 0) && (match_first_bytes(packet->payload, "UDPR") || match_first_bytes(packet->payload, "UDPE"))) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "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. */
@@ -98,7 +98,7 @@ 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. */
if ((payload_len == 0) || (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE"))) {
if ((payload_len == 0) || match_first_bytes(packet->payload, "UDPR") || match_first_bytes(packet->payload, "UDPE")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
} else {
@@ -115,7 +115,7 @@ 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. */
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "UDPA")) {
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
} else {
+7 -7
View File
@@ -39,7 +39,7 @@ static void ndpi_check_pplive_udp1(struct ndpi_detection_module_struct *ndpi_str
if (flow->pplive_stage1 == 0) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "PPLIVE stage 0: \n");
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\xe9\x03\x41\x01")) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Possible PPLIVE 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. */
@@ -47,7 +47,7 @@ static void ndpi_check_pplive_udp1(struct ndpi_detection_module_struct *ndpi_str
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x42\x01")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\xe9\x03\x42\x01")) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Possible PPLIVE 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. */
@@ -55,7 +55,7 @@ static void ndpi_check_pplive_udp1(struct ndpi_detection_module_struct *ndpi_str
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "\x1c\x1c\x32\x01")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\x1c\x1c\x32\x01")) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Possible PPLIVE 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. */
@@ -72,7 +72,7 @@ static void ndpi_check_pplive_udp1(struct ndpi_detection_module_struct *ndpi_str
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x42\x01") || ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
if ((payload_len > 0) && (match_first_bytes(packet->payload, "\xe9\x03\x42\x01") || match_first_bytes(packet->payload, "\xe9\x03\x41\x01"))) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Found PPLIVE.\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
@@ -89,7 +89,7 @@ static void ndpi_check_pplive_udp1(struct ndpi_detection_module_struct *ndpi_str
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\xe9\x03\x41\x01")) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Found PPLIVE.\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
@@ -105,7 +105,7 @@ static void ndpi_check_pplive_udp1(struct ndpi_detection_module_struct *ndpi_str
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\x1c\x1c\x32\x01")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\x1c\x1c\x32\x01")) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Found PPLIVE.\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
@@ -124,7 +124,7 @@ static void ndpi_check_pplive_udp2(struct ndpi_detection_module_struct *ndpi_str
if (flow->pplive_stage2 == 0) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "PPLIVE stage 0: \n");
if ((payload_len == 57) && ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
if ((payload_len == 57) && match_first_bytes(packet->payload, "\xe9\x03\x41\x01")) {
NDPI_LOG(NDPI_PROTOCOL_PPLIVE, ndpi_struct, NDPI_LOG_DEBUG, "Possible PPLIVE 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. */
+5 -5
View File
@@ -238,9 +238,9 @@ static void ndpi_search_qq_udp(struct ndpi_detection_module_struct *ndpi_struct,
{
struct ndpi_packet_struct *packet = &flow->packet;
static const u_int16_t p8000_patt_02[13] = // maybe version numbers
{ 0x1549, 0x1801, 0x180d, 0x0961, 0x01501, 0x0e35, 0x113f, 0x0b37, 0x1131, 0x163a, 0x1e0d, 0x3619,};
u_int16_t no_of_patterns = 12, index = 0;
static const u_int16_t p8000_patt_02[12] = // maybe version numbers
{ 0x1549, 0x1801, 0x180d, 0x0961, 0x01501, 0x0e35, 0x113f, 0x0b37, 0x1131, 0x163a, 0x1e0d };
u_int16_t no_of_patterns = 11, index = 0;
NDPI_LOG(NDPI_PROTOCOL_QQ, ndpi_struct, NDPI_LOG_DEBUG, "search qq udp.\n");
@@ -668,8 +668,8 @@ void init_qq_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32
ndpi_set_bitmask_protocol_detection("QQ", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_QQ,
ndpi_search_qq,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD,
NO_SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
+139 -97
View File
@@ -1,12 +1,11 @@
/*
* quic.c
*
* Copyright (C) 2012-16 - ntop.org
*
* Based on code of:
* Andrea Buscarinu - <andrea.buscarinu@gmail.com>
* Michele Campus - <campus@ntop.org>
*
* Copyright (C) 2012-15 - ntop.org
*
* This module 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
@@ -22,121 +21,164 @@
*
*/
#include "ndpi_api.h"
#define QUIC_NO_V_RES_RSV 0xC3 // 1100 0011
#define QUIC_CID_MASK 0x0C // 0000 1100
#define QUIC_VER_MASK 0x01 // 0000 0001
#define QUIC_SEQ_MASK 0x30 // 0011 0000
#define CID_LEN_8 0x0C // 0000 1100
#define CID_LEN_4 0x08 // 0000 1000
#define CID_LEN_1 0x04 // 0000 0100
#define CID_LEN_0 0x00 // 0000 0000
#define SEQ_LEN_6 0x30 // 0011 0000
#define SEQ_LEN_4 0x20 // 0010 0000
#define SEQ_LEN_2 0x10 // 0001 0000
#define SEQ_LEN_1 0x00 // 0000 0000
#define SEQ_CONV(ARR) (ARR[0] | ARR[1] | ARR[2] | ARR[3] | ARR[4] | ARR[5] << 8)
#ifdef NDPI_PROTOCOL_QUIC
static int quic_ports(u_int16_t sport, u_int16_t dport)
static void ndpi_int_quic_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
if ((sport == 443 || dport == 443 || sport == 80 || dport == 80) &&
(sport != 123 && dport != 123))
return 1;
return 0;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_QUIC, NDPI_PROTOCOL_UNKNOWN);
}
/* ***************************************************************** */
static int connect_id(const unsigned char pflags)
{
u_int cid_len;
static int quic_len(u_int8_t l) {
switch(l) {
case 0:
return(1);
break;
case 1:
return(2);
break;
case 2:
return(4);
break;
case 3:
return(8);
break;
}
// Check CID length.
switch (pflags & QUIC_CID_MASK)
{
case CID_LEN_8: cid_len = 8; break;
case CID_LEN_4: cid_len = 4; break;
case CID_LEN_1: cid_len = 1; break;
case CID_LEN_0: cid_len = 0; break;
default:
return -1;
return(0); /* NOTREACHED */
}
// Return offset.
return cid_len + 1;
}
/* ***************************************************************** */
void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
static int sequence(const unsigned char *payload)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t udp_len = packet->payload_packet_len;
u_int version_len = ((packet->payload[0] & 0x01) == 0) ? 0 : 4;
u_int cid_len = quic_len((packet->payload[0] & 0x0C) >> 2);
u_int seq_len = quic_len((packet->payload[0] & 0x30) >> 4);
u_int quic_hlen = 1 /* flags */ + version_len + seq_len + cid_len;
if(packet->udp != NULL
&& (udp_len > (quic_hlen+4 /* QXXX */))
&& ((packet->payload[0] & 0xC2) == 0x00)
&& (quic_ports(ntohs(packet->udp->source), ntohs(packet->udp->dest)))
) {
char *begin;
unsigned char conv[6] = {0};
u_int seq_value = -1;
int seq_lens;
int cid_offs;
int i;
if((version_len > 0) && (packet->payload[1+cid_len] != 'Q'))
goto no_quic;
// Search SEQ bytes length.
switch (payload[0] & QUIC_SEQ_MASK)
{
case SEQ_LEN_6: seq_lens = 6; break;
case SEQ_LEN_4: seq_lens = 4; break;
case SEQ_LEN_2: seq_lens = 2; break;
case SEQ_LEN_1: seq_lens = 1; break;
default:
return -1;
}
// Retrieve SEQ offset.
cid_offs = connect_id(payload[0]);
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "found QUIC.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_QUIC, NDPI_PROTOCOL_UNKNOWN);
if (cid_offs >= 0 && seq_lens > 0)
{
for (i = 0; i < seq_lens; i++)
conv[i] = payload[cid_offs + i];
if(!strncmp((char*)&packet->payload[quic_hlen+17], "CHLO" /* Client Hello */, 4)) {
/* Check if SNI (Server Name Identification) is present */
for(i=quic_hlen+12; i<udp_len-3; i++) {
if((packet->payload[i] == 'S')
&& (packet->payload[i+1] == 'N')
&& (packet->payload[i+2] == 'I')
&& (packet->payload[i+3] == 0)) {
u_int32_t offset = *((u_int32_t*)&packet->payload[i+4]);
u_int32_t prev_offset = *((u_int32_t*)&packet->payload[i-4]);
int len = offset-prev_offset;
int sni_offset = i+prev_offset+1;
seq_value = SEQ_CONV(conv);
}
while((packet->payload[sni_offset] == '-') && (sni_offset < udp_len))
sni_offset++;
if((sni_offset+len) < udp_len) {
int max_len = sizeof(flow->host_server_name)-1, j = 0;
if(len > max_len) len = max_len;
while((len > 0) && (sni_offset < udp_len)) {
flow->host_server_name[j++] = packet->payload[sni_offset];
sni_offset++, len--;
}
ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
NDPI_PROTOCOL_QUIC);
}
break;
}
}
}
return;
}
no_quic:
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "exclude QUIC.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_QUIC);
// Return SEQ dec value;
return seq_value;
}
/* ***************************************************************** */
void init_quic_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_bitmask_protocol_detection("QUIC", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_QUIC, ndpi_search_quic,
struct ndpi_packet_struct *packet = &flow->packet;
int ver_offs;
if(packet->udp != NULL) {
u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "calculating quic over udp.\n");
if((((sport == 80) || (dport == 80) || (sport == 443) || (dport == 443))))
{
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "exclude quic.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_QUIC);
// Settings without version. First check if PUBLIC FLAGS & SEQ bytes are 0x0. SEQ must be 1 at least.
if ((packet->payload[0] == 0x00 && packet->payload[1] != 0x00) || ((packet->payload[0] & QUIC_NO_V_RES_RSV) == 0))
{
if (sequence(packet->payload) < 1)
{
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "exclude quic.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_QUIC);
}
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "found quic.\n");
ndpi_int_quic_add_connection(ndpi_struct, flow);
}
// Check if version, than the CID length.
else if (packet->payload[0] & QUIC_VER_MASK)
{
// Skip CID length.
ver_offs = connect_id(packet->payload[0]);
if (ver_offs >= 0)
{
unsigned char vers[] = {packet->payload[ver_offs], packet->payload[ver_offs + 1],
packet->payload[ver_offs + 2], packet->payload[ver_offs + 3]};
// Version Match.
if ((vers[0] == 'Q' && vers[1] == '0') &&
((vers[2] == '2' && (vers[3] == '5' || vers[3] == '4' || vers[3] == '3' || vers[3] == '2' ||
vers[3] == '1' || vers[3] == '0')) ||
(vers[2] == '1' && (vers[3] == '9' || vers[3] == '8' || vers[3] == '7' || vers[3] == '6' ||
vers[3] == '5' || vers[3] == '4' || vers[3] == '3' || vers[3] == '2' ||
vers[3] == '1' || vers[3] == '0')) ||
(vers[2] == '0' && vers[3] == '9')))
{
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "found quic.\n");
ndpi_int_quic_add_connection(ndpi_struct, flow);
}
}
}
}
else
{
NDPI_LOG(NDPI_PROTOCOL_QUIC, ndpi_struct, NDPI_LOG_DEBUG, "exclude quic.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_QUIC);
}
}
}
void init_quic_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Quic", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_QUIC,
ndpi_search_quic,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, ADD_TO_DETECTION_BITMASK);
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif /* NDPI_PROTOCOL_QUIC */
#endif
+10 -1
View File
@@ -35,13 +35,22 @@ static void ndpi_check_radius(struct ndpi_detection_module_struct *ndpi_struct,
// const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len;
#if 0
printf("[len=%u][%02X %02X %02X %02X]\n", payload_len,
packet->payload[0] & 0xFF,
packet->payload[1] & 0xFF,
packet->payload[2] & 0xFF,
packet->payload[3] & 0xFF);
#endif
if(packet->udp != NULL) {
struct radius_header *h = (struct radius_header*)packet->payload;
u_int len = ntohs(h->len);
if((payload_len > sizeof(struct radius_header))
&& (h->code > 0)
&& (h->code <= 5)
&& (ntohs(h->len) == payload_len)) {
&& (len == payload_len)) {
NDPI_LOG(NDPI_PROTOCOL_RADIUS, ndpi_struct, NDPI_LOG_DEBUG, "Found radius.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RADIUS, NDPI_PROTOCOL_UNKNOWN);
+4 -4
View File
@@ -38,7 +38,7 @@ void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct, struct n
/* Let's check first the RTCP packet length */
u_int16_t len, offset = 0, rtcp_section_len;
while(offset + 3 < packet->payload_packet_len) {
while(offset < packet->payload_packet_len) {
len = packet->payload[2+offset] * 256 + packet->payload[2+offset+1];
rtcp_section_len = (len + 1) * 4;
@@ -48,11 +48,11 @@ void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct, struct n
offset += rtcp_section_len;
}
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "calculating dport over udp.\n");
/* TODO changed a pair of length condition to the && from ||. Is it correct? */
if(((packet->payload_packet_len >= 28 && packet->payload_packet_len <= 1200) &&
if(((packet->payload_packet_len >= 28 || packet->payload_packet_len <= 1200) &&
((packet->payload[0] == 0x80) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9)) && (packet->payload[2] == 0x00)))
|| (packet->payload_packet_len >= 3 && ((packet->payload[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
|| (((packet->payload[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
&& (packet->payload[2] == 0x00)))) {
NDPI_LOG(NDPI_PROTOCOL_RTCP, ndpi_struct, NDPI_LOG_DEBUG, "found rtcp.\n");
ndpi_int_rtcp_add_connection(ndpi_struct, flow);
+9 -67
View File
@@ -27,86 +27,28 @@
#ifdef NDPI_PROTOCOL_RTP
/* http://www.myskypelab.com/2014/05/microsoft-lync-wireshark-plugin.html */
static u_int8_t isValidMSRTPType(u_int8_t payloadType) {
switch(payloadType) {
case 0: /* G.711 u-Law */
case 3: /* GSM 6.10 */
case 4: /* G.723.1 */
case 8: /* G.711 A-Law */
case 9: /* G.722 */
case 13: /* Comfort Noise */
case 96: /* Dynamic RTP */
case 97: /* Redundant Audio Data Payload */
case 101: /* DTMF */
case 103: /* SILK Narrowband */
case 104: /* SILK Wideband */
case 111: /* Siren */
case 112: /* G.722.1 */
case 114: /* RT Audio Wideband */
case 115: /* RT Audio Narrowband */
case 116: /* G.726 */
case 117: /* G.722 */
case 118: /* Comfort Noise Wideband */
case 34: /* H.263 [MS-H26XPF] */
case 121: /* RT Video */
case 122: /* H.264 [MS-H264PF] */
case 123: /* H.264 FEC [MS-H264PF] */
case 127: /* x-data */
return(1 /* RTP */);
break;
case 200: /* RTCP PACKET SENDER */
case 201: /* RTCP PACKET RECEIVER */
case 202: /* RTCP Source Description */
case 203: /* RTCP Bye */
return(2 /* RTCP */);
break;
default:
return(0);
}
}
static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const u_int8_t * payload, const u_int16_t payload_len)
{
if (payload_len < 2)
return;
//struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t payloadType, payload_type = payload[1] & 0x7F;
u_int8_t payload_type = payload[1] & 0x7F;
u_int32_t *ssid = (u_int32_t*)&payload[8];
/* Check whether this is an RTP flow */
if((payload_len >= 12)
&& (((payload[0] & 0xFF) == 0x80) || ((payload[0] & 0xFF) == 0xA0)) /* RTP magic byte[1] */
&& ((payload[0] & 0xFF) == 0x80) /* RTP magic byte[1] */
&& ((payload_type < 72) || (payload_type > 76))
&& ((payload_type <= 34)
|| ((payload_type >= 96) && (payload_type <= 127))
/* http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml */
)
&& (*ssid != 0)
&& (payload_type < 128 /* http://anonsvn.wireshark.org/wireshark/trunk/epan/dissectors/packet-rtp.c */)
&& (*ssid != 0)
) {
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "Found RTP.\n");
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "Found rtp.\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RTP, NDPI_PROTOCOL_UNKNOWN);
return;
} else if((payload_len >= 12)
&& (((payload[0] & 0xFF) == 0x80) || ((payload[0] & 0xFF) == 0xA0)) /* RTP magic byte[1] */
&& (payloadType = isValidMSRTPType(payload[1] & 0xFF))) {
if(payloadType == 1 /* RTP */) {
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "Found MS Lync\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MS_LYNC, NDPI_PROTOCOL_UNKNOWN);
} else /* RTCP */ {
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "Found MS RTCP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RTCP, NDPI_PROTOCOL_UNKNOWN);
}
}
/* No luck this time */
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "exclude rtp.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RTP);
} else {
NDPI_LOG(NDPI_PROTOCOL_RTP, ndpi_struct, NDPI_LOG_DEBUG, "exclude rtp.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RTP);
}
}
void ndpi_search_rtp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-234
View File
@@ -1,234 +0,0 @@
/*
* rx.c
*
* Copyright (C) 2012-16 - ntop.org
*
* Giovanni Mascellani <gio@debian.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_api.h"
#ifdef NDPI_PROTOCOL_RX
/* See http://web.mit.edu/kolya/afs/rx/rx-spec for procotol description. */
/* The should be no need for explicit packing, but just in case... */
PACK_ON
struct ndpi_rx_header {
u_int32_t conn_epoch;
u_int32_t conn_id;
u_int32_t call_number;
u_int32_t sequence_number;
u_int32_t serial_number;
u_int8_t type;
u_int8_t flags;
u_int8_t status;
u_int8_t security;
u_int16_t checksum;
u_int16_t service_id;
} PACK_OFF;
/* Type values */
#define DATA 1
#define ACK 2
#define BUSY 3
#define ABORT 4
#define ACKALL 5
#define CHALLENGE 6
#define RESPONSE 7
#define DEBUG 8
#define PARAM_1 9
#define PARAM_2 10
#define PARAM_3 11
#define PARAMS_4 12
#define VERSION 13
/* Flags values */
#define EMPTY 0
#define CLIENT_INIT_1 1
#define REQ_ACK 2
#define PLUS_0 3
#define LAST_PKT 4
#define PLUS_1 5
#define PLUS_2 6
#define MORE_1 9
#define CLIENT_INIT_2 33
void ndpi_check_rx(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
int found = 0;
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "RX: pck: %d, dir[0]: %d, dir[1]: %d\n",
flow->packet_counter, flow->packet_direction_counter[0], flow->packet_direction_counter[1]);
/* Check that packet is long enough */
if (payload_len < sizeof(struct ndpi_rx_header)) {
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
}
struct ndpi_rx_header *header = (struct ndpi_rx_header*) packet->payload;
/**
* Useless check: a session could be detected also after it starts
* and this check limit the correct detection for -d option (disable guess)
* TODO - maybe to improve
**/
/* Check whether the packet has counters beginning from one; the
Sequence Number can be zero if the packet is just an ACK. */
/* if ((ntohl(header->sequence_number) | 1) != 1 || ntohl(header->serial_number) != 1) */
/**
* Check the TYPE and FLAGS fields of an RX packet header.
* This check is necessary because we could detect an RX session already begun
**/
/* TYPE field */
if((header->type < DATA) || (header->type > VERSION)) {
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
}
/* FLAGS fields */
if(header->flags == EMPTY || header->flags == LAST_PKT ||
header->flags == PLUS_0 || header->flags == PLUS_1 ||
header->flags == PLUS_2 || header->flags == REQ_ACK ||
header->flags == MORE_1 || header->flags == CLIENT_INIT_1 ||
header->flags == CLIENT_INIT_2) {
/* TYPE and FLAGS combo */
switch(header->type)
{
case DATA:
if(header->flags == LAST_PKT || header->flags == EMPTY ||
header->flags == PLUS_0 || header->flags == PLUS_1 ||
header->flags == PLUS_2 || header->flags == REQ_ACK ||
header->flags == MORE_1)
goto security;
case ACK:
if(header->flags == CLIENT_INIT_1 || header->flags == CLIENT_INIT_2 ||
header->flags == EMPTY)
goto security;
case CHALLENGE:
if(header->flags == EMPTY || header->call_number == 0)
goto security;
case RESPONSE:
if(header->flags == EMPTY || header->call_number == 0)
goto security;
case ACKALL:
if(header->flags == EMPTY)
goto security;
case BUSY:
goto security;
case ABORT:
goto security;
case DEBUG:
goto security;
case PARAM_1:
goto security;
case PARAM_2:
goto security;
case PARAM_3:
goto security;
case VERSION:
goto security;
default:
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
} // switch
} else { // FLAG
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
}
security:
/* SECURITY field */
if(header->security > 3)
{
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
}
/* If we have already seen one packet in the other direction, then
the two must have matching connection numbers. Otherwise store
them. */
if(flow->packet_direction_counter[!packet->packet_direction] != 0)
{
if (flow->l4.udp.rx_conn_epoch == header->conn_epoch &&
flow->l4.udp.rx_conn_id == header->conn_id)
{
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "found RX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RX, NDPI_PROTOCOL_UNKNOWN);
}
/* https://www.central.org/frameless/numbers/rxservice.html. */
else
{
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "excluding RX\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_RX);
return;
}
} else {
flow->l4.udp.rx_conn_epoch = header->conn_epoch;
flow->l4.udp.rx_conn_id = header->conn_id;
{
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "found RX\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RX, NDPI_PROTOCOL_UNKNOWN);
}
}
}
void ndpi_search_rx(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_RX, ndpi_struct, NDPI_LOG_DEBUG, "entering RX search\n");
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_RX) {
ndpi_check_rx(ndpi_struct, flow);
}
}
void init_rx_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("RX", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_RX,
ndpi_search_rx,
NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+5 -5
View File
@@ -19,7 +19,7 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
@@ -31,7 +31,7 @@ static void ndpi_int_sip_add_connection(struct ndpi_detection_module_struct *ndp
u_int8_t due_to_correlation) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SIP, NDPI_PROTOCOL_UNKNOWN);
}
#if !defined(WIN32)
static inline
#else
@@ -41,7 +41,7 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
const u_int8_t *packet_payload = packet->payload;
@@ -92,7 +92,7 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
* maybe it could be deleted, if somebody sees it in the first direction,
* please delete this comment.
*/
/*
if (memcmp(packet_payload, "SIP/2.0 200 OK", 14) == 0 || memcmp(packet_payload, "sip/2.0 200 OK", 14) == 0) {
NDPI_LOG(NDPI_PROTOCOL_SIP, ndpi_struct, NDPI_LOG_DEBUG, "found sip SIP/2.0 0K.\n");
@@ -121,7 +121,7 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
}
if ((memcmp(packet_payload, "CANCEL ", 7) == 0 || memcmp(packet_payload, "cancel ", 7) == 0)
&& (memcmp(&packet_payload[4], "SIP:", 4) == 0 || memcmp(&packet_payload[4], "sip:", 4) == 0)) {
&& (memcmp(&packet_payload[4], "SIP:", 7) == 0 || memcmp(&packet_payload[4], "sip:", 7) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_SIP, ndpi_struct, NDPI_LOG_DEBUG, "found sip CANCEL.\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0);
return;
-3
View File
@@ -55,9 +55,6 @@ static void ndpi_check_skype(struct ndpi_detection_module_struct *ndpi_struct, s
// const u_int8_t *packet_payload = packet->payload;
u_int32_t payload_len = packet->payload_packet_len;
if(flow->host_server_name[0] != '\0')
return;
/*
Skype AS8220
212.161.8.0/24
+96
View File
@@ -0,0 +1,96 @@
/*
* socks4.c
*
* Copyright (C) 2014 Tomasz Bujlow <tomasz@skatnet.dk>
*
* The signature is based on the Libprotoident library.
*
* 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_api.h"
#ifdef NDPI_PROTOCOL_SOCKS4
static void ndpi_int_socks4_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SOCKS4, NDPI_PROTOCOL_UNKNOWN);
}
static void ndpi_check_socks4(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
/* Break after 20 packets. */
if (flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "Exclude SOCKS4.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOCKS4);
return;
}
/* Check if we so far detected the protocol in the request or not. */
if (flow->socks4_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS4 stage 0: \n");
/*Octets 3 and 4 contain the port number, port 80 and 25 for now. */
if ((payload_len == 9) &&
(((packet->payload[0] == 0x04) && (packet->payload[1] == 0x01) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x50))
||
((packet->payload[0] == 0x04) && (packet->payload[1] == 0x01) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x19)))) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "Possible SOCKS4 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. */
flow->socks4_stage = packet->packet_direction + 1;
}
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS4 stage %u: \n", flow->socks4_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->socks4_stage - packet->packet_direction) == 1) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if (payload_len == 0) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "Found SOCKS4.\n");
ndpi_int_socks4_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to SOCKS4, resetting the stage to 0...\n");
flow->socks4_stage = 0;
}
}
}
void ndpi_search_socks4(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_SOCKS4, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS4 detection...\n");
/* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS4) {
if (packet->tcp_retransmission == 0) {
ndpi_check_socks4(ndpi_struct, flow);
}
}
}
#endif
-155
View File
@@ -1,155 +0,0 @@
/*
* socks4.c
*
* Copyright (C) 2016 - ntop.org
* Copyright (C) 2014 Tomasz Bujlow <tomasz@skatnet.dk>
*
* The signature is based on the Libprotoident library.
*
* 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_api.h"
#ifdef NDPI_PROTOCOL_SOCKS
static void ndpi_int_socks_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SOCKS, NDPI_PROTOCOL_UNKNOWN);
}
static void ndpi_check_socks4(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
/* Break after 20 packets. */
if(flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "Exclude SOCKS4.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOCKS);
return;
}
/* Check if we so far detected the protocol in the request or not. */
if(flow->socks4_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS4 stage 0: \n");
/*Octets 3 and 4 contain the port number, port 80 and 25 for now. */
if((payload_len == 9) &&
(((packet->payload[0] == 0x04) && (packet->payload[1] == 0x01) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x50))
||
((packet->payload[0] == 0x04) && (packet->payload[1] == 0x01) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x19)))) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "Possible SOCKS4 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. */
flow->socks4_stage = packet->packet_direction + 1;
}
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS4 stage %u: \n", flow->socks4_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if((flow->socks4_stage - packet->packet_direction) == 1) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if(payload_len == 0) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "Found SOCKS4.\n");
ndpi_int_socks_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to SOCKS4, resetting the stage to 0...\n");
flow->socks4_stage = 0;
}
}
}
static void ndpi_check_socks5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
/* Break after 20 packets. */
if(flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "Exclude SOCKS5.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOCKS);
return;
}
/* Check if we so far detected the protocol in the request or not. */
if(flow->socks5_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS5 stage 0: \n");
if((payload_len == 3) && (packet->payload[0] == 0x05) && (packet->payload[1] == 0x01) && (packet->payload[2] == 0x00)) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "Possible SOCKS5 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. */
flow->socks5_stage = packet->packet_direction + 1;
}
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS5 stage %u: \n", flow->socks5_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if((flow->socks5_stage - packet->packet_direction) == 1) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if((payload_len == 0) || ((payload_len == 2) && (packet->payload[0] == 0x05) && (packet->payload[1] == 0x00))) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "Found SOCKS5.\n");
ndpi_int_socks_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to SOCKS5, resetting the stage to 0...\n");
flow->socks5_stage = 0;
}
}
}
void ndpi_search_socks(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_SOCKS, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS detection...\n");
/* skip marked packets */
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS) {
if(packet->tcp_retransmission == 0) {
ndpi_check_socks4(ndpi_struct, flow);
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS)
ndpi_check_socks5(ndpi_struct, flow);
}
}
}
void init_socks_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("SOCKS", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_SOCKS,
ndpi_search_socks,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+92
View File
@@ -0,0 +1,92 @@
/*
* socks5.c
*
* Copyright (C) 2014 Tomasz Bujlow <tomasz@skatnet.dk>
*
* The signature is based on the Libprotoident library.
*
* 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_api.h"
#ifdef NDPI_PROTOCOL_SOCKS5
static void ndpi_int_socks5_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SOCKS5, NDPI_PROTOCOL_UNKNOWN);
}
static void ndpi_check_socks5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
/* Break after 20 packets. */
if (flow->packet_counter > 20) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "Exclude SOCKS5.\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOCKS5);
return;
}
/* Check if we so far detected the protocol in the request or not. */
if (flow->socks5_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS5 stage 0: \n");
if ((payload_len == 3) && (packet->payload[0] == 0x05) && (packet->payload[1] == 0x01) && (packet->payload[2] == 0x00)) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "Possible SOCKS5 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. */
flow->socks5_stage = packet->packet_direction + 1;
}
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS5 stage %u: \n", flow->socks5_stage);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->socks5_stage - packet->packet_direction) == 1) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 0) || ((payload_len == 2) && (packet->payload[0] == 0x05) && (packet->payload[1] == 0x00))) {
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "Found SOCKS5.\n");
ndpi_int_socks5_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "The reply did not seem to belong to SOCKS5, resetting the stage to 0...\n");
flow->socks5_stage = 0;
}
}
}
void ndpi_search_socks5(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_SOCKS5, ndpi_struct, NDPI_LOG_DEBUG, "SOCKS5 detection...\n");
/* skip marked packets */
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_SOCKS5) {
if (packet->tcp_retransmission == 0) {
ndpi_check_socks5(ndpi_struct, flow);
}
}
}
#endif
+1 -1
View File
@@ -54,7 +54,7 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
}
} else if(packet->tcp != NULL) {
if(payload_len >= 8 && packet->payload[0] == 0x00 && packet->payload[1] == 0x04 &&
if(packet->payload[0] == 0x00 && packet->payload[1] == 0x04 &&
packet->payload[2] == 0x00 && packet->payload[3] == 0x00&&
packet->payload[6] == 0x52 && packet->payload[7] == 0x0e &&
packet->payload[8] == 0x50 ) {
+63 -72
View File
@@ -92,12 +92,11 @@ static void ndpi_int_ssl_add_connection(struct ndpi_detection_module_struct *ndp
((ch) >= '{' && (ch) <= '~'))
static void stripCertificateTrailer(char *buffer, int buffer_len) {
int i, is_puny;
int i;
// printf("->%s<-\n", buffer);
for(i = 0; i < buffer_len; i++) {
for(i=0; i<buffer_len; i++) {
// printf("%c [%d]\n", buffer[i], buffer[i]);
if((buffer[i] != '.')
@@ -111,28 +110,21 @@ static void stripCertificateTrailer(char *buffer, int buffer_len) {
}
}
/* check for punycode encoding */
is_puny = check_punycode_string(buffer, buffer_len);
// not a punycode string - need more checks
if(is_puny == 0) {
if(i > 0) i--;
while(i > 0) {
if(!ndpi_isalpha(buffer[i])) {
buffer[i] = '\0';
buffer_len = i;
i--;
} else
break;
}
for(i = buffer_len; i > 0; i--) {
if(buffer[i] == '.') break;
else if(ndpi_isdigit(buffer[i]))
buffer[i] = '\0', buffer_len = i;
}
if(i > 0) i--;
while(i > 0) {
if(!ndpi_isalpha(buffer[i])) {
buffer[i] = '\0';
buffer_len = i;
i--;
} else
break;
}
for(i=buffer_len; i>0; i--) {
if(buffer[i] == '.') break;
else if(ndpi_isdigit(buffer[i]))
buffer[i] = '\0', buffer_len = i;
}
}
@@ -223,67 +215,64 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
}
} else if(handshake_protocol == 0x01 /* Client Hello */) {
u_int offset, base_offset = 43;
if (base_offset + 2 <= packet->payload_packet_len)
{
u_int16_t session_id_len = packet->payload[base_offset];
u_int16_t session_id_len = packet->payload[base_offset];
if((session_id_len+base_offset+2) <= total_len) {
u_int16_t cypher_len = packet->payload[session_id_len+base_offset+2] + (packet->payload[session_id_len+base_offset+1] << 8);
offset = base_offset + session_id_len + cypher_len + 2;
if((session_id_len+base_offset+2) <= total_len) {
u_int16_t cypher_len = packet->payload[session_id_len+base_offset+2] + (packet->payload[session_id_len+base_offset+1] << 8);
offset = base_offset + session_id_len + cypher_len + 2;
flow->l4.tcp.ssl_seen_client_cert = 1;
flow->l4.tcp.ssl_seen_client_cert = 1;
if(offset < total_len) {
u_int16_t compression_len;
u_int16_t extensions_len;
compression_len = packet->payload[offset+1];
offset += compression_len + 3;
if(offset < total_len) {
u_int16_t compression_len;
u_int16_t extensions_len;
extensions_len = packet->payload[offset];
compression_len = packet->payload[offset+1];
offset += compression_len + 3;
if((extensions_len+offset) < total_len) {
u_int16_t extension_offset = 1; /* Move to the first extension */
if(offset < total_len) {
extensions_len = packet->payload[offset];
while(extension_offset < extensions_len) {
u_int16_t extension_id, extension_len;
if((extensions_len+offset) < total_len) {
u_int16_t extension_offset = 1; /* Move to the first extension */
memcpy(&extension_id, &packet->payload[offset+extension_offset], 2);
extension_offset += 2;
while(extension_offset < extensions_len) {
u_int16_t extension_id, extension_len;
memcpy(&extension_len, &packet->payload[offset+extension_offset], 2);
extension_offset += 2;
memcpy(&extension_id, &packet->payload[offset+extension_offset], 2);
extension_offset += 2;
extension_id = ntohs(extension_id), extension_len = ntohs(extension_len);
memcpy(&extension_len, &packet->payload[offset+extension_offset], 2);
extension_offset += 2;
if(extension_id == 0) {
u_int begin = 0,len;
char *server_name = (char*)&packet->payload[offset+extension_offset];
extension_id = ntohs(extension_id), extension_len = ntohs(extension_len);
if(extension_id == 0) {
u_int begin = 0,len;
char *server_name = (char*)&packet->payload[offset+extension_offset];
while(begin < extension_len) {
if((!ndpi_isprint(server_name[begin]))
|| ndpi_ispunct(server_name[begin])
|| ndpi_isspace(server_name[begin]))
begin++;
else
break;
}
len = (u_int)ndpi_min(extension_len-begin, buffer_len-1);
strncpy(buffer, &server_name[begin], len);
buffer[len] = '\0';
stripCertificateTrailer(buffer, buffer_len);
snprintf(flow->protos.ssl.client_certificate,
sizeof(flow->protos.ssl.client_certificate), "%s", buffer);
/* We're happy now */
return(2 /* Client Certificate */);
while(begin < extension_len) {
if((!ndpi_isprint(server_name[begin]))
|| ndpi_ispunct(server_name[begin])
|| ndpi_isspace(server_name[begin]))
begin++;
else
break;
}
extension_offset += extension_len;
len = (u_int)ndpi_min(extension_len-begin, buffer_len-1);
strncpy(buffer, &server_name[begin], len);
buffer[len] = '\0';
stripCertificateTrailer(buffer, buffer_len);
snprintf(flow->protos.ssl.client_certificate,
sizeof(flow->protos.ssl.client_certificate), "%s", buffer);
/* We're happy now */
return(2 /* Client Certificate */);
}
extension_offset += extension_len;
}
}
}
@@ -299,6 +288,8 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
if(!packet->iph /* IPv4 */) return(-1);
if((packet->payload_packet_len > 9)
&& (packet->payload[0] == 0x16 /* consider only specific SSL packets (handshake) */)) {
if((packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)
+3 -2
View File
@@ -49,8 +49,9 @@ u_int8_t ndpi_check_starcraft_tcp(struct ndpi_detection_module_struct* ndpi_stru
{
if (sc2_match_logon_ip(&flow->packet)
&& flow->packet.tcp->dest == htons(1119) //bnetgame port
&& (ndpi_match_strprefix(flow->packet.payload, flow->packet.payload_packet_len, "\x4a\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66")
|| ndpi_match_strprefix(flow->packet.payload, flow->packet.payload_packet_len, "\x49\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66")))
&& flow->packet.payload_packet_len >= 10
&& (match_first_bytes(flow->packet.payload, "\x4a\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66")
|| match_first_bytes(flow->packet.payload, "\x49\x00\x00\x0a\x66\x02\x0a\xed\x2d\x66")))
return 1;
else
return -1;
+11 -12
View File
@@ -34,7 +34,6 @@ static void ndpi_int_steam_add_connection(struct ndpi_detection_module_struct *n
static void ndpi_check_steam_http(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_PARSE_PACKET_LINE_INFO(ndpi_struct, flow, packet);
if (packet->user_agent_line.ptr != NULL
&& packet->user_agent_line.len >= 23
&& memcmp(packet->user_agent_line.ptr, "Valve/Steam HTTP Client", 23) == 0) {
@@ -50,7 +49,7 @@ static void ndpi_check_steam_tcp(struct ndpi_detection_module_struct *ndpi_struc
if (flow->steam_stage == 0) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "STEAM stage 0: \n");
if ((payload_len == 1 && packet->payload[0] == 0x01) || ((payload_len == 4 || payload_len == 5) && ndpi_match_strprefix(packet->payload, payload_len, "\x01\x00\x00\x00"))) {
if (((payload_len == 1) || (payload_len == 4) || (payload_len == 5)) && match_first_bytes(packet->payload, "\x01\x00\x00\x00")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Possible STEAM 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. */
@@ -58,7 +57,7 @@ static void ndpi_check_steam_tcp(struct ndpi_detection_module_struct *ndpi_struc
return;
}
if ((payload_len == 1 && packet->payload[0] == 0x00) || ((payload_len == 4 || payload_len == 5) && ndpi_match_strprefix(packet->payload, payload_len, "\x00\x00\x00"))) {
if (((payload_len == 1) || (payload_len == 4) || (payload_len == 5)) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00)) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Possible STEAM 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. */
@@ -74,7 +73,7 @@ static void ndpi_check_steam_tcp(struct ndpi_detection_module_struct *ndpi_struc
}
/* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 1 && packet->payload[0] == 0x00) || ((payload_len == 4 || payload_len == 5) && ndpi_match_strprefix(packet->payload, payload_len, "\x00\x00\x00"))) {
if (((payload_len == 1) || (payload_len == 4) || (payload_len == 5)) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00)) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
ndpi_int_steam_add_connection(ndpi_struct, flow);
} else {
@@ -90,7 +89,7 @@ static void ndpi_check_steam_tcp(struct ndpi_detection_module_struct *ndpi_struc
}
/* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 1 && packet->payload[0] == 0x01) || ((payload_len == 4 || payload_len == 5) && ndpi_match_strprefix(packet->payload, payload_len, "\x01\x00\x00\x00"))) {
if (((payload_len == 1) || (payload_len == 4) || (payload_len == 5)) && match_first_bytes(packet->payload, "\x01\x00\x00\x00")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
ndpi_int_steam_add_connection(ndpi_struct, flow);
} else {
@@ -104,7 +103,7 @@ static void ndpi_check_steam_udp1(struct ndpi_detection_module_struct *ndpi_stru
struct ndpi_packet_struct *packet = &flow->packet;
u_int32_t payload_len = packet->payload_packet_len;
if (ndpi_match_strprefix(packet->payload, payload_len, "VS01")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "VS01")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
ndpi_int_steam_add_connection(ndpi_struct, flow);
return;
@@ -114,7 +113,7 @@ static void ndpi_check_steam_udp1(struct ndpi_detection_module_struct *ndpi_stru
if (flow->steam_stage1 == 0) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "STEAM stage 0: \n");
if (ndpi_match_strprefix(packet->payload, payload_len, "\x31\xff\x30\x2e")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\x31\xff\x30\x2e")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Possible STEAM 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. */
@@ -122,7 +121,7 @@ static void ndpi_check_steam_udp1(struct ndpi_detection_module_struct *ndpi_stru
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "\xff\xff\xff\xff")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Possible STEAM 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. */
@@ -139,7 +138,7 @@ static void ndpi_check_steam_udp1(struct ndpi_detection_module_struct *ndpi_stru
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\xff\xff\xff\xff")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
ndpi_int_steam_add_connection(ndpi_struct, flow);
} else {
@@ -156,7 +155,7 @@ static void ndpi_check_steam_udp1(struct ndpi_detection_module_struct *ndpi_stru
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\x31\xff\x30\x2e")) {
if ((payload_len > 0) && match_first_bytes(packet->payload, "\x31\xff\x30\x2e")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
ndpi_int_steam_add_connection(ndpi_struct, flow);
} else {
@@ -175,7 +174,7 @@ static void ndpi_check_steam_udp2(struct ndpi_detection_module_struct *ndpi_stru
if (flow->steam_stage2 == 0) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "STEAM stage 0: \n");
if ((payload_len == 25) && ndpi_match_strprefix(packet->payload, payload_len, "\xff\xff\xff\xff")) {
if ((payload_len == 25) && match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Possible STEAM 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. */
@@ -191,7 +190,7 @@ static void ndpi_check_steam_udp2(struct ndpi_detection_module_struct *ndpi_stru
}
/* 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, "\xff\xff\xff\xff")) {
if ((payload_len == 0) || match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
ndpi_int_steam_add_connection(ndpi_struct, flow);
} else {
+16 -65
View File
@@ -27,7 +27,7 @@
#ifdef NDPI_PROTOCOL_STUN
#define MAX_NUM_STUN_PKTS 10
#define MAX_NUM_STUN_PKTS 6
struct stun_packet_header {
@@ -50,18 +50,12 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
struct ndpi_flow_struct *flow,
const u_int8_t * payload,
const u_int16_t payload_length,
u_int8_t *is_whatsapp,
u_int8_t *is_lync) {
u_int8_t *is_whatsapp) {
u_int16_t msg_type, msg_len;
struct stun_packet_header *h = (struct stun_packet_header*)payload;
if(payload_length < sizeof(struct stun_packet_header)) {
if(flow->num_stun_udp_pkts > 0) {
*is_whatsapp = 1;
return NDPI_IS_STUN; /* This is WhatsApp Voice */
} else
return(NDPI_IS_NOT_STUN);
}
if(payload_length < sizeof(struct stun_packet_header))
return(NDPI_IS_NOT_STUN);
if((strncmp((const char*)payload, (const char*)"RSP/", 4) == 0)
&& (strncmp((const char*)&payload[7], (const char*)" STUN_", 6) == 0)) {
@@ -74,51 +68,10 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if((payload[0] != 0x80) && ((msg_len+20) > payload_length))
return(NDPI_IS_NOT_STUN);
/* printf("msg_type=%04X, msg_len=%u\n", msg_type, msg_len); */
if((payload_length == (msg_len+20))
&& ((msg_type <= 0x000b) /* http://www.3cx.com/blog/voip-howto/stun-details/ */)) {
u_int offset = 20;
/*
This can either be the standard RTCP or Ms Lync RTCP that
later will becomg Ms Lync RTP. In this case we need to
be careful before deciding about the protocol before dissecting the packet
*/
&& ((msg_type <= 0x000b) /* http://www.3cx.com/blog/voip-howto/stun-details/ */))
goto udp_stun_found;
while(offset < payload_length) {
u_int16_t attribute = ntohs(*((u_int16_t*)&payload[offset]));
u_int16_t len = ntohs(*((u_int16_t*)&payload[offset+2]));
switch(attribute) {
case 0x8054: /* Candidate Identifier */
if((len == 4)
&& (payload[offset+4] == 0x31)
&& (payload[offset+5] == 0x00)
&& (payload[offset+6] == 0x00)
&& (payload[offset+7] == 0x00)) {
*is_lync = 1;
return(NDPI_IS_STUN);
}
break;
case 0x8070: /* Implementation Version */
if((len == 4)
&& (payload[offset+4] == 0x00)
&& (payload[offset+5] == 0x00)
&& (payload[offset+6] == 0x00)
&& (payload[offset+7] == 0x02)) {
*is_lync = 1;
return(NDPI_IS_STUN);
}
break;
}
offset += len + 4;
}
goto udp_stun_found;
}
#ifdef ORIGINAL_CODE
/*
* token list of message types and attribute types from
@@ -220,7 +173,10 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
#endif
if((flow->num_stun_udp_pkts > 0) && (msg_type <= 0x00FF)) {
if(
((flow->num_stun_udp_pkts > 0) && (msg_type == 0x0800))
|| ((msg_type == 0x0800) && (msg_len == 106))
) {
*is_whatsapp = 1;
return NDPI_IS_STUN; /* This is WhatsApp Voice */
} else
@@ -235,7 +191,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t is_whatsapp = 0, is_lync = 0;
u_int8_t is_whatsapp = 0;
NDPI_LOG(NDPI_PROTOCOL_STUN, ndpi_struct, NDPI_LOG_DEBUG, "search stun.\n");
@@ -249,7 +205,7 @@ void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, struct n
* improved by checking only the STUN packet of given length */
if(ndpi_int_check_stun(ndpi_struct, flow, packet->payload + 2,
packet->payload_packet_len - 2, &is_whatsapp, &is_lync) == NDPI_IS_STUN) {
packet->payload_packet_len - 2, &is_whatsapp) == NDPI_IS_STUN) {
NDPI_LOG(NDPI_PROTOCOL_STUN, ndpi_struct, NDPI_LOG_DEBUG, "found TCP stun.\n");
ndpi_int_stun_add_connection(ndpi_struct, NDPI_PROTOCOL_STUN, flow);
return;
@@ -258,15 +214,10 @@ void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, struct n
}
if(ndpi_int_check_stun(ndpi_struct, flow, packet->payload,
packet->payload_packet_len, &is_whatsapp, &is_lync) == NDPI_IS_STUN) {
if(is_lync) {
NDPI_LOG(NDPI_PROTOCOL_STUN, ndpi_struct, NDPI_LOG_DEBUG, "Found MS Lync\n");
ndpi_int_stun_add_connection(ndpi_struct, NDPI_PROTOCOL_MS_LYNC, flow);
} else {
NDPI_LOG(NDPI_PROTOCOL_STUN, ndpi_struct, NDPI_LOG_DEBUG, "found UDP stun.\n");
ndpi_int_stun_add_connection(ndpi_struct,
is_whatsapp ? NDPI_PROTOCOL_WHATSAPP_VOICE : NDPI_PROTOCOL_STUN, flow);
}
packet->payload_packet_len, &is_whatsapp) == NDPI_IS_STUN) {
NDPI_LOG(NDPI_PROTOCOL_STUN, ndpi_struct, NDPI_LOG_DEBUG, "found UDP stun.\n");
ndpi_int_stun_add_connection(ndpi_struct,
is_whatsapp ? NDPI_PROTOCOL_WHATSAPP_VOICE : NDPI_PROTOCOL_STUN, flow);
return;
}
+3 -7
View File
@@ -30,7 +30,6 @@ u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struc
u_int16_t sport, u_int16_t dport) /* host endianess */
{
u_int16_t rc;
struct in_addr host;
if(protocol == IPPROTO_UDP) {
if((sport == dport) && (sport == 17500)) {
@@ -38,12 +37,9 @@ u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struc
}
}
host.s_addr = htonl(saddr);
if((rc = ndpi_network_ptree_match(ndpi_struct, &host)) != NDPI_PROTOCOL_UNKNOWN)
return (rc);
host.s_addr = htonl(daddr);
return (ndpi_network_ptree_match(ndpi_struct, &host));
if((rc = ndpi_host_ptree_match(ndpi_struct, htonl(saddr))) != NDPI_PROTOCOL_UNKNOWN) return(rc);
return(ndpi_host_ptree_match(ndpi_struct, htonl(daddr)));
}
void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
-2
View File
@@ -29,8 +29,6 @@ void ndpi_search_teredo(struct ndpi_detection_module_struct *ndpi_struct, struct
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->udp
&& packet->iph
&& ((ntohl(packet->iph->daddr) & 0xF0000000) == 0xE0000000 /* A multicast address */)
&& ((ntohs(packet->udp->source) == 3544) || (ntohs(packet->udp->dest) == 3544))
&& (packet->payload_packet_len >= 40 /* IPv6 header */))
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_TEREDO, NDPI_PROTOCOL_UNKNOWN);
+33 -36
View File
@@ -1,7 +1,7 @@
/*
* tor.c
*
* Copyright (C) 2016 ntop.org
* Copyright (C) 2015 ntop.org
* Copyright (C) 2013 Remy Mudingay <mudingay@ill.fr>
*
*/
@@ -19,12 +19,12 @@ static void ndpi_int_tor_add_connection(struct ndpi_detection_module_struct
int ndpi_is_ssl_tor(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, char *certificate) {
int prev_num = 0, numbers_found = 0, num_found = 0, i, len;
int prev_num = 0, numbers_found = 0, num_found = 0, i;
char dummy[48], *dot, *name;
if((certificate == NULL)
|| (strlen(certificate) < 6)
|| (strncmp(certificate, "www.", 4)))
|| strncmp(certificate, "www.", 4))
return(0);
// printf("***** [SSL] %s(): %s\n", __FUNCTION__, certificate);
@@ -37,46 +37,43 @@ int ndpi_is_ssl_tor(struct ndpi_detection_module_struct *ndpi_struct,
if((dot = strrchr(dummy, '.')) == NULL) return(0);
name = &dot[1];
len = strlen(name);
if(len >= 5) {
for(i = 0; name[i+1] != '\0'; i++) {
// printf("***** [SSL] %s(): [%d][%c]", __FUNCTION__, i, name[i]);
if((name[i] >= '0') && (name[i] <= '9')) {
if(prev_num != 1) {
numbers_found++;
for(i = 0; name[i+1] != '\0'; i++) {
if((name[i] >= '0') && (name[i] <= '9')) {
if(numbers_found == 2) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
}
prev_num = 1;
if(prev_num != 1) {
numbers_found++;
if(numbers_found == 2) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
}
} else
prev_num = 0;
if(ndpi_match_bigram(ndpi_struct, &ndpi_struct->impossible_bigrams_automa, &name[i])) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
prev_num = 1;
}
} else
prev_num = 0;
if(ndpi_match_bigram(ndpi_struct, &ndpi_struct->bigrams_automa, &name[i])) {
num_found++;
}
}
if(num_found == 0) {
if(ndpi_match_bigram(ndpi_struct, &ndpi_struct->impossible_bigrams_automa, &name[i])) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
} else {
#ifdef PENDANTIC_TOR_CHECK
if(gethostbyname(certificate) == NULL) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
}
#endif
}
if(ndpi_match_bigram(ndpi_struct, &ndpi_struct->bigrams_automa, &name[i])) {
num_found++;
}
}
if(num_found == 0) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
} else {
#ifndef __KERNEL__
#ifdef PENDANTIC_TOR_CHECK
if(gethostbyname(certificate) == NULL) {
ndpi_int_tor_add_connection(ndpi_struct, flow);
return(1);
}
#endif
#endif
}
return(0);
-63
View File
@@ -1,63 +0,0 @@
/*
* ubntac2.c
*
* Copyright (C) 2015 Thomas Fjellstrom
*
* 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_UBNTAC2
static void ndpi_int_ubntac2_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_UBNTAC2, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_ubntac2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG(NDPI_PROTOCOL_UBNTAC2, ndpi_struct, NDPI_LOG_TRACE, "UBNTAC2 detection... plen:%i %i:%i\n", packet->payload_packet_len, ntohs(packet->udp->source), ntohs(packet->udp->dest));
if (packet->payload_packet_len >= 135 &&
(packet->udp->source == htons(10001) || packet->udp->dest == htons(10001)) &&
memcmp(&(packet->payload[36]), "UBNT", 4) == 0) {
NDPI_LOG(NDPI_PROTOCOL_UBNTAC2, ndpi_struct, NDPI_LOG_DEBUG, "UBNT AirControl 2 request\n");
ndpi_int_ubntac2_add_connection(ndpi_struct, flow);
return;
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_UBNTAC2);
}
void init_ubntac2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("UBNTAC2", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_UBNTAC2,
ndpi_search_ubntac2,
NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+130
View File
@@ -0,0 +1,130 @@
/*
* veohtv.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-15 - 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_api.h"
#ifdef NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV
static void ndpi_int_veohtv_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow/* , ndpi_protocol_type_t protocol_type */)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_veohtv_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
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->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV)
return;
if (flow->l4.tcp.veoh_tv_stage == 1 || flow->l4.tcp.veoh_tv_stage == 2) {
if (packet->packet_direction != flow->setup_packet_direction &&
packet->payload_packet_len > NDPI_STATICSTRING_LEN("HTTP/1.1 20")
&& memcmp(packet->payload, "HTTP/1.1 ", NDPI_STATICSTRING_LEN("HTTP/1.1 ")) == 0 &&
(packet->payload[NDPI_STATICSTRING_LEN("HTTP/1.1 ")] == '2' ||
packet->payload[NDPI_STATICSTRING_LEN("HTTP/1.1 ")] == '3' ||
packet->payload[NDPI_STATICSTRING_LEN("HTTP/1.1 ")] == '4' ||
packet->payload[NDPI_STATICSTRING_LEN("HTTP/1.1 ")] == '5')) {
#ifdef NDPI_CONTENT_FLASH
ndpi_parse_packet_line_info(ndpi_struct, flow);
if (packet->detected_protocol_stack[0] == NDPI_CONTENT_FLASH &&
packet->server_line.ptr != NULL &&
packet->server_line.len > NDPI_STATICSTRING_LEN("Veoh-") &&
memcmp(packet->server_line.ptr, "Veoh-", NDPI_STATICSTRING_LEN("Veoh-")) == 0) {
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV, ndpi_struct, NDPI_LOG_DEBUG, "VeohTV detected.\n");
ndpi_int_veohtv_add_connection(ndpi_struct, flow);
return;
}
#endif
if (flow->l4.tcp.veoh_tv_stage == 2) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask,
NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV);
return;
}
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV, ndpi_struct, NDPI_LOG_DEBUG, "VeohTV detected.\n");
ndpi_int_veohtv_add_connection(ndpi_struct, flow);
return;
} else if (flow->packet_direction_counter[(flow->setup_packet_direction == 1) ? 0 : 1] > 3) {
if (flow->l4.tcp.veoh_tv_stage == 2) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask,
NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV);
return;
}
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV, ndpi_struct, NDPI_LOG_DEBUG, "VeohTV detected.\n");
ndpi_int_veohtv_add_connection(ndpi_struct, flow);
return;
} else {
if (flow->packet_counter > 10) {
if (flow->l4.tcp.veoh_tv_stage == 2) {
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask,
NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV);
return;
}
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV, ndpi_struct, NDPI_LOG_DEBUG, "VeohTV detected.\n");
ndpi_int_veohtv_add_connection(ndpi_struct, flow);
return;
}
return;
}
} else if (packet->udp) {
/* UDP packets from Veoh Client Player
*
* packet starts with 16 byte random? value
* then a 4 byte mode value
* values between 21 and 26 has been seen
* then a 4 byte counter */
if (packet->payload_packet_len == 28 &&
get_u_int32_t(packet->payload, 16) == htonl(0x00000021) &&
get_u_int32_t(packet->payload, 20) == htonl(0x00000000) && get_u_int32_t(packet->payload, 24) == htonl(0x01040000)) {
NDPI_LOG(NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV, ndpi_struct, NDPI_LOG_DEBUG, "UDP VeohTV found.\n");
ndpi_int_veohtv_add_connection(ndpi_struct, flow);
return;
}
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV);
}
void init_veohtv_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("HTTP_APPLICATION_VEOHTV", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV,
ndpi_search_veohtv_tcp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+117
View File
@@ -0,0 +1,117 @@
/*
* winmx.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-15 - 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_WINMX
static void ndpi_int_winmx_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow);
static void ndpi_int_winmx_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_WINMX, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_winmx_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
// struct ndpi_id_struct *src=ndpi_struct->src;
// struct ndpi_id_struct *dst=ndpi_struct->dst;
if (flow->l4.tcp.winmx_stage == 0) {
if (packet->payload_packet_len == 1 || (packet->payload_packet_len > 1 && packet->payload[0] == 0x31)) {
return;
}
/* did not see this pattern in any trace that we have */
if (((packet->payload_packet_len) == 4)
&& (memcmp(packet->payload, "SEND", 4) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_WINMX, ndpi_struct, NDPI_LOG_DEBUG, "maybe WinMX Send\n");
flow->l4.tcp.winmx_stage = 1;
return;
}
if (((packet->payload_packet_len) == 3)
&& (memcmp(packet->payload, "GET", 3) == 0)) {
NDPI_LOG(NDPI_PROTOCOL_WINMX, ndpi_struct, NDPI_LOG_DEBUG, "found winmx by GET\n");
ndpi_int_winmx_add_connection(ndpi_struct, flow);
return;
}
if (packet->payload_packet_len == 149 && packet->payload[0] == '8') {
NDPI_LOG(NDPI_PROTOCOL_WINMX, ndpi_struct, NDPI_LOG_DEBUG, "maybe WinMX\n");
if (get_u_int32_t(packet->payload, 17) == 0
&& get_u_int32_t(packet->payload, 21) == 0
&& get_u_int32_t(packet->payload, 25) == 0
&& get_u_int16_t(packet->payload, 39) == 0 && get_u_int16_t(packet->payload, 135) == htons(0x7edf)
&& get_u_int16_t(packet->payload, 147) == htons(0xf792)) {
NDPI_LOG(NDPI_PROTOCOL_WINMX, ndpi_struct, NDPI_LOG_DEBUG,
"found winmx by pattern in first packet\n");
ndpi_int_winmx_add_connection(ndpi_struct, flow);
return;
}
}
/* did not see this pattern in any trace that we have */
} else if (flow->l4.tcp.winmx_stage == 1) {
if (packet->payload_packet_len > 10 && packet->payload_packet_len < 1000) {
u_int16_t left = packet->payload_packet_len - 1;
while (left > 0) {
if (packet->payload[left] == ' ') {
NDPI_LOG(NDPI_PROTOCOL_WINMX, ndpi_struct, NDPI_LOG_DEBUG, "found winmx in second packet\n");
ndpi_int_winmx_add_connection(ndpi_struct, flow);
return;
} else if (packet->payload[left] < '0' || packet->payload[left] > '9') {
break;
}
left--;
}
}
}
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_WINMX);
}
void init_winmx_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("WinMX", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_WINMX,
ndpi_search_winmx_tcp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
#endif
+7
View File
@@ -51,13 +51,18 @@
/* { from defs.h */
#define prefix_touchar(prefix) ((u_char *)&(prefix)->add.sin)
#ifdef __KERNEL__
#define MAXLINE 512
#else
#define MAXLINE 1024
#endif
#define BIT_TEST(f, b) ((f) & (b))
/* } */
#define addroute make_and_lookup
#ifndef __KERNEL__
#include <sys/types.h> /* for u_* definitions (on FreeBSD 5) */
#include <errno.h> /* for EAFNOSUPPORT */
@@ -76,6 +81,8 @@
#include <ws2tcpip.h> /* IPv6 */
#endif
#endif /* __KERNEL__ */
/* { from mrt.h */
typedef struct the_prefix4_t {
+4
View File
@@ -18,10 +18,12 @@
along with multifast. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __KERNEL__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#endif
#include "ndpi_api.h"
#include "ahocorasick.h"
@@ -243,6 +245,7 @@ void ac_automata_release (AC_AUTOMATA_t * thiz)
ndpi_free(thiz);
}
#ifndef __KERNEL__
/******************************************************************************
* FUNCTION: ac_automata_display
* Prints the automata to output in human readable form. it is useful for
@@ -296,6 +299,7 @@ void ac_automata_display (AC_AUTOMATA_t * thiz, char repcast)
printf("---------------------------------\n");
}
}
#endif /* __KERNEL__ */
/******************************************************************************
* FUNCTION: ac_automata_register_nodeptr
+80 -11
View File
@@ -39,6 +39,7 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __KERNEL__
#include <assert.h> /* assert */
#include <ctype.h> /* isdigit */
#include <errno.h> /* errno */
@@ -53,8 +54,26 @@
#include <netinet/in.h> /* BSD, Linux: for inet_addr */
#include <arpa/inet.h> /* BSD, Linux, Solaris: for inet_addr */
#endif
#else
#define assert(a) ;
#endif /* __KERNEL__ */
#include "ndpi_patricia.h"
#ifdef __KERNEL__
long atol(const char *nptr) {
long l;
char *endp;
l = simple_strtol(nptr, &endp, 10);
return(l);
}
#endif
// #define PATRICIA_DEBUG
void ndpi_DeleteEntry(void *a) {
ndpi_free(a);
}
@@ -84,6 +103,47 @@ int ndpi_comp_with_mask (void *addr, void *dest, u_int mask) {
return (0);
}
#if 0 /* this implementation does not support IPv6, using system inet_pton */
#ifndef WIN32
/* inet_pton substitute implementation
* Uses inet_addr to convert an IP address in dotted decimal notation into
* unsigned long and copies the result to dst.
* Only supports AF_INET. Follows standard error return conventions of
* inet_pton.
*/
int
inet_pton (int af, const char *src, void *dst)
{
u_long result;
if(af == AF_INET) {
result = inet_addr(src);
if(result == -1)
return 0;
else {
memcpy (dst, &result, sizeof(struct in_addr));
return 1;
}
}
#ifdef NT
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
else if(af == AF_INET6) {
struct in6_addr Address;
return (inet6_addr(src, &Address));
}
#endif /* PATRICIA_IPV6 */
#endif /* NT */
#ifndef NT
else {
printf("NOT SUPP\n");
errno = EAFNOSUPPORT;
return -1;
}
#endif /* NT */
}
#endif
#endif
/* this allows imcomplete prefix */
int
ndpi_my_inet_pton (int af, const char *src, void *dst)
@@ -115,13 +175,15 @@ ndpi_my_inet_pton (int af, const char *src, void *dst)
}
memcpy (dst, xp, sizeof(struct in_addr));
return (1);
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
} else if(af == AF_INET6) {
return (inet_pton (af, src, dst));
return (inet_pton (af, src, dst));
#endif /* PATRICIA_IPV6 */
} else {
} else {
#ifndef NT
errno = EAFNOSUPPORT;
#ifndef __KERNEL__
errno = EAFNOSUPPORT;
#endif
#endif /* NT */
return -1;
}
@@ -174,7 +236,7 @@ ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
}
return (buff);
}
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
else if(prefix->family == AF_INET6) {
char *r;
r = (char *) inet_ntop (AF_INET6, &prefix->add.sin6, buff, 48 /* a guess value */ );
@@ -212,7 +274,7 @@ ndpi_New_Prefix2 (int family, void *dest, int bitlen, prefix_t *prefix)
int dynamic_allocated = 0;
int default_bitlen = sizeof(struct in_addr) * 8;
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
if(family == AF_INET6) {
default_bitlen = sizeof(struct in6_addr) * 8;
if(prefix == NULL) {
@@ -257,7 +319,8 @@ ndpi_New_Prefix (int family, void *dest, int bitlen)
return (ndpi_New_Prefix2 (family, dest, bitlen, NULL));
}
/* ndpi_ascii2prefix */
/* ndpi_ascii2prefix
*/
prefix_t *
ndpi_ascii2prefix (int family, char *string)
{
@@ -265,7 +328,7 @@ ndpi_ascii2prefix (int family, char *string)
long maxbitlen = 0;
char *cp;
struct in_addr sin;
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
struct in6_addr sin6;
#endif /* PATRICIA_IPV6 */
char save[MAXLINE];
@@ -276,7 +339,7 @@ ndpi_ascii2prefix (int family, char *string)
/* easy way to handle both families */
if(family == 0) {
family = AF_INET;
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
if(strchr (string, ':')) family = AF_INET6;
#endif /* PATRICIA_IPV6 */
}
@@ -284,7 +347,7 @@ ndpi_ascii2prefix (int family, char *string)
if(family == AF_INET) {
maxbitlen = sizeof(struct in_addr) * 8;
}
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
else if(family == AF_INET6) {
maxbitlen = sizeof(struct in6_addr) * 8;
}
@@ -310,7 +373,7 @@ ndpi_ascii2prefix (int family, char *string)
return (ndpi_New_Prefix (AF_INET, &sin, bitlen));
}
#if defined(PATRICIA_IPV6)
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
else if(family == AF_INET6) {
// Get rid of this with next IPv6 upgrade
#if defined(NT) && !defined(HAVE_INET_NTOP)
@@ -357,6 +420,8 @@ ndpi_Deref_Prefix (prefix_t * prefix)
}
}
/* } */
/* #define PATRICIA_DEBUG 1 */
static int num_active_patricia = 0;
@@ -381,6 +446,7 @@ ndpi_New_Patricia (int maxbits)
* if func is supplied, it will be called as func(node->data)
* before deleting the node
*/
void
ndpi_Clear_Patricia (patricia_tree_t *patricia, void_fn_t func)
{
@@ -437,6 +503,7 @@ ndpi_Destroy_Patricia (patricia_tree_t *patricia, void_fn_t func)
/*
* if func is supplied, it will be called as func(node->prefix, node->data)
*/
void
ndpi_patricia_process (patricia_tree_t *patricia, void_fn2_t func)
{
@@ -1006,3 +1073,5 @@ ndpi_lookup_then_remove (patricia_tree_t *tree, char *string)
patricia_remove (tree, node);
}
#endif
/* } */
+4
View File
@@ -18,10 +18,14 @@
along with multifast. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __KERNEL__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#endif
#include "ndpi_api.h"
#include "../include/node.h"
#include "sort.h"
+38
View File
@@ -4,6 +4,9 @@
* Jan 23 2005 Matt Mackall <mpm@selenic.com>
*/
#ifdef __KERNEL__
#include <linux/types.h>
#else
#ifdef WIN32
#include <stdint.h>
typedef uint32_t u_int32_t;
@@ -12,6 +15,7 @@ typedef uint32_t u_int32_t;
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#endif
/* This is a function ported from the Linux kernel lib/sort.c */
@@ -90,3 +94,37 @@ void sort(void *_base, size_t num, size_t size,
}
}
}
#if 0
/* a simple boot-time regression test */
int cmpint(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main(int argc, char *argv[]) {
int *a, i, r = 1;
a = ndpi_malloc(1000 * sizeof(int));
printf("testing sort()\n");
for (i = 0; i < 1000; i++) {
r = (r * 725861) % 6599;
a[i] = r;
}
sort(a, 1000, sizeof(int), cmpint, NULL);
for (i = 0; i < 999; i++)
if (a[i] > a[i+1]) {
printf("sort() failed!\n");
break;
}
return 0;
}
#endif
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

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