Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d113f8db5a | ||
|
|
db36040fe1 | ||
|
|
f0c1688b1b | ||
|
|
67d3c9e9c8 | ||
|
|
ac664940da | ||
|
|
8eb0829267 | ||
|
|
f8ecdc004f | ||
|
|
c088672632 | ||
|
|
552076a36c | ||
|
|
a0fe6665b2 | ||
|
|
b05907f592 | ||
|
|
bae6a09a7c | ||
|
|
8bc1ed7d86 | ||
|
|
9935cb0e3b | ||
|
|
594f7074f7 | ||
|
|
a6c9d33c09 | ||
|
|
e0e1ed6936 | ||
|
|
7fb4b42092 | ||
|
|
1b3055faef | ||
|
|
cf905d0c7f | ||
|
|
f084bbb6d0 | ||
|
|
a2843084d6 | ||
|
|
3d23ee0e23 | ||
|
|
92718c4def | ||
|
|
e1d3a8ea7d | ||
|
|
2f7a9bb789 | ||
|
|
ef2cb860a3 | ||
|
|
1e37916156 | ||
|
|
f3fb445166 | ||
|
|
ac55d8dd8b | ||
|
|
f517a6a373 | ||
|
|
ccdcf9d82b | ||
|
|
b7863e2dc2 | ||
|
|
6edb280cc7 | ||
|
|
32847fcfd0 | ||
|
|
69bdc44441 | ||
|
|
4d58e55781 | ||
|
|
90843a4228 | ||
|
|
d233459195 | ||
|
|
6dab2b8c62 | ||
|
|
86893a2984 | ||
|
|
3618f066bb | ||
|
|
5c149e0363 | ||
|
|
22e03ee98a | ||
|
|
18901ca4d6 | ||
|
|
d5f77e92f7 | ||
|
|
d139c31972 | ||
|
|
53550d8bb4 | ||
|
|
356f9914cc | ||
|
|
6e57c4618e | ||
|
|
9b0bef50de | ||
|
|
c957a12742 | ||
|
|
1b9aa2ab71 | ||
|
|
1d17ece9ce | ||
|
|
34ce35dcfa | ||
|
|
f66cfca2a9 | ||
|
|
7c1e8ba2bf | ||
|
|
e23446389c | ||
|
|
8cb6172e4b | ||
|
|
d427647ce7 | ||
|
|
8a4c15ecf5 | ||
|
|
1be9194734 | ||
|
|
792d2fc79a | ||
|
|
5386aede36 | ||
|
|
4e1317cd0f | ||
|
|
9ee6442004 | ||
|
|
6f84b85358 | ||
|
|
d7548e72b2 | ||
|
|
7964e11c7f | ||
|
|
a4d0af1f96 | ||
|
|
282bc16243 | ||
|
|
4ba106a525 | ||
|
|
1d54092c7d | ||
|
|
4b50045ecd | ||
|
|
a6e715f574 | ||
|
|
18f5362a34 | ||
|
|
a71f525a2b | ||
|
|
efae85de84 | ||
|
|
da811fbdd0 | ||
|
|
d7a2515093 | ||
|
|
885cc3864e | ||
|
|
c22d3d3cae | ||
|
|
fb3fc0c6de | ||
|
|
624f61193c | ||
|
|
5a37ee9976 | ||
|
|
6a63ea46a4 | ||
|
|
f437fac412 | ||
|
|
afea67e303 | ||
|
|
3d46f3df61 | ||
|
|
697617622c | ||
|
|
7e9e3903d8 | ||
|
|
7b66fcff37 | ||
|
|
40b219c397 | ||
|
|
b5e74ee3f1 | ||
|
|
6f95182751 | ||
|
|
41d7430442 | ||
|
|
aa86387ba9 | ||
|
|
2a1f44610f | ||
|
|
4704f48daa | ||
|
|
8dacc91d51 | ||
|
|
a594273989 | ||
|
|
d9264e415c | ||
|
|
b3df389bd6 | ||
|
|
2998b78797 | ||
|
|
46a526ce26 | ||
|
|
95fffec172 | ||
|
|
323912371e | ||
|
|
3213d2205a | ||
|
|
3dde80ed0f | ||
|
|
6f428c03e2 | ||
|
|
2d5d39db7b | ||
|
|
28806f3187 | ||
|
|
5349d33abf | ||
|
|
a499da00ba | ||
|
|
a4d9c8cc3b | ||
|
|
27d09c33ce | ||
|
|
5b86186e85 | ||
|
|
3b399f62f4 | ||
|
|
7c511fb2f2 | ||
|
|
4370781b49 | ||
|
|
1cf4926b4e | ||
|
|
7ae06a114d | ||
|
|
8321b2fa66 | ||
|
|
ba966634f5 | ||
|
|
dd12757493 | ||
|
|
7ea37edfbf | ||
|
|
462368f959 | ||
|
|
73833e0ef0 | ||
|
|
7d699ade0c | ||
|
|
bc52b8f310 | ||
|
|
ecb8d117ac | ||
|
|
ead8c4933e | ||
|
|
20374b542d | ||
|
|
6df31099c2 | ||
|
|
b7e2d8f019 | ||
|
|
80a35226c5 | ||
|
|
e025d696f6 | ||
|
|
245ca20eea | ||
|
|
8f60ad8874 | ||
|
|
d18a1edb67 | ||
|
|
a8050635fa | ||
|
|
33fa1989bc | ||
|
|
7d3ab6d0b4 | ||
|
|
237102b5f2 | ||
|
|
407b4fd1d5 | ||
|
|
882cbd8b4e | ||
|
|
4c3d9788dd | ||
|
|
59c65118e1 | ||
|
|
84976ed5dc | ||
|
|
15ccb70ae6 | ||
|
|
e1481f3a90 | ||
|
|
01413c8d9f | ||
|
|
392a14241f | ||
|
|
16a5c6995c | ||
|
|
c7334e7c56 | ||
|
|
cc4ceb88a0 | ||
|
|
7ee464709b | ||
|
|
ee5e7449ac | ||
|
|
278a067d43 | ||
|
|
e9f7df081f | ||
|
|
d0b83a7196 | ||
|
|
bc48b770de | ||
|
|
e7cb3d324a | ||
|
|
0f3222e489 | ||
|
|
a08a0077e6 | ||
|
|
5336aecde7 | ||
|
|
a2c51a586e | ||
|
|
3aa506eb1b | ||
|
|
60e7e19dab | ||
|
|
1b2702df24 | ||
|
|
6d37ee2970 | ||
|
|
2aa007fbad | ||
|
|
bfded90875 | ||
|
|
e0c6d80c09 | ||
|
|
237de95285 | ||
|
|
357d8c98a3 | ||
|
|
5f40394501 | ||
|
|
41c6d2d031 | ||
|
|
d2c355bdb0 | ||
|
|
6f3d5a7b33 | ||
|
|
34491f4be1 | ||
|
|
34e0a74c07 | ||
|
|
587f156557 | ||
|
|
f04c3c6acb | ||
|
|
80171b7c54 | ||
|
|
cb68d4d00a | ||
|
|
98ef945d2e | ||
|
|
12b47fece0 | ||
|
|
bfb44934b7 | ||
|
|
08ca34f5d0 | ||
|
|
a46c12c014 | ||
|
|
d24093c4a6 | ||
|
|
ec034da5c9 | ||
|
|
d5b9e4ccd5 | ||
|
|
169c837613 | ||
|
|
33f38dd437 | ||
|
|
bd7004ecd7 | ||
|
|
8babee0efb | ||
|
|
a407da79a9 | ||
|
|
8399afa607 | ||
|
|
68091c7cdb | ||
|
|
e62be406ce | ||
|
|
dd3a79dac2 | ||
|
|
a4f170604c | ||
|
|
349e0b6fd2 | ||
|
|
78eceb43a1 | ||
|
|
0cd8d939f1 | ||
|
|
9fa2c7404f | ||
|
|
8cd0a8838a | ||
|
|
d92ffa6771 | ||
|
|
63cab68a96 | ||
|
|
f6eb2724e2 | ||
|
|
fc6980e0c9 | ||
|
|
7a95a21e09 | ||
|
|
8edd628973 | ||
|
|
50e7e959fe | ||
|
|
b5f70d02b2 | ||
|
|
76c2fb3de7 | ||
|
|
27ea5c0026 | ||
|
|
59d0af33b8 | ||
|
|
25631a25f7 | ||
|
|
ac9b4f8135 | ||
|
|
46694ece47 | ||
|
|
74b016c8b6 | ||
|
|
7242b08609 | ||
|
|
ee0954c8cb | ||
|
|
fd9f4753bb | ||
|
|
dc9ad66fe2 | ||
|
|
247acce949 | ||
|
|
91b2e0bff2 | ||
|
|
17ad351386 | ||
|
|
72eafff843 | ||
|
|
4ec03b7e87 | ||
|
|
88d466e58e | ||
|
|
cf2c59b1d7 | ||
|
|
93f02c08dc | ||
|
|
efac255821 | ||
|
|
06515b43d8 | ||
|
|
0e436e66de | ||
|
|
3f2eec75c7 | ||
|
|
6519a1e326 | ||
|
|
a2ff20990c | ||
|
|
0a6d43c5f6 | ||
|
|
64a368dd8e | ||
|
|
1dc03d5741 | ||
|
|
e5c2fee022 | ||
|
|
00bfba1d77 | ||
|
|
76c963a70c | ||
|
|
f78f6b59cc | ||
|
|
faf3c81be3 | ||
|
|
a994722bb1 | ||
|
|
b383475282 | ||
|
|
ce7866a6a6 | ||
|
|
0dfd6d3986 | ||
|
|
50757e7afe | ||
|
|
df64a1069e | ||
|
|
9450226675 | ||
|
|
8f8052735c | ||
|
|
aa6640e1c0 | ||
|
|
5f1b82d696 | ||
|
|
19e96f7dd2 | ||
|
|
591d6df489 | ||
|
|
8fe318495f | ||
|
|
569c055389 | ||
|
|
26ce076f61 | ||
|
|
07c7d63d44 |
@@ -1,8 +1,13 @@
|
||||
# What is nDPI ?
|
||||
![ntop][ntopng_logo] ![ntop][ntop_logo]
|
||||
# nDPI
|
||||
|
||||
[](https://travis-ci.org/ntop/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
|
||||
|
||||
@@ -14,7 +19,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:
|
||||
|
||||
@@ -30,13 +35,12 @@ 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
|
||||
|
||||
# Acknowledgements
|
||||
|
||||
Many thanks to <A HREF=http://www.radcom.com>Radcom</A> Ltd for supporting the development of nDPI.
|
||||
[ntop_logo]: https://camo.githubusercontent.com/58e2a1ecfff62d8ecc9d74633bd1013f26e06cba/687474703a2f2f7777772e6e746f702e6f72672f77702d636f6e74656e742f75706c6f6164732f323031352f30352f6e746f702e706e67
|
||||
|
||||
+1
-1
@@ -30,4 +30,4 @@ if test -z $AUTORECONF; then
|
||||
fi
|
||||
|
||||
autoreconf -ivf
|
||||
./configure
|
||||
./configure $*
|
||||
|
||||
+15
-13
@@ -1,4 +1,4 @@
|
||||
AC_INIT([libndpi], [1.7.1])
|
||||
AC_INIT([libndpi], [1.8.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_LIB="$PCAP_HOME/libpcap/libpcap.a $PCAP_HOME/lib/libpfring.a $LIBNUMA `$PCAP_HOME/lib/pfring_config --libs`"
|
||||
|
||||
AC_CHECK_LIB([rt], [clock_gettime], [PCAP_LIB="$PCAP_LIB -lrt"])
|
||||
AC_CHECK_LIB([nl], [nl_handle_alloc], [PCAP_LIB="$PCAP_LIB -lnl"])
|
||||
@@ -61,17 +61,20 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
PKG_CONFIG=$(which pkg-config)
|
||||
AC_ARG_ENABLE([json-c],
|
||||
AS_HELP_STRING([--disable-json-c], [Disable json-c support]))
|
||||
|
||||
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
|
||||
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]))
|
||||
],
|
||||
[])
|
||||
])
|
||||
|
||||
OLD_LIBS=$LIBS
|
||||
LIBS="-L/opt/napatech3/lib $LIBS"
|
||||
@@ -81,7 +84,6 @@ 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
@@ -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
|
||||
ndpiReader_SOURCES = ndpiReader.c ndpi_util.c
|
||||
|
||||
ndpiReader.o: ndpiReader.c
|
||||
|
||||
|
||||
+351
-841
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,847 @@
|
||||
/*
|
||||
* 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 & 0x3FFF) != 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);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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
@@ -1,4 +1,6 @@
|
||||
ndpi_dump_protocols
|
||||
ndpi_strnstr
|
||||
ndpi_detection_giveup
|
||||
ndpi_get_proto_name
|
||||
ndpi_free
|
||||
ndpi_guess_undetected_protocol
|
||||
@@ -10,6 +12,7 @@ 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
|
||||
@@ -28,3 +31,18 @@ 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
|
||||
@@ -1,4 +0,0 @@
|
||||
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
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
library_includedir=$(includedir)/libndpi-1.4/libndpi
|
||||
|
||||
library_include_HEADERS = ndpi_api.h \
|
||||
ndpi_debug_functions.h \
|
||||
ndpi_define.h \
|
||||
ndpi_macros.h \
|
||||
ndpi_protocols_osdpi.h \
|
||||
ndpi_public_functions.h
|
||||
ndpi_define.h \
|
||||
ndpi_typedefs.h \
|
||||
ndpi_main.h \
|
||||
ndpi_protocol_ids.h \
|
||||
ndpi_protocols.h \
|
||||
ndpi_win32.h \
|
||||
ndpi_includes.h
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* linux_compat.h
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NDPI_LINUX_COMPAT_H__
|
||||
#define __NDPI_LINUX_COMPAT_H__
|
||||
|
||||
#include "ndpi_define.h"
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
#include <machine/endian.h>
|
||||
|
||||
#if _BYTE_ORDER == _LITTLE_ENDIAN
|
||||
#ifndef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__ 1
|
||||
#endif
|
||||
#else
|
||||
#ifndef __BIG_ENDIAN__
|
||||
#define __BIG_ENDIAN__ 1
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#pragma pack(push, 1) /* push current alignment to stack */
|
||||
#pragma pack(1) /* set alignment to 1 byte boundary */
|
||||
|
||||
#pragma pack(pop) /* restore original alignment from stack */
|
||||
|
||||
struct ndpi_ethhdr {
|
||||
u_char h_dest[6]; /* destination eth addr */
|
||||
u_char h_source[6]; /* source ether addr */
|
||||
u_int16_t h_proto; /* packet type ID field */
|
||||
};
|
||||
|
||||
struct ndpi_80211q {
|
||||
u_int16_t vlanId;
|
||||
u_int16_t protoType;
|
||||
};
|
||||
|
||||
struct ndpi_iphdr {
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
u_int8_t ihl:4, version:4;
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
u_int8_t version:4, ihl:4;
|
||||
#else
|
||||
# error "Byte order must be defined"
|
||||
#endif
|
||||
u_int8_t tos;
|
||||
u_int16_t tot_len;
|
||||
u_int16_t id;
|
||||
u_int16_t frag_off;
|
||||
u_int8_t ttl;
|
||||
u_int8_t protocol;
|
||||
u_int16_t check;
|
||||
u_int32_t saddr;
|
||||
u_int32_t daddr;
|
||||
};
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned short u_short;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long u_long;
|
||||
typedef u_char u_int8_t;
|
||||
typedef u_short u_int16_t;
|
||||
typedef uint u_int32_t;
|
||||
|
||||
#define _WS2TCPIP_H_ /* Avoid compilation problems */
|
||||
#define HAVE_SIN6_LEN
|
||||
|
||||
|
||||
/* IPv6 address */
|
||||
/* Already defined in WS2tcpip.h */
|
||||
struct ndpi_win_in6_addr
|
||||
{
|
||||
union
|
||||
{
|
||||
u_int8_t u6_addr8[16];
|
||||
u_int16_t u6_addr16[8];
|
||||
u_int32_t u6_addr32[4];
|
||||
} in6_u;
|
||||
#ifdef s6_addr
|
||||
#undef s6_addr
|
||||
#endif
|
||||
|
||||
#ifdef s6_addr16
|
||||
#undef s6_addr16
|
||||
#endif
|
||||
|
||||
#ifdef s6_addr32
|
||||
#undef s6_addr32
|
||||
#endif
|
||||
|
||||
#define s6_addr in6_u.u6_addr8
|
||||
// #define s6_addr16 in6_u.u6_addr16
|
||||
// #define s6_addr32 in6_u.u6_addr32
|
||||
|
||||
};
|
||||
|
||||
#define in6_addr win_in6_addr
|
||||
|
||||
/* Generic extension header. */
|
||||
struct ndpi_ip6_ext
|
||||
{
|
||||
u_int8_t ip6e_nxt; /* next header. */
|
||||
u_int8_t ip6e_len; /* length in units of 8 octets. */
|
||||
};
|
||||
|
||||
#define s6_addr16 __u6_addr.__u6_addr16
|
||||
#define s6_addr32 __u6_addr.__u6_addr32
|
||||
#else
|
||||
#ifndef __KERNEL__
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
struct ndpi_in6_addr {
|
||||
union {
|
||||
u_int8_t __u6_addr8[16];
|
||||
u_int16_t __u6_addr16[8];
|
||||
u_int32_t __u6_addr32[4];
|
||||
} __u6_addr; /* 128-bit IP6 address */
|
||||
};
|
||||
|
||||
struct ndpi_ip6_hdr {
|
||||
union {
|
||||
struct ndpi_ip6_hdrctl {
|
||||
u_int32_t ip6_un1_flow;
|
||||
u_int16_t ip6_un1_plen;
|
||||
u_int8_t ip6_un1_nxt;
|
||||
u_int8_t ip6_un1_hlim;
|
||||
} ip6_un1;
|
||||
u_int8_t ip6_un2_vfc;
|
||||
} ip6_ctlun;
|
||||
struct ndpi_in6_addr ip6_src;
|
||||
struct ndpi_in6_addr ip6_dst;
|
||||
};
|
||||
|
||||
struct ndpi_tcphdr {
|
||||
u_int16_t source;
|
||||
u_int16_t dest;
|
||||
u_int32_t seq;
|
||||
u_int32_t ack_seq;
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
u_int16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
u_int16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1;
|
||||
#else
|
||||
# error "Byte order must be defined"
|
||||
#endif
|
||||
u_int16_t window;
|
||||
u_int16_t check;
|
||||
u_int16_t urg_ptr;
|
||||
};
|
||||
|
||||
struct ndpi_udphdr {
|
||||
u_int16_t source;
|
||||
u_int16_t dest;
|
||||
u_int16_t len;
|
||||
u_int16_t check;
|
||||
};
|
||||
|
||||
#endif
|
||||
+560
-164
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_api.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-2011 by ipoque GmbH
|
||||
* 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
|
||||
@@ -23,8 +22,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NDPI_PUBLIC_FUNCTIONS_H__
|
||||
#define __NDPI_PUBLIC_FUNCTIONS_H__
|
||||
#ifndef __NDPI_API_H__
|
||||
#define __NDPI_API_H__
|
||||
|
||||
#include "ndpi_main.h"
|
||||
|
||||
@@ -32,96 +31,190 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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);
|
||||
#define NDPI_DETECTION_ONLY_IPV4 ( 1 << 0 )
|
||||
#define NDPI_DETECTION_ONLY_IPV6 ( 1 << 1 )
|
||||
|
||||
/**
|
||||
* 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);
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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(u_int32_t ticks_per_second,
|
||||
void* (*__ndpi_malloc)(unsigned long size),
|
||||
void (*__ndpi_free)(void *ptr),
|
||||
ndpi_debug_function_ptr ndpi_debug_printf);
|
||||
#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 frees the memory allocated in the specified flow
|
||||
* @param flow to free
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
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
|
||||
*
|
||||
*/
|
||||
u_int32_t ndpi_detection_get_sizeof_ndpi_id_struct(void);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
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
|
||||
*
|
||||
*/
|
||||
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
struct ndpi_detection_module_struct *ndpi_init_detection_module();
|
||||
|
||||
/**
|
||||
* Frees the memory allocated in the specified flow
|
||||
*
|
||||
* @par flow = the flow to deallocate
|
||||
*
|
||||
*/
|
||||
void ndpi_free_flow(struct ndpi_flow_struct *flow);
|
||||
|
||||
|
||||
/**
|
||||
* This function enables cache support in nDPI used for some protocol such as Skype
|
||||
* @param cache host name
|
||||
* @param cache port
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
void ndpi_enable_cache(struct ndpi_detection_module_struct *ndpi_mod, char* host, u_int port);
|
||||
|
||||
|
||||
/**
|
||||
* This function destroys the detection module
|
||||
* @param ndpi_struct the to clearing detection module
|
||||
* @param ndpi_free function pointer to a memory free function
|
||||
* Destroys the detection module
|
||||
*
|
||||
* @par ndpi_struct = the struct to clearing for the detection module
|
||||
*
|
||||
*/
|
||||
void
|
||||
ndpi_exit_detection_module(struct ndpi_detection_module_struct
|
||||
*ndpi_struct, void (*ndpi_free) (void *ptr));
|
||||
void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_struct);
|
||||
|
||||
|
||||
/**
|
||||
* This function sets the protocol bitmask2
|
||||
* @param ndpi_struct the detection module
|
||||
* @param detection_bitmask the protocol bitmask
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
void
|
||||
ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const NDPI_PROTOCOL_BITMASK * detection_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);
|
||||
|
||||
|
||||
/**
|
||||
* This function will processes one packet and returns the ID of the detected protocol.
|
||||
* This is the main packet processing function.
|
||||
* 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
|
||||
*
|
||||
* @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,
|
||||
@@ -131,117 +224,420 @@ 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
|
||||
* 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);
|
||||
/**
|
||||
* returns the real protocol for the flow of the last packet given to the detection.
|
||||
* if no real protocol could be found, the unknown protocol will be returned.
|
||||
* @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
|
||||
*
|
||||
* @param ndpi_struct the detection module
|
||||
* @return the protocol id of the last real protocol found in the protocol history of the flow
|
||||
*/
|
||||
/* u_int16_t ndpi_detection_get_real_protocol_of_flow(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow); */
|
||||
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);
|
||||
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);
|
||||
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,
|
||||
u_int16_t master_protocol_id);
|
||||
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,
|
||||
u_int16_t master_protocol_id);
|
||||
int ndpi_match_bigram(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
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);
|
||||
char* ndpi_get_proto_name(struct ndpi_detection_module_struct *mod, u_int16_t proto_id);
|
||||
ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t proto);
|
||||
char* ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_struct, ndpi_protocol_breed_t breed_id);
|
||||
int ndpi_get_protocol_id(struct ndpi_detection_module_struct *ndpi_mod, char *proto);
|
||||
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);
|
||||
|
||||
int ndpi_load_protocols_file(struct ndpi_detection_module_struct *ndpi_mod, char* path);
|
||||
u_int ndpi_get_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
|
||||
char* ndpi_revision(void);
|
||||
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
|
||||
/*
|
||||
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);
|
||||
|
||||
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);
|
||||
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
|
||||
*
|
||||
*/
|
||||
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
|
||||
*
|
||||
*/
|
||||
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,
|
||||
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,
|
||||
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
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
|
||||
#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
|
||||
*
|
||||
*/
|
||||
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);
|
||||
#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
|
||||
#endif
|
||||
|
||||
#endif /* __NDPI_API_H__ */
|
||||
|
||||
+32
-45
@@ -1,7 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-2011 by ipoque GmbH
|
||||
* 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
|
||||
@@ -42,15 +41,22 @@
|
||||
#endif/* BYTE_ORDER */
|
||||
#endif/* __OPENBSD__ */
|
||||
|
||||
#if 0
|
||||
#ifndef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
#define NDPI_ENABLE_DEBUG_MESSAGES
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#ifndef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__
|
||||
#endif
|
||||
#else
|
||||
#ifndef __BIG_ENDIAN__
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__ 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !(defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__))
|
||||
#if defined(__mips__)
|
||||
@@ -59,13 +65,6 @@
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
|
||||
/* Kernel modules */
|
||||
#if defined(__LITTLE_ENDIAN)
|
||||
#define __LITTLE_ENDIAN__
|
||||
#endif
|
||||
#if defined(__BIG_ENDIAN)
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
/* Everything else */
|
||||
#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__))
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
@@ -77,7 +76,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)
|
||||
@@ -160,29 +159,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
|
||||
|
||||
/**********************
|
||||
* detection features *
|
||||
**********************/
|
||||
/* #define NDPI_SELECT_DETECTION_WITH_REAL_PROTOCOL ( 1 << 0 ) */
|
||||
|
||||
#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
|
||||
@@ -199,7 +193,7 @@
|
||||
|
||||
#else /* NDPI_ENABLE_DEBUG_MESSAGES */
|
||||
|
||||
#if defined(WIN32)
|
||||
#ifdef WIN32
|
||||
#define NDPI_LOG(...) {}
|
||||
#else
|
||||
#define NDPI_LOG(proto, mod, log_level, args...) {}
|
||||
@@ -218,12 +212,7 @@
|
||||
#define NDPI_COMPARE_IPV6_ADDRESS_STRUCTS(x,y) \
|
||||
((((u_int64_t *)(x))[0]) < (((u_int64_t *)(y))[0]) || ( (((u_int64_t *)(x))[0]) == (((u_int64_t *)(y))[0]) && (((u_int64_t *)(x))[1]) < (((u_int64_t *)(y))[1])) )
|
||||
|
||||
#if !defined(__KERNEL__) && !defined(NDPI_IPTABLES_EXT)
|
||||
#define NDPI_NUM_BITS 256
|
||||
#else
|
||||
/* custom protocols not supported */
|
||||
#define NDPI_NUM_BITS 192
|
||||
#endif
|
||||
|
||||
#define NDPI_BITS /* 32 */ (sizeof(ndpi_ndpi_mask) * 8 /* number of bits in a byte */) /* bits per mask */
|
||||
#define howmanybits(x, y) (((x)+((y)-1))/(y))
|
||||
@@ -238,7 +227,7 @@
|
||||
#define NDPI_NUM_FDS_BITS howmanybits(NDPI_NUM_BITS, NDPI_BITS)
|
||||
|
||||
#define NDPI_PROTOCOL_BITMASK ndpi_protocol_bitmask_struct_t
|
||||
|
||||
|
||||
#define NDPI_BITMASK_ADD(a,b) NDPI_SET(&a,b)
|
||||
#define NDPI_BITMASK_DEL(a,b) NDPI_CLR(&a,b)
|
||||
#define NDPI_BITMASK_RESET(a) NDPI_ZERO(&a)
|
||||
@@ -246,7 +235,7 @@
|
||||
#define NDPI_BITMASK_SET(a, b) { memcpy(&a, &b, sizeof(NDPI_PROTOCOL_BITMASK)); }
|
||||
|
||||
/* this is a very very tricky macro *g*,
|
||||
* the compiler will remove all shifts here if the protocol is static...
|
||||
* the compiler will remove all shifts here if the protocol is static...
|
||||
*/
|
||||
#define NDPI_ADD_PROTOCOL_TO_BITMASK(bmask,value) NDPI_SET(&bmask,value)
|
||||
#define NDPI_DEL_PROTOCOL_FROM_BITMASK(bmask,value) NDPI_CLR(&bmask,value)
|
||||
@@ -289,21 +278,19 @@
|
||||
#define get_l32(X,O) get_u_int32_t(X,O)
|
||||
#elif defined(__BIG_ENDIAN__) || defined(__BIG_ENDIAN)
|
||||
/* convert the bytes from big to little endian */
|
||||
#ifndef __KERNEL__
|
||||
# define get_l16(X,O) bswap_16(get_u_int16_t(X,O))
|
||||
# define get_l32(X,O) bswap_32(get_u_int32_t(X,O))
|
||||
#else
|
||||
# define get_l16(X,O) __cpu_to_le16(get_u_int16_t(X,O))
|
||||
# define get_l32(X,O) __cpu_to_le32(get_u_int32_t(X,O))
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#error "__BYTE_ORDER MUST BE DEFINED !"
|
||||
|
||||
#endif /* __BYTE_ORDER */
|
||||
|
||||
/* define memory callback function */
|
||||
#define match_first_bytes(payload,st) (memcmp((payload),(st),(sizeof(st)-1))==0)
|
||||
|
||||
#if defined(WIN32) && !defined(snprintf)
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#define NDPI_MAX_DNS_REQUESTS 16
|
||||
|
||||
#endif /* __NDPI_DEFINE_INCLUDE_FILE__ */
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* ndpi_includes.h
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NDPI_INCLUDES_H__
|
||||
#define __NDPI_INCLUDES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include "ndpi_win32.h"
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <pthread.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
|
||||
#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
|
||||
#include <endian.h>
|
||||
#include <byteswap.h>
|
||||
|
||||
#if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
|
||||
#include <netinet/in.h>
|
||||
|
||||
#if defined __NetBSD__ || defined __OpenBSD__
|
||||
#include <netinet/in_systm.h>
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
#include <pthread.h>
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* Win32 */
|
||||
|
||||
#endif /* __NDPI_INCLUDES_H__ */
|
||||
+37
-70
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_main.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-2011 by ipoque GmbH
|
||||
* 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
|
||||
@@ -22,54 +21,19 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NDPI_MAIN_INCLUDE_FILE__
|
||||
#define __NDPI_MAIN_INCLUDE_FILE__
|
||||
#ifndef __NDPI_MAIN_H__
|
||||
#define __NDPI_MAIN_H__
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef __KERNEL__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#if !defined __APPLE__ && !defined __FreeBSD__ && !defined __NetBSD__ && !defined __OpenBSD__
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <endian.h>
|
||||
#include <byteswap.h>
|
||||
#else
|
||||
#include <asm/byteorder.h>
|
||||
#include <linux/ctype.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* default includes */
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#include <sys/param.h>
|
||||
#include <limits.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ndpi_win32.h"
|
||||
#include "ndpi_unix.h"
|
||||
#include "ndpi_includes.h"
|
||||
#include "ndpi_define.h"
|
||||
#include "ndpi_protocol_ids.h"
|
||||
#include "ndpi_typedefs.h"
|
||||
#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 *));
|
||||
@@ -103,58 +67,61 @@ void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol);
|
||||
|
||||
|
||||
/* function to parse a packet which has line based information into a line based structure
|
||||
* this function will also set some well known line pointers like:
|
||||
* - host, user agent, empty line,....
|
||||
*/
|
||||
extern void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
extern void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
|
||||
extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, u_int16_t counter);
|
||||
extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
|
||||
extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol);
|
||||
extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol);
|
||||
extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
|
||||
ndpi_protocol_breed_t protoBreed, u_int16_t protoId,
|
||||
u_int16_t tcp_alias_protoId[2], u_int16_t udp_alias_protoId[2],
|
||||
char *protoName,
|
||||
extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol_breed_t protoBreed, u_int16_t protoId,
|
||||
u_int16_t tcp_alias_protoId[2], u_int16_t udp_alias_protoId[2], char *protoName,
|
||||
ndpi_port_range *tcpDefPorts, ndpi_port_range *udpDefPorts);
|
||||
|
||||
extern void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet);
|
||||
extern void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow);
|
||||
|
||||
extern int ndpi_packet_src_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
|
||||
extern int ndpi_packet_dst_ip_eql(const struct ndpi_packet_struct *packet, const ndpi_ip_addr_t * ip);
|
||||
extern void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
|
||||
extern void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
|
||||
|
||||
extern char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const ndpi_ip_addr_t * ip);
|
||||
extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const struct ndpi_packet_struct *packet);
|
||||
extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const struct ndpi_packet_struct *packet);
|
||||
extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id);
|
||||
|
||||
extern u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
u_int8_t proto, u_int16_t sport, u_int16_t dport);
|
||||
|
||||
extern u_int8_t ndpi_is_proto(ndpi_protocol p, u_int16_t proto);
|
||||
|
||||
extern u_int16_t ndpi_get_lower_proto(ndpi_protocol p);
|
||||
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
u_int16_t protocol_id,
|
||||
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t protocol_id,
|
||||
u_int16_t** tcp_master_proto,
|
||||
u_int16_t** udp_master_proto);
|
||||
|
||||
extern u_int8_t ndpi_net_match(u_int32_t ip_to_check,
|
||||
u_int32_t net,
|
||||
u_int32_t num_bits);
|
||||
|
||||
extern u_int8_t ndpi_ips_match(u_int32_t src, u_int32_t dst,
|
||||
u_int32_t net, u_int32_t num_bits);
|
||||
|
||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const char **file, const char **func, u_int32_t * line);
|
||||
#endif
|
||||
|
||||
#include "ndpi_api.h"
|
||||
/** 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);
|
||||
|
||||
#endif /* __NDPI_MAIN_INCLUDE_FILE__ */
|
||||
/* 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__ */
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_protocol_ids.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-11 - ipoque GmbH
|
||||
* 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
|
||||
@@ -23,7 +22,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NDPI_API_INCLUDE_FILE__
|
||||
#ifndef __NDPI_API_H__
|
||||
|
||||
#endif
|
||||
|
||||
@@ -49,14 +48,14 @@
|
||||
#define NDPI_PROTOCOL_IP_ICMPV6 102
|
||||
|
||||
#define NDPI_PROTOCOL_HTTP 7
|
||||
#define NDPI_PROTOCOL_HTTP_APPLICATION_VEOHTV 60
|
||||
#define NDPI_PROTOCOL_HTTP_DOWNLOAD 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_SOCKS5 172 /* Tomasz Bujlow <tomasz@skatnet.dk> */
|
||||
#define NDPI_PROTOCOL_SOCKS4 173 /* Tomasz Bujlow <tomasz@skatnet.dk> */
|
||||
#define NDPI_PROTOCOL_SOCKS 172 /* Tomasz Bujlow <tomasz@skatnet.dk> */
|
||||
|
||||
|
||||
#define NDPI_PROTOCOL_FTP_CONTROL 1 /* Tomasz Bujlow <tomasz@skatnet.dk> */
|
||||
#define NDPI_PROTOCOL_MAIL_POP 2
|
||||
@@ -83,7 +82,7 @@
|
||||
#define NDPI_PROTOCOL_APPLEJUICE 24
|
||||
#define NDPI_PROTOCOL_DIRECTCONNECT 25
|
||||
#define NDPI_PROTOCOL_SOCRATES 26
|
||||
#define NDPI_PROTOCOL_WINMX 27
|
||||
#define NDPI_PROTOCOL_COAP 27
|
||||
#define NDPI_PROTOCOL_VMWARE 28
|
||||
#define NDPI_PROTOCOL_MAIL_SMTPS 29
|
||||
#define NDPI_PROTOCOL_FILETOPIA 30
|
||||
@@ -201,6 +200,11 @@
|
||||
#define NDPI_PROTOCOL_WHATSAPP_VOICE 189
|
||||
#define NDPI_PROTOCOL_STARCRAFT 213 /* Matteo Bracci <matteobracci1@gmail.com> */
|
||||
#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_CONTENT_AVI 39
|
||||
#define NDPI_CONTENT_FLASH 40
|
||||
@@ -227,15 +231,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 /* Tomasz Bujlow <tomasz@skatnet.dk> */
|
||||
#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
|
||||
#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
|
||||
@@ -261,9 +265,16 @@
|
||||
#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
|
||||
/* UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE UPDATE */
|
||||
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_SERVICE_HOTSPOT_SHIELD
|
||||
#define NDPI_LAST_IMPLEMENTED_PROTOCOL NDPI_SERVICE_OPENDNS
|
||||
|
||||
#define NDPI_MAX_SUPPORTED_PROTOCOLS (NDPI_LAST_IMPLEMENTED_PROTOCOL + 1)
|
||||
#define NDPI_MAX_NUM_CUSTOM_PROTOCOLS (NDPI_NUM_BITS-NDPI_LAST_IMPLEMENTED_PROTOCOL)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_protocols.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-2011 by ipoque GmbH
|
||||
* 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
|
||||
@@ -23,8 +22,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NDPI_PROTOCOLS_INCLUDE_FILE__
|
||||
#define __NDPI_PROTOCOLS_INCLUDE_FILE__
|
||||
#ifndef __NDPI_PROTOCOLS_H__
|
||||
#define __NDPI_PROTOCOLS_H__
|
||||
|
||||
#include "ndpi_main.h"
|
||||
|
||||
@@ -53,14 +52,9 @@ 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);
|
||||
@@ -72,6 +66,7 @@ void ndpi_search_oscar(struct ndpi_detection_module_struct *ndpi_struct, struct
|
||||
void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_sip(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_hep(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_direct_download_link_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_mail_pop_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
@@ -195,8 +190,10 @@ void ndpi_search_eaq(struct ndpi_detection_module_struct *ndpi_struct, struct nd
|
||||
void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
void ndpi_search_mpegts(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
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);
|
||||
/* --- 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);
|
||||
@@ -288,6 +285,7 @@ void init_rtsp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int
|
||||
void init_sflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
void init_shoutcast_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
void init_sip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
void init_hep_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
void init_skinny_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
void init_skype_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
void init_smb_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
@@ -295,6 +293,7 @@ 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);
|
||||
@@ -323,7 +322,6 @@ 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);
|
||||
@@ -332,5 +330,8 @@ void init_yahoo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_in
|
||||
void init_zattoo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
|
||||
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);
|
||||
|
||||
#endif /* __NDPI_PROTOCOLS_INCLUDE_FILE__ */
|
||||
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);
|
||||
#endif /* __NDPI_PROTOCOLS_H__ */
|
||||
|
||||
+328
-123
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_typedefs.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-11 - ipoque GmbH
|
||||
* 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
|
||||
@@ -22,94 +21,285 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NDPI_TYPEDEFS_FILE__
|
||||
#define __NDPI_TYPEDEFS_FILE__
|
||||
#ifndef __NDPI_TYPEDEFS_H__
|
||||
#define __NDPI_TYPEDEFS_H__
|
||||
|
||||
typedef enum {
|
||||
NDPI_LOG_ERROR,
|
||||
NDPI_LOG_TRACE,
|
||||
NDPI_LOG_DEBUG
|
||||
} ndpi_log_level_t;
|
||||
#include "ndpi_define.h"
|
||||
|
||||
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol,
|
||||
void *module_struct, ndpi_log_level_t log_level,
|
||||
const char *format, ...);
|
||||
#define BT_ANNOUNCE
|
||||
#define SNAP_EXT
|
||||
|
||||
typedef enum {
|
||||
ndpi_preorder,
|
||||
ndpi_postorder,
|
||||
ndpi_endorder,
|
||||
ndpi_leaf
|
||||
} ndpi_VISIT;
|
||||
|
||||
typedef struct node_t {
|
||||
/* NDPI_LOG_LEVEL */
|
||||
typedef enum
|
||||
{
|
||||
NDPI_LOG_ERROR,
|
||||
NDPI_LOG_TRACE,
|
||||
NDPI_LOG_DEBUG
|
||||
} ndpi_log_level_t;
|
||||
|
||||
/* NDPI_VISIT */
|
||||
typedef enum
|
||||
{
|
||||
ndpi_preorder,
|
||||
ndpi_postorder,
|
||||
ndpi_endorder,
|
||||
ndpi_leaf
|
||||
} ndpi_VISIT;
|
||||
|
||||
/* NDPI_NODE */
|
||||
typedef struct node_t
|
||||
{
|
||||
char *key;
|
||||
struct node_t *left, *right;
|
||||
} ndpi_node;
|
||||
|
||||
/* NDPI_MASK_SIZE */
|
||||
typedef u_int32_t ndpi_ndpi_mask;
|
||||
|
||||
typedef struct ndpi_protocol_bitmask_struct {
|
||||
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
|
||||
/* NDPI_PROTO_BITMASK_STRUCT */
|
||||
typedef struct ndpi_protocol_bitmask_struct
|
||||
{
|
||||
ndpi_ndpi_mask fds_bits[NDPI_NUM_FDS_BITS];
|
||||
} ndpi_protocol_bitmask_struct_t;
|
||||
|
||||
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
||||
struct ndpi_ip6_addr {
|
||||
union {
|
||||
u_int8_t u6_addr8[16];
|
||||
u_int16_t u6_addr16[8];
|
||||
u_int32_t u6_addr32[4];
|
||||
u_int64_t u6_addr64[2];
|
||||
} ndpi_v6_u;
|
||||
/* NDPI_DEBUG_FUNCTION_PTR (cast) */
|
||||
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, void *module_struct,
|
||||
ndpi_log_level_t log_level, const char *format, ...);
|
||||
|
||||
#define ndpi_v6_addr ndpi_v6_u.u6_addr8
|
||||
#define ndpi_v6_addr16 ndpi_v6_u.u6_addr16
|
||||
#define ndpi_v6_addr32 ndpi_v6_u.u6_addr32
|
||||
#define ndpi_v6_addr64 ndpi_v6_u.u6_addr64
|
||||
};
|
||||
|
||||
struct ndpi_ipv6hdr {
|
||||
/* use userspace and kernelspace compatible compile parameters */
|
||||
/* ************************************************************ */
|
||||
/* ******************* NDPI NETWORKS HEADERS ****************** */
|
||||
/* ************************************************************ */
|
||||
|
||||
/* ++++++++++++++++++++++++ Cisco headers +++++++++++++++++++++ */
|
||||
|
||||
/* Cisco HDLC */
|
||||
#ifdef _MSC_VER
|
||||
/* Windows */
|
||||
#define PACK_ON __pragma(pack(push, 1))
|
||||
#define PACK_OFF __pragma(pack(pop))
|
||||
#elif defined(__GNUC__)
|
||||
/* GNU C */
|
||||
#define PACK_ON
|
||||
#define PACK_OFF __attribute__((packed))
|
||||
#endif
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_chdlc
|
||||
{
|
||||
u_int8_t addr; /* 0x0F (Unicast) - 0x8F (Broadcast) */
|
||||
u_int8_t ctrl; /* always 0x00 */
|
||||
u_int16_t proto_code; /* protocol type (e.g. 0x0800 IP) */
|
||||
} PACK_OFF;
|
||||
|
||||
/* SLARP - Serial Line ARP http://tinyurl.com/qa54e95 */
|
||||
PACK_ON
|
||||
struct ndpi_slarp
|
||||
{
|
||||
/* address requests (0x00)
|
||||
address replies (0x01)
|
||||
keep-alive (0x02)
|
||||
*/
|
||||
u_int32_t slarp_type;
|
||||
u_int32_t addr_1;
|
||||
u_int32_t addr_2;
|
||||
} PACK_OFF;
|
||||
|
||||
/* Cisco Discovery Protocol http://tinyurl.com/qa6yw9l */
|
||||
PACK_ON
|
||||
struct ndpi_cdp
|
||||
{
|
||||
u_int8_t version;
|
||||
u_int8_t ttl;
|
||||
u_int16_t checksum;
|
||||
u_int16_t type;
|
||||
u_int16_t length;
|
||||
} PACK_OFF;
|
||||
|
||||
/* +++++++++++++++ Ethernet header (IEEE 802.3) +++++++++++++++ */
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_ethhdr
|
||||
{
|
||||
u_char h_dest[6]; /* destination eth addr */
|
||||
u_char h_source[6]; /* source ether addr */
|
||||
u_int16_t h_proto; /* data length (<= 1500) or type ID proto (>=1536) */
|
||||
} PACK_OFF;
|
||||
|
||||
/* +++++++++++++++++++ LLC header (IEEE 802.2) ++++++++++++++++ */
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_snap_extension
|
||||
{
|
||||
u_int16_t oui;
|
||||
u_int8_t oui2;
|
||||
u_int16_t proto_ID;
|
||||
} PACK_OFF;
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_llc_header
|
||||
{
|
||||
u_int8_t dsap;
|
||||
u_int8_t ssap;
|
||||
u_int8_t ctrl;
|
||||
#ifdef SNAP_EXT
|
||||
struct ndpi_snap_extension snap;
|
||||
#endif
|
||||
} PACK_OFF;
|
||||
|
||||
/* ++++++++++ RADIO TAP header (for IEEE 802.11) +++++++++++++ */
|
||||
PACK_ON
|
||||
struct ndpi_radiotap_header
|
||||
{
|
||||
u_int8_t version; /* set to 0 */
|
||||
u_int8_t pad;
|
||||
u_int16_t len;
|
||||
u_int32_t present;
|
||||
u_int64_t MAC_timestamp;
|
||||
u_int8_t flags;
|
||||
} PACK_OFF;
|
||||
|
||||
/* ++++++++++++ Wireless header (IEEE 802.11) ++++++++++++++++ */
|
||||
PACK_ON
|
||||
struct ndpi_wifi_header
|
||||
{
|
||||
u_int16_t fc;
|
||||
u_int16_t duration;
|
||||
u_char rcvr[6];
|
||||
u_char trsm[6];
|
||||
u_char dest[6];
|
||||
u_int16_t seq_ctrl;
|
||||
/* u_int64_t ccmp - for data encription only - check fc.flag */
|
||||
} PACK_OFF;
|
||||
|
||||
/* +++++++++++++++++++++++ MPLS header +++++++++++++++++++++++ */
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_mpls_header
|
||||
{
|
||||
u_int32_t label:20, exp:3, s:1, ttl:8;
|
||||
} PACK_OFF;
|
||||
|
||||
/* ++++++++++++++++++++++++ IP header ++++++++++++++++++++++++ */
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_iphdr {
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
u_int8_t priority:4, version:4;
|
||||
u_int8_t ihl:4, version:4;
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
u_int8_t version:4, priority:4;
|
||||
u_int8_t version:4, ihl:4;
|
||||
#else
|
||||
# error "Byte order must be defined"
|
||||
#endif
|
||||
u_int8_t tos;
|
||||
u_int16_t tot_len;
|
||||
u_int16_t id;
|
||||
u_int16_t frag_off;
|
||||
u_int8_t ttl;
|
||||
u_int8_t protocol;
|
||||
u_int16_t check;
|
||||
u_int32_t saddr;
|
||||
u_int32_t daddr;
|
||||
} PACK_OFF;
|
||||
|
||||
u_int8_t flow_lbl[3];
|
||||
/* +++++++++++++++++++++++ IPv6 header +++++++++++++++++++++++ */
|
||||
/* rfc3542 */
|
||||
|
||||
u_int16_t payload_len;
|
||||
u_int8_t nexthdr;
|
||||
u_int8_t hop_limit;
|
||||
|
||||
struct ndpi_ip6_addr saddr;
|
||||
struct ndpi_ip6_addr daddr;
|
||||
struct ndpi_in6_addr
|
||||
{
|
||||
union
|
||||
{
|
||||
u_int8_t u6_addr8[16];
|
||||
u_int16_t u6_addr16[8];
|
||||
u_int32_t u6_addr32[4];
|
||||
} u6_addr; /* 128-bit IP6 address */
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
PACK_ON
|
||||
struct ndpi_ipv6hdr
|
||||
{
|
||||
union
|
||||
{
|
||||
struct ndpi_ip6_hdrctl
|
||||
{
|
||||
u_int32_t ip6_un1_flow;
|
||||
u_int16_t ip6_un1_plen;
|
||||
u_int8_t ip6_un1_nxt;
|
||||
u_int8_t ip6_un1_hlim;
|
||||
} ip6_un1;
|
||||
u_int8_t ip6_un2_vfc;
|
||||
} ip6_ctlun;
|
||||
|
||||
struct ndpi_in6_addr ip6_src;
|
||||
struct ndpi_in6_addr ip6_dst;
|
||||
} PACK_OFF;
|
||||
|
||||
/* +++++++++++++++++++++++ TCP header +++++++++++++++++++++++ */
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_tcphdr
|
||||
{
|
||||
u_int16_t source;
|
||||
u_int16_t dest;
|
||||
u_int32_t seq;
|
||||
u_int32_t ack_seq;
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
u_int16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
u_int16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1;
|
||||
#else
|
||||
# error "Byte order must be defined"
|
||||
#endif
|
||||
u_int16_t window;
|
||||
u_int16_t check;
|
||||
u_int16_t urg_ptr;
|
||||
} PACK_OFF;
|
||||
|
||||
/* +++++++++++++++++++++++ UDP header +++++++++++++++++++++++ */
|
||||
|
||||
PACK_ON
|
||||
struct ndpi_udphdr
|
||||
{
|
||||
u_int16_t source;
|
||||
u_int16_t dest;
|
||||
u_int16_t len;
|
||||
u_int16_t check;
|
||||
} PACK_OFF;
|
||||
|
||||
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;
|
||||
} PACK_OFF;
|
||||
|
||||
typedef union
|
||||
{
|
||||
u_int32_t ipv4;
|
||||
u_int8_t ipv4_u_int8_t[4];
|
||||
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
||||
struct ndpi_ip6_addr ipv6;
|
||||
struct ndpi_in6_addr ipv6;
|
||||
#endif
|
||||
} ndpi_ip_addr_t;
|
||||
|
||||
/* ************************************************************ */
|
||||
/* ******************* ********************* ****************** */
|
||||
/* ************************************************************ */
|
||||
|
||||
#ifdef NDPI_PROTOCOL_BITTORRENT
|
||||
#ifndef __KERNEL__
|
||||
|
||||
typedef struct spinlock {
|
||||
volatile int val;
|
||||
} spinlock_t;
|
||||
|
||||
typedef struct atomic {
|
||||
volatile int counter;
|
||||
} atomic_t;
|
||||
|
||||
#endif
|
||||
|
||||
struct hash_ip4p_node {
|
||||
struct hash_ip4p_node *next,*prev;
|
||||
time_t lchg;
|
||||
@@ -154,17 +344,13 @@ typedef enum {
|
||||
HTTP_METHOD_CONNECT
|
||||
} ndpi_http_method;
|
||||
|
||||
typedef struct ndpi_id_struct {
|
||||
/* detected_protocol_bitmask:
|
||||
* access this bitmask to find out whether an id has used skype or not
|
||||
* if a flag is set here, it will not be resetted
|
||||
* to compare this, use:
|
||||
* if (NDPI_BITMASK_COMPARE(id->detected_protocol_bitmask,
|
||||
* NDPI_PROTOCOL_BITMASK_XXX) != 0)
|
||||
* {
|
||||
* // protocol XXX detected on this id
|
||||
* }
|
||||
*/
|
||||
struct ndpi_id_struct {
|
||||
/**
|
||||
detected_protocol_bitmask:
|
||||
access this bitmask to find out whether an id has used skype or not
|
||||
if a flag is set here, it will not be resetted
|
||||
to compare this, use:
|
||||
**/
|
||||
NDPI_PROTOCOL_BITMASK detected_protocol_bitmask;
|
||||
#ifdef NDPI_PROTOCOL_RTSP
|
||||
ndpi_ip_addr_t rtsp_ip_address;
|
||||
@@ -254,7 +440,7 @@ typedef struct ndpi_id_struct {
|
||||
#ifdef NDPI_PROTOCOL_RTSP
|
||||
u_int32_t rtsp_ts_set:1;
|
||||
#endif
|
||||
} ndpi_id_struct;
|
||||
};
|
||||
|
||||
/* ************************************************** */
|
||||
|
||||
@@ -287,9 +473,6 @@ 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
|
||||
@@ -310,7 +493,7 @@ struct ndpi_flow_tcp_struct {
|
||||
u_int32_t http_stage:2;
|
||||
u_int32_t http_empty_line_seen:1;
|
||||
u_int32_t http_wait_for_retransmission:1;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NDPI_PROTOCOL_GNUTELLA
|
||||
u_int32_t gnutella_stage:2; // 0 - 2
|
||||
#endif
|
||||
@@ -390,7 +573,7 @@ struct ndpi_flow_tcp_struct {
|
||||
u_char prev_zmq_pkt[10];
|
||||
#endif
|
||||
}
|
||||
#if !defined(WIN32)
|
||||
#ifndef WIN32
|
||||
__attribute__ ((__packed__))
|
||||
#endif
|
||||
;
|
||||
@@ -438,20 +621,24 @@ 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
|
||||
}
|
||||
#if !defined(WIN32)
|
||||
#ifndef WIN32
|
||||
__attribute__ ((__packed__))
|
||||
#endif
|
||||
;
|
||||
|
||||
/* ************************************************** */
|
||||
|
||||
typedef struct ndpi_int_one_line_struct {
|
||||
struct ndpi_int_one_line_struct {
|
||||
const u_int8_t *ptr;
|
||||
u_int16_t len;
|
||||
} ndpi_int_one_line_struct_t;
|
||||
};
|
||||
|
||||
typedef struct ndpi_packet_struct {
|
||||
struct ndpi_packet_struct {
|
||||
const struct ndpi_iphdr *iph;
|
||||
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
||||
const struct ndpi_ipv6hdr *iphv6;
|
||||
@@ -468,10 +655,10 @@ typedef struct ndpi_packet_struct {
|
||||
u_int8_t detected_subprotocol_stack[NDPI_PROTOCOL_HISTORY_SIZE];
|
||||
|
||||
|
||||
#if !defined(WIN32)
|
||||
__attribute__ ((__packed__))
|
||||
#ifndef WIN32
|
||||
__attribute__ ((__packed__))
|
||||
#endif
|
||||
u_int16_t protocol_stack_info;
|
||||
u_int16_t protocol_stack_info;
|
||||
|
||||
struct ndpi_int_one_line_struct line[NDPI_MAX_PARSE_LINES_PER_PACKET];
|
||||
struct ndpi_int_one_line_struct host_line;
|
||||
@@ -506,22 +693,22 @@ typedef 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;
|
||||
|
||||
typedef struct ndpi_call_function_struct {
|
||||
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;
|
||||
};
|
||||
|
||||
typedef struct ndpi_subprotocol_conf_struct {
|
||||
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 {
|
||||
@@ -564,7 +751,8 @@ typedef struct ndpi_proto {
|
||||
|
||||
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN }
|
||||
|
||||
typedef struct ndpi_detection_module_struct {
|
||||
struct ndpi_detection_module_struct {
|
||||
|
||||
NDPI_PROTOCOL_BITMASK detection_bitmask;
|
||||
NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask;
|
||||
|
||||
@@ -574,7 +762,7 @@ typedef struct ndpi_detection_module_struct {
|
||||
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
|
||||
void *user_data;
|
||||
#endif
|
||||
|
||||
|
||||
/* callback function buffer */
|
||||
struct ndpi_call_function_struct callback_buffer[NDPI_MAX_SUPPORTED_PROTOCOLS + 1];
|
||||
u_int32_t callback_buffer_size;
|
||||
@@ -617,6 +805,7 @@ typedef 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;
|
||||
|
||||
@@ -660,49 +849,53 @@ typedef struct ndpi_detection_module_struct {
|
||||
|
||||
ndpi_proto_defaults_t proto_defaults[NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS];
|
||||
|
||||
u_int8_t match_dns_host_names:1, http_dont_dissect_response:1;
|
||||
u_int8_t http_dont_dissect_response:1;
|
||||
u_int8_t direction_detect_disable:1; /* disable internal detection of packet direction */
|
||||
} ndpi_detection_module_struct_t;
|
||||
};
|
||||
|
||||
typedef struct ndpi_flow_struct {
|
||||
struct ndpi_flow_struct {
|
||||
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_HISTORY_SIZE];
|
||||
#if !defined(WIN32)
|
||||
__attribute__ ((__packed__))
|
||||
#ifndef WIN32
|
||||
__attribute__ ((__packed__))
|
||||
#endif
|
||||
u_int16_t protocol_stack_info;
|
||||
u_int16_t protocol_stack_info;
|
||||
|
||||
/* init parameter, internal used to set up timestamp,... */
|
||||
u_int16_t guessed_protocol_id;
|
||||
u_int16_t guessed_protocol_id, guessed_host_protocol_id;
|
||||
|
||||
u_int8_t protocol_id_already_guessed:1;
|
||||
u_int8_t init_finished:1;
|
||||
u_int8_t setup_packet_direction:1;
|
||||
u_int8_t packet_direction:1; /* if ndpi_struct->direction_detect_disable == 1 */
|
||||
/* tcp sequence number connection tracking */
|
||||
u_int8_t protocol_id_already_guessed:1, host_already_guessed:1, init_finished:1, setup_packet_direction:1, packet_direction:1;
|
||||
|
||||
/*
|
||||
if ndpi_struct->direction_detect_disable == 1
|
||||
tcp sequence number connection tracking
|
||||
*/
|
||||
u_int32_t next_tcp_seq_nr[2];
|
||||
|
||||
/* the tcp / udp / other l4 value union
|
||||
* this is used to reduce the number of bytes for tcp or udp protocol states
|
||||
* */
|
||||
/*
|
||||
the tcp / udp / other l4 value union
|
||||
used to reduce the number of bytes for tcp or udp protocol states
|
||||
*/
|
||||
union {
|
||||
struct ndpi_flow_tcp_struct tcp;
|
||||
struct ndpi_flow_udp_struct udp;
|
||||
} l4;
|
||||
|
||||
struct ndpi_id_struct *server_id; /*
|
||||
Pointer to src or dst
|
||||
that identifies the
|
||||
server of this connection
|
||||
*/
|
||||
#ifndef __KERNEL__
|
||||
u_char host_server_name[256]; /* HTTP host or DNS query */
|
||||
#else
|
||||
u_char host_server_name[160];
|
||||
#endif
|
||||
u_char detected_os[32]; /* Via HTTP User-Agent */
|
||||
u_char nat_ip[24]; /* Via HTTP X-Forwarded-For */
|
||||
/*
|
||||
Pointer to src or dst
|
||||
that identifies the
|
||||
server of this connection
|
||||
*/
|
||||
struct ndpi_id_struct *server_id;
|
||||
/* HTTP host or DNS query */
|
||||
u_char host_server_name[192];
|
||||
/* 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
|
||||
structure below as HTTP is used by many subprotocols
|
||||
such as FaceBook, Google... so it is hard to know
|
||||
@@ -710,27 +903,29 @@ typedef struct ndpi_flow_struct {
|
||||
time being.
|
||||
*/
|
||||
struct {
|
||||
ndpi_http_method method;
|
||||
ndpi_http_method method;
|
||||
char *url, *content_type;
|
||||
} http;
|
||||
|
||||
union {
|
||||
|
||||
/* the only fields useful for nDPI and ntopng */
|
||||
struct {
|
||||
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;
|
||||
u_int8_t num_answers, ret_code;
|
||||
u_int16_t query_type;
|
||||
} dns;
|
||||
|
||||
|
||||
struct {
|
||||
u_int8_t request_code;
|
||||
u_int8_t version;
|
||||
} ntp;
|
||||
|
||||
|
||||
struct {
|
||||
char client_certificate[48], server_certificate[48];
|
||||
} ssl;
|
||||
} protos;
|
||||
/* ALL protocol specific 64 bit variables here */
|
||||
|
||||
/*** ALL protocol specific 64 bit variables here ***/
|
||||
|
||||
/* protocols which have marked a connection as this connection cannot be protocol XXX, multiple u_int64_t */
|
||||
NDPI_PROTOCOL_BITMASK excluded_protocol_bitmask;
|
||||
@@ -756,7 +951,7 @@ typedef struct ndpi_flow_struct {
|
||||
#endif
|
||||
#ifdef NDPI_PROTOCOL_HTTP
|
||||
u_int32_t http_detected:1;
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NDPI_PROTOCOL_RTSP
|
||||
u_int32_t rtsprdt_stage:2;
|
||||
u_int32_t rtsp_control_flow:1;
|
||||
@@ -780,10 +975,8 @@ typedef struct ndpi_flow_struct {
|
||||
#ifdef NDPI_PROTOCOL_FLORENSIA
|
||||
u_int32_t florensia_stage:1;
|
||||
#endif
|
||||
#ifdef NDPI_PROTOCOL_SOCKS5
|
||||
#ifdef NDPI_PROTOCOL_SOCKS
|
||||
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
|
||||
@@ -818,6 +1011,18 @@ typedef struct ndpi_flow_struct {
|
||||
struct ndpi_flow_struct *flow;
|
||||
struct ndpi_id_struct *src;
|
||||
struct ndpi_id_struct *dst;
|
||||
} ndpi_flow_struct_t;
|
||||
};
|
||||
|
||||
#endif/* __NDPI_TYPEDEFS_FILE__ */
|
||||
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;
|
||||
|
||||
#endif/* __NDPI_TYPEDEFS_H__ */
|
||||
|
||||
+1
-11
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_unix.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-2011 by ipoque GmbH
|
||||
* 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
|
||||
@@ -25,8 +24,6 @@
|
||||
#ifndef __NDPI_UNIX_INCLUDE_FILE__
|
||||
#define __NDPI_UNIX_INCLUDE_FILE__
|
||||
|
||||
#include "linux_compat.h"
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
#include <netinet/in.h>
|
||||
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
@@ -38,16 +35,9 @@
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#ifndef __KERNEL__
|
||||
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#else
|
||||
#include <linux/ip.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* __NDPI_UNIX_INCLUDE_FILE__ */
|
||||
|
||||
+18
-23
@@ -1,8 +1,7 @@
|
||||
/*
|
||||
* ndpi_win32.h
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* Copyright (C) 2009-2011 by ipoque GmbH
|
||||
* 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
|
||||
@@ -22,36 +21,34 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NDPI_WIN32_INCLUDE_FILE__
|
||||
#define __NDPI_WIN32_INCLUDE_FILE__
|
||||
#ifndef __NDPI_WIN32_H__
|
||||
#define __NDPI_WIN32_H__
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h> /* winsock.h is included automatically */
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <process.h>
|
||||
#include <io.h>
|
||||
#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
|
||||
#include <process.h> /* for getpid() and the exec..() family */
|
||||
#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
|
||||
#include <process.h> /* for getpid() and the exec..() family */
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
#define snprintf _snprintf
|
||||
|
||||
extern char* strsep(char **stringp, const char *delim);
|
||||
#define _WS2TCPIP_H_ /* Avoid compilation problems */
|
||||
|
||||
extern char* strsep(char **sp, const char *sep);
|
||||
|
||||
#define __attribute__(x)
|
||||
#include <stdint.h>
|
||||
#ifndef __GNUC__
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned short u_short;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long u_long;
|
||||
#endif
|
||||
typedef u_char u_int8_t;
|
||||
typedef u_short u_int16_t;
|
||||
typedef unsigned int u_int32_t;
|
||||
typedef unsigned __int64 u_int64_t;
|
||||
|
||||
typedef u_char u_int8_t;
|
||||
typedef u_short u_int16_t;
|
||||
typedef uint u_int32_t;
|
||||
typedef uint u_int;
|
||||
typedef unsigned __int64 u_int64_t;
|
||||
|
||||
#define pthread_t HANDLE
|
||||
#define pthread_mutex_t HANDLE
|
||||
@@ -62,12 +59,10 @@ typedef unsigned __int64 u_int64_t;
|
||||
#define pthread_rwlock_unlock pthread_mutex_unlock
|
||||
#define pthread_rwlock_destroy pthread_mutex_destroy
|
||||
|
||||
#define gmtime_r(a, b) gmtime(a) /* Already thread safe on windows */
|
||||
#define gmtime_r(a, b) memcpy(b, gmtime(a), sizeof(struct tm))
|
||||
|
||||
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
|
||||
|
||||
#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
|
||||
|
||||
#endif /* Win32 */
|
||||
|
||||
#endif /* __NDPI_WIN32_INCLUDE_FILE__ */
|
||||
#endif /* __NDPI_WIN32_H__ */
|
||||
|
||||
+8
-8
@@ -7,14 +7,12 @@ libndpi_la_LDFLAGS = -version-info 1:0:0 -export-symbols $(top_srcdir)/libndpi.s
|
||||
libndpi_la_includedir = $(includedir)/libndpi-@VERSION@/libndpi
|
||||
|
||||
libndpi_la_include_HEADERS = ../include/ndpi_api.h \
|
||||
../include/linux_compat.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_unix.h \
|
||||
../include/ndpi_win32.h
|
||||
../include/ndpi_typedefs.h
|
||||
|
||||
libndpi_la_SOURCES = ndpi_content_match.c.inc \
|
||||
ndpi_main.c \
|
||||
@@ -52,6 +50,7 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
|
||||
protocols/guildwars.c \
|
||||
protocols/h323.c \
|
||||
protocols/halflife2_and_mods.c \
|
||||
protocols/hep.c \
|
||||
protocols/http_activesync.c \
|
||||
protocols/http.c \
|
||||
protocols/iax.c \
|
||||
@@ -112,8 +111,7 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
|
||||
protocols/skype.c \
|
||||
protocols/smb.c \
|
||||
protocols/snmp.c \
|
||||
protocols/socks4.c \
|
||||
protocols/socks5.c \
|
||||
protocols/socks45.c \
|
||||
protocols/socrates.c \
|
||||
protocols/sopcast.c \
|
||||
protocols/soulseek.c \
|
||||
@@ -139,15 +137,14 @@ 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 \
|
||||
@@ -155,6 +152,9 @@ libndpi_la_SOURCES = ndpi_content_match.c.inc \
|
||||
protocols/yahoo.c \
|
||||
protocols/zattoo.c \
|
||||
protocols/zeromq.c \
|
||||
protocols/coap.c \
|
||||
protocols/mqtt.c \
|
||||
protocols/rx.c \
|
||||
third_party/include/actypes.h \
|
||||
third_party/include/ahocorasick.h \
|
||||
third_party/include/node.h \
|
||||
|
||||
+185
-171
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* ndpi_content_match.c
|
||||
*
|
||||
* Copyright (C) 2011-15 - ntop.org
|
||||
* 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
|
||||
@@ -18,21 +18,98 @@
|
||||
*
|
||||
*/
|
||||
|
||||
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
|
||||
@@ -48,10 +125,16 @@ static ndpi_network host_protocol_list[] = {
|
||||
{ 0x4272A000 /* 66.114.160.0 */, 20, NDPI_PROTOCOL_WEBEX },
|
||||
|
||||
/*
|
||||
Viber
|
||||
54.171.62.0/24
|
||||
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
|
||||
*/
|
||||
{ 0x36AB3E00 /* 54.171.62.0 */, 24, NDPI_PROTOCOL_VIBER },
|
||||
{ 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 },
|
||||
|
||||
/*
|
||||
Apple (FaceTime, iMessage,...)
|
||||
@@ -63,22 +146,26 @@ 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 },
|
||||
{ 0x6CA0A000 /* 108.160.160.0 */, 20, NDPI_PROTOCOL_DROPBOX },
|
||||
{ 0x2D3A4000 /* 45.58.64.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
|
||||
@@ -90,9 +177,15 @@ 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)
|
||||
@@ -118,155 +211,7 @@ 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},
|
||||
|
||||
/* 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 },
|
||||
|
||||
/* TOR */
|
||||
{ 0x012A1231, 32, NDPI_PROTOCOL_TOR },
|
||||
{ 0x01E69FA1, 32, NDPI_PROTOCOL_TOR },
|
||||
{ 0x020DE985, 32, NDPI_PROTOCOL_TOR },
|
||||
@@ -7313,6 +7258,7 @@ 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 },
|
||||
@@ -7320,13 +7266,19 @@ 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 */
|
||||
{ "fbcdn-", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN }, /* fbcdn-video-a-akamaihd.net */
|
||||
{ ".facebook.net", "Facebook", NDPI_SERVICE_FACEBOOK, NDPI_PROTOCOL_FUN },
|
||||
{ ".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 },
|
||||
@@ -7349,23 +7301,26 @@ 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.net", "WhatsApp", NDPI_SERVICE_WHATSAPP, NDPI_PROTOCOL_ACCEPTABLE },
|
||||
{ ".whatsapp.", "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 },
|
||||
@@ -7384,6 +7339,13 @@ 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 },
|
||||
@@ -7411,12 +7373,51 @@ 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 }
|
||||
};
|
||||
|
||||
@@ -7462,6 +7463,18 @@ 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 }
|
||||
};
|
||||
|
||||
@@ -7536,3 +7549,4 @@ 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 };
|
||||
|
||||
|
||||
+565
-524
File diff suppressed because it is too large
Load Diff
@@ -23,8 +23,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
@@ -22,8 +22,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* include files */
|
||||
|
||||
#include "ndpi_protocols.h"
|
||||
|
||||
#ifdef NDPI_PROTOCOL_ARMAGETRON
|
||||
|
||||
|
||||
|
||||
+15
-15
@@ -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;
|
||||
|
||||
// struct ndpi_id_struct *src=ndpi_struct->src;
|
||||
// struct ndpi_id_struct *dst=ndpi_struct->dst;
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
u_int16_t bgp_port = htons(179);
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BGP);
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_BGP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+137
-114
@@ -25,15 +25,53 @@
|
||||
|
||||
#include "ndpi_protocols.h"
|
||||
#ifdef NDPI_PROTOCOL_BITTORRENT
|
||||
#define NDPI_PROTOCOL_UNSAFE_DETECTION 0
|
||||
#define NDPI_PROTOCOL_SAFE_DETECTION 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
|
||||
|
||||
|
||||
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_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/* , */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
@@ -43,96 +81,89 @@ 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 (memcmp(&packet->payload[0], "BitTorrent protocol", 19) == 0) {
|
||||
if(flow->packet_counter == 2 && packet->payload_packet_len > 20) {
|
||||
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,
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, 19, 1,
|
||||
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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_REAL_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);
|
||||
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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
|
||||
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,
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
|
||||
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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
|
||||
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 ",
|
||||
@@ -160,15 +191,13 @@ 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,
|
||||
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
|
||||
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;",
|
||||
@@ -187,13 +216,12 @@ 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,
|
||||
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
|
||||
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;",
|
||||
@@ -209,19 +237,17 @@ 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,
|
||||
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_UNSAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
|
||||
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--;
|
||||
@@ -237,40 +263,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 {
|
||||
@@ -280,15 +306,14 @@ 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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
|
||||
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 |
|
||||
@@ -306,30 +331,28 @@ 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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_REAL_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
|
||||
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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION/* , */
|
||||
/* NDPI_CORRELATED_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_WEBSEED_DETECTION);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -341,17 +364,16 @@ 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;
|
||||
@@ -367,6 +389,7 @@ 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
|
||||
@@ -378,10 +401,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);
|
||||
}
|
||||
@@ -400,9 +423,8 @@ 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,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION/* , */
|
||||
/* NDPI_REAL_PROTOCOL */);
|
||||
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 1,
|
||||
NDPI_PROTOCOL_SAFE_DETECTION, NDPI_PROTOCOL_PLAIN_DETECTION);
|
||||
return;
|
||||
} else {
|
||||
/* Check if this is protocol v0 */
|
||||
@@ -414,34 +436,31 @@ 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((packet->payload[0]== 0x60)
|
||||
if(is_utp_pkt(packet->payload, packet->payload_packet_len))
|
||||
goto bittorrent_found;
|
||||
else 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;
|
||||
}
|
||||
}
|
||||
@@ -451,24 +470,28 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
flow->bittorrent_stage++;
|
||||
|
||||
if(flow->bittorrent_stage < 10) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@ 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) {
|
||||
@@ -183,11 +181,8 @@ static void _print_safe_str(char *msg,char *k,const u_int8_t *s,size_t l) {
|
||||
static void print_safe_str(char *msg,bt_parse_data_cb_t *cbd) {
|
||||
_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 DEBUG_TRACE(cmd) { if(bt_parse_debug) cmd; }
|
||||
#define STREQ(a,b) !strcmp(a,b)
|
||||
|
||||
|
||||
|
||||
@@ -139,9 +139,7 @@ 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);
|
||||
|
||||
|
||||
@@ -33,14 +33,6 @@ 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++;
|
||||
|
||||
@@ -70,7 +62,6 @@ 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);
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
||||
// header too short
|
||||
if(packet->payload_packet_len < 4) {
|
||||
|
||||
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
|
||||
@@ -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,20 +35,21 @@ 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)
|
||||
&& ((ntohs(packet->tcp->source) == 135) || (ntohs(packet->tcp->dest) == 135))
|
||||
if((packet->tcp != NULL)
|
||||
&& (packet->payload_packet_len >= 64)
|
||||
&& (packet->payload[0] == 0x05) /* version 5 */
|
||||
&& (packet->payload[2] < 16) /* Packet type */
|
||||
) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_DCERPC, ndpi_struct, NDPI_LOG_DEBUG, "DCERPC match\n");
|
||||
&& (((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_int_dcerpc_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
}
|
||||
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DCERPC);
|
||||
if(packet->payload_packet_len>1){
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_DCERPC);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+15
-15
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -709,23 +709,10 @@ 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;
|
||||
#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
|
||||
/* 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 */
|
||||
if (packet->detected_protocol_stack[0] != NDPI_PROTOCOL_DIRECT_DOWNLOAD_LINK) {
|
||||
if (search_ddl_domains(ndpi_struct, flow) != 0) {
|
||||
return;
|
||||
|
||||
+100
-252
@@ -1,7 +1,9 @@
|
||||
/*
|
||||
* dns.c
|
||||
*
|
||||
* Copyright (C) 2012-15 - ntop.org
|
||||
* Copyright (C) 2012-16 - ntop.org
|
||||
*
|
||||
* Michele Campus - <campus@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,285 +23,131 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "ndpi_protocols.h"
|
||||
|
||||
#ifdef NDPI_PROTOCOL_DNS
|
||||
|
||||
static u_int getNameLength(u_int i, const u_int8_t *payload, u_int payloadLen) {
|
||||
if(payload[i] == 0x00)
|
||||
return(1);
|
||||
else if(payload[i] == 0xC0)
|
||||
return(2);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/* *********************************************** */
|
||||
|
||||
static char* ndpi_intoa_v4(unsigned int addr, char* buf, u_short bufLen) {
|
||||
char *cp, *retStr;
|
||||
uint byte;
|
||||
int n;
|
||||
|
||||
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));
|
||||
#define FLAGS_MASK 0x8000
|
||||
|
||||
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");
|
||||
int x;
|
||||
u_int8_t is_query, ret_code;
|
||||
u_int16_t s_port = 0;
|
||||
u_int16_t d_port = 0;
|
||||
|
||||
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");
|
||||
NDPI_LOG(NDPI_PROTOCOL_DNS, ndpi_struct, NDPI_LOG_DEBUG, "search DNS.\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);
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
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;
|
||||
/* 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(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
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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++;
|
||||
|
||||
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((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(!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 */
|
||||
} else
|
||||
invalid = 1;
|
||||
} else {
|
||||
/* DNS Reply */
|
||||
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 */
|
||||
} else
|
||||
invalid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(is_dns) {
|
||||
int j = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
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; 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)));
|
||||
/* extract host name server */
|
||||
ret_code = (is_query == 0) ? 0 : (dns_header.flags & 0x0F);
|
||||
int j = 0;
|
||||
int 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 < strlen((char*)flow->host_server_name)) {
|
||||
if(flow->host_server_name[j] < ' ')
|
||||
flow->host_server_name[j] = '.';
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
flow->host_server_name[j] = '\0';
|
||||
off++;
|
||||
}
|
||||
flow->host_server_name[j] = '\0';
|
||||
|
||||
if(j > 0) {
|
||||
#ifdef DEBUG
|
||||
printf("==> %s\n", flow->host_server_name);
|
||||
#endif
|
||||
flow->protos.dns.num_answers = (u_int8_t) (dns_header.num_answers + dns_header.authority_rrs + dns_header.additional_rrs);
|
||||
flow->protos.dns.ret_code = ret_code;
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
|
||||
if(flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)
|
||||
{
|
||||
/**
|
||||
Do not set the protocol with DNS if ndpi_match_host_subprotocol() has
|
||||
matched a subprotocol
|
||||
**/
|
||||
NDPI_LOG(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 {
|
||||
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,
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#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)
|
||||
@@ -40,12 +44,14 @@ 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(17500);
|
||||
|
||||
u_int16_t dropbox_port = htons(DB_LSP_PORT);
|
||||
|
||||
if((packet->udp->source == dropbox_port)
|
||||
&& (packet->udp->dest == dropbox_port)) {
|
||||
if(payload_len > 2) {
|
||||
if(strncmp((const char *)packet->payload, "{\"", 2) == 0) {
|
||||
if(strncmp((const char *)packet->payload, "{\"host_int\"", 11) == 0) {
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_DROPBOX, ndpi_struct, NDPI_LOG_DEBUG, "Found dropbox.\n");
|
||||
ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0);
|
||||
return;
|
||||
|
||||
+228
-228
File diff suppressed because it is too large
Load Diff
@@ -60,13 +60,14 @@ 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(match_first_bytes(packet->payload, "RIFF"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "RIFF"))
|
||||
return 1;
|
||||
|
||||
/* MZ is a .exe file */
|
||||
@@ -74,7 +75,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* Ogg files */
|
||||
if(match_first_bytes(packet->payload, "OggS"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "OggS"))
|
||||
return 1;
|
||||
|
||||
/* ZIP files */
|
||||
@@ -86,7 +87,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* RAR files */
|
||||
if(match_first_bytes(packet->payload, "Rar!"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "Rar!"))
|
||||
return 1;
|
||||
|
||||
/* EBML */
|
||||
@@ -98,7 +99,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* GIF */
|
||||
if(match_first_bytes(packet->payload, "GIF8"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "GIF8"))
|
||||
return 1;
|
||||
|
||||
/* PHP scripts */
|
||||
@@ -110,7 +111,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* PDFs */
|
||||
if(match_first_bytes(packet->payload, "%PDF"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "%PDF"))
|
||||
return 1;
|
||||
|
||||
/* PNG */
|
||||
@@ -118,7 +119,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* HTML */
|
||||
if(match_first_bytes(packet->payload, "<htm"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "<htm"))
|
||||
return 1;
|
||||
if((packet->payload[0] == 0x0a) && (packet->payload[1] == '<') && (packet->payload[2] == '!') && (packet->payload[3] == 'D'))
|
||||
return 1;
|
||||
@@ -132,17 +133,17 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* XML */
|
||||
if(match_first_bytes(packet->payload, "<!DO"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "<!DO"))
|
||||
return 1;
|
||||
|
||||
/* FLAC */
|
||||
if(match_first_bytes(packet->payload, "fLaC"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "fLaC"))
|
||||
return 1;
|
||||
|
||||
/* MP3 */
|
||||
if((packet->payload[0] == 'I') && (packet->payload[1] == 'D') && (packet->payload[2] == '3') && (packet->payload[3] == 0x03))
|
||||
return 1;
|
||||
if(match_first_bytes(packet->payload, "\xff\xfb\x90\xc0"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "\xff\xfb\x90\xc0"))
|
||||
return 1;
|
||||
|
||||
/* RPM */
|
||||
@@ -150,7 +151,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* Wz Patch */
|
||||
if(match_first_bytes(packet->payload, "WzPa"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "WzPa"))
|
||||
return 1;
|
||||
|
||||
/* Flash Video */
|
||||
@@ -158,7 +159,7 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* .BKF (Microsoft Tape Format) */
|
||||
if(match_first_bytes(packet->payload, "TAPE"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "TAPE"))
|
||||
return 1;
|
||||
|
||||
/* MS Office Doc file - this is unpleasantly geeky */
|
||||
@@ -174,23 +175,23 @@ static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return 1;
|
||||
|
||||
/* ar archive, typically .deb files */
|
||||
if(match_first_bytes(packet->payload, "!<ar"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "!<ar"))
|
||||
return 1;
|
||||
|
||||
/* Raw XML (skip jabber-like traffic as this is not FTP but unencrypted jabber) */
|
||||
if((match_first_bytes(packet->payload, "<?xm"))
|
||||
if((ndpi_match_strprefix(packet->payload, payload_len, "<?xm"))
|
||||
&& (ndpi_strnstr((const char *)packet->payload, "jabber", packet->payload_packet_len) == NULL))
|
||||
return 1;
|
||||
|
||||
if(match_first_bytes(packet->payload, "<iq "))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "<iq "))
|
||||
return 1;
|
||||
|
||||
/* SPF */
|
||||
if(match_first_bytes(packet->payload, "SPFI"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "SPFI"))
|
||||
return 1;
|
||||
|
||||
/* ABIF - Applied Biosystems */
|
||||
if(match_first_bytes(packet->payload, "ABIF"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, "ABIF"))
|
||||
return 1;
|
||||
|
||||
/* bzip2 - other digits are also possible instead of 9 */
|
||||
@@ -203,11 +204,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(match_first_bytes(packet->payload, ".tem"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, ".tem"))
|
||||
return 1;
|
||||
if(match_first_bytes(packet->payload, ".ite"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, ".ite"))
|
||||
return 1;
|
||||
if(match_first_bytes(packet->payload, ".lef"))
|
||||
if(ndpi_match_strprefix(packet->payload, payload_len, ".lef"))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@@ -229,7 +230,6 @@ 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) {
|
||||
|
||||
@@ -294,7 +294,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
|
||||
return;
|
||||
}
|
||||
|
||||
if (memcmp(packet->payload, "GND", 3) == 0) {
|
||||
if (packet->payload_packet_len >= 3 && 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
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "ndpi_api.h"
|
||||
|
||||
#ifdef NDPI_PROTOCOL_GTP
|
||||
@@ -35,14 +34,6 @@ 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);
|
||||
|
||||
@@ -27,7 +27,8 @@ 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[0] == 0x03)
|
||||
if(packet->payload_packet_len >= 3
|
||||
&& (packet->payload[0] == 0x03)
|
||||
&& (packet->payload[1] == 0x00)
|
||||
&& (packet->payload[2] == 0x00)) {
|
||||
struct tpkt *t = (struct tpkt*)packet->payload;
|
||||
@@ -63,7 +64,8 @@ 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[0] == 0x80 && packet->payload[1] == 0x08 && (packet->payload[2] == 0xe7 || packet->payload[2] == 0x26) &&
|
||||
if(packet->payload_packet_len >= 5 && 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");
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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
|
||||
+19
-35
@@ -37,18 +37,14 @@ 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) {
|
||||
ndpi_search_tcp_or_udp(ndpi_struct, flow);
|
||||
ndpi_set_detected_protocol(ndpi_struct, flow, protocol, NDPI_PROTOCOL_UNKNOWN);
|
||||
} else {
|
||||
if(protocol == NDPI_PROTOCOL_HTTP)
|
||||
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
|
||||
@@ -202,21 +198,14 @@ 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
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -247,7 +236,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';
|
||||
}
|
||||
@@ -282,8 +271,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';
|
||||
}
|
||||
}
|
||||
@@ -349,14 +338,6 @@ 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 */
|
||||
@@ -367,11 +348,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);
|
||||
@@ -771,6 +752,8 @@ 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;
|
||||
@@ -911,6 +894,7 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = (packet->line[packet->parsed_lines - 1].ptr - packet->payload) + 2;
|
||||
u_int16_t http_header_len = (u_int16_t)((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;
|
||||
}
|
||||
|
||||
@@ -30,12 +30,10 @@
|
||||
#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 > 0)
|
||||
&& (packet->payload_packet_len >= 4)
|
||||
) {
|
||||
if((packet->payload[0] == 0x81)
|
||||
|| (packet->payload[1] == 0xC8)
|
||||
@@ -56,7 +54,7 @@ void ndpi_search_kakaotalk_voice(struct ndpi_detection_module_struct *ndpi_struc
|
||||
}
|
||||
}
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_KAKAOTALK_VOICE, ndpi_struct, NDPI_LOG_DEBUG, "Exclude kakaotalk_voice.\n");
|
||||
NDPI_LOG(NDPI_SERVICE_KAKAOTALK_VOICE, ndpi_struct, NDPI_LOG_DEBUG, "Exclude kakaotalk_voice.\n");
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_SERVICE_KAKAOTALK_VOICE);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,20 +35,6 @@ 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
|
||||
|
||||
@@ -117,10 +117,10 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct
|
||||
&& (packet->line[a].ptr[1] == 'T' || packet->line[a].ptr[1] == 't')
|
||||
&& (packet->line[a].ptr[2] == 'A' || packet->line[a].ptr[2] == 'a')
|
||||
&& (packet->line[a].ptr[3] == 'R' || packet->line[a].ptr[3] == 'r')
|
||||
&& (packet->line[a].ptr[4] == 'T' || packet->line[a].ptr[0] == 't')
|
||||
&& (packet->line[a].ptr[5] == 'T' || packet->line[a].ptr[1] == 't')
|
||||
&& (packet->line[a].ptr[6] == 'L' || packet->line[a].ptr[2] == 'l')
|
||||
&& (packet->line[a].ptr[7] == 'S' || packet->line[a].ptr[3] == 's')) {
|
||||
&& (packet->line[a].ptr[4] == 'T' || packet->line[a].ptr[4] == 't')
|
||||
&& (packet->line[a].ptr[5] == 'T' || packet->line[a].ptr[5] == 't')
|
||||
&& (packet->line[a].ptr[6] == 'L' || packet->line[a].ptr[6] == 'l')
|
||||
&& (packet->line[a].ptr[7] == 'S' || packet->line[a].ptr[7] == 's')) {
|
||||
flow->l4.tcp.smtp_command_bitmask |= SMTP_BIT_STARTTLS;
|
||||
}
|
||||
}
|
||||
|
||||
+73
-73
@@ -37,108 +37,108 @@ static void ndpi_int_mdns_add_connection(struct ndpi_detection_module_struct
|
||||
}
|
||||
|
||||
static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
|
||||
*ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
*ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
{
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
|
||||
if ((packet->payload[2] & 0x80) == 0 &&
|
||||
ntohs(get_u_int16_t(packet->payload, 4)) <= NDPI_MAX_MDNS_REQUESTS &&
|
||||
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS) {
|
||||
if ((packet->payload[2] & 0x80) == 0 &&
|
||||
ntohs(get_u_int16_t(packet->payload, 4)) <= NDPI_MAX_MDNS_REQUESTS &&
|
||||
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS) {
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with question query.\n");
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with question query.\n");
|
||||
|
||||
return 1;
|
||||
} else if ((packet->payload[2] & 0x80) != 0 &&
|
||||
ntohs(get_u_int16_t(packet->payload, 4)) == 0 &&
|
||||
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS &&
|
||||
ntohs(get_u_int16_t(packet->payload, 6)) != 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with answer query.\n");
|
||||
return 1;
|
||||
} else if ((packet->payload[2] & 0x80) != 0 &&
|
||||
ntohs(get_u_int16_t(packet->payload, 4)) == 0 &&
|
||||
ntohs(get_u_int16_t(packet->payload, 6)) <= NDPI_MAX_MDNS_REQUESTS &&
|
||||
ntohs(get_u_int16_t(packet->payload, 6)) != 0) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with answer query.\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ndpi_search_mdns(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;
|
||||
|
||||
u_int16_t dport;
|
||||
// const u_int16_t sport=ntohs(packet->udp->source);
|
||||
u_int16_t dport;
|
||||
// const u_int16_t sport=ntohs(packet->udp->source);
|
||||
|
||||
/* check if UDP and */
|
||||
if (packet->udp != NULL) {
|
||||
/*read destination port */
|
||||
dport = ntohs(packet->udp->dest);
|
||||
/* check if UDP and */
|
||||
if (packet->udp != NULL) {
|
||||
/*read destination port */
|
||||
dport = ntohs(packet->udp->dest);
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "MDNS udp start \n");
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "MDNS udp start \n");
|
||||
|
||||
|
||||
|
||||
/*check standard MDNS to port 5353 */
|
||||
/*took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
|
||||
/*check standard MDNS to port 5353 */
|
||||
/*took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
|
||||
|
||||
if (dport == 5353 && packet->payload_packet_len >= 12) {
|
||||
if (dport == 5353 && packet->payload_packet_len >= 12) {
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with destination port 5353\n");
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct, NDPI_LOG_DEBUG, "found MDNS with destination port 5353\n");
|
||||
|
||||
/* MDNS header is similar to dns header */
|
||||
/* dns header
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ID |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| QDCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ANCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| NSCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ARCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* dns query check: query: QR set, ancount = 0, nscount = 0, QDCOUNT < MAX_MDNS, ARCOUNT < MAX_MDNS
|
||||
*
|
||||
*/
|
||||
/* MDNS header is similar to dns header */
|
||||
/* dns header
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ID |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
|QR| Opcode |AA|TC|RD|RA| Z | RCODE |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| QDCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ANCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| NSCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
| ARCOUNT |
|
||||
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
||||
*
|
||||
* dns query check: query: QR set, ancount = 0, nscount = 0, QDCOUNT < MAX_MDNS, ARCOUNT < MAX_MDNS
|
||||
*
|
||||
*/
|
||||
|
||||
/* mdns protocol must have destination address 224.0.0.251 */
|
||||
/* took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
|
||||
/* mdns protocol must have destination address 224.0.0.251 */
|
||||
/* took this information from http://www.it-administrator.de/lexikon/multicast-dns.html */
|
||||
|
||||
if (packet->iph != NULL && ntohl(packet->iph->daddr) == 0xe00000fb) {
|
||||
if (packet->iph != NULL && ntohl(packet->iph->daddr) == 0xe00000fb) {
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "found MDNS with destination address 224.0.0.251 (=0xe00000fb)\n");
|
||||
|
||||
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
|
||||
ndpi_int_mdns_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
|
||||
ndpi_int_mdns_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
||||
if (packet->iphv6 != NULL) {
|
||||
const u_int32_t *daddr = packet->iphv6->daddr.ndpi_v6_u.u6_addr32;
|
||||
if (daddr[0] == htonl(0xff020000) && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb)) {
|
||||
if (packet->iphv6 != NULL) {
|
||||
const u_int32_t *daddr = packet->iphv6->ip6_dst.u6_addr.u6_addr32;
|
||||
if (daddr[0] == htonl(0xff020000) && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb)) {
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "found MDNS with destination address ff02::fb\n");
|
||||
NDPI_LOG(NDPI_PROTOCOL_MDNS, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "found MDNS with destination address ff02::fb\n");
|
||||
|
||||
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
|
||||
ndpi_int_mdns_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ndpi_int_check_mdns_payload(ndpi_struct, flow) == 1) {
|
||||
ndpi_int_mdns_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MDNS);
|
||||
}
|
||||
}
|
||||
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MDNS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ 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;
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -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 (memcmp(packet->payload, "VER ", 4) == 0) {
|
||||
if (ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "VER ")) {
|
||||
|
||||
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 (memcmp(&packet->payload[4], "MSNFT", 5) == 0) {
|
||||
if (ndpi_match_strprefix(&packet->payload[4], packet->payload_packet_len-4, "MSNFT")) {
|
||||
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
|
||||
memcmp(packet->payload, "GET ", NDPI_STATICSTRING_LEN("GET ")) == 0 ||
|
||||
memcmp(packet->payload, "POST ", NDPI_STATICSTRING_LEN("POST ")) == 0) {
|
||||
ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "GET ") ||
|
||||
ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "POST ")) {
|
||||
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
|
||||
(memcmp(packet->payload, "HTTP/1.0 200 OK", 15) == 0) ||
|
||||
(memcmp(packet->payload, "HTTP/1.1 200 OK", 15) == 0)
|
||||
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")
|
||||
) {
|
||||
|
||||
ndpi_parse_packet_line_info(ndpi_struct, flow);
|
||||
|
||||
@@ -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, len;
|
||||
int ret = 0, 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;
|
||||
return(-1);
|
||||
break;
|
||||
}
|
||||
|
||||
*out = ((in[0]-'A')<<4) + (in[1]-'A');
|
||||
in += 2;
|
||||
out++;
|
||||
out++, ret++;
|
||||
}
|
||||
ret = *(--out);
|
||||
|
||||
*out = 0;
|
||||
|
||||
/* Courtesy of Roberto F. De Luca <deluca@tandar.cnea.gov.ar> */
|
||||
@@ -318,12 +318,12 @@ 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[32];
|
||||
char name[64];
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_NETBIOS, ndpi_struct,
|
||||
NDPI_LOG_DEBUG, "found netbios with checked ip-address.\n");
|
||||
|
||||
if(netbios_name_interpret((char*)&packet->payload[14], name, sizeof(name)) > 0)
|
||||
if(netbios_name_interpret((char*)&packet->payload[12], 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);
|
||||
|
||||
@@ -23,12 +23,10 @@
|
||||
|
||||
#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 */
|
||||
|
||||
+26
-36
@@ -22,54 +22,44 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#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;
|
||||
|
||||
// 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.");
|
||||
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.");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
+23
-14
@@ -30,7 +30,7 @@
|
||||
/* Flap channels */
|
||||
#define SIGNON 0x01
|
||||
#define DATA 0x02
|
||||
#define ERROR 0x03
|
||||
#define O_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,9 +245,10 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
|
||||
if (channel == DATA)
|
||||
{
|
||||
family = get_u_int16_t(packet->payload, 6);
|
||||
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);
|
||||
if (packet->payload_packet_len >= 10)
|
||||
type = get_u_int16_t(packet->payload, 8);
|
||||
else
|
||||
type = 0;
|
||||
|
||||
/* Family 0x0001 */
|
||||
if (family == htons(GE_SE_CTL))
|
||||
@@ -561,22 +562,30 @@ static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
|
||||
}
|
||||
|
||||
/* flag */
|
||||
if (flag == htons(0x0000)|| flag == htons(0x8000) || flag == htons(0x0001))
|
||||
{
|
||||
/* request ID */
|
||||
if((req_ID <= 4294967295))
|
||||
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)
|
||||
{
|
||||
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected \n");
|
||||
ndpi_int_oscar_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
ERROR -> FLAP__ERROR_CHANNEL_0x03
|
||||
A FLAP error - rare
|
||||
*/
|
||||
if (channel == ERROR)
|
||||
if (channel == O_ERROR)
|
||||
{
|
||||
NDPI_LOG(NDPI_PROTOCOL_OSCAR, ndpi_struct, NDPI_LOG_DEBUG, "OSCAR Detected - Error frame \n");
|
||||
ndpi_int_oscar_add_connection(ndpi_struct, flow);
|
||||
|
||||
@@ -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 ((payload_len > 0) && match_first_bytes(packet->payload, "\x0ePan")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 ((payload_len > 0) && match_first_bytes(packet->payload, "UDPA")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Possible PANDO request detected, we will look further for the response...\n");
|
||||
|
||||
/* 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 ((payload_len > 0) && (match_first_bytes(packet->payload, "UDPR") || match_first_bytes(packet->payload, "UDPE"))) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE")) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Possible PANDO request detected, we will look further for the response...\n");
|
||||
|
||||
/* 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) || match_first_bytes(packet->payload, "UDPR") || match_first_bytes(packet->payload, "UDPE")) {
|
||||
if ((payload_len == 0) || (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE"))) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n");
|
||||
ndpi_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 ((payload_len > 0) && match_first_bytes(packet->payload, "UDPA")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_PANDO, ndpi_struct, NDPI_LOG_DEBUG, "Found PANDO.\n");
|
||||
ndpi_int_pando_add_connection(ndpi_struct, flow);
|
||||
} else {
|
||||
|
||||
@@ -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 ((payload_len > 0) && match_first_bytes(packet->payload, "\xe9\x03\x41\x01")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 ((payload_len > 0) && match_first_bytes(packet->payload, "\xe9\x03\x42\x01")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 ((payload_len > 0) && match_first_bytes(packet->payload, "\x1c\x1c\x32\x01")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 ((payload_len > 0) && (match_first_bytes(packet->payload, "\xe9\x03\x42\x01") || match_first_bytes(packet->payload, "\xe9\x03\x41\x01"))) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x42\x01") || ndpi_match_strprefix(packet->payload, payload_len, "\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 ((payload_len > 0) && match_first_bytes(packet->payload, "\xe9\x03\x41\x01")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 ((payload_len > 0) && match_first_bytes(packet->payload, "\x1c\x1c\x32\x01")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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) && match_first_bytes(packet->payload, "\xe9\x03\x41\x01")) {
|
||||
if ((payload_len == 57) && ndpi_match_strprefix(packet->payload, payload_len, "\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. */
|
||||
|
||||
@@ -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[12] = // maybe version numbers
|
||||
{ 0x1549, 0x1801, 0x180d, 0x0961, 0x01501, 0x0e35, 0x113f, 0x0b37, 0x1131, 0x163a, 0x1e0d };
|
||||
u_int16_t no_of_patterns = 11, index = 0;
|
||||
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;
|
||||
|
||||
|
||||
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_TCP_WITH_PAYLOAD,
|
||||
NO_SAVE_DETECTION_BITMASK_AS_UNKNOWN,
|
||||
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
|
||||
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
|
||||
ADD_TO_DETECTION_BITMASK);
|
||||
|
||||
*id += 1;
|
||||
|
||||
+94
-129
@@ -1,11 +1,12 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -24,161 +25,125 @@
|
||||
|
||||
#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 void ndpi_int_quic_add_connection(struct ndpi_detection_module_struct
|
||||
*ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
|
||||
static int quic_ports(u_int16_t sport, u_int16_t dport)
|
||||
{
|
||||
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_QUIC, NDPI_PROTOCOL_UNKNOWN);
|
||||
if ((sport == 443 || dport == 443 || sport == 80 || dport == 80) &&
|
||||
(sport != 123 && dport != 123))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int connect_id(const unsigned char pflags)
|
||||
{
|
||||
u_int cid_len;
|
||||
/* ***************************************************************** */
|
||||
|
||||
// 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;
|
||||
static int quic_payload(const u_int8_t *payload) {
|
||||
if((payload[0] == 'Q')
|
||||
&& isdigit(payload[1])
|
||||
&& isdigit(payload[2])
|
||||
&& isdigit(payload[3]))
|
||||
return(1);
|
||||
|
||||
}
|
||||
// Return offset.
|
||||
return cid_len + 1;
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int sequence(const unsigned char *payload)
|
||||
/* ***************************************************************** */
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return(0); /* NOTREACHED */
|
||||
}
|
||||
|
||||
/* ***************************************************************** */
|
||||
|
||||
void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow)
|
||||
{
|
||||
unsigned char conv[6] = {0};
|
||||
u_int seq_value = -1;
|
||||
int seq_lens;
|
||||
int cid_offs;
|
||||
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;
|
||||
int i;
|
||||
|
||||
// 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]);
|
||||
if((version_len > 0) && (packet->payload[1+cid_len] != 'Q'))
|
||||
goto no_quic;
|
||||
|
||||
if (cid_offs >= 0 && seq_lens > 0)
|
||||
{
|
||||
for (i = 0; i < seq_lens; i++)
|
||||
conv[i] = payload[cid_offs + i];
|
||||
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);
|
||||
|
||||
seq_value = SEQ_CONV(conv);
|
||||
}
|
||||
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;
|
||||
|
||||
// Return SEQ dec value;
|
||||
return seq_value;
|
||||
}
|
||||
while((packet->payload[sni_offset] == '-') && (sni_offset < udp_len))
|
||||
sni_offset++;
|
||||
|
||||
void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
{
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
int ver_offs;
|
||||
|
||||
if(packet->udp != NULL) {
|
||||
if((sni_offset+len) < udp_len) {
|
||||
int max_len = sizeof(flow->host_server_name)-1, j = 0;
|
||||
|
||||
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);
|
||||
if(len > max_len) len = max_len;
|
||||
|
||||
|
||||
// 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);
|
||||
while((len > 0) && (sni_offset < udp_len)) {
|
||||
flow->host_server_name[j++] = packet->payload[sni_offset];
|
||||
sni_offset++, len--;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/* ***************************************************************** */
|
||||
|
||||
void init_quic_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
|
||||
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_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
|
||||
#endif /* NDPI_PROTOCOL_QUIC */
|
||||
|
||||
@@ -35,22 +35,13 @@ 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)
|
||||
&& (len == payload_len)) {
|
||||
&& (ntohs(h->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);
|
||||
|
||||
|
||||
@@ -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 < packet->payload_packet_len) {
|
||||
while(offset + 3 < 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");
|
||||
if(((packet->payload_packet_len >= 28 || packet->payload_packet_len <= 1200) &&
|
||||
/* TODO changed a pair of length condition to the && from ||. Is it correct? */
|
||||
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[0] == 0x81) && ((packet->payload[1] == 0xc8) || (packet->payload[1] == 0xc9))
|
||||
|| (packet->payload_packet_len >= 3 && ((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);
|
||||
|
||||
+67
-9
@@ -27,28 +27,86 @@
|
||||
|
||||
#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 payload_type = payload[1] & 0x7F;
|
||||
u_int8_t payloadType, 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) /* RTP magic byte[1] */
|
||||
&& (((payload[0] & 0xFF) == 0x80) || ((payload[0] & 0xFF) == 0xA0)) /* RTP magic byte[1] */
|
||||
&& ((payload_type < 72) || (payload_type > 76))
|
||||
&& (payload_type < 128 /* http://anonsvn.wireshark.org/wireshark/trunk/epan/dissectors/packet-rtp.c */)
|
||||
&& (*ssid != 0)
|
||||
&& ((payload_type <= 34)
|
||||
|| ((payload_type >= 96) && (payload_type <= 127))
|
||||
/* http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xhtml */
|
||||
)
|
||||
&& (*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);
|
||||
} 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
void ndpi_search_rtp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* 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... */
|
||||
struct __attribute__((__packed__)) 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;
|
||||
};
|
||||
|
||||
/* 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 != 0 && header->security != 1 &&
|
||||
header->security != 2 && 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
|
||||
@@ -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:", 7) == 0 || memcmp(&packet_payload[4], "sip:", 7) == 0)) {
|
||||
&& (memcmp(&packet_payload[4], "SIP:", 4) == 0 || memcmp(&packet_payload[4], "sip:", 4) == 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;
|
||||
|
||||
@@ -40,8 +40,8 @@ u_int8_t is_skype_flow(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
Skype connections are identified by some SSL-like communications
|
||||
without SSL certificate being exchanged
|
||||
*/
|
||||
if(is_skype_host(ndpi_struct, ntohl(packet->iph->saddr))
|
||||
|| is_skype_host(ndpi_struct, ntohl(packet->iph->daddr))) {
|
||||
if(is_skype_host(ndpi_struct, packet->iph->saddr)
|
||||
|| is_skype_host(ndpi_struct, packet->iph->daddr)) {
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,9 @@ 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
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -54,7 +54,7 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
}
|
||||
} else if(packet->tcp != NULL) {
|
||||
|
||||
if(packet->payload[0] == 0x00 && packet->payload[1] == 0x04 &&
|
||||
if(payload_len >= 8 && 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 ) {
|
||||
|
||||
+72
-63
@@ -92,11 +92,12 @@ 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;
|
||||
|
||||
int i, is_puny;
|
||||
|
||||
// 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] != '.')
|
||||
@@ -110,21 +111,28 @@ static void stripCertificateTrailer(char *buffer, int buffer_len) {
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,64 +223,67 @@ int getSSLcertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
}
|
||||
} else if(handshake_protocol == 0x01 /* Client Hello */) {
|
||||
u_int offset, base_offset = 43;
|
||||
u_int16_t session_id_len = packet->payload[base_offset];
|
||||
if (base_offset + 2 <= packet->payload_packet_len)
|
||||
{
|
||||
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;
|
||||
|
||||
if(offset < total_len) {
|
||||
u_int16_t compression_len;
|
||||
u_int16_t extensions_len;
|
||||
|
||||
compression_len = packet->payload[offset+1];
|
||||
offset += compression_len + 3;
|
||||
flow->l4.tcp.ssl_seen_client_cert = 1;
|
||||
|
||||
if(offset < total_len) {
|
||||
extensions_len = packet->payload[offset];
|
||||
u_int16_t compression_len;
|
||||
u_int16_t extensions_len;
|
||||
|
||||
if((extensions_len+offset) < total_len) {
|
||||
u_int16_t extension_offset = 1; /* Move to the first extension */
|
||||
compression_len = packet->payload[offset+1];
|
||||
offset += compression_len + 3;
|
||||
|
||||
while(extension_offset < extensions_len) {
|
||||
u_int16_t extension_id, extension_len;
|
||||
if(offset < total_len) {
|
||||
extensions_len = packet->payload[offset];
|
||||
|
||||
memcpy(&extension_id, &packet->payload[offset+extension_offset], 2);
|
||||
extension_offset += 2;
|
||||
if((extensions_len+offset) < total_len) {
|
||||
u_int16_t extension_offset = 1; /* Move to the first extension */
|
||||
|
||||
memcpy(&extension_len, &packet->payload[offset+extension_offset], 2);
|
||||
extension_offset += 2;
|
||||
while(extension_offset < extensions_len) {
|
||||
u_int16_t extension_id, extension_len;
|
||||
|
||||
extension_id = ntohs(extension_id), extension_len = ntohs(extension_len);
|
||||
memcpy(&extension_id, &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];
|
||||
memcpy(&extension_len, &packet->payload[offset+extension_offset], 2);
|
||||
extension_offset += 2;
|
||||
|
||||
while(begin < extension_len) {
|
||||
if((!ndpi_isprint(server_name[begin]))
|
||||
|| ndpi_ispunct(server_name[begin])
|
||||
|| ndpi_isspace(server_name[begin]))
|
||||
begin++;
|
||||
else
|
||||
break;
|
||||
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 */);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
extension_offset += extension_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,8 +299,6 @@ 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)
|
||||
|
||||
@@ -49,9 +49,8 @@ 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
|
||||
&& 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")))
|
||||
&& (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")))
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
|
||||
+12
-11
@@ -34,6 +34,7 @@ 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) {
|
||||
@@ -49,7 +50,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) || (payload_len == 4) || (payload_len == 5)) && match_first_bytes(packet->payload, "\x01\x00\x00\x00")) {
|
||||
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"))) {
|
||||
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. */
|
||||
@@ -57,7 +58,7 @@ static void ndpi_check_steam_tcp(struct ndpi_detection_module_struct *ndpi_struc
|
||||
return;
|
||||
}
|
||||
|
||||
if (((payload_len == 1) || (payload_len == 4) || (payload_len == 5)) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00)) {
|
||||
if ((payload_len == 1 && packet->payload[0] == 0x00) || ((payload_len == 4 || payload_len == 5) && ndpi_match_strprefix(packet->payload, payload_len, "\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. */
|
||||
@@ -73,7 +74,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) || (payload_len == 4) || (payload_len == 5)) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00)) {
|
||||
if ((payload_len == 1 && packet->payload[0] == 0x00) || ((payload_len == 4 || payload_len == 5) && ndpi_match_strprefix(packet->payload, payload_len, "\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 {
|
||||
@@ -89,7 +90,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) || (payload_len == 4) || (payload_len == 5)) && match_first_bytes(packet->payload, "\x01\x00\x00\x00")) {
|
||||
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"))) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
|
||||
ndpi_int_steam_add_connection(ndpi_struct, flow);
|
||||
} else {
|
||||
@@ -103,7 +104,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 ((payload_len > 0) && match_first_bytes(packet->payload, "VS01")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "VS01")) {
|
||||
NDPI_LOG(NDPI_PROTOCOL_STEAM, ndpi_struct, NDPI_LOG_DEBUG, "Found STEAM.\n");
|
||||
ndpi_int_steam_add_connection(ndpi_struct, flow);
|
||||
return;
|
||||
@@ -113,7 +114,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 ((payload_len > 0) && match_first_bytes(packet->payload, "\x31\xff\x30\x2e")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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. */
|
||||
@@ -121,7 +122,7 @@ static void ndpi_check_steam_udp1(struct ndpi_detection_module_struct *ndpi_stru
|
||||
return;
|
||||
}
|
||||
|
||||
if ((payload_len > 0) && match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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. */
|
||||
@@ -138,7 +139,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 ((payload_len > 0) && match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 {
|
||||
@@ -155,7 +156,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 ((payload_len > 0) && match_first_bytes(packet->payload, "\x31\xff\x30\x2e")) {
|
||||
if (ndpi_match_strprefix(packet->payload, payload_len, "\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 {
|
||||
@@ -174,7 +175,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) && match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
|
||||
if ((payload_len == 25) && ndpi_match_strprefix(packet->payload, payload_len, "\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. */
|
||||
@@ -190,7 +191,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) || match_first_bytes(packet->payload, "\xff\xff\xff\xff")) {
|
||||
if ((payload_len == 0) || ndpi_match_strprefix(packet->payload, payload_len, "\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 {
|
||||
|
||||
+65
-16
@@ -27,7 +27,7 @@
|
||||
#ifdef NDPI_PROTOCOL_STUN
|
||||
|
||||
|
||||
#define MAX_NUM_STUN_PKTS 6
|
||||
#define MAX_NUM_STUN_PKTS 10
|
||||
|
||||
|
||||
struct stun_packet_header {
|
||||
@@ -50,12 +50,18 @@ 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_whatsapp,
|
||||
u_int8_t *is_lync) {
|
||||
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))
|
||||
return(NDPI_IS_NOT_STUN);
|
||||
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((strncmp((const char*)payload, (const char*)"RSP/", 4) == 0)
|
||||
&& (strncmp((const char*)&payload[7], (const char*)" STUN_", 6) == 0)) {
|
||||
@@ -68,10 +74,51 @@ 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/ */))
|
||||
goto udp_stun_found;
|
||||
&& ((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
|
||||
*/
|
||||
|
||||
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
|
||||
@@ -173,10 +220,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
|
||||
#endif
|
||||
|
||||
|
||||
if(
|
||||
((flow->num_stun_udp_pkts > 0) && (msg_type == 0x0800))
|
||||
|| ((msg_type == 0x0800) && (msg_len == 106))
|
||||
) {
|
||||
if((flow->num_stun_udp_pkts > 0) && (msg_type <= 0x00FF)) {
|
||||
*is_whatsapp = 1;
|
||||
return NDPI_IS_STUN; /* This is WhatsApp Voice */
|
||||
} else
|
||||
@@ -191,7 +235,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;
|
||||
u_int8_t is_whatsapp = 0, is_lync = 0;
|
||||
|
||||
NDPI_LOG(NDPI_PROTOCOL_STUN, ndpi_struct, NDPI_LOG_DEBUG, "search stun.\n");
|
||||
|
||||
@@ -205,7 +249,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) == NDPI_IS_STUN) {
|
||||
packet->payload_packet_len - 2, &is_whatsapp, &is_lync) == 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;
|
||||
@@ -214,10 +258,15 @@ 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) == 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);
|
||||
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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ 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)) {
|
||||
@@ -37,9 +38,12 @@ u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struc
|
||||
}
|
||||
}
|
||||
|
||||
if((rc = ndpi_host_ptree_match(ndpi_struct, saddr)) != NDPI_PROTOCOL_UNKNOWN) return(rc);
|
||||
|
||||
return(ndpi_host_ptree_match(ndpi_struct, daddr));
|
||||
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));
|
||||
}
|
||||
|
||||
void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
|
||||
@@ -48,6 +52,9 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
u_int proto;
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
|
||||
if(flow->host_server_name[0] != '\0')
|
||||
return;
|
||||
|
||||
if(ndpi_is_tor_flow(ndpi_struct, flow)) {
|
||||
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_TOR, NDPI_PROTOCOL_UNKNOWN);
|
||||
return;
|
||||
@@ -61,7 +68,7 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
|
||||
proto = ndpi_search_tcp_or_udp_raw(ndpi_struct,
|
||||
flow->packet.iph ? flow->packet.iph->protocol :
|
||||
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|
||||
flow->packet.iphv6->nexthdr,
|
||||
flow->packet.iphv6->ip6_ctlun.ip6_un1.ip6_un1_nxt,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
|
||||
+32
-30
@@ -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;
|
||||
int prev_num = 0, numbers_found = 0, num_found = 0, i, len;
|
||||
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,43 +37,45 @@ int ndpi_is_ssl_tor(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
if((dot = strrchr(dummy, '.')) == NULL) return(0);
|
||||
name = &dot[1];
|
||||
|
||||
for(i = 0; name[i+1] != '\0'; i++) {
|
||||
if((name[i] >= '0') && (name[i] <= '9')) {
|
||||
len = strlen(name);
|
||||
|
||||
if(len > 6) {
|
||||
for(i = 0; name[i+1] != '\0'; i++) {
|
||||
if((name[i] >= '0') && (name[i] <= '9')) {
|
||||
|
||||
if(prev_num != 1) {
|
||||
numbers_found++;
|
||||
if(prev_num != 1) {
|
||||
numbers_found++;
|
||||
|
||||
if(numbers_found == 2) {
|
||||
ndpi_int_tor_add_connection(ndpi_struct, flow);
|
||||
return(1);
|
||||
if(numbers_found == 2) {
|
||||
ndpi_int_tor_add_connection(ndpi_struct, flow);
|
||||
return(1);
|
||||
}
|
||||
prev_num = 1;
|
||||
}
|
||||
prev_num = 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);
|
||||
}
|
||||
} else
|
||||
prev_num = 0;
|
||||
|
||||
if(ndpi_match_bigram(ndpi_struct, &ndpi_struct->impossible_bigrams_automa, &name[i])) {
|
||||
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);
|
||||
}
|
||||
|
||||
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__
|
||||
} else {
|
||||
#ifdef PENDANTIC_TOR_CHECK
|
||||
if(gethostbyname(certificate) == NULL) {
|
||||
ndpi_int_tor_add_connection(ndpi_struct, flow);
|
||||
return(1);
|
||||
if(gethostbyname(certificate) == NULL) {
|
||||
ndpi_int_tor_add_connection(ndpi_struct, flow);
|
||||
return(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
return(0);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* 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
@@ -51,18 +51,13 @@
|
||||
/* { 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 */
|
||||
|
||||
@@ -81,8 +76,6 @@
|
||||
#include <ws2tcpip.h> /* IPv6 */
|
||||
#endif
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/* { from mrt.h */
|
||||
|
||||
typedef struct the_prefix4_t {
|
||||
|
||||
-4
@@ -18,12 +18,10 @@
|
||||
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"
|
||||
@@ -245,7 +243,6 @@ 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
|
||||
@@ -299,7 +296,6 @@ void ac_automata_display (AC_AUTOMATA_t * thiz, char repcast)
|
||||
printf("---------------------------------\n");
|
||||
}
|
||||
}
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/******************************************************************************
|
||||
* FUNCTION: ac_automata_register_nodeptr
|
||||
|
||||
+11
-80
@@ -39,7 +39,6 @@
|
||||
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 */
|
||||
@@ -54,26 +53,8 @@
|
||||
#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);
|
||||
}
|
||||
@@ -103,47 +84,6 @@ 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)
|
||||
@@ -175,15 +115,13 @@ ndpi_my_inet_pton (int af, const char *src, void *dst)
|
||||
}
|
||||
memcpy (dst, xp, sizeof(struct in_addr));
|
||||
return (1);
|
||||
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
} else if(af == AF_INET6) {
|
||||
return (inet_pton (af, src, dst));
|
||||
return (inet_pton (af, src, dst));
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
} else {
|
||||
} else {
|
||||
#ifndef NT
|
||||
#ifndef __KERNEL__
|
||||
errno = EAFNOSUPPORT;
|
||||
#endif
|
||||
errno = EAFNOSUPPORT;
|
||||
#endif /* NT */
|
||||
return -1;
|
||||
}
|
||||
@@ -236,7 +174,7 @@ ndpi_prefix_toa2x (prefix_t *prefix, char *buff, int with_len)
|
||||
}
|
||||
return (buff);
|
||||
}
|
||||
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
else if(prefix->family == AF_INET6) {
|
||||
char *r;
|
||||
r = (char *) inet_ntop (AF_INET6, &prefix->add.sin6, buff, 48 /* a guess value */ );
|
||||
@@ -274,7 +212,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) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
if(family == AF_INET6) {
|
||||
default_bitlen = sizeof(struct in6_addr) * 8;
|
||||
if(prefix == NULL) {
|
||||
@@ -319,8 +257,7 @@ 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)
|
||||
{
|
||||
@@ -328,7 +265,7 @@ ndpi_ascii2prefix (int family, char *string)
|
||||
long maxbitlen = 0;
|
||||
char *cp;
|
||||
struct in_addr sin;
|
||||
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
struct in6_addr sin6;
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
char save[MAXLINE];
|
||||
@@ -339,7 +276,7 @@ ndpi_ascii2prefix (int family, char *string)
|
||||
/* easy way to handle both families */
|
||||
if(family == 0) {
|
||||
family = AF_INET;
|
||||
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
if(strchr (string, ':')) family = AF_INET6;
|
||||
#endif /* PATRICIA_IPV6 */
|
||||
}
|
||||
@@ -347,7 +284,7 @@ ndpi_ascii2prefix (int family, char *string)
|
||||
if(family == AF_INET) {
|
||||
maxbitlen = sizeof(struct in_addr) * 8;
|
||||
}
|
||||
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
else if(family == AF_INET6) {
|
||||
maxbitlen = sizeof(struct in6_addr) * 8;
|
||||
}
|
||||
@@ -373,7 +310,7 @@ ndpi_ascii2prefix (int family, char *string)
|
||||
return (ndpi_New_Prefix (AF_INET, &sin, bitlen));
|
||||
}
|
||||
|
||||
#if defined(PATRICIA_IPV6) && (!defined(__KERNEL__))
|
||||
#if defined(PATRICIA_IPV6)
|
||||
else if(family == AF_INET6) {
|
||||
// Get rid of this with next IPv6 upgrade
|
||||
#if defined(NT) && !defined(HAVE_INET_NTOP)
|
||||
@@ -420,8 +357,6 @@ ndpi_Deref_Prefix (prefix_t * prefix)
|
||||
}
|
||||
}
|
||||
|
||||
/* } */
|
||||
|
||||
/* #define PATRICIA_DEBUG 1 */
|
||||
|
||||
static int num_active_patricia = 0;
|
||||
@@ -446,7 +381,6 @@ 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)
|
||||
{
|
||||
@@ -503,7 +437,6 @@ 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)
|
||||
{
|
||||
@@ -1073,5 +1006,3 @@ ndpi_lookup_then_remove (patricia_tree_t *tree, char *string)
|
||||
patricia_remove (tree, node);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* } */
|
||||
|
||||
Vendored
-4
@@ -18,14 +18,10 @@
|
||||
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"
|
||||
|
||||
|
||||
Vendored
-38
@@ -4,9 +4,6 @@
|
||||
* 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;
|
||||
@@ -15,7 +12,6 @@ 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 */
|
||||
|
||||
@@ -94,37 +90,3 @@ 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.
@@ -0,0 +1,16 @@
|
||||
HTTP 10 1792 1
|
||||
IMAPS 4 516 2
|
||||
SSL 28 15397 1
|
||||
ICMPV6 48 7862 3
|
||||
Facebook 37 14726 3
|
||||
|
||||
1 TCP [2001:470:1f17:13f:3e97:eff:fe73:4dec]:443 <-> [2a03:2880:1010:6f03:face:b00c::2]:53234 [proto: 91.119/SSL.Facebook][33 pkts/13926 bytes][SSL client: www.facebook.com]
|
||||
2 UDP [2001:470:1f16:13f::2]:6404 <-> [2a03:2880:fffe:b:face:b00c::99]:53 [proto: 5.119/DNS.Facebook][2 pkts/394 bytes][Host: star.c10r.facebook.com]
|
||||
3 TCP [2001:470:1f17:13f:3e97:eff:fe73:4dec]:443 <-> [2604:a880:1:20::224:b001]:60205 [proto: 91/SSL][28 pkts/15397 bytes][SSL client: mail.tomasu.net]
|
||||
4 ICMPV6 [2001:470:1f16:13f::2]:0 <-> [2604:a880:1:20::224:b001]:0 [proto: 102/ICMPV6][1 pkts/200 bytes]
|
||||
5 ICMPV6 [2a03:2880:1010:6f03:face:b00c::2]:0 <-> [2001:470:1f17:13f:3e97:eff:fe73:4dec]:0 [proto: 102/ICMPV6][1 pkts/1314 bytes]
|
||||
6 TCP [2604:a880:1:20::224:b001]:993 <-> [2001:470:1f17:13f:6d69:c72:7313:616f]:35610 [proto: 51/IMAPS][2 pkts/258 bytes]
|
||||
7 ICMPV6 [2001:470:1f17:13f:3e97:eff:fe73:4dec]:0 <-> [2604:a880:1:20::224:b001]:0 [proto: 102/ICMPV6][46 pkts/6348 bytes]
|
||||
8 TCP [2604:a880:1:20::224:b001]:993 <-> [2001:470:1f17:13f:6d69:c72:7313:616f]:56381 [proto: 51/IMAPS][2 pkts/258 bytes]
|
||||
9 UDP [2001:470:1f16:13f::2]:53959 <-> [2a03:2880:fffe:b:face:b00c::99]:53 [proto: 5.119/DNS.Facebook][2 pkts/406 bytes][Host: star.c10r.facebook.com]
|
||||
10 TCP [2001:470:1f17:13f:3e97:eff:fe73:4dec]:80 <-> [2604:a880:1:20::224:b001]:41538 [proto: 7/HTTP][10 pkts/1792 bytes][Host: mail.tomasu.net]
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user