Compare commits

..
606 Commits
Author SHA1 Message Date
Luca Deri 75898a4f9e Cherry pick of https://github.com/ntop/nDPI/commit/6462f4671cfafa00290d5658f860962651ab2a0d 2020-12-22 10:13:41 +01:00
candybit f40aaaf369 Fix bad DHCP options offset (#1091) 2020-12-19 12:38:44 +01:00
Alfredo Cardigliano f578353756 Add NDPI_PROTOCOL_ANY_CATEGORY to ndpi_protocol_category_t enum 2020-12-11 13:47:39 +00:00
Luca Deri d22bcc96cf Fix for detection of numeric IPs in HTTP 2020-11-01 13:35:27 +01:00
Alfredo Cardigliano eb8102fb2a Merge pull request #1045 from vitalivanov/pull_668
Generate NDPI_API_VERSION based on git commands.
2020-10-29 09:13:11 +01:00
Vitaliy Ivanov a17eeb9060 Generate NDPI_API_VERSION based on git commands.
https://github.com/ntop/PF_RING/issues/668

Check for .git directory works in case of usual clone of nDPI repo.
But if you integrate is as submodule then .git is a file.

Signed-off-by: Vitaliy Ivanov <vitaliyi@interfacemasters.com>
2020-10-29 00:17:41 +02:00
Alfredo Cardigliano 12e6e04c0e Print API rev 2020-10-27 18:27:30 +01:00
Luca Deri 64929a75e0 3.4 nDPI Release 2020-10-19 16:18:25 +02:00
Luca Deri 02de8e10ca Added makefile target for creating changelog
Updated Changelog
2020-10-19 15:39:48 +02:00
Toni c2d8955c18 Fixed missing PCAP include directories in Makefiles. (#1034)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-10-19 11:25:22 +02:00
Luca Deri e9721eb4ce Improved processing of IPv6 header
Improved QUIC serialization
2020-10-15 21:57:59 +02:00
Alfredo Cardigliano 88f3519ab3 Handle list items in ndpi_deserialize_get_single_size 2020-10-15 12:02:43 +02:00
Alfredo Cardigliano 031cd04b7c Add serialization of values list in TLV 2020-10-15 10:45:43 +02:00
aouinizied d5d2a7e3f3 Fix CAPWAP handling. 2020-10-13 19:13:07 +02:00
Alfredo Cardigliano 2051e51380 Decoupled fuzzy and unit tests 2020-10-12 12:11:35 +02:00
Alfredo Cardigliano c92e0d13fd Serialized doxygen doc 2020-10-05 11:25:48 +02:00
Luca 05d93790e4 Added ndpi_quick_16_byte_hash
Warning fix
2020-10-05 08:26:24 +02:00
Luca Deri 32e4922c5a Warning fix 2020-10-03 17:14:40 +02:00
Luca Deri d4d82c27a5 Tests update 2020-10-02 21:35:15 +02:00
Luca Deri addc775811 Added fix for invalid SNI check when SNI is missing 2020-10-02 21:26:43 +02:00
Luca Deri b68a3707f6 Updated serialization test unit 2020-10-02 12:39:08 +02:00
b0c4d01734 don't pass arguments to ./configure as 1 string (#1027)
this causes the following error if there are arguments after --host :
'checking host system type... config.sub: too many arguments'

Co-authored-by: sahnalys12 <boris.vanhoof_ext@softathome.com>
Co-authored-by: Luca Deri <lucaderi@users.noreply.github.com>
2020-09-29 18:02:08 +02:00
Ivan Nardi 2c1b7cf1bd QUIC: fix dissection of "offset" field (#1025)
The "offset" field is a variable-length integer.
This bug hasn't any practical effects right now, since we are ignoring any
packet with "offset" != 0 (and the value 0 is always encoded in only one byte).
But extracting a correct "offset" is important if we are ever going to handle
fragmented Client Hello messages.
2020-09-29 17:59:03 +02:00
Toni 656323c334 Added missing files to `make dist' target which are not required to build nDPI but still somehow essential. (#1024)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-29 17:58:33 +02:00
Luca Deri 8e1a3f5cdc Added JSON-C check for unit tests 2020-09-26 12:50:30 +02:00
Luca Deri 58538b7d19 Added extra boundary checks 2020-09-26 12:33:57 +02:00
Luca Deri d0dbcf6dd6 Added back ndpi_check_flow_func (correct) prototype 2020-09-25 10:39:33 +02:00
Luca Deri 8413faf2ef Boundary fix 2020-09-25 09:56:24 +02:00
Luca Deri 204f3ddff5 Compilation fix 2020-09-25 09:36:10 +02:00
Luca Deri 044ed14b4f Various optimizations to reduce not-necessary calls
Optimized various UDP dissectors
Removed dead protocols such as pando and pplive
2020-09-24 23:26:03 +02:00
Luca Deri 51e86346d3 Added -fno-sanitize=alignment in clang-7 2020-09-24 16:46:28 +02:00
Luca Deri 8e7a707be1 -O0 -> -Og 2020-09-23 18:49:44 +02:00
Luca Deri 837ce7306b Attempt to avoid errors due to misaligned packet headers 2020-09-23 18:17:51 +02:00
Luca Deri 05dfae6430 Improved boundary check to prevent overflow 2020-09-23 17:14:40 +02:00
Luca Deri d29a0241ee Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-09-22 12:45:44 +02:00
Luca Deri cbf1be5789 Macro redefinition 2020-09-22 12:23:44 +02:00
Luca Deri 5f99433ee7 Minor UA handling improvement to avoid heap-overflow 2020-09-22 08:56:35 +02:00
lucaderi 27bad14738 Added missing install target in newly added unit tsts 2020-09-22 08:42:50 +02:00
Luca Deri 362baa6321 Minor change for alignment issue 2020-09-21 21:15:52 +02:00
Luca Deri 60a9f6610d Added risks for checking
- invalid DNS traffic (probably carrying exfiltrated data)
- TLS traffic with no SNI extension
2020-09-21 19:57:23 +02:00
Alfredo Cardigliano 0259ff58e1 Exclude sanitizer on unit tests involving json-c due to a bug in the lib 2020-09-21 17:59:06 +02:00
Alfredo Cardigliano d700ab3994 Add distdir directive 2020-09-21 17:32:57 +02:00
Alfredo Cardigliano e6d206fd15 Add unit tests to travis. Move ndpi serializer tests to unit tests. 2020-09-21 17:24:06 +02:00
Luca Deri a263ac9024 Merge pull request #1022 from lnslbrty/fix/ndpi-mingw-fn-redef
Do not re-define libc functions for mingw builds.
2020-09-21 14:42:06 +02:00
Toni Uhlig 87c43450f3 Do not re-define libc functions for mingw builds.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-20 23:29:23 +02:00
Luca Deri 8ba1baace1 Added sample Windows MSVC project 2020-09-20 18:44:57 +02:00
Luca Deri ff1cc1fa41 Merge pull request #1019 from IvanNardi/quic_fb
QUIC: add support for MVFST EXPERIMENTAL version
2020-09-20 18:34:27 +02:00
Luca Deri ea9177cc93 Merge pull request #1018 from lnslbrty/fix/make-dist
Fixed broken `make dist' and added CI check.
2020-09-20 18:33:57 +02:00
Luca Deri 1385f05713 Merge pull request #1017 from lnslbrty/fix/mingw-xcompile
Added support for mingw xcompile.
2020-09-20 18:33:40 +02:00
Nardi Ivan dcac633878 QUIC: add support for MVFST EXPERIMENTAL version 2020-09-20 16:38:28 +02:00
Toni Uhlig fdef6f3545 Fixed broken `make dist' and added CI check.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-19 02:23:53 +02:00
Toni Uhlig d0052fd5b2 Using NDPI_I64_FORMAT, NDPI_U64_FORMAT format string to differentiate between Windows and non-Windows.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-18 19:46:20 +02:00
Toni Uhlig bcce122665 Fixed mingw build w/o examples/tests/fuzzer.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-18 19:46:07 +02:00
Luca Deri 6a7139bb24 Updated results 2020-09-18 00:17:43 +02:00
Luca Deri b5b4512022 Added MDNS in extra packet dissection function 2020-09-18 00:08:27 +02:00
Luca Deri d81bc1add6 Reworked MDNS dissector that is not based on the DNS dissector 2020-09-17 23:24:02 +02:00
Luca Deri 753b5dde16 Merge pull request #1012 from IvanNardi/ua
QUIC: extract User Agent information
2020-09-17 21:32:25 +02:00
Luca Deri 9189aee83b Disabled QUIC tracing that pollutes the output 2020-09-17 14:37:56 +02:00
aouinizied 4cc4efa228 Update example. 2020-09-14 16:42:33 +02:00
Luca ad8318e247 Commented unused function 2020-09-13 09:48:29 +02:00
Alfredo Cardigliano 91e3292e6b Temporarily keep using snprintf 2020-09-11 19:17:10 +02:00
Luca Deri 98a81cb163 Reworked DGA checks 2020-09-11 10:31:19 +02:00
Alfredo Cardigliano 3a6ba7fa12 Replace snprintf with ndpi_snappend 2020-09-11 10:04:43 +02:00
Luca Deri 37abe0daea Added boundary check 2020-09-10 20:06:25 +02:00
Luca Deri 1c0e617d80 Added buffer check in DGA analysis 2020-09-10 19:58:31 +02:00
Nardi Ivan 8db084ab06 TLS: fix memory accesses in QUIC transport parameters extension 2020-09-10 18:19:18 +02:00
lucaderi ea4240055d Complation fix as not on all platforms isnumber() is available 2020-09-10 00:05:02 +02:00
Luca Deri 5ac870074b Merge pull request #1014 from lnslbrty/improved/teamspeak
Improved Teamspeak(3) protocol detection.
2020-09-09 23:28:21 +02:00
Luca Deri 7086197047 Added extension to detect nested subdomains as used in Browsertunnel attack tool
https://github.com/veggiedefender/browsertunnel
2020-09-09 23:25:19 +02:00
Toni Uhlig 8ca13bc46a Improved Teamspeak(3) protocol detection.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-09 21:57:31 +02:00
Alfredo Cardigliano 842c00e681 Add missing low-level serializer calls to the API 2020-09-09 17:09:01 +02:00
Toni Uhlig 4c776501a6 Fixed shlib xcompile for x86_64-w64-mingw32
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-08 19:52:46 +02:00
Nardi Ivan 7d5a0e1f04 QUIC: extract User Agent information 2020-09-08 11:03:22 +02:00
Nardi Ivan a1014e8895 http: create a common function to parse User Agent field
Prepare the code to handle UA information from flows other than HTTP
2020-09-08 10:34:05 +02:00
Luca Deri 601928cc8e Merge pull request #1008 from lnslbrty/add/dnscrypt
Improved dnscrypt v1/v2 protocol detection (and DoH provider).
2020-09-08 09:53:22 +02:00
Luca Deri 5a3956fe27 Added command for specifying the aux files dir 2020-09-08 09:51:02 +02:00
Toni Uhlig df14d225f6 Added pcap file which contains dnscrypt-v1 data and resolver update requests/responses (v1/v2).
* Renamed dnscrypt.pcap to simple-dnscrypt.pcap

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-07 21:04:23 +02:00
Toni Uhlig fe5aa7ebca Added dnscrypt-v2-doh resolver test pcaps.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-07 20:22:52 +02:00
Toni Uhlig 41d35fc7d0 Updated DoT/DoH provider.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-07 20:22:45 +02:00
Toni Uhlig 799a6abfe6 Improved dnscrypt v1/v2 protocol detection.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-06 23:24:55 +02:00
Alfredo Cardigliano 8ed6409b35 Add start_of_block/end_of_block support to TLV 2020-09-04 17:23:04 +02:00
Luca Deri 3f49062db9 Added some additional TLS mappings 2020-09-02 23:35:22 +02:00
Luca Deri 3cca5af8c3 Merge pull request #1003 from lnslbrty/fix/fals-positive-cisco-hsrp-radius-detection
Fixed false positive detection for Skype.SkypeCall (affects at least Cisco HSRP and RADIUS).
2020-09-02 12:32:48 +02:00
Toni Uhlig 7051acc0b5 Fixed off-by-one error in Kerberos protocol.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-02 07:37:26 +02:00
Toni Uhlig 580859a47d Fixed false positive detection for Skype.SkypeCall (affects at least Cisco HSRP and RADIUS).
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-09-02 07:29:33 +02:00
Luca Deri 5d2551ff3e Added boundary check 2020-09-01 22:31:34 +02:00
Luca Deri cefb667d8b Added trademark information 2020-09-01 18:03:01 +02:00
Luca Deri 8575a07113 Added check for ndpi_ssl_version2str() 2020-08-31 17:23:00 +02:00
Luca Deri 460ff3c7ab Added (optional) notifier for LRU add 2020-08-31 08:47:16 +02:00
Luca Deri 029448759b Merge pull request #999 from IvanNardi/quic
QUIC: add support for GQUIC T050 and T051
2020-08-30 20:56:15 +02:00
Luca Deri 448265a151 Merge pull request #998 from lnslbrty/fix/ndpireader-opt-sigsegv
Fixed invalid memory access leading to a SIGSEGV in ndpiReader's option parser.
2020-08-30 20:55:44 +02:00
Nardi Ivan 7da4abe6ad QUIC: add support for GQUIC T050 and T051
QUIC versioning wasn't complex enough without T05X family...
These versions are very similar to Q050, but use TLS as their handshake
protocol.
2020-08-30 20:51:33 +02:00
Luca Deri 638624869a Added new risk for NDPI_UNSAFE_PROTOCOL that identifies protocols that are not condidered safe/secure 2020-08-30 20:48:58 +02:00
Luca Deri 647c7d59bb Improved ntop detection over HTTP
Added cap on number of attempts for CiscoVPN
2020-08-30 19:42:09 +02:00
Luca Deri f597086386 Stddev calculation changes 2020-08-30 12:48:32 +02:00
Luca Deri dd75060932 Fixed false positive in suspicous user agent
Optimized stddev calculation
2020-08-30 12:25:15 +02:00
Luca Deri 8bf95b6198 Merge pull request #996 from lnslbrty/fix/travis-ci
Fix travis-ci related errors.
2020-08-28 13:04:26 +02:00
Toni Uhlig adab0139c2 Fixed invalid memory access leading to a SIGSEGV in ndpiReader's option parser.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-28 06:53:58 +02:00
Toni Uhlig bf9dbd6ccf Fixed travis-ci fuzzm job. Might be a false positive related to clang-7's MSAN.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-27 16:42:24 +02:00
Toni Uhlig e998fc28d1 Fixed use-of-uninitialized-value in QUIC clho decryption probably caused by a BUG in libgcrypt (not verified).
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-27 16:30:05 +02:00
Simone Mainardi 1810281d7f Fixes control reaches end of non-void function 2020-08-27 10:39:36 +02:00
Simone Mainardi f0325f713a Passes method_len param to ndpi_http_str2method 2020-08-27 10:05:38 +02:00
Toni Uhlig 5b27dfdd0c Moved NDPI_CURRENT_PROTO define before ndpi_api.h include to prevent a redefinition warning.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-27 00:29:44 +02:00
Toni Uhlig c17463539f Fixed broken travis-ci YAML.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-27 00:27:31 +02:00
Luca Deri 2e8aa9f08e Added ndpi_http_method ndpi_http_str2method(const char* method) API call 2020-08-26 23:17:19 +02:00
Luca Deri 487d915262 Added ndpi_http_method2str() API call 2020-08-26 12:25:28 +02:00
Luca Deri 5e1bb0dbc1 Merge pull request #992 from lnslbrty/fix/pkg-config
Fixed broken pkg-config file which did not care about gcrypt/pcre.
2020-08-26 10:29:39 +02:00
Toni Uhlig 363ab2259c Fixed broken pkg-config file which did not care about gcrypt/pcre.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-24 18:12:49 +02:00
Luca Deri b94e13da43 Merge pull request #991 from IvanNardi/quic2
QUIC: minor fixes
2020-08-24 14:45:04 +02:00
Nardi Ivan 97b80a8838 QUIC: minor fixes
LGTM found a real issue on a boundary check
Fix unit tests: a pcap ha been uploaded twice (with different names)
Fix compilation when using DPDK (see #990)
2020-08-24 13:53:36 +02:00
Luca Deri b8307eb855 Creared IoT-Scada category
Minor dnp3 changes
2020-08-23 13:32:36 +02:00
Luca Deri 46ba657562 Cosmetic fix 2020-08-22 23:48:00 +02:00
Luca Deri 4570dbfece Added QUIC dependency 2020-08-22 17:02:11 +02:00
Luca Deri 35fd4ddb27 Added libgcrypt20-dev dependency to handle QUIC 2020-08-22 16:53:44 +02:00
Luca Deri fe1e2c241f Added som GQUIC and IETF QUIC test pcaps 2020-08-22 16:47:05 +02:00
Luca Deri af3ce74e02 Fixes compilation issues introduced by https://github.com/ntop/nDPI/pull/989 2020-08-22 16:41:51 +02:00
Luca Deri 93003d0523 Warning fix 2020-08-22 16:41:42 +02:00
Luca Deri 519ba7a9d5 Merge pull request #989 from IvanNardi/quic
Improve QUIC detection
2020-08-22 16:30:29 +02:00
Nardi Ivan b23cfd6b84 Add sub-classification for GQUIC >= Q050 and (IETF-)QUIC
Add QUIC payload and header decryption: most of the crypto code has been
"copied-and-incolled" from Wireshark. That code has been clearly marked
as such. All credits for that code should go to the original authors.

I tried to keep the Wireshark code as similar as possible to the original,
comments included, to ease future backporting of fixes.
Inevitably, glibc data types and data structures, tvbuff abstraction and
allocation functions have been converted.
2020-08-21 22:04:55 +02:00
Nardi Ivan 7a1147d733 Update TLS dissector to handle QUIC flows
Latest QUIC versions use TLS for the encryption layer: reuse existing code
to allow Client Hello parsing and sub-classification based on SNI value.
Side effect: we might have J3AC, TLS negotiated version, SNI value and
supported cipher list for QUIC, too.
2020-08-21 22:04:55 +02:00
Nardi Ivan d62ae567d1 Add (optional) dependency on external libraries: libgcrypt and libgpg-error
To support QUIC payload and header decryption, it is necessary to choose an
external crypto library to handle the low-level crypto stuff. Since we will
use some Wireshark code, it is quite natural to choose the same library used
by Wireshark itself: libgcrypt.

More precisely, we will use libgcrypt and libgpg-error.
Both libraries have LGPL license, so there should be no issue from this point
of view.

These libraries are not required to build nDPI, and their usage is optional:
nDPI will keep working (and compiling) even if they are not available.
However, without them, QUIC sub-classification is next to impossible.
The configure flag "--disable-gcrypt" forces the build system to ignore these
libraries.

libgpg-error is only used for debug to have meaningful error messages and its
usage is trivial.
The same cannot be said for libgcrypt because its initialization is a significant
issue.

The rest of this commit message try explaining how libgcrypt is
initialized.

According to the documentation
   https://gnupg.org/documentation/manuals/gcrypt/Initializing-the-library.html
   https://gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html#Multi_002dThreading
libgcrypt must be initialized before using it, but such initialization should
be performed by the actual application and not by any library.

Forcing the users to proper initialize libgcrypt in their own code seems
unreasonable: most people using nDPI might be complete unaware of any crypto
stuff and update each and every one application linking to nDPI with specific
libgcrypt code should be out of question, anyway.

Fortunately, it seems a workaround exists to initialize libgcrypt in a library
    https://lists.gnupg.org/pipermail/gcrypt-devel/2003-August/000458.html

Therefore, we could provide a wrapper to this initialization stuff in a nDPI
function. Unfortunately nDPI API lacks a global init function that must be
called only once, before any other functions. We could add it, but that would
be a major API break.
AFAIK, ndpi_init_detection_module() might be called multiple times, for example
to create multiple independent dpi engines in the same program.

The proposed solution is to (optionally) initialize libgcrypt in
ndpi_init_detection_module() anyway:
* if the actual application doesn't directly use libgcrypt and only calls
  ndpi_init_detection_module() once, everything is formally correct and it
  should work out of the box [by far the most common user case];
* if the actual application already uses libgcrypt directly, it already
  performs the required initialization. In this case the ndpi_prefs.ndpi_dont_init_libgcrypt
  flag should be passed to ndpi_init_detection_module() to avoid further
  initializations.

The only scenario not supported by this solution is when the application is
unaware of libgcrypt and calls ndpi_init_detection_module() multiple times
concurrently. But this scenario should be uncommon.

A completely different option should be to switch to another crypto library,
with a huge impact on the QUIC dissector code.

Bottom line: crypto is hard, using libgcrypt is complex and the proposed
initialization, even if not perfect, should cover the most frequent user
cases and should work, for the time being.
If anyone has some suggestions...
2020-08-21 22:04:55 +02:00
Nardi Ivan 23ec82b59d Major rework of QUIC dissector
Improve support for GQUIC (up to Q046) and add support for Q050 and (IETF-)QUIC
Still no sub-classification for Q050 and QUIC
2020-08-21 22:04:55 +02:00
Luca Deri fef199ad45 Added new check for detecting suspicious (too long) names 2020-08-21 19:35:27 +02:00
Luca Deri b23781e807 Added the ability do identigy as DGA those host/domain names with too many consucutive repeated characters
such as ckaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa used fr netbios reflection attacks
https://www.akamai.com/uk/en/multimedia/documents/state-of-the-internet/ddos-reflection-netbios-name-server-rpc-portmap-sentinel-udp-threat-advisory.pdf
2020-08-21 18:41:35 +02:00
Luca Deri da2684dbe1 MySQL8 update 2020-08-21 07:17:34 +02:00
Luca Deri 7e9354ef23 Merge pull request #988 from lnslbrty/add/mysql-8-manipulated-pkt
Added (manipulated) MySQL 8 test pcap.
2020-08-21 06:49:18 +02:00
Toni Uhlig f4421314b0 Added (manipulated) MySQL 8 test pcap.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-20 23:46:47 +02:00
Luca Deri 59ac73b37f Configure code cleanup 2020-08-19 22:01:03 +02:00
Luca Deri 115888ef7a Compilation fix 2020-08-19 21:56:34 +02:00
Luca Deri 248d756e99 Merge pull request #987 from lnslbrty/update/mysql-protocol-detection
Updated MySQL protocol detection to support server version 8.
2020-08-19 21:49:53 +02:00
Luca Deri 9f431f9218 Merge pull request #985 from lnslbrty/add/SOAP
Added support for SOAP.
2020-08-19 21:49:12 +02:00
Luca Deri d87bdf9302 Merge pull request #977 from adek05/dev
Enable building on OpenBSD 6.7
2020-08-19 21:48:38 +02:00
Toni Uhlig 3a76786121 Updated MySQL protocol detection to support server version 8.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-19 18:33:06 +02:00
Toni Uhlig 8e93f48c43 Added support for SOAP.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-18 16:21:26 +02:00
Luca Deri 673d8b7fac Updated OpenWRT instructions 2020-08-17 18:17:43 +02:00
Luca Deri 1f921562d1 Added fix for API versions starting with 0 2020-08-17 18:11:18 +02:00
Luca Deri 34a98abcc0 Added --with-only-libndpi configure option to build just lindpi 2020-08-17 18:00:38 +02:00
Luca Deri b501239d3f Added README for building libndpi under OpenWRT 2020-08-17 17:17:09 +02:00
Luca Deri ebf89f46e3 Merge pull request #984 from lnslbrty/fix/invalid-fncall-dpdk
Fixed invalid dpdk fn call.
2020-08-16 10:03:55 +02:00
Luca Deri 019a64630b Merge pull request #983 from lnslbrty/fix/libpcap-obsolete-pcap_lookupdev-usage
Replaced obsolete libpcap pcap_lookupdev with pcap_findalldevs.
2020-08-16 10:03:33 +02:00
Luca Deri 98a9afc40c Added support for discord 2020-08-16 10:01:40 +02:00
Toni Uhlig 13cbd1e4ae Fixed invalid dpdk fn call.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-15 12:38:47 +02:00
Toni Uhlig b31fde4bbb Replaced obsolete libpcap pcap_lookupdev with pcap_findalldevs.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-15 12:35:49 +02:00
Luca Deri 46ec91ca4b Merge pull request #976 from lnslbrty/fix/ndpi_simpleint_builderr
Fix/ndpi simpleint builderr
2020-08-13 10:41:25 +02:00
Luca Deri 8090765a64 Merge pull request #974 from IvanNardi/esni4
Suspicious ESNI usage: add a comment and a pcap example
2020-08-13 10:40:51 +02:00
Toni Uhlig aa856735c0 num_extra_packets_checked check can be 0 for some protocols and therefor requires lesser-or-equal condition for max_extra_packets_to_check
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-13 10:32:31 +02:00
Luca Deri 9edddee0b7 Fixes invalid detection on traffic on non standard ports 2020-08-12 11:08:28 +02:00
Luca Deri d5cac570d6 Improved DGA detection algoritm 2020-08-11 17:13:40 +02:00
Luca Deri 0e363d0ca6 Added HLL notes 2020-08-11 16:23:35 +02:00
aouinizied 8c2c388d54 Add Connectivity check category and blacklisted host risk. 2020-08-10 21:19:17 +02:00
aouinizied 8fcb49af25 Fix typo. 2020-08-10 21:17:36 +02:00
Luca Deri dfa9dd66c0 Added case-insensitive substring matching 2020-08-10 19:36:43 +02:00
Adrian Zgorzałek 56a3a33bc0 OpenBSD: Do not redefine __LITTLE_ENDIAN__
Will silence omnipresent compiler warnings when building ntopng.
2020-08-09 14:30:12 +01:00
Adrian Zgorzałek 8f74d5733d OpenBSD: Introduce pkt_timeval to deal with (bpf_)_timeval
Some BSD APIs called in example/ return `struct bpf_timeval`, where nDPI
APIs expect `struct timeval`. These two structs, besides having
a different name, share the exact same set of fields.
2020-08-09 14:30:12 +01:00
Toni Uhlig 4ead6d6594 travis-ci: build ndpiSimpleIntegration as well
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-08 12:17:54 +02:00
Toni Uhlig 8da5f42fa0 Changed ndpi_ssl_version2str function call in ndpiSimpleIntegration.
Fixes build error introduced with 23c072153.

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-08-08 12:05:11 +02:00
Nardi Ivan 2722861d6e Suspicious ESNI usage: add a comment and a pcap example
See: 79b89d2866
2020-08-06 10:29:35 +02:00
Luca Deri 95dfbdc64a Merge pull request #973 from IvanNardi/esni3
Add risk flag about suspicious ESNI usage
2020-08-06 10:18:27 +02:00
Luca Deri c2156a5161 Added note on memory management 2020-08-06 09:19:04 +02:00
Luca Deri 5b6ffad278 Added new ndpi_string_sha1_hash API call 2020-08-05 21:45:38 +02:00
Luca Deri d3fb1fb25a Fixed possible memory leak in TLS certificate handling 2020-08-05 17:57:00 +02:00
Nardi Ivan 79b89d2866 Add risk flag about suspicious ESNI usage
In a Client Hello, the presence of both SNI and ESNI may obfuscate the real
domain of an HTTPS connection, fooling DPI engines and firewalls, similarly
to Domain Fronting.

Such technique is reported in a presentation at DEF CON 28:
"Domain Fronting is Dead, Long Live Domain Fronting: Using TLS 1.3 to evade
censors, bypass network defenses, and blend in with the noise"
Full credit for the idea must go the original author

At the moment, the only way to get the pdf presention and related video is via
https://forum.defcon.org/node/234492
Hopefully a direct link (and an example pcap) will be available soon
2020-08-05 17:13:23 +02:00
Luca Deri 07d9fa7f96 Win #define fix 2020-08-05 11:13:27 +02:00
Luca Deri 00b2763399 Added check on payload lenght during extra packet processing 2020-08-04 21:59:45 +02:00
Luca Deri e16675b700 Added new traffic category for connectivity check detection 2020-08-04 18:09:13 +02:00
Luca Deri ea10b8e757 Added memory checks 2020-08-02 13:00:31 +02:00
aouinizied 57e28e03ee Sync TLS definitions. 2020-08-01 01:27:29 +02:00
Luca Deri 2ae4c6675d Fixed partial TLS dissection 2020-07-30 18:30:07 +02:00
Luca Deri e71df49b3e Changed due to bin size extension 2020-07-30 00:06:46 +02:00
Luca Deri 6904935934 Restored TLS dissection 2020-07-30 00:06:35 +02:00
Luca Deri a828ac0191 Tiny changes for TLS block lenght dissection 2020-07-29 22:36:27 +02:00
aouinizied c4b19fd6c5 Update CFFI definitions. 2020-07-29 12:31:21 +02:00
Luca Deri 02dc8d5feb Merge pull request #970 from IvanNardi/fix
Minor fixes
2020-07-28 19:38:12 +02:00
Luca Deri 32bd3d7a59 TLS dissection improvements 2020-07-28 01:06:38 +02:00
Luca Deri da87cc3157 Added NDPI_SMB_INSECURE_VERSION for detecting insecure SMB versions (e.g. v1) 2020-07-27 13:05:06 +02:00
Luca Deri 69f140878c Boundary check on QUIC 2020-07-27 07:40:50 +02:00
Luca Deri 4b1cae2c2b Boundary check 2020-07-27 06:52:35 +02:00
Nardi Ivan 7d843f4d17 Minor fixes
Fix a memory leak and an issue (re)-introduced in configure script
2020-07-26 21:11:34 +02:00
Luca Deri 95263fc32e Added parentheses to avoid issues with macro expansion 2020-07-25 18:59:48 +02:00
Luca Deri 1c405e382a SSH code cleanup 2020-07-25 16:43:54 +02:00
Luca Deri b26539d65a Merge pull request #967 from MrRadix/dev
Ssh signature checking
2020-07-25 16:17:24 +02:00
MrRadix 6719fa30f9 added other ssh implementations to check 2020-07-24 20:53:02 +02:00
Luca Deri 21e2e57614 Fixed bin similarity 2020-07-24 01:30:58 +02:00
Luca Deri 439558f6a3 Improved bin clustering 2020-07-22 23:56:50 +02:00
Luca Deri 0956badd11 Merge pull request #968 from catenacyber/fuzzci
Reenables CI with sanitizers
2020-07-22 19:38:05 +02:00
MrRadix a9ca47fcdb added cipher check 2020-07-22 17:17:12 +02:00
MrRadix 1c1be5a0d1 Resolved conflicts on fetch 2020-07-22 16:25:01 +02:00
Philippe Antoine 2723ac70ce msan cxx 2020-07-22 16:09:13 +02:00
Luca Deri 3cd1ec5c9a Added changes for handlign SSSH cipher detection 2020-07-22 15:58:46 +02:00
Philippe Antoine a279423bff Reenables CI with sanitizers 2020-07-22 15:49:03 +02:00
MrRadix a3ba9253ef fixed bug inside set bit macro call 2020-07-22 15:39:44 +02:00
MrRadix c450caae94 modified new last two risks 2020-07-22 15:38:31 +02:00
Luca Deri 36af97a14c Minor HLL fixes 2020-07-22 14:40:15 +02:00
MrRadix af5d792c08 added sscanf error handling 2020-07-22 13:06:08 +02:00
MrRadix 8e2cd9ff43 improved performance and legibility 2020-07-22 12:42:26 +02:00
MrRadix 88dd3ebd62 added modified risks 2020-07-22 12:41:59 +02:00
MrRadix d9fc4d52e9 merged with remote 2020-07-22 11:56:51 +02:00
MrRadix a688e36b51 improved ndpi_risk2str output for new risks 2020-07-22 11:44:56 +02:00
Luca Deri f83d0b18c6 Introduced SSH rick checks 2020-07-22 11:40:57 +02:00
Luca Deri 66178e37cc Merge pull request #966 from catenacyber/ossfuzzbuild
Enables fuzz targets even without sanitizer
2020-07-22 11:36:48 +02:00
Luca Deri 1740042cbb Merge branch 'dev' into ossfuzzbuild 2020-07-22 11:36:31 +02:00
Luca Deri f6242f0e46 HLL memory usage notes 2020-07-22 11:28:14 +02:00
MrRadix 0a182c6d18 Merge remote-tracking branch 'ntop_origin/dev' into dev 2020-07-22 11:15:02 +02:00
MrRadix 53b2b08aeb added new risks to ndpi_risk_enum 2020-07-22 10:56:59 +02:00
MrRadix 9c521c5ddd added new risks iside ndpi_risk2str function 2020-07-22 10:55:53 +02:00
MrRadix 847eb7b180 improved performance by removing linear scan 2020-07-22 10:54:55 +02:00
Luca Deri d90b333363 Merge pull request #965 from lnslbrty/fix/autoconf-ubuntu
fixes autoconf issue on ubuntu 18 (#953)
2020-07-21 21:41:02 +02:00
MrRadix f66cd5aabc added ssh_analyse_signature_version and ssh_has_old_signature for check old signature version of ssh 2020-07-21 19:31:02 +02:00
MrRadix 4b4dcabeda added ssh obsolete version risks 2020-07-21 19:29:59 +02:00
Luca Deri 879cec94b2 User agent detection improvements 2020-07-21 12:06:34 +02:00
Luca Deri 9f4f228832 Added skeleton for checking SSH signature 2020-07-20 17:25:17 +02:00
Philippe Antoine b568c26989 Enables fuzz targets even without sanitizer
Should fix ossfuzz build
2020-07-20 10:07:54 +02:00
Toni Uhlig 29315cee6d fixes autoconf issue on ubuntu 18 (#953)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-19 20:30:41 +02:00
Luca Deri f452dabd92 Fix for invalid boundary check 2020-07-17 23:26:28 +02:00
Luca Deri 64fb40d21e Added ndpi_reset_data_analysis() API call 2020-07-17 13:16:01 +02:00
Luca Deri 6e1dcba9dd Indendentation fix 2020-07-16 17:56:37 +02:00
Luca Deri ebf18a0c61 Merge pull request #964 from yskcg/dev
1:add free pointer NULL check;2:fix xbox and teredo protocol detected…
2020-07-16 17:05:40 +02:00
ysk a268952068 remove the unused code 2020-07-16 17:26:46 +08:00
Luca Deri acd05b171e Added ndpi_data_last() API call 2020-07-16 11:22:06 +02:00
ysk 69ca98ca35 1:add free pointer NULL check;2:fix xbox and teredo protocol detected error when use the commm udp port 3544 2020-07-16 16:07:04 +08:00
Luca Deri 46e97d5da3 Added ndpi_data_window_variance() and ndpi_data_window_stddev() API calls 2020-07-15 18:13:06 +02:00
Luca Deri 9f3e3e8456 Add ndpi_hll_reset() API call
Fixes bug in ndpi_data_window_average() with zero points
2020-07-15 10:30:45 +02:00
Luca Deri 91d132ea3d Check for avoiding buffer overflow in netbios dissector 2020-07-14 22:16:43 +02:00
Luca Deri 3fd3153089 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-07-13 15:48:53 +02:00
Luca Deri a8ad99aca5 Fixed makefile error message
Code hardedning fix
2020-07-13 15:46:19 +02:00
aouinizied 7744c225f9 Add note for sync with cffi bindings. 2020-07-13 12:51:32 +02:00
aouinizied e2e0303099 Add ssl_version_str to flow structure. 2020-07-13 12:48:35 +02:00
Luca Deri 802254327a wrapper cleanup 2020-07-13 10:53:25 +02:00
Luca Deri 9d8717a0c7 Merge pull request #963 from yskcg/dev
add improved boundary check and check malloc return is NULL
2020-07-13 10:24:23 +02:00
Luca Deri 9d35364ef1 Merge pull request #961 from lnslbrty/fix/ssl-version2str-race-condition
Fixed race condition in ndpi_ssl_version2str() caused by static quali…
2020-07-13 10:23:47 +02:00
Luca Deri 051bdb1957 Merge pull request #960 from lnslbrty/fix/heap-overflow-in-llc-readear-util
Fixed heap overflow caused by missing lengthcheck in 802.11 LLC heade…
2020-07-13 10:23:06 +02:00
Toni Uhlig 96c193cf79 Fixed heap overflow caused by missing lengthcheck in 802.11 LLC header parsing.
* triggered by fuzz traces from wireshark

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-11 13:10:03 +02:00
Toni Uhlig 23c0721538 Fixed race condition in ndpi_ssl_version2str() caused by static qualifier in the version string buffer.
* added also GREASE supported tls versions as specified in
   https://tools.ietf.org/html/draft-davidben-tls-grease-01#page-4

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-11 01:05:39 +02:00
ysk 35f1c362b9 add improved boundary check and check malloc return is NULL 2020-07-10 17:49:35 +08:00
Luca Deri 12abcd516b Updated test results due to bin changes 2020-07-09 17:28:02 +02:00
Luca Deri 014fdd9a02 Various fixes in bins implementation
Added -b flag in ndpiReader to test bins
2020-07-09 17:28:02 +02:00
Luca Deri 9d8967236e Merge pull request #957 from lnslbrty/fix/build
Fix/build
2020-07-09 17:27:53 +02:00
Alfredo Cardigliano 6511db8941 Guide update 2020-07-09 15:37:02 +02:00
aouinizied b8d406b1f8 Update note. 2020-07-09 00:58:48 +02:00
aouinizied ce02359953 Add NDPI_MALFORMED_PACKET risk. 2020-07-09 00:56:44 +02:00
Toni Uhlig 24fea66a26 travis-ci cleanups
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-09 00:33:20 +02:00
Luca Deri d658ac9e61 Added -b to ndpiReader to evaluate bins 2020-07-09 00:15:21 +02:00
Toni Uhlig f75984633b ndpiSimpleIntegration should not be included in a static library
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-08 23:47:51 +02:00
Toni Uhlig 20fed83e0f Removed csv_fp as external symbol. Instead passing csv_fp through as argument.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-08 23:21:35 +02:00
Luca Deri f72b402aa2 Merge pull request #956 from IvanNardi/leak
Fix memory leak reported in #955
2020-07-08 17:15:13 +02:00
Luca Deri 4f794aec22 Merge pull request #955 from lnslbrty/fix/heap-overflow-thunder
Fixed thunder protocol detection heap overflow caused by missing leng…
2020-07-08 17:14:45 +02:00
Nardi Ivan fd6a5bc1cd Fix memory leak reported in #955
This leak is clearly happening because of missing/disabled code in "bins"
handling.
This is a trivial workaround useful until such code is completed.
In this way tavis-ci will stop complaining
2020-07-08 11:30:39 +02:00
Alfredo Cardigliano 5be9370cd2 Fix warnings 2020-07-08 09:15:48 +02:00
Toni Uhlig ccb30a04ad Fixed thunder protocol detection heap overflow caused by missing lengthcheck.
* triggered by fuzz traces from wireshark

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-08 00:21:00 +02:00
Luca Deri fb04dbbc47 Added testing bin code 2020-07-07 19:18:43 +02:00
Luca Deri f1dd8bc8c5 Memory allocation fixes 2020-07-07 17:32:26 +02:00
Luca Deri 0c80e6ee3b Merge pull request #954 from lnslbrty/fix/memleak-cluster-bins
fixed memory leak in ndpi_cluster_bins / binUnitTest
2020-07-07 17:18:03 +02:00
Toni Uhlig e308e59002 fixed memory leak in ndpi_cluster_bins / binUnitTest
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-07 17:07:20 +02:00
Luca Deri 1c60c22893 Added ndpi_cluster_bins() for clustering bins and ancillary functions for bins manipulation 2020-07-07 15:10:51 +02:00
Luca Deri db707e0829 Merge pull request #932 from IvanNardi/log
Log
2020-07-07 14:43:32 +02:00
Luca Deri 540326f3ff Merge pull request #953 from lnslbrty/fix/broken-autoconf-fsanitizer
fix broken sanitizer CFLAGS, --enable-fuzztargets should also set -fs…
2020-07-07 14:42:42 +02:00
Luca Deri 94bf7b0130 Merge pull request #952 from lnslbrty/fix/missing-lengthcheck-in-reader-uutil
Fixed heap overflow caused by missing lengthcheck in reader uutil.
2020-07-07 14:42:20 +02:00
Nardi Ivan 030f3f3d48 Fix a memory leak 2020-07-07 10:27:57 +02:00
Toni Uhlig de25ba7d0b Fixed heap overflow caused by missing lengthcheck in reader uutil.
* triggered by fuzz traces from wireshark

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-06 23:30:40 +02:00
Toni Uhlig 9bbcc2548e fix broken sanitizer CFLAGS, --enable-fuzztargets should also set -fsanitize
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-06 22:09:11 +02:00
lucaderi 055422503c configure fixes 2020-07-06 10:38:29 +02:00
Luca Deri c0b34555c2 Merge pull request #951 from lnslbrty/fix/ossfuzzer
ossfuzz.sh: do not use wildcards for fuzzer e.g. fuzz/fuzz*
2020-07-06 10:23:50 +02:00
Luca Deri b4edb75824 Merge pull request #950 from lnslbrty/improved/http-line-parsing
Improved HTTP line parsing if request splitted into multiple packets.
2020-07-06 10:23:29 +02:00
Luca Deri dfb9e8ec1f Merge pull request #940 from lnslbrty/fix/small-and-optimistic-improvments
Fixed CodeInspector issues.
2020-07-06 10:23:04 +02:00
Toni Uhlig c17a21359b Fixed CodeInspector issues.
* Added compiler search list for AC_PROG_CC, AM_PROG_CC_C_O, AC_PROG_CXX, AC_PROG_CC_STDC
   for Mac OS X only
   The list rendered the AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer]) useless as it did use
   clang for AX_CHECK_COMPILE_FLAG but gcc during the compile process. Seems broken somehow.

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-05 20:41:02 +02:00
Toni Uhlig 6e8f268873 ossfuzz.sh: do not use wildcards for fuzzer e.g. fuzz/fuzz*
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-05 20:18:16 +02:00
Toni Uhlig 4b8c8608d1 Improved HTTP line parsing if request splitted into multiple packets.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-05 18:36:57 +02:00
Luca Deri 503e3bb495 Added comment on stddev 2020-07-03 14:45:58 +02:00
Luca Deri 513c857631 Added unit test 2020-07-03 14:43:14 +02:00
Luca Deri f7b91b46fa Merge pull request #947 from lnslbrty/add/download-script-wireshark-traces
added shell script to download wireshark traces, can be used in combi…
2020-07-03 00:45:45 +02:00
Luca Deri 143fcf0b0e Merge pull request #946 from lnslbrty/fix/teamviewer-iprange
Improved TeamViewer IP range (fixes #944)
2020-07-03 00:45:11 +02:00
Toni Uhlig ae89831055 added shell script to download wireshark fuzzing traces, can be used in combination with ./tests/do.sh
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-02 20:22:58 +02:00
Toni Uhlig 8f53c231df Improved TeamViewer IP range (fixes #944)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-07-02 18:11:39 +02:00
Nardi Ivan 974c1cc681 Improve help message of --dbg-proto option
Make it clear that such option is general, not about extcap
functionality
2020-07-02 09:42:53 +02:00
Nardi Ivan c08693fda5 Incorporated some feedback 2020-07-01 20:16:16 +02:00
Luca Deri 08698c65e5 Merge pull request #943 from lnslbrty/fix/missing-lengthcheck-in-tls-esni
Fixed heap overflow in tls esni extraction triggered by manipulated p…
2020-07-01 12:37:29 +02:00
Luca Deri 2d68f8f635 Merge pull request #942 from lnslbrty/improved/fuzzer-automake-dependency-tracking
Added fuzz_*_LDADD to give Automake the opportunity to do some depend…
2020-07-01 12:37:06 +02:00
Luca Deri 2860e3af15 Merge pull request #941 from lnslbrty/add/ossfuzz-script
Copy&Paste ./tests/ossfuzz.sh from https://github.com/google/oss-fuzz…
2020-07-01 12:36:42 +02:00
Luca Deri be35d423b4 Make clean enhancement 2020-07-01 12:34:28 +02:00
Luca Deri cf9c0b96b8 Indent 2020-06-30 16:25:53 +02:00
Alfredo Cardigliano ea6332e004 Fix segfault on ndpi_guess_protocol_id with flow = null 2020-06-30 15:54:52 +02:00
Luca Deri 392ce44573 Added ndpi_print_bin() API call 2020-06-29 22:36:46 +02:00
Toni Uhlig 05d7400563 Fixed heap overflow in tls esni extraction triggered by manipulated packets.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-29 21:51:46 +02:00
Toni Uhlig ea30fcb5de Added fuzz_*_LDADD to give Automake the opportunity to do some dependency tracking.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-29 21:27:03 +02:00
Toni Uhlig 3068306b60 Copy&Paste ./tests/ossfuzz.sh from https://github.com/google/oss-fuzz/pull/4041
* Changing the OSS-Fuzz script from our side is much more easier then
   opening a PR to google/oss-fuzz every time we have to change a single line.
 * https://github.com/google/oss-fuzz/pull/4041 will be updated once this PR is merged

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-29 20:50:09 +02:00
Luca Deri 0d2d44f1b6 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-06-29 19:51:36 +02:00
Luca Deri 07615903e2 Merge pull request #939 from lnslbrty/improved/fuzzy-reader-smp
Improved fuzz_ndpi_reader which supports now SMP/MT w/o race-coniditi…
2020-06-29 19:15:46 +02:00
Luca Deri 2c263bc726 Added ndpi_bin_similarity() for computing bin similarity 2020-06-29 19:09:38 +02:00
Toni Uhlig 4a6c525db8 Improved fuzz_ndpi_reader which supports now SMP/MT w/o race-coniditions.
./tests/do.sh can supports SMP/MT via environment variables.
Removed -fno-sanitize=shift as well, was fixed by 317d3ffd.

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-29 19:07:59 +02:00
Luca Deri 93a4a4387a Merge pull request #938 from IvanNardi/errors
Errors
2020-06-28 21:32:08 +02:00
Nardi Ivan f39e3c98f0 Update test results 2020-06-28 12:47:27 +02:00
Nardi Ivan 317d3ffd3e Fix undefined behaviour in internal tests
Error messages:
ndpiReader.c:3211:2: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
ndpiReader.c:3207:5: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

The errors started popping up since 3d9285f1
2020-06-28 12:13:21 +02:00
Nardi Ivan b24f5c4c0a Fix memory leak about purged/expired flows
Create an helper to avoid similar errors in the future
Fixes: 1a62f4c7
2020-06-28 12:05:12 +02:00
Nardi Ivan d6a97219ea Fix use-after-free in http content parsing 2020-06-28 12:05:12 +02:00
Nardi Ivan 3669c14afd DNP3: add missing initialization 2020-06-28 12:05:12 +02:00
Nardi Ivan ece5d3e199 Fix (harmless) memory leaks when DPDK is enabled 2020-06-28 12:05:12 +02:00
Nardi Ivan 2cdf7ce806 Fix startup when DPDK is enabled
Fixes:a58c838c4
2020-06-28 12:05:12 +02:00
Nardi Ivan 2effa57d8a ndpiReader: fix ports statistics
They should take idle/expired flows into account, too
2020-06-28 12:05:12 +02:00
Nardi Ivan b68b45f3bb TLS: extract JA3 signatures in some corner cases
In some (rare) cases, Client Hello message contains lots of cipher
suits.
2020-06-28 12:05:12 +02:00
Luca Deri b2e89e6736 Merge pull request #937 from lnslbrty/re-add-corpus-zipfile-for-google-oss-fuzz
Re-Added corpus zipfile generation required for google-oss fuzzer
2020-06-28 07:29:45 +02:00
Luca Deri 1010520cc4 Merge pull request #936 from lnslbrty/fix/h323-off-by-one
Fixed off-by-one error in h323.
2020-06-28 07:28:55 +02:00
Toni Uhlig f028cce209 Re-Added corpus zipfile generation required for google-oss fuzzer
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-27 23:04:20 +02:00
Toni Uhlig fbfa54eee6 Fixed off-by-one error in h323.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-27 22:58:05 +02:00
Luca Deri ff67e09101 Restored compiler check for fuzzy targets 2020-06-27 19:34:57 +02:00
Luca Deri 76e6c38459 Use clang where available and fallback to gcc when missing 2020-06-27 19:15:52 +02:00
Luca Deri 243104a8c2 Merge pull request #935 from lnslbrty/fix/fuzzing-tests
fixed fuzzing tests in a way that ./tests/do.sh is now able to use co…
2020-06-27 18:57:56 +02:00
Toni Uhlig 1f4523e331 fixed fuzzing tests in a way that ./tests/do.sh is now able to use corpus *.pcap files from ./tests/pcap
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-27 18:41:03 +02:00
Luca Deri b5f3facf7c Added notes whenever a new flow risk is added 2020-06-26 23:39:48 +02:00
Luca Deri 8566288e43 Added malformed packet risk support 2020-06-26 22:37:52 +02:00
Luca Deri 8de62c6d34 Values stored in patricia tree are now 32 bit (they used to be 16 bit) long 2020-06-26 17:49:45 +02:00
Nardi Ivan 0cd0905400 mqtt: add boundary check in log message 2020-06-26 12:04:02 +02:00
Nardi Ivan 56d87186f7 Fix compilation with --enable-debug-messages flag
NDPI_LOG* macros dereference ndpi_detection_module_struct object which is
private to ndpi library (via NDPI_LIB_COMPILATION define). So we can't use
them outside the library itself, i.e. in ndpiReader code
Therefore, in files in example/, convert all (rare) uses of NDPI_LOG* macros
to a new very simple macro, private to ndpiReader program. If necessary,
such macro may be improved.

According to a comment in ndpi_define.h, each dissector must define its own
NDPI_CURRENT_PROTO macro before including ndpi_api.h file
2020-06-26 12:04:02 +02:00
lucaderi ebfb5e7f01 Check for CentOS 6 2020-06-26 09:01:58 +02:00
Luca Deri d805611fcb Merge pull request #931 from lnslbrty/fix/autogen.sh
fixed autoconf version check
2020-06-25 23:31:10 +02:00
Luca Deri 9742dcc45c Merge pull request #930 from IvanNardi/extcap
Extcap
2020-06-25 23:30:20 +02:00
Toni Uhlig f38a8bd7a5 fixed autoconf version check
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-25 20:02:23 +02:00
Nardi Ivan 3c66ca236b Make lua script more robust 2020-06-25 18:02:03 +02:00
Nardi Ivan 70a926088f Fixed harmless memory leak in extcap initialization 2020-06-25 18:02:03 +02:00
Nardi Ivan 6b69e7ebbc Restore extcap functionality, i.e. integration with wireshark 2020-06-25 18:02:03 +02:00
Luca Deri 0b53bc2aab Disabled unused code 2020-06-25 10:50:39 +02:00
lucaderi ecdf7df454 Compilation fixes for non-Linux (or outdated Linux) platforms 2020-06-25 10:25:24 +02:00
lucaderi 3034e53d00 CentOS6 fix (santize won't work as too old system)
Fixes warning
2020-06-25 10:22:16 +02:00
Luca Deri 2350daa2dc Merge pull request #928 from lnslbrty/added/yet-another-ndpi-integration-example
PROPOSAL: ndpiSimpleIntegration: added another integration example
2020-06-25 10:05:49 +02:00
Luca Deri d710b8291d Merge pull request #927 from lnslbrty/fix/fbzero-missing-length-check
Fixed missing length check in fbzero.
2020-06-24 22:17:35 +02:00
Luca Deri 485e56d855 Merge pull request #926 from lnslbrty/added/hulustream-sni-pattern
Added hulustream SNI pattern. Fixes #904.
2020-06-24 22:17:09 +02:00
Luca Deri 38c0d927a9 Merge pull request #925 from lnslbrty/fix/ndpi-rader-unitialized-values
Fixed unitialized values in ndpiReader protocol detection bitmask dur…
2020-06-24 22:16:48 +02:00
Luca Deri 94a68451df Merge pull request #924 from lnslbrty/improved/autoconf-sanitizer-compile-flag-checks
Allow -fsanitize for LLVM as well as for GCC.
2020-06-24 22:15:11 +02:00
Toni Uhlig 17c26911fb ndpiSimpleIntegration: added another integration example
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-24 22:03:18 +02:00
Toni Uhlig ca68beda85 Fixed missing length check in fbzero.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-23 18:35:50 +02:00
Toni Uhlig 2f5766d2f5 Added hulustream SNI pattern. Fixes #904.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-23 17:30:37 +02:00
Toni Uhlig 39800c88fa Fixed unitialized values in ndpiReader protocol detection bitmask during dga selftest.
* make ./tests/vagrind_test.sh directory agnostic

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-23 17:23:56 +02:00
Toni Uhlig 678fbcdfd6 Allow -fsanitize for LLVM as well as for GCC.
* renamed --with-llvm-sanitizer to --with-sanitizer
 * disable all optimisations (-O0) if --with-sanitizer set,
   no functions/paramaters/variables will be optimised, improves debugging
 * enable undefined behaviour sanitizer (ubsan)
 * enable leak sanitizer (lsan)
 * check if -fsanitize=fuzzer is available and --enable-fuzztargets set,
   fail if not (only supported by clang)
 * include level 3 debugging information (-g3), improves macro debugging
 * disabled ubsan misaligned pointer access and lshift overflow

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-23 00:22:33 +02:00
Luca Deri d9af1562f0 Fixes #906
Packet bins are not printed wehn empty
2020-06-22 14:30:26 +02:00
Luca Deri e29e14b7aa Merge pull request #921 from lnslbrty/improved/test-sh
make tests/do.sh directory agnostic
2020-06-22 12:51:17 +02:00
Luca Deri c9d8efc2a4 Warning fix 2020-06-22 10:20:05 +02:00
Luca Deri 1a62f4c799 Added ndpi_bin_XXX API
Added packet lenght distribution bins
2020-06-22 01:02:54 +02:00
Luca Deri 2a137100da Merge pull request #922 from lnslbrty/fix/http-content-disposition-crash
Fixed use after free caused by dangling pointer
2020-06-22 00:57:15 +02:00
Toni Uhlig 6a9f5e4f7c Fixed use after free caused by dangling pointer
* This fix also improved RCE Injection detection

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-21 20:05:38 +02:00
Luca Deri fd0591b4fc Merge pull request #920 from lnslbrty/fix/tls-rdn-crash
Fixed stack overflow caused by missing length check
2020-06-19 11:44:37 +02:00
Luca Deri 48758d28ea Added GoogleDNS DoH on Android 10 2020-06-19 09:55:58 +02:00
Toni Uhlig 14f514134d make tests/do.sh directory agnostic
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-19 07:15:20 +02:00
Luca Deri 63670927e7 Fixed API documentation: packet tiestamp is expressed in milliseconds 2020-06-18 14:15:18 +02:00
Toni Uhlig 23594f0365 Fixed stack overflow caused by missing length check
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-18 00:52:04 +02:00
Luca Deri b2c24558c5 DGA detection improvements 2020-06-18 00:17:30 +02:00
Luca Deri 46d96e7f32 Added checks for DGA detection 2020-06-17 19:46:37 +02:00
Luca Deri ffd20ebdf9 Merge pull request #919 from lnslbrty/new/protocol/anydesk
Implemented proprietary AnyDesk protocol
2020-06-17 06:47:35 +02:00
Toni Uhlig da37f2444f Implemented proprietary AnyDesk protocol
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-06-17 01:23:03 +02:00
Alfredo Cardigliano 073e3a027b Add API ndpi_serializer_get_format 2020-06-16 18:40:17 +02:00
Luca Deri 0ddc3a0052 Fixed invalid assignment (typo) 2020-06-14 09:37:56 +02:00
Luca Deri 38e4910636 Added improved boundary check 2020-06-14 09:29:52 +02:00
aouinizied 4247dd8322 Synchronize type definitions. 2020-06-12 22:58:58 +02:00
Luca Deri 55364ef0b4 Added DGA risk for names that look like a DGA 2020-06-11 18:51:53 +02:00
Luca Deri 60aaa80570 Added HyperLogLog cardinality estimator API calls
/* Memory lifecycle */
int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits);
void ndpi_hll_destroy(struct ndpi_hll *hll);

/* Add values */
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len);
void ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) ;

/* Get cardinality estimation */
double ndpi_hll_count(struct ndpi_hll *hll);
2020-06-10 23:43:35 +02:00
Luca Deri 0b9e46e65a Updated (C) 2020-06-08 23:11:20 +02:00
Luca Deri 64fab4a478 Win fixes 2020-06-08 23:08:12 +02:00
Luca Deri 3506a07864 Added check in TLS 1.2+ for reporting a risk when TLS is not used to carry HTTPS 2020-06-08 14:20:10 +02:00
Luca Deri d318285cae Added HTTP check 2020-06-07 09:46:27 +02:00
Luca Deri 1479c0a278 Added TLS bounadry check 2020-06-07 09:25:19 +02:00
Luca Deri 43ddbfdfba Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-06-06 11:30:47 +02:00
Luca Deri 801c9481cb Removed some obsolete protocols (battlefield, oscar, pcanywhere, tvants) 2020-06-06 11:29:03 +02:00
Alfredo Cardigliano 2beecdc8af Handle EOR in TLV test 2020-06-06 11:18:17 +02:00
Luca Deri 605d548d4a removed obsolete yahoo plugin 2020-06-06 09:38:19 +02:00
Alfredo Cardigliano 0da76fdac6 Support for multiple records in CSV serialization 2020-06-05 17:28:27 +02:00
Luca Deri 597d6e5d60 Merge pull request #913 from yskcg/fix_segment_fault_dev
Fix segment fault dev
2020-06-05 16:57:46 +02:00
Alfredo Cardigliano 67c72a8cb5 Add ndpi_serializer_get_header API (CSV only) 2020-06-05 16:52:26 +02:00
Luca Deri 07c54f9992 Added ndpi_dpi2json() API call 2020-06-05 16:08:23 +02:00
Luca Deri 16ca69733a Improved teamviewer detection 2020-06-03 10:14:27 +02:00
ysk 40550073ef fix segment fault cause by the ssl.server_names when it may NULL 2020-06-03 11:19:37 +08:00
ysk 52893d99f6 fix segment fault cause by the ssl.server_names when it may NULL 2020-06-03 10:44:35 +08:00
ysk 86a3dc5bea Merge branch 'dev' of github.com:yskcg/nDPI into dev 2020-06-03 10:41:40 +08:00
Luca Deri 5afa3ad818 Improved spotify detection 2020-06-02 15:00:14 +02:00
Luca Deri af2a44ae5f Added boundary check in kerberos protocol 2020-06-01 18:22:10 +02:00
Luca Deri 241af016e9 Added check for spotify payload lenght 2020-06-01 16:36:12 +02:00
Luca Deri 16dc0ec29e Check to avoid allocating twice the esni memory 2020-06-01 16:34:24 +02:00
Luca Deri 29d9c2d2c8 Reworked HTTP header processing workflow 2020-06-01 09:54:05 +02:00
Luca Deri 669b7579ff HTTP comparison optimization 2020-05-31 19:31:01 +02:00
Luca Deri a4f8d913ea Minor changes 2020-05-31 19:11:12 +02:00
Luca Deri dc5b4cbde0 Reworked ndpi_strncasestr 2020-05-31 18:50:25 +02:00
Luca Deri b0bf66c436 Added offset check in kerberos dissector 2020-05-31 08:30:55 +02:00
Luca Deri c793e16050 Added extra TLS memory boundary checks 2020-05-31 08:28:02 +02:00
Luca Deri b6eef17e54 Added check to avoid producing alerts for known protocol on unknown port when using TLS 2020-05-30 19:33:13 +02:00
Luca Deri 374a24a1fb HTTP dissector improvements 2020-05-30 18:40:15 +02:00
Luca Deri cbb0b864a2 Minor cleanup 2020-05-29 21:51:51 +02:00
Luca Deri 61066fb106 Added check for heap buffer overflow read 2020-05-29 21:43:06 +02:00
Luca Deri 4ceff1dc77 Fixes for https://github.com/ntop/nDPI/pull/911
Added code for dumping invalid HTTP header
2020-05-29 21:23:46 +02:00
Luca Deri 0271e29097 Added references to ESNI 2020-05-29 21:23:34 +02:00
Luca Deri fcb50dec70 Merge pull request #911 from tmacchioni/dev
Added check for suspicious HTTP headers
2020-05-29 21:14:39 +02:00
Tommaso Macchioni db5cd92fe1 Added check for suspicious HTTP headers 2020-05-29 15:55:52 +02:00
Luca Deri 3085d8e4ff Refreshed test pcap 2020-05-28 21:23:02 +02:00
Luca Deri 9c3bfeca80 Added support for Encrypted TLS SNI dissection
https://datatracker.ietf.org/doc/draft-ietf-tls-sni-encryption/
2020-05-28 17:44:18 +02:00
Luca Deri f6038c358a Added ndpi_serialize_risk() API function 2020-05-27 17:35:11 +02:00
Luca Deri 3108c75059 Result update 2020-05-27 15:26:30 +02:00
Luca Deri 811d7a39b5 Added pcap with encrypted SNI
- https://blog.cloudflare.com/encrypted-sni/
- https://www.inmotionhosting.com/support/website/security/dns-over-https-encrypted-sni-in-firefox/
2020-05-27 15:00:55 +02:00
Luca Deri 030e9dddb7 Extended the cache for services that need to be reconciled such as Microsoft Teams
Added JSON-formatted Microsoft list of IP/services
2020-05-27 12:40:35 +02:00
Alfredo Cardigliano 2dce6cd525 Add ndpi_serialize_start_of_list/ndpi_serialize_end_of_list to serialize simple lists in JSON 2020-05-25 16:37:00 +02:00
Luca Deri 8fa5c31996 Added ndpi_serialize_risk() to the nDPI API 2020-05-24 08:54:38 +02:00
Luca Deri ee35834be6 Added flow risk serilization 2020-05-24 08:46:10 +02:00
aouinizied e5c2c400ef Update APIs and structures. 2020-05-22 23:48:54 +02:00
Luca Deri bbbc5fdbae Added memory boundary checks 2020-05-22 07:24:02 +02:00
Luca Deri 3874f0e0e0 Added stub for checking HTTP header
Updated Teams result
2020-05-21 15:19:55 +02:00
ysk 83ae5b7256 nDpi#remove build warnings 2020-05-21 14:06:52 +08:00
Luca Deri c02b00e0ce MS Teams uses as underlying protocol for voice/video. This commit adds the ability
to mark as MS Teams all Skype traffic made by a host with active MS Teams flows
2020-05-21 00:06:22 +02:00
Luca Deri 07d9e4f9ba Fixed valse positive whatsapp detection
Cleaned Microsoft IP addresses list
2020-05-20 23:28:21 +02:00
Luca Deri e9519c9aca Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-05-20 23:14:46 +02:00
Luca Deri 329eff069e Removed bittorrent false positive detection 2020-05-20 23:14:09 +02:00
Luca Deri 246ec53bcf Merge pull request #905 from lnslbrty/dev
Fixed docstring typos for ndpi_finalize_initalization
2020-05-20 08:48:49 +02:00
ysk cd65da69d3 Merge branch 'dev' of github.com:yskcg/nDPI into dev 2020-05-20 13:21:36 +08:00
ysk 068c1b1f22 someip#fix when run across architectures such ARM ,may be occour sigbus error(),Unhandled fault: alignment fault (0x92000021) at 0x00000000f67004aa 2020-05-20 13:15:42 +08:00
Luca Deri b7e666e465 Added fix to avoid potential heap buffer overflow in H.323 dissector
Modified HTTP report information to make it closer to the HTTP field names
2020-05-19 08:31:05 +02:00
Toni Uhlig c5e16b4ff7 Fixed docstring typos for ndpi_finalize_initalization
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-05-17 16:59:57 +02:00
Luca Deri 3d9285f1be Added check for invalid HTTP URLs 2020-05-16 00:10:35 +02:00
Luca Deri c375782b96 Added check for binary scripts
Added NDPI_HTTP_NUMERIC_IP_HOST risk
ndpi_risk moved to 32 bit
2020-05-15 22:49:55 +02:00
Luca Deri 8e7b1ea7a1 Fix for potential heap-buffer-overflow in ndpi_search_openvpn 2020-05-15 21:10:37 +02:00
Luca Deri e90c5c7c32 Added NDPI_HTTP_SUSPICIOUS_USER_AGENT ndpi_risk 2020-05-15 19:19:17 +02:00
Luca Deri 7dfbfff743 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-05-15 18:58:10 +02:00
Luca Deri da22aa5fc7 Added NDPI_TLS_CERTIFICATE_EXPIRED, NDPI_TLS_CERTIFICATE_MISMATCH, to ndpi_risk 2020-05-15 18:57:49 +02:00
Luca Deri a183b2ab9b Added link to nfstream 2020-05-15 18:11:59 +02:00
Luca Deri adfe6b763c Gotomeeting address range fix 2020-05-15 11:20:21 +02:00
Luca Deri 9ed94a722c Improvements on GotoMeeting
Added pcap for testing malware
2020-05-15 10:52:23 +02:00
Luca Deri 7037e79604 Merge pull request #903 from Loures/dev
Extend packet struct with Content-Disposition HTTP header field
2020-05-14 20:56:07 +02:00
loures 1edf5c49d6 Extend filetype matching for Content-Disposition header 2020-05-14 14:30:34 +02:00
loures baddfbb6c3 Extend packet struct with Content-Disposition HTTP header field
and improve HTTP binary transfer mime type check
2020-05-14 12:47:22 +02:00
Luca Deri fb64346e28 Code clenup for PR #902 2020-05-14 09:49:47 +02:00
Luca Deri 50be0b0049 Merge pull request #902 from Loures/dev
Add check for HTTP transfer of executable files
2020-05-14 09:12:17 +02:00
loures 08f32f2e0e Set risk field instead of changing protocol when checking for dangerous
HTTP traffic
2020-05-13 19:56:49 +02:00
loures 0a4fbb8cfb Add check for HTTP transfer of executable files 2020-05-13 18:32:29 +02:00
Luca Deri 9dfd0d0071 Code cleanup 2020-05-13 17:49:02 +02:00
Luca Deri 17235d234e Merge pull request #897 from catenacyber/fuzzoracle
Adds bound check in oracle protocol
2020-05-12 13:53:55 +02:00
Luca Deri db16a987c5 Merge pull request #896 from IvanNardi/nats
Fix NATS dissector
2020-05-12 13:52:42 +02:00
Luca Deri f7f705406f Invalid TLS check 2020-05-12 12:25:07 +02:00
Luca Deri cd765c08d6 Added NDPI_XXX_BIT_16 2020-05-11 09:07:30 +02:00
Luca Deri ee15c6149d Added TLS weak cipher and obsolete protocol version detection 2020-05-10 21:55:35 +02:00
Luca Deri ae803c8b51 Added detection of self-signed TLS certificates 2020-05-10 21:40:35 +02:00
Luca Deri e5e69d0f7a Added the ability to detect when a known protocol is using a non-standard port
Added check to spot executables exchanged via HTTP
2020-05-10 21:25:38 +02:00
Philippe Antoine b69177be2f Adds bound check in oracle protocol
Found by oss-fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21780
2020-05-10 15:04:23 +02:00
Nardi Ivan f8503da9e9 Fix NATS dissector 2020-05-09 15:41:20 +02:00
Luca Deri 39ae57e6a3 Cleaned hyperscan leftover
Added further hyperscan hooks
2020-05-08 18:24:07 +02:00
Luca Deri c9b37b92f5 Added self signed certificate test pcap 2020-05-08 09:09:58 +02:00
Luca Deri 4a09b4efa0 Added TLS issuerDN and subjectDN 2020-05-07 18:44:51 +02:00
Luca Deri fd646bd05f Reworked TLS dissector with a certificate RDN sequence reader 2020-05-07 17:22:01 +02:00
Luca Deri 6a1b8baa00 Fixed category matching 2020-05-06 23:50:35 +02:00
Luca Deri 2ccd2c204b API cleanup for indetifying explicitly in automa's what we're searching (protocol or category)
Removed hyperscan support that is apperently unused
2020-05-06 23:19:59 +02:00
Luca Deri 263547e77d Updated automa API to use 32 bit values splits from protocol/categpry 2020-05-06 21:57:32 +02:00
Luca Deri 86e34fbf6d Added support for Telegram v6 2020-05-06 18:06:30 +02:00
Luca Deri 84f66b4d6b Introduced custom protocols with IP and (optional) port support
Example

- Single IP address
  ip:213.75.170.11@CustomProtocol

- IP address with CIDR
  ip:213.75.170.11/32@CustomProtocol

- IP address with CIDR and port
  ip:213.75.170.11/32:443@CustomProtocol

Please note that there are some restrictions on the port
usage. They have been listed in example/protos.txt
2020-05-06 12:51:44 +02:00
Luca Deri 7855e0318d Various fixes to patricia tree handling 2020-05-06 11:13:57 +02:00
Luca Deri 48282369e2 False positive fixes 2020-05-06 01:34:55 +02:00
Luca Deri 7d63149ced Updated API 2020-05-06 00:41:07 +02:00
Luca Deri 427002d14f Reworked protocol handling chnging it is u_int16_t 2020-05-06 00:31:40 +02:00
Luca Deri 4148c5e065 Removed now obsolete MSN protocol
Added nats.io protocol dissector
2020-05-03 18:20:21 +02:00
Luca Deri c120cca662 SSH boundary check rework 2020-04-30 20:08:03 +02:00
Luca Deri 7344bf65bc Minor cleanup 2020-04-30 19:58:07 +02:00
Luca Deri 6f79b78f71 Merge pull request #891 from catenacyber/ghsl2
Better fix for integer overflow in SSH
2020-04-30 19:53:16 +02:00
Philippe Antoine a70fd6ed3b Better fix for integer overflow in SSH
Credits to GHSL
2020-04-30 18:44:40 +02:00
Luca Deri bd0fd6cf8d Merge pull request #883 from leonn/websocket
💡 implement WebSocket protocol dissector
2020-04-27 23:28:23 +02:00
Luca Deri 0bf809f8e5 Merge pull request #884 from lnslbrty/dev
Added missing ndpiReader dependency for the install target
2020-04-27 23:27:26 +02:00
Luca Deri 44259ab2b9 Merge pull request #887 from IvanNardi/tunnel
Tunnel
2020-04-27 23:27:03 +02:00
Alfredo Cardigliano 328016895f Handle empty blocks 2020-04-27 13:34:54 +00:00
Leonn Paiva 780dc8d1e7 💡 implement websocket protocol dissector 2020-04-26 02:53:12 -03:00
Alfredo Cardigliano 4d746dabe9 Enable IEC 60870-5-104 dissector 2020-04-24 15:31:44 +00:00
Nardi Ivan 097127c31d Fix heap-overflow error in CAPWAP detunneling code 2020-04-24 10:42:52 +02:00
Nardi Ivan c2ebbb15ad Fix "division by zero" runtime error 2020-04-23 14:24:49 +02:00
Nardi Ivan f965983c23 Add basic support for some ip-in-ip tunnels
Add support for 4in4, 6in6 and 4in6 encapsulations
Add support for ipv6 traffic in gtp tunnels, too

To allow gtp unit test, gtp detunneling flag has been globally enabled
in the test suite
2020-04-23 10:55:33 +02:00
Toni Uhlig 8d8e61b256 Added missing ndpiReader dependency for the install target
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2020-04-22 21:51:57 +02:00
Luca Deri 0b702c20d3 Warning fix 2020-04-22 18:52:36 +02:00
Luca Deri 473a5d1d0b Merge pull request #881 from leonn/bug_protocol_was_guessed
Bug protocol was guessed
2020-04-22 18:49:55 +02:00
Luca Deri 65b428899d Fix for nDPI code not downlooaded from git 2020-04-22 16:15:15 +02:00
Leonn Paiva 6769168d89 🐛 use protocol_was_guessed in ndpi_detection_giveup 2020-04-22 03:48:12 -03:00
Leonn Paiva 4d5ca2c473 🆒 code ident & style 2020-04-22 03:40:55 -03:00
Luca Deri e8cae3cff9 Updated results 2020-04-21 19:26:49 +02:00
Luca Deri 019b51bb17 Merge pull request #879 from IvanNardi/warnings
Fix some compilation warnings
2020-04-21 19:23:57 +02:00
Luca Deri e2be7daed6 Merge pull request #880 from catenacyber/fuzz8fix
Gets right protocol after IPv6 header
2020-04-21 19:22:50 +02:00
Philippe Antoine 1b73f7372e Gets right protocol after IPv6 header 2020-04-21 15:34:53 +02:00
Nardi Ivan b1a6c6b895 Fix some compilation warnings 2020-04-20 16:53:39 +02:00
Luca Deri e603549967 Office365 renamed to Microsoft365 (by Microsoft) 2020-04-20 15:44:27 +02:00
Luca Deri 3bdec5ae5f Updated node list (fixes #766) 2020-04-20 15:16:31 +02:00
Luca Deri 25cd2a23a6 Compilation fixes 2020-04-20 15:08:51 +02:00
Luca Deri 97badc574b Merge pull request #877 from catenacyber/fuzz7fix
Adds bound check before calling ndpi_handle_ipv6_extension_headers
2020-04-20 13:56:53 +02:00
Luca Deri 493bffb3e0 Added check for pkg-config presence 2020-04-19 21:48:24 +02:00
Philippe Antoine c2b2692e65 Seeting right flow protocol after IP6 extensions
Finally fixing https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20727
2020-04-18 14:39:57 +02:00
Philippe Antoine db5f3b38b7 Adds CIFuzz to check PRs
cf https://google.github.io/oss-fuzz/getting-started/continuous-integration/
2020-04-18 10:50:56 +02:00
Philippe Antoine da0889d3ba Adds bound check before calling ndpi_handle_ipv6_extension_headers 2020-04-17 22:21:03 +02:00
Luca Deri 94eee66a7b CiscoVPN dissection improvements 2020-04-17 16:56:55 +02:00
Luca Deri 748df7972a Results update 2020-04-17 10:36:27 +02:00
Luca Deri a766de7b94 Merge pull request #876 from a-czyrny/dev
additional csv semicolon fix
2020-04-17 10:34:41 +02:00
Luca Deri 711ba99eaa Added detection of Microsoft Teams 2020-04-16 15:23:07 +02:00
Alexander Czyrny 32d25bfdaf additional csv semicolon fix
Created function correct_csv_data_field to pevent duplicated code. Additionally used for _flow->ndpi_flow->protos.stun_ssl.ssl.alpn_ and _flow->ndpi_flow->protos.stun_ssl.ssl.tls_supported_versions_ to guarantee a valid csv output (commas replaced by semicolon) .
2020-04-16 14:12:48 +02:00
Luca Deri 287015ffdc Fixed invalid check 2020-04-15 22:42:09 +02:00
Luca Deri f4c24663fc Merge pull request #874 from catenacyber/fuzz6fix
Fuzz6fix
2020-04-15 18:05:16 +02:00
Luca Deri 9f2dabbda4 Merge pull request #873 from a-czyrny/a-czyrny-ndpireader-csv-patch
Fix for missing line breaks in CSV file
2020-04-15 18:04:26 +02:00
Philippe Antoine 4f370fe7c4 Adds netbios bound check 2020-04-15 16:40:00 +02:00
Philippe Antoine 9483c842b5 TLS initializes version_str 2020-04-15 16:40:00 +02:00
Philippe Antoine c1f9f05d33 Adds tls check before reading memory 2020-04-15 16:22:16 +02:00
Philippe Antoine cf47ba234a Use ndpi_handle_ipv6_extension_headers in reader_util 2020-04-15 16:19:57 +02:00
Philippe Antoine 98f2d3a73c Adds bound check for IRC 2020-04-15 15:56:58 +02:00
Philippe Antoine c1baf1516d Adds bound check for TZSP 2020-04-15 15:50:58 +02:00
Philippe Antoine 369dc65c1a Fix integer overflow in quic 2020-04-15 15:45:32 +02:00
Philippe Antoine 4ec3e6c064 Adds bound check in TLS 2020-04-15 15:42:54 +02:00
Philippe Antoine 81e97d7515 Fixes OOB reads in postgres
Reported by GHSL
2020-04-15 15:35:34 +02:00
Alexander Czyrny 32ab88a26e Fix for missing line breaks in CSV file
If "-v" is used as an argument, the line breaks are missing in the csv file ("-C"), because the argument "-J" is assumed. Moving the condition for the CSV file handler out of the scope of the "enable_joy_stats" condition removes this dependency and the CSV file is formatted correctly.
2020-04-15 10:12:37 +02:00
Luca Deri afdae85b30 Restored ndpi_get_api_version() prototype 2020-04-15 09:06:02 +02:00
Luca Deri 63c4eaae9b Invalid function definition fix 2020-04-13 22:40:20 +02:00
Luca Deri 4e876a4543 Merge pull request #866 from anticomputer/packet_payload_integer_ql
ql query to identify suspicious use of network sourced integers
2020-04-15 08:38:23 +02:00
Luca Deri 7b54d028a3 Merge pull request #872 from aouinizied/dev
Update python example.
2020-04-15 08:37:28 +02:00
Luca Deri 9cba06a080 Merge pull request #869 from disconnect3d/patch-2
Fix incorrect "<iq from=\"' parsing
2020-04-15 08:36:27 +02:00
Luca Deri 794f7fa124 Merge pull request #868 from disconnect3d/patch-1
Fix off by one when checking for "GET / HTTP" string
2020-04-15 08:35:59 +02:00
Luca Deri d3b4b81d6f Merge pull request #867 from IvanNardi/memory-leaks
Memory leaks
2020-04-15 08:35:28 +02:00
Zied Aouini 1bee9d85a4 Fix flow_printer example. 2020-04-15 08:05:03 +02:00
Disconnect3d fa15e170b4 Fix incorrect "<iq from=\"' parsing
This PR fixes a wrong size arg passed to memcmp when checking for "<iq from=\"" and "<iq from \'" strings.
2020-04-13 16:35:03 +02:00
Disconnect3d b75838b771 Fix off by one when checking for "GET / HTTP" string 2020-04-13 16:33:27 +02:00
Luca Deri d665df64e2 Added ndpi_serialize_raw_record() API call 2020-04-10 21:39:23 +02:00
Nardi Ivan e84563f971 ndpiReader: fix memory leak in idle sessions purging 2020-04-08 15:15:34 +02:00
Nardi Ivan a60854bae6 Fix some debug messages 2020-04-08 15:15:34 +02:00
Nardi Ivan 7b690d8b2d kerberos: fix heap-overflow error 2020-04-08 15:15:34 +02:00
Nardi Ivan 0c1322a718 s7comm: fix heap-overflow error 2020-04-08 15:15:34 +02:00
Nardi Ivan b40732d8a5 Fix an harmless memory leak
Leak introduced in 90e08b35, while fixing #845
2020-04-08 15:15:34 +02:00
Luca Deri db8497778d Fixes #853 and adds a self check for duplicates 2020-04-07 19:17:37 +02:00
Luca Deri dea883a25d Minor refresh 2020-04-07 19:01:38 +02:00
Luca Deri 81a2f54dd7 Merge pull request #865 from catenacyber/ghsl-2020-05x
Ghsl 2020 05x
2020-04-05 08:29:43 +02:00
Luca Deri c2c01b618b Fix for string serialization with initial empty string 2020-04-03 15:26:24 +02:00
Bas Alberts fb863c6bfb ql query to identify suspicious use of network sourced integers 2020-04-02 17:14:49 -04:00
Philippe Antoine 7ce478a58b ssh: fixing unsigned overflow leading to heap overflow
cf GHSL-2020-051
2020-04-02 16:48:35 +02:00
Philippe Antoine 3bbb0cd329 ssh: adds systematic bounds checks in concat_hash_string
cf GHSL-2020-052
2020-04-02 16:35:10 +02:00
Luca Deri 56ca71bda9 Merge pull request #863 from IvanNardi/memory-errors
Memory errors
2020-03-31 17:51:20 +02:00
Nardi Ivan 498571354d openvpn: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan 3924257f32 telnet: fix another heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan 817aa54214 telnet: fix heap-overflow error
There is some boilerplate since I removed an if branch and I had to reindent
the code
2020-03-27 11:09:53 +01:00
Nardi Ivan 97fc94c7e8 kerberos: fix use-after-free error
After leaving kerberos code, the original packet may be processed from
other dissector (i.e. TLS)
2020-03-27 11:09:53 +01:00
Nardi Ivan 9ec711aa90 tls: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan 9c2c04d8ce ssh: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan 4f399356a6 quic: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan 45ff2a3f5a h323: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan 58f0f29113 soulseek: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Nardi Ivan da5e5a3e2a ciscovpn: fix heap-overflow error 2020-03-27 11:09:53 +01:00
Luca Deri 17d531e3db Added s7comm test pcap 2020-03-27 09:35:59 +01:00
Luca Deri 0d223ada3f Compilation fix 2020-03-27 08:46:03 +01:00
Luca Deri 890e8644ac Merge pull request #861 from havup/dev
pull request with s7comm
2020-03-27 08:38:44 +01:00
havup 1bab8a1c22 Update s7comm.c 2020-03-27 14:02:10 +08:00
havup 24bb0b7f53 Update s7comm.c 2020-03-27 13:09:46 +08:00
havup 803b13a7a8 Update s7comm.c 2020-03-27 12:58:56 +08:00
havup 7841145d9c Update tls_long_cert.pcap.out 2020-03-27 12:28:15 +08:00
havup efdac78ddc Update s7comm.c 2020-03-27 11:19:50 +08:00
havup 74825ffc6e Update s7comm.c 2020-03-26 13:06:02 +08:00
emanuele-f 1b8f7ed101 Fix API version generation 2020-03-25 14:07:19 +01:00
emanuele-f 9cf016c5f1 Fix ndpi_get_api_version version truncation 2020-03-25 14:00:47 +01:00
Luca Deri 47a4507d9e NDPI_API_VERSION is now computed automatically 2020-03-25 12:51:06 +01:00
havup 779d9a6e51 Add files via upload 2020-03-25 19:09:14 +08:00
havup ac17e0bea7 Update ndpi_main.c 2020-03-25 19:06:36 +08:00
havup 4d95dae2ae Update ndpi_main.c 2020-03-25 19:05:49 +08:00
havup 6c3cbe50e2 Update ndpi_protocols.h 2020-03-25 19:04:35 +08:00
havup a2b163beca Update ndpi_protocol_ids.h 2020-03-25 19:04:00 +08:00
Luca Deri c8a1767465 Fixed invalid allocation 2020-03-24 13:36:03 +01:00
Luca Deri 40be74c629 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-03-23 14:45:08 +01:00
Luca Deri df5cf59787 Format update 2020-03-23 14:44:33 +01:00
Luca Deri d26349e082 Format update 2020-03-23 14:37:14 +01:00
Luca Deri 7add3acc53 Added fuzz-2020-02-16-11 fuzzy pcap 2020-03-23 10:27:32 +01:00
Luca Deri 1c1a18d12f Added fuzz-2006-09-29-2858 fuzzy pcap 2020-03-23 10:25:28 +01:00
Luca Deri 92bd223c34 Added fuzz-2006-06-26-2594.pcap fuzzy pcap 2020-03-23 10:24:11 +01:00
Luca Deri 9d53c3c3b8 Added wa_video.pcap 2020-03-23 10:23:05 +01:00
Luca Deri 906d7fe0c1 Added wa_voice.pcap 2020-03-23 10:22:46 +01:00
Luca Deri cd78740caf Added netflow-fritz.pcap 2020-03-23 10:11:51 +01:00
Luca Deri 626ee52049 Added smb_deletefile.pcap 2020-03-23 10:09:47 +01:00
Luca Deri 7a93994802 Added iphone.pcap 2020-03-23 10:09:14 +01:00
Luca Deri 1bb10863e4 Added android.pcap 2020-03-23 10:08:57 +01:00
Luca Deri 924bc9698b Added badpackets.pcap 2020-03-23 10:06:16 +01:00
Luca Deri 9aba94713c Added dns_exfiltration.pcap 2020-03-23 10:06:00 +01:00
Luca Deri 00beac6b1a Added netbios.pcap 2020-03-23 10:05:41 +01:00
Luca Deri 8c2ffc5b37 Added dos_win98_smb_netbeui.pcap 2020-03-23 10:05:24 +01:00
Luca Deri a845e99720 Merge pull request #859 from catenacyber/fuzzudpfix
Checks enough data for UDP header
2020-03-20 18:02:27 +01:00
Luca Deri 8cda02bb14 Fixed loop in serialization 2020-03-20 18:01:37 +01:00
Philippe Antoine 3e259aac98 tls_supported_versions only if version_str is initialized
With version_len == (extension_len-1)
2020-03-19 17:19:28 +01:00
Philippe Antoine 2aec630202 Fix use of uninitialized value in TLS 2020-03-19 17:16:41 +01:00
Philippe Antoine c6acf97bfb Adds different checks against overflows 2020-03-19 16:54:31 +01:00
Philippe Antoine e9195589d2 Checks enough data for UDP header 2020-03-19 16:44:53 +01:00
Luca Deri b2cbe76e71 Added QUIC v046 test pcap 2020-03-17 16:51:25 +01:00
Luca Deri 4227be7989 Update for QUIC 046 2020-03-17 16:48:34 +01:00
Simone Mainardi e282e43279 Fixes netbios overread
This commit inherits from https://github.com/ntop/nDPI/commit/7a2bcd9c395f9fe554109e04add33e9e65564d82
but leaves ndpi_netbios_name_interpret as part of the API as it
is used by ntopng
2020-03-12 22:21:07 +01:00
Simone Mainardi 2f15ce706f Fixed API change which removed ndpi_netbios_name_interpret
This reverts commit 7a2bcd9c39.
2020-03-12 22:08:59 +01:00
Luca Deri 70ee793ff3 Merge pull request #856 from catenacyber/fuzzfix5
Fuzzfix5
2020-03-12 18:13:30 +01:00
Philippe Antoine 7806eb5f5b Fix infinite loop in tls 2020-03-12 14:31:47 +01:00
Philippe Antoine 9d1340a8e7 Fix buffer overread in yahoo 2020-03-12 14:26:08 +01:00
Philippe Antoine 7a2bcd9c39 Fix buffer overread in netbios 2020-03-12 14:22:46 +01:00
Philippe Antoine fe513014a8 Fix buffer over read in dns 2020-03-12 14:13:04 +01:00
Philippe Antoine 3c05d4551d Fix snprintf return value check for tls 2020-03-12 14:05:48 +01:00
Philippe Antoine 4976d93d4e Fix buffer overread in ndpi_search_setup_capwap 2020-03-12 14:03:31 +01:00
Luca Deri 1e933e8b02 Win fixes 2020-03-12 11:26:38 +01:00
Luca Deri 942a71c7eb NetBIOS dissection improvements 2020-03-01 11:42:21 +01:00
Luca Deri 7fd135a8c9 Added SMBv1 over NetBIOS detection 2020-03-01 11:32:09 +01:00
Luca Deri 34ad06fef5 Compilation fix 2020-02-28 16:03:27 +01:00
Luca Deri 8f45f51e6c Compilation fix 2020-02-28 15:28:41 +01:00
Luca Deri 9f72b15fff Merge pull request #850 from catenacyber/fuzz4fix
Fuzz4fix
2020-02-28 14:39:17 +01:00
Philippe Antoine 6fe9535881 Adds check before memcpy for bittorrent 2020-02-26 17:12:46 +01:00
Philippe Antoine 5fc9d41eb0 Run ndpi_detection_process_packet only with payload
Real problem is decapsulation of all ipv6 headers
2020-02-26 17:05:08 +01:00
Philippe Antoine 933351840d Fix off by one in imap 2020-02-26 16:59:04 +01:00
Philippe Antoine 83fdfe24d0 Fix read overflow before UDP header 2020-02-26 16:16:29 +01:00
Alfredo Cardigliano d4c093e828 Check NULL strings in ndpi_serialize_string_string 2020-02-26 09:55:24 +01:00
Luca Deri c0ec78885d Merge pull request #849 from annp1987/fix_ndpi_flow2json_segfault
ndpi_flow2json should check http.url before serializer
2020-02-26 08:06:11 +01:00
Luca Deri a55c410202 Merge pull request #848 from aouinizied/dev
nDPI 3.2 support in python cffi bindings
2020-02-26 08:05:45 +01:00
Nguyen Phuong An e675be1a83 ndpi_flow2json should check http.url before serializer
This patch will fix issue: https://github.com/ntop/PF_RING/issues/557
2020-02-26 13:32:13 +07:00
Luca Deri f07a329447 Merge branch 'dev' of https://github.com/ntop/nDPI into dev 2020-02-23 19:10:14 +01:00
Luca Deri 2ceff3e214 Fixed swapped protocol 2020-02-23 19:09:58 +01:00
Zied Aouini dcb6fde0c9 Update Python cffi bindings. 2020-02-21 17:28:44 +01:00
Zied Aouini e67604a583 Remove trailing alignment directives. 2020-02-21 16:37:36 +01:00
Zied Aouini 40896d3d44 Fix docstrings. 2020-02-21 15:51:17 +01:00
Zied Aouini 5a0f609086 Add ndpi_flow_tcp_struct and ndpi_flow_udp_struct api calls. 2020-02-21 15:49:46 +01:00
Alfredo Cardigliano 2972e29097 Moved to 3.3 2020-02-20 10:15:11 +01:00
386 changed files with 19947 additions and 13037 deletions
+23
View File
@@ -0,0 +1,23 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'ndpi'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'ndpi'
fuzz-seconds: 600
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v1
if: failure()
with:
name: artifacts
path: ./out/artifacts
@@ -0,0 +1,83 @@
/**
* @name Suspicious packet->payload based integer arithmetic
* @description An arithmetic operation influenced array access is suspicious
* if it uses an integer value that is likely to be network-controlled, and
* may require a closer manual audit.
* @kind problem
* @problem.severity warning
* @id cpp/packet-payload-integer-arithmetic
* @tags audit security
*/
import cpp
import semmle.code.cpp.dataflow.TaintTracking
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
/** A source of an integer value that is likely to come from the network.
* This is produced by an invocation of a macro of the form `ntoh*` or `get_u_int*_t`,
* called with `packet->payload` as an argument.
*/
class NetworkMacro extends Macro {
NetworkMacro() { this.getName().regexpMatch("^ntoh(ll|l|s)") }
}
class NetworkIntegerSource extends Expr {
NetworkIntegerSource() {
exists(MacroInvocation mi |
this = mi.getExpr() and
mi.getUnexpandedArgument(0).regexpMatch(".*packet->payload.*") |
// catch all get_u_int*_t(x)
mi.getMacroName().regexpMatch("^get_u_int(64|32|16|8)_t") and
// dedup ntoh*(get_u_int*_t(x)) since we'll catch those in the next case
not mi.getOutermostMacroAccess().getMacro() instanceof NetworkMacro
or
// catch all ntoh*(x) ... this will also catch the nested cases
mi.getMacro() instanceof NetworkMacro
)
}
}
class ArithmeticOperation extends Operation {
ArithmeticOperation() {
this instanceof UnaryArithmeticOperation or this instanceof BinaryArithmeticOperation
}
}
class NetworkToArrayAccess extends TaintTracking::Configuration {
NetworkToArrayAccess() { this = "NetworkToArrayAccess" }
override predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof NetworkIntegerSource
}
override predicate isSink(DataFlow::Node sink) {
exists(ArrayExpr ae | sink.asExpr() = ae.getArrayOffset())
}
}
class NetworkToArithmetic extends TaintTracking::Configuration {
NetworkToArithmetic() { this = "NetworkToArithmetic" }
override predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof NetworkIntegerSource
}
override predicate isSink(DataFlow::Node sink) {
exists (Assignment assign |
sink.asExpr() = assign.getRValue().(ArithmeticOperation) or
sink.asExpr() = assign.(AssignArithmeticOperation)
) or
exists(LocalVariable var |
sink.asExpr() = var.getInitializer().getExpr().(ArithmeticOperation)
)
}
}
// find audit candidates based on suspicious network integer use
from NetworkIntegerSource source, Expr sink1, Expr sink2, NetworkToArithmetic config1, NetworkToArrayAccess config2
where config1.hasFlow(DataFlow::exprNode(source), DataFlow::exprNode(sink1))
// or this if you want integer arithmeric _OR_ array accesses
and config2.hasFlow(DataFlow::exprNode(source), DataFlow::exprNode(sink2))
select source, "Suspicious use of network integer arithmetic."
+37 -13
View File
@@ -12,6 +12,8 @@ matrix:
apt:
packages:
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
- os: linux
@@ -21,6 +23,8 @@ matrix:
apt:
packages:
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
- os: linux
@@ -31,6 +35,8 @@ matrix:
apt:
packages:
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
- os: linux
@@ -41,6 +47,8 @@ matrix:
apt:
packages:
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
# Targets below have been disabled as we have no way
@@ -53,6 +61,7 @@ matrix:
# apt:
# packages:
# - libpcap-dev
# - libjson-c-dev
# - autogen
#
# - os: linux
@@ -63,6 +72,7 @@ matrix:
# apt:
# packages:
# - libpcap-dev
# - libjson-c-dev
# - autogen
- os: linux
@@ -74,9 +84,11 @@ matrix:
packages:
- g++-8
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
env:
- MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
- MATRIX_EVAL="CC=gcc-8"
- os: linux
compiler: gcc-9
@@ -87,9 +99,11 @@ matrix:
packages:
- g++-9
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
env:
- MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
- MATRIX_EVAL="CC=gcc-9"
- os: linux
compiler: clang-8
@@ -101,9 +115,11 @@ matrix:
packages:
- clang-8
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
env:
- MATRIX_EVAL="CC=clang-8 && CXX=clang++-8"
- MATRIX_EVAL="CC=clang-8"
- os: linux
compiler: clang-7
@@ -115,12 +131,14 @@ matrix:
packages:
- clang-7
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
env:
- MATRIX_EVAL="CC=clang-7 && CXX=clang++-7"
- MATRIX_EVAL="CC=clang-7"
- name: fuzza
env: CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link" CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link" LDFLAGS="-g -fsanitize=address" QA_FUZZ=asan CC=clang-7 && CXX=clang++-7 ASAN_SYMBOLIZER_PATH=/usr/local/clang-7.0.0/bin/llvm-symbolizer
env: CXXFLAGS="-g3 -O0 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link" CFLAGS="-g3 -O0 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize=fuzzer-no-link" LDFLAGS="-g3 -O0 -fsanitize=address" QA_FUZZ=asan CC=clang-7 && CXX=clang++-7 ASAN_SYMBOLIZER_PATH=/usr/local/clang-7.0.0/bin/llvm-symbolizer
os: linux
compiler: clang-7
addons:
@@ -131,22 +149,23 @@ matrix:
packages:
- clang-7
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
- name: fuzzm
env: CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link" CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link" LDFLAGS="-g -fsanitize=memory" QA_FUZZ=msan CC=clang-7 && CXX=clang++-7 MSAN_SYMBOLIZER_PATH=/usr/local/clang-7.0.0/bin/llvm-symbolizer
env: CXXFLAGS="-g3 -O0 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link" CFLAGS="-g3 -O0 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize=fuzzer-no-link" LDFLAGS="-g3 -O0 -fsanitize=memory" QA_FUZZ=msan CC=clang && CXX=clang++
os: linux
compiler: clang-7
compiler: clang
dist: bionic
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
packages:
- clang-7
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
- name: fuzzu
env: CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fsanitize=fuzzer-no-link" CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fno-sanitize-recover=undefined,integer -fsanitize=fuzzer-no-link" LDFLAGS="-g -fsanitize=undefined" QA_FUZZ=ubsan CC=clang-7 && CXX=clang++-7
env: CXXFLAGS="-g3 -Og -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fsanitize=fuzzer-no-link -fno-sanitize=alignment" CFLAGS="-g3 -Og -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=undefined -fno-sanitize-recover=undefined,integer -fsanitize=fuzzer-no-link -fno-sanitize=alignment" LDFLAGS="-g3 -Og -fsanitize=undefined -fno-sanitize=alignment" QA_FUZZ=ubsan CC=clang-7 && CXX=clang++-7
os: linux
compiler: clang-7
addons:
@@ -157,10 +176,12 @@ matrix:
packages:
- clang-7
- libpcap-dev
- libgcrypt20-dev
- libjson-c-dev
- autogen
before_install:
before_install:
- eval "${MATRIX_EVAL}"
before_script:
@@ -170,10 +191,13 @@ before_script:
script:
- if [ -n "$QA_FUZZ" ]; then ./configure --enable-fuzztargets ; else ./configure ; fi
- make
- make -C example ndpiSimpleIntegration
- make dist
#after_script:
- cd tests
- ./do.sh
- ./do-unit.sh
#after_success:
#- cd ${TRAVIS_BUILD_DIR}
+57 -3
View File
@@ -1,5 +1,59 @@
# CHANGELOG
#### nDPI 3.4 (October 2020)
## New Features
* Completely reworked and extended QUIC dissector
* Added flow risk concept to move nDPI towards result interpretation
* Added ndpi_dpi2json() API call
* Added DGA risk for names that look like a DGA
* Added HyperLogLog cardinality estimator API calls
* Added ndpi_bin_XXX API calls to handle bin handling
* Fully fuzzy tested code that has greatly improved reliability and robustness
## New Supported Protocols and Services
* QUIC
* SMBv1
* WebSocket
* TLS: added ESNI support
* SOAP
* DNScrypt
## Improvements
* Python CFFI bindings
* Various TLS extensions and fixes including extendede metadata support
* Added various pcap files for testing corner cases in protocols
* Various improvements in JSON/Binary data serialization
* CiscoVPN
* H323
* MDNS
* MySQL 8
* IEC 60870-5-104
* DoH/DoT dissection improvements
* Office365 renamed to Microsoft365
* Major protocol dissection improvement in particular with unknwon traffic
* Improvement in Telegram v6 protocol support
* HTTP improvements to detect file download/upload and binary files
* BitTorrent and WhatsApp dissection improvement
* Spotify
* Added detection of malformed packets
* Fuzzy testing support has been greatly improved
* SSH code cleanup
## Fixes
* Fixed various memory leaks and race conditions in protocol decoding
* NATS, CAPWAP dissector
* Removed HyperScan support that greatly simplified the code
* ARM platform fixes on memory alignment
* Wireshark extcap support
* DPDK support
* OpenWRT, OpenBSD support
* MINGW compiler support
## MISC
* Created demo app for nDPI newcomers
* Removed obsolete pplive and pando protocols
#### nDPI 3.2 (February 2020)
## New Features
@@ -47,7 +101,7 @@
* Improved Python bindings
* Improved Ethereum support
* Improved categories detection with streaming and HTTP
* Support for IP-based detection to compute the application protocol
* Support for IP-based detection to compute the application protocol
* Renamed protocol 104 to IEC60870 (more meaningful)
* Added failed authentication support with FTP
* Renamed DNSoverHTTPS to handle bot DoH and DoT
@@ -59,7 +113,7 @@
* Modified API signatures for ndpi_ssl_version2str / ndpi_detection_giveup
* Removed ndpi_pref_http_dont_dissect_response / ndpi_pref_dns_dont_dissect_response (replaced by ndpi_extra_dissection_possible)
## Fixes
## Fixes
* Fixed memory invalid access in SMTP and leaks in TLS
* Fixed a few memory leaks
* Fixrd invalid memory access in a few protocol dissectors (HTTP, memcached, Citrix, STUN, DNS, Amazon Video, TLS, Viber)
@@ -228,7 +282,7 @@
## Other
* Deb and RPM packages: ndpi with shared libraries and binaries, ndpi-dev with headers and static libraries
* Protocols now have an optional subprotocol: Spotify cannot have subprotocols, DNS can (DNS.Spotify)
* Protocols now have an optional subprotocol: Spotify cannot have subprotocols, DNS can (DNS.Spotify)
* New API functions:
* ndpi_fill_ip_protocol_category to handle ICMP flows category
* ndpi_flowv4_flow_hash and ndpi_flowv6_flow_hash to support the Community ID Flow Hashing (https://github.com/corelight/community-id-spec)
+5 -2
View File
@@ -1,5 +1,5 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src/lib example tests
SUBDIRS = src/lib @EXTRA_TARGETS@
if BUILD_FUZZTARGETS
SUBDIRS += fuzz
@@ -8,4 +8,7 @@ endif
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libndpi.pc
EXTRA_DIST = autogen.sh
EXTRA_DIST = README.md CHANGELOG.md CONTRIBUTING.md README.protocols autogen.sh configure.seed wireshark python windows utils packages doc/nDPI_QuickStartGuide.pages doc/nDPI_QuickStartGuide.pdf example/MacOS example/Win32
changelog:
git log --since={`curl -s https://github.com/ntop/ndpi/releases | grep datetime | head -n1 | egrep -o "[0-9]+\-[0-9]+\-[0-9]+"`} --name-only --pretty=format:" - %s" | grep "^ " > Changelog.latest
+5 -11
View File
@@ -8,7 +8,7 @@
## 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
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
@@ -42,21 +42,15 @@ The entire procedure of adding new protocols in detail:
10. make check
### How to use nDPI to Block Selected Traffic
You can use nDPI to selectively block selected Internet traffic by embedding it onto an application (remember that nDPI is just a library). Both [ntopng](https://github.com/ntop/ntopng) and [nProbe cento](http://www.ntop.org/products/netflow/nprobe-cento/) can do this.
### nDPI-Related Projects
- [nfstream](https://github.com/aouinizied/nfstream)
### DISCLAIMER
While we do our best to detect network protocols, we cannot guarantee that our software is error free and 100% accurate in protocol detection. Please make sure that you respect the privacy of users and you have proper authorization to listen, capture and inspect network traffic.
### Creating A Source File Tar Ball
If you want to distribute a source tar file of nDPI do:
- make dist
To ensure that a tar file includes all necessary files and to run tests on distribution do:
- make distcheck
nDPI is a registered trademark in the US and EU.
[ntopng_logo]: https://camo.githubusercontent.com/0f789abcef232035c05e0d2e82afa3cc3be46485/687474703a2f2f7777772e6e746f702e6f72672f77702d636f6e74656e742f75706c6f6164732f323031312f30382f6e746f706e672d69636f6e2d313530783135302e706e67
+5 -4
View File
@@ -5,17 +5,18 @@ Prerequisites
- GNU autotools/libtool
- libpcap or PF_RING (optional but recommended)
- apt-get install libjson-c-dev (for JSON support)
- libgcrypt20-dev (for QUIC support)
On Ubuntu/Debian
- apt-get install build-essential
- apt-get install git autoconf automake autogen libpcap-dev libtool
- apt-get install git autoconf automake autogen libpcap-dev libtool libgcrypt20-dev
On Fedora/CentOS
- yum groupinstall "Development tools"
- yum install git autoconf automake autogen libpcap-devel libtool
- yum install git autoconf automake autogen libpcap-devel libtool libgcrypt-devel
On MacOSX (using http://brew.sh)
brew install autoconf automake libtool git
brew install autoconf automake libtool git libgcrypt
On FreeBSD
- pkg install autoconf automake libtool gmake git
- pkg install autoconf automake libtool gmake git libgcrypt
+16 -2
View File
@@ -1,7 +1,7 @@
#!/bin/sh
NDPI_MAJOR="3"
NDPI_MINOR="2"
NDPI_MINOR="4"
NDPI_PATCH="0"
NDPI_VERSION_SHORT="$NDPI_MAJOR.$NDPI_MINOR.$NDPI_PATCH"
@@ -12,10 +12,17 @@ AUTOMAKE=$(command -v automake)
LIBTOOL=$(command -v libtool)
LIBTOOLIZE=$(command -v libtoolize)
AUTORECONF=$(command -v autoreconf)
PKG_CONFIG=$(command -v pkg-config)
FUZZY=
if test -z $AUTOCONF; then
echo "autoconf is missing: please install it and try again"
exit
else
V=`autoconf --version | head -1 | cut -d ' ' -f 4`
if [ "$V" = '2.63' ]; then
FUZZY="dnl> "
fi
fi
if test -z $AUTOMAKE; then
@@ -33,11 +40,17 @@ if test -z $AUTORECONF; then
exit
fi
if test -z $PKG_CONFIG; then
echo "pkg-config is missing: please install it (apt-get install pkg-config) and try again"
exit
fi
cat configure.seed | sed \
-e "s/@NDPI_MAJOR@/$NDPI_MAJOR/g" \
-e "s/@NDPI_MINOR@/$NDPI_MINOR/g" \
-e "s/@NDPI_PATCH@/$NDPI_PATCH/g" \
-e "s/@NDPI_VERSION_SHORT@/$NDPI_VERSION_SHORT/g" \
-e "s/@FUZZY@/$FUZZY/g" \
> configure.ac
autoreconf -ivf
@@ -45,4 +58,5 @@ cat configure | sed "s/#define PACKAGE/#define NDPI_PACKAGE/g" | sed "s/#define
cat configure.tmp > configure
chmod +x configure
./configure "$*"
./configure $@
+92 -75
View File
@@ -1,24 +1,39 @@
AC_INIT([libndpi], [@NDPI_VERSION_SHORT@])
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_ARG_WITH(llvm_sanitizer, [ --with-llvm-sanitizer Build with support for the LLVM address sanitizer])
EXTRA_TARGETS="example tests tests/unit"
AC_ARG_WITH(only-libndpi, AS_HELP_STRING([--with-only-libndpi], [Build only libndpi (no examples, tests etc)]))
AS_IF([test "${with_only_libndpi+set}" = set],[
EXTRA_TARGETS=""
])
AS_IF([test "${with_llvm_sanitizer+set}" = set],[
CFLAGS="${CFLAGS} -g -O2 -Wno-unused-value -fsanitize=address -fno-omit-frame-pointer"
LDFLAGS="${LDFLAGS} -fsanitize=address"
CC=clang
CXX=clang++
AC_ARG_WITH(sanitizer, AS_HELP_STRING([--with-sanitizer], [Build with support for address, undefined and leak sanitizer]))
AC_ARG_ENABLE(fuzztargets, AS_HELP_STRING([--enable-fuzztargets], [Enable fuzz targets]),[enable_fuzztargets=$enableval],[enable_fuzztargets=no])
AM_CONDITIONAL([BUILD_FUZZTARGETS], [test "x$enable_fuzztargets" = "xyes"])
AS_IF([test "${with_sanitizer+set}" = set],[
CFLAGS="${CFLAGS} -g3 -O0 -Wno-unused-value -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=leak -fno-omit-frame-pointer"
LDFLAGS="${LDFLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=leak"
])
LT_INIT
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_CC_STDC
SYSTEM=`uname -s`
if test $SYSTEM = "Darwin"; then
dnl> AC_PROG_CC(clang gcc)
AM_PROG_CC_C_O(clang gcc)
AC_PROG_CXX(clang++ g++)
AC_PROG_CC_STDC(clang gcc)
else
dnl> AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_CC_STDC
fi
AC_LANG_WERROR
AX_PTHREAD
@@ -31,39 +46,52 @@ AC_DEFINE_UNQUOTED(NDPI_MAJOR_RELEASE, "${NDPI_MAJOR}", [nDPI major release])
AC_DEFINE_UNQUOTED(NDPI_MINOR_RELEASE, "${NDPI_MINOR}", [nDPI minor release])
AC_DEFINE_UNQUOTED(NDPI_PATCH_LEVEL, "${NDPI_PATCH}", [nDPI patch level])
if test -d ".git"; then :
# .git as directory in a cloned repo
# .git as file in submodule based integration
if test -d ".git" || test -f ".git" ; then :
GIT_TAG=`git log -1 --format=%h`
GIT_DATE=`git log -1 --format=%cd`
#
# On CentOS 6 `git rev-list HEAD --count` does not work
#
#
#
GIT_NUM=`git log --pretty=oneline | wc -l | tr -d '[[:space:]]'`
GIT_RELEASE="${PACKAGE_VERSION}-${GIT_NUM}-${GIT_TAG}"
A=`git log src/include/ndpi_typedefs.h|wc -l`
B=`git log src/include/ndpi_protocol_ids.h|wc -l`
C=`git log src/include/ndpi_api.h.in|wc -l`
NDPI_API_VERSION=$((A+B+C))
else
GIT_RELEASE="${PACKAGE_VERSION}"
GIT_DATE=`date -u -r CHANGELOG.md`
NDPI_API_VERSION=`date +%s | cut -c7-10`
fi
NDPI_API_VERSION=`echo $NDPI_API_VERSION | sed 's/^0*//'`
AC_DEFINE_UNQUOTED(NDPI_GIT_RELEASE, "${GIT_RELEASE}", [GIT Release])
AC_DEFINE_UNQUOTED(NDPI_GIT_DATE, "${GIT_DATE}", [Last GIT change])
AC_CHECK_HEADERS([netinet/in.h stdint.h stdlib.h string.h unistd.h])
dnl> used by json-c
JSONC_INC=`pkg-config --cflags json-c`
CFLAGS="${CFLAGS} ${JSONC_INC}"
AC_CHECK_HEADERS([netinet/in.h stdint.h stdlib.h string.h unistd.h json.h])
ADDITIONAL_LIBS=
PCAP_HOME=$HOME/PF_RING/userland
DPDK_TARGET=
AC_MSG_CHECKING([DPDK (used by ndpiReader)])
if test -d $HOME/DPDK; then :
echo "Enabling DPDK support in ndpiReader"
AC_MSG_RESULT(yes)
DPDK_TARGET=dpdk
else
echo "DPDK support disabled (missing $HOME/DPDK)"
AC_MSG_RESULT([no (missing $HOME/DPDK)])
fi
if test -d $PCAP_HOME; then :
echo -n ""
else
if ! test -d $PCAP_HOME; then :
PCAP_HOME=`pwd`/../../PF_RING/userland
fi
SHORT_MACHINE=`uname -m | cut -b1-3`
@@ -74,10 +102,6 @@ else
fi
MACHINE=`uname -m`
SYSTEM=`uname -s`
if test $SYSTEM = "Darwin"; then
CC=clang
fi
CUSTOM_NDPI=
@@ -86,30 +110,11 @@ if test -d ../nDPI-custom; then :
AC_MSG_RESULT([Compiling with custom nDPI protocols])
fi
AC_ARG_WITH(hyperscan, [ --with-hyperscan Enable nDPI build with Intel Hyperscan])
AS_IF([test "${with_hyperscan+set}" = set],[
BKP=$LIBS
LIBS="$LIBS -lstdc++ -lm"
AC_CHECK_LIB([hs], [hs_compile_multi], AC_DEFINE_UNQUOTED(HAVE_HYPERSCAN, 1, [Intel Hyperscan is present]))
LIBS=$BKP
AS_IF([test "x$ac_cv_lib_hs_hs_compile_multi" = xyes],[
AC_CHECK_LIB([m], [pow])
AC_CHECK_LIB([stdc++], [main])
PKG_CHECK_MODULES([HS],[libhs])
LDFLAGS="$LDFLAGS $HS_LIBS"
AC_MSG_RESULT([compiling with Intel Hyperscan])
],[
AC_MSG_RESULT([Intel Hyperscan not found, exiting. See https://github.com/intel/hyperscan/blob/master/doc/dev-reference/getting_started.rst for install/build instructions])
exit 1
])
])
case "$host" in
*-*-mingw32*|*-*-msys)
CFLAGS="${CFLAGS} -DOS_WIN32"
LDFLAGS="${LDFLAGS} -lws2_32 -lucrtbase"
BUILD_MINGW=1
;;
*)
if test -f $PCAP_HOME/libpcap/libpcap.a; then :
@@ -137,57 +142,66 @@ AC_ARG_ENABLE([debug-messages],
AS_HELP_STRING([--enable-debug-messages], [Define NDPI_ENABLE_DEBUG_MESSAGES=1]), [
AC_DEFINE(NDPI_ENABLE_DEBUG_MESSAGES, 1, [Enable ndpi_debug_messages]) ])
AC_ARG_ENABLE(fuzztargets,
AS_HELP_STRING([--enable-fuzztargets], [Enable fuzz targets]),[enable_fuzztargets=$enableval],[enable_fuzztargets=no])
AM_CONDITIONAL([BUILD_FUZZTARGETS], [test "x$enable_fuzztargets" = "xyes"])
AS_IF([test "x$enable_fuzztargets" = "xyes"], [
AC_PROG_CXX
AC_LANG_PUSH(C++)
tmp_saved_flags=$[]_AC_LANG_PREFIX[]FLAGS
AS_IF([test "x$LIB_FUZZING_ENGINE" = "x"], [
LIB_FUZZING_ENGINE=-fsanitize=fuzzer
AC_SUBST(LIB_FUZZING_ENGINE)
])
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $LIB_FUZZING_ENGINE"
AC_MSG_CHECKING([whether $CXX accepts $LIB_FUZZING_ENGINE])
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size);
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) {
(void)Data;
(void)Size;
return 0;
}
]])],
[ AC_MSG_RESULT(yes)
has_sanitizefuzzer=yes],
[ AC_MSG_RESULT(no) ]
)
_AC_LANG_PREFIX[]FLAGS=$tmp_saved_flags
AC_LANG_POP()
])
@FUZZY@ AS_IF([test "x$enable_fuzztargets" = "xyes"], [
@FUZZY@ AC_PROG_CXX
@FUZZY@ AC_LANG_PUSH(C++)
@FUZZY@ tmp_saved_flags=$[]_AC_LANG_PREFIX[]FLAGS
@FUZZY@ AX_CHECK_COMPILE_FLAG([-fsanitize=fuzzer],,
@FUZZY@ [AC_MSG_ERROR([--enable-fuzztargets requires -fsanitize=fuzzer which is only supported by LLVM])],
@FUZZY@ [-Werror])
@FUZZY@ AS_IF([test "x$LIB_FUZZING_ENGINE" = "x"], [
@FUZZY@ LIB_FUZZING_ENGINE=-fsanitize=fuzzer
@FUZZY@ AC_SUBST(LIB_FUZZING_ENGINE)
@FUZZY@ ])
@FUZZY@ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $LIB_FUZZING_ENGINE"
@FUZZY@ AC_MSG_CHECKING([whether $CXX accepts $LIB_FUZZING_ENGINE])
@FUZZY@ AC_LINK_IFELSE([AC_LANG_SOURCE([[
@FUZZY@ #include <sys/types.h>
@FUZZY@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size);
@FUZZY@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) {
@FUZZY@ (void)Data;
@FUZZY@ (void)Size;
@FUZZY@ return 0;
@FUZZY@ }
@FUZZY@ ]])],
@FUZZY@ [ AC_MSG_RESULT(yes)
@FUZZY@ has_sanitizefuzzer=yes],
@FUZZY@ [ AC_MSG_RESULT(no) ]
@FUZZY@ )
@FUZZY@ _AC_LANG_PREFIX[]FLAGS=$tmp_saved_flags
@FUZZY@ AC_LANG_POP()
@FUZZY@ ])
AM_CONDITIONAL([HAS_FUZZLDFLAGS], [test "x$has_sanitizefuzzer" = "xyes"])
AC_CHECK_LIB(pthread, pthread_setaffinity_np, AC_DEFINE_UNQUOTED(HAVE_PTHREAD_SETAFFINITY_NP, 1, [libc has pthread_setaffinity_np]))
dnl> GCRYPT
AC_ARG_ENABLE([gcrypt],
[AS_HELP_STRING([--disable-gcrypt], [Avoid compiling with libgcrypt/libgpg-error, even if they are present. QUIC sub-classification may be missing])],
[:],
[AC_CHECK_LIB(gcrypt, gcry_cipher_checktag)
AC_CHECK_LIB(gpg-error, gpg_strerror_r)])
if test "x$ac_cv_lib_gcrypt_gcry_cipher_checktag" = xyes; then :
ADDITIONAL_LIBS="${ADDITIONAL_LIBS} -lgcrypt"
fi
dnl> PCRE
AC_ARG_WITH(pcre, [ --with-pcre Enable nDPI build with libpcre])
if test "${with_pcre+set}" = set; then :
AC_CHECK_LIB(pcre, pcre_compile, AC_DEFINE_UNQUOTED(HAVE_PCRE, 1, [libpcre(-dev) is present]))
if test "x$ac_cv_lib_pcre_pcre_compile" = xyes; then :
ADDITIONAL_LIBS=-lpcre
ADDITIONAL_LIBS="${ADDITIONAL_LIBS} -lpcre"
fi
fi
AC_CONFIG_FILES([Makefile example/Makefile example/Makefile.dpdk tests/Makefile libndpi.pc src/include/ndpi_define.h src/lib/Makefile python/Makefile fuzz/Makefile])
AC_CONFIG_FILES([Makefile example/Makefile example/Makefile.dpdk tests/Makefile tests/unit/Makefile libndpi.pc src/include/ndpi_define.h src/lib/Makefile python/Makefile fuzz/Makefile src/include/ndpi_api.h])
AC_CONFIG_HEADERS(src/include/ndpi_config.h)
AC_SUBST(GIT_RELEASE)
AC_SUBST(NDPI_MAJOR)
AC_SUBST(NDPI_MINOR)
AC_SUBST(NDPI_PATCH)
AC_SUBST(NDPI_VERSION_SHORT)
AC_SUBST(SVN_DATE)
AC_SUBST(JSON_C_LIB)
AC_SUBST(PCAP_INC)
AC_SUBST(PCAP_LIB)
AC_SUBST(ADDITIONAL_LIBS)
@@ -195,4 +209,7 @@ AC_SUBST(DL_LIB)
AC_SUBST(DPDK_TARGET)
AC_SUBST(HAVE_PTHREAD_SETAFFINITY_NP)
AC_SUBST(CUSTOM_NDPI)
AC_SUBST(NDPI_API_VERSION)
AC_SUBST(EXTRA_TARGETS)
AC_SUBST(BUILD_MINGW)
AC_OUTPUT
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -21,7 +21,7 @@ SRCS-y := reader_util.c intrusion_detection.c ndpiReader.c
CFLAGS += -g
CFLAGS += -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-parameter -I $(PWD)/../src/include @CFLAGS@ -DUSE_DPDK
LDLIBS = $(LIBNDPI) @PCAP_LIB@ -lpthread @LDFLAGS@
LDLIBS = $(LIBNDPI) @PCAP_LIB@ @LIBS@ -lpthread -lm @LDFLAGS@
include $(RTE_SDK)/mk/rte.extapp.mk
+22 -6
View File
@@ -1,29 +1,39 @@
CC=@CC@
CXX=@CXX@
BUILD_MINGW=@BUILD_MINGW@
SRCHOME=../src
CFLAGS=-g -fPIC -DPIC -I$(SRCHOME)/include @CFLAGS@
CFLAGS=-g -fPIC -DPIC -I$(SRCHOME)/include @PCAP_INC@ @CFLAGS@
LIBNDPI=$(SRCHOME)/lib/libndpi.a
LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @ADDITIONAL_LIBS@ -lpthread -lm @LDFLAGS@
LDFLAGS=$(LIBNDPI) @PCAP_LIB@ @LIBS@ @ADDITIONAL_LIBS@ -lpthread -lm @LDFLAGS@
HEADERS=intrusion_detection.h reader_util.h $(SRCHOME)/include/ndpi_api.h \
$(SRCHOME)/include/ndpi_typedefs.h $(SRCHOME)/include/ndpi_protocol_ids.h
OBJS=ndpiReader.o reader_util.o intrusion_detection.o
PREFIX?=@prefix@
ifneq ($(BUILD_MINGW),)
all:
@echo 'Examples disabled due to mingw build.'
else
all: ndpiReader @DPDK_TARGET@
EXECUTABLE_SOURCES := ndpiReader.c
EXECUTABLE_SOURCES := ndpiReader.c ndpiSimpleIntegration.c
COMMON_SOURCES := $(filter-out $(EXECUTABLE_SOURCES),$(wildcard *.c ))
libndpiReader.a: $(COMMON_SOURCES:%.c=%.o) $(LIBNDPI)
ar rsv libndpiReader.a $(COMMON_SOURCES:%.c=%.o)
ndpiReader: libndpiReader.a $(LIBNDPI) $(EXECUTABLE_SOURCES:%.c=%.o)
$(CXX) $(CFLAGS) $(EXECUTABLE_SOURCES:%.c=%.o) libndpiReader.a -o $@ $(LDFLAGS)
ndpiReader: libndpiReader.a $(LIBNDPI) ndpiReader.o
$(CC) $(CFLAGS) ndpiReader.o libndpiReader.a -o $@ $(LDFLAGS)
ndpiSimpleIntegration: ndpiSimpleIntegration.o
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) -c $< -o $@
install:
install: ndpiReader
mkdir -p $(DESTDIR)$(PREFIX)/bin/
mkdir -p $(DESTDIR)$(PREFIX)/share/ndpi
cp ndpiReader $(DESTDIR)$(PREFIX)/bin/
@@ -44,6 +54,12 @@ clean:
/bin/rm -f _install _postbuild _postinstall _preinstall
/bin/rm -rf build
distdir:
cp categories.txt mining_hosts.txt protos.txt README.DPDK '$(distdir)/'
find . -maxdepth 1 -type f -name '*.c' -o -name '*.h' -o -name '*.py' | xargs -I'{}' cp '{}' '$(distdir)/{}'
distclean: clean
/bin/rm -f Makefile.dpdk
/bin/rm -f Makefile
endif
+3 -9
View File
@@ -1,7 +1,7 @@
/*
* intrusion_detection.c
*
* Copyright (C) 2011-19 - ntop.org
* Copyright (C) 2011-20 - 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
@@ -53,7 +53,6 @@ double get_flow_score(ndpi_norm_value* scores, int n_metrics){
/* ********************************** */
double Ddos_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_c_to_s_avg */
@@ -105,7 +104,6 @@ double Ddos_score(struct ndpi_flow_info* flow){
}
double Dos_goldeneye_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_s_to_c_max */
@@ -156,7 +154,7 @@ double Dos_goldeneye_score(struct ndpi_flow_info* flow){
}
double Dos_hulk_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
double f = (double)flow->first_seen_ms/1000.0, l = (double)flow->last_seen_ms/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* duration */
@@ -208,7 +206,6 @@ double Dos_hulk_score(struct ndpi_flow_info* flow){
}
double Dos_slow_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_s_to_c_max */
@@ -260,7 +257,6 @@ double Dos_slow_score(struct ndpi_flow_info* flow){
}
double Ftp_patator_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* iat_flow_min */
@@ -312,7 +308,7 @@ double Ftp_patator_score(struct ndpi_flow_info* flow){
}
double Hearthbleed_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
double f = (double)flow->first_seen_ms/1000.0, l = (double)flow->last_seen_ms/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* iat_flow_max */
@@ -364,7 +360,6 @@ double Hearthbleed_score(struct ndpi_flow_info* flow){
}
double Infiltration_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* pktlen_c_to_s_max */
@@ -416,7 +411,6 @@ double Infiltration_score(struct ndpi_flow_info* flow){
}
double Ssh_patator_score(struct ndpi_flow_info* flow){
double f = (double)flow->first_seen/1000.0, l = (double)flow->last_seen/1000.0;
int n_metrics = 6;
ndpi_norm_value* scores = malloc(n_metrics * sizeof(ndpi_norm_value));
/* fin */
+512 -224
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+22 -9
View File
@@ -10,19 +10,32 @@ tcp:3000@ntop
# Format:
# host:"<value>",host:"<value>",.....@<subproto>
host:"googlesyndication.com"@Google
host:"venere.com"@Venere
host:"kataweb.it",host:"repubblica.it"@Repubblica
host:"ntop"@ntop
host:"atv-ext.amazon.com",host:"*.api.amazon.com",host:"*.api.amazonvideo.com"@AmazonVideo
host:"*.amazonaws.com"@AmazonVideo
host:"*.netflix.com"@Netflix
host:"disneyplus.com"host:"cdn.registerdisney.go.com",host:"disney-portal.my.onetrust.com",host:"disneyplus.bn5x.net",host:"disney-plus.net"@DisneyPlus
host:"*.lvlt.dash.us.aiv-cdn.net.c.footprint.net"@AmazonVideo
host:"api-global.netflix.com"@Netflix
# IP based Subprotocols
# Format:
# ip:<value>,ip:<value>,.....@<subproto>
ip:213.75.170.11@CustomProtocol
ip:8.248.73.247@AmazonPrime
#
# NOTES
# 1) the port of a custom protocol is optional but if
# specified it must match the port.
# 2) you can specify up to 1 port per IP address
# 3) if you specify a custom ip:<IP>:<PORT> rule,
# even if the <PORT> doesn't match the <IP>
# (if best match during the search) will
# have priority as best match. Example if
# you specify a <Google IP>:<port 9999> and
# in your traffic have match for such IP but
# with a port other than 9999, the IP address
# begin a best match will hve preference over
# <Google IP> so this protocol will not be
# detected as <L7 proto>.Google but only
# as <L7 proto>
#
ip:213.75.170.11/32:443@CustomProtocol
ip:8.248.73.247:443@AmazonPrime
ip:54.80.47.130@AmazonPrime
+393 -227
View File
File diff suppressed because it is too large Load Diff
+36 -11
View File
@@ -31,6 +31,7 @@
#include "uthash.h"
#include <pcap.h>
#include "ndpi_includes.h"
#include "ndpi_classify.h"
#include "ndpi_typedefs.h"
@@ -50,6 +51,7 @@
#define PREFETCH_OFFSET 3
extern int dpdk_port_init(int port, struct rte_mempool *mbuf_pool);
extern int dpdk_port_deinit(int port);
#endif
/* ETTA Spec defiintions for feature readiness */
@@ -127,13 +129,13 @@ struct flow_metrics {
struct ndpi_entropy {
// Entropy fields
struct timeval src2dst_last_pkt_time, dst2src_last_pkt_time, flow_last_pkt_time;
pkt_timeval src2dst_last_pkt_time, dst2src_last_pkt_time, flow_last_pkt_time;
u_int16_t src2dst_pkt_len[MAX_NUM_PKTS]; /*!< array of packet appdata lengths */
struct timeval src2dst_pkt_time[MAX_NUM_PKTS]; /*!< array of arrival times */
pkt_timeval src2dst_pkt_time[MAX_NUM_PKTS]; /*!< array of arrival times */
u_int16_t dst2src_pkt_len[MAX_NUM_PKTS]; /*!< array of packet appdata lengths */
struct timeval dst2src_pkt_time[MAX_NUM_PKTS]; /*!< array of arrival times */
struct timeval src2dst_start; /*!< first packet arrival time */
struct timeval dst2src_start; /*!< first packet arrival time */
pkt_timeval dst2src_pkt_time[MAX_NUM_PKTS]; /*!< array of arrival times */
pkt_timeval src2dst_start; /*!< first packet arrival time */
pkt_timeval dst2src_start; /*!< first packet arrival time */
u_int32_t src2dst_opackets; /*!< non-zero packet counts */
u_int32_t dst2src_opackets; /*!< non-zero packet counts */
u_int16_t src2dst_pkt_count; /*!< packet counts */
@@ -174,7 +176,7 @@ typedef struct ndpi_flow_info {
u_int32_t fin_count, src2dst_fin_count, dst2src_fin_count;
u_int32_t rst_count, src2dst_rst_count, dst2src_rst_count;
u_int32_t c_to_s_init_win, s_to_c_init_win;
u_int64_t first_seen, last_seen;
u_int64_t first_seen_ms, last_seen_ms;
u_int64_t src2dst_bytes, dst2src_bytes;
u_int64_t src2dst_goodput_bytes, dst2src_goodput_bytes;
u_int32_t src2dst_packets, dst2src_packets;
@@ -193,16 +195,21 @@ typedef struct ndpi_flow_info {
char host_server_name[240];
char bittorent_hash[41];
char dhcp_fingerprint[48];
ndpi_risk risk;
struct {
u_int16_t ssl_version;
char client_requested_server_name[64], server_info[64],
client_hassh[33], server_hassh[33], *server_names,
*tls_alpn, *tls_supported_versions,
server_organization[64],
*tls_issuerDN, *tls_subjectDN,
ja3_client[33], ja3_server[33],
sha1_cert_fingerprint[20];
u_int8_t sha1_cert_fingerprint_set;
struct {
u_int16_t cipher_suite;
char *esni;
} encrypted_sni;
time_t notBefore, notAfter;
u_int16_t server_cipher;
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
@@ -221,6 +228,13 @@ typedef struct ndpi_flow_info {
struct ndpi_entropy entropy;
struct ndpi_entropy last_entropy;
/* Payload lenght bins */
#ifdef DIRECTION_BINS
struct ndpi_bin payload_len_bin_src2dst, payload_len_bin_dst2src;
#else
struct ndpi_bin payload_len_bin;
#endif
} ndpi_flow_info_t;
@@ -295,7 +309,8 @@ void ndpi_free_flow_info_half(struct ndpi_flow_info *flow);
/* Process a packet and update the workflow */
struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
const struct pcap_pkthdr *header,
const u_char *packet);
const u_char *packet,
FILE * csv_fp);
/* flow callbacks for complete detected flow
@@ -314,13 +329,23 @@ static inline void ndpi_workflow_set_flow_giveup_callback(struct ndpi_workflow *
/* compare two nodes in workflow */
int ndpi_workflow_node_cmp(const void *a, const void *b);
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow);
void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_flow_info *flow, FILE * csv_fp);
u_int32_t ethernet_crc32(const void* data, size_t n_bytes);
void ndpi_flow_info_free_data(struct ndpi_flow_info *flow);
void ndpi_flow_info_freer(void *node);
void ndpi_free_flow_data_analysis(struct ndpi_flow_info *flow);
const char* print_cipher_id(u_int32_t cipher);
float ndpi_flow_get_byte_count_entropy(const uint32_t byte_count[256], unsigned int num_bytes);
extern int nDPI_LogLevel;
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
#define LOG(log_level, args...) \
{ \
if(log_level <= nDPI_LogLevel) \
printf(args); \
}
#else
#define LOG(...) {}
#endif
#endif
+20 -10
View File
@@ -1,11 +1,12 @@
bin_PROGRAMS = fuzz_process_packet fuzz_ndpi_reader
bin_PROGRAMS = fuzz_process_packet fuzz_ndpi_reader fuzz_ndpi_reader_with_main
fuzz_process_packet_SOURCES = fuzz_process_packet.c
fuzz_process_packet_LDFLAGS = ../src/lib/libndpi.a $(ADDITIONAL_LIBS)
fuzz_process_packet_CFLAGS =
fuzz_process_packet_LDADD = ../src/lib/libndpi.a
fuzz_process_packet_LDFLAGS = $(ADDITIONAL_LIBS) $(LIBS)
if HAS_FUZZLDFLAGS
fuzz_process_packet_LDFLAGS += $(LIB_FUZZING_ENGINE)
else
fuzz_process_packet_SOURCES += onefile.c
fuzz_process_packet_CFLAGS += $(LIB_FUZZING_ENGINE)
fuzz_process_packet_LDFLAGS += $(LIB_FUZZING_ENGINE)
endif
# force usage of CXX for linker
fuzz_process_packet_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -14,19 +15,28 @@ fuzz_process_packet_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
fuzz_ndpi_reader_SOURCES = fuzz_ndpi_reader.c
fuzz_ndpi_reader_CFLAGS = -I../example/
fuzz_ndpi_reader_LDFLAGS = ../example/libndpiReader.a ../src/lib/libndpi.a $(PCAP_LIB) $(ADDITIONAL_LIBS)
fuzz_ndpi_reader_LDADD = ../src/lib/libndpi.a
fuzz_ndpi_reader_LDFLAGS = ../example/libndpiReader.a $(PCAP_LIB) $(ADDITIONAL_LIBS) $(LIBS)
if HAS_FUZZLDFLAGS
fuzz_ndpi_reader_LDFLAGS += $(LIB_FUZZING_ENGINE)
else
fuzz_ndpi_reader_SOURCES += onefile.c
fuzz_ndpi_reader_CFLAGS += $(LIB_FUZZING_ENGINE)
fuzz_ndpi_reader_LDFLAGS += $(LIB_FUZZING_ENGINE)
endif
# force usage of CXX for linker
fuzz_ndpi_reader_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(fuzz_ndpi_reader_LDFLAGS) $(LDFLAGS) -o $@
EXTRA_fuzz_ndpi_reader_DEPENDENCIES = fuzz_ndpi_reader_seed_corpus.zip
fuzz_ndpi_reader_with_main_SOURCES = fuzz_ndpi_reader.c
fuzz_ndpi_reader_with_main_CFLAGS = -I../example/ -DBUILD_MAIN
fuzz_ndpi_reader_with_main_LDADD = ../src/lib/libndpi.a
fuzz_ndpi_reader_with_main_LDFLAGS = ../example/libndpiReader.a $(PCAP_LIB) $(ADDITIONAL_LIBS) $(LIBS)
# force usage of CXX for linker
fuzz_ndpi_reader_with_main_LINK=$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXX) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(fuzz_ndpi_reader_with_main_LDFLAGS) $(LDFLAGS) -o $@
# required for Google oss-fuzz
# see https://github.com/google/oss-fuzz/tree/master/projects/ndpi
testpcaps := $(wildcard ../tests/pcap/*.pcap)
fuzz_ndpi_reader_seed_corpus.zip: $(testpcaps)
+81 -9
View File
@@ -21,13 +21,13 @@ int bufferToFile(const char * name, const uint8_t *Data, size_t Size) {
FILE * fd;
if (remove(name) != 0) {
if (errno != ENOENT) {
printf("failed remove, errno=%d\n", errno);
perror("remove failed");
return -1;
}
}
fd = fopen(name, "wb");
if (fd == NULL) {
printf("failed open, errno=%d\n", errno);
perror("open failed");
return -2;
}
if (fwrite (Data, 1, Size, fd) != Size) {
@@ -45,6 +45,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
int r;
char errbuf[PCAP_ERRBUF_SIZE];
NDPI_PROTOCOL_BITMASK all;
char * pcap_path = tempnam("/tmp", "fuzz-ndpi-reader");
if (prefs == NULL) {
prefs = calloc(sizeof(struct ndpi_workflow_prefs), 1);
@@ -57,10 +58,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
prefs->max_ndpi_flows = 1024;
prefs->quiet_mode = 0;
}
bufferToFile("/tmp/fuzz.pcap", Data, Size);
bufferToFile(pcap_path, Data, Size);
pkts = pcap_open_offline("/tmp/fuzz.pcap", errbuf);
pkts = pcap_open_offline(pcap_path, errbuf);
if (pkts == NULL) {
remove(pcap_path);
free(pcap_path);
return 0;
}
struct ndpi_workflow * workflow = ndpi_workflow_init(prefs, pkts);
@@ -77,15 +80,84 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
r = pcap_next_ex(pkts, &header, &pkt);
while (r > 0) {
/* allocate an exact size buffer to check overflows */
uint8_t *packet_checked = malloc(header->caplen);
memcpy(packet_checked, pkt, header->caplen);
ndpi_workflow_process_packet(workflow, header, packet_checked);
free(packet_checked);
if(header->caplen >= 42 /* ARP+ size */) {
/* allocate an exact size buffer to check overflows */
uint8_t *packet_checked = malloc(header->caplen);
if(packet_checked) {
memcpy(packet_checked, pkt, header->caplen);
ndpi_workflow_process_packet(workflow, header, packet_checked, NULL);
free(packet_checked);
}
}
r = pcap_next_ex(pkts, &header, &pkt);
}
ndpi_workflow_free(workflow);
pcap_close(pkts);
remove(pcap_path);
free(pcap_path);
return 0;
}
#ifdef BUILD_MAIN
int main(int argc, char ** argv)
{
FILE * pcap_file;
long pcap_file_size;
uint8_t * pcap_buffer;
int test_retval;
if (argc != 2) {
fprintf(stderr, "usage: %s: [pcap-file]\n",
(argc > 0 ? argv[0] : "fuzz_ndpi_reader_with_main"));
return 1;
}
pcap_file = fopen(argv[1], "r");
if (pcap_file == NULL) {
perror("fopen failed");
return 1;
}
if (fseek(pcap_file, 0, SEEK_END) != 0) {
perror("fseek(SEEK_END) failed");
fclose(pcap_file);
return 1;
}
pcap_file_size = ftell(pcap_file);
if (pcap_file_size < 0) {
perror("ftell failed");
fclose(pcap_file);
return 1;
}
if (fseek(pcap_file, 0, SEEK_SET) != 0) {
perror("fseek(0, SEEK_SET) failed");
fclose(pcap_file);
return 1;
}
pcap_buffer = malloc(pcap_file_size);
if (pcap_buffer == NULL) {
perror("malloc failed");
fclose(pcap_file);
return 1;
}
if (fread(pcap_buffer, sizeof(*pcap_buffer), pcap_file_size, pcap_file) != pcap_file_size) {
perror("fread failed");
fclose(pcap_file);
return 1;
}
test_retval = LLVMFuzzerTestOneInput(pcap_buffer, pcap_file_size);
fclose(pcap_file);
free(pcap_buffer);
return test_retval;
}
#endif
+1 -1
View File
@@ -6,5 +6,5 @@ includedir=@includedir@
Name: libndpi
Description: deep packet inspection library
Version: @VERSION@
Libs: -L${libdir} -lndpi
Libs: -L${libdir} -lndpi @ADDITIONAL_LIBS@
Cflags: -I${includedir}/ndpi
+53
View File
@@ -0,0 +1,53 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
#
# DESCRIPTION
#
# Check whether the given FLAG works with the current language's compiler
# or gives an error. (Warnings, however, are ignored)
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# If EXTRA-FLAGS is defined, it is added to the current language's default
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
# force the compiler to issue an error when a bad flag is given.
#
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
#
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 6
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
AS_VAR_IF(CACHEVAR,yes,
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_COMPILE_FLAGS
+6 -8
View File
@@ -1,22 +1,22 @@
#
# Copyright (C) 2018 - ntop.org
# Copyright (C) 2018-20 - ntop.org
#
include $(TOPDIR)/rules.mk
PKG_NAME:=libndpi
PKG_VERSION:=1333.ab2f3ce
PKG_VERSION:=17022020
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/ntop/nDPI.git
PKG_SOURCE_VERSION:=ab2f3cefc89017d73e67faa4eb4011e7e3f2044d
PKG_SOURCE_VERSION:=1f921562d1d7962f1d23ca5b59c25f9b65073460
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_PROTO:=git
PKG_MAINTAINER:=Emanuele Faranda <faranda@ntop.org>
PKG_MAINTAINER:=Luca Deri <deri@ntop.org>
PKG_LICENSE:=GPL3
PKG_BUILD_DEPENDS:=+libpcap
PKG_BUILD_DEPENDS:=
PKG_BUILD_PARALLEL:=1
# autogen fix
@@ -27,7 +27,6 @@ include $(INCLUDE_DIR)/package.mk
define Package/libndpi
SECTION:=network
CATEGORY:=Network
#DEPENDS:=+libc +libjson-c +libpthread
TITLE:=nDPI Deep Packet Inspection Library
URL:=https://www.ntop.org
endef
@@ -37,8 +36,7 @@ define Package/libndpi/description
endef
CONFIGURE_ARGS += \
--with-pic \
--disable-json-c \
--with-only-libndpi
define Build/Prepare
$(call Build/Prepare/Default)
+25
View File
@@ -0,0 +1,25 @@
Howto Compile lindpi on OpenWRT
-------------------------------
cd myopenwrt_directory
mkdir package/network/services/libndpi
cd package/network/services/libndpi
cp ~/nDPI/packages/openwrt/Makefile .
cd myopenwrt_directory
make menuconfig
Go under network and select
<M> libndpi.............................. nDPI Deep Packet Inspection Library
Build Commands
--------------
If you want to build just libndpi do:
make -j1 V=s package/network/services/libndpi/clean
make -j1 V=s package/network/services/libndpi/compile
Other Documents
---------------
https://openwrt.org/packages/pkgdata/libndpi
+3 -3
View File
@@ -1,8 +1,8 @@
CC=@CC@
CFLAGS=-I. -I../src/include -I./src/lib/third_party/include -shared -Wl,
CFLAGS=-I. -I../src/include -I./src/lib/third_party/include @CFLAGS@ @CUSTOM_NDPI@ -shared
#LIBNDPI=../src/lib/libndpi.so.@NDPI_VERSION_SHORT@
LIBNDPI=../src/lib/libndpi.a
LDFLAGS=$(CFILE) $(LIBNDPI) -lpcap
LDFLAGS=$(CFILE) $(LIBNDPI) -lpcap @ADDITIONAL_LIBS@
SHARE = -soname,ndpi_wrap
SO=ndpi_wrap.so
OBJS = ndpi_wrap.o
@@ -19,7 +19,7 @@ endif
all: $(SO)
$(SO): $(CFILE) $(LIBNDPI) Makefile
$(CC) $(CFLAGS)$(SHARE) -o $@ $(PIC) $(LDFLAGS)
$(CC) $(CFLAGS) -Wl,$(SHARE) -o $@ $(PIC) $(LDFLAGS)
# ln -s $(LIBNDPI) .
clean:
+19 -20
View File
@@ -1,7 +1,25 @@
nDPI Python bindings
--------------------
This directory contains the Python3 bindings for nDPI. We provide both ctypes and cffi based bindings.
This directory contains the Python3 bindings for nDPI. We provide both cffi and ctypes based bindings.
**cffi bindings**
Files:
* ndpi.py
Example (using `nfstream <https://github.com/aouinizied/nfstream>`_ package):
.. code-block:: bash
pip3 install nfstream
python3 flow_printer.py <interface>
python3 flow_printer.py <pcap_file>
Code courtesy:
* Zied Aouini
**ctypes bindings**
@@ -23,22 +41,3 @@ Code courtesy:
* Massimo Puddu
* Zied Aouini
**cffi bindings**
Files:
* ndpi.py
Example (using NFStream package):
.. code-block:: bash
pip3 install nfstream
python3 flow_printer.py <interface>
python3 flow_printer.py <pcap_file>
Code courtesy:
* Zied Aouini
+18 -19
View File
@@ -2,38 +2,37 @@
# -*- coding: utf-8 -*-
"""
file: flow_printer.py
This file is part of nfstream.
Copyright (C) 2019 - Zied Aouini <aouinizied@gmail.com>
nfstream is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
nfstream 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with nfstream.
------------------------------------------------------------------------------------------------------------------------
flow_printer.py
Copyright (C) 2019-20 - NFStream Developers
This file is part of NFStream, a Flexible Network Data Analysis Framework (https://www.nfstream.org/).
NFStream 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.
NFStream 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 NFStream.
If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------------------------------------------------------
"""
from nfstream import NFStreamer
import sys
# Example must run with nfstream >= 6.1.1
path = sys.argv[1]
flow_streamer = NFStreamer(source=path)
flow_streamer = NFStreamer(source=path, statistical_analysis=False, performance_report=1)
result = {}
try:
for flow in flow_streamer:
print(flow)
try:
result[flow.application_name] += flow.total_packets
result[flow.application_name] += flow.bidirectional_packets
except KeyError:
result[flow.application_name] = flow.total_packets
print("Summary (Application Name: Packets):")
result[flow.application_name] = flow.bidirectional_packets
print("\nSummary (Application Name: Packets):")
print(result)
except KeyboardInterrupt:
print("Summary (Application Name: Packets):")
print("\nSummary (Application Name: Packets):")
print(result)
print("Terminated.")
print("Terminated.")
+922 -760
View File
File diff suppressed because it is too large Load Diff
-10
View File
@@ -1,10 +0,0 @@
plibrary_includedir=$(includedir)/libndpi-@VERSION@/libndpi
library_include_HEADERS = ndpi_api.h \
ndpi_define.h \
ndpi_typedefs.h \
ndpi_main.h \
ndpi_protocol_ids.h \
ndpi_protocols.h \
ndpi_win32.h \
ndpi_includes.h
@@ -34,7 +34,7 @@ extern "C" {
/* The #define below is used for apps that dynamically link with nDPI to make
sure that datastructures and in sync across versions
*/
#define NDPI_API_VERSION 1
#define NDPI_API_VERSION @NDPI_API_VERSION@
#define SIZEOF_ID_STRUCT ( sizeof(struct ndpi_id_struct) )
#define SIZEOF_FLOW_STRUCT ( sizeof(struct ndpi_flow_struct) )
@@ -78,9 +78,34 @@ extern "C" {
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_id_struct(void);
/**
* Get the size of the flow tcp struct
*
* @return the size of the flow tcp struct
*
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_flow_tcp_struct(void);
/**
* Get the size of the flow udp struct
*
* @return the size of the flow udp struct
*
*/
u_int32_t ndpi_detection_get_sizeof_ndpi_flow_udp_struct(void);
/*
Same as the API call above but used for matching raw id's added
via ndpi_add_string_value_to_automa()
*/
int ndpi_match_string_value(void *_automa, char *string_to_match,
u_int match_len, u_int32_t *num);
/**
* 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);
@@ -112,7 +137,7 @@ extern "C" {
* NULL if the substring is not found
*
*/
char* ndpi_strncasestr(const char *s, const char *find, size_t slen);
const char* ndpi_strncasestr(const char *s, const char *find, size_t slen);
/**
* Returns the nDPI protocol id for IP-based protocol detection
@@ -126,6 +151,21 @@ extern "C" {
u_int16_t ndpi_network_ptree_match(struct ndpi_detection_module_struct *ndpi_struct,
struct in_addr *pin);
/**
* Returns the nDPI protocol id for IP+port-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
* @par port = The port (MUST BE in network byte order) or
* 0 if ignored
* @return the nDPI protocol ID
*
*/
u_int16_t ndpi_network_port_ptree_match(struct ndpi_detection_module_struct *ndpi_struct,
struct in_addr *pin /* network byte order */,
u_int16_t port /* network byte order */);
/**
* Init single protocol match
*
@@ -142,6 +182,10 @@ extern "C" {
* hosts and do other things. As soon as you are ready to use
* it do not forget to call first ndpi_finalize_initalization()
*
* You can call this function multiple times, (i.e. to create multiple
* indipendent detection contexts) but all these calls MUST NOT run
* in parallel
*
* @par prefs = load preferences
* @return the initialized detection module
*
@@ -151,7 +195,7 @@ extern "C" {
/**
* Completes the initialization (2nd step)
*
* @return the initialized detection module
* @par ndpi_str = the struct created for the protocol detection
*
*/
void ndpi_finalize_initalization(struct ndpi_detection_module_struct *ndpi_str);
@@ -218,7 +262,7 @@ extern "C" {
*/
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
@@ -240,13 +284,13 @@ extern "C" {
* (like SSL getting both client and server certificate even if we already know after
* seeing the client certificate what the protocol is)
*
* @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
* @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 packet_time_ms = the current timestamp for the packet (expressed in msec)
* @par src = pointer to the source subscriber state machine
* @par dst = pointer to the destination subscriber state machine
* @return void
*
*/
@@ -254,7 +298,7 @@ extern "C" {
struct ndpi_flow_struct *flow,
const unsigned char *packet,
const unsigned short packetlen,
const u_int64_t current_tick,
const u_int64_t packet_time_ms,
struct ndpi_id_struct *src,
struct ndpi_id_struct *dst);
@@ -262,13 +306,13 @@ extern "C" {
* 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
* @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 packet_time_ms = the current timestamp for the packet (expressed in msec)
* @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
*
*/
@@ -276,7 +320,7 @@ extern "C" {
struct ndpi_flow_struct *flow,
const unsigned char *packet,
const unsigned short packetlen,
const u_int64_t current_tick,
const u_int64_t packet_time_ms,
struct ndpi_id_struct *src,
struct ndpi_id_struct *dst);
/**
@@ -290,7 +334,7 @@ extern "C" {
*/
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
/**
* API call that is called internally by ndpi_detection_process_packet or by apps
* that want to avoid calling ndpi_detection_process_packet as they have already
@@ -300,12 +344,14 @@ extern "C" {
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module
* @par ndpi_selection_bitmask = the protocol selected bitmask
* @return number of protocol dissector that have been tried (0 = no more dissectors)
*
*/
void ndpi_check_flow_func(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE *ndpi_selection_packet);
u_int32_t ndpi_check_flow_func(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE *ndpi_selection_packet);
/**
* Query the pointer to the layer 4 packet
*
@@ -391,7 +437,7 @@ extern "C" {
char *string_to_match,
u_int string_to_match_len,
ndpi_protocol_match_result *ret_match,
u_int16_t master_protocol_id);
u_int16_t master_protocol_id);
/**
* Check if the string content passed match with a protocol
@@ -518,7 +564,7 @@ extern "C" {
*/
int ndpi_match_hostname_protocol(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow,
u_int16_t master_protocol,
u_int16_t master_protocol,
char *name, u_int name_len);
/**
@@ -742,7 +788,7 @@ extern "C" {
* @return 0 in case of no error, or -1 if an error occurred.
*
*/
int ndpi_add_string_value_to_automa(void *_automa, char *str, unsigned long num);
int ndpi_add_string_value_to_automa(void *_automa, char *str, u_int32_t num);
/**
* Add a string to match to an automata. Same as ndpi_add_string_value_to_automa() with num set to 1
@@ -784,12 +830,13 @@ extern "C" {
u_int32_t daddr,
ndpi_protocol *ret);
int ndpi_match_custom_category(struct ndpi_detection_module_struct *ndpi_struct,
char *name, u_int name_len, unsigned long *id);
char *name, u_int name_len, ndpi_protocol_category_t *id);
void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol *ret);
int ndpi_get_custom_category_match(struct ndpi_detection_module_struct *ndpi_struct,
char *name_or_ip, u_int name_len, unsigned long *id);
char *name_or_ip, u_int name_len,
ndpi_protocol_category_t *id);
int ndpi_set_detection_preferences(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_detection_preference pref,
int value);
@@ -797,12 +844,13 @@ extern "C" {
/* Tells to called on what l4 protocol given application protocol can be found */
ndpi_l4_proto_info ndpi_get_l4_proto_info(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_proto_id);
const char* ndpi_get_l4_proto_name(ndpi_l4_proto_info proto);
ndpi_proto_defaults_t* ndpi_get_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_supported_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_num_custom_protocols(struct ndpi_detection_module_struct *ndpi_mod);
u_int ndpi_get_ndpi_detection_module_size(void);
void ndpi_set_log_level(struct ndpi_detection_module_struct *ndpi_mod, u_int l);
void ndpi_set_debug_bitmask(struct ndpi_detection_module_struct *ndpi_mod, NDPI_PROTOCOL_BITMASK debug_bitmask);
/* LRU cache */
struct ndpi_lru_cache* ndpi_lru_cache_init(u_int32_t num_entries);
@@ -810,18 +858,21 @@ extern "C" {
u_int8_t ndpi_lru_find_cache(struct ndpi_lru_cache *c, u_int32_t key,
u_int16_t *value, u_int8_t clean_key_when_found);
void ndpi_lru_add_to_cache(struct ndpi_lru_cache *c, u_int32_t key, u_int16_t value);
/**
* Add a string to match to an automata
* Find a protocol id associated with a string automata
*
* @par The automata initialized with ndpi_init_automa();
* @par The (sub)string to search
* @par The (sub)string length
* @par The id associated with the matched string or 0 id not found.
* @par The protocol id associated with the matched string or 0 id not found.
* @return 0 in case of match, or -1 if no match, or -2 if an error occurred.
*
*/
int ndpi_match_string_id(void *_automa, char *string_to_match, u_int match_len, unsigned long *id);
int ndpi_match_string_protocol_id(void *_automa, char *string_to_match, u_int match_len,
u_int16_t *protocol_id,
ndpi_protocol_category_t *category,
ndpi_protocol_breed_t *breed);
/* Utility functions to set ndpi malloc/free/print wrappers */
void set_ndpi_malloc(void* (*__ndpi_malloc)(size_t size));
@@ -833,7 +884,8 @@ extern "C" {
//void * ndpi_malloc(size_t size);
//void * ndpi_calloc(unsigned long count, size_t size);
//void ndpi_free(void *ptr);
u_int8_t ndpi_get_api_version(void);
u_int16_t ndpi_get_api_version(void);
const char *ndpi_get_gcrypt_version(void);
/* https://github.com/corelight/community-id-spec */
int ndpi_flowv4_flow_hash(u_int8_t l4_proto, u_int32_t src_ip, u_int32_t dst_ip, u_int16_t src_port, u_int16_t dst_port,
@@ -842,7 +894,7 @@ extern "C" {
u_int16_t src_port, u_int16_t dst_port, u_int8_t icmp_type, u_int8_t icmp_code,
u_char *hash_buf, u_int8_t hash_buf_len);
u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher);
const char* ndpi_cipher2str(u_int32_t cipher);
const char* ndpi_tunnel2str(ndpi_packet_tunnel tt);
@@ -852,15 +904,21 @@ extern "C" {
char *buffer, u_int buffer_size,
u_int8_t min_string_match_len, /* Will return 0 if no string > min_string_match_len have been found */
char *outbuf, u_int outbuf_len);
char* ndpi_ssl_version2str(u_int16_t version, u_int8_t *unknown_tls_version);
char* ndpi_ssl_version2str(struct ndpi_flow_struct *flow,
u_int16_t version, u_int8_t *unknown_tls_version);
void ndpi_patchIPv6Address(char *str);
void ndpi_user_pwd_payload_copy(u_int8_t *dest, u_int dest_len, u_int offset,
const u_int8_t *src, u_int src_len);
u_char* ndpi_base64_decode(const u_char *src, size_t len, size_t *out_len);
char* ndpi_base64_encode(unsigned char const* bytes_to_encode, ssize_t in_len);
char* ndpi_base64_encode(unsigned char const* bytes_to_encode, size_t in_len); /* NOTE: caller MUST free the returned pointer */
void ndpi_string_sha1_hash(const uint8_t *message, size_t len, u_char *hash /* 20-bytes */);
int ndpi_load_ipv4_ptree(struct ndpi_detection_module_struct *ndpi_str,
const char *path, u_int16_t protocol_id);
int ndpi_dpi2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol l7_protocol,
ndpi_serializer *serializer);
int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t ip_version,
@@ -873,81 +931,417 @@ extern "C" {
void ndpi_md5(const u_char *data, size_t data_len, u_char hash[16]);
const char* ndpi_http_method2str(ndpi_http_method m);
ndpi_http_method ndpi_http_str2method(const char* method, ssize_t method_len);
/* ptree (trie) API */
ndpi_ptree_t* ndpi_ptree_create(void);
int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, uint user_data);
int ndpi_ptree_match_addr(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, uint *user_data);
int ndpi_ptree_insert(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int8_t bits, u_int32_t user_data);
int ndpi_ptree_match_addr(ndpi_ptree_t *tree, const ndpi_ip_addr_t *addr, u_int32_t *user_data);
void ndpi_ptree_destroy(ndpi_ptree_t *tree);
/* Serializer */
int ndpi_init_serializer_ll(ndpi_serializer *serializer, ndpi_serialization_format fmt,
u_int32_t buffer_size);
/* General purpose utilities */
u_int64_t ndpi_htonll(u_int64_t v);
u_int64_t ndpi_ntohll(u_int64_t v);
/* DGA */
int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow,
char *name, u_int8_t is_hostname);
/* Serializer (supports JSON, TLV, CSV) */
/**
* Initialize a serializer handle (allocated by the caller).
* @param serializer The serializer handle
* @param fmt The serialization format (ndpi_serialization_format_json, ndpi_serialization_format_tlv, ndpi_serialization_format_csv)
* @return 0 on success, a negative number otherwise
*/
int ndpi_init_serializer(ndpi_serializer *serializer, ndpi_serialization_format fmt);
/**
* Initialize a serializer handle. Same as ndpi_init_serializer, but with some low-level settings.
* @param serializer The serializer handle
* @param fmt The serialization format (ndpi_serialization_format_json, ndpi_serialization_format_tlv, ndpi_serialization_format_csv)
* @param buffer_size The initial internal buffer_size
* @return 0 on success, a negative number otherwise
*/
int ndpi_init_serializer_ll(ndpi_serializer *serializer, ndpi_serialization_format fmt, u_int32_t buffer_size);
/**
* Release all allocated data structure.
* @param serializer The serializer handle
*/
void ndpi_term_serializer(ndpi_serializer *serializer);
/**
* Reset the serializer (cleanup the internal buffer to start a new serialization)
* @param serializer The serializer handle
*/
void ndpi_reset_serializer(ndpi_serializer *serializer);
int ndpi_serialize_uint32_uint32(ndpi_serializer *serializer,
u_int32_t key, u_int32_t value);
int ndpi_serialize_uint32_uint64(ndpi_serializer *serializer,
u_int32_t key, u_int64_t value);
int ndpi_serialize_uint32_int32(ndpi_serializer *serializer,
u_int32_t key, int32_t value);
int ndpi_serialize_uint32_int64(ndpi_serializer *serializer,
u_int32_t key, int64_t value);
int ndpi_serialize_uint32_float(ndpi_serializer *serializer,
u_int32_t key, float value,
const char *format /* e.f. "%.2f" */);
int ndpi_serialize_uint32_string(ndpi_serializer *serializer,
u_int32_t key, const char *value);
int ndpi_serialize_uint32_boolean(ndpi_serializer *serializer,
u_int32_t key, u_int8_t value);
/**
* Serialize a 32-bit unsigned int key and a 32-bit unsigned int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_uint32(ndpi_serializer *serializer, u_int32_t key, u_int32_t value);
int ndpi_serialize_string_int32(ndpi_serializer *serializer,
const char *key, int32_t value);
int ndpi_serialize_string_int64(ndpi_serializer *serializer,
const char *key, int64_t value);
int ndpi_serialize_string_uint32(ndpi_serializer *serializer,
const char *key, u_int32_t value);
int ndpi_serialize_string_uint32_format(ndpi_serializer *serializer,
const char *key, u_int32_t value,
const char *format);
int ndpi_serialize_string_uint64(ndpi_serializer *serializer,
const char *key, u_int64_t value);
int ndpi_serialize_string_string(ndpi_serializer *serializer,
const char *key, const char *value);
int ndpi_serialize_string_binary(ndpi_serializer *serializer,
const char *key, const char *_value,
u_int16_t vlen);
int ndpi_serialize_string_raw(ndpi_serializer *_serializer,
const char *key, const char *_value,
u_int16_t vlen);
int ndpi_serialize_string_float(ndpi_serializer *serializer,
const char *key, float value,
const char *format /* e.f. "%.2f" */);
int ndpi_serialize_string_boolean(ndpi_serializer *serializer,
const char *key, u_int8_t value);
/**
* Serialize a 32-bit unsigned int key and a 64-bit unsigned int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_uint64(ndpi_serializer *serializer, u_int32_t key, u_int64_t value);
/**
* Serialize a 32-bit unsigned int key and a 32-bit signed int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_int32(ndpi_serializer *serializer, u_int32_t key, int32_t value);
/**
* Serialize a 32-bit unsigned int key and a 64-bit signed int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_int64(ndpi_serializer *serializer, u_int32_t key, int64_t value);
/**
* Serialize a 32-bit unsigned int key and a float value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @param format The float value format
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_float(ndpi_serializer *serializer, u_int32_t key, float value, const char *format /* e.f. "%.2f" */);
/**
* Serialize a 32-bit unsigned int key and a string value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_string(ndpi_serializer *serializer, u_int32_t key, const char *value);
/**
* Serialize a 32-bit unsigned int key and a boolean value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_uint32_boolean(ndpi_serializer *serializer, u_int32_t key, u_int8_t value);
/**
* Serialize an unterminated string key and a 32-bit signed int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_binary_int32(ndpi_serializer *_serializer, const char *key, u_int16_t klen, int32_t value);
/**
* Serialize a string key and a 32-bit signed int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_int32(ndpi_serializer *serializer, const char *key, int32_t value);
/**
* Serialize an unterminated string key and a 64-bit signed int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_binary_int64(ndpi_serializer *_serializer, const char *key, u_int16_t klen, int64_t value);
/**
* Serialize a string key and a 64-bit signed int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_int64(ndpi_serializer *serializer, const char *key, int64_t value);
/**
* Serialize an unterminated string key and a 32-bit unsigned int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_binary_uint32(ndpi_serializer *_serializer, const char *key, u_int16_t klen, u_int32_t value);
/**
* Serialize a string key and a 32-bit unsigned int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_uint32(ndpi_serializer *serializer, const char *key, u_int32_t value);
/**
* Serialize a string key and a float value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @param format The float format
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_uint32_format(ndpi_serializer *serializer, const char *key, u_int32_t value, const char *format);
/**
* Serialize an unterminated string key and a 64-bit unsigned int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_binary_uint64(ndpi_serializer *_serializer, const char *key, u_int16_t klen, u_int64_t value);
/**
* Serialize a string key and a 64-bit unsigned int value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_uint64(ndpi_serializer *serializer, const char *key, u_int64_t value);
/**
* Serialize an unterminated string key and an unterminated string value
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @param value The field value
* @param vlen The value length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_binary_binary(ndpi_serializer *_serializer, const char *key, u_int16_t klen, const char *_value, u_int16_t vlen);
/**
* Serialize a string key and a string value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_string(ndpi_serializer *serializer, const char *key, const char *value);
/**
* Serialize a string key and an unterminated string value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @param vlen The value length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_binary(ndpi_serializer *serializer, const char *key, const char *_value, u_int16_t vlen);
/**
* Serialize a string key and a raw value (this is a string which is added to the JSON without any quote or escaping)
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @param vlen The value length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_raw(ndpi_serializer *_serializer, const char *key, const char *_value, u_int16_t vlen);
/**
* Serialize an unterminated string key and a float value
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @param value The field value
* @param format The float format
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_binary_float(ndpi_serializer *_serializer, const char *key, u_int16_t klen, float value, const char *format /* e.f. "%.2f" */);
/**
* Serialize a string key and a a float value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @param format The float format
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_float(ndpi_serializer *serializer, const char *key, float value, const char *format /* e.f. "%.2f" */);
/**
* Serialize a string key and a boolean value
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_string_boolean(ndpi_serializer *serializer, const char *key, u_int8_t value);
/**
* Serialize a raw record in an array (this is a low-level function and its use is not recommended)
* @param serializer The serializer handle
* @param record The record value
* @param record_len The record length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_raw_record(ndpi_serializer *_serializer, u_char *record, u_int32_t record_len);
/**
* Serialize an End-Of-Record (the current object becomes is terminated and added to an array,
* and a new object is created where the next items will be added)
* @param serializer The serializer handle
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_end_of_record(ndpi_serializer *serializer);
int ndpi_serialize_start_of_block(ndpi_serializer *serializer,
const char *key);
/**
* Serialize the start of a list with an unterminated string key, where the next serialized items
* will be added (note: keys for the new items are ignored)
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_start_of_list_binary(ndpi_serializer *_serializer, const char *key, u_int16_t klen);
/**
* Serialize the start of a list, where the next serialized items will be added (note: keys for
* the new items are ignored)
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_start_of_list(ndpi_serializer *serializer, const char *key);
/**
* Serialize the end of a list
* @param serializer The serializer handle
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_end_of_list(ndpi_serializer *serializer);
/**
* Serialize the start of a block with an unterminated string key
* @param serializer The serializer handle
* @param key The field name or ID
* @param klen The key length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_start_of_block_binary(ndpi_serializer *_serializer, const char *key, u_int16_t klen);
/**
* Serialize the start of a block with a string key
* @param serializer The serializer handle
* @param key The field name or ID
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_start_of_block(ndpi_serializer *serializer, const char *key);
/**
* Serialize the end of a block
* @param serializer The serializer handle
* @param key The field name or ID
* @param value The field value
* @return 0 on success, a negative number otherwise
*/
int ndpi_serialize_end_of_block(ndpi_serializer *serializer);
/**
* Return the serialized buffer
* @param serializer The serializer handle
* @param buffer_len The buffer length (out)
* @return The buffer
*/
char* ndpi_serializer_get_buffer(ndpi_serializer *serializer, u_int32_t *buffer_len);
/**
* Return the current serialized buffer length
* @param serializer The serializer handle
* @return The buffer length
*/
u_int32_t ndpi_serializer_get_buffer_len(ndpi_serializer *serializer);
/**
* Return the real internal buffer size (containing the serialized buffer)
* @param serializer The serializer handle
* @return The internal buffer size
*/
u_int32_t ndpi_serializer_get_internal_buffer_size(ndpi_serializer *serializer);
/**
* Change the serializer buffer length
* @param serializer The serializer handle
* @param l The new buffer length
* @return 0 on success, a negative number otherwise
*/
int ndpi_serializer_set_buffer_len(ndpi_serializer *serializer, u_int32_t l);
/**
* Return the configured serialization format
* @param serializer The serializer handle
* @return The serialization format
*/
ndpi_serialization_format ndpi_serializer_get_format(ndpi_serializer *serializer);
/**
* Set the CSV separator
* @param serializer The serializer handle
* @param separator The separator
*/
void ndpi_serializer_set_csv_separator(ndpi_serializer *serializer, char separator);
/**
* Return the header automatically built from keys (CSV only)
* @param serializer The serializer handle
* @param buffer_len The buffer length (out)
* @return The header
*/
char* ndpi_serializer_get_header(ndpi_serializer *serializer, u_int32_t *buffer_len);
/**
* Create a snapshot of the internal buffer for later rollback (ndpi_serializer_rollback_snapshot)
* @param serializer The serializer handle
*/
void ndpi_serializer_create_snapshot(ndpi_serializer *serializer);
/**
* Rollback to the latest snapshot
* @param serializer The serializer handle
*/
void ndpi_serializer_rollback_snapshot(ndpi_serializer *serializer);
/* Deserializer */
/* Deserializer (supports TLV only) */
int ndpi_init_deserializer(ndpi_deserializer *deserializer,
ndpi_serializer *serializer);
int ndpi_init_deserializer_buf(ndpi_deserializer *deserializer,
u_int8_t *serialized_buffer,
u_int32_t serialized_buffer_len);
ndpi_serialization_format ndpi_deserialize_get_format(ndpi_deserializer *_deserializer);
ndpi_serialization_type ndpi_deserialize_get_item_type(ndpi_deserializer *deserializer, ndpi_serialization_type *key_type);
int ndpi_deserialize_next(ndpi_deserializer *deserializer);
@@ -969,26 +1363,69 @@ extern "C" {
struct ndpi_analyze_struct* ndpi_alloc_data_analysis(u_int16_t _max_series_len);
void ndpi_init_data_analysis(struct ndpi_analyze_struct *s, u_int16_t _max_series_len);
void ndpi_free_data_analysis(struct ndpi_analyze_struct *d);
void ndpi_reset_data_analysis(struct ndpi_analyze_struct *d);
void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int32_t value);
float ndpi_data_average(struct ndpi_analyze_struct *s);
/* Sliding-window only */
float ndpi_data_window_average(struct ndpi_analyze_struct *s);
float ndpi_data_window_variance(struct ndpi_analyze_struct *s);
float ndpi_data_window_stddev(struct ndpi_analyze_struct *s);
/* All data */
float ndpi_data_average(struct ndpi_analyze_struct *s);
float ndpi_data_entropy(struct ndpi_analyze_struct *s);
float ndpi_data_variance(struct ndpi_analyze_struct *s);
float ndpi_data_stddev(struct ndpi_analyze_struct *s);
u_int32_t ndpi_data_last(struct ndpi_analyze_struct *s);
u_int32_t ndpi_data_min(struct ndpi_analyze_struct *s);
u_int32_t ndpi_data_max(struct ndpi_analyze_struct *s);
float ndpi_data_ratio(u_int32_t sent, u_int32_t rcvd);
const char* ndpi_data_ratio2str(float ratio);
void ndpi_data_print_window_values(struct ndpi_analyze_struct *s); /* debug */
ndpi_url_risk ndpi_validate_url(char *url);
ndpi_risk_enum ndpi_validate_url(char *url);
u_int8_t ndpi_is_protocol_detected(struct ndpi_detection_module_struct *ndpi_str,
ndpi_protocol proto);
void ndpi_serialize_risk(ndpi_serializer *serializer, struct ndpi_flow_struct *flow);
const char* ndpi_risk2str(ndpi_risk_enum risk);
/* ******************************* */
/* HyperLogLog cardinality estimator */
/* Memory lifecycle */
int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits);
void ndpi_hll_destroy(struct ndpi_hll *hll);
void ndpi_hll_reset(struct ndpi_hll *hll);
/* Add values */
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len);
void ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) ;
/* Get cardinality estimation */
double ndpi_hll_count(struct ndpi_hll *hll);
/* ******************************* */
int ndpi_init_bin(struct ndpi_bin *b, enum ndpi_bin_family f, u_int8_t num_bins);
void ndpi_free_bin(struct ndpi_bin *b);
struct ndpi_bin* ndpi_clone_bin(struct ndpi_bin *b);
void ndpi_inc_bin(struct ndpi_bin *b, u_int8_t slot_id, u_int32_t val);
void ndpi_set_bin(struct ndpi_bin *b, u_int8_t slot_id, u_int32_t value);
u_int32_t ndpi_get_bin_value(struct ndpi_bin *b, u_int8_t slot_id);
void ndpi_reset_bin(struct ndpi_bin *b);
void ndpi_normalize_bin(struct ndpi_bin *b);
char* ndpi_print_bin(struct ndpi_bin *b, u_int8_t normalize_first, char *out_buf, u_int out_buf_len);
float ndpi_bin_similarity(struct ndpi_bin *b1, struct ndpi_bin *b2, u_int8_t normalize_first);
int ndpi_cluster_bins(struct ndpi_bin *bins, u_int16_t num_bins,
u_int8_t num_clusters, u_int16_t *cluster_ids,
struct ndpi_bin *centroids);
u_int32_t ndpi_quick_16_byte_hash(u_int8_t *in_16_bytes_long);
#ifdef __cplusplus
}
#endif
+13 -13
View File
@@ -43,7 +43,7 @@
#ifndef NDPI_CLASSIFY_H
#define NDPI_CLASSIFY_H
#include "ndpi_includes.h"
/* constants */
#define NUM_PARAMETERS_SPLT_LOGREG 208
@@ -66,27 +66,27 @@ extern float parameters_bd[NUM_PARAMETERS_BD_LOGREG];
extern float parameters_splt[NUM_PARAMETERS_SPLT_LOGREG];
/* Classifier functions */
float ndpi_classify(const unsigned short *pkt_len, const struct timeval *pkt_time,
const unsigned short *pkt_len_twin, const struct timeval *pkt_time_twin,
struct timeval start_time, struct timeval start_time_twin, uint32_t max_num_pkt_len,
float ndpi_classify(const unsigned short *pkt_len, const pkt_timeval *pkt_time,
const unsigned short *pkt_len_twin, const pkt_timeval *pkt_time_twin,
pkt_timeval start_time, pkt_timeval start_time_twin, uint32_t max_num_pkt_len,
uint16_t sp, uint16_t dp, uint32_t op, uint32_t ip, uint32_t np_o, uint32_t np_i,
uint32_t ob, uint32_t ib, uint16_t use_bd, const uint32_t *bd, const uint32_t *bd_t);
void ndpi_merge_splt_arrays(const uint16_t *pkt_len, const struct timeval *pkt_time,
const uint16_t *pkt_len_twin, const struct timeval *pkt_time_twin,
struct timeval start_time, struct timeval start_time_twin,
void ndpi_merge_splt_arrays(const uint16_t *pkt_len, const pkt_timeval *pkt_time,
const uint16_t *pkt_len_twin, const pkt_timeval *pkt_time_twin,
pkt_timeval start_time, pkt_timeval start_time_twin,
uint16_t s_idx, uint16_t r_idx,
uint16_t *merged_lens, uint16_t *merged_times);
void ndpi_update_params(classifier_type_codes_t param_type, const char *param_file);
void ndpi_flow_info_freer(void *node);
unsigned int ndpi_timer_eq(const struct timeval *a, const struct timeval *b);
unsigned int ndpi_timer_lt(const struct timeval *a, const struct timeval *b);
void ndpi_timer_sub(const struct timeval *a, const struct timeval *b, struct timeval *result);
void ndpi_timer_clear(struct timeval *a);
unsigned int ndpi_timeval_to_milliseconds(struct timeval ts);
unsigned int ndpi_timeval_to_microseconds(struct timeval ts);
unsigned int ndpi_timer_eq(const pkt_timeval *a, const pkt_timeval *b);
unsigned int ndpi_timer_lt(const pkt_timeval *a, const pkt_timeval *b);
void ndpi_timer_sub(const pkt_timeval *a, const pkt_timeval *b, pkt_timeval *result);
void ndpi_timer_clear(pkt_timeval *a);
unsigned int ndpi_timeval_to_milliseconds(pkt_timeval ts);
unsigned int ndpi_timeval_to_microseconds(pkt_timeval ts);
void ndpi_log_timestamp(char *log_ts, uint32_t log_ts_len);
#endif /* NDPI_CLASSIFY_H */
+21 -7
View File
@@ -35,7 +35,9 @@
#include <endian.h>
#define __BYTE_ORDER BYTE_ORDER
#if BYTE_ORDER == LITTLE_ENDIAN
#ifndef __LITTLE_ENDIAN__
#define __LITTLE_ENDIAN__
#endif /* __LITTLE_ENDIAN__ */
#else
#define __BIG_ENDIAN__
#endif/* BYTE_ORDER */
@@ -179,6 +181,8 @@
#define NDPI_JABBER_FT_TIMEOUT 5
#define NDPI_SOULSEEK_CONNECTION_IP_TICK_TIMEOUT 600
#include "ndpi_config.h" /* To have access to NDPI_ENABLE_DEBUG_MESSAGES */
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
#define NDPI_LOG(proto, m, log_level, args...) \
{ \
@@ -187,7 +191,7 @@
(*(mod->ndpi_debug_printf))(proto, mod, log_level, __FILE__, __FUNCTION__, __LINE__, args); \
}
/* We must define NDPI_CURRENT_PROTO before include ndpi_main.h !!!
/* We must define NDPI_CURRENT_PROTO before include ndpi_main.h !!!
*
* #include "ndpi_protocol_ids.h"
* #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_XXXX
@@ -196,7 +200,7 @@
*/
#ifndef NDPI_CURRENT_PROTO
#define NDPI_CURRENT_PROTO NDPI_PROTO_UNKNOWN
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_UNKNOWN
#endif
#define NDPI_LOG_ERR(mod, args...) \
@@ -274,6 +278,12 @@
#define NDPI_BITMASK_SET_ALL(a) NDPI_ONE(&a)
#define NDPI_BITMASK_SET(a, b) { memcpy(&a, &b, sizeof(NDPI_PROTOCOL_BITMASK)); }
#define NDPI_SET_BIT(num, n) num |= 1UL << ( n )
#define NDPI_CLR_BIT(num, n) num &= ~(1UL << ( n ))
#define NDPI_CLR_BIT(num, n) num &= ~(1UL << ( n ))
#define NDPI_ISSET_BIT(num, n) (num & (1UL << ( n )))
#define NDPI_ZERO_BIT(num) num = 0
/* this is a very very tricky macro *g*,
* the compiler will remove all shifts here if the protocol is static...
*/
@@ -304,10 +314,10 @@
#define NDPI_ICMPV6_PROTOCOL_TYPE 0x3a
/* the get_uXX will return raw network packet bytes !! */
#define get_u_int8_t(X,O) (*(u_int8_t *)(((u_int8_t *)X) + O))
#define get_u_int16_t(X,O) (*(u_int16_t *)(((u_int8_t *)X) + O))
#define get_u_int32_t(X,O) (*(u_int32_t *)(((u_int8_t *)X) + O))
#define get_u_int64_t(X,O) (*(u_int64_t *)(((u_int8_t *)X) + O))
#define get_u_int8_t(X,O) (*(u_int8_t *)((&(((u_int8_t *)X)[O]))))
#define get_u_int16_t(X,O) (*(u_int16_t *)((&(((u_int8_t *)X)[O]))))
#define get_u_int32_t(X,O) (*(u_int32_t *)((&(((u_int8_t *)X)[O]))))
#define get_u_int64_t(X,O) (*(u_int64_t *)((&(((u_int8_t *)X)[O]))))
/* new definitions to get little endian from network bytes */
#define get_ul8(X,O) get_u_int8_t(X,O)
@@ -328,7 +338,7 @@
#define match_first_bytes(payload,st) (memcmp((payload),(st),(sizeof(st)-1))==0)
#if defined(WIN32) && !defined(snprintf)
#define snprintf _snprintf
#define snprintf _snprintf
#endif
#define NDPI_MAX_DNS_REQUESTS 16
@@ -343,6 +353,10 @@
#define NDPI_CIPHER_WEAK 1
#define NDPI_CIPHER_INSECURE 2
#define NDPI_OPTIMAL_HLL_NUM_BUCKETS 16
#define NDPI_MAX_NUM_TLS_APPL_BLOCKS 8
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
+7 -1
View File
@@ -57,7 +57,7 @@
#if defined __NetBSD__ || defined __OpenBSD__
#include <netinet/in_systm.h>
#ifdef __OpenBSD__
#if defined __OpenBSD__
#include <pthread.h>
#endif
@@ -67,4 +67,10 @@
#endif /* Win32 */
#if defined __OpenBSD__
#include "ndpi_includes_OpenBSD.h"
#else
typedef struct timeval pkt_timeval;
#endif /* __OpenBSD__ */
#endif /* __NDPI_INCLUDES_H__ */
+35
View File
@@ -0,0 +1,35 @@
/*
* ndpi_includes_OpenBSD.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_OPENBSD_H__
#define __NDPI_INCLUDES_OPENBSD_H__
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP 132
#endif /* IPPROTO_SCTP */
#include <net/bpf.h>
typedef struct bpf_timeval pkt_timeval;
#endif /* __NDPI_INCLUDES_OPENBSD_H__ */
+4
View File
@@ -150,6 +150,10 @@ extern "C" {
#define ndpi_match_strprefix(payload, payload_len, str) \
ndpi_match_prefix((payload), (payload_len), (str), (sizeof(str)-1))
#ifdef NDPI_DETECTION_SUPPORT_IPV6
int ndpi_handle_ipv6_extension_headers(struct ndpi_detection_module_struct *ndpi_str, const u_int8_t ** l4ptr, u_int16_t * l4len, u_int8_t * nxt_hdr);
#endif
#ifdef __cplusplus
}
#endif
+16 -11
View File
@@ -82,12 +82,12 @@ typedef enum {
NDPI_PROTOCOL_RTSP = 50,
NDPI_PROTOCOL_MAIL_IMAPS = 51,
NDPI_PROTOCOL_ICECAST = 52,
NDPI_PROTOCOL_PPLIVE = 53, /* Tomasz Bujlow <tomasz@skatnet.dk> */
NDPI_PROTOCOL_FREE_53 = 53,
NDPI_PROTOCOL_PPSTREAM = 54,
NDPI_PROTOCOL_ZATTOO = 55,
NDPI_PROTOCOL_SHOUTCAST = 56,
NDPI_PROTOCOL_SOPCAST = 57,
NDPI_PROTOCOL_TVANTS = 58,
NDPI_PROTOCOL_DISCORD = 58,
NDPI_PROTOCOL_TVUPLAYER = 59,
NDPI_PROTOCOL_HTTP_DOWNLOAD = 60,
NDPI_PROTOCOL_QQLIVE = 61,
@@ -97,10 +97,10 @@ typedef enum {
NDPI_PROTOCOL_IRC = 65,
NDPI_PROTOCOL_AYIYA = 66,
NDPI_PROTOCOL_UNENCRYPTED_JABBER = 67,
NDPI_PROTOCOL_MSN = 68,
NDPI_PROTOCOL_OSCAR = 69,
NDPI_PROTOCOL_NATS = 68,
NDPI_PROTOCOL_FREE_69 = 69, /* Free */
NDPI_PROTOCOL_YAHOO = 70,
NDPI_PROTOCOL_BATTLEFIELD = 71,
NDPI_PROTOCOL_FREE_71 = 71, /* Free */
NDPI_PROTOCOL_GOOGLE_PLUS = 72,
NDPI_PROTOCOL_IP_VRRP = 73,
NDPI_PROTOCOL_STEAM = 74, /* Tomasz Bujlow <tomasz@skatnet.dk> */
@@ -119,7 +119,7 @@ typedef enum {
NDPI_PROTOCOL_RTP = 87,
NDPI_PROTOCOL_RDP = 88,
NDPI_PROTOCOL_VNC = 89,
NDPI_PROTOCOL_PCANYWHERE = 90,
NDPI_PROTOCOL_FREE90 = 90, /* Free */
NDPI_PROTOCOL_TLS = 91,
NDPI_PROTOCOL_SSH = 92,
NDPI_PROTOCOL_USENET = 93,
@@ -212,7 +212,7 @@ typedef enum {
NDPI_PROTOCOL_CNN = 180, /* Tomasz Bujlow <tomasz@skatnet.dk> */
NDPI_PROTOCOL_MEGACO = 181, /* Gianluca Costa <g.costa@xplico.org> */
NDPI_PROTOCOL_REDIS = 182,
NDPI_PROTOCOL_PANDO = 183, /* Tomasz Bujlow <tomasz@skatnet.dk> */
NDPI_PROTOCOL_FREE_183 = 183,
NDPI_PROTOCOL_VHUA = 184,
NDPI_PROTOCOL_TELEGRAM = 185, /* Gianluca Costa <g.costa@xplico.org> */
NDPI_PROTOCOL_VEVO = 186,
@@ -237,7 +237,7 @@ typedef enum {
NDPI_PROTOCOL_FREE_205 = 205,
NDPI_PROTOCOL_WIREGUARD = 206,
NDPI_PROTOCOL_SMPP = 207, /* Damir Franusic <df@release14.org> */
NDPI_PROTOCOL_DNSCRYPT = 208,
NDPI_PROTOCOL_DNSCRYPT = 208, /* Toni Uhlig <matzeton@googlemail.com> */
NDPI_PROTOCOL_TINC = 209, /* William Guglielmo <william@deselmo.com> */
NDPI_PROTOCOL_DEEZER = 210,
NDPI_PROTOCOL_INSTAGRAM = 211, /* Andrea Buscarinu <andrea.buscarinu@gmail.com> */
@@ -248,7 +248,7 @@ typedef enum {
NDPI_PROTOCOL_IMO = 216,
NDPI_PROTOCOL_GOOGLE_DRIVE = 217,
NDPI_PROTOCOL_OCS = 218,
NDPI_PROTOCOL_OFFICE_365 = 219,
NDPI_PROTOCOL_MICROSOFT_365 = 219,
NDPI_PROTOCOL_CLOUDFLARE = 220,
NDPI_PROTOCOL_MS_ONE_DRIVE = 221,
NDPI_PROTOCOL_MQTT = 222,
@@ -265,8 +265,8 @@ typedef enum {
NDPI_PROTOCOL_LINKEDIN = 233, /* Paulo Angelo <pa@pauloangelo.com> */
NDPI_PROTOCOL_SOUNDCLOUD = 234,
NDPI_PROTOCOL_CSGO = 235, /* Counter-Strike Global Offensive, Dota = 2 */
NDPI_PROTOCOL_LISP = 236,
NDPI_PROTOCOL_DIAMETER = 237,
NDPI_PROTOCOL_LISP = 236,
NDPI_PROTOCOL_DIAMETER = 237,
NDPI_PROTOCOL_APPLE_PUSH = 238,
NDPI_PROTOCOL_GOOGLE_SERVICES = 239,
NDPI_PROTOCOL_AMAZON_VIDEO = 240,
@@ -278,6 +278,11 @@ typedef enum {
NDPI_PROTOCOL_BLOOMBERG = 246,
NDPI_PROTOCOL_CAPWAP = 247,
NDPI_PROTOCOL_ZABBIX = 248,
NDPI_PROTOCOL_S7COMM = 249,
NDPI_PROTOCOL_MSTEAMS = 250,
NDPI_PROTOCOL_WEBSOCKET = 251, /* Leonn Paiva <leonn.paiva@gmail.com> */
NDPI_PROTOCOL_ANYDESK = 252, /* Toni Uhlig <matzeton@googlemail.com> */
NDPI_PROTOCOL_SOAP = 253, /* Toni Uhlig <matzeton@googlemail.com> */
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_protocol_ids.h"
+6 -9
View File
@@ -58,7 +58,6 @@ void init_applejuice_dissector(struct ndpi_detection_module_struct *ndpi_struct,
void init_armagetron_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ayiya_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_amqp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_battlefield_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_bgp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_bittorrent_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_lisp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -103,12 +102,11 @@ void init_mail_imap_dissector(struct ndpi_detection_module_struct *ndpi_struct,
void init_mail_pop_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mail_smtp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_maplestory_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mdns_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_megaco_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mgpc_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mining_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mms_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_msn_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_nats_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mpegts_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mssql_tds_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_mysql_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -121,11 +119,7 @@ void init_ntp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int3
void init_openft_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_openvpn_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_oracle_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_oscar_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_pando_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_pcanywhere_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_postgres_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_pplive_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_ppstream_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_pptp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_qq_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -167,7 +161,6 @@ void init_telnet_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_i
void init_tftp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_thunder_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_tor_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_tvants_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_tvuplayer_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_usenet_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_upnp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
@@ -182,7 +175,6 @@ void init_world_of_warcraft_dissector(struct ndpi_detection_module_struct *ndpi_
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);
void init_xdmcp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_yahoo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
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);
@@ -216,4 +208,9 @@ void init_wireguard_dissector(struct ndpi_detection_module_struct *ndpi_struct,
void init_targus_getdata_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_dnp3_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_104_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_s7comm_dissector(struct ndpi_detection_module_struct *ndpi_struct,u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_websocket_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_soap_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
void init_dnscrypt_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
#endif /* __NDPI_PROTOCOLS_H__ */
+159 -111
View File
@@ -50,19 +50,52 @@ typedef enum {
ndpi_l2tp_tunnel,
} ndpi_packet_tunnel;
/*
NOTE
When the typedef below is modified don't forget to update
- ndpi_risk2str (in ndpi_utils.c)
- https://github.com/ntop/ntopng/blob/dev/scripts/lua/modules/flow_risk_utils.lua
- ndpi_risk_enum (in python/ndpi.py)
*/
typedef enum {
ndpi_url_no_problem = 0,
ndpi_url_possible_xss,
ndpi_url_possible_sql_injection,
ndpi_url_possible_rce_injection
} ndpi_url_risk;
NDPI_NO_RISK = 0,
NDPI_URL_POSSIBLE_XSS,
NDPI_URL_POSSIBLE_SQL_INJECTION,
NDPI_URL_POSSIBLE_RCE_INJECTION,
NDPI_BINARY_APPLICATION_TRANSFER,
NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT,
NDPI_TLS_SELFSIGNED_CERTIFICATE,
NDPI_TLS_OBSOLETE_VERSION,
NDPI_TLS_WEAK_CIPHER,
NDPI_TLS_CERTIFICATE_EXPIRED,
NDPI_TLS_CERTIFICATE_MISMATCH, /* 10 */
NDPI_HTTP_SUSPICIOUS_USER_AGENT,
NDPI_HTTP_NUMERIC_IP_HOST,
NDPI_HTTP_SUSPICIOUS_URL,
NDPI_HTTP_SUSPICIOUS_HEADER,
NDPI_TLS_NOT_CARRYING_HTTPS,
NDPI_SUSPICIOUS_DGA_DOMAIN,
NDPI_MALFORMED_PACKET,
NDPI_SSH_OBSOLETE_CLIENT_VERSION_OR_CIPHER,
NDPI_SSH_OBSOLETE_SERVER_VERSION_OR_CIPHER,
NDPI_SMB_INSECURE_VERSION, /* 20 */
NDPI_TLS_SUSPICIOUS_ESNI_USAGE,
NDPI_UNSAFE_PROTOCOL,
NDPI_DNS_SUSPICIOUS_TRAFFIC,
NDPI_TLS_MISSING_SNI,
/* Leave this as last member */
NDPI_MAX_RISK /* must be <= 31 due to (**) */
} ndpi_risk_enum;
typedef u_int32_t ndpi_risk; /* (**) */
/* NDPI_VISIT */
typedef enum {
ndpi_preorder,
ndpi_postorder,
ndpi_endorder,
ndpi_leaf
ndpi_preorder,
ndpi_postorder,
ndpi_endorder,
ndpi_leaf
} ndpi_VISIT;
/* NDPI_NODE */
@@ -446,6 +479,10 @@ PACK_ON struct tinc_cache_entry {
u_int16_t dst_port;
} PACK_OFF;
/*
In case the typedef below is modified, please update
ndpi_http_method2str (ndpi_utils.c)
*/
typedef enum {
NDPI_HTTP_METHOD_UNKNOWN = 0,
NDPI_HTTP_METHOD_OPTIONS,
@@ -493,18 +530,12 @@ struct ndpi_id_struct {
/* NDPI_PROTOCOL_GNUTELLA */
u_int32_t gnutella_ts;
/* NDPI_PROTOCOL_BATTLEFIELD */
u_int32_t battlefield_ts;
/* NDPI_PROTOCOL_THUNDER */
u_int32_t thunder_ts;
/* NDPI_PROTOCOL_RTSP */
u_int32_t rtsp_timer;
/* NDPI_PROTOCOL_OSCAR */
u_int32_t oscar_last_safe_access_time;
/* NDPI_PROTOCOL_ZATTOO */
u_int32_t zattoo_ts;
@@ -545,9 +576,6 @@ struct ndpi_id_struct {
/* NDPI_PROTOCOL_IRC */
u_int8_t irc_number_of_port;
/* NDPI_PROTOCOL_OSCAR */
u_int8_t oscar_ssl_session_id[33];
/* NDPI_PROTOCOL_UNENCRYPTED_JABBER */
u_int8_t jabber_voice_stun_used_ports;
@@ -649,7 +677,8 @@ struct ndpi_flow_tcp_struct {
/* NDPI_PROTOCOL_TLS */
u_int8_t hello_processed:1, certificate_processed:1, subprotocol_detected:1,
fingerprint_set:1, _pad:4;
u_int8_t sha1_certificate_fingerprint[20];
u_int8_t sha1_certificate_fingerprint[20], num_tls_blocks;
int16_t tls_application_blocks_len[NDPI_MAX_NUM_TLS_APPL_BLOCKS]; /* + = src->dst, - = dst->src */
} tls;
/* NDPI_PROTOCOL_POSTGRES */
@@ -688,6 +717,9 @@ struct ndpi_flow_tcp_struct {
/* NDPI_PROTOCOL_MAIL_IMAP */
u_int32_t mail_imap_stage:3, mail_imap_starttls:2;
/* NDPI_PROTOCOL_SOAP */
u_int32_t soap_stage:1;
/* NDPI_PROTOCOL_SKYPE */
u_int8_t skype_packet_id;
@@ -712,24 +744,14 @@ struct ndpi_flow_tcp_struct {
/* NDPI_PROTOCOL_NEST_LOG_SINK */
u_int8_t nest_log_sink_matches;
}
#ifndef WIN32
__attribute__ ((__packed__))
#endif
;
};
/* ************************************************** */
struct ndpi_flow_udp_struct {
/* NDPI_PROTOCOL_BATTLEFIELD */
u_int32_t battlefield_msg_id;
/* NDPI_PROTOCOL_SNMP */
u_int32_t snmp_msg_id;
/* NDPI_PROTOCOL_BATTLEFIELD */
u_int32_t battlefield_stage:3;
/* NDPI_PROTOCOL_SNMP */
u_int32_t snmp_stage:2;
@@ -771,11 +793,7 @@ struct ndpi_flow_udp_struct {
/* NDPI_PROTOCOL_WIREGUARD */
u_int8_t wireguard_stage;
u_int32_t wireguard_peer_index[2];
}
#ifndef WIN32
__attribute__ ((__packed__))
#endif
;
};
/* ************************************************** */
@@ -794,15 +812,10 @@ struct ndpi_packet_struct {
const u_int8_t *generic_l4_ptr; /* is set only for non tcp-udp traffic */
const u_int8_t *payload;
u_int32_t tick_timestamp;
u_int64_t tick_timestamp_l;
u_int64_t current_time_ms;
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_SIZE];
u_int8_t detected_subprotocol_stack[NDPI_PROTOCOL_SIZE];
#ifndef WIN32
__attribute__ ((__packed__))
#endif
u_int16_t protocol_stack_info;
struct ndpi_int_one_line_struct line[NDPI_MAX_PARSE_LINES_PER_PACKET];
@@ -811,6 +824,7 @@ struct ndpi_packet_struct {
struct ndpi_int_one_line_struct forwarded_line;
struct ndpi_int_one_line_struct referer_line;
struct ndpi_int_one_line_struct content_line;
struct ndpi_int_one_line_struct content_disposition_line;
struct ndpi_int_one_line_struct accept_line;
struct ndpi_int_one_line_struct user_agent_line;
struct ndpi_int_one_line_struct http_url_name;
@@ -846,6 +860,7 @@ struct ndpi_detection_module_struct;
struct ndpi_flow_struct;
struct ndpi_call_function_struct {
u_int16_t ndpi_protocol_id;
NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK excluded_protocol_bitmask;
NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask;
@@ -910,6 +925,12 @@ typedef enum {
NDPI_PROTOCOL_CATEGORY_SHOPPING,
NDPI_PROTOCOL_CATEGORY_PRODUCTIVITY,
NDPI_PROTOCOL_CATEGORY_FILE_SHARING,
/*
The category below is used by sites who are used
to test connectivity
*/
NDPI_PROTOCOL_CATEGORY_CONNECTIVITY_CHECK,
NDPI_PROTOCOL_CATEGORY_IOT_SCADA,
/* Some custom categories */
CUSTOM_CATEGORY_MINING = 99,
@@ -935,15 +956,17 @@ typedef enum {
in ndpi_main.c
*/
NDPI_PROTOCOL_NUM_CATEGORIES /*
NDPI_PROTOCOL_NUM_CATEGORIES, /*
NOTE: Keep this as last member
Unused as value but useful to getting the number of elements
in this datastructure
*/
NDPI_PROTOCOL_ANY_CATEGORY /* Used to handle wildcards */
} ndpi_protocol_category_t;
typedef enum {
ndpi_pref_direction_detect_disable = 0,
ndpi_pref_enable_tls_block_dissection
} ndpi_detection_preference;
/* ntop extensions */
@@ -953,6 +976,7 @@ typedef struct ndpi_proto_defaults {
u_int8_t can_have_a_subprotocol;
u_int16_t protoId, protoIdx;
u_int16_t master_tcp_protoId[2], master_udp_protoId[2]; /* The main protocols on which this sub-protocol sits on */
u_int16_t tcp_default_ports[MAX_DEFAULT_PORTS], udp_default_ports[MAX_DEFAULT_PORTS];
ndpi_protocol_breed_t protoBreed;
void (*func) (struct ndpi_detection_module_struct *, struct ndpi_flow_struct *flow);
} ndpi_proto_defaults_t;
@@ -978,7 +1002,7 @@ typedef struct ndpi_proto {
ndpi_protocol_category_t category;
} ndpi_protocol;
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN }
#define NDPI_PROTOCOL_NULL { NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_UNKNOWN , NDPI_PROTOCOL_CATEGORY_UNSPECIFIED }
#define NUM_CUSTOM_CATEGORIES 5
#define CUSTOM_CATEGORY_LABEL_LEN 32
@@ -988,21 +1012,6 @@ typedef struct ndpi_proto {
/* Needed to have access to HAVE_* defines */
#include "ndpi_config.h"
#ifdef HAVE_HYPERSCAN
#include <hs/hs.h>
struct hs_list {
char *expression;
unsigned int id;
struct hs_list *next;
};
struct hs {
hs_database_t *database;
hs_scratch_t *scratch;
};
#endif
#ifdef HAVE_PCRE
#include <pcre.h>
@@ -1012,13 +1021,19 @@ struct pcre_struct {
};
#endif
typedef enum {
ndpi_stun_cache,
ndpi_hangout_cache
} ndpi_lru_cache_type;
struct ndpi_detection_module_struct {
NDPI_PROTOCOL_BITMASK detection_bitmask;
NDPI_PROTOCOL_BITMASK generic_http_packet_bitmask;
u_int32_t current_ts;
u_int32_t ticks_per_second;
u_int16_t num_tls_blocks_to_follow;
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void *user_data;
#endif
@@ -1071,13 +1086,7 @@ struct ndpi_detection_module_struct {
/* IMPORTANT: please update ndpi_finalize_initalization() whenever you add a new automa */
struct {
#ifdef HAVE_HYPERSCAN
struct hs *hostnames;
unsigned int num_to_load;
struct hs_list *to_load;
#else
ndpi_automa hostnames, hostnames_shadow;
#endif
void *ipAddresses, *ipAddresses_shadow; /* Patricia */
u_int8_t categories_loaded;
} custom_categories;
@@ -1089,16 +1098,12 @@ struct ndpi_detection_module_struct {
u_int32_t irc_timeout;
/* gnutella parameters */
u_int32_t gnutella_timeout;
/* battlefield parameters */
u_int32_t battlefield_timeout;
/* thunder parameters */
u_int32_t thunder_timeout;
/* SoulSeek parameters */
u_int32_t soulseek_connection_ip_tick_timeout;
/* rtsp parameters */
u_int32_t rtsp_connection_timeout;
/* tvants parameters */
u_int32_t tvants_connection_timeout;
/* rstp */
u_int32_t orb_rstp_ts_timeout;
/* yahoo */
@@ -1127,12 +1132,18 @@ struct ndpi_detection_module_struct {
/* NDPI_PROTOCOL_STUN and subprotocols */
struct ndpi_lru_cache *stun_cache;
/* NDPI_PROTOCOL_MSTEAMS */
struct ndpi_lru_cache *msteams_cache;
ndpi_proto_defaults_t proto_defaults[NDPI_MAX_SUPPORTED_PROTOCOLS+NDPI_MAX_NUM_CUSTOM_PROTOCOLS];
u_int8_t direction_detect_disable:1, /* disable internal detection of packet direction */
_pad:7;
u_int8_t direction_detect_disable:1, /* disable internal detection of packet direction */ _pad:7;
void *hyperscan; /* Intel Hyperscan */
void (*ndpi_notify_lru_add_handler_ptr)(ndpi_lru_cache_type cache_type, u_int32_t proto, u_int32_t app_proto);
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_typedefs.h"
#endif
};
#endif /* NDPI_LIB_COMPILATION */
@@ -1143,16 +1154,18 @@ typedef enum {
ndpi_cipher_insecure = NDPI_CIPHER_INSECURE
} ndpi_cipher_weakness;
/*
NOTE
When the struct below is modified don't forget to update
- ndpi_flow_struct (in python/ndpi.py)
*/
struct ndpi_flow_struct {
u_int16_t detected_protocol_stack[NDPI_PROTOCOL_SIZE];
#ifndef WIN32
__attribute__ ((__packed__))
#endif
u_int16_t protocol_stack_info;
/* init parameter, internal used to set up timestamp,... */
u_int16_t guessed_protocol_id, guessed_host_protocol_id, guessed_category, guessed_header_category;
u_int8_t l4_proto, protocol_id_already_guessed:1, host_already_guessed:1,
u_int8_t l4_proto, protocol_id_already_guessed:1, host_already_guessed:1, fail_with_unknown:1,
init_finished:1, setup_packet_direction:1, packet_direction:1, check_extra_packets:1;
/*
@@ -1186,7 +1199,10 @@ struct ndpi_flow_struct {
struct ndpi_id_struct *server_id;
/* HTTP host or DNS query */
u_char host_server_name[240];
u_int8_t initial_binary_bytes[8], initial_binary_bytes_len;
u_int8_t risk_checked;
ndpi_risk risk; /* Issues found with this flow [bitmask of ndpi_risk] */
/*
This structure below will not not stay inside the protos
structure below as HTTP is used by many subprotocols
@@ -1231,12 +1247,18 @@ struct ndpi_flow_struct {
struct {
struct {
char ssl_version_str[12];
u_int16_t ssl_version, server_names_len;
char client_requested_server_name[64], *server_names, server_organization[64],
*alpn, *tls_supported_versions;
char client_requested_server_name[64], *server_names,
*alpn, *tls_supported_versions, *issuerDN, *subjectDN;
u_int32_t notBefore, notAfter;
char ja3_client[33], ja3_server[33];
u_int16_t server_cipher;
struct {
u_int16_t cipher_suite;
char *esni;
} encrypted_sni;
ndpi_cipher_weakness server_unsafe_cipher;
} ssl;
@@ -1264,10 +1286,6 @@ struct ndpi_flow_struct {
char username[32], password[32];
} telnet;
struct {
char answer[96];
} mdns;
struct {
char version[32];
} ubntac2;
@@ -1314,9 +1332,6 @@ struct ndpi_flow_struct {
/* NDPI_PROTOCOL_DIRECTCONNECT */
u_int8_t directconnect_stage:2; // 0 - 1
/* NDPI_PROTOCOL_YAHOO */
u_int8_t sip_yahoo_voice:1;
/* NDPI_PROTOCOL_HTTP */
u_int8_t http_detected:1;
@@ -1335,9 +1350,6 @@ struct ndpi_flow_struct {
/* NDPI_PROTOCOL_THUNDER */
u_int8_t thunder_stage:2; // 0 - 3
/* NDPI_PROTOCOL_OSCAR */
u_int8_t oscar_ssl_voice_stage:3, oscar_video_voice:1;
/* NDPI_PROTOCOL_FLORENSIA */
u_int8_t florensia_stage:1;
@@ -1353,15 +1365,9 @@ struct ndpi_flow_struct {
/* NDPI_PROTOCOL_RTMP */
u_int8_t rtmp_stage:2;
/* NDPI_PROTOCOL_PANDO */
u_int8_t pando_stage:3;
/* NDPI_PROTOCOL_STEAM */
u_int16_t steam_stage:3, steam_stage1:3, steam_stage2:2, steam_stage3:2;
/* NDPI_PROTOCOL_PPLIVE */
u_int8_t pplive_stage1:3, pplive_stage2:2, pplive_stage3:2;
/* NDPI_PROTOCOL_STARCRAFT */
u_int8_t starcraft_udp_stage : 3; // 0-7
@@ -1376,10 +1382,7 @@ struct ndpi_flow_struct {
/* NDPI_PROTOCOL_CSGO */
u_int8_t csgo_strid[18],csgo_state,csgo_s2;
u_int32_t csgo_id2;
/* NDPI_PROTOCOL_1KXUN || NDPI_PROTOCOL_IQIYI */
u_int16_t kxun_counter, iqiyi_counter;
/* internal structures to save functions calls */
struct ndpi_packet_struct packet;
struct ndpi_flow_struct *flow;
@@ -1388,14 +1391,14 @@ struct ndpi_flow_struct {
};
typedef struct {
char *string_to_match, *string2_to_match, *pattern_to_match, *proto_name;
char *string_to_match, *proto_name;
int protocol_id;
ndpi_protocol_category_t protocol_category;
ndpi_protocol_breed_t protocol_breed;
} ndpi_protocol_match;
typedef struct {
char *string_to_match, *hyperscan_string_to_match;
char *string_to_match;
ndpi_protocol_category_t protocol_category;
} ndpi_category_match;
@@ -1411,6 +1414,7 @@ typedef enum
{
ndpi_no_prefs = 0,
ndpi_dont_load_tor_hosts,
ndpi_dont_init_libgcrypt,
} ndpi_prefs;
typedef struct {
@@ -1426,8 +1430,9 @@ typedef enum {
ndpi_serialization_format_csv
} ndpi_serialization_format;
/* Note: key supports string and uint32 (compressed to uint8/uint16) only,
* this is also enforced by the API */
/* Note:
* - up to 16 types (TLV encoding: "4 bit key type" << 4 | "4 bit value type")
* - key supports string and uint32 (compressed to uint8/uint16) only, this is also enforced by the API */
typedef enum {
ndpi_serialization_unknown = 0,
ndpi_serialization_end_of_record,
@@ -1440,9 +1445,14 @@ typedef enum {
ndpi_serialization_int32,
ndpi_serialization_int64,
ndpi_serialization_float,
ndpi_serialization_string
ndpi_serialization_string,
ndpi_serialization_start_of_block,
ndpi_serialization_end_of_block,
ndpi_serialization_start_of_list,
ndpi_serialization_end_of_list
} ndpi_serialization_type;
#define NDPI_SERIALIZER_DEFAULT_HEADER_SIZE 1024
#define NDPI_SERIALIZER_DEFAULT_BUFFER_SIZE 8192
#define NDPI_SERIALIZER_DEFAULT_BUFFER_INCR 1024
@@ -1451,19 +1461,31 @@ typedef enum {
#define NDPI_SERIALIZER_STATUS_EOR (1 << 2)
#define NDPI_SERIALIZER_STATUS_SOB (1 << 3)
#define NDPI_SERIALIZER_STATUS_NOT_EMPTY (1 << 4)
#define NDPI_SERIALIZER_STATUS_LIST (1 << 5)
#define NDPI_SERIALIZER_STATUS_SOL (1 << 6)
#define NDPI_SERIALIZER_STATUS_HDR_DONE (1 << 7)
typedef struct {
u_int32_t size_used;
} ndpi_private_serializer_buffer_status;
typedef struct {
u_int32_t flags;
u_int32_t size_used;
ndpi_private_serializer_buffer_status buffer;
ndpi_private_serializer_buffer_status header;
} ndpi_private_serializer_status;
typedef struct {
u_int32_t initial_size;
u_int32_t size;
u_int8_t *data;
} ndpi_private_serializer_buffer;
typedef struct {
ndpi_private_serializer_status status;
u_int32_t initial_buffer_size;
u_int32_t buffer_size;
ndpi_private_serializer_buffer buffer;
ndpi_private_serializer_buffer header;
ndpi_serialization_format fmt;
u_int8_t *buffer;
char csv_separator[2];
u_int8_t has_snapshot;
ndpi_private_serializer_status snapshot;
@@ -1485,11 +1507,10 @@ typedef struct {
struct ndpi_analyze_struct {
u_int32_t *values;
u_int32_t min_val, max_val, sum_total, num_data_entries, next_value_insert_index;
u_int16_t num_values_array_len /* lenght of the values array */;
u_int16_t num_values_array_len /* length of the values array */;
struct {
/* https://www.johndcook.com/blog/standard_deviation/ */
float mu, q;
u_int64_t sum_square_total;
} stddev;
};
@@ -1501,4 +1522,31 @@ struct ndpi_analyze_struct {
typedef struct ndpi_ptree ndpi_ptree_t;
/* **************************************** */
struct ndpi_hll {
u_int8_t bits;
size_t size;
u_int8_t *registers;
};
/* **************************************** */
enum ndpi_bin_family {
ndpi_bin_family8,
ndpi_bin_family16,
ndpi_bin_family32
};
struct ndpi_bin {
u_int8_t num_bins, is_empty;
enum ndpi_bin_family family;
union {
u_int8_t *bins8; /* num_bins bins */
u_int16_t *bins16; /* num_bins bins */
u_int32_t *bins32; /* num_bins bins */
} u;
};
#endif /* __NDPI_TYPEDEFS_H__ */
+21 -1
View File
@@ -31,6 +31,8 @@
#define __mingw_forceinline __inline__ __attribute__((__always_inline__,__gnu_inline__))
#endif
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WIN8
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
@@ -39,6 +41,7 @@
#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
#include <process.h> /* for getpid() and the exec..() family */
#include <stdint.h>
#include <time.h>
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
@@ -48,6 +51,17 @@
#define IPVERSION 4 /* on *nix it is defined in netinet/ip.h */
#ifndef MIN
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#endif
#ifndef IPPROTO_SCTP
#define IPPROTO_SCTP 132
#endif
#undef gettimeofday
#define gettimeofday mingw_gettimeofday
extern char* strsep(char **sp, char *sep);
typedef unsigned char u_char;
@@ -76,8 +90,14 @@ typedef unsigned __int64 u_int64_t;
extern unsigned long waitForNextEvent(unsigned long ulDelay /* ms */);
#define sleep(a /* sec */) waitForNextEvent(1000*a /* ms */)
#define localtime_r(a, b) localtime_s(b, a)
#define strtok_r strtok_s
#define timegm _mkgmtime
static inline struct tm * localtime_r(const time_t *timep, struct tm * result)
{
struct tm *timeinfo;
timeinfo = localtime(timep);
return timeinfo;
}
#endif /* __NDPI_WIN32_H__ */
+16 -4
View File
@@ -15,7 +15,7 @@ libdir = ${prefix}/lib
includedir = ${prefix}/include/ndpi
CC = @CC@
CFLAGS += -fPIC -DPIC -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION -Wall @CFLAGS@ @CUSTOM_NDPI@
LDFLAGS = @LDFLAGS@
LDFLAGS = @LDFLAGS@ @ADDITIONAL_LIBS@ @LIBS@
RANLIB = ranlib
OBJECTS = $(patsubst protocols/%.c, protocols/%.o, $(wildcard protocols/*.c)) $(patsubst third_party/src/%.c, third_party/src/%.o, $(wildcard third_party/src/*.c)) $(patsubst ./%.c, ./%.o, $(wildcard ./*.c))
@@ -29,13 +29,19 @@ NDPI_LIBS = $(NDPI_LIB_STATIC) $(NDPI_LIB_SHARED)
ifneq ($(OS),Windows_NT)
OS := $(shell uname)
endif
BUILD_MINGW = @BUILD_MINGW@
ifeq ($(OS),Darwin)
CC=clang
SONAME_FLAG=
else
ifneq ($(BUILD_MINGW),)
NDPI_LIB_SHARED_BASE = libndpi
NDPI_LIB_SHARED = $(NDPI_LIB_SHARED_BASE)-@NDPI_VERSION_SHORT@.dll
else
SONAME_FLAG=-Wl,-soname,$(NDPI_LIB_SHARED_BASE).$(NDPI_VERSION_MAJOR)
endif
endif
all: $(NDPI_LIBS)
@@ -46,15 +52,21 @@ $(NDPI_LIB_STATIC): $(OBJECTS)
$(RANLIB) $@
$(NDPI_LIB_SHARED): $(OBJECTS)
$(CC) -shared -fPIC $(SONAME_FLAG) -o $@ $(OBJECTS) $(LDFLAGS) @ADDITIONAL_LIBS@
$(CC) -shared -fPIC $(SONAME_FLAG) -o $@ $(OBJECTS) $(LDFLAGS)
ln -fs $(NDPI_LIB_SHARED) $(NDPI_LIB_SHARED_BASE)
ln -fs $(NDPI_LIB_SHARED) $(NDPI_LIB_SHARED_BASE).$(NDPI_VERSION_MAJOR)
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) -c $< -o $@ $(LDFLAGS)
$(CC) $(CFLAGS) -c $< -o $@
clean:
/bin/rm -f $(NDPI_LIB_STATIC) $(OBJECTS) *.o *.so *.lo $(NDPI_LIB_SHARED)
/bin/rm -f $(NDPI_LIB_STATIC) $(OBJECTS) *.o *.so *.lo libndpi.so*
distdir:
cp ndpi_content_match.c.inc '$(distdir)/'
find . -type d | xargs -I'{}' mkdir -p '$(distdir)/{}'
find ../include -type f -name '*.h' | xargs -I'{}' cp '{}' '$(distdir)/{}'
find . -type f -name '*.c' -o -name '*.h' | xargs -I'{}' cp '{}' '$(distdir)/{}'
distclean: clean
/bin/rm -f Makefile
+632 -22
View File
@@ -40,7 +40,7 @@ void ndpi_init_data_analysis(struct ndpi_analyze_struct *ret, u_int16_t _max_ser
u_int32_t len;
memset(ret, 0, sizeof(struct ndpi_analyze_struct));
if(_max_series_len > MAX_SERIES_LEN) _max_series_len = MAX_SERIES_LEN;
ret->num_values_array_len = _max_series_len;
@@ -61,8 +61,8 @@ struct ndpi_analyze_struct* ndpi_alloc_data_analysis(u_int16_t _max_series_len)
struct ndpi_analyze_struct *ret = ndpi_malloc(sizeof(struct ndpi_analyze_struct));
if(ret != NULL)
ndpi_init_data_analysis(ret, _max_series_len);
ndpi_init_data_analysis(ret, _max_series_len);
return(ret);
}
@@ -75,12 +75,18 @@ void ndpi_free_data_analysis(struct ndpi_analyze_struct *d) {
/* ********************************************************************************* */
void ndpi_reset_data_analysis(struct ndpi_analyze_struct *d) {
memset(d, 0, sizeof(struct ndpi_analyze_struct));
memset(d->values, 0, sizeof(u_int32_t)*d->num_values_array_len);
d->num_data_entries = 0;
}
/* ********************************************************************************* */
/*
Add a new point to analyze
*/
void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int32_t value) {
float tmp_mu;
if(s->sum_total == 0)
s->min_val = s->max_val = value;
else {
@@ -89,18 +95,22 @@ void ndpi_data_add_value(struct ndpi_analyze_struct *s, const u_int32_t value) {
}
s->sum_total += value, s->num_data_entries++;
if(s->num_values_array_len) {
s->values[s->next_value_insert_index] = value;
if(++s->next_value_insert_index == s->num_values_array_len)
s->next_value_insert_index = 0;
}
/* Update stddev */
tmp_mu = s->stddev.mu;
s->stddev.mu = ((s->stddev.mu * (s->num_data_entries - 1)) + value) / s->num_data_entries;
s->stddev.q = s->stddev.q + (value - tmp_mu)*(value - s->stddev.mu);
/*
Optimized stddev calculation
https://www.khanacademy.org/math/probability/data-distributions-a1/summarizing-spread-distributions/a/calculating-standard-deviation-step-by-step
https://math.stackexchange.com/questions/683297/how-to-calculate-standard-deviation-without-detailed-historical-data
http://mathcentral.uregina.ca/QQ/database/QQ.09.02/carlos1.html
*/
s->stddev.sum_square_total += value * value;
}
/* ********************************************************************************* */
@@ -112,6 +122,16 @@ float ndpi_data_average(struct ndpi_analyze_struct *s) {
/* ********************************************************************************* */
u_int32_t ndpi_data_last(struct ndpi_analyze_struct *s) {
if((s->num_data_entries == 0) || (s->sum_total == 0))
return(0);
if(s->next_value_insert_index == 0)
return(s->values[s->num_values_array_len-1]);
else
return(s->values[s->next_value_insert_index-1]);
}
/* Return min/max on all values */
u_int32_t ndpi_data_min(struct ndpi_analyze_struct *s) { return(s->min_val); }
u_int32_t ndpi_data_max(struct ndpi_analyze_struct *s) { return(s->max_val); }
@@ -120,11 +140,17 @@ u_int32_t ndpi_data_max(struct ndpi_analyze_struct *s) { return(s->max_val); }
/* Compute the variance on all values */
float ndpi_data_variance(struct ndpi_analyze_struct *s) {
return(s->num_data_entries ? (s->stddev.q / s->num_data_entries) : 0);
return(s->num_data_entries ? (float)(s->stddev.sum_square_total - ((s->sum_total * s->sum_total) / (s->num_data_entries))) / (float)s->num_data_entries : 0);
}
/* ********************************************************************************* */
/*
See the link below for "Population and sample standard deviation review"
https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/variance-standard-deviation-sample/a/population-and-sample-standard-deviation-review
In nDPI we use an approximate stddev calculation to avoid storing all data in memory
*/
/* Compute the standard deviation on all values */
float ndpi_data_stddev(struct ndpi_analyze_struct *s) {
return(sqrt(ndpi_data_variance(s)));
@@ -137,10 +163,13 @@ float ndpi_data_window_average(struct ndpi_analyze_struct *s) {
if(s->num_values_array_len) {
float sum = 0.0;
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
if(n == 0)
return(0);
for(i=0; i<n; i++)
sum += s->values[i];
return((float)sum / (float)n);
} else
return(0);
@@ -148,6 +177,32 @@ float ndpi_data_window_average(struct ndpi_analyze_struct *s) {
/* ********************************************************************************* */
/* Compute the variance only on the sliding window */
float ndpi_data_window_variance(struct ndpi_analyze_struct *s) {
if(s->num_values_array_len) {
float sum = 0.0, avg = ndpi_data_window_average(s);
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
if(n == 0)
return(0);
for(i=0; i<n; i++)
sum += pow(s->values[i]-avg, 2);
return((float)sum / (float)n);
} else
return(0);
}
/* ********************************************************************************* */
/* Compute the variance only on the sliding window */
float ndpi_data_window_stddev(struct ndpi_analyze_struct *s) {
return(sqrt(ndpi_data_window_variance(s)));
}
/* ********************************************************************************* */
/*
Compute entropy on the last sliding window values
*/
@@ -155,17 +210,17 @@ float ndpi_data_entropy(struct ndpi_analyze_struct *s) {
if(s->num_values_array_len) {
int i;
float sum = 0.0, total = 0.0;
for(i=0; i<s->num_values_array_len; i++)
total += s->values[i];
for (i=0; i<s->num_values_array_len; i++) {
float tmp = (float)s->values[i] / (float)total;
if(tmp > FLT_EPSILON)
sum -= tmp * logf(tmp);
sum -= tmp * logf(tmp);
}
return(sum / logf(2.0));
} else
return(0);
@@ -176,10 +231,10 @@ float ndpi_data_entropy(struct ndpi_analyze_struct *s) {
void ndpi_data_print_window_values(struct ndpi_analyze_struct *s) {
if(s->num_values_array_len) {
u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len);
for(i=0; i<n; i++)
printf("[%u: %u]", i, s->values[i]);
printf("\n");
}
}
@@ -196,12 +251,567 @@ void ndpi_data_print_window_values(struct ndpi_analyze_struct *s) {
float ndpi_data_ratio(u_int32_t sent, u_int32_t rcvd) {
float s = (float)((int64_t)sent + (int64_t)rcvd);
float d = (float)((int64_t)sent - (int64_t)rcvd);
return((s == 0) ? 0 : (d/s));
}
/* ********************************************************************************* */
const char* ndpi_data_ratio2str(float ratio) {
if(ratio < -0.2) return("Download");
else if(ratio > 0.2) return("Upload");
else return("Mixed");
}
/* ********************************************************************************* */
/* ********************************************************************************* */
#include "third_party/src/hll/hll.c"
#include "third_party/src/hll/MurmurHash3.c"
int ndpi_hll_init(struct ndpi_hll *hll, u_int8_t bits) {
return(hll_init(hll, bits));
}
void ndpi_hll_destroy(struct ndpi_hll *hll) {
hll_destroy(hll);
}
void ndpi_hll_reset(struct ndpi_hll *hll) {
hll_reset(hll);
}
void ndpi_hll_add(struct ndpi_hll *hll, const char *data, size_t data_len) {
hll_add(hll, (const void *)data, data_len);
}
void ndpi_hll_add_number(struct ndpi_hll *hll, u_int32_t value) {
hll_add(hll, (const void *)&value, sizeof(value));
}
double ndpi_hll_count(struct ndpi_hll *hll) {
return(hll_count(hll));
}
/* ********************************************************************************* */
/* ********************************************************************************* */
int ndpi_init_bin(struct ndpi_bin *b, enum ndpi_bin_family f, u_int8_t num_bins) {
b->num_bins = num_bins, b->family = f, b->is_empty = 1;
switch(f) {
case ndpi_bin_family8:
if((b->u.bins8 = (u_int8_t*)ndpi_calloc(num_bins, sizeof(u_int8_t))) == NULL)
return(-1);
break;
case ndpi_bin_family16:
if((b->u.bins16 = (u_int16_t*)ndpi_calloc(num_bins, sizeof(u_int16_t))) == NULL)
return(-1);
break;
case ndpi_bin_family32:
if((b->u.bins32 = (u_int32_t*)ndpi_calloc(num_bins, sizeof(u_int32_t))) == NULL)
return(-1);
break;
}
return(0);
}
/* ********************************************************************************* */
void ndpi_free_bin(struct ndpi_bin *b) {
switch(b->family) {
case ndpi_bin_family8:
free(b->u.bins8);
break;
case ndpi_bin_family16:
free(b->u.bins16);
break;
case ndpi_bin_family32:
free(b->u.bins32);
break;
}
}
/* ********************************************************************************* */
struct ndpi_bin* ndpi_clone_bin(struct ndpi_bin *b) {
struct ndpi_bin *out = (struct ndpi_bin*)ndpi_malloc(sizeof(struct ndpi_bin));
if(!out) return(NULL);
out->num_bins = b->num_bins, out->family = b->family, out->is_empty = b->is_empty;
switch(out->family) {
case ndpi_bin_family8:
if((out->u.bins8 = (u_int8_t*)ndpi_calloc(out->num_bins, sizeof(u_int8_t))) == NULL) {
free(out);
return(NULL);
} else
memcpy(out->u.bins8, b->u.bins8, out->num_bins*sizeof(u_int8_t));
break;
case ndpi_bin_family16:
if((out->u.bins16 = (u_int16_t*)ndpi_calloc(out->num_bins, sizeof(u_int16_t))) == NULL) {
free(out);
return(NULL);
} else
memcpy(out->u.bins16, b->u.bins16, out->num_bins*sizeof(u_int16_t));
break;
case ndpi_bin_family32:
if((out->u.bins32 = (u_int32_t*)ndpi_calloc(out->num_bins, sizeof(u_int32_t))) == NULL) {
free(out);
return(NULL);
} else
memcpy(out->u.bins32, b->u.bins32, out->num_bins*sizeof(u_int32_t));
break;
}
return(out);
}
/* ********************************************************************************* */
void ndpi_set_bin(struct ndpi_bin *b, u_int8_t slot_id, u_int32_t val) {
if(slot_id >= b->num_bins) slot_id = 0;
switch(b->family) {
case ndpi_bin_family8:
b->u.bins8[slot_id] = (u_int8_t)val;
break;
case ndpi_bin_family16:
b->u.bins16[slot_id] = (u_int16_t)val;
break;
case ndpi_bin_family32:
b->u.bins32[slot_id] = (u_int32_t)val;
break;
}
}
/* ********************************************************************************* */
void ndpi_inc_bin(struct ndpi_bin *b, u_int8_t slot_id, u_int32_t val) {
b->is_empty = 0;
if(slot_id >= b->num_bins) slot_id = 0;
switch(b->family) {
case ndpi_bin_family8:
b->u.bins8[slot_id] += (u_int8_t)val;
break;
case ndpi_bin_family16:
b->u.bins16[slot_id] += (u_int16_t)val;
break;
case ndpi_bin_family32:
b->u.bins32[slot_id] += (u_int32_t)val;
break;
}
}
/* ********************************************************************************* */
u_int32_t ndpi_get_bin_value(struct ndpi_bin *b, u_int8_t slot_id) {
if(slot_id >= b->num_bins) slot_id = 0;
switch(b->family) {
case ndpi_bin_family8:
return(b->u.bins8[slot_id]);
break;
case ndpi_bin_family16:
return(b->u.bins16[slot_id]);
break;
case ndpi_bin_family32:
return(b->u.bins32[slot_id]);
break;
}
return(0);
}
/* ********************************************************************************* */
void ndpi_reset_bin(struct ndpi_bin *b) {
b->is_empty = 1;
switch(b->family) {
case ndpi_bin_family8:
memset(b->u.bins8, 0, sizeof(u_int8_t)*b->num_bins);
break;
case ndpi_bin_family16:
memset(b->u.bins16, 0, sizeof(u_int16_t)*b->num_bins);
break;
case ndpi_bin_family32:
memset(b->u.bins32, 0, sizeof(u_int32_t)*b->num_bins);
break;
}
}
/* ********************************************************************************* */
/*
Each bin slot is transformed in a % with respect to the value total
*/
void ndpi_normalize_bin(struct ndpi_bin *b) {
u_int8_t i;
u_int32_t tot = 0;
if(b->is_empty) return;
switch(b->family) {
case ndpi_bin_family8:
for(i=0; i<b->num_bins; i++) tot += b->u.bins8[i];
if(tot > 0) {
for(i=0; i<b->num_bins; i++)
b->u.bins8[i] = (b->u.bins8[i]*100) / tot;
}
break;
case ndpi_bin_family16:
for(i=0; i<b->num_bins; i++) tot += b->u.bins16[i];
if(tot > 0) {
for(i=0; i<b->num_bins; i++)
b->u.bins16[i] = (b->u.bins16[i]*100) / tot;
}
break;
case ndpi_bin_family32:
for(i=0; i<b->num_bins; i++) tot += b->u.bins32[i];
if(tot > 0) {
for(i=0; i<b->num_bins; i++)
b->u.bins32[i] = (b->u.bins32[i]*100) / tot;
}
break;
}
}
/* ********************************************************************************* */
char* ndpi_print_bin(struct ndpi_bin *b, u_int8_t normalize_first, char *out_buf, u_int out_buf_len) {
u_int8_t i;
u_int len = 0;
if(!out_buf) return(out_buf); else out_buf[0] = '\0';
if(normalize_first)
ndpi_normalize_bin(b);
switch(b->family) {
case ndpi_bin_family8:
for(i=0; i<b->num_bins; i++) {
int rc = snprintf(&out_buf[len], out_buf_len-len, "%s%u", (i > 0) ? "," : "", b->u.bins8[i]);
if(rc < 0) break;
len += rc;
}
break;
case ndpi_bin_family16:
for(i=0; i<b->num_bins; i++) {
int rc = snprintf(&out_buf[len], out_buf_len-len, "%s%u", (i > 0) ? "," : "", b->u.bins16[i]);
if(rc < 0) break;
len += rc;
}
break;
case ndpi_bin_family32:
for(i=0; i<b->num_bins; i++) {
int rc = snprintf(&out_buf[len], out_buf_len-len, "%s%u", (i > 0) ? "," : "", b->u.bins32[i]);
if(rc < 0) break;
len += rc;
}
break;
}
return(out_buf);
}
/* ********************************************************************************* */
// #define COSINE_SIMILARITY
/*
Determines how similar are two bins
Cosine Similiarity
0 = Very differet
... (gray zone)
1 = Alike
See https://en.wikipedia.org/wiki/Cosine_similarity for more details
---
Euclidean similarity
0 = alike
...
the higher the more different
*/
float ndpi_bin_similarity(struct ndpi_bin *b1, struct ndpi_bin *b2, u_int8_t normalize_first) {
u_int8_t i;
if(
// (b1->family != b2->family) ||
(b1->num_bins != b2->num_bins))
return(-1);
if(normalize_first)
ndpi_normalize_bin(b1), ndpi_normalize_bin(b2);
#ifdef COSINE_SIMILARITY
{
u_int32_t sumxx = 0, sumxy = 0, sumyy = 0;
for(i=0; i<b1->num_bins; i++) {
u_int32_t a = ndpi_get_bin_value(b1, i);
u_int32_t b = ndpi_get_bin_value(b2, i);
sumxx += a*a, sumyy += b*b, sumxy += a*b;
}
if((sumxx == 0) || (sumyy == 0))
return(0);
else
return((float)sumxy / sqrt((float)(sumxx * sumyy)));
}
#else
{
u_int32_t sum = 0;
for(i=0; i<b1->num_bins; i++) {
u_int32_t a = ndpi_get_bin_value(b1, i);
u_int32_t b = ndpi_get_bin_value(b2, i);
u_int32_t diff = (a > b) ? (a - b) : (b - a);
if(a != b) sum += pow(diff, 2);
// printf("[a: %u][b: %u][sum: %u]\n", a, b, sum);
}
/* The lower the more similar */
return(sqrt(sum));
}
#endif
}
/* ********************************************************************************* */
#define MAX_NUM_CLUSTERS 128
/*
Clusters bins into 'num_clusters'
- (in) bins: a vection 'num_bins' long of bins to cluster
- (in) 'num_clusters': number of desired clusters 0...(num_clusters-1)
- (out) 'cluster_ids': a vector 'num_bins' long containing the id's of each clustered bin
- (out) 'centroids': an optional 'num_clusters' long vector of (centroid) bins
See
- https://en.wikipedia.org/wiki/K-means_clustering
*/
int ndpi_cluster_bins(struct ndpi_bin *bins, u_int16_t num_bins,
u_int8_t num_clusters, u_int16_t *cluster_ids,
struct ndpi_bin *centroids) {
u_int16_t i, j, max_iterations = 25, num_iterations, num_moves;
u_int8_t verbose = 0, alloc_centroids = 0;
char out_buf[256];
float *bin_score;
u_int16_t num_cluster_elems[MAX_NUM_CLUSTERS] = { 0 };
srand(time(NULL));
if(num_clusters > num_bins) num_clusters = num_bins;
if(num_clusters > MAX_NUM_CLUSTERS) num_clusters = MAX_NUM_CLUSTERS;
if(verbose)
printf("Distributing %u bins over %u clusters\n", num_bins, num_clusters);
if((bin_score = (float*)ndpi_calloc(num_bins, sizeof(float))) == NULL)
return(-2);
if(centroids == NULL) {
alloc_centroids = 1;
if((centroids = (struct ndpi_bin*)ndpi_malloc(sizeof(struct ndpi_bin)*num_clusters)) == NULL) {
ndpi_free(bin_score);
return(-2);
} else {
for(i=0; i<num_clusters; i++)
ndpi_init_bin(&centroids[i], ndpi_bin_family32 /* Use 32 bit to avoid overlaps */, bins[0].num_bins);
}
}
/* Reset the id's */
memset(cluster_ids, 0, sizeof(u_int16_t) * num_bins);
/* Randomly pick a cluster id */
for(i=0; i<num_bins; i++) {
u_int cluster_id = rand() % num_clusters;
cluster_ids[i] = cluster_id;
if(verbose)
printf("Initializing cluster %u for bin %u: %s\n",
cluster_id, i,
ndpi_print_bin(&bins[i], 0, out_buf, sizeof(out_buf)));
num_cluster_elems[cluster_id]++;
}
num_iterations = 0;
/* Now let's try to find a better arrangement */
while(num_iterations++ < max_iterations) {
/* Compute the centroids for each cluster */
memset(bin_score, 0, num_bins*sizeof(float));
if(verbose) {
printf("\nIteration %u\n", num_iterations);
for(j=0; j<num_clusters; j++)
printf("Cluster %u: %u bins\n", j, num_cluster_elems[j]);
}
for(i=0; i<num_clusters; i++)
ndpi_reset_bin(&centroids[i]);
for(i=0; i<num_bins; i++) {
for(j=0; j<bins[i].num_bins; j++) {
ndpi_inc_bin(&centroids[cluster_ids[i]], j, ndpi_get_bin_value(&bins[i], j));
}
}
for(i=0; i<num_clusters; i++) {
ndpi_normalize_bin(&centroids[i]);
if(verbose)
printf("Centroid [%u] %s\n", i,
ndpi_print_bin(&centroids[i], 0, out_buf, sizeof(out_buf)));
}
/* Now let's check if there are bins to move across clusters */
num_moves = 0;
for(i=0; i<num_bins; i++) {
u_int16_t j;
float best_similarity, current_similarity = 0;
u_int8_t cluster_id = 0;
if(verbose)
printf("Analysing bin %u [cluster: %u]\n",
i, cluster_ids[i]);
#ifdef COSINE_SIMILARITY
best_similarity = -1;
#else
best_similarity = 99999999999;
#endif
for(j=0; j<num_clusters; j++) {
float similarity;
if(centroids[j].is_empty) continue;
similarity = ndpi_bin_similarity(&bins[i], &centroids[j], 0);
if(j == cluster_ids[i])
current_similarity = similarity;
if(verbose)
printf("Bin %u / centroid %u [similarity: %f]\n", i, j, similarity);
#ifdef COSINE_SIMILARITY
if(similarity > best_similarity) {
cluster_id = j, best_similarity = similarity;
}
#else
if(similarity < best_similarity) {
cluster_id = j, best_similarity = similarity;
}
#endif
}
if((best_similarity == current_similarity) && (num_cluster_elems[cluster_ids[i]] > 1)) {
/*
In case of identical similarity let's leave things as they are
this unless this is a cluster with only one element
*/
cluster_id = cluster_ids[i];
}
bin_score[i] = best_similarity;
if(cluster_ids[i] != cluster_id) {
if(verbose)
printf("Moved bin %u from cluster %u -> %u [similarity: %f]\n",
i, cluster_ids[i], cluster_id, best_similarity);
num_cluster_elems[cluster_ids[i]]--;
num_cluster_elems[cluster_id]++;
cluster_ids[i] = cluster_id;
num_moves++;
}
}
if(num_moves == 0)
break;
if(verbose) {
for(j=0; j<num_clusters; j++)
printf("Cluster %u: %u bins\n", j, num_cluster_elems[j]);
}
#if 0
for(j=0; j<num_clusters; j++) {
if(num_cluster_elems[j] == 0) {
u_int16_t candidate;
float score;
if(verbose)
printf("\nCluster %u is empty: need to rebalance\n", j);
#ifdef COSINE_SIMILARITY
score = 99999999999;
for(i=0; i<num_bins; i++) {
if((cluster_ids[i] != j) && (bin_score[i] < score) && (num_cluster_elems[cluster_ids[i]] > 1))
score = bin_score[i], candidate = i;
}
#else
score = 0;
for(i=0; i<num_bins; i++) {
if((cluster_ids[i] != j) && (bin_score[i] > score) && (num_cluster_elems[cluster_ids[i]] > 1))
score = bin_score[i], candidate = i;
}
#endif
if(verbose)
printf("Rebalance: moving bin %u from cluster %u -> %u [similarity: %f]\n",
candidate, cluster_ids[candidate], j, score);
num_cluster_elems[cluster_ids[candidate]]--;
num_cluster_elems[j]++;
cluster_ids[candidate] = j;
}
}
#endif
} /* while(...) */
if(alloc_centroids) {
for(i=0; i<num_clusters; i++)
ndpi_free_bin(&centroids[i]);
ndpi_free(centroids);
}
ndpi_free(bin_score);
return(0);
}
/* ********************************************************************************* */
+27 -26
View File
@@ -51,6 +51,7 @@
#include <math.h>
#include "ndpi_main.h"
#include "ndpi_classify.h"
#include "ndpi_includes.h"
/** finds the minimum value between to inputs */
#ifndef min
@@ -240,9 +241,9 @@ float ndpi_parameters_bd[NUM_PARAMETERS_BD_LOGREG] = {
};
/**
* \fn void ndpi_merge_splt_arrays (const uint16_t *pkt_len, const struct timeval *pkt_time,
const uint16_t *pkt_len_twin, const struct timeval *pkt_time_twin,
struct timeval start_time, struct timeval start_time_twin,
* \fn void ndpi_merge_splt_arrays (const uint16_t *pkt_len, const pkt_timeval *pkt_time,
const uint16_t *pkt_len_twin, const pkt_timeval *pkt_time_twin,
pkt_timeval start_time, pkt_timeval start_time_twin,
uint16_t s_idx, uint16_t r_idx,
uint16_t *merged_lens, uint16_t *merged_times,
uint32_t max_num_pkt_len, uint32_t max_merged_num_pkts)
@@ -260,16 +261,16 @@ float ndpi_parameters_bd[NUM_PARAMETERS_BD_LOGREG] = {
* \return none
*/
void
ndpi_merge_splt_arrays (const uint16_t *pkt_len, const struct timeval *pkt_time,
const uint16_t *pkt_len_twin, const struct timeval *pkt_time_twin,
struct timeval start_time, struct timeval start_time_twin,
ndpi_merge_splt_arrays (const uint16_t *pkt_len, const pkt_timeval *pkt_time,
const uint16_t *pkt_len_twin, const pkt_timeval *pkt_time_twin,
pkt_timeval start_time, pkt_timeval start_time_twin,
uint16_t s_idx, uint16_t r_idx,
uint16_t *merged_lens, uint16_t *merged_times)
{
int s,r;
struct timeval ts_start = { 0, 0 }; /* initialize to avoid spurious warnings */
struct timeval tmp, tmp_r;
struct timeval start_m;
pkt_timeval ts_start = { 0, 0 }; /* initialize to avoid spurious warnings */
pkt_timeval tmp, tmp_r;
pkt_timeval start_m;
if(r_idx + s_idx == 0) {
return ;
@@ -419,9 +420,9 @@ ndpi_get_mc_rep_times (uint16_t *times, float *time_mc, uint16_t num_packets)
}
/**
* \fn float classify (const unsigned short *pkt_len, const struct timeval *pkt_time,
const unsigned short *pkt_len_twin, const struct timeval *pkt_time_twin,
struct timeval start_time, struct timeval start_time_twin, uint32_t max_num_pkt_len,
* \fn float classify (const unsigned short *pkt_len, const pkt_timeval *pkt_time,
const unsigned short *pkt_len_twin, const pkt_timeval *pkt_time_twin,
pkt_timeval start_time, pkt_timeval start_time_twin, uint32_t max_num_pkt_len,
uint16_t sp, uint16_t dp, uint32_t op, uint32_t ip, uint32_t np_o, uint32_t np_i,
uint32_t ob, uint32_t ib, uint16_t use_bd, const uint32_t *bd, const uint32_t *bd_t)
* \param pkt_len length of the packet
@@ -445,9 +446,9 @@ ndpi_get_mc_rep_times (uint16_t *times, float *time_mc, uint16_t num_packets)
* \return float score
*/
float
ndpi_classify (const unsigned short *pkt_len, const struct timeval *pkt_time,
const unsigned short *pkt_len_twin, const struct timeval *pkt_time_twin,
struct timeval start_time, struct timeval start_time_twin, uint32_t max_num_pkt_len,
ndpi_classify (const unsigned short *pkt_len, const pkt_timeval *pkt_time,
const unsigned short *pkt_len_twin, const pkt_timeval *pkt_time_twin,
pkt_timeval start_time, pkt_timeval start_time_twin, uint32_t max_num_pkt_len,
uint16_t sp, uint16_t dp, uint32_t op, uint32_t ip, uint32_t np_o, uint32_t np_i,
uint32_t ob, uint32_t ib, uint16_t use_bd, const uint32_t *bd, const uint32_t *bd_t)
{
@@ -604,8 +605,8 @@ ndpi_update_params (classifier_type_codes_t param_type, const char *param_file)
* \return 1 if equal, 0 otherwise
*/
unsigned int
ndpi_timer_eq(const struct timeval *a,
const struct timeval *b)
ndpi_timer_eq(const pkt_timeval *a,
const pkt_timeval *b)
{
if(a->tv_sec == b->tv_sec && a->tv_usec == b->tv_usec) {
return 1;
@@ -615,8 +616,8 @@ ndpi_timer_eq(const struct timeval *a,
}
unsigned int
ndpi_timer_lt(const struct timeval *a,
const struct timeval *b)
ndpi_timer_lt(const pkt_timeval *a,
const pkt_timeval *b)
{
return (a->tv_sec == b->tv_sec) ?
(a->tv_usec < b->tv_usec):(a->tv_sec < b->tv_sec);
@@ -630,9 +631,9 @@ ndpi_timer_lt(const struct timeval *a,
* \return none
*/
void
ndpi_timer_sub(const struct timeval *a,
const struct timeval *b,
struct timeval *result)
ndpi_timer_sub(const pkt_timeval *a,
const pkt_timeval *b,
pkt_timeval *result)
{
result->tv_sec = a->tv_sec - b->tv_sec;
result->tv_usec = a->tv_usec - b->tv_usec;
@@ -648,7 +649,7 @@ ndpi_timer_sub(const struct timeval *a,
* \return none
*/
void
ndpi_timer_clear(struct timeval *a)
ndpi_timer_clear(pkt_timeval *a)
{
a->tv_sec = a->tv_usec = 0;
}
@@ -659,7 +660,7 @@ ndpi_timer_clear(struct timeval *a)
* \return unsigned int - Milliseconds
*/
unsigned int
ndpi_timeval_to_milliseconds(struct timeval ts)
ndpi_timeval_to_milliseconds(pkt_timeval ts)
{
unsigned int result = ts.tv_usec / 1000 + ts.tv_sec * 1000;
return result;
@@ -671,7 +672,7 @@ ndpi_timeval_to_milliseconds(struct timeval ts)
* \return unsigned int - Milliseconds
*/
unsigned int
ndpi_timeval_to_microseconds(struct timeval ts)
ndpi_timeval_to_microseconds(pkt_timeval ts)
{
unsigned int result = ts.tv_usec + ts.tv_sec * 1000 * 1000;
return result;
@@ -680,7 +681,7 @@ ndpi_timeval_to_microseconds(struct timeval ts)
void
ndpi_log_timestamp(char *log_ts, uint32_t log_ts_len)
{
struct timeval tv;
pkt_timeval tv;
time_t nowtime;
struct tm nowtm_r;
char tmbuf[NDPI_TIMESTAMP_LEN];
+9 -5
View File
@@ -31,6 +31,7 @@
#include "ndpi_api.h"
#include "ndpi_config.h"
#include "ndpi_includes.h"
#include <time.h>
#ifndef WIN32
@@ -167,13 +168,15 @@ static int ndpi_community_id_peer_v4_is_less_than(u_int32_t ip1, u_int32_t ip2,
static int ndpi_community_id_peer_v6_is_less_than(struct ndpi_in6_addr *ip1, struct ndpi_in6_addr *ip2, u_int16_t p1, u_int16_t p2) {
int comp = memcmp(ip1, ip2, sizeof(struct ndpi_in6_addr));
return comp < 0 || (comp == 0 && p1 < p2);
}
/* **************************************************** */
static void ndpi_community_id_sha1_hash(const uint8_t *message, size_t len, u_char *hash /* 20-bytes */) {
void ndpi_string_sha1_hash(const uint8_t *message, size_t len, u_char *hash /* 20-bytes */) {
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, message, len);
SHA1Final(hash, &ctx);
@@ -185,7 +188,8 @@ static void ndpi_community_id_sha1_hash(const uint8_t *message, size_t len, u_ch
https://github.com/corelight/community-id-spec/blob/bda913f617389df07cdaa23606e11bbd318e265c/community-id.py#L285
*/
static int ndpi_community_id_finalize_and_compute_hash(u_int8_t *comm_buf, u_int16_t off, u_int8_t l4_proto,
u_int16_t src_port, u_int16_t dst_port, char *hash_buf, u_int8_t hash_buf_len) {
u_int16_t src_port, u_int16_t dst_port,
char *hash_buf, u_int8_t hash_buf_len) {
u_int8_t pad = 0;
uint32_t hash[5];
char *community_id;
@@ -209,12 +213,12 @@ static int ndpi_community_id_finalize_and_compute_hash(u_int8_t *comm_buf, u_int
}
/* Compute SHA1 */
ndpi_community_id_sha1_hash(comm_buf, off, (u_char*)hash);
ndpi_string_sha1_hash(comm_buf, off, (u_char*)hash);
/* Base64 encoding */
community_id = ndpi_base64_encode((u_int8_t*)hash, sizeof(hash));
if (community_id == NULL)
if(community_id == NULL)
return -1;
#if 0 /* Debug Info */
@@ -231,7 +235,7 @@ static int ndpi_community_id_finalize_and_compute_hash(u_int8_t *comm_buf, u_int
printf("Base64: %s\n", community_id);
#endif
if (hash_buf_len < 2 || hash_buf_len-2 < strlen(community_id)+1) {
if(hash_buf_len < 2 || hash_buf_len-2 < strlen(community_id)+1) {
ndpi_free(community_id);
return -1;
}
File diff suppressed because it is too large Load Diff
+2751 -2614
View File
File diff suppressed because it is too large Load Diff
+866 -378
View File
File diff suppressed because it is too large Load Diff
+490 -78
View File
@@ -31,6 +31,7 @@
#include "ndpi_config.h"
#include "ndpi_api.h"
#include "ndpi_includes.h"
#include "ahocorasick.h"
#include "libcache.h"
@@ -233,7 +234,7 @@ u_int8_t ndpi_ips_match(u_int32_t src, u_int32_t dst,
/* ****************************************** */
#ifdef WIN32
#if defined(WIN32) && !defined(__MINGW32__)
/* http://opensource.apple.com/source/Libc/Libc-186/string.subproj/strcasecmp.c */
/*
@@ -336,6 +337,9 @@ u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher) {
/* ***************************************************** */
/*
Some values coming from packet-tls-utils.c (wireshark)
*/
const char* ndpi_cipher2str(u_int32_t cipher) {
switch(cipher) {
case 0x000000: return("TLS_NULL_WITH_NULL_NULL");
@@ -497,7 +501,31 @@ const char* ndpi_cipher2str(u_int32_t cipher) {
case 0x0000C4: return("TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256");
case 0x0000C5: return("TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256");
case 0x0000FF: return("TLS_EMPTY_RENEGOTIATION_INFO_SCSV");
case 0x00c001: return("TLS_ECDH_ECDSA_WITH_NULL_SHA");
/* RFC 8701 */
case 0x0A0A: return("Reserved (GREASE)");
/* RFC 8446 */
case 0x1301: return("TLS_AES_128_GCM_SHA256");
case 0x1302: return("TLS_AES_256_GCM_SHA384");
case 0x1303: return("TLS_CHACHA20_POLY1305_SHA256");
case 0x1304: return("TLS_AES_128_CCM_SHA256");
case 0x1305: return("TLS_AES_128_CCM_8_SHA256");
/* RFC 8701 */
case 0x1A1A: return("Reserved (GREASE)");
case 0x2A2A: return("Reserved (GREASE)");
case 0x3A3A: return("Reserved (GREASE)");
case 0x4A4A: return("Reserved (GREASE)");
/* From RFC 7507 */
case 0x5600: return("TLS_FALLBACK_SCSV");
/* RFC 8701 */
case 0x5A5A: return("Reserved (GREASE)");
case 0x6A6A: return("Reserved (GREASE)");
case 0x7A7A: return("Reserved (GREASE)");
case 0x8A8A: return("Reserved (GREASE)");
case 0x9A9A: return("Reserved (GREASE)");
case 0xAAAA: return("Reserved (GREASE)");
case 0xBABA: return("Reserved (GREASE)");
case 0x00c001: return("TLS_ECDH_ECDSA_WITH_NULL_SHA");
case 0x00c002: return("TLS_ECDH_ECDSA_WITH_RC4_128_SHA");
case 0x00c003: return("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA");
case 0x00c004: return("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA");
@@ -556,6 +584,148 @@ const char* ndpi_cipher2str(u_int32_t cipher) {
case 0x00C039: return("TLS_ECDHE_PSK_WITH_NULL_SHA");
case 0x00C03A: return("TLS_ECDHE_PSK_WITH_NULL_SHA256");
case 0x00C03B: return("TLS_ECDHE_PSK_WITH_NULL_SHA384");
/* RFC 6209 */
case 0xC03C: return("TLS_RSA_WITH_ARIA_128_CBC_SHA256");
case 0xC03D: return("TLS_RSA_WITH_ARIA_256_CBC_SHA384");
case 0xC03E: return("TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256");
case 0xC03F: return("TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384");
case 0xC040: return("TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256");
case 0xC041: return("TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384");
case 0xC042: return("TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256");
case 0xC043: return("TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384");
case 0xC044: return("TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256");
case 0xC045: return("TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384");
case 0xC046: return("TLS_DH_anon_WITH_ARIA_128_CBC_SHA256");
case 0xC047: return("TLS_DH_anon_WITH_ARIA_256_CBC_SHA384");
case 0xC048: return("TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256");
case 0xC049: return("TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384");
case 0xC04A: return("TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256");
case 0xC04B: return("TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384");
case 0xC04C: return("TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256");
case 0xC04D: return("TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384");
case 0xC04E: return("TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256");
case 0xC04F: return("TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384");
case 0xC050: return("TLS_RSA_WITH_ARIA_128_GCM_SHA256");
case 0xC051: return("TLS_RSA_WITH_ARIA_256_GCM_SHA384");
case 0xC052: return("TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256");
case 0xC053: return("TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384");
case 0xC054: return("TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256");
case 0xC055: return("TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384");
case 0xC056: return("TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256");
case 0xC057: return("TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384");
case 0xC058: return("TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256");
case 0xC059: return("TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384");
case 0xC05A: return("TLS_DH_anon_WITH_ARIA_128_GCM_SHA256");
case 0xC05B: return("TLS_DH_anon_WITH_ARIA_256_GCM_SHA384");
case 0xC05C: return("TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256");
case 0xC05D: return("TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384");
case 0xC05E: return("TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256");
case 0xC05F: return("TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384");
case 0xC060: return("TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256");
case 0xC061: return("TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384");
case 0xC062: return("TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256");
case 0xC063: return("TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384");
case 0xC064: return("TLS_PSK_WITH_ARIA_128_CBC_SHA256");
case 0xC065: return("TLS_PSK_WITH_ARIA_256_CBC_SHA384");
case 0xC066: return("TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256");
case 0xC067: return("TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384");
case 0xC068: return("TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256");
case 0xC069: return("TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384");
case 0xC06A: return("TLS_PSK_WITH_ARIA_128_GCM_SHA256");
case 0xC06B: return("TLS_PSK_WITH_ARIA_256_GCM_SHA384");
case 0xC06C: return("TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256");
case 0xC06D: return("TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384");
case 0xC06E: return("TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256");
case 0xC06F: return("TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384");
case 0xC070: return("TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256");
case 0xC071: return("TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384");
/* RFC 6367 */
case 0xC072: return("TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC073: return("TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC074: return("TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC075: return("TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC076: return("TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC077: return("TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC078: return("TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC079: return("TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC07A: return("TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC07B: return("TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC07C: return("TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC07D: return("TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC07E: return("TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC07F: return("TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC080: return("TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC081: return("TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC082: return("TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC083: return("TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC084: return("TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC085: return("TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC086: return("TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC087: return("TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC088: return("TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC089: return("TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC08A: return("TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC08B: return("TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC08C: return("TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC08D: return("TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC08E: return("TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC08F: return("TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC090: return("TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC091: return("TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC092: return("TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256");
case 0xC093: return("TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384");
case 0xC094: return("TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC095: return("TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC096: return("TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC097: return("TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC098: return("TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC099: return("TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384");
case 0xC09A: return("TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256");
case 0xC09B: return("TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384");
/* RFC 6655 */
case 0xC09C: return("TLS_RSA_WITH_AES_128_CCM");
case 0xC09D: return("TLS_RSA_WITH_AES_256_CCM");
case 0xC09E: return("TLS_DHE_RSA_WITH_AES_128_CCM");
case 0xC09F: return("TLS_DHE_RSA_WITH_AES_256_CCM");
case 0xC0A0: return("TLS_RSA_WITH_AES_128_CCM_8");
case 0xC0A1: return("TLS_RSA_WITH_AES_256_CCM_8");
case 0xC0A2: return("TLS_DHE_RSA_WITH_AES_128_CCM_8");
case 0xC0A3: return("TLS_DHE_RSA_WITH_AES_256_CCM_8");
case 0xC0A4: return("TLS_PSK_WITH_AES_128_CCM");
case 0xC0A5: return("TLS_PSK_WITH_AES_256_CCM");
case 0xC0A6: return("TLS_DHE_PSK_WITH_AES_128_CCM");
case 0xC0A7: return("TLS_DHE_PSK_WITH_AES_256_CCM");
case 0xC0A8: return("TLS_PSK_WITH_AES_128_CCM_8");
case 0xC0A9: return("TLS_PSK_WITH_AES_256_CCM_8");
case 0xC0AA: return("TLS_PSK_DHE_WITH_AES_128_CCM_8");
case 0xC0AB: return("TLS_PSK_DHE_WITH_AES_256_CCM_8");
/* RFC 7251 */
case 0xC0AC: return("TLS_ECDHE_ECDSA_WITH_AES_128_CCM");
case 0xC0AD: return("TLS_ECDHE_ECDSA_WITH_AES_256_CCM");
case 0xC0AE: return("TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8");
case 0xC0AF: return("TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8");
/* RFC 8492 */
case 0xC0B0: return("TLS_ECCPWD_WITH_AES_128_GCM_SHA256");
case 0xC0B1: return("TLS_ECCPWD_WITH_AES_256_GCM_SHA384");
case 0xC0B2: return("TLS_ECCPWD_WITH_AES_128_CCM_SHA256");
case 0xC0B3: return("TLS_ECCPWD_WITH_AES_256_CCM_SHA384");
/* draft-camwinget-tls-ts13-macciphersuites */
case 0xC0B4: return("TLS_SHA256_SHA256");
case 0xC0B5: return("TLS_SHA384_SHA384");
/* https://www.ietf.org/archive/id/draft-cragie-tls-ecjpake-01.txt */
case 0xC0FF: return("TLS_ECJPAKE_WITH_AES_128_CCM_8");
/* draft-smyshlyaev-tls12-gost-suites */
case 0xC100: return("TLS_GOSTR341112_256_WITH_KUZNYECHIK_CTR_OMAC");
case 0xC101: return("TLS_GOSTR341112_256_WITH_MAGMA_CTR_OMAC");
case 0xC102: return("TLS_GOSTR341112_256_WITH_28147_CNT_IMIT");
/* draft-smyshlyaev-tls13-gost-suites */
case 0xC103: return("TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L");
case 0xC104: return("TLS_GOSTR341112_256_WITH_MAGMA_MGM_L");
case 0xC105: return("TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S");
case 0xC106: return("TLS_GOSTR341112_256_WITH_MAGMA_MGM_S");
/* RFC 8701 */
case 0xCACA: return("Reserved (GREASE)");
case 0x00CC13: return("TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256");
case 0x00CC14: return("TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256");
case 0x00CC15: return("TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256");
@@ -594,11 +764,6 @@ const char* ndpi_cipher2str(u_int32_t cipher) {
case 0x060040: return("SSL2_DES_64_CBC_WITH_MD5");
case 0x0700c0: return("SSL2_DES_192_EDE3_CBC_WITH_MD5");
case 0x080080: return("SSL2_RC4_64_WITH_MD5");
case 0x001301: return("TLS_AES_128_GCM_SHA256");
case 0x001302: return("TLS_AES_256_GCM_SHA384");
case 0x001303: return("TLS_CHACHA20_POLY1305_SHA256");
case 0x001304: return("TLS_AES_128_CCM_SHA256");
case 0x001305: return("TLS_AES_128_CCM_8_SHA256");
default:
{
@@ -714,10 +879,11 @@ int ndpi_has_human_readeable_string(struct ndpi_detection_module_struct *ndpi_st
/* ********************************** */
char* ndpi_ssl_version2str(u_int16_t version, u_int8_t *unknown_tls_version) {
static char v[12];
char* ndpi_ssl_version2str(struct ndpi_flow_struct *flow,
u_int16_t version, u_int8_t *unknown_tls_version) {
*unknown_tls_version = 0;
if(unknown_tls_version)
*unknown_tls_version = 0;
switch(version) {
case 0x0300: return("SSLv3");
@@ -728,15 +894,37 @@ char* ndpi_ssl_version2str(u_int16_t version, u_int8_t *unknown_tls_version) {
case 0XFB1A: return("TLSv1.3 (Fizz)"); /* https://engineering.fb.com/security/fizz/ */
case 0XFEFF: return("DTLSv1.0");
case 0XFEFD: return("DTLSv1.2");
case 0x0A0A:
case 0x1A1A:
case 0x2A2A:
case 0x3A3A:
case 0x4A4A:
case 0x5A5A:
case 0x6A6A:
case 0x7A7A:
case 0x8A8A:
case 0x9A9A:
case 0xAAAA:
case 0xBABA:
case 0xCACA:
case 0xDADA:
case 0xEAEA:
case 0xFAFA: return("GREASE");
}
if((version >= 0x7f00) && (version <= 0x7fff))
return("TLSv1.3 (draft)");
*unknown_tls_version = 1;
snprintf(v, sizeof(v), "TLS (%04X)", version);
if(unknown_tls_version)
*unknown_tls_version = 1;
return(v);
if(flow != NULL) {
snprintf(flow->protos.stun_ssl.ssl.ssl_version_str,
sizeof(flow->protos.stun_ssl.ssl.ssl_version_str), "TLS (%04X)", version);
return(flow->protos.stun_ssl.ssl.ssl_version_str);
} else
return("");
}
/* ***************************************************** */
@@ -854,8 +1042,9 @@ u_char* ndpi_base64_decode(const u_char *src, size_t len, size_t *out_len) {
/* ********************************** */
char* ndpi_base64_encode(unsigned char const* bytes_to_encode, ssize_t in_len) {
ssize_t len = 0, ret_size;
/* NOTE: caller MUST free returned pointer */
char* ndpi_base64_encode(unsigned char const* bytes_to_encode, size_t in_len) {
size_t len = 0, ret_size;
char *ret;
int i = 0;
unsigned char char_array_3[3];
@@ -901,64 +1090,45 @@ char* ndpi_base64_encode(unsigned char const* bytes_to_encode, ssize_t in_len) {
return ret;
}
/* ********************************** */
void ndpi_serialize_risk(ndpi_serializer *serializer,
struct ndpi_flow_struct *flow) {
if(flow->risk != 0) {
u_int32_t i;
ndpi_serialize_start_of_block(serializer, "flow_risk");
for(i = 0; i < NDPI_MAX_RISK; i++) {
ndpi_risk_enum r = (ndpi_risk_enum)i;
if(NDPI_ISSET_BIT(flow->risk, r))
ndpi_serialize_uint32_string(serializer, i, ndpi_risk2str(r));
}
ndpi_serialize_end_of_block(serializer);
}
}
/* ********************************** */
/* ********************************** */
int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t ip_version,
u_int8_t l4_protocol, u_int16_t vlan_id,
u_int32_t src_v4, u_int32_t dst_v4,
struct ndpi_in6_addr *src_v6, struct ndpi_in6_addr *dst_v6,
u_int16_t src_port, u_int16_t dst_port,
ndpi_protocol l7_protocol,
ndpi_serializer *serializer) {
char buf[64], src_name[32], dst_name[32];
if(ndpi_init_serializer(serializer, ndpi_serialization_format_json) == -1)
return(-1);
if(ip_version == 4) {
inet_ntop(AF_INET, &src_v4, src_name, sizeof(src_name));
inet_ntop(AF_INET, &dst_v4, dst_name, sizeof(dst_name));
} else {
inet_ntop(AF_INET6, src_v6, src_name, sizeof(src_name));
inet_ntop(AF_INET6, dst_v6, dst_name, sizeof(dst_name));
/* For consistency across platforms replace :0: with :: */
ndpi_patchIPv6Address(src_name), ndpi_patchIPv6Address(dst_name);
}
ndpi_serialize_string_string(serializer, "src_ip", src_name);
ndpi_serialize_string_string(serializer, "dest_ip", dst_name);
if(src_port) ndpi_serialize_string_uint32(serializer, "src_port", src_port);
if(dst_port) ndpi_serialize_string_uint32(serializer, "dst_port", dst_port);
switch(l4_protocol) {
case IPPROTO_TCP:
ndpi_serialize_string_string(serializer, "proto", "TCP");
break;
case IPPROTO_UDP:
ndpi_serialize_string_string(serializer, "proto", "UDP");
break;
case IPPROTO_ICMP:
ndpi_serialize_string_string(serializer, "proto", "ICMP");
break;
default:
ndpi_serialize_string_uint32(serializer, "proto", l4_protocol);
break;
}
/* NOTE: serializer must have been already initialized */
int ndpi_dpi2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
ndpi_protocol l7_protocol,
ndpi_serializer *serializer) {
char buf[64];
if(flow == NULL) return(-1);
ndpi_serialize_start_of_block(serializer, "ndpi");
ndpi_serialize_risk(serializer, flow);
ndpi_serialize_string_string(serializer, "proto", ndpi_protocol2name(ndpi_struct, l7_protocol, buf, sizeof(buf)));
if(l7_protocol.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED)
ndpi_serialize_string_string(serializer, "category", ndpi_category_get_name(ndpi_struct, l7_protocol.category));
ndpi_serialize_end_of_block(serializer);
if(flow == NULL) return(0);
switch(l7_protocol.master_protocol ? l7_protocol.master_protocol : l7_protocol.app_protocol) {
case NDPI_PROTOCOL_DHCP:
ndpi_serialize_start_of_block(serializer, "dhcp");
@@ -1003,7 +1173,7 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
case NDPI_PROTOCOL_MDNS:
ndpi_serialize_start_of_block(serializer, "mdns");
ndpi_serialize_string_string(serializer, "answer", flow->protos.mdns.answer);
ndpi_serialize_string_string(serializer, "answer", (const char*)flow->host_server_name);
ndpi_serialize_end_of_block(serializer);
break;
@@ -1032,10 +1202,19 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_serialize_start_of_block(serializer, "http");
if(flow->host_server_name[0] != '\0')
ndpi_serialize_string_string(serializer, "hostname", (const char*)flow->host_server_name);
ndpi_serialize_string_string(serializer, "url", flow->http.url);
ndpi_serialize_string_uint32(serializer, "code", flow->http.response_status_code);
ndpi_serialize_string_string(serializer, "content_type", flow->http.content_type);
ndpi_serialize_string_string(serializer, "user_agent", flow->http.user_agent);
if(flow->http.url != NULL){
ndpi_serialize_string_string(serializer, "url", flow->http.url);
ndpi_serialize_string_uint32(serializer, "code", flow->http.response_status_code);
ndpi_serialize_string_string(serializer, "content_type", flow->http.content_type);
ndpi_serialize_string_string(serializer, "user_agent", flow->http.user_agent);
}
ndpi_serialize_end_of_block(serializer);
break;
case NDPI_PROTOCOL_QUIC:
ndpi_serialize_start_of_block(serializer, "quic");
if(flow->host_server_name[0] != '\0')
ndpi_serialize_string_string(serializer, "hostname", (const char*)flow->host_server_name);
ndpi_serialize_end_of_block(serializer);
break;
@@ -1083,7 +1262,7 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
struct tm a, b, *before = NULL, *after = NULL;
u_int i, off;
u_int8_t unknown_tls_version;
char *version = ndpi_ssl_version2str(flow->protos.stun_ssl.ssl.ssl_version, &unknown_tls_version);
char *version = ndpi_ssl_version2str(flow, flow->protos.stun_ssl.ssl.ssl_version, &unknown_tls_version);
if(flow->protos.stun_ssl.ssl.notBefore)
before = gmtime_r((const time_t *)&flow->protos.stun_ssl.ssl.notBefore, &a);
@@ -1097,15 +1276,14 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
flow->protos.stun_ssl.ssl.client_requested_server_name);
if(flow->protos.stun_ssl.ssl.server_names)
ndpi_serialize_string_string(serializer, "server_names", flow->protos.stun_ssl.ssl.server_names);
ndpi_serialize_string_string(serializer, "issuer", flow->protos.stun_ssl.ssl.server_organization);
if(before) {
strftime(notBefore, sizeof(notBefore), "%F %T", before);
strftime(notBefore, sizeof(notBefore), "%Y-%m-%d %H:%M:%S", before);
ndpi_serialize_string_string(serializer, "notbefore", notBefore);
}
if(after) {
strftime(notAfter, sizeof(notAfter), "%F %T", after);
strftime(notAfter, sizeof(notAfter), "%Y-%m-%d %H:%M:%S", after);
ndpi_serialize_string_string(serializer, "notafter", notAfter);
}
ndpi_serialize_string_string(serializer, "ja3", flow->protos.stun_ssl.ssl.ja3_client);
@@ -1113,6 +1291,18 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_serialize_string_uint32(serializer, "unsafe_cipher", flow->protos.stun_ssl.ssl.server_unsafe_cipher);
ndpi_serialize_string_string(serializer, "cipher", ndpi_cipher2str(flow->protos.stun_ssl.ssl.server_cipher));
if(flow->protos.stun_ssl.ssl.issuerDN)
ndpi_serialize_string_string(serializer, "issuerDN", flow->protos.stun_ssl.ssl.issuerDN);
if(flow->protos.stun_ssl.ssl.subjectDN)
ndpi_serialize_string_string(serializer, "issuerDN", flow->protos.stun_ssl.ssl.subjectDN);
if(flow->protos.stun_ssl.ssl.alpn)
ndpi_serialize_string_string(serializer, "alpn", flow->protos.stun_ssl.ssl.alpn);
if(flow->protos.stun_ssl.ssl.tls_supported_versions)
ndpi_serialize_string_string(serializer, "tls_supported_versions", flow->protos.stun_ssl.ssl.tls_supported_versions);
if(flow->l4.tcp.tls.sha1_certificate_fingerprint[0] != '\0') {
for(i=0, off=0; i<20; i++) {
int rc = snprintf(&buf[off], sizeof(buf)-off,"%s%02X", (i > 0) ? ":" : "",
@@ -1135,6 +1325,59 @@ int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
/* ********************************** */
/* NOTE: serializer is initialized by the function */
int ndpi_flow2json(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int8_t ip_version,
u_int8_t l4_protocol, u_int16_t vlan_id,
u_int32_t src_v4, u_int32_t dst_v4,
struct ndpi_in6_addr *src_v6, struct ndpi_in6_addr *dst_v6,
u_int16_t src_port, u_int16_t dst_port,
ndpi_protocol l7_protocol,
ndpi_serializer *serializer) {
char src_name[32], dst_name[32];
if(ndpi_init_serializer(serializer, ndpi_serialization_format_json) == -1)
return(-1);
if(ip_version == 4) {
inet_ntop(AF_INET, &src_v4, src_name, sizeof(src_name));
inet_ntop(AF_INET, &dst_v4, dst_name, sizeof(dst_name));
} else {
inet_ntop(AF_INET6, src_v6, src_name, sizeof(src_name));
inet_ntop(AF_INET6, dst_v6, dst_name, sizeof(dst_name));
/* For consistency across platforms replace :0: with :: */
ndpi_patchIPv6Address(src_name), ndpi_patchIPv6Address(dst_name);
}
ndpi_serialize_string_string(serializer, "src_ip", src_name);
ndpi_serialize_string_string(serializer, "dest_ip", dst_name);
if(src_port) ndpi_serialize_string_uint32(serializer, "src_port", src_port);
if(dst_port) ndpi_serialize_string_uint32(serializer, "dst_port", dst_port);
switch(l4_protocol) {
case IPPROTO_TCP:
ndpi_serialize_string_string(serializer, "proto", "TCP");
break;
case IPPROTO_UDP:
ndpi_serialize_string_string(serializer, "proto", "UDP");
break;
case IPPROTO_ICMP:
ndpi_serialize_string_string(serializer, "proto", "ICMP");
break;
default:
ndpi_serialize_string_uint32(serializer, "proto", l4_protocol);
break;
}
return(ndpi_dpi2json(ndpi_struct, flow, l7_protocol, serializer));
}
/* ********************************** */
const char* ndpi_tunnel2str(ndpi_packet_tunnel tt) {
switch(tt) {
case ndpi_no_tunnel:
@@ -1319,9 +1562,9 @@ static int ndpi_is_rce_injection(char* query) {
/* ********************************** */
ndpi_url_risk ndpi_validate_url(char *url) {
ndpi_risk_enum ndpi_validate_url(char *url) {
char *orig_str = NULL, *str = NULL, *question_mark = strchr(url, '?');
ndpi_url_risk rc = ndpi_url_no_problem;
ndpi_risk_enum rc = NDPI_NO_RISK;
if(question_mark) {
char *tmp;
@@ -1351,12 +1594,12 @@ ndpi_url_risk ndpi_validate_url(char *url) {
/* Valid string */
if(ndpi_is_xss_injection(decoded))
rc = ndpi_url_possible_xss;
rc = NDPI_URL_POSSIBLE_XSS;
else if(ndpi_is_sql_injection(decoded))
rc = ndpi_url_possible_sql_injection;
rc = NDPI_URL_POSSIBLE_SQL_INJECTION;
#ifdef HAVE_PCRE
else if(ndpi_is_rce_injection(decoded))
rc = ndpi_url_possible_rce_injection;
rc = NDPI_URL_POSSIBLE_RCE_INJECTION;
#endif
#ifdef URL_CHECK_DEBUG
@@ -1366,7 +1609,7 @@ ndpi_url_risk ndpi_validate_url(char *url) {
ndpi_free(decoded);
if(rc != ndpi_url_no_problem)
if(rc != NDPI_NO_RISK)
break;
}
@@ -1376,6 +1619,15 @@ ndpi_url_risk ndpi_validate_url(char *url) {
validate_rc:
if(orig_str) ndpi_free(orig_str);
if(rc == NDPI_NO_RISK) {
/* Let's do an extra check */
if(strstr(url, "..")) {
/* 127.0.0.1/msadc/..%255c../..%255c../..%255c../winnt/system32/cmd.exe */
rc = NDPI_HTTP_SUSPICIOUS_URL;
}
}
return(rc);
}
@@ -1390,3 +1642,163 @@ u_int8_t ndpi_is_protocol_detected(struct ndpi_detection_module_struct *ndpi_str
else
return(0);
}
/* ******************************************************************** */
const char* ndpi_risk2str(ndpi_risk_enum risk) {
static char buf[16];
switch(risk) {
case NDPI_URL_POSSIBLE_XSS:
return("XSS attack");
case NDPI_URL_POSSIBLE_SQL_INJECTION:
return("SQL injection");
case NDPI_URL_POSSIBLE_RCE_INJECTION:
return("RCE injection");
case NDPI_BINARY_APPLICATION_TRANSFER:
return("Binary application transfer");
case NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT:
return("Known protocol on non standard port");
case NDPI_TLS_SELFSIGNED_CERTIFICATE:
return("Self-signed Certificate");
case NDPI_TLS_OBSOLETE_VERSION:
return("Obsolete TLS version (< 1.1)");
case NDPI_TLS_WEAK_CIPHER:
return("Weak TLS cipher");
case NDPI_TLS_CERTIFICATE_EXPIRED:
return("TLS Expired Certificate");
case NDPI_TLS_CERTIFICATE_MISMATCH:
return("TLS Certificate Mismatch");
case NDPI_HTTP_SUSPICIOUS_USER_AGENT:
return("HTTP Suspicious User-Agent");
case NDPI_HTTP_NUMERIC_IP_HOST:
return("HTTP Numeric IP Address");
case NDPI_HTTP_SUSPICIOUS_URL:
return("HTTP Suspicious URL");
case NDPI_HTTP_SUSPICIOUS_HEADER:
return("HTTP Suspicious Header");
case NDPI_TLS_NOT_CARRYING_HTTPS:
return("TLS (probably) not carrying HTTPS");
case NDPI_SUSPICIOUS_DGA_DOMAIN:
return("Suspicious DGA domain name");
case NDPI_MALFORMED_PACKET:
return("Malformed packet");
case NDPI_SSH_OBSOLETE_CLIENT_VERSION_OR_CIPHER:
return("SSH Obsolete Client Version/Cipher");
case NDPI_SSH_OBSOLETE_SERVER_VERSION_OR_CIPHER:
return("SSH Obsolete Server Version/Cipher");
case NDPI_SMB_INSECURE_VERSION:
return("SMB Insecure Version");
case NDPI_TLS_SUSPICIOUS_ESNI_USAGE:
return("TLS Suspicious ESNI Usage");
case NDPI_UNSAFE_PROTOCOL:
return("Unsafe Protocol");
case NDPI_DNS_SUSPICIOUS_TRAFFIC:
return("Suspicious DNS traffic"); /* Exfiltration ? */
case NDPI_TLS_MISSING_SNI:
return("SNI TLS extension was missing");
default:
snprintf(buf, sizeof(buf), "%d", (int)risk);
return(buf);
}
}
/* ******************************************************************** */
const char* ndpi_http_method2str(ndpi_http_method m) {
switch(m) {
case NDPI_HTTP_METHOD_UNKNOWN: break;
case NDPI_HTTP_METHOD_OPTIONS: return("OPTIONS");
case NDPI_HTTP_METHOD_GET: return("GET");
case NDPI_HTTP_METHOD_HEAD: return("HEAD");
case NDPI_HTTP_METHOD_PATCH: return("PATCH");
case NDPI_HTTP_METHOD_POST: return("POST");
case NDPI_HTTP_METHOD_PUT: return("PUT");
case NDPI_HTTP_METHOD_DELETE: return("DELETE");
case NDPI_HTTP_METHOD_TRACE: return("TRACE");
case NDPI_HTTP_METHOD_CONNECT: return("CONNECT");
}
return("Unknown HTTP method");
}
/* ******************************************************************** */
ndpi_http_method ndpi_http_str2method(const char* method, ssize_t method_len) {
if(!method || method_len < 3)
return(NDPI_HTTP_METHOD_UNKNOWN);
switch(method[0]) {
case 'O': return(NDPI_HTTP_METHOD_OPTIONS);
case 'G': return(NDPI_HTTP_METHOD_GET);
case 'H': return(NDPI_HTTP_METHOD_HEAD);
case 'P':
switch(method[1]) {
case 'A':return(NDPI_HTTP_METHOD_PATCH);
case 'O':return(NDPI_HTTP_METHOD_POST);
case 'U':return(NDPI_HTTP_METHOD_PUT);
}
break;
case 'D': return(NDPI_HTTP_METHOD_DELETE);
case 'T': return(NDPI_HTTP_METHOD_TRACE);
case 'C': return(NDPI_HTTP_METHOD_CONNECT);
}
return(NDPI_HTTP_METHOD_UNKNOWN);
}
/* ******************************************************************** */
#define ROR64(x,r) (((x)>>(r))|((x)<<(64-(r))))
/*
'in_16_bytes_long` points to some 16 byte memory data to be hashed;
two independent 64-bit linear congruential generators are applied
results are mixed, scrambled and cast to 32-bit
*/
u_int32_t ndpi_quick_16_byte_hash(u_int8_t *in_16_bytes_long) {
u_int64_t a = *(u_int64_t*)(in_16_bytes_long + 0);
u_int64_t c = *(u_int64_t*)(in_16_bytes_long + 8);
// multipliers are taken from sprng.org, addends are prime
a = a * 0x2c6fe96ee78b6955 + 0x9af64480a3486659;
c = c * 0x369dea0f31a53f85 + 0xd0c6225445b76b5b;
// mix results
a += c;
// final scramble
a ^= ROR64(a, 13) ^ ROR64(a, 7);
// down-casting, also taking advantage of upper half
a ^= a >> 32;
return((u_int32_t)a);
}
+1 -1
View File
@@ -63,7 +63,7 @@ static void set_ajp_detected(struct ndpi_detection_module_struct *ndpi_struct,
/* If no custom protocol has been detected */
/* if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) */
ndpi_int_reset_protocol(flow);
ndpi_set_detected_protocol(ndpi_struct, flow, flow->guessed_host_protocol_id, NDPI_PROTOCOL_AJP);
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_AJP, flow->guessed_host_protocol_id);
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ void ndpi_search_ayiya(struct ndpi_detection_module_struct *ndpi_struct, struct
u_int32_t epoch = ntohl(a->epoch), now;
u_int32_t fiveyears = 86400 * 365 * 5;
now = flow->packet.tick_timestamp;
now = flow->packet.current_time_ms;
if((epoch >= (now - fiveyears)) && (epoch <= (now+86400 /* 1 day */))) {
NDPI_LOG_INFO(ndpi_struct, "found AYIYA\n");
-126
View File
@@ -1,126 +0,0 @@
/*
* battlefield.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_BATTLEFIELD
#include "ndpi_api.h"
static void ndpi_int_battlefield_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BATTLEFIELD, NDPI_PROTOCOL_UNKNOWN);
if (src != NULL) {
src->battlefield_ts = packet->tick_timestamp;
}
if (dst != NULL) {
dst->battlefield_ts = packet->tick_timestamp;
}
}
void ndpi_search_battlefield(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_BATTLEFIELD) {
if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->battlefield_ts) < ndpi_struct->battlefield_timeout)) {
NDPI_LOG_DBG2(ndpi_struct,
"battlefield : save src connection packet detected\n");
src->battlefield_ts = packet->tick_timestamp;
} else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->battlefield_ts) < ndpi_struct->battlefield_timeout)) {
NDPI_LOG_DBG2(ndpi_struct,
"battlefield : save dst connection packet detected\n");
dst->battlefield_ts = packet->tick_timestamp;
}
return;
}
if (NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_BATTLEFIELD)) {
if (flow->l4.udp.battlefield_stage == 0 || flow->l4.udp.battlefield_stage == 1 + packet->packet_direction) {
if (packet->payload_packet_len > 8 && get_u_int16_t(packet->payload, 0) == htons(0xfefd)) {
flow->l4.udp.battlefield_msg_id = get_u_int32_t(packet->payload, 2);
flow->l4.udp.battlefield_stage = 1 + packet->packet_direction;
return;
}
} else if (flow->l4.udp.battlefield_stage == 2 - packet->packet_direction) {
if (packet->payload_packet_len > 8 && get_u_int32_t(packet->payload, 0) == flow->l4.udp.battlefield_msg_id) {
NDPI_LOG_INFO(ndpi_struct, "found Battlefield message and reply detected\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return;
}
}
}
if (flow->l4.udp.battlefield_stage == 0) {
if (packet->payload_packet_len == 46 && packet->payload[2] == 0 && packet->payload[4] == 0
&& get_u_int32_t(packet->payload, 7) == htonl(0x98001100)) {
flow->l4.udp.battlefield_stage = 3 + packet->packet_direction;
return;
}
} else if (flow->l4.udp.battlefield_stage == 4 - packet->packet_direction) {
if (packet->payload_packet_len == 7
&& (packet->payload[0] == 0x02 || packet->payload[packet->payload_packet_len - 1] == 0xe0)) {
NDPI_LOG_INFO(ndpi_struct, "found Battlefield message and reply detected\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return;
}
}
if (packet->payload_packet_len == 18 && memcmp(&packet->payload[5], "battlefield2\x00", 13) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found Battlefield 2 hello packet detected\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return;
} else if (packet->payload_packet_len > 10 &&
(memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\x50\xb9\x10\x11", 10) == 0
|| memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\x30\xb9\x10\x11", 10) == 0
|| memcmp(packet->payload, "\x11\x20\x00\x01\x00\x00\xa0\x98\x00\x11", 10) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found Battlefield safe pattern detected\n");
ndpi_int_battlefield_add_connection(ndpi_struct, flow);
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_battlefield_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("BattleField", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_BATTLEFIELD,
ndpi_search_battlefield,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+17 -23
View File
@@ -43,7 +43,7 @@ struct ndpi_utp_hdr {
u_int16_t sequence_nr, ack_nr;
};
static u_int8_t is_utp_pkt(const u_int8_t *payload, u_int payload_len) {
static u_int8_t is_utpv1_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);
@@ -52,6 +52,9 @@ static u_int8_t is_utp_pkt(const u_int8_t *payload, u_int payload_len) {
if(h->next_extension > 2) return(0);
if(ntohl(h->window_size) > 65565) return(0);
if((h->window_size == 0) && (payload_len != sizeof(struct ndpi_utp_hdr)))
return(0);
return(1);
}
@@ -62,7 +65,7 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
{
if(check_hash) {
const char *bt_hash = 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);
@@ -72,7 +75,8 @@ static void ndpi_add_connection_as_bittorrent(struct ndpi_detection_module_struc
} else
bt_hash = (const char*)&flow->packet.payload[28];
if(bt_hash) memcpy(flow->protos.bittorrent.hash, bt_hash, 20);
if(bt_hash && (flow->packet.payload_packet_len >= (20 + (bt_hash-(const char*)flow->packet.payload))))
memcpy(flow->protos.bittorrent.hash, bt_hash, 20);
}
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_BITTORRENT, NDPI_PROTOCOL_UNKNOWN);
@@ -385,10 +389,8 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
/* This is broadcast */
if(packet->iph) {
if((packet->iph->saddr == 0xFFFFFFFF) || (packet->iph->daddr == 0xFFFFFFFF))
goto exclude_bt;
if(packet->udp) {
u_int16_t sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
@@ -413,9 +415,11 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
char *bt_search = "BT-SEARCH * HTTP/1.1\r\n";
if((ntohs(packet->udp->source) < 1024)
|| (ntohs(packet->udp->dest) < 1024) /* High ports only */)
|| (ntohs(packet->udp->dest) < 1024) /* High ports only */) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
/*
Check for uTP http://www.bittorrent.org/beps/bep_0029.html
@@ -432,14 +436,10 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
u_int8_t v0_extension = packet->payload[17];
u_int8_t v0_flags = packet->payload[18];
/* Check if this is protocol v1 */
u_int8_t v1_version = packet->payload[0];
u_int8_t v1_extension = packet->payload[1];
u_int32_t v1_window_size = *((u_int32_t*)&packet->payload[12]);
if(is_utp_pkt(packet->payload, packet->payload_packet_len))
if(is_utpv1_pkt(packet->payload, packet->payload_packet_len)) {
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found;
else if((packet->payload[0]== 0x60)
} else if((packet->payload[0]== 0x60)
&& (packet->payload[1]== 0x0)
&& (packet->payload[2]== 0x0)
&& (packet->payload[3]== 0x0)
@@ -447,14 +447,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
/* Heuristic */
bt_proto = ndpi_strnstr((const char *)&packet->payload[20], "BitTorrent protocol", packet->payload_packet_len-20);
goto bittorrent_found;
/* CSGO/DOTA conflict */
} else if(flow->packet_counter > 8 && ((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;
/* CSGO/DOTA conflict */
} 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;
@@ -471,7 +464,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
flow->bittorrent_stage++;
if(flow->bittorrent_stage < 10) {
if(flow->bittorrent_stage < 5) {
/* We have detected bittorrent but we need to wait until we get a hash */
if(packet->payload_packet_len > 19 /* min size */) {
@@ -496,6 +489,7 @@ void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, st
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
}
+4 -2
View File
@@ -23,12 +23,13 @@
*/
#include "ndpi_api.h"
#if 0
#ifndef NDPI_NO_STD_INC
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <strings.h>
/*
@@ -43,6 +44,7 @@ typedef unsigned long long int u_int64_t;
#include <arpa/inet.h>
#endif
#endif
#endif
#include "btlib.h"
+5 -3
View File
@@ -66,10 +66,12 @@ static void ndpi_search_setup_capwap(struct ndpi_detection_module_struct *ndpi_s
else
offset = 15, to_add = 17;
msg_len = ntohs(*(u_int16_t*)&packet->payload[offset]);
if (packet->payload_packet_len >= offset + sizeof(u_int16_t)) {
msg_len = ntohs(*(u_int16_t*)&packet->payload[offset]);
if((msg_len+to_add) == packet->payload_packet_len)
goto capwap_found;
if((msg_len+to_add) == packet->payload_packet_len)
goto capwap_found;
}
}
if(
+60 -24
View File
@@ -1,6 +1,22 @@
/*
* ciscovpn.c
* Copyright (C) 2013 by Remy Mudingay <mudingay@ill.fr>
*
* Copyright (C) 2013-20 - 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/>.
*
* Dissector developed by Remy Mudingay <mudingay@ill.fr>
*
*/
@@ -10,12 +26,15 @@
#include "ndpi_api.h"
/* ****************************************************************** */
static void ndpi_int_ciscovpn_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CISCOVPN, NDPI_PROTOCOL_UNKNOWN);
}
/* ****************************************************************** */
void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
@@ -29,6 +48,7 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
tsport = ntohs(packet->tcp->source), tdport = ntohs(packet->tcp->dest);
NDPI_LOG_DBG2(ndpi_struct, "calculated CISCOVPN over tcp ports\n");
}
if(packet->udp != NULL) {
usport = ntohs(packet->udp->source), udport = ntohs(packet->udp->dest);
NDPI_LOG_DBG2(ndpi_struct, "calculated CISCOVPN over udp ports\n");
@@ -36,26 +56,26 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
if((tdport == 10000 && tsport == 10000) ||
((tsport == 443 || tdport == 443) &&
(packet->payload_packet_len >= 4) &&
(packet->payload[0] == 0x17 &&
packet->payload[1] == 0x01 &&
packet->payload[2] == 0x00 &&
packet->payload[3] == 0x00)
)
)
{
/* This is a good query 17010000*/
NDPI_LOG_INFO(ndpi_struct, "found CISCOVPN\n");
ndpi_int_ciscovpn_add_connection(ndpi_struct, flow);
return;
}
) {
/* This is a good query 17010000*/
NDPI_LOG_INFO(ndpi_struct, "found CISCOVPN\n");
ndpi_int_ciscovpn_add_connection(ndpi_struct, flow);
return;
}
else if(((tsport == 443 || tdport == 443) ||
(tsport == 80 || tdport == 80)) &&
(tsport == 80 || tdport == 80)) &&
(packet->payload_packet_len >= 5) &&
((packet->payload[0] == 0x17 &&
packet->payload[1] == 0x03 &&
packet->payload[2] == 0x03 &&
packet->payload[3] == 0x00 &&
packet->payload[4] == 0x3A)))
packet->payload[1] == 0x03 &&
packet->payload[2] == 0x03 &&
packet->payload[3] == 0x00 &&
packet->payload[4] == 0x3A)))
{
/* TLS signature of Cisco AnyConnect 0X170303003A */
NDPI_LOG_INFO(ndpi_struct, "found CISCO Anyconnect VPN\n");
@@ -63,12 +83,13 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
return;
}
else if(((tsport == 8009 || tdport == 8009) ||
(tsport == 8008 || tdport == 8008)) &&
(tsport == 8008 || tdport == 8008)) &&
(packet->payload_packet_len >= 5) &&
((packet->payload[0] == 0x17 &&
packet->payload[1] == 0x03 &&
packet->payload[2] == 0x03 &&
packet->payload[3] == 0x00 &&
packet->payload[4] == 0x69)))
packet->payload[1] == 0x03 &&
packet->payload[2] == 0x03 &&
packet->payload[3] == 0x00 &&
packet->payload[4] == 0x69)))
{
/* TCP signature of Cisco AnyConnect 0X1703030069 */
NDPI_LOG_INFO(ndpi_struct, "found CISCO Anyconnect VPN\n");
@@ -79,6 +100,7 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
(
(usport == 10000 && udport == 10000)
&&
(packet->payload_packet_len >= 4) &&
(packet->payload[0] == 0xfe &&
packet->payload[1] == 0x57 &&
packet->payload[2] == 0x7e &&
@@ -86,15 +108,29 @@ void ndpi_search_ciscovpn(struct ndpi_detection_module_struct *ndpi_struct, stru
)
)
{
/* This is a good query fe577e2b */
NDPI_LOG_INFO(ndpi_struct, "found CISCOVPN\n");
ndpi_int_ciscovpn_add_connection(ndpi_struct, flow);
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
} else if(
(
(usport == 443 || udport == 443)
&&
(packet->payload_packet_len >= 5) &&
(packet->payload[0] == 0x17 &&
packet->payload[1] == 0x01 &&
packet->payload[2] == 0x00 &&
packet->payload[3] == 0x00 &&
packet->payload[4] == 0x01)
)
)
{
NDPI_LOG_INFO(ndpi_struct, "found CISCOVPN\n");
ndpi_int_ciscovpn_add_connection(ndpi_struct, flow);
return;
}
if(flow->num_processed_pkts > 5)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
+47 -32
View File
@@ -29,8 +29,8 @@
void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) {
struct ndpi_packet_struct* packet = &flow->packet;
if (packet->udp != NULL) {
if (packet->payload_packet_len < sizeof(uint32_t)) {
if(packet->udp != NULL) {
if(packet->payload_packet_len < sizeof(uint32_t)) {
NDPI_LOG_DBG2(ndpi_struct, "Short csgo packet\n");
return;
}
@@ -38,58 +38,65 @@ void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct n
uint32_t w = htonl(get_u_int32_t(packet->payload, 0));
NDPI_LOG_DBG2(ndpi_struct, "CSGO: word %08x\n", w);
if (!flow->csgo_state && packet->payload_packet_len == 23 && w == 0xfffffffful) {
if (!memcmp(packet->payload + 5, "connect0x", 9)) {
if(!flow->csgo_state && packet->payload_packet_len == 23 && w == 0xfffffffful) {
if(!memcmp(packet->payload + 5, "connect0x", 9)) {
flow->csgo_state++;
memcpy(flow->csgo_strid, packet->payload + 5, 18);
NDPI_LOG_DBG2(ndpi_struct, "Found csgo connect0x\n");
return;
}
}
if (flow->csgo_state == 1 && packet->payload_packet_len >= 42 && w == 0xfffffffful) {
if (!memcmp(packet->payload + 24, flow->csgo_strid, 18)) {
if(flow->csgo_state == 1 && packet->payload_packet_len >= 42 && w == 0xfffffffful) {
if(!memcmp(packet->payload + 24, flow->csgo_strid, 18)) {
flow->csgo_state++;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
NDPI_LOG_INFO( ndpi_struct, "found csgo connect0x reply\n");
return;
}
}
if (packet->payload_packet_len == 8 && ( w == 0x3a180000 || w == 0x39180000) ) {
if(packet->payload_packet_len == 8 && ( w == 0x3a180000 || w == 0x39180000) ) {
NDPI_LOG_INFO( ndpi_struct, "found csgo udp 8b\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
}
if (packet->payload_packet_len >= 36 && w == 0x56533031ul) {
if(packet->payload_packet_len >= 36 && w == 0x56533031ul) {
NDPI_LOG_INFO( ndpi_struct, "found csgo udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
}
if (packet->payload_packet_len >= 36 && w == 0x01007364) {
if(packet->payload_packet_len >= 36 && w == 0x01007364) {
uint32_t w2 = htonl(get_u_int32_t(packet->payload, 4));
if (w2 == 0x70696e67) {
if(w2 == 0x70696e67) {
NDPI_LOG_INFO( ndpi_struct, "found csgo udp ping\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
if (flow->csgo_s2 < 3 && (w & 0xffff0000ul) == 0x0d1d0000) {
if(flow->csgo_s2 < 3 && (w & 0xffff0000ul) == 0x0d1d0000) {
uint32_t w2 = get_u_int32_t(packet->payload, 2);
if (packet->payload_packet_len == 13) {
if (!flow->csgo_s2) {
if(packet->payload_packet_len == 13) {
if(!flow->csgo_s2) {
flow->csgo_id2 = w2;
flow->csgo_s2 = 1;
NDPI_LOG_DBG2( ndpi_struct, "Found csgo udp 0d1d step1\n");
return;
}
if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
if(flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
NDPI_LOG_DBG2( ndpi_struct, "Found csgo udp 0d1d step1 DUP\n");
return;
}
flow->csgo_s2 = 3;
return;
}
if (packet->payload_packet_len == 15) {
if (flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
if(packet->payload_packet_len == 15) {
if(flow->csgo_s2 == 1 && flow->csgo_id2 == w2) {
NDPI_LOG_INFO( ndpi_struct, "found csgo udp 0d1d\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -97,31 +104,39 @@ void ndpi_search_csgo(struct ndpi_detection_module_struct* ndpi_struct, struct n
}
flow->csgo_s2 = 3;
}
if (packet->payload_packet_len >= 140 && (w == 0x02124c6c || w == 0x02125c6c) &&
if(packet->payload_packet_len >= 140 && (w == 0x02124c6c || w == 0x02125c6c) &&
!memcmp(&packet->payload[3], "lta\000mob\000tpc\000bhj\000bxd\000tae\000urg\000gkh\000", 32)) {
NDPI_LOG_INFO( ndpi_struct, "found csgo dictionary udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
NDPI_LOG_INFO( ndpi_struct, "found csgo dictionary udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
}
if (packet->payload_packet_len >= 33 && packet->iph && packet->iph->daddr == 0xffffffff &&
if(packet->payload_packet_len >= 33 && packet->iph && packet->iph->daddr == 0xffffffff &&
!memcmp(&packet->payload[17], "LanSearch", 9)) {
NDPI_LOG_INFO( ndpi_struct, "found csgo LanSearch udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
NDPI_LOG_INFO( ndpi_struct, "found csgo LanSearch udp\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CSGO, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(w == 0) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
if (flow->packet_counter > 20)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
if(flow->packet_counter > 5)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_csgo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("CSGO", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_CSGO,
ndpi_search_csgo,
NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
ndpi_set_bitmask_protocol_detection("CSGO", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_CSGO,
ndpi_search_csgo,
NDPI_SELECTION_BITMASK_PROTOCOL_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+8 -6
View File
@@ -70,14 +70,14 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
if(packet->udp) {
dhcp_packet_t *dhcp = (dhcp_packet_t*)packet->payload;
if((packet->payload_packet_len >= 244 /* 244 is the offset of options[0] in dhcp_packet_t */)
if((packet->payload_packet_len >= 240 /* 240 is the offset of options[0] in dhcp_packet_t */)
&& (packet->udp->source == htons(67) || packet->udp->source == htons(68))
&& (packet->udp->dest == htons(67) || packet->udp->dest == htons(68))
&& (dhcp->magic == htonl(DHCP_OPTION_MAGIC_NUMBER))) {
u_int i = 0, foundValidMsgType = 0;
u_int dhcp_options_size = ndpi_min(DHCP_VEND_LEN /* maximum size of options in dhcp_packet_t */,
packet->payload_packet_len - 244);
packet->payload_packet_len - 240);
while(i + 1 /* for the len */ < dhcp_options_size) {
u_int8_t id = dhcp->options[i];
@@ -89,8 +89,10 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
u_int8_t len = ndpi_min(dhcp->options[i+1] /* len as found in the packet */,
dhcp_options_size - (i+2) /* 1 for the type and 1 for the value */);
if(len == 0) break;
if(len == 0)
break;
#ifdef DHCP_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "[DHCP] Id=%d [len=%d]\n", id, len);
#endif
@@ -150,8 +152,8 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
}
void init_dhcp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
void init_dhcp_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("DHCP", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_DHCP,
ndpi_search_dhcp_udp,
+16 -16
View File
@@ -85,7 +85,7 @@ static void ndpi_int_directconnect_add_connection(struct ndpi_detection_module_s
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
if(src != NULL) {
src->directconnect_last_safe_access_time = packet->tick_timestamp;
src->directconnect_last_safe_access_time = packet->current_time_ms;
if(connection_type == DIRECT_CONNECT_TYPE_PEER) {
if(packet->tcp != NULL
&& flow->setup_packet_direction != packet->packet_direction && src->detected_directconnect_port == 0) {
@@ -101,7 +101,7 @@ static void ndpi_int_directconnect_add_connection(struct ndpi_detection_module_s
}
if(dst != NULL) {
dst->directconnect_last_safe_access_time = packet->tick_timestamp;
dst->directconnect_last_safe_access_time = packet->current_time_ms;
if(connection_type == DIRECT_CONNECT_TYPE_PEER) {
if(packet->tcp != NULL
&& flow->setup_packet_direction == packet->packet_direction && dst->detected_directconnect_port == 0) {
@@ -162,9 +162,9 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if(src != NULL) {
if(src->detected_directconnect_port == packet->tcp->source) {
if((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
src->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
src->directconnect_last_safe_access_time = packet->tick_timestamp;
src->directconnect_last_safe_access_time = packet->current_time_ms;
NDPI_LOG_INFO(ndpi_struct, "found DC using port %d\n", ntohs(src->detected_directconnect_port));
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -176,9 +176,9 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
}
if(src->detected_directconnect_ssl_port == packet->tcp->dest) {
if((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
src->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
src->directconnect_last_safe_access_time = packet->tick_timestamp;
src->directconnect_last_safe_access_time = packet->current_time_ms;
NDPI_LOG_INFO(ndpi_struct, "found DC using port %d\n", ntohs(src->detected_directconnect_ssl_port));
ndpi_int_change_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -194,9 +194,9 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
if(dst != NULL) {
if(dst->detected_directconnect_port == packet->tcp->dest) {
if((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
dst->directconnect_last_safe_access_time = packet->tick_timestamp;
dst->directconnect_last_safe_access_time = packet->current_time_ms;
NDPI_LOG_INFO(ndpi_struct, "found DC using port %d\n", ntohs(dst->detected_directconnect_port));
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -208,9 +208,9 @@ static void ndpi_search_directconnect_tcp(struct ndpi_detection_module_struct *n
}
if(dst->detected_directconnect_ssl_port == packet->tcp->dest) {
if((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
dst->directconnect_last_safe_access_time = packet->tick_timestamp;
dst->directconnect_last_safe_access_time = packet->current_time_ms;
NDPI_LOG_DBG(ndpi_struct, "found DC using port %d\n", ntohs(dst->detected_directconnect_ssl_port));
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -319,10 +319,10 @@ static void ndpi_search_directconnect_udp(struct ndpi_detection_module_struct
if(dst != NULL && dst->detected_directconnect_udp_port == packet->udp->dest) {
if((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
dst->directconnect_last_safe_access_time) < ndpi_struct->directconnect_connection_ip_tick_timeout) {
dst->directconnect_last_safe_access_time = packet->tick_timestamp;
dst->directconnect_last_safe_access_time = packet->current_time_ms;
NDPI_LOG_INFO(ndpi_struct, "found DC using udp port %d\n", ntohs(dst->detected_directconnect_udp_port));
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DIRECTCONNECT, NDPI_PROTOCOL_UNKNOWN);
return;
@@ -405,16 +405,16 @@ void ndpi_search_directconnect(struct ndpi_detection_module_struct
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_DIRECTCONNECT) {
if(src != NULL && ((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
src->directconnect_last_safe_access_time) <
ndpi_struct->directconnect_connection_ip_tick_timeout)) {
src->directconnect_last_safe_access_time = packet->tick_timestamp;
src->directconnect_last_safe_access_time = packet->current_time_ms;
} else if(dst != NULL && ((u_int32_t)
(packet->tick_timestamp -
(packet->current_time_ms -
dst->directconnect_last_safe_access_time) <
ndpi_struct->directconnect_connection_ip_tick_timeout)) {
dst->directconnect_last_safe_access_time = packet->tick_timestamp;
dst->directconnect_last_safe_access_time = packet->current_time_ms;
} else {
packet->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN;
NDPI_LOG_DBG2(ndpi_struct, "skipping as unknown due to timeout\n");
+34 -14
View File
@@ -1,41 +1,61 @@
/*
* dnp3.c
* Extension for dnp3 recognition
*
* Copyright (C) 2011-20 - 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/>.
*
* Created by Cesar HM
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNP3
#include "ndpi_api.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNP3
/*
https://www.ixiacom.com/company/blog/scada-distributed-network-protocol-dnp3
*/
/* ******************************************************** */
void ndpi_search_dnp3_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search DNP3\n");
/* Check connection over TCP */
NDPI_LOG_DBG(ndpi_struct, "search DNP3\n");
if(packet->tcp) {
/* The payload of DNP3 is 10 bytes long.
* Header bytes: 0x0564
*/
if ( packet->payload_packet_len >= 10 &&
packet->payload[0] == 0x05 && packet->payload[1] == 0x64 ){
NDPI_LOG_INFO(ndpi_struct, "found DNP3\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DNP3, NDPI_PROTOCOL_UNKNOWN);
return;
}
*/
if ((packet->payload_packet_len >= 10)
&& (packet->payload[0] == 0x05)
&& (packet->payload[1] == 0x64)) {
NDPI_LOG_INFO(ndpi_struct, "found DNP3\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DNP3, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
/* ******************************************************** */
void init_dnp3_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("DNP3", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_DNP3,
+164 -28
View File
@@ -27,12 +27,101 @@
#include "ndpi_api.h"
#define FLAGS_MASK 0x8000
// #define DNS_DEBUG 1
/* #define DNS_DEBUG 1 */
static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
#define DNS_PORT 53
#define LLMNR_PORT 5355
#define MDNS_PORT 5353
static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
/* *********************************************** */
static void ndpi_check_dns_type(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t dns_type) {
/* https://en.wikipedia.org/wiki/List_of_DNS_record_types */
switch(dns_type) {
/* Obsolete record types */
case 3:
case 4:
case 254:
case 7:
case 8:
case 9:
case 14:
case 253:
case 11:
case 33:
case 10:
case 38:
case 30:
case 25:
case 24:
case 13:
case 17:
case 19:
case 20:
case 21:
case 22:
case 23:
case 26:
case 31:
case 32:
case 34:
case 42:
case 40:
case 27:
case 100:
case 101:
case 102:
case 103:
case 99:
case 56:
case 57:
case 58:
case 104:
case 105:
case 106:
case 107:
case 259:
NDPI_SET_BIT(flow->risk, NDPI_DNS_SUSPICIOUS_TRAFFIC);
break;
}
}
/* *********************************************** */
static u_int16_t checkPort(u_int16_t port) {
switch(port) {
case DNS_PORT:
return(NDPI_PROTOCOL_DNS);
break;
case LLMNR_PORT:
return(NDPI_PROTOCOL_LLMNR);
break;
case MDNS_PORT:
return(NDPI_PROTOCOL_MDNS);
break;
}
return(0);
}
/* *********************************************** */
static u_int16_t checkDNSSubprotocol(u_int16_t sport, u_int16_t dport) {
u_int16_t rc = checkPort(sport);
if(rc == 0)
return(checkPort(dport));
else
return(rc);
}
/* *********************************************** */
@@ -104,8 +193,10 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
/* 0x8000 RESPONSE */
else if((dns_header->flags & FLAGS_MASK) == 0x8000)
*is_query = 0;
else
else {
NDPI_SET_BIT(flow->risk, NDPI_MALFORMED_PACKET);
return(1 /* invalid */);
}
if(*is_query) {
/* DNS Request */
@@ -113,35 +204,37 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
&& (((dns_header->flags & 0x2800) == 0x2800 /* Dynamic DNS Update */)
|| ((dns_header->num_answers == 0) && (dns_header->authority_rrs == 0)))) {
/* This is a good query */
while(x < flow->packet.payload_packet_len) {
while(x+2 < flow->packet.payload_packet_len) {
if(flow->packet.payload[x] == '\0') {
x++;
flow->protos.dns.query_type = get16(&x, flow->packet.payload);
#ifdef DNS_DEBUG
NDPI_LOG_DBG2(ndpi_struct, "query_type=%2d\n", flow->protos.dns.query_type);
printf("[DNS] query_type=%d\n", flow->protos.dns.query_type);
printf("[DNS] [request] query_type=%d\n", flow->protos.dns.query_type);
#endif
break;
} else
x++;
}
} else
} else {
NDPI_SET_BIT(flow->risk, NDPI_MALFORMED_PACKET);
return(1 /* invalid */);
}
} else {
/* DNS Reply */
flow->protos.dns.reply_code = dns_header->flags & 0x0F;
if((dns_header->num_queries > 0) && (dns_header->num_queries <= NDPI_MAX_DNS_REQUESTS) /* Don't assume that num_queries must be zero */
&& (((dns_header->num_answers > 0) && (dns_header->num_answers <= NDPI_MAX_DNS_REQUESTS))
|| ((dns_header->authority_rrs > 0) && (dns_header->authority_rrs <= NDPI_MAX_DNS_REQUESTS))
|| ((dns_header->additional_rrs > 0) && (dns_header->additional_rrs <= NDPI_MAX_DNS_REQUESTS)))
&& ((((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: we dissect it both for request and response */
/* Leave the statement below commented necessary in case of call to ndpi_get_partial_detection() */
x++;
if(flow->packet.payload[x] != '\0') {
if(x < flow->packet.payload_packet_len && flow->packet.payload[x] != '\0') {
while((x < flow->packet.payload_packet_len)
&& (flow->packet.payload[x] != '\0')) {
x++;
@@ -163,7 +256,8 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
break;
}
if((data_len = getNameLength(x, flow->packet.payload, flow->packet.payload_packet_len)) == 0) {
if((data_len = getNameLength(x, flow->packet.payload,
flow->packet.payload_packet_len)) == 0) {
break;
} else
x += data_len;
@@ -171,14 +265,22 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
if((x+2) >= flow->packet.payload_packet_len) {
break;
}
rsp_type = get16(&x, flow->packet.payload);
#ifdef DNS_DEBUG
printf("[DNS] [response] response_type=%d\n", rsp_type);
#endif
ndpi_check_dns_type(ndpi_struct, flow, rsp_type);
flow->protos.dns.rsp_type = rsp_type;
/* here x points to the response "class" field */
if((x+12) <= flow->packet.payload_packet_len) {
x += 6;
data_len = get16(&x, flow->packet.payload);
if((x + data_len) <= flow->packet.payload_packet_len) {
// printf("[rsp_type: %u][data_len: %u]\n", rsp_type, data_len);
@@ -186,7 +288,7 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
x += data_len;
continue; /* Skip CNAME */
}
if((((rsp_type == 0x1) && (data_len == 4)) /* A */
#ifdef NDPI_DETECTION_SUPPORT_IPV6
|| ((rsp_type == 0x1c) && (data_len == 16)) /* AAAA */
@@ -196,11 +298,11 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
}
}
}
break;
}
}
if((flow->packet.detected_protocol_stack[0] == NDPI_PROTOCOL_DNS)
|| (flow->packet.detected_protocol_stack[1] == NDPI_PROTOCOL_DNS)) {
/* Request already set the protocol */
@@ -208,13 +310,10 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
} else {
/* We missed the request */
u_int16_t s_port = flow->packet.udp ? ntohs(flow->packet.udp->source) : ntohs(flow->packet.tcp->source);
ndpi_set_detected_protocol(ndpi_struct, flow,
(s_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS,
NDPI_PROTOCOL_UNKNOWN);
ndpi_set_detected_protocol(ndpi_struct, flow, checkPort(s_port), NDPI_PROTOCOL_UNKNOWN);
}
} else
return(1 /* invalid */);
}
}
/* Valid */
@@ -253,15 +352,18 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
return;
}
if((s_port == 53 || d_port == 53 || d_port == 5355)
if(((s_port == DNS_PORT) || (d_port == DNS_PORT)
|| (s_port == MDNS_PORT) || (d_port == MDNS_PORT)
|| (d_port == LLMNR_PORT))
&& (flow->packet.payload_packet_len > sizeof(struct ndpi_dns_packet_header)+payload_offset)) {
struct ndpi_dns_packet_header dns_header;
int j = 0, max_len, off;
int invalid = search_valid_dns(ndpi_struct, flow, &dns_header, payload_offset, &is_query);
ndpi_protocol ret;
u_int num_queries, idx;
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN;
ret.app_protocol = (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS;
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN;
ret.app_protocol = (d_port == LLMNR_PORT) ? NDPI_PROTOCOL_LLMNR : ((d_port == MDNS_PORT) ? NDPI_PROTOCOL_MDNS : NDPI_PROTOCOL_DNS);
if(invalid) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
@@ -271,7 +373,35 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
/* extract host name server */
max_len = sizeof(flow->host_server_name)-1;
off = sizeof(struct ndpi_dns_packet_header) + payload_offset;
/* Before continuing let's dissect the following queries to see if they are valid */
for(idx=off, num_queries=0; (num_queries < dns_header.num_queries) && (idx < flow->packet.payload_packet_len);) {
u_int8_t name_len = flow->packet.payload[idx];
#ifdef DNS_DEBUG
printf("[DNS] [name_len: %u]\n", name_len);
#endif
if(name_len == 0) {
/* End of query */
num_queries++;
idx += 5;
continue;
}
if((name_len+idx) >= flow->packet.payload_packet_len) {
/* Invalid */
#ifdef DNS_DEBUG
printf("[DNS] Invalid query len [%u >= %u]\n",
(name_len+idx),
flow->packet.payload_packet_len);
#endif
NDPI_SET_BIT(flow->risk, NDPI_MALFORMED_PACKET);
break;
} else
idx += name_len+1;
}
while(j < max_len && off < flow->packet.payload_packet_len && flow->packet.payload[off] != '\0') {
uint8_t c, cl = flow->packet.payload[off++];
@@ -285,18 +415,21 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
while(j < max_len && cl != 0) {
u_int32_t shift;
c = flow->packet.payload[off++];
shift = ((u_int32_t) 1) << (c & 0x1f);
flow->host_server_name[j++] = tolower((dns_validchar[c >> 5] & shift) ? c : '_');
cl--;
}
}
flow->host_server_name[j] = '\0';
if(j > 0) {
ndpi_protocol_match_result ret_match;
ndpi_check_dga_name(ndpi_struct, flow, (char*)flow->host_server_name, 1);
ret.app_protocol = ndpi_match_host_subprotocol(ndpi_struct, flow,
(char *)flow->host_server_name,
strlen((const char*)flow->host_server_name),
@@ -307,7 +440,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
flow->category = ret_match.protocol_category;
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN)
ret.master_protocol = (d_port == 5355) ? NDPI_PROTOCOL_LLMNR : NDPI_PROTOCOL_DNS;
ret.master_protocol = checkDNSSubprotocol(s_port, d_port);
else
ret.master_protocol = NDPI_PROTOCOL_DNS;
}
@@ -353,6 +486,9 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
}
if(flow->packet_counter > 3)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_dns_dissector(struct ndpi_detection_module_struct *ndpi_struct,
+69
View File
@@ -0,0 +1,69 @@
/*
* dnscrypt.c
*
* Copyright (C) 2020 - 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/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_DNSCRYPT
#include "ndpi_api.h"
static void ndpi_int_dnscrypt_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DNSCRYPT, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_dnscrypt(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
static char const * const dnscrypt_initial = "2\rdnscrypt";
NDPI_LOG_DBG(ndpi_struct, "search dnscrypt\n");
if (flow->packet_counter > 2)
{
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
/* dnscrypt protocol version 1: check magic */
if (packet->payload_packet_len >= 64 &&
strncmp((char*)packet->payload, "r6fnvWj8", strlen("r6fnvWj8")) == 0)
{
ndpi_int_dnscrypt_add_connection(ndpi_struct, flow);
}
/* dnscrypt protocol version 1 and 2: resolver ping */
if (packet->payload_packet_len > 13 + strlen(dnscrypt_initial) &&
strncasecmp((char*)packet->payload + 13, dnscrypt_initial, strlen(dnscrypt_initial)) == 0)
{
ndpi_int_dnscrypt_add_connection(ndpi_struct, flow);
}
}
void init_dnscrypt_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id,
NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection(
"DNScrypt", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_DNSCRYPT, ndpi_search_dnscrypt, NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN, ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+10 -4
View File
@@ -165,8 +165,11 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
return;
}
if(payload_len == 0) return;
if(payload_len == 0) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
/* Check if we so far detected the protocol in the request or not. */
if(flow->edonkey_stage == 0) {
NDPI_LOG_DBG2(ndpi_struct, "EDONKEY stage 0: \n");
@@ -176,7 +179,8 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->edonkey_stage = packet->packet_direction + 1;
}
} else
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "EDONKEY stage %u: \n", flow->edonkey_stage);
@@ -193,8 +197,10 @@ static void ndpi_check_edonkey(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to EDONKEY, resetting the stage to 0\n");
flow->edonkey_stage = 0;
}
}
if(flow->packet_counter > 5)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void ndpi_search_edonkey(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
+4 -1
View File
@@ -85,9 +85,12 @@ void ndpi_search_fbzero(struct ndpi_detection_module_struct *ndpi_struct,
char *value = (char*)&packet->payload[data_offset + data_prev_offset];
u_int tag_len = t->tag_offset_len-data_prev_offset, max_len;
ndpi_protocol_match_result ret_match;
max_len = ndpi_min(tag_len, sizeof(flow->host_server_name)-1);
if (data_offset + data_prev_offset + max_len >= packet->payload_packet_len) {
return;
}
strncpy((char*)flow->host_server_name, value, max_len);
flow->host_server_name[max_len] = '\0';
+1 -1
View File
@@ -33,7 +33,7 @@ void ndpi_search_fix(struct ndpi_detection_module_struct *ndpi_struct, struct nd
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search FIX\n");
if(packet->tcp) {
if(packet->tcp && packet->payload_packet_len > 5) {
// 8=
if(packet->payload[0] == 0x38 && packet->payload[1] == 0x3d) {
// FIX.
+2 -2
View File
@@ -43,7 +43,7 @@ static int ndpi_ftp_control_check_request(struct ndpi_flow_struct *flow,
const u_int8_t *payload,
size_t payload_len) {
#ifdef FTP_DEBUG
printf("%s() [%s]\n", __FUNCTION__, payload);
printf("%s() [%.*s]\n", __FUNCTION__, (int)payload_len, payload);
#endif
if(ndpi_match_strprefix(payload, payload_len, "USER")) {
@@ -550,7 +550,7 @@ static int ndpi_ftp_control_check_response(struct ndpi_flow_struct *flow,
const u_int8_t *payload,
size_t payload_len) {
#ifdef FTP_DEBUG
printf("%s() [%s]\n", __FUNCTION__, payload);
printf("%s() [%.*s]\n", __FUNCTION__, (int)payload_len, payload);
#endif
if(payload_len == 0) return(1);
+10 -10
View File
@@ -41,7 +41,7 @@ static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct
NDPI_LOG_INFO(ndpi_struct, "found GNUTELLA\n");
if (src != NULL) {
src->gnutella_ts = packet->tick_timestamp;
src->gnutella_ts = packet->current_time_ms;
if (packet->udp != NULL) {
if (!src->detected_gnutella_udp_port1) {
src->detected_gnutella_udp_port1 = (packet->udp->source);
@@ -58,7 +58,7 @@ static void ndpi_int_gnutella_add_connection(struct ndpi_detection_module_struct
}
}
if (dst != NULL) {
dst->gnutella_ts = packet->tick_timestamp;
dst->gnutella_ts = packet->current_time_ms;
}
}
@@ -74,19 +74,19 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_GNUTELLA) {
if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
(packet->current_time_ms - src->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
NDPI_LOG_DBG2(ndpi_struct, "save src connection packet detected\n");
src->gnutella_ts = packet->tick_timestamp;
src->gnutella_ts = packet->current_time_ms;
} else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
(packet->current_time_ms - dst->gnutella_ts) < ndpi_struct->gnutella_timeout)) {
NDPI_LOG_DBG2(ndpi_struct, "save dst connection packet detected\n");
dst->gnutella_ts = packet->tick_timestamp;
dst->gnutella_ts = packet->current_time_ms;
}
if (src != NULL && (packet->tick_timestamp - src->gnutella_ts) > ndpi_struct->gnutella_timeout) {
if (src != NULL && (packet->current_time_ms - src->gnutella_ts) > ndpi_struct->gnutella_timeout) {
src->detected_gnutella_udp_port1 = 0;
src->detected_gnutella_udp_port2 = 0;
}
if (dst != NULL && (packet->tick_timestamp - dst->gnutella_ts) > ndpi_struct->gnutella_timeout) {
if (dst != NULL && (packet->current_time_ms - dst->gnutella_ts) > ndpi_struct->gnutella_timeout) {
dst->detected_gnutella_udp_port1 = 0;
dst->detected_gnutella_udp_port2 = 0;
}
@@ -125,7 +125,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
}
}
}
if (packet->payload_packet_len > 50 && ((memcmp(packet->payload, "GET / HTTP", 9) == 0))) {
if (packet->payload_packet_len > 50 && ((memcmp(packet->payload, "GET / HTTP", 10) == 0))) {
ndpi_parse_packet_line_info(ndpi_struct, flow);
if ((packet->user_agent_line.ptr != NULL && packet->user_agent_line.len > 15
&& memcmp(packet->user_agent_line.ptr, "BearShare Lite ", 15) == 0)
@@ -236,7 +236,7 @@ void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struct, stru
} else if (packet->udp != NULL) {
if (src != NULL && (packet->udp->source == src->detected_gnutella_udp_port1 ||
packet->udp->source == src->detected_gnutella_udp_port2) &&
(packet->tick_timestamp - src->gnutella_ts) < ndpi_struct->gnutella_timeout) {
(packet->current_time_ms - src->gnutella_ts) < ndpi_struct->gnutella_timeout) {
NDPI_LOG_DBG2(ndpi_struct, "port based detection\n\n");
ndpi_int_gnutella_add_connection(ndpi_struct, flow);
}
+67 -50
View File
@@ -1,9 +1,22 @@
/*
* h323.c
*
* Copyright (C) 2015-18 ntop.org
* Copyright (C) 2015-20 ntop.org
* Copyright (C) 2013 Remy Mudingay <mudingay@ill.fr>
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
@@ -25,44 +38,48 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
NDPI_LOG_DBG(ndpi_struct, "search H323\n");
if(packet->tcp != NULL) {
/*
The TPKT protocol is used by ISO 8072 (on port 102)
and H.323. So this check below is to avoid ambiguities
*/
if((packet->tcp != NULL) && (packet->tcp->dest != ntohs(102))) {
NDPI_LOG_DBG2(ndpi_struct, "calculated dport over tcp\n");
/* H323 */
if(packet->payload_packet_len >= 3
if(packet->payload_packet_len > 4
&& (packet->payload[0] == 0x03)
&& (packet->payload[1] == 0x00)) {
struct tpkt *t = (struct tpkt*)packet->payload;
u_int16_t len = ntohs(t->len);
struct tpkt *t = (struct tpkt*)packet->payload;
u_int16_t len = ntohs(t->len);
if(packet->payload_packet_len == len) {
/*
We need to check if this packet is in reality
a RDP (Remote Desktop) packet encapsulated on TPTK
*/
if(packet->payload_packet_len == len) {
/*
We need to check if this packet is in reality
a RDP (Remote Desktop) packet encapsulated on TPTK
*/
if(packet->payload[4] == (packet->payload_packet_len - sizeof(struct tpkt) - 1)) {
/* ISO 8073/X.224 */
if((packet->payload[5] == 0xE0 /* CC Connect Request */)
|| (packet->payload[5] == 0xD0 /* CC Connect Confirm */)) {
NDPI_LOG_INFO(ndpi_struct, "found RDP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(packet->payload[4] == (packet->payload_packet_len - sizeof(struct tpkt) - 1)) {
/* ISO 8073/X.224 */
if((packet->payload[5] == 0xE0 /* CC Connect Request */)
|| (packet->payload[5] == 0xD0 /* CC Connect Confirm */)) {
NDPI_LOG_INFO(ndpi_struct, "found RDP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN);
return;
}
flow->l4.tcp.h323_valid_packets++;
if(flow->l4.tcp.h323_valid_packets >= 2) {
NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
}
} else {
/* This is not H.323 */
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
flow->l4.tcp.h323_valid_packets++;
if(flow->l4.tcp.h323_valid_packets >= 2) {
NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
}
} else {
/* This is not H.323 */
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
} else if(packet->udp != NULL) {
sport = ntohs(packet->udp->source), dport = ntohs(packet->udp->dest);
NDPI_LOG_DBG2(ndpi_struct, "calculated dport over udp\n");
@@ -76,28 +93,28 @@ void ndpi_search_h323(struct ndpi_detection_module_struct *ndpi_struct, struct n
return;
}
/* H323 */
if(sport == 1719 || dport == 1719)
{
if(packet->payload[0] == 0x16 && packet->payload[1] == 0x80 && packet->payload[4] == 0x06 && packet->payload[5] == 0x00)
{
NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return;
}
else if(packet->payload_packet_len >= 20 && packet->payload_packet_len <= 117)
{
NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return;
}
else
{
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
if(sport == 1719 || dport == 1719) {
if((packet->payload_packet_len >= 5)
&& (packet->payload[0] == 0x16)
&& (packet->payload[1] == 0x80)
&& (packet->payload[4] == 0x06)
&& (packet->payload[5] == 0x00)) {
NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return;
} else if(packet->payload_packet_len >= 20 && packet->payload_packet_len <= 117) {
NDPI_LOG_INFO(ndpi_struct, "found H323 broadcast\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_H323, NDPI_PROTOCOL_UNKNOWN);
return;
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
}
if(flow->packet_counter > 5)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_h323_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+2
View File
@@ -108,6 +108,8 @@ void ndpi_search_hangout(struct ndpi_detection_module_struct *ndpi_struct,
#endif
ndpi_lru_add_to_cache(ndpi_struct->stun_cache, key, NDPI_PROTOCOL_HANGOUT_DUO);
if(ndpi_struct->ndpi_notify_lru_add_handler_ptr)
ndpi_struct->ndpi_notify_lru_add_handler_ptr(ndpi_hangout_cache, key, NDPI_PROTOCOL_HANGOUT_DUO);
}
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HANGOUT_DUO,
+380 -185
View File
@@ -28,21 +28,62 @@
#include "ndpi_api.h"
#include <stdlib.h>
static const char* binary_file_mimes_e[] = { "exe", NULL };
static const char* binary_file_mimes_v[] = { "vnd.ms-cab-compressed", "vnd.microsoft.portable-executable", NULL };
static const char* binary_file_mimes_x[] = { "x-msdownload", "x-dosexec", NULL };
#define ATTACHMENT_LEN 3
static const char* binary_file_ext[] = {
"exe",
"msi",
"cab",
NULL
};
static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow);
/* *********************************************** */
static void ndpi_analyze_content_signature(struct ndpi_flow_struct *flow) {
if((flow->initial_binary_bytes_len >= 2) && (flow->initial_binary_bytes[0] == 0x4D) && (flow->initial_binary_bytes[1] == 0x5A))
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER); /* Win executable */
else if((flow->initial_binary_bytes_len >= 4) && (flow->initial_binary_bytes[0] == 0x7F) && (flow->initial_binary_bytes[1] == 'E')
&& (flow->initial_binary_bytes[2] == 'L') && (flow->initial_binary_bytes[3] == 'F'))
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER); /* Linux executable */
else if((flow->initial_binary_bytes_len >= 4) && (flow->initial_binary_bytes[0] == 0xCF) && (flow->initial_binary_bytes[1] == 0xFA)
&& (flow->initial_binary_bytes[2] == 0xED) && (flow->initial_binary_bytes[3] == 0xFE))
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER); /* Linux executable */
else if((flow->initial_binary_bytes_len >= 3)
&& (flow->initial_binary_bytes[0] == '#')
&& (flow->initial_binary_bytes[1] == '!')
&& (flow->initial_binary_bytes[2] == '/'))
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER); /* Unix script (e.g. #!/bin/sh) */
else if(flow->initial_binary_bytes_len >= 8) {
u_int8_t exec_pattern[] = { 0x64, 0x65, 0x78, 0x0A, 0x30, 0x33, 0x35, 0x00 };
if(memcmp(flow->initial_binary_bytes, exec_pattern, 8) == 0)
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER); /* Dalvik Executable (Android) */
}
}
/* *********************************************** */
static int ndpi_search_http_tcp_again(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
ndpi_search_http_tcp(ndpi_struct, flow);
#ifdef HTTP_DEBUG
printf("=> %s()\n", __FUNCTION__);
#endif
if((flow->host_server_name[0] != '\0') && (flow->http.response_status_code != 0)) {
if((flow->host_server_name[0] != '\0')
&& (flow->http.response_status_code != 0)
) {
/* stop extra processing */
if(flow->initial_binary_bytes_len) ndpi_analyze_content_signature(flow);
flow->extra_packets_func = NULL; /* We're good now */
return(0);
}
@@ -62,10 +103,59 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
u_int app_len = sizeof("application");
if(packet->content_line.len > app_len) {
if(ndpi_strncasestr((const char *)&packet->content_line.ptr[app_len], "mpeg",
packet->content_line.len-app_len) != NULL) {
const char *app = (const char *)&packet->content_line.ptr[app_len];
u_int app_len_avail = packet->content_line.len-app_len;
if(strncasecmp(app, "mpeg", app_len_avail) == 0) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_STREAMING;
return(flow->category);
} else if(app_len_avail > 3) {
const char** cmp_mimes = NULL;
switch(app[0]) {
case 'e': cmp_mimes = binary_file_mimes_e; break;
case 'v': cmp_mimes = binary_file_mimes_v; break;
case 'x': cmp_mimes = binary_file_mimes_x; break;
}
if(cmp_mimes != NULL) {
u_int8_t i;
for(i = 0; cmp_mimes[i] != NULL; i++) {
if(strncasecmp(app, cmp_mimes[i], app_len_avail) == 0) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT;
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER);
NDPI_LOG_INFO(ndpi_struct, "found executable HTTP transfer");
return(flow->category);
}
}
}
}
}
/* check for attachment */
if(packet->content_disposition_line.len > 0) {
u_int8_t attachment_len = sizeof("attachment; filename");
if(packet->content_disposition_line.len > attachment_len) {
u_int8_t filename_len = packet->content_disposition_line.len - attachment_len;
if(filename_len > ATTACHMENT_LEN) {
attachment_len += filename_len-ATTACHMENT_LEN-1;
if((attachment_len+ATTACHMENT_LEN) <= packet->content_disposition_line.len) {
for(int i = 0; binary_file_ext[i] != NULL; i++) {
/* Use memcmp in case content-disposition contains binary data */
if(memcmp((const char*)&packet->content_disposition_line.ptr[attachment_len],
binary_file_ext[i], ATTACHMENT_LEN) == 0) {
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT;
NDPI_SET_BIT(flow->risk, NDPI_BINARY_APPLICATION_TRANSFER);
NDPI_LOG_INFO(ndpi_struct, "found executable HTTP transfer");
return(flow->category);
}
}
}
}
}
}
@@ -75,7 +165,7 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
ndpi_min(packet->content_line.len, 5)) == 0)
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_MEDIA;
break;
case 'v':
if(strncasecmp((const char *)packet->content_line.ptr, "video",
ndpi_min(packet->content_line.len, 5)) == 0)
@@ -107,15 +197,14 @@ static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *nd
if((flow->guessed_host_protocol_id == NDPI_PROTOCOL_UNKNOWN) || (http_protocol != NDPI_PROTOCOL_HTTP))
flow->guessed_host_protocol_id = http_protocol;
category = ndpi_http_check_content(ndpi_struct, flow);
ndpi_int_reset_protocol(flow);
// ndpi_int_reset_protocol(flow);
ndpi_set_detected_protocol(ndpi_struct, flow, flow->guessed_host_protocol_id, NDPI_PROTOCOL_HTTP);
/* This is necessary to inform the core to call this dissector again */
flow->check_extra_packets = 1;
flow->max_extra_packets_to_check = 5;
flow->extra_packets_func = ndpi_search_http_tcp_again;
flow->http_detected = 1, flow->guessed_category = flow->category = category;
flow->http_detected = 1;
}
/* ************************************************************* */
@@ -136,7 +225,7 @@ static void rtsp_parse_packet_acceptline(struct ndpi_detection_module_struct
static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, char *ua) {
if ( !strcmp(ua, "Windows NT 5.0")) ua = "Windows 2000";
if( !strcmp(ua, "Windows NT 5.0")) ua = "Windows 2000";
else if(!strcmp(ua, "Windows NT 5.1")) ua = "Windows XP";
else if(!strcmp(ua, "Windows NT 5.2")) ua = "Windows Server 2003";
else if(!strcmp(ua, "Windows NT 6.0")) ua = "Windows Vista";
@@ -148,9 +237,8 @@ static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
/* Good reference for future implementations:
* https://github.com/ua-parser/uap-core/blob/master/regexes.yaml */
//printf("==> %s\n", ua);
snprintf((char*)flow->protos.http.detected_os,
sizeof(flow->protos.http.detected_os), "%s", ua);
sizeof(flow->protos.http.detected_os), "%s", ua);
}
/* ************************************************************* */
@@ -162,7 +250,7 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp
if(double_col) double_col[0] = '\0';
ndpi_match_hostname_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP,
ndpi_match_hostname_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP,
(char *)flow->host_server_name,
strlen((const char *)flow->host_server_name));
}
@@ -170,6 +258,136 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp
/* ************************************************************* */
static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
char *ua) {
if((!ua) || (ua[0] == '\0')) return;
if((strlen(ua) < 4)
|| (!strncmp(ua, "test", 4))
|| (!strncmp(ua, "<?", 2))
|| strchr(ua, '{')
|| strchr(ua, '}')
|| ndpi_check_dga_name(ndpi_struct, NULL, ua, 0)
// || ndpi_match_bigram(ndpi_struct, &ndpi_struct->impossible_bigrams_automa, ua)
) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_USER_AGENT);
}
}
int http_process_user_agent(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
const u_int8_t *ua_ptr, u_int16_t ua_ptr_len)
{
/**
Format examples:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ....
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
*/
if(ua_ptr_len > 7) {
char ua[256];
u_int mlen = ndpi_min(ua_ptr_len, sizeof(ua)-1);
strncpy(ua, (const char *)ua_ptr, mlen);
ua[mlen] = '\0';
if(strncmp(ua, "Mozilla", 7) == 0) {
char *parent = strchr(ua, '(');
if(parent) {
char *token, *end;
parent++;
end = strchr(parent, ')');
if(end) end[0] = '\0';
token = strsep(&parent, ";");
if(token) {
if((strcmp(token, "X11") == 0)
|| (strcmp(token, "compatible") == 0)
|| (strcmp(token, "Linux") == 0)
|| (strcmp(token, "Macintosh") == 0)
) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token
&& ((strcmp(token, "U") == 0)
|| (strncmp(token, "MSIE", 4) == 0))) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "Update", 6) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "AOL", 3) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
}
}
}
}
if(token)
setHttpUserAgent(ndpi_struct, flow, token);
}
}
} else if((ua_ptr_len > 14) && (memcmp(ua, "netflix-ios-app", 15) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found netflix\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_NETFLIX, NDPI_PROTOCOL_CATEGORY_STREAMING);
return -1;
}
}
if(flow->http.user_agent == NULL) {
int len = ua_ptr_len + 1;
flow->http.user_agent = ndpi_malloc(len);
if(flow->http.user_agent) {
memcpy(flow->http.user_agent, (char*)ua_ptr, ua_ptr_len);
flow->http.user_agent[ua_ptr_len] = '\0';
ndpi_check_user_agent(ndpi_struct, flow, flow->http.user_agent);
}
}
NDPI_LOG_DBG2(ndpi_struct, "User Agent Type line found %.*s\n",
ua_ptr_len, ua_ptr);
return 0;
}
/* ************************************************************* */
static void ndpi_check_numeric_ip(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
char *ip, u_int ip_len) {
char buf[22], *double_dot;
struct in_addr ip_addr;
strncpy(buf, ip, ip_len);
buf[ip_len] = '\0';
if((double_dot = strchr(buf, ':')) != NULL)
double_dot[0] = '\0';
ip_addr.s_addr = inet_addr(buf);
if(strcmp(inet_ntoa(ip_addr), buf) == 0)
NDPI_SET_BIT(flow->risk, NDPI_HTTP_NUMERIC_IP_HOST);
}
/* ************************************************************* */
static void ndpi_check_http_url(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
char *url) {
/* Nothing to do */
}
/* ************************************************************* */
/**
NOTE
ndpi_parse_packet_line_info is in ndpi_main.c
@@ -177,149 +395,45 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp
static void check_content_type_and_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
int ret;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_UNKNOWN);
if(flow->http_detected && (flow->http.response_status_code != 0))
return;
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* PPStream */
if(flow->l4.tcp.ppstream_stage > 0 && flow->iqiyi_counter == 0) {
NDPI_LOG_INFO(ndpi_struct, "found PPStream\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PPSTREAM,
NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_STREAMING);
} else if(flow->iqiyi_counter > 0) {
NDPI_LOG_INFO(ndpi_struct, "found iQiyi\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IQIYI,
NDPI_PROTOCOL_HTTP, NDPI_PROTOCOL_CATEGORY_STREAMING);
}
#endif
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* 1KXUN */
if(flow->kxun_counter > 0) {
NDPI_LOG_INFO(ndpi_struct, "found 1kxun\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_1KXUN, NDPI_PROTOCOL_CATEGORY_STREAMING);
}
#endif
if((flow->http.url == NULL)
if((flow->http.url == NULL)
&& (packet->http_url_name.len > 0)
&& (packet->host_line.len > 0)) {
int len = packet->http_url_name.len + packet->host_line.len + 1;
if(isdigit(packet->host_line.ptr[0])
&& (packet->host_line.len < 21))
ndpi_check_numeric_ip(ndpi_struct, flow, (char*)packet->host_line.ptr, packet->host_line.len);
flow->http.url = ndpi_malloc(len);
if(flow->http.url) {
strncpy(flow->http.url, (char*)packet->host_line.ptr, packet->host_line.len);
strncpy(&flow->http.url[packet->host_line.len], (char*)packet->http_url_name.ptr,
packet->http_url_name.len);
flow->http.url[len-1] = '\0';
ndpi_check_http_url(ndpi_struct, flow, &flow->http.url[packet->host_line.len]);
}
if(flow->packet.http_method.len < 3)
flow->http.method = NDPI_HTTP_METHOD_UNKNOWN;
else {
switch(flow->packet.http_method.ptr[0]) {
case 'O': flow->http.method = NDPI_HTTP_METHOD_OPTIONS; break;
case 'G': flow->http.method = NDPI_HTTP_METHOD_GET; break;
case 'H': flow->http.method = NDPI_HTTP_METHOD_HEAD; break;
case 'P':
switch(flow->packet.http_method.ptr[1]) {
case 'A': flow->http.method = NDPI_HTTP_METHOD_PATCH; break;
case 'O': flow->http.method = NDPI_HTTP_METHOD_POST; break;
case 'U': flow->http.method = NDPI_HTTP_METHOD_PUT; break;
}
break;
case 'D': flow->http.method = NDPI_HTTP_METHOD_DELETE; break;
case 'T': flow->http.method = NDPI_HTTP_METHOD_TRACE; break;
case 'C': flow->http.method = NDPI_HTTP_METHOD_CONNECT; break;
default:
flow->http.method = NDPI_HTTP_METHOD_UNKNOWN;
break;
}
}
flow->http.method = ndpi_http_str2method((const char*)flow->packet.http_method.ptr, flow->packet.http_method.len);
}
if(packet->server_line.ptr != NULL && (packet->server_line.len > 7)) {
if(strncmp((const char *)packet->server_line.ptr, "ntopng ", 7) == 0)
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NTOP, NDPI_PROTOCOL_HTTP);
}
if(packet->user_agent_line.ptr != NULL && packet->user_agent_line.len != 0) {
/**
Format examples:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) ....
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
*/
if(packet->user_agent_line.len > 7) {
char ua[256];
u_int mlen = ndpi_min(packet->user_agent_line.len, sizeof(ua)-1);
strncpy(ua, (const char *)packet->user_agent_line.ptr, mlen);
ua[mlen] = '\0';
if(strncmp(ua, "Mozilla", 7) == 0) {
char *parent = strchr(ua, '(');
if(parent) {
char *token, *end;
parent++;
end = strchr(parent, ')');
if(end) end[0] = '\0';
token = strsep(&parent, ";");
if(token) {
if((strcmp(token, "X11") == 0)
|| (strcmp(token, "compatible") == 0)
|| (strcmp(token, "Linux") == 0)
|| (strcmp(token, "Macintosh") == 0)
) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token
&& ((strcmp(token, "U") == 0)
|| (strncmp(token, "MSIE", 4) == 0))) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "Update", 6) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
if(token && (strncmp(token, "AOL", 3) == 0)) {
token = strsep(&parent, ";");
if(token && (token[0] == ' ')) token++; /* Skip space */
}
}
}
}
if(token)
setHttpUserAgent(ndpi_struct, flow, token);
}
}
} else if((packet->user_agent_line.len > 14) && (memcmp(ua, "netflix-ios-app", 15) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found netflix\n");
ndpi_int_http_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_NETFLIX, NDPI_PROTOCOL_CATEGORY_STREAMING);
return;
}
}
if(flow->http.user_agent == NULL) {
int len = packet->user_agent_line.len + 1;
flow->http.user_agent = ndpi_malloc(len);
if(flow->http.user_agent) {
strncpy(flow->http.user_agent, (char*)packet->user_agent_line.ptr,
packet->user_agent_line.len);
flow->http.user_agent[packet->user_agent_line.len] = '\0';
}
}
NDPI_LOG_DBG2(ndpi_struct, "User Agent Type line found %.*s\n",
packet->user_agent_line.len, packet->user_agent_line.ptr);
ret = http_process_user_agent(ndpi_struct, flow, packet->user_agent_line.ptr, packet->user_agent_line.len);
/* TODO: Is it correct to avoid setting ua, host_name,... if we have a (Netflix) subclassification? */
if(ret != 0)
return;
}
/* check for host line */
@@ -335,6 +449,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
flow->host_server_name[len] = '\0';
flow->extra_packets_func = NULL; /* We're good now */
if(len > 0) ndpi_check_dga_name(ndpi_struct, flow, (char*)flow->host_server_name, 1);
flow->server_id = flow->dst;
if(packet->forwarded_line.ptr) {
@@ -418,7 +533,8 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
strncpy(flow->http.content_type, (char*)packet->content_line.ptr,
packet->content_line.len);
flow->http.content_type[packet->content_line.len] = '\0';
}
flow->guessed_category = flow->category = ndpi_http_check_content(ndpi_struct, flow);}
}
if(flow->http_detected) {
@@ -441,6 +557,14 @@ static void check_http_payload(struct ndpi_detection_module_struct *ndpi_struct,
/* ************************************************************* */
#ifdef NDPI_ENABLE_DEBUG_MESSAGES
static uint8_t non_ctrl(uint8_t c) {
return c < 32 ? '.':c;
}
#endif
/* ************************************************************* */
/**
* Functions to check whether the packet begins with a valid http request
* @param ndpi_struct
@@ -472,12 +596,16 @@ static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *nd
int i;
NDPI_LOG_DBG2(ndpi_struct, "====>>>> HTTP: %c%c%c%c [len: %u]\n",
non_ctrl(packet->payload[0]), non_ctrl(packet->payload[1]),
non_ctrl(packet->payload[2]), non_ctrl(packet->payload[3]),
packet->payload_packet_len > 0 ? non_ctrl(packet->payload[0]) : '.',
packet->payload_packet_len > 1 ? non_ctrl(packet->payload[1]) : '.',
packet->payload_packet_len > 2 ? non_ctrl(packet->payload[2]) : '.',
packet->payload_packet_len > 3 ? non_ctrl(packet->payload[3]) : '.',
packet->payload_packet_len);
/* Check first char */
if(!packet->payload_packet_len || !strchr(http_fs,packet->payload[0])) return 0;
if(!packet->payload_packet_len || !strchr(http_fs,packet->payload[0]))
return 0;
/**
FIRST PAYLOAD PACKET FROM CLIENT
**/
@@ -496,6 +624,106 @@ static void http_bitmask_exclude_other(struct ndpi_flow_struct *flow)
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_XBOX);
}
/* *********************************************************************************************** */
/* Trick to speed-up detection */
static const char* suspicious_http_header_keys_A[] = { "Arch", NULL};
static const char* suspicious_http_header_keys_C[] = { "Cores", NULL};
static const char* suspicious_http_header_keys_M[] = { "Mem", NULL};
static const char* suspicious_http_header_keys_O[] = { "Os", "Osname", "Osversion", NULL};
static const char* suspicious_http_header_keys_R[] = { "Root", NULL};
static const char* suspicious_http_header_keys_S[] = { "S", NULL};
static const char* suspicious_http_header_keys_T[] = { "TLS_version", NULL};
static const char* suspicious_http_header_keys_U[] = { "Uuid", NULL};
static const char* suspicious_http_header_keys_X[] = { "X-Hire-Me", NULL};
static int is_a_suspicious_header(const char* suspicious_headers[], struct ndpi_int_one_line_struct packet_line){
int i;
unsigned int header_len;
const u_int8_t* header_limit;
if((header_limit = memchr(packet_line.ptr, ':', packet_line.len))) {
header_len = header_limit - packet_line.ptr;
for(i=0; suspicious_headers[i] != NULL; i++){
if(!strncasecmp((const char*) packet_line.ptr,
suspicious_headers[i], header_len))
return 1;
}
}
return 0;
}
/* *********************************************************************************************** */
static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
u_int32_t i;
struct ndpi_packet_struct *packet = &flow->packet;
for(i=0; (i < packet->parsed_lines)
&& (packet->line[i].ptr != NULL)
&& (packet->line[i].len > 0); i++) {
switch(packet->line[i].ptr[0]){
case 'A':
if(is_a_suspicious_header(suspicious_http_header_keys_A, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'C':
if(is_a_suspicious_header(suspicious_http_header_keys_C, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'M':
if(is_a_suspicious_header(suspicious_http_header_keys_M, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'O':
if(is_a_suspicious_header(suspicious_http_header_keys_O, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'R':
if(is_a_suspicious_header(suspicious_http_header_keys_R, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'S':
if(is_a_suspicious_header(suspicious_http_header_keys_S, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'T':
if(is_a_suspicious_header(suspicious_http_header_keys_T, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'U':
if(is_a_suspicious_header(suspicious_http_header_keys_U, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
case 'X':
if(is_a_suspicious_header(suspicious_http_header_keys_X, packet->line[i])) {
NDPI_SET_BIT(flow->risk, NDPI_HTTP_SUSPICIOUS_HEADER);
return;
}
break;
}
}
}
/*************************************************************************************************/
static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
@@ -506,7 +734,8 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
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) {
if((packet->payload_packet_len > 0) /* Needed in case of extra packet processing */
&& (flow->l4.tcp.http_stage == 0)) {
/* Expected a request */
flow->http_detected = 0;
@@ -586,6 +815,13 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
return;
}
/* try to get some additional request header info even if the packet may not be HTTP */
ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->http_num_headers > 0) {
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
http_bitmask_exclude_other(flow);
return;
@@ -595,6 +831,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
"Filename HTTP found: %d, we look for line info..\n", filename_start);
ndpi_parse_packet_line_info(ndpi_struct, flow);
ndpi_check_http_header(ndpi_struct, flow);
if(packet->parsed_lines <= 1) {
NDPI_LOG_DBG2(ndpi_struct,
@@ -612,7 +849,8 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
"Found more than one line, we look further for the next packet...\n");
if(packet->line[0].len >= (9 + filename_start)
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) { /* Request line complete. Ex. "GET / HTTP/1.1" */
&& memcmp(&packet->line[0].ptr[packet->line[0].len - 9], " HTTP/1.", 8) == 0) {
/* Request line complete. Ex. "GET / HTTP/1.1" */
packet->http_url_name.ptr = &packet->payload[filename_start];
packet->http_url_name.len = packet->line[0].len - (filename_start + 9);
@@ -635,50 +873,6 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
goto ookla_found;
}
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* check PPStream protocol or iQiyi service
(iqiyi is delivered by ppstream) */
// substring in url
if(ndpi_strnstr((const char*) &packet->payload[filename_start], "iqiyi.com",
(packet->payload_packet_len - filename_start)) != NULL) {
if(flow->kxun_counter == 0) {
flow->l4.tcp.ppstream_stage++;
flow->iqiyi_counter++;
check_content_type_and_change_protocol(ndpi_struct, flow); /* ***** CHECK ****** */
return;
}
}
// additional field in http payload
x = 1;
while((packet->line[x].len >= 4) && (packet->line[x+1].len >= 5) && (packet->line[x+2].len >= 10)) {
if(packet->line[x].ptr && ((memcmp(packet->line[x].ptr, "qyid", 4)) == 0)
&& packet->line[x+1].ptr && ((memcmp(packet->line[x+1].ptr, "qypid", 5)) == 0)
&& packet->line[x+2].ptr && ((memcmp(packet->line[x+2].ptr, "qyplatform", 10)) == 0)
) {
flow->l4.tcp.ppstream_stage++;
flow->iqiyi_counter++;
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
x++;
}
#endif
#if defined(NDPI_PROTOCOL_1KXUN) || defined(NDPI_PROTOCOL_IQIYI)
/* Check for 1kxun packet */
int a;
for (a = 0; a < packet->parsed_lines; a++) {
if(packet->line[a].len >= 14 && (memcmp(packet->line[a].ptr, "Client-Source:", 14)) == 0) {
if((memcmp(packet->line[a].ptr+15, "1kxun", 5)) == 0) {
flow->kxun_counter++;
check_content_type_and_change_protocol(ndpi_struct, flow);
return;
}
}
}
#endif
if((packet->http_url_name.len > 7)
&& (!strncmp((const char*) packet->http_url_name.ptr, "http://", 7))) {
NDPI_LOG_INFO(ndpi_struct, "found HTTP_PROXY\n");
@@ -836,9 +1030,10 @@ static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struc
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod,
struct ndpi_flow_struct *flow) {
if(!flow)
if(!flow) {
NDPI_SET_BIT(flow->risk, NDPI_MALFORMED_PACKET);
return(NDPI_HTTP_METHOD_UNKNOWN);
else
} else
return(flow->http.method);
}
+6 -5
View File
@@ -65,17 +65,18 @@ static void ndpi_search_setup_iax(struct ndpi_detection_module_struct *ndpi_stru
ndpi_int_iax_add_connection(ndpi_struct, flow);
return;
}
packet_len = 12;
for (i = 0; i < NDPI_IAX_MAX_INFORMATION_ELEMENTS; i++) {
for(i = 0; i < NDPI_IAX_MAX_INFORMATION_ELEMENTS; i++) {
if ((packet_len+1) >= packet->payload_packet_len)
break;
packet_len = packet_len + 2 + packet->payload[packet_len + 1];
if (packet_len == packet->payload_packet_len) {
if(packet_len == packet->payload_packet_len) {
NDPI_LOG_INFO(ndpi_struct, "found IAX\n");
ndpi_int_iax_add_connection(ndpi_struct, flow);
return;
}
if (packet_len > packet->payload_packet_len) {
break;
}
}
}
+1 -2
View File
@@ -25,9 +25,8 @@
*/
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_IEC60870
#include "ndpi_api.h"
void ndpi_search_iec60870_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
+1 -1
View File
@@ -59,7 +59,7 @@ void ndpi_search_imo(struct ndpi_detection_module_struct *ndpi_struct, struct nd
NDPI_LOG_INFO(ndpi_struct, "found IMO\n");
ndpi_int_imo_add_connection(ndpi_struct, flow);
} else {
if(flow->num_processed_pkts > 7)
if(flow->num_processed_pkts > 5)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
else
flow->protos.imo.last_one_byte_pkt = 0;
+13 -13
View File
@@ -399,25 +399,25 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
}
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_IRC) {
if (src != NULL && ((u_int32_t)
(packet->tick_timestamp - src->irc_ts) < ndpi_struct->irc_timeout)) {
(packet->current_time_ms - src->irc_ts) < ndpi_struct->irc_timeout)) {
NDPI_LOG_DBG2(ndpi_struct, "irc : save src connection packet detected\n");
src->irc_ts = packet->tick_timestamp;
src->irc_ts = packet->current_time_ms;
} else if (dst != NULL && ((u_int32_t)
(packet->tick_timestamp - dst->irc_ts) < ndpi_struct->irc_timeout)) {
(packet->current_time_ms - dst->irc_ts) < ndpi_struct->irc_timeout)) {
NDPI_LOG_DBG2(ndpi_struct, "irc : save dst connection packet detected\n");
dst->irc_ts = packet->tick_timestamp;
dst->irc_ts = packet->current_time_ms;
}
}
if (((dst != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_IRC)
&& ((u_int32_t)
(packet->tick_timestamp - dst->irc_ts)) <
(packet->current_time_ms - dst->irc_ts)) <
ndpi_struct->irc_timeout)) || (src != NULL
&&
NDPI_COMPARE_PROTOCOL_TO_BITMASK
(src->detected_protocol_bitmask, NDPI_PROTOCOL_IRC)
&& ((u_int32_t)
(packet->tick_timestamp - src->irc_ts)) < ndpi_struct->irc_timeout)) {
(packet->current_time_ms - src->irc_ts)) < ndpi_struct->irc_timeout)) {
if (packet->tcp != NULL) {
sport = packet->tcp->source;
dport = packet->tcp->dest;
@@ -425,7 +425,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (dst != NULL) {
for (counter = 0; counter < dst->irc_number_of_port; counter++) {
if (dst->irc_port[counter] == sport || dst->irc_port[counter] == dport) {
dst->last_time_port_used[counter] = packet->tick_timestamp;
dst->last_time_port_used[counter] = packet->current_time_ms;
NDPI_LOG_INFO(ndpi_struct, "found IRC: dest port matched with the DCC port");
ndpi_int_irc_add_connection(ndpi_struct, flow);
return;
@@ -435,7 +435,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (src != NULL) {
for (counter = 0; counter < src->irc_number_of_port; counter++) {
if (src->irc_port[counter] == sport || src->irc_port[counter] == dport) {
src->last_time_port_used[counter] = packet->tick_timestamp;
src->last_time_port_used[counter] = packet->current_time_ms;
NDPI_LOG_INFO(ndpi_struct, "found IRC: Source port matched with the DCC port");
ndpi_int_irc_add_connection(ndpi_struct, flow);
return;
@@ -677,7 +677,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
if (memcmp(&packet->line[i].ptr[j], "SEND ", 5) == 0
|| (memcmp(&packet->line[i].ptr[j], "CHAT", 4) == 0)
|| (memcmp(&packet->line[i].ptr[j], "chat", 4) == 0)
|| (memcmp(&packet->line[i].ptr[j], "sslchat", 7) == 0)
|| (j+7 < packet->line[i].len && memcmp(&packet->line[i].ptr[j], "sslchat", 7) == 0)
|| (memcmp(&packet->line[i].ptr[j], "TSEND", 5) == 0)) {
NDPI_LOG_DBG2(ndpi_struct, "found CHAT,chat,sslchat,TSEND.");
j += 4;
@@ -716,7 +716,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
NDPI_LOG_DBG2(ndpi_struct, "found port=%d jjeeeeeeeeeeeeeeeeeeeeeeeee",
ntohs(get_u_int16_t(src->irc_port, 0)));
}
src->irc_ts = packet->tick_timestamp;
src->irc_ts = packet->current_time_ms;
} else if (port != 0 && src->irc_number_of_port == NDPI_PROTOCOL_IRC_MAXPORT) {
if (!ndpi_is_duplicate(src, port)) {
less = 0;
@@ -724,7 +724,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
src->irc_port[less] = port;
NDPI_LOG_DBG2(ndpi_struct, "found port=%d", ntohs(get_u_int16_t(src->irc_port, 0)));
}
src->irc_ts = packet->tick_timestamp;
src->irc_ts = packet->current_time_ms;
}
if (dst == NULL) {
break;
@@ -747,7 +747,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
NDPI_LOG_DBG2(ndpi_struct, "found port=%d", ntohs(get_u_int16_t(dst->irc_port, 0)));
NDPI_LOG_DBG2(ndpi_struct, "juuuuuuuuuuuuuuuu");
}
dst->irc_ts = packet->tick_timestamp;
dst->irc_ts = packet->current_time_ms;
} else if (port != 0 && dst->irc_number_of_port == NDPI_PROTOCOL_IRC_MAXPORT) {
if (!ndpi_is_duplicate(dst, port)) {
less = 0;
@@ -756,7 +756,7 @@ void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
NDPI_LOG_DBG2(ndpi_struct, "found port=%d", ntohs(get_u_int16_t(dst->irc_port, 0)));
}
dst->irc_ts = packet->tick_timestamp;
dst->irc_ts = packet->current_time_ms;
}
break;
+9 -9
View File
@@ -81,9 +81,9 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
ntohs(src->jabber_file_transfer_port[0]),
ntohs(src->jabber_file_transfer_port[1]));
if (((u_int32_t)
(packet->tick_timestamp - src->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
(packet->current_time_ms - src->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
NDPI_LOG_DBG2(ndpi_struct, "JABBER src stun timeout %u %u\n",
src->jabber_stun_or_ft_ts, packet->tick_timestamp);
src->jabber_stun_or_ft_ts, packet->current_time_ms);
src->jabber_file_transfer_port[0] = 0;
src->jabber_file_transfer_port[1] = 0;
} else if (src->jabber_file_transfer_port[0] == packet->tcp->dest
@@ -101,9 +101,9 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
ntohs(dst->jabber_file_transfer_port[0]),
ntohs(dst->jabber_file_transfer_port[1]));
if (((u_int32_t)
(packet->tick_timestamp - dst->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
(packet->current_time_ms - dst->jabber_stun_or_ft_ts)) >= ndpi_struct->jabber_file_transfer_timeout) {
NDPI_LOG_DBG2(ndpi_struct, "JABBER dst stun timeout %u %u\n",
dst->jabber_stun_or_ft_ts, packet->tick_timestamp);
dst->jabber_stun_or_ft_ts, packet->current_time_ms);
dst->jabber_file_transfer_port[0] = 0;
dst->jabber_file_transfer_port[1] = 0;
} else if (dst->jabber_file_transfer_port[0] == packet->tcp->dest
@@ -135,7 +135,7 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
return;
}
/* need message to or type for file-transfer */
if (memcmp(packet->payload, "<iq from=\"", 8) == 0 || memcmp(packet->payload, "<iq from=\'", 8) == 0) {
if (memcmp(packet->payload, "<iq from=\"", 10) == 0 || memcmp(packet->payload, "<iq from=\'", 10) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "JABBER <iq from=\"\n");
lastlen = packet->payload_packet_len - 11;
for (x = 10; x < lastlen; x++) {
@@ -143,11 +143,11 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
if (memcmp(&packet->payload[x], "port=", 5) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "port=\n");
if (src != NULL) {
src->jabber_stun_or_ft_ts = packet->tick_timestamp;
src->jabber_stun_or_ft_ts = packet->current_time_ms;
}
if (dst != NULL) {
dst->jabber_stun_or_ft_ts = packet->tick_timestamp;
dst->jabber_stun_or_ft_ts = packet->current_time_ms;
}
x += 6;
j_port = ntohs_ndpi_bytestream_to_number(&packet->payload[x], packet->payload_packet_len, &x);
@@ -204,11 +204,11 @@ void ndpi_search_jabber_tcp(struct ndpi_detection_module_struct *ndpi_struct, st
if (memcmp(&packet->payload[x], "port=", 5) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "port=\n");
if (src != NULL) {
src->jabber_stun_or_ft_ts = packet->tick_timestamp;
src->jabber_stun_or_ft_ts = packet->current_time_ms;
}
if (dst != NULL) {
dst->jabber_stun_or_ft_ts = packet->tick_timestamp;
dst->jabber_stun_or_ft_ts = packet->current_time_ms;
}
x += 6;
+45 -25
View File
@@ -45,6 +45,8 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t sport = packet->tcp ? ntohs(packet->tcp->source) : ntohs(packet->udp->source);
u_int16_t dport = packet->tcp ? ntohs(packet->tcp->dest) : ntohs(packet->udp->dest);
const u_int8_t *original_packet_payload = NULL;
u_int16_t original_payload_packet_len = 0;
if((sport != KERBEROS_PORT) && (dport != KERBEROS_PORT)) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
@@ -65,6 +67,8 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
flow->kerberos_buf.pktbuf_currlen += packet->payload_packet_len;
if(flow->kerberos_buf.pktbuf_currlen == flow->kerberos_buf.pktbuf_maxlen) {
original_packet_payload = packet->payload;
original_payload_packet_len = packet->payload_packet_len;
packet->payload = (u_int8_t *)flow->kerberos_buf.pktbuf;
packet->payload_packet_len = flow->kerberos_buf.pktbuf_currlen;
#ifdef KERBEROS_DEBUG
@@ -148,7 +152,7 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
|| (packet->payload[koffset] == 0x0C)
|| (packet->payload[koffset] == 0x0D)
|| (packet->payload[koffset] == 0x0E))) {
u_int16_t koffsetp, body_offset, pad_len;
u_int16_t koffsetp, body_offset = 0, pad_len;
u_int8_t msg_type = packet->payload[koffset];
#ifdef KERBEROS_DEBUG
@@ -185,8 +189,7 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
body_offset = koffsetp + 1 + pad_len;
for(i=0; i<10 && body_offset < packet->payload_packet_len; i++)
if(packet->payload[body_offset] != 0x05) body_offset++; /* ASN.1 */
for(i=0; i<10; i++) if(body_offset<packet->payload_packet_len && packet->payload[body_offset] != 0x05) body_offset++; /* ASN.1 */
#ifdef KERBEROS_DEBUG
printf("body_offset=%u [%02X %02X] [byte 0 must be 0x05]\n", body_offset, packet->payload[body_offset], packet->payload[body_offset+1]);
#endif
@@ -199,11 +202,13 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
if(body_offset < packet->payload_packet_len) {
u_int16_t name_offset;
name_offset = body_offset + 13;
for(i=0; i<20; i++) if(packet->payload[name_offset] != 0x1b) name_offset++; /* ASN.1 */
u_int16_t name_offset = body_offset + 13;
for(i=0; (i<20) && (name_offset < packet->payload_packet_len); i++) {
if(packet->payload[name_offset] != 0x1b)
name_offset++; /* ASN.1 */
}
#ifdef KERBEROS_DEBUG
printf("name_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", name_offset, packet->payload[name_offset], packet->payload[name_offset+1]);
#endif
@@ -247,36 +252,46 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
realm_offset = cname_len + name_offset + 3;
/* if cname does not end with a $ then it's a username */
if(cname_len && cname_str[cname_len-1] == '$') {
if(cname_len
&& (cname_len < sizeof(cname_str))
&& (cname_str[cname_len-1] == '$')) {
cname_str[cname_len-1] = '\0';
snprintf(flow->protos.kerberos.hostname, sizeof(flow->protos.kerberos.hostname), "%s", cname_str);
} else
snprintf(flow->protos.kerberos.username, sizeof(flow->protos.kerberos.username), "%s", cname_str);
for(i=0; i<14; i++) if(packet->payload[realm_offset] != 0x1b) realm_offset++; /* ASN.1 */
for(i=0; (i < 14) && (realm_offset < packet->payload_packet_len); i++) {
if(packet->payload[realm_offset] != 0x1b)
realm_offset++; /* ASN.1 */
}
#ifdef KERBEROS_DEBUG
printf("realm_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", realm_offset, packet->payload[realm_offset], packet->payload[realm_offset+1]);
printf("realm_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", realm_offset,
packet->payload[realm_offset], packet->payload[realm_offset+1]);
#endif
realm_offset += 1;
//if(num_cname == 2) realm_offset++;
realm_len = packet->payload[realm_offset];
if(realm_offset < packet->payload_packet_len) {
realm_len = packet->payload[realm_offset];
if((realm_offset+realm_len) < packet->payload_packet_len) {
char realm_str[48];
if((realm_offset+realm_len) < packet->payload_packet_len) {
char realm_str[48];
if(realm_len > sizeof(realm_str)-1)
realm_len = sizeof(realm_str)-1;
if(realm_len > sizeof(realm_str)-1)
realm_len = sizeof(realm_str)-1;
realm_offset += 1;
realm_offset += 1;
strncpy(realm_str, (char*)&packet->payload[realm_offset], realm_len);
realm_str[realm_len] = '\0';
for(i=0; i<realm_len; i++) realm_str[i] = tolower(realm_str[i]);
strncpy(realm_str, (char*)&packet->payload[realm_offset], realm_len);
realm_str[realm_len] = '\0';
for(i=0; i<realm_len; i++) realm_str[i] = tolower(realm_str[i]);
#ifdef KERBEROS_DEBUG
printf("[AS-REQ][Kerberos Realm][len: %u][%s]\n", realm_len, realm_str);
printf("[AS-REQ][Kerberos Realm][len: %u][%s]\n", realm_len, realm_str);
#endif
snprintf(flow->protos.kerberos.domain, sizeof(flow->protos.kerberos.domain), "%s", realm_str);
snprintf(flow->protos.kerberos.domain, sizeof(flow->protos.kerberos.domain), "%s", realm_str);
}
}
}
}
@@ -296,7 +311,7 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
printf("name_offset=%u [%02X %02X] [byte 0 must be 0x1b]\n", name_offset, packet->payload[name_offset], packet->payload[name_offset+1]);
#endif
if(name_offset < packet->payload_packet_len) {
if(name_offset < (packet->payload_packet_len - 1)) {
u_int realm_len;
name_offset++;
@@ -320,8 +335,11 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
snprintf(flow->protos.kerberos.domain, sizeof(flow->protos.kerberos.domain), "%s", realm_str);
/* If necessary we can decode sname */
if(flow->kerberos_buf.pktbuf) ndpi_free(flow->kerberos_buf.pktbuf);
if(flow->kerberos_buf.pktbuf) {
ndpi_free(flow->kerberos_buf.pktbuf);
packet->payload = original_packet_payload;
packet->payload_packet_len = original_payload_packet_len;
}
flow->kerberos_buf.pktbuf = NULL;
}
}
@@ -333,6 +351,8 @@ void ndpi_search_kerberos(struct ndpi_detection_module_struct *ndpi_struct,
/* We set the protocol in the response */
if(flow->kerberos_buf.pktbuf != NULL) {
ndpi_free(flow->kerberos_buf.pktbuf);
packet->payload = original_packet_payload;
packet->payload_packet_len = original_payload_packet_len;
flow->kerberos_buf.pktbuf = NULL;
}
+1 -1
View File
@@ -161,7 +161,7 @@ void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->payload[command_start + 4] == 'N' || packet->payload[command_start + 4] == 'n')) {
/* xxxx LOGIN "username" "password" */
char str[256], *item;
u_int len = packet->payload_packet_len > sizeof(str) ? sizeof(str) : packet->payload_packet_len;
u_int len = packet->payload_packet_len >= sizeof(str) ? sizeof(str)-1 : packet->payload_packet_len;
strncpy(str, (const char*)packet->payload, len);
str[len] = '\0';
+2 -2
View File
@@ -125,7 +125,7 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct *ndpi_struct,
&& (packet->line[a].ptr[3] == 'H' || packet->line[a].ptr[3] == 'h')
&& packet->line[a].ptr[4] == ' ') {
#ifdef SMTP_DEBUG
printf("%s() AUTH [%s]\n", __FUNCTION__, packet->line[a].ptr);
printf("%s() AUTH [%.*s]\n", __FUNCTION__, packet->line[a].len, packet->line[a].ptr);
#endif
flow->l4.tcp.smtp_command_bitmask |= SMTP_BIT_AUTH;
@@ -133,7 +133,7 @@ void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} else {
if(packet->line[a].ptr[3] != ' ') {
#ifdef SMTP_DEBUG
printf("%s() => [%s]\n", __FUNCTION__, packet->line[a].ptr);
printf("%s() => [%.*s]\n", __FUNCTION__, packet->line[a].len, packet->line[a].ptr);
#endif
if(flow->protos.ftp_imap_pop_smtp.auth_found) {
-153
View File
@@ -1,153 +0,0 @@
/*
* mdns.c
*
* Copyright (C) 2016-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MDNS
#include "ndpi_api.h"
#define NDPI_MAX_MDNS_REQUESTS 128
PACK_ON
struct mdns_header {
u_int16_t transaction_id, flags, questions, answers, authority_rr, additional_rr;
} PACK_OFF;
/**
MDNS header is similar to dns header
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ID = 0x0000 |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| FLAGS |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| QDCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ANCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| NSCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| ARCOUNT |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*/
static void ndpi_int_mdns_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MDNS, NDPI_PROTOCOL_UNKNOWN);
}
static int ndpi_int_check_mdns_payload(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
struct mdns_header *h = (struct mdns_header*)packet->payload;
u_int16_t questions = ntohs(h->questions), answers = ntohs(h->answers);
if((questions > NDPI_MAX_MDNS_REQUESTS)
|| (answers > NDPI_MAX_MDNS_REQUESTS))
return(0);
if((packet->payload[2] & 0x80) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MDNS with question query\n");
return 1;
} else if((packet->payload[2] & 0x80) != 0) {
char answer[256];
int i, j, len;
for(i=13, j=0; (i < packet->payload_packet_len) && (i < (sizeof(answer)-1)) && (packet->payload[i] != 0); i++)
answer[j++] = (packet->payload[i] < 13) ? '.' : packet->payload[i];
answer[j] = '\0';
/* printf("==> [%d] %s\n", j, answer); */
len = ndpi_min(sizeof(flow->protos.mdns.answer)-1, j);
strncpy(flow->protos.mdns.answer, (const char *)answer, len);
flow->protos.mdns.answer[len] = '\0';
NDPI_LOG_INFO(ndpi_struct, "found MDNS with answer query\n");
return 1;
}
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;
NDPI_LOG_DBG(ndpi_struct, "search MDNS\n");
/**
information from http://www.it-administrator.de/lexikon/multicast-dns.html
*/
/* check if UDP packet */
if(packet->udp != NULL) {
/* read destination port */
u_int16_t sport = ntohs(packet->udp->source);
u_int16_t dport = ntohs(packet->udp->dest);
/* check standard MDNS ON port 5353 */
if(((dport == 5353) || (sport == 5353))
&& (packet->payload_packet_len >= 12)) {
if(packet->iph != NULL) {
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) {
u_int32_t daddr_0 = packet->iphv6->ip6_dst.u6_addr.u6_addr32[0];
if(daddr_0 == htonl(0xff020000) /* && daddr[1] == 0 && daddr[2] == 0 && daddr[3] == htonl(0xfb) */) {
NDPI_LOG_INFO(ndpi_struct, "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;
}
}
}
#endif
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_mdns_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("MDNS", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_MDNS,
ndpi_search_mdns,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+1 -1
View File
@@ -21,7 +21,7 @@
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MINING
#include "ndpi_api.h"
/* ************************************************************************** */
+1 -2
View File
@@ -24,9 +24,8 @@
#include "ndpi_protocol_ids.h"
#include "ndpi_api.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MODBUS
#include "ndpi_api.h"
void ndpi_search_modbus_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
+5 -1
View File
@@ -79,7 +79,11 @@ void ndpi_search_mqtt (struct ndpi_detection_module_struct *ndpi_struct,
}
NDPI_LOG_DBG2(ndpi_struct, "====>>>> Mqtt header: %4x%4x%4x%4x [len: %u]\n",
packet->payload[0], packet->payload[1], packet->payload[2], packet->payload[3], packet->payload_packet_len);
packet->payload_packet_len > 0 ? packet->payload[0] : '.',
packet->payload_packet_len > 1 ? packet->payload[1] : '.',
packet->payload_packet_len > 2 ? packet->payload[2] : '.',
packet->payload_packet_len > 3 ? packet->payload[3] : '.',
packet->payload_packet_len);
if (packet->payload_packet_len < 2) {
NDPI_LOG_DBG(ndpi_struct, "Excluding Mqtt .. mandatory header not found!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MQTT);
-526
View File
@@ -1,526 +0,0 @@
/*
* msn.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MSN
#include "ndpi_api.h"
#define MAX_PACKETS_FOR_MSN 100
static void ndpi_int_msn_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MSN, NDPI_PROTOCOL_UNKNOWN);
}
static u_int8_t ndpi_int_find_xmsn(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if(packet->parsed_lines > 3) {
u_int16_t i;
for(i = 2; i < packet->parsed_lines; i++) {
if(packet->line[i].ptr != NULL && packet->line[i].len > NDPI_STATICSTRING_LEN("X-MSN") &&
memcmp(packet->line[i].ptr, "X-MSN", NDPI_STATICSTRING_LEN("X-MSN")) == 0) {
return 1;
}
}
}
return 0;
}
/* search over TCP */
static void ndpi_search_msn_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 = flow->src;
struct ndpi_id_struct *dst = flow->dst;
u_int16_t plen;
u_int16_t status = 0;
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_TLS) {
NDPI_LOG_DBG2(ndpi_struct, "msn ssl ft test\n");
if(flow->packet_counter < 10) {
if(flow->packet_counter == 7 && packet->payload_packet_len > 300) {
if(memcmp(packet->payload + 24, "MSNSLP", 6) == 0
|| (get_u_int32_t(packet->payload, 0) == htonl(0x30000000)
&& get_u_int32_t(packet->payload, 4) == 0x00000000)) {
NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer, ifdef ssl\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
if(flow->packet_counter >= 5 && flow->packet_counter <= 10
&& (get_u_int32_t(packet->payload, 0) == htonl(0x18000000)
&& get_u_int32_t(packet->payload, 4) == 0x00000000)) {
flow->l4.tcp.msn_ssl_ft++;
NDPI_LOG_DBG2(ndpi_struct,
"increased msn ft ssl stage to: %u at packet nr: %u\n",
flow->l4.tcp.msn_ssl_ft,
flow->packet_counter);
if (flow->l4.tcp.msn_ssl_ft == 2) {
NDPI_LOG_INFO(ndpi_struct,
"found MSN File Transfer, ifdef ssl 2.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
}
return;
}
}
}
/* we detect the initial connection only ! */
/* match: "VER " ..... "CVR" x 0x0d 0x0a
* len should be small, lets say less than 100 bytes
* x is now "0", but can be increased
*/
/* now we have a look at the first packet only. */
if(flow->packet_counter == 1
|| ((packet->detected_protocol_stack[0] == NDPI_PROTOCOL_TLS)
&& flow->packet_counter <= 3)
) {
/* this part is working asymmetrically */
if(packet->payload_packet_len > 32
&& (packet->payload[0] == 0x02 || packet->payload[0] == 0x00)
&& (ntohl(get_u_int32_t(packet->payload, 8)) == 0x2112a442
|| ntohl(get_u_int32_t(packet->payload, 4)) == 0x2112a442)
&& ((ntohl(get_u_int32_t(packet->payload, 24)) == 0x000f0004
&& ntohl(get_u_int32_t(packet->payload, 28)) == 0x72c64bc6)
|| (ntohl(get_u_int32_t(packet->payload, 20)) == 0x000f0004
&& ntohl(get_u_int32_t(packet->payload, 24)) == 0x72c64bc6))) {
NDPI_LOG_INFO(ndpi_struct,
"found MSN in packets that also contain voice.messenger.live.com.\n");
/* TODO this is an alternative pattern for video detection */
/* if (packet->payload_packet_len > 100 &&
get_u_int16_t(packet->payload, 86) == htons(0x05dc)) { */
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
/* this case works asymmetrically */
if (packet->payload_packet_len > 10 && packet->payload_packet_len < 100) {
if (get_u_int8_t(packet->payload, packet->payload_packet_len - 2) == 0x0d
&& get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x0a) {
/* The MSNP string is used in XBOX clients. */
if (ndpi_match_strprefix(packet->payload, packet->payload_packet_len, "VER ")) {
if (memcmp(&packet->payload[packet->payload_packet_len - 6], "CVR",
3) == 0 || memcmp(&packet->payload[packet->payload_packet_len - 8], "MSNP", 4) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MSN by pattern VER...CVR/MSNP ODOA\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
if (ndpi_match_strprefix(&packet->payload[4], packet->payload_packet_len-4, "MSNFT")) {
NDPI_LOG_INFO(ndpi_struct, "found MSN FT by pattern VER MSNFT...0d0a\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
}
}
if(
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
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/") &&
memcmp(packet->user_agent_line.ptr, "Messenger/", NDPI_STATICSTRING_LEN("Messenger/")) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MSN Messenger/\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
/* not seen this pattern in any trace */
/* now test for http login, at least 100 a bytes packet */
if(packet->payload_packet_len > 100) {
if(
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
memcmp(packet->payload, "POST http://", 12) == 0) {
/* scan packet if not already done... */
ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->content_line.ptr != NULL &&
((packet->content_line.len == NDPI_STATICSTRING_LEN("application/x-msn-messenger") &&
memcmp(packet->content_line.ptr, "application/x-msn-messenger",
NDPI_STATICSTRING_LEN("application/x-msn-messenger")) == 0) ||
(packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") &&
memcmp(packet->content_line.ptr, "text/x-msnmsgr",
NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) {
NDPI_LOG_INFO(ndpi_struct, "found MSN POST application/x-msn-messenger\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
}
/* now test for http login that uses a gateway, at least 400 a bytes packet */
/* for this case the asymmetric detection is asym (1) */
if(packet->payload_packet_len > 400) {
if((
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
(memcmp(packet->payload, "POST ", 5) == 0))) {
u_int16_t c;
if(memcmp(&packet->payload[5], "http://", 7) == 0) {
/*
* We are searching for a pattern "POST http://gateway.messenger.hotmail.com/gateway/gateway.dll" or
* "POST http://<some ip address here like 172.0.0.0>/gateway/gateway.dll"
* POST http:// is 12 byte so we are searching for 13 to 70 byte for this paten.
*/
for(c = 13; c < 50; c++) {
if(memcmp(&packet->payload[c], "/", 1) == 0) {
if(memcmp(&packet->payload[c], "/gateway/gateway.dll", 20) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "found pattern http://.../gateway/gateway.ddl\n");
status = 1;
break;
}
}
}
} else if((memcmp(&packet->payload[5], "/gateway/gateway.dll", 20) == 0)) {
NDPI_LOG_DBG2(ndpi_struct, "found pattern http://.../gateway/gateway.ddl\n");
status = 1;
}
}
if(status) {
u_int16_t a;
ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->content_line.ptr != NULL && ((packet->content_line.len == 23
&& memcmp(packet->content_line.ptr, "text/xml; charset=utf-8", 23) == 0)
||
(packet->content_line.len == 24
&& memcmp(packet->content_line.ptr, "text/html; charset=utf-8", 24) == 0)
||
(packet->content_line.len == 33
&& memcmp(packet->content_line.ptr, "application/x-www-form-urlencoded", 33) == 0))) {
if ((src != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)
|| (dst != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)) {
NDPI_LOG_INFO(ndpi_struct, "found MSN with pattern text/xml; charset=utf-8\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
for(a = 0; a < packet->parsed_lines; a++) {
if(packet->line[a].len >= 4 && (memcmp(packet->line[a].ptr, "CVR ", 4) == 0
|| memcmp(packet->line[a].ptr, "VER ", 4) == 0 ||
memcmp(packet->line[a].ptr, "ANS ", 4) == 0)) {
NDPI_LOG_DBG2(ndpi_struct, "found MSN with pattern text/sml; charset0utf-8\n");
NDPI_LOG_INFO(ndpi_struct, "found MSN xml CVS / VER / ANS found\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
}
}
}
/* asym (1) ; possibly occurs in symmetric cases also. */
if(flow->packet_counter <= 10 &&
(flow->packet_direction_counter[0] <= 2 || flow->packet_direction_counter[1] <= 2)
&& packet->payload_packet_len > 100) {
/* not necessary to check the length, because this has been done : >400. */
if(
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
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);
if(packet->content_line.ptr != NULL &&
((packet->content_line.len == NDPI_STATICSTRING_LEN("application/x-msn-messenger") &&
memcmp(packet->content_line.ptr, "application/x-msn-messenger", NDPI_STATICSTRING_LEN("application/x-msn-messenger")) == 0) ||
(packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") &&
memcmp(packet->content_line.ptr, "text/x-msnmsgr", NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) {
NDPI_LOG_INFO(ndpi_struct,
"found MSN application/x-msn-messenger.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
if(ndpi_int_find_xmsn(ndpi_struct, flow) == 1) {
NDPI_LOG_INFO(ndpi_struct, "found MSN X-MSN\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
}
/* did not find any trace with this pattern */
/* now block proxy connection */
if(packet->payload_packet_len >= 42) {
if(memcmp(packet->payload, "CONNECT messenger.hotmail.com:1863 HTTP/1.", 42) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MSN with pattern CONNECT messenger.hotmail.com:1863 HTTP/1.\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
if (packet->payload_packet_len >= 18) {
if (memcmp(packet->payload, "USR ", 4) == 0 || memcmp(packet->payload, "ANS ", 4) == 0) {
/* now we must see a number */
const u_int16_t endlen = packet->payload_packet_len - 12;
plen = 4;
while (1) {
if (packet->payload[plen] == ' ') {
break;
}
if (packet->payload[plen] < '0' || packet->payload[plen] > '9') {
goto ndpi_msn_exclude;
}
plen++;
if (plen >= endlen) {
goto ndpi_msn_exclude;
}
}
while (plen < endlen) {
if (ndpi_check_for_email_address(ndpi_struct, flow, plen) != 0) {
NDPI_LOG_DBG2(ndpi_struct, "found mail address\n");
break;
}
if (packet->payload_packet_len > plen + 1
&& (packet->payload[plen] < 20 || packet->payload[plen] > 128)) {
goto ndpi_msn_exclude;
}
plen++;
if (plen >= endlen) {
goto ndpi_msn_exclude;
}
}
NDPI_LOG_INFO(ndpi_struct, "found MSN with pattern USR/ANS ...mail_address\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
}
/* finished examining the first packet only. */
/* asym (1) ; possibly occurs in symmetric cases also. */
if(flow->packet_counter <= 10 &&
(flow->packet_direction_counter[0] <= 2 || flow->packet_direction_counter[1] <= 2) &&
packet->payload_packet_len > 100) {
/* not necessary to check the length, because this has been done : >400. */
if(
packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP ||
(memcmp(packet->payload, "HTTP/1.0 200 OK", 15) == 0) ||
(memcmp(packet->payload, "HTTP/1.1 200 OK", 15) == 0)) {
ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->content_line.ptr != NULL && ((packet->content_line.len == NDPI_STATICSTRING_LEN("application/x-msn-messenger") &&
memcmp(packet->content_line.ptr, "application/x-msn-messenger",
NDPI_STATICSTRING_LEN("application/x-msn-messenger")) == 0) ||
(packet->content_line.len >= NDPI_STATICSTRING_LEN("text/x-msnmsgr") &&
memcmp(packet->content_line.ptr, "text/x-msnmsgr", NDPI_STATICSTRING_LEN("text/x-msnmsgr")) == 0))) {
NDPI_LOG_INFO(ndpi_struct, "found MSN application/x-msn-messenger\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
if(ndpi_int_find_xmsn(ndpi_struct, flow) == 1) {
NDPI_LOG_INFO(ndpi_struct, "found MSN X-MSN\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
}
/* finished examining the second packet only */
/* direct user connection (file transfer,...) */
if((src != NULL && NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)
|| (dst != NULL
&& NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) != 0)) {
if (flow->packet_counter == 1 &&
packet->payload_packet_len > 12 && memcmp(packet->payload, "recipientid=", 12) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found MSN file transfer\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
return;
}
}
/* MSN File Transfer of MSN 8.1 and 8.5
* first packet with length 4 and pattern 0x04000000
* second packet (in the same direction), with length 56 and pattern 0x00000000 from payload[16]
* third packet (in the opposite direction to 1 & 2), with length 4 and pattern 0x30000000
*/
if(flow->l4.tcp.msn_stage == 0) {
/* asymmetric detection to this pattern is asym (2) */
if((packet->payload_packet_len == 4 || packet->payload_packet_len == 8)
&& get_u_int32_t(packet->payload, 0) == htonl(0x04000000)) {
NDPI_LOG_DBG2(ndpi_struct, "maybe first TCP MSN detected\n");
if(packet->payload_packet_len == 8 && get_u_int32_t(packet->payload, 4) == htonl(0x666f6f00)) {
flow->l4.tcp.msn_stage = 5 + packet->packet_direction;
return;
}
flow->l4.tcp.msn_stage = 1 + packet->packet_direction;
return;
}
/* asymmetric detection to this pattern is asym (2) */
} else if (flow->l4.tcp.msn_stage == 1 + packet->packet_direction) {
if (packet->payload_packet_len > 10 && get_u_int32_t(packet->payload, 0) == htonl(0x666f6f00)) {
ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 1\n");
return;
}
/* did not see this pattern in any trace */
if (packet->payload_packet_len == 56 && get_u_int32_t(packet->payload, 16) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "maybe Second TCP MSN detected\n");
flow->l4.tcp.msn_stage = 3 + packet->packet_direction;
return;
}
} else if (flow->l4.tcp.msn_stage == 2 - packet->packet_direction
&& packet->payload_packet_len == 4 && get_u_int32_t(packet->payload, 0) == htonl(0x30000000)) {
ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 2\n");
return;
} else if ((flow->l4.tcp.msn_stage == 3 + packet->packet_direction)
|| (flow->l4.tcp.msn_stage == 4 - packet->packet_direction)) {
if (packet->payload_packet_len == 4 && get_u_int32_t(packet->payload, 0) == htonl(0x30000000)) {
ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 2\n");
return;
}
} else if (flow->l4.tcp.msn_stage == 6 - packet->packet_direction) {
if ((packet->payload_packet_len == 4) &&
(get_u_int32_t(packet->payload, 0) == htonl(0x10000000) || get_u_int32_t(packet->payload, 0) == htonl(0x30000000))) {
ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 3\n");
return;
}
} else if (flow->l4.tcp.msn_stage == 5 + packet->packet_direction) {
if ((packet->payload_packet_len == 20) && get_u_int32_t(packet->payload, 0) == htonl(0x10000000)) {
ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found MSN File Transfer 3\n");
return;
}
}
NDPI_LOG_DBG(ndpi_struct, "msn 7\n");
if (flow->packet_counter <= MAX_PACKETS_FOR_MSN) {
if (packet->payload_packet_len >=4 && (memcmp(&packet->payload[0], "MSG ", 4) == 0
|| memcmp(&packet->payload[0], "PNG", 3) == 0
|| memcmp(&packet->payload[0], "QNG ", 4) == 0
|| memcmp(&packet->payload[0], "OUT", 3) == 0
|| memcmp(&packet->payload[0], "RNG ", 4) == 0
|| memcmp(&packet->payload[0], "NLN ", 4) == 0
|| memcmp(&packet->payload[0], "UBX ", 4) == 0
|| memcmp(&packet->payload[0], "XFR ", 4) == 0)
){
ndpi_int_msn_add_connection(ndpi_struct, flow);
NDPI_LOG_INFO(ndpi_struct, "found MSN\n");
return;
}
}
ndpi_msn_exclude:
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
/* search over UDP */
static void ndpi_search_msn_udp_misc(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
/* do we have an msn login ? */
if ((src == NULL || NDPI_COMPARE_PROTOCOL_TO_BITMASK(src->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0)
&& (dst == NULL
|| NDPI_COMPARE_PROTOCOL_TO_BITMASK(dst->detected_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0)) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
/* asymmetric ft detection works */
if (packet->payload_packet_len == 20
&& get_u_int32_t(packet->payload, 4) == 0 && packet->payload[9] == 0
&& get_u_int16_t(packet->payload, 10) == htons(0x0100)) {
NDPI_LOG_INFO(ndpi_struct, "found MSN udp misc data connection\n");
ndpi_int_msn_add_connection(ndpi_struct, flow);
}
/* asymmetric detection working. */
return;
//}
}
void ndpi_search_msn(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search msn\n");
/* this if request should always be true */
if(NDPI_COMPARE_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_MSN) == 0) {
/* we deal with tcp now */
if(packet->tcp != NULL) {
/* msn can use http or ssl for connection. That's why every http, ssl and ukn packet must enter in the msn detection */
/* the detection can switch out the http or the ssl detection. In this case we need not check those protocols */
// need to do the ceck when protocol == http too (POST /gateway ...)
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN
|| packet->detected_protocol_stack[0] == NDPI_PROTOCOL_HTTP
|| packet->detected_protocol_stack[0] == NDPI_PROTOCOL_TLS
|| packet->detected_protocol_stack[0] == NDPI_PROTOCOL_STUN
)
ndpi_search_msn_tcp(ndpi_struct, flow);
} else if (packet->udp != NULL) {
ndpi_search_msn_udp_misc(ndpi_struct, flow);
}
}
}
void init_msn_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
NDPI_BITMASK_RESET(ndpi_struct->callback_buffer[*id].excluded_protocol_bitmask);
ndpi_set_bitmask_protocol_detection("MSN", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_MSN,
ndpi_search_msn,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+6 -1
View File
@@ -51,7 +51,12 @@ void ndpi_search_mssql_tds(struct ndpi_detection_module_struct *ndpi_struct, str
NDPI_LOG_DBG(ndpi_struct, "search mssql_tds\n");
if(packet->payload_packet_len < sizeof(struct tds_packet_header)) {
if((packet->payload_packet_len < sizeof(struct tds_packet_header))
/*
The TPKT protocol used by ISO 8072 (on port 102) is similar
to this potocol and it can cause false positives
*/
|| (packet->tcp->dest == ntohs(102))) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
+1 -1
View File
@@ -40,7 +40,7 @@ void ndpi_search_mysql_tcp(struct ndpi_detection_module_struct *ndpi_struct, str
&& get_u_int8_t(packet->payload, 2) == 0x00 //3rd byte of packet length
&& get_u_int8_t(packet->payload, 3) == 0x00 //packet sequence number is 0 for startup packet
&& get_u_int8_t(packet->payload, 5) > 0x30 //server version > 0
&& get_u_int8_t(packet->payload, 5) < 0x37 //server version < 7
&& get_u_int8_t(packet->payload, 5) < 0x39 //server version < 9
&& get_u_int8_t(packet->payload, 6) == 0x2e //dot
) {
#if 0
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2020 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_NATS
#include "ndpi_api.h"
static const char* commands[] =
{
"INFO {",
"CONNECT {",
"PUB ",
"SUB",
"UNSUB ",
"MSG ",
"PING",
"PONG",
"+OK",
"-ERR",
NULL
};
void ndpi_search_nats_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
/* Check connection over TCP */
NDPI_LOG_DBG(ndpi_struct, "search NATS\n");
if(packet->tcp && (packet->payload_packet_len > 4)) {
int i;
for(i=0; commands[i] != NULL; i++) {
char *match = ndpi_strnstr((const char *)flow->packet.payload,
commands[i],
flow->packet.payload_packet_len);
if(!match) continue;
if(ndpi_strnstr((const char *)match, "\r\n",
flow->packet.payload_packet_len - ((size_t)match - (size_t)flow->packet.payload)) != NULL) {
NDPI_LOG_INFO(ndpi_struct, "found NATS\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NATS, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
}
void init_nats_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask) {
ndpi_set_bitmask_protocol_detection("Nats", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_NATS,
ndpi_search_nats_tcp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+139 -116
View File
@@ -1,8 +1,8 @@
/*
* netbios.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-20 - ntop.org
* Copyright (C) 2009-2011 by ipoque GmbH
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
@@ -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/>.
*
*
*/
@@ -29,32 +29,35 @@
#include "ndpi_api.h"
/* ****************************************************************** */
struct netbios_header {
u_int16_t transaction_id, flags, questions, answer_rrs, authority_rrs, additional_rrs;
};
/* ****************************************************************** */
/* The function below has been inherited by tcpdump */
int ndpi_netbios_name_interpret(char *in, size_t inlen, char *out, u_int out_len) {
int ret = 0, len;
int ret = 0, len, idx = inlen;
char *b;
len = (*in++)/2;
b = out;
*out = 0;
if(len > (out_len-1) || len < 1 || 2*len > inlen)
if((len > (out_len-1)) || (len < 1) || ((2*len) > inlen))
return(-1);
while (len--) {
if(in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
while(len--) {
if((idx < 2) || (in[0] < 'A') || (in[0] > 'P') || (in[1] < 'A') || (in[1] > 'P')) {
*out = 0;
break;
}
*out = ((in[0]-'A')<<4) + (in[1]-'A');
*out = ((in[0] - 'A') << 4) + (in[1] - 'A');
in += 2;
in += 2, idx -= 2;
if(isprint(*out))
out++, ret++;
@@ -69,24 +72,37 @@ int ndpi_netbios_name_interpret(char *in, size_t inlen, char *out, u_int out_len
return(ret);
}
static void ndpi_int_netbios_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) {
/* ****************************************************************** */
static void ndpi_int_netbios_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow,
u_int16_t sub_protocol) {
char name[64];
u_int off = flow->packet.payload[12] == 0x20 ? 12 : 14;
if(ndpi_netbios_name_interpret((char*)&flow->packet.payload[off], flow->packet.payload_packet_len - off, name, sizeof(name)) > 0)
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name);
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETBIOS, NDPI_PROTOCOL_UNKNOWN);
if((off < flow->packet.payload_packet_len)
&& ndpi_netbios_name_interpret((char*)&flow->packet.payload[off],
flow->packet.payload_packet_len - off, name, sizeof(name)) > 0) {
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name);
ndpi_check_dga_name(ndpi_struct, flow, (char*)flow->host_server_name, 1);
}
if(sub_protocol == NDPI_PROTOCOL_UNKNOWN)
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETBIOS, NDPI_PROTOCOL_UNKNOWN);
else
ndpi_set_detected_protocol(ndpi_struct, flow, sub_protocol, NDPI_PROTOCOL_NETBIOS);
}
/* ****************************************************************** */
void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
u_int16_t dport;
NDPI_LOG_DBG(ndpi_struct, "search netbios\n");
if(packet->udp != NULL) {
dport = ntohs(packet->udp->dest);
@@ -98,110 +114,110 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct,
h.transaction_id = ntohs(h.transaction_id), h.flags = ntohs(h.flags),
h.questions = ntohs(h.questions), h.answer_rrs = ntohs(h.answer_rrs),
h.authority_rrs = ntohs(h.authority_rrs), h.additional_rrs = ntohs(h.additional_rrs);
NDPI_LOG_DBG(ndpi_struct, "found netbios port 137 and payload_packet_len 50\n");
if(h.flags == 0 &&
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers = 0, authority = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(((h.flags & 0x8710) == 0x10) &&
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0) {
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0) {
NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers = 0, authority = 0 and broadcast \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(packet->payload[2] == 0x80 &&
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) {
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) {
NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(h.flags == 0x4000 &&
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) {
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) {
NDPI_LOG_INFO(ndpi_struct, "found netbios with questions = 1 and answers = 0, authority = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(h.flags == 0x8400 &&
h.questions == 0 &&
h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
h.questions == 0 &&
h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios with flag 8400 questions = 0 and answers = 1, authority, additional = 0 \n");
"found netbios with flag 8400 questions = 0 and answers = 1, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(h.flags == 0x8500 &&
h.questions == 0 &&
h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
h.questions == 0 &&
h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios with flag 8500 questions = 0 and answers = 1, authority, additional = 0 \n");
"found netbios with flag 8500 questions = 0 and answers = 1, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(((h.flags == 0x2900) || (h.flags == 0x2910)) &&
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) {
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 1) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios with flag 2910, questions = 1 and answers, authority=0, additional = 1 \n");
"found netbios with flag 2910, questions = 1 and answers, authority=0, additional = 1 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(h.flags == 0xAD86 &&
h.questions == 0 &&
h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
h.questions == 0 &&
h.answer_rrs == 1 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios with flag ad86 questions = 0 and answers = 1, authority, additional = 0 \n");
"found netbios with flag ad86 questions = 0 and answers = 1, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
if(h.flags == 0x0110 &&
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
h.questions == 1 &&
h.answer_rrs == 0 &&
h.authority_rrs == 0 && h.additional_rrs == 0) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios with flag 0110 questions = 1 and answers = 0, authority, additional = 0 \n");
"found netbios with flag 0110 questions = 1 and answers = 0, authority, additional = 0 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
@@ -209,111 +225,111 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_LOG_DBG2(ndpi_struct, "possible netbios name query request\n");
if(get_u_int16_t(packet->payload, 4) == htons(1) &&
get_u_int16_t(packet->payload, 6) == 0 &&
get_u_int16_t(packet->payload, 8) == 0 && get_u_int16_t(packet->payload, 10) == 0) {
get_u_int16_t(packet->payload, 6) == 0 &&
get_u_int16_t(packet->payload, 8) == 0 && get_u_int16_t(packet->payload, 10) == 0) {
/* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12];
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query request, one question\n");
"possible netbios name query request, one question\n");
if(packet->payload_packet_len == 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query request, length matches\n");
"possible netbios name query request, length matches\n");
/* null terminated? */
if(packet->payload[12 + name_length + 1] == 0 &&
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios name query request\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
"found netbios name query request\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
}
} else if((h.flags & 0xf800) == 0x8000) {
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response\n");
"possible netbios name query response\n");
if(get_u_int16_t(packet->payload, 4) == 0 &&
get_u_int16_t(packet->payload, 6) == htons(1) &&
get_u_int16_t(packet->payload, 8) == 0 && get_u_int16_t(packet->payload, 10) == 0) {
get_u_int16_t(packet->payload, 6) == htons(1) &&
get_u_int16_t(packet->payload, 8) == 0 && get_u_int16_t(packet->payload, 10) == 0) {
/* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12];
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios positive name query response, one answer\n");
"possible netbios positive name query response, one answer\n");
if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response, length matches\n");
"possible netbios name query response, length matches\n");
/* null terminated? */
if(packet->payload[12 + name_length + 1] == 0 &&
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0020) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
"found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
} else if(get_u_int16_t(packet->payload, 4) == 0 &&
get_u_int16_t(packet->payload, 6) == 0 &&
get_u_int16_t(packet->payload, 8) == 0 && get_u_int16_t(packet->payload, 10) == 0) {
get_u_int16_t(packet->payload, 6) == 0 &&
get_u_int16_t(packet->payload, 8) == 0 && get_u_int16_t(packet->payload, 10) == 0) {
/* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12];
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios negative name query response, one answer\n");
"possible netbios negative name query response, one answer\n");
if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response, length matches\n");
"possible netbios name query response, length matches\n");
/* null terminated? */
if(packet->payload[12 + name_length + 1] == 0 &&
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x000A) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x000A) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
"found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
} else if(get_u_int16_t(packet->payload, 4) == 0 &&
get_u_int16_t(packet->payload, 6) == 0 &&
get_u_int16_t(packet->payload, 8) == htons(1) && get_u_int16_t(packet->payload, 10) == htons(1)) {
get_u_int16_t(packet->payload, 6) == 0 &&
get_u_int16_t(packet->payload, 8) == htons(1) && get_u_int16_t(packet->payload, 10) == htons(1)) {
/* name is encoded as described in rfc883 */
u_int8_t name_length = packet->payload[12];
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios redirect name query response, one answer\n");
"possible netbios redirect name query response, one answer\n");
if(packet->payload_packet_len >= 12 + 1 + name_length + 1 + 2 + 2) {
NDPI_LOG_DBG2(ndpi_struct,
"possible netbios name query response, length matches\n");
"possible netbios name query response, length matches\n");
/* null terminated? */
if(packet->payload[12 + name_length + 1] == 0 &&
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0002) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
get_u_int16_t(packet->payload, 12 + name_length + 2) == htons(0x0002) &&
get_u_int16_t(packet->payload, 12 + name_length + 4) == htons(0x0001)) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
"found netbios name query response\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
@@ -322,24 +338,29 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct,
/* TODO: extend according to rfc1002 */
}
/*check standard NETBIOS over udp to port 138 */
/* check standard NETBIOS over udp to port 138 */
/*netbios header token from http://www.protocolbase.net/protocols/protocol_NBDGM.php */
/* netbios header token from http://www.protocolbase.net/protocols/protocol_NBDGM.php */
if((dport == 138) &&
packet->payload_packet_len >= 14 &&
ntohs(get_u_int16_t(packet->payload, 10)) == packet->payload_packet_len - 14) {
NDPI_LOG_DBG2(ndpi_struct, "found netbios port 138 and payload length >= 112 \n");
if(packet->payload[0] >= 0x10 && packet->payload[0] <= 0x16) {
NDPI_LOG_DBG2(ndpi_struct, "found netbios with MSG-type 0x10,0x11,0x12,0x13,0x14,0x15 or 0x16\n");
if((dport == 138) && (packet->payload_packet_len >= 14)) {
u_int16_t netbios_len = ntohs(get_u_int16_t(packet->payload, 10));
if(ntohl(get_u_int32_t(packet->payload, 4)) == ntohl(packet->iph->saddr)) {
NDPI_LOG_INFO(ndpi_struct, "found netbios with checked ip-address\n");
if(netbios_len == packet->payload_packet_len - 14) {
NDPI_LOG_DBG2(ndpi_struct, "found netbios port 138 and payload length >= 112 \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
return;
if(packet->payload[0] >= 0x10 && packet->payload[0] <= 0x16) {
u_int32_t source_ip = ntohl(get_u_int32_t(packet->payload, 4));
NDPI_LOG_DBG2(ndpi_struct, "found netbios with MSG-type 0x10,0x11,0x12,0x13,0x14,0x15 or 0x16\n");
if(source_ip == ntohl(packet->iph->saddr)) {
int16_t leftover = netbios_len - 82; /* NetBIOS len */
NDPI_LOG_INFO(ndpi_struct, "found netbios with checked ip-address\n");
ndpi_int_netbios_add_connection(ndpi_struct, flow, (leftover > 0) ? NDPI_PROTOCOL_SMBV1 : NDPI_PROTOCOL_UNKNOWN);
return;
}
}
}
}
@@ -358,9 +379,9 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct,
if(packet->payload[0] == 0x81 && packet->payload[1] == 0 && ntohs(get_u_int16_t(packet->payload, 2)) == 68) {
NDPI_LOG_INFO(ndpi_struct,
"found netbios with session request = 81, flags=0 and length od following bytes = 68. \n");
"found netbios with session request = 81, flags=0 and length od following bytes = 68. \n");
ndpi_int_netbios_add_connection(ndpi_struct, flow);
ndpi_int_netbios_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
@@ -371,6 +392,8 @@ void ndpi_search_netbios(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
/* ****************************************************************** */
void init_netbios_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("NETBIOS", ndpi_struct, detection_bitmask, *id,
+15 -4
View File
@@ -117,19 +117,24 @@ void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struc
case 5:
case 7:
case 9:
if((n == 0) || (n > 30))
if((n == 0) || (n > 30)) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
switch(version) {
case 1:
expected_len = n * sizeof(struct flow_ver1_rec) + 16 /* header */;
break;
case 5:
expected_len = n * sizeof(struct flow_ver5_rec) + 24 /* header */;
break;
case 7:
expected_len = n * sizeof(struct flow_ver7_rec) + 24 /* header */;
break;
case 9:
/* We need to check the template */
break;
@@ -142,16 +147,21 @@ void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struc
uptime_offset = 8;
break;
case 10: /* IPFIX */
{
u_int16_t ipfix_len = n;
if(ipfix_len != payload_len)
if(ipfix_len != payload_len) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
uptime_offset = 4;
break;
default:
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
@@ -167,7 +177,8 @@ void ndpi_search_netflow(struct ndpi_detection_module_struct *ndpi_struct, struc
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETFLOW, NDPI_PROTOCOL_UNKNOWN);
return;
}
}
} else
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_netflow_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+20 -3
View File
@@ -2,6 +2,23 @@
* noe.c (Alcatel new office environment)
*
* Copyright (C) 2013 Remy Mudingay <mudingay@ill.fr>
* Copyright (C) 2011-20 - 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/>.
*
*/
@@ -47,9 +64,9 @@ void ndpi_search_noe(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_int_noe_add_connection(ndpi_struct, flow);
return;
}
} else {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
+63 -33
View File
@@ -3,6 +3,29 @@
*
* Copyright (C) 2011-20 - 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/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OPENVPN
#include "ndpi_api.h"
/*
* OpenVPN TCP / UDP Detection - 128/160 hmac
*
* Detection based upon these openvpn protocol properties:
@@ -21,13 +44,6 @@
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OPENVPN
#include "ndpi_api.h"
#define P_CONTROL_HARD_RESET_CLIENT_V1 (0x01 << 3)
#define P_CONTROL_HARD_RESET_CLIENT_V2 (0x07 << 3)
#define P_CONTROL_HARD_RESET_SERVER_V1 (0x02 << 3)
@@ -72,11 +88,12 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
u_int8_t alen;
int8_t hmac_size;
int8_t failed = 0;
if(packet->payload_packet_len >= 40) {
/* No u_ */int16_t ovpn_payload_len = packet->payload_packet_len;
if(ovpn_payload_len >= 40) {
// skip openvpn TCP transport packet size
if(packet->tcp != NULL)
ovpn_payload += 2;
ovpn_payload += 2, ovpn_payload_len -= 2;;
opcode = ovpn_payload[0] & P_OPCODE_MASK;
@@ -85,16 +102,16 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
printf("[packet_id: %u][opcode: %u][Packet ID: %d][%u <-> %u][len: %u]\n",
flow->num_processed_pkts,
opcode, check_pkid_and_detect_hmac_size(ovpn_payload),
htons(packet->udp->source), htons(packet->udp->dest), packet->payload_packet_len);
htons(packet->udp->source), htons(packet->udp->dest), ovpn_payload_len);
#endif
if(
(flow->num_processed_pkts == 1)
&& (
((packet->payload_packet_len == 112)
((ovpn_payload_len == 112)
&& ((opcode == 168) || (opcode == 192))
)
|| ((packet->payload_packet_len == 80)
|| ((ovpn_payload_len == 80)
&& ((opcode == 184) || (opcode == 88) || (opcode == 160) || (opcode == 168) || (opcode == 200)))
)) {
NDPI_LOG_INFO(ndpi_struct,"found openvpn\n");
@@ -104,35 +121,46 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
}
if(flow->ovpn_counter < P_HARD_RESET_CLIENT_MAX_COUNT && (opcode == P_CONTROL_HARD_RESET_CLIENT_V1 ||
opcode == P_CONTROL_HARD_RESET_CLIENT_V2)) {
opcode == P_CONTROL_HARD_RESET_CLIENT_V2)) {
if(check_pkid_and_detect_hmac_size(ovpn_payload) > 0) {
memcpy(flow->ovpn_session_id, ovpn_payload+1, 8);
NDPI_LOG_DBG2(ndpi_struct,
"session key: %02x%02x%02x%02x%02x%02x%02x%02x\n",
flow->ovpn_session_id[0], flow->ovpn_session_id[1], flow->ovpn_session_id[2], flow->ovpn_session_id[3],
flow->ovpn_session_id[4], flow->ovpn_session_id[5], flow->ovpn_session_id[6], flow->ovpn_session_id[7]);
"session key: %02x%02x%02x%02x%02x%02x%02x%02x\n",
flow->ovpn_session_id[0], flow->ovpn_session_id[1], flow->ovpn_session_id[2], flow->ovpn_session_id[3],
flow->ovpn_session_id[4], flow->ovpn_session_id[5], flow->ovpn_session_id[6], flow->ovpn_session_id[7]);
}
} else if(flow->ovpn_counter >= 1 && flow->ovpn_counter <= P_HARD_RESET_CLIENT_MAX_COUNT &&
(opcode == P_CONTROL_HARD_RESET_SERVER_V1 || opcode == P_CONTROL_HARD_RESET_SERVER_V2)) {
(opcode == P_CONTROL_HARD_RESET_SERVER_V1 || opcode == P_CONTROL_HARD_RESET_SERVER_V2)) {
hmac_size = check_pkid_and_detect_hmac_size(ovpn_payload);
if(hmac_size > 0) {
alen = ovpn_payload[P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size)];
session_remote = ovpn_payload + P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size) + 1 + alen * 4;
u_int16_t offset = P_PACKET_ID_ARRAY_LEN_OFFSET(hmac_size);
alen = ovpn_payload[offset];
if (alen > 0) {
offset += 1 + alen * 4;
if(memcmp(flow->ovpn_session_id, session_remote, 8) == 0) {
NDPI_LOG_INFO(ndpi_struct,"found openvpn\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OPENVPN, NDPI_PROTOCOL_UNKNOWN);
return;
} else {
NDPI_LOG_DBG2(ndpi_struct,
"key mismatch: %02x%02x%02x%02x%02x%02x%02x%02x\n",
session_remote[0], session_remote[1], session_remote[2], session_remote[3],
session_remote[4], session_remote[5], session_remote[6], session_remote[7]);
if((offset+8) <= ovpn_payload_len) {
session_remote = &ovpn_payload[offset];
if(memcmp(flow->ovpn_session_id, session_remote, 8) == 0) {
NDPI_LOG_INFO(ndpi_struct,"found openvpn\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OPENVPN, NDPI_PROTOCOL_UNKNOWN);
return;
} else {
NDPI_LOG_DBG2(ndpi_struct,
"key mismatch: %02x%02x%02x%02x%02x%02x%02x%02x\n",
session_remote[0], session_remote[1], session_remote[2], session_remote[3],
session_remote[4], session_remote[5], session_remote[6], session_remote[7]);
failed = 1;
}
} else
failed = 1;
} else
failed = 1;
}
} else
failed = 1;
} else
@@ -140,10 +168,12 @@ void ndpi_search_openvpn(struct ndpi_detection_module_struct* ndpi_struct,
flow->ovpn_counter++;
if(failed) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
if(failed)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
if(flow->packet_counter > 5)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_openvpn_dissector(struct ndpi_detection_module_struct *ndpi_struct,
+1 -1
View File
@@ -43,7 +43,7 @@ void ndpi_search_oracle(struct ndpi_detection_module_struct *ndpi_struct, struct
NDPI_LOG_DBG2(ndpi_struct, "calculating ORACLE over tcp\n");
/* Oracle Database 9g,10g,11g */
if ((dport == 1521 || sport == 1521)
&& (((packet->payload[0] == 0x07) && (packet->payload[1] == 0xff) && (packet->payload[2] == 0x00))
&& (((packet->payload_packet_len >= 3 && packet->payload[0] == 0x07) && (packet->payload[1] == 0xff) && (packet->payload[2] == 0x00))
|| ((packet->payload_packet_len >= 232) && ((packet->payload[0] == 0x00) || (packet->payload[0] == 0x01))
&& (packet->payload[1] != 0x00)
&& (packet->payload[2] == 0x00)
-816
View File
@@ -1,816 +0,0 @@
/*
* oscar.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OSCAR
#include "ndpi_api.h"
#define FLAPVERSION 0x00000001
/* Flap channels */
#define SIGNON 0x01
#define DATA 0x02
#define O_ERROR 0x03
#define SIGNOFF 0x04
#define KEEP_ALIVE 0x05
/* Signon tags */
#define SCREEN_NAME 0x0001
#define PASSWD 0x0002
#define CLIENT_NAME 0x0003
#define BOS 0x0005
#define LOGIN_COOKIE 0x0006
#define MAJOR_VERSION 0x0017
#define MINOR_VERSION 0x0018
#define POINT_VERSION 0x0019
#define BUILD_NUM 0x001a
#define MULTICONN_FLAGS 0x004a
#define CLIENT_LANG 0x00OF
#define CLIENT_CNTRY 0x00OE
#define CLIENT_RECONNECT 0x0094
/* Family */
#define GE_SE_CTL 0x0001
#define LOC_SRV 0x0002
#define BUDDY_LIST 0x0003
#define IM 0x0004
#define IS 0x0006
#define ACC_ADM 0x0007
#define POPUP 0x0008
#define PMS 0x0009
#define USS 0x000b
#define CHAT_ROOM_SETUP 0x000d
#define CHAT_ROOM_ACT 0x000e
#define USER_SRCH 0x000f
#define BUDDY_ICON_SERVER 0x0010
#define SERVER_STORED_INFO 0x0013
#define ICQ 0x0015
#define INIT_AUTH 0x0017
#define EMAIL 0x0018
#define IS_EXT 0x0085
static void ndpi_int_oscar_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
struct ndpi_id_struct *src = flow->src;
struct ndpi_id_struct *dst = flow->dst;
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OSCAR, NDPI_PROTOCOL_UNKNOWN);
if(src != NULL) {
src->oscar_last_safe_access_time = packet->tick_timestamp;
}
if(dst != NULL) {
dst->oscar_last_safe_access_time = packet->tick_timestamp;
}
}
/**
Oscar connection work on FLAP protocol.
FLAP is a low-level communications protocol that facilitates the development of higher-level, datagram-oriented, communications layers.
It is used on the TCP connection between all clients and servers.
Here is format of FLAP datagram
**/
static void ndpi_search_oscar_tcp_connect(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
int excluded = 0;
// u_int8_t channel;
u_int16_t family;
u_int16_t type;
u_int16_t flag;
struct ndpi_packet_struct * packet = &flow->packet;
struct ndpi_id_struct * src = flow->src;
struct ndpi_id_struct * dst = flow->dst;
/* FLAP__Header
*
* [ 6 byte FLAP header ]
* +-----------+--------------+-------------+--------------+
* | 0x2a (1B) | Channel (1B) | SeqNum (2B) | PyldLen (2B) |
* +-----------+--------------+-------------+--------------+
*
* [ 4 byte of data ]
*
* */
if(packet->payload_packet_len >= 6 && packet->payload[0] == 0x2a)
{
/* FLAP__FRAME_TYPE (Channel)*/
u_int8_t channel = get_u_int8_t(packet->payload, 1);
/*
Initialize the FLAP connection.
SIGNON -> FLAP__SIGNON_FRAME
+--------------------------------------------------+
+ FLAP__Header | 6 byte +
+ FlapVersion | 4 byte (Always 1 = 0x00000001) +
+ TLVs | [Class: FLAP__SIGNON_TAGS] TLVs +
+--------------------------------------------------+
*/
if(channel == SIGNON && packet->payload_packet_len >= 10 &&
get_u_int16_t(packet->payload, 4) == htons(packet->payload_packet_len - 6) &&
get_u_int32_t(packet->payload, 6) == htonl(FLAPVERSION))
{
/* No TLVs */
if(packet->payload_packet_len == 10)
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Sign In \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/* /\* SCREEN_NAME *\/ */
/* if(get_u_int16_t(packet->payload, 10) == htons(SCREEN_NAME)) /\* packet->payload[10] == 0x00 && packet->payload[11] == 0x01 *\/ */
/* { */
/* NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Screen Name \n"); */
/* ndpi_int_oscar_add_connection(ndpi_struct, flow); */
/* return; */
/* } */
/* /\* PASSWD *\/ */
/* if(get_u_int16_t(packet->payload, 10) == htons(PASSWD)) /\* packet->payload[10] == 0x00 && packet->payload[11] == 0x02 *\/ */
/* { */
/* NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Password (roasted) \n"); */
/* ndpi_int_oscar_add_connection(ndpi_struct, flow); */
/* return; */
/* } */
/* CLIENT_NAME */
if(get_u_int16_t(packet->payload, 10) == htons(CLIENT_NAME)) /* packet->payload[10] == 0x00 && packet->payload[11] == 0x03 */
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Client Name \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/* LOGIN_COOKIE */
if(get_u_int16_t(packet->payload, 10) == htons(LOGIN_COOKIE) &&
get_u_int16_t(packet->payload, 12) == htons(0x0100))
{
if(get_u_int16_t(packet->payload, packet->payload_packet_len - 5) == htons(MULTICONN_FLAGS)) /* MULTICONN_FLAGS */
{
if(get_u_int16_t(packet->payload, packet->payload_packet_len - 3) == htons(0x0001))
if((get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x00) ||
(get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x01) ||
(get_u_int8_t(packet->payload, packet->payload_packet_len - 1) == 0x03))
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Login \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
}
/* MAJOR_VERSION */
if(get_u_int16_t(packet->payload, 10) == htons(MAJOR_VERSION))
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Major_Version \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/* MINOR_VERSION */
if(get_u_int16_t(packet->payload, 10) == htons(MINOR_VERSION))
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Minor_Version \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/* POINT_VERSION */
if(get_u_int16_t(packet->payload, 10) == htons(POINT_VERSION))
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Point_Version \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/* BUILD_NUM */
if(get_u_int16_t(packet->payload, 10) == htons(BUILD_NUM))
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Build_Num \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/* CLIENT_RECONNECT */
if(get_u_int16_t(packet->payload, 10) == htons(CLIENT_RECONNECT))
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Client_Reconnect \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
/*
Messages using the FLAP connection, usually a SNAC message.
DATA -> FLAP__DATA_FRAME
+-------------------------+
+ FLAP__Header | 6 byte +
+ SNAC__Header | 10 byte +
+ snac | +
+-------------------------+
SNAC__Header
+----------------------------------------------+
+ ID | 4 byte (2 foodgroup + 2 type) +
+ FLAGS | 2 byte +
+ requestId | 4 byte +
+----------------------------------------------+
*/
if(channel == DATA)
{
if(packet->payload_packet_len >= 8)
family = get_u_int16_t(packet->payload, 6);
else
family = 0;
if(packet->payload_packet_len >= 10)
type = get_u_int16_t(packet->payload, 8);
else
type = 0;
if(family == 0 || type == 0)
{
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
/* Family 0x0001 */
if(family == htons(GE_SE_CTL))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
case (0x000a): break;
case (0x000b): break;
case (0x000c): break;
case (0x000d): break;
case (0x000e): break;
case (0x000f): break;
case (0x0010): break;
case (0x0011): break;
case (0x0012): break;
case (0x0013): break;
case (0x0014): break;
case (0x0015): break;
case (0x0016): break;
case (0x0017): break;
case (0x0018): break;
case (0x001e): break;
case (0x001f): break;
case (0x0020): break;
case (0x0021): break;
default: excluded = 1;
}
}
/* Family 0x0002 */
if(family == htons(LOC_SRV))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
case (0x000a): break;
case (0x000b): break;
case (0x000c): break;
case (0x000f): break;
case (0x0010): break;
case (0x0015): break;
default: excluded = 1;
}
}
/* Family 0x0003 */
if(family == htons(BUDDY_LIST))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
case (0x000a): break;
case (0x000b): break;
case (0x000c): break;
default: excluded = 1;
}
}
/* Family 0x0004 */
if(family == htons(IM))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
case (0x000a): break;
case (0x000b): break;
case (0x000c): break;
case (0x0014): break;
default: excluded = 1;
}
}
/* Family 0x0006 */
if(family == htons(IS))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
default: excluded = 1;
}
}
/* Family 0x0007 */
if(family == htons(ACC_ADM))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
default: excluded = 1;
}
}
/* Family 0x0008 */
if(family == htons(POPUP))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
default: excluded = 1;
}
}
/* Family 0x0009 */
if(family == htons(PMS))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
case (0x000a): break;
case (0x000b): break;
default: excluded = 1;
}
}
/* Family 0x000b */
if(family == htons(USS))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
default: excluded = 1;
}
}
/* Family 0x000d */
if(family == htons(CHAT_ROOM_SETUP))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
default: excluded = 1;
}
}
/* Family 0x000e */
if(family == htons(CHAT_ROOM_ACT))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
default: excluded = 1;
}
}
/* Family 0x000f */
if(family == htons(USER_SRCH))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
default: excluded = 1;
}
}
/* Family 0x0010 */
if(family == htons(BUDDY_ICON_SERVER))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
default: excluded = 1;
}
}
/* Family 0x0013 */
if(family == htons(SERVER_STORED_INFO))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x0008): break;
case (0x0009): break;
case (0x000a): break;
case (0x000e): break;
case (0x000f): break;
case (0x0011): break;
case (0x0012): break;
case (0x0014): break;
case (0x0015): break;
case (0x0016): break;
case (0x0018): break;
case (0x001a): break;
case (0x001b): break;
case (0x001c): break;
default: excluded = 1;
}
}
/* Family 0x0015 */
if(family == htons(ICQ))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
default: excluded = 1;
}
}
/* Family 0x0017 */
if(family == htons(INIT_AUTH))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
case (0x0004): break;
case (0x0005): break;
case (0x0006): break;
case (0x0007): break;
case (0x000a): break;
case (0x000b): break;
default: excluded = 1;
}
}
/* Family 0x0018 */
if(family == htons(EMAIL))
{
/* TODO */
}
/* Family 0x0085 */
if(family == htons(IS_EXT))
{
switch (type) {
case (0x0001): break;
case (0x0002): break;
case (0x0003): break;
default: excluded = 1;
}
}
if(excluded == 1)
{
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
/* flag */
if(packet->payload_packet_len >= 12)
{
flag = get_u_int16_t(packet->payload, 10);
if(flag == htons(0x0000)|| flag == htons(0x8000) || flag == htons(0x0001))
{
if(packet->payload_packet_len >= 16)
{
/* request ID */
// u_int32_t req_ID = get_u_int32_t(packet->payload, 12);
/* if((req_ID <= ((u_int32_t)-1))) */
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
}
}
}
/*
ERROR -> FLAP__ERROR_CHANNEL_0x03
A FLAP error - rare
*/
if(channel == O_ERROR)
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Error frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/*
Close down the FLAP connection gracefully.
SIGNOFF: FLAP__SIGNOFF_CHANNEL_0x04
*/
if(channel == SIGNOFF)
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Signoff frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
/*
Send a heartbeat to server to help keep connection open.
KEEP_ALIVE: FLAP__KEEP_ALIVE_CHANNEL_0x05
*/
if(channel == KEEP_ALIVE)
{
NDPI_LOG_INFO(ndpi_struct, "found OSCAR - Keep Alive frame \n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
/* detect http connections */
if(packet->payload_packet_len >= 18) {
if((packet->payload[0] == 'P') && (memcmp(packet->payload, "POST /photo/upload", 18) == 0)) {
NDPI_PARSE_PACKET_LINE_INFO(ndpi_struct, flow, packet);
if(packet->host_line.len >= 18 && packet->host_line.ptr != NULL) {
if(memcmp(packet->host_line.ptr, "lifestream.aol.com", 18) == 0) {
NDPI_LOG_INFO(ndpi_struct,
"found OSCAR over HTTP, POST method\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
}
}
if(packet->payload_packet_len > 40) {
if((packet->payload[0] == 'G') && (memcmp(packet->payload, "GET /", 5) == 0)) {
if((memcmp(&packet->payload[5], "aim/fetchEvents?aimsid=", 23) == 0) ||
(memcmp(&packet->payload[5], "aim/startSession?", 17) == 0) ||
(memcmp(&packet->payload[5], "aim/gromit/aim_express", 22) == 0) ||
(memcmp(&packet->payload[5], "b/ss/aolwpaim", 13) == 0) ||
(memcmp(&packet->payload[5], "hss/storage/aimtmpshare", 23) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR over HTTP, GET /aim/\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
if((memcmp(&packet->payload[5], "aim", 3) == 0) || (memcmp(&packet->payload[5], "im", 2) == 0)) {
NDPI_PARSE_PACKET_LINE_INFO(ndpi_struct, flow, packet);
if(packet->user_agent_line.len > 15 && packet->user_agent_line.ptr != NULL &&
((memcmp(packet->user_agent_line.ptr, "mobileAIM/", 10) == 0) ||
(memcmp(packet->user_agent_line.ptr, "ICQ/", 4) == 0) ||
(memcmp(packet->user_agent_line.ptr, "mobileICQ/", 10) == 0) ||
(memcmp(packet->user_agent_line.ptr, "AIM%20Free/", NDPI_STATICSTRING_LEN("AIM%20Free/")) == 0) ||
(memcmp(packet->user_agent_line.ptr, "AIM/", 4) == 0))) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR over HTTP\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
NDPI_PARSE_PACKET_LINE_INFO(ndpi_struct, flow, packet);
if(packet->referer_line.ptr != NULL && packet->referer_line.len >= 22) {
if(memcmp(&packet->referer_line.ptr[packet->referer_line.len - NDPI_STATICSTRING_LEN("WidgetMain.swf")],
"WidgetMain.swf", NDPI_STATICSTRING_LEN("WidgetMain.swf")) == 0) {
u_int16_t i;
for (i = 0; i < (packet->referer_line.len - 22); i++) {
if(packet->referer_line.ptr[i] == 'a') {
if(memcmp(&packet->referer_line.ptr[i + 1], "im/gromit/aim_express", 21) == 0) {
NDPI_LOG_INFO(ndpi_struct,
"found OSCAR over HTTP : aim/gromit/aim_express\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
}
}
}
}
if(memcmp(packet->payload, "CONNECT ", 8) == 0) {
if(memcmp(packet->payload, "CONNECT login.icq.com:443 HTTP/1.", 33) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR ICQ-HTTP\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
if(memcmp(packet->payload, "CONNECT login.oscar.aol.com:5190 HTTP/1.", 40) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR AIM-HTTP\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
}
if(packet->payload_packet_len > 43
&& memcmp(packet->payload, "GET http://http.proxy.icq.com/hello HTTP/1.", 43) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR ICQ-HTTP PROXY\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
if(packet->payload_packet_len > 46
&& memcmp(packet->payload, "GET http://aimhttp.oscar.aol.com/hello HTTP/1.", 46) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR AIM-HTTP PROXY\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
if(packet->payload_packet_len > 5 && get_u_int32_t(packet->payload, 0) == htonl(0x05010003)) {
NDPI_LOG_DBG2(ndpi_struct, "Maybe OSCAR Picturetransfer\n");
return;
}
if(packet->payload_packet_len == 10 && get_u_int32_t(packet->payload, 0) == htonl(0x05000001) &&
get_u_int32_t(packet->payload, 4) == 0) {
NDPI_LOG_DBG2(ndpi_struct, "Maybe OSCAR Picturetransfer\n");
return;
}
if(packet->payload_packet_len >= 70 &&
memcmp(&packet->payload[packet->payload_packet_len - 26],
"\x67\x00\x65\x00\x74\x00\x43\x00\x61\x00\x74\x00\x61\x00\x6c\x00\x6f\x00\x67", 19) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR PICTURE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
if(NDPI_SRC_OR_DST_HAS_PROTOCOL(src, dst, NDPI_PROTOCOL_OSCAR) != 0) {
if(flow->packet_counter == 1
&&
((packet->payload_packet_len == 9
&& memcmp(packet->payload, "\x00\x09\x00\x00\x83\x01\xc0\x00\x00", 9) == 0)
|| (packet->payload_packet_len == 13
&& (memcmp(packet->payload, "\x00\x0d\x00\x87\x01\xc0", 6) == 0
|| memcmp(packet->payload, "\x00\x0d\x00\x87\x01\xc1", 6) == 0)))) {
flow->oscar_video_voice = 1;
}
#if 0
if(flow->oscar_video_voice && ntohs(get_u_int16_t(packet->payload, 0)) == packet->payload_packet_len
&& packet->payload[2] == 0x00 && packet->payload[3] == 0x00) {
}
#endif
if(packet->payload_packet_len >= 70 && ntohs(get_u_int16_t(packet->payload, 4)) == packet->payload_packet_len) {
if(memcmp(packet->payload, "OFT", 3) == 0 &&
((packet->payload[3] == '3' && ((memcmp(&packet->payload[4], "\x01\x00\x01\x01", 4) == 0)
|| (memcmp(&packet->payload[6], "\x01\x01\x00", 3) == 0)))
|| (packet->payload[3] == '2' && ((memcmp(&packet->payload[6], "\x01\x01", 2)
== 0)
)))) {
// FILE TRANSFER PATTERN:: OFT3 or OFT2
NDPI_LOG_INFO(ndpi_struct, "found OSCAR FILE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
if(memcmp(packet->payload, "ODC2", 4) == 0 && memcmp(&packet->payload[6], "\x00\x01\x00\x06", 4) == 0) {
//PICTURE TRANSFER PATTERN EXMAPLE::
//4f 44 43 32 00 4c 00 01 00 06 00 00 00 00 00 00 ODC2.L..........
NDPI_LOG_INFO(ndpi_struct, "found OSCAR PICTURE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
return;
}
}
if(packet->payload_packet_len > 40 && (memcmp(&packet->payload[2], "\x04\x4a\x00", 3) == 0)
&& (memcmp(&packet->payload[6], "\x00\x00", 2) == 0)
&& packet->payload[packet->payload_packet_len - 15] == 'F'
&& packet->payload[packet->payload_packet_len - 12] == 'L'
&& (memcmp(&packet->payload[packet->payload_packet_len - 6], "DEST", 4) == 0)
&& (memcmp(&packet->payload[packet->payload_packet_len - 2], "\x00\x00", 2) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found OSCAR PICTURE TRANSFER\n");
ndpi_int_oscar_add_connection(ndpi_struct, flow);
if(ntohs(packet->tcp->dest) == 443 || ntohs(packet->tcp->source) == 443) {
flow->oscar_ssl_voice_stage = 1;
}
return;
}
}
if(flow->packet_counter < 3 && packet->payload_packet_len > 11 && (memcmp(packet->payload, "\x00\x37\x04\x4a", 4)
|| memcmp(packet->payload, "\x00\x0a\x04\x4a",
4))) {
return;
}
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_OSCAR) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
}
void ndpi_search_oscar(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search OSCAR\n");
if(packet->tcp != NULL) {
ndpi_search_oscar_tcp_connect(ndpi_struct, flow);
}
}
void init_oscar_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Oscar", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_OSCAR,
ndpi_search_oscar,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
-167
View File
@@ -1,167 +0,0 @@
/*
* pando.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_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_PANDO
#include "ndpi_api.h"
static void ndpi_int_pando_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PANDO, NDPI_PROTOCOL_UNKNOWN);
}
static void ndpi_check_pando_tcp(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;
if (ndpi_match_strprefix(packet->payload, payload_len, "\x0ePan")) {
NDPI_LOG_INFO(ndpi_struct, "Found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
}
}
static void ndpi_check_pando_udp(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;
/* Check if we so far detected the protocol in the request or not. */
NDPI_LOG_DBG2(ndpi_struct, "PANDO stage %u: \n", flow->pando_stage);
if (flow->pando_stage == 0) {
if ((payload_len >= 4) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x09)) {
NDPI_LOG_DBG2(ndpi_struct, "Possible PANDO request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->pando_stage = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
NDPI_LOG_DBG2(ndpi_struct, "Possible PANDO request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->pando_stage = packet->packet_direction + 3; // packet_direction 0: stage 3, packet_direction 1: stage 4
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE")) {
NDPI_LOG_DBG2(ndpi_struct, "Possible PANDO request detected, we will look further for the response..\n");
/* Encode the direction of the packet in the stage, so we will know when we need to look for the response packet. */
flow->pando_stage = packet->packet_direction + 5; // packet_direction 0: stage 5, packet_direction 1: stage 6
return;
}
} else if ((flow->pando_stage == 1) || (flow->pando_stage == 2)) {
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pando_stage - packet->packet_direction) == 1) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 0) || ((payload_len >= 4) && (packet->payload[0] == 0x00) && (packet->payload[1] == 0x00) && (packet->payload[2] == 0x00) && (packet->payload[3] == 0x09))) {
NDPI_LOG_INFO(ndpi_struct, "found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PANDO, resetting the stage to 0..\n");
flow->pando_stage = 0;
}
} else if ((flow->pando_stage == 3) || (flow->pando_stage == 4)) {
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pando_stage - packet->packet_direction) == 3) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if ((payload_len == 0) || (ndpi_match_strprefix(packet->payload, payload_len, "UDPR") || ndpi_match_strprefix(packet->payload, payload_len, "UDPE"))) {
NDPI_LOG_INFO(ndpi_struct, "found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PANDO, resetting the stage to 0..\n");
flow->pando_stage = 0;
}
} else if ((flow->pando_stage == 5) || (flow->pando_stage == 6)) {
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pando_stage - packet->packet_direction) == 5) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "UDPA")) {
NDPI_LOG_INFO(ndpi_struct, "found PANDO\n");
ndpi_int_pando_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PANDO, resetting the stage to 0\n");
flow->pando_stage = 0;
}
}
}
void ndpi_search_pando(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search PANDO\n");
/* Break after 20 packets. */
if (flow->packet_counter > 20) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
/* skip marked or retransmitted packets */
if (packet->tcp_retransmission != 0) {
return;
}
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PANDO) {
return;
}
ndpi_check_pando_tcp(ndpi_struct, flow);
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PANDO) {
return;
}
ndpi_check_pando_udp(ndpi_struct, flow);
}
void init_pando_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Pando_Media_Booster", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_PANDO,
ndpi_search_pando,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
-67
View File
@@ -1,67 +0,0 @@
/*
* pcanywhere.c
*
* Copyright (C) 2009-2011 by ipoque GmbH
* Copyright (C) 2011-20 - ntop.org
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_PCANYWHERE
#include "ndpi_api.h"
static void ndpi_int_pcanywhere_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PCANYWHERE, NDPI_PROTOCOL_UNKNOWN);
}
void ndpi_search_pcanywhere(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow)
{
struct ndpi_packet_struct *packet = &flow->packet;
if (packet->udp != NULL && packet->udp->dest == htons(5632)
&& packet->payload_packet_len == 2
&& (memcmp(packet->payload, "NQ", 2) == 0 || memcmp(packet->payload, "ST", 2) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "PC Anywhere name or status query detected\n");
ndpi_int_pcanywhere_add_connection(ndpi_struct, flow);
return;
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_pcanywhere_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("PcAnywhere", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_PCANYWHERE,
ndpi_search_pcanywhere,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+2 -2
View File
@@ -97,7 +97,7 @@ void ndpi_search_postgres_tcp(struct ndpi_detection_module_struct
return;
}
size = (u_int16_t)ntohl(get_u_int32_t(packet->payload, 1)) + 1;
if (packet->payload[size - 1] == 'S') {
if (size > 0 && size - 1 < packet->payload_packet_len && packet->payload[size - 1] == 'S') {
if ((size + get_u_int32_t(packet->payload, (size + 1))) == packet->payload_packet_len) {
NDPI_LOG_INFO(ndpi_struct, "found postgres asymmetrically\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow);
@@ -105,7 +105,7 @@ void ndpi_search_postgres_tcp(struct ndpi_detection_module_struct
}
}
size += get_u_int32_t(packet->payload, (size + 1)) + 1;
if (packet->payload[size - 1] == 'S') {
if (size > 0 && size - 1 < packet->payload_packet_len && packet->payload[size - 1] == 'S') {
NDPI_LOG_INFO(ndpi_struct, "found postgres asymmetrically\n");
ndpi_int_postgres_add_connection(ndpi_struct, flow);
return;
-232
View File
@@ -1,232 +0,0 @@
/*
* pplive.c
*
* Copyright (C) 2014 Tomasz Bujlow <tomasz@skatnet.dk>
*
* The signature is mostly based on the Libprotoident library
* except the detection of HTTP Steam flows.
*
* This file is part of nDPI, an open source deep packet inspection
* library based on the OpenDPI and PACE technology by ipoque GmbH
*
* nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_PPLIVE
#include "ndpi_api.h"
static void ndpi_int_pplive_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_PPLIVE, NDPI_PROTOCOL_UNKNOWN);
}
static void ndpi_check_pplive_udp1(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;
/* Check if we so far detected the protocol in the request or not. */
if (flow->pplive_stage1 == 0) {
NDPI_LOG_DBG2(ndpi_struct, "PPLIVE stage 0: \n");
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
NDPI_LOG_DBG2(ndpi_struct, "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. */
flow->pplive_stage1 = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x42\x01")) {
NDPI_LOG_DBG2(ndpi_struct, "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. */
flow->pplive_stage1 = packet->packet_direction + 3; // packet_direction 0: stage 3, packet_direction 1: stage 4
return;
}
if (ndpi_match_strprefix(packet->payload, payload_len, "\x1c\x1c\x32\x01")) {
NDPI_LOG_DBG2(ndpi_struct, "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. */
flow->pplive_stage1 = packet->packet_direction + 5; // packet_direction 0: stage 5, packet_direction 1: stage 6
return;
}
} else if ((flow->pplive_stage1 == 1) || (flow->pplive_stage1 == 2)) {
NDPI_LOG_DBG2(ndpi_struct, "PPLIVE stage %u: \n", flow->pplive_stage1);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pplive_stage1 - packet->packet_direction) == 1) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x42\x01") || ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
NDPI_LOG_DBG2(ndpi_struct, "Found PPLIVE\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PPLIVE, resetting the stage to 0..\n");
flow->pplive_stage1 = 0;
}
} else if ((flow->pplive_stage1 == 3) || (flow->pplive_stage1 == 4)) {
NDPI_LOG_DBG2(ndpi_struct, "PPLIVE stage %u: \n", flow->pplive_stage1);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pplive_stage1 - packet->packet_direction) == 3) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
NDPI_LOG_INFO(ndpi_struct, "found PPLIVE\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PPLIVE, resetting the stage to 0..\n");
flow->pplive_stage1 = 0;
}
} else if ((flow->pplive_stage1 == 5) || (flow->pplive_stage1 == 6)) {
NDPI_LOG_DBG2(ndpi_struct, "PPLIVE stage %u: \n", flow->pplive_stage1);
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pplive_stage1 - packet->packet_direction) == 5) {
return;
}
/* This is a packet in another direction. Check if we find the proper response. */
if (ndpi_match_strprefix(packet->payload, payload_len, "\x1c\x1c\x32\x01")) {
NDPI_LOG_INFO(ndpi_struct, "Found PPLIVE\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PPLIVE, resetting the stage to 0..\n");
flow->pplive_stage1 = 0;
}
}
}
static void ndpi_check_pplive_udp2(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;
/* Check if we so far detected the protocol in the request or not. */
NDPI_LOG_DBG2(ndpi_struct, "PPLIVE stage %u: \n", flow->pplive_stage2);
if (flow->pplive_stage2 == 0) {
if ((payload_len == 57) && ndpi_match_strprefix(packet->payload, payload_len, "\xe9\x03\x41\x01")) {
NDPI_LOG_DBG2(ndpi_struct, "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. */
flow->pplive_stage2 = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
}
} else {
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pplive_stage2 - 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_INFO(ndpi_struct, "found PPLIVE\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PPLIVE, resetting the stage to 0..\n");
flow->pplive_stage2 = 0;
}
}
}
static void ndpi_check_pplive_udp3(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;
/* Check if we so far detected the protocol in the request or not. */
NDPI_LOG_DBG(ndpi_struct, "PPLIVE stage %u: \n", flow->pplive_stage3);
if (flow->pplive_stage3 == 0) {
if ((payload_len == 94) && (packet->udp->dest == htons(5041) || packet->udp->source == htons(5041) || packet->udp->dest == htons(8303) || packet->udp->source == htons(8303))) {
NDPI_LOG_DBG2(ndpi_struct, "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. */
flow->pplive_stage3 = packet->packet_direction + 1; // packet_direction 0: stage 1, packet_direction 1: stage 2
return;
}
} else {
/* At first check, if this is for sure a response packet (in another direction. If not, do nothing now and return. */
if ((flow->pplive_stage3 - 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 == 49) ||(payload_len == 94)) {
NDPI_LOG_INFO(ndpi_struct, "found PPLIVE\n");
ndpi_int_pplive_add_connection(ndpi_struct, flow);
} else {
NDPI_LOG_DBG2(ndpi_struct, "The reply did not seem to belong to PPLIVE, resetting the stage to 0..\n");
flow->pplive_stage3 = 0;
}
}
}
void ndpi_search_pplive(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet;
NDPI_LOG_DBG(ndpi_struct, "search PPLIVE\n");
/* Break after 20 packets. */
if (flow->packet_counter > 20) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PPLIVE) {
return;
}
ndpi_check_pplive_udp1(ndpi_struct, flow);
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PPLIVE) {
return;
}
ndpi_check_pplive_udp2(ndpi_struct, flow);
if (packet->detected_protocol_stack[0] == NDPI_PROTOCOL_PPLIVE) {
return;
}
ndpi_check_pplive_udp3(ndpi_struct, flow);
}
void init_pplive_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("PPLive", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_PPLIVE,
ndpi_search_pplive,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}
+1246 -101
View File
File diff suppressed because it is too large Load Diff
+5 -3
View File
@@ -40,9 +40,11 @@ static void ndpi_check_radius(struct ndpi_detection_module_struct *ndpi_struct,
if(packet->udp != NULL) {
struct radius_header *h = (struct radius_header*)packet->payload;
/* RFC2865: The minimum length is 20 and maximum length is 4096. */
if((payload_len < 20) || (payload_len > 4096))
return;
if((payload_len < 20) || (payload_len > 4096)) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
if((h->code > 0)
&& (h->code <= 13)
&& (ntohs(h->len) == payload_len)) {
+4 -1
View File
@@ -45,7 +45,7 @@ void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct,
len = packet->payload[2+offset] * 256 + packet->payload[2+offset+1];
rtcp_section_len = (len + 1) * 4;
if(((offset+rtcp_section_len) > packet->payload_packet_len) || (rtcp_section_len == 0))
if(((offset+rtcp_section_len) > packet->payload_packet_len) || (rtcp_section_len == 0) || (len == 0))
goto exclude_rtcp;
else
offset += rtcp_section_len;
@@ -60,6 +60,9 @@ void ndpi_search_rtcp(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_LOG_INFO(ndpi_struct, "found rtcp\n");
ndpi_int_rtcp_add_connection(ndpi_struct, flow);
}
if(flow->packet_counter > 3)
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} else {
exclude_rtcp:
+6 -10
View File
@@ -76,6 +76,8 @@ static u_int8_t isValidMSRTPType(u_int8_t payloadType) {
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) {
u_int8_t payloadType, payload_type;
NDPI_LOG_DBG(ndpi_struct, "search RTP\n");
if((payload_len < 2) || flow->protos.stun_ssl.stun.num_binding_requests) {
@@ -83,9 +85,8 @@ static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
return;
}
//struct ndpi_packet_struct *packet = &flow->packet;
u_int8_t payloadType, payload_type = payload[1] & 0x7F;
payload_type = payload[1] & 0x7F;
/* Check whether this is an RTP flow */
if((payload_len >= 12)
&& (((payload[0] & 0xFF) == 0x80) || ((payload[0] & 0xFF) == 0xA0)) /* RTP magic byte[1] */
@@ -105,13 +106,6 @@ static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_LOG_INFO(ndpi_struct, "Found Skype for Business (former MS Lync)\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SKYPE, NDPI_PROTOCOL_UNKNOWN);
return;
} else /* RTCP */ {
#if 0
/* If it's RTCP the RTCP decoder will catch it */
NDPI_LOG_INFO(ndpi_struct, "Found MS RTCP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RTCP, NDPI_PROTOCOL_UNKNOWN);
return;
#endif
}
}
@@ -136,6 +130,8 @@ void ndpi_search_rtp(struct ndpi_detection_module_struct *ndpi_struct, struct nd
&& (dest > 1023)
)
ndpi_rtp_search(ndpi_struct, flow, packet->payload, packet->payload_packet_len);
else
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
/* *************************************************************** */
+2 -2
View File
@@ -75,13 +75,13 @@ void ndpi_search_rtsp_tcp_udp(struct ndpi_detection_module_struct
if (dst != NULL) {
NDPI_LOG_DBG2(ndpi_struct, "found dst\n");
ndpi_packet_src_ip_get(packet, &dst->rtsp_ip_address);
dst->rtsp_timer = packet->tick_timestamp;
dst->rtsp_timer = packet->current_time_ms;
dst->rtsp_ts_set = 1;
}
if (src != NULL) {
NDPI_LOG_DBG2(ndpi_struct, "found src\n");
ndpi_packet_dst_ip_get(packet, &src->rtsp_ip_address);
src->rtsp_timer = packet->tick_timestamp;
src->rtsp_timer = packet->current_time_ms;
src->rtsp_ts_set = 1;
}
NDPI_LOG_INFO(ndpi_struct, "found RTSP\n");

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