Commit graph

585 commits

Author SHA1 Message Date
Ivan Nardi
f4995e5d5f Revert "Always compute nDPI fingerprint (#2950)"
This reverts commit 2531c2555e.
2025-08-31 19:07:13 +02:00
Ivan Nardi
2531c2555e
Always compute nDPI fingerprint (#2950) 2025-08-31 16:11:56 +02:00
Ivan Nardi
f293851eee
SSH: fix extraction of client identification string (#2949)
Close #2947
2025-08-31 11:53:31 +02:00
Ivan Nardi
1da8b85ee7
Fix compilation and unit tests (#2948)
```
ndpi_analyze.c: In function ‘ndpi_deserialize_ranking’:
ndpi_analyze.c:2244:3: warning: ignoring return value of ‘fread’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 2244 |   fread(&rank->header, sizeof(ndpi_ranking_header), 1, fd);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ndpi_main.c: In function ‘ndpi_match_host_subprotocol’:
ndpi_main.c:11798:9: warning: ‘__builtin_strncpy’ output may be truncated copying between 0 and 63 bytes from a string of length 255 [-Wstringop-truncation]
11798 |         strncpy(str, string_to_match, ndpi_min(string_to_match_len, sizeof(str)-1));
      |         ^
ndpi_main.c:11811:7: warning: ‘__builtin_strncpy’ output may be truncated copying between 0 and 63 bytes from a string of length 255 [-Wstringop-truncation]
11811 |       strncpy(str, string_to_match, ndpi_min(string_to_match_len, sizeof(str)-1));

```
2025-08-30 21:05:40 +02:00
Luca Deri
0aca481a0a Tests update 2025-08-29 11:53:35 +02:00
Luca Deri
d403d900de
nDPI Fingerprint Changes (#2946)
* Modified boundary check
nDPI fingeprint now defaults on client only (it can be changed via runtime configuration)

* Undated testcases

* Added lenght check

* Typo
2025-08-21 14:58:20 +02:00
Luca Deri
7c53fcde85 Code cleanup
Added check in fingeprinting code
2025-08-21 12:30:40 +02:00
Luca Deri
11d74ea286 Implemented nDPI fingerprint that is computed using
- TCP fingerprint
- JA4 fingepriint
- TLS SHA1 certificate (if present), or JA3S fingerprint (is SHA1 is missing)

By default the fingerprint uses the client and server fingerprints (format 0)
and combines them. However you can chnge it format (eg. use only the client info,
format 1) with

--cfg NULL,metadata.ndpi_fingerprint_format,X

where X is the fingerprint format.

By default nDPI fingerprint is enabled but you can enable/disble it as follows

--cfg NULL,metadata.ndpi_fingerprint,0
2025-08-21 10:34:49 +02:00
Ivan Nardi
2279a011c8 Fix nBPF matches 2025-08-13 10:58:40 +02:00
Ivan Nardi
087c558202 Rework calling check_tcp_flags() and check_probing_attempt() 2025-08-13 10:58:40 +02:00
Ivan Nardi
29dde6c65d
Z39.50: avoid false positives (#2938)
Close #2540
2025-08-08 10:41:38 +02:00
Ivan Nardi
f25ffea432
HTTP: fix protocol stack for some proxy flows (#2935) 2025-08-07 16:44:43 +02:00
Toni
470d0d6323
Add Mudfish protocol dissector (#2932)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2025-08-06 21:07:27 +02:00
Ivan Nardi
c5c309708b Sync unit tests results 2025-08-06 20:07:40 +02:00
Ivan Nardi
8dd2220116
Add the concept of protocols stack: more than 2 protocols per flow (#2913)
The idea is to remove the limitation of only two protocols ("master" and
"app") in the flow classifcation.
This is quite handy expecially for STUN flows and, in general, for any
flows where there is some kind of transitionf from a cleartext protocol
to TLS: HTTP_PROXY -> TLS/Youtube; SMTP -> SMTPS (via STARTTLS msg).

In the vast majority of the cases, the protocol stack is simply
Master/Application.

Examples of real stacks (from the unit tests)  different from the standard
"master/app":
* "STUN.WhatsAppCall.SRTP": a WA call
* "STUN.DTLS.GoogleCall": a Meet call
* "Telegram.STUN.DTLS.TelegramVoip": a Telegram call
* "SMTP.SMTPS.Google": a SMTP connection to Google server started in
  cleartext and updated to TLS
* "HTTP.Google.ntop": a HTTP connection to a Google domain (match via
  "Host" header) and to a ntop server (match via "Server" header)

The logic to create the stack is still a bit coarse: we have a decade of
code try to push everything in only ywo protocols... Therefore, the
content of the stack is still **highly experimental** and might change
in the next future; do you have any suggestions?

It is quite likely that the legacy fields "master_protocol" and
"app_protocol" will be there for a long time.

Add some helper to use the stack:
```
ndpi_stack_get_upper_proto();
ndpi_stack_get_lower_proto();
bool ndpi_stack_contains(struct ndpi_proto_stack *s, u_int16_t proto_id);
bool ndpi_stack_is_tls_like(struct ndpi_proto_stack *s);
bool ndpi_stack_is_http_like(struct ndpi_proto_stack *s);

```

Be sure new stack logic is compatible with legacy code:
```
assert(ndpi_stack_get_upper_proto(&flow->detected_protocol.protocol_stack) ==
       ndpi_get_upper_proto(flow->detected_protocol));
assert(ndpi_stack_get_lower_proto(&flow->detected_protocol.protocol_stack) ==
       ndpi_get_lower_proto(flow->detected_protocol));
```
2025-08-01 10:05:50 +02:00
Ivan Nardi
79f0cbd32a
Whois/DAS: avoid false positives (#2925)
Close #2922
2025-07-30 20:11:07 +02:00
Ivan Nardi
44b9a2da81
ndpiReader: add breed to flow information (#2924) 2025-07-30 18:46:28 +02:00
Ivan Nardi
ade7c9fec7
Google, Signal: fix breed value (#2920)
Use the same breed value for both standard and content-matching
classification
2025-07-29 18:02:19 +02:00
Ivan Nardi
ae48c8df7a Workaround for big-endian builds
Fix CI tests on big-endian builds.
We have a long-standing issue on big-endian archs: it might be related
to utash or about how we use utash in ndpiReader
2025-07-19 16:44:56 +02:00
Adrian Pekar
5f312c0cd6
Fix JA4 fingerprinting (#2915)
* Fix JA4 ALPN fingerprint to use first and last characters

According to the JA4 specification (line 2139), the ALPN field should
contain the first and last characters of the first ALPN extension value.

Currently, nDPI uses the first and second characters (alpn[0] and alpn[1]),
which produces incorrect fingerprints that don't match other JA4
implementations like Wireshark.

For example, with ALPN 'http/1.1':
- Current (incorrect): 'ht' (first + second char)
- Fixed (correct):     'h1' (first + last char)

This change ensures nDPI's JA4 implementation conforms to the official
specification and maintains interoperability with other JA4 tools.

Fixes: Incorrect JA4 ALPN fingerprint generation

* Fix JA4 ALPN implementation to correctly parse first ALPN protocol

The previous fix attempted to use strlen(ja->client.alpn)-1 but this was
insufficient because nDPI modifies the ALPN string by:
1. Adding null terminators that truncate the last character
2. Converting semicolons to dashes, affecting multi-protocol ALPNs

This complete fix:
- Adds alpn_original_last field to store the true last character
- Captures the last character of the FIRST ALPN protocol only (before ;/,)
- Preserves the original character before nDPI's string modifications

Now correctly implements JA4 spec: first + last characters of first ALPN protocol
Examples:
- ALPN 'h2;http/1.1' -> 'h2' (not 'h.' or 'h1')
- ALPN 'http/1.1' -> 'h1' (not 'ht' or 'h.')

Fixes: #2914

* Fix JA4 SNI detection to properly handle missing SNI extensions

Previously, nDPI incorrectly set JA4 SNI flag to 'd' (domain present) for
flows without any SNI extension. This was because the logic only checked
for NDPI_NUMERIC_IP_HOST risk (set when SNI contains IP) but didn't
distinguish between missing SNI and domain SNI.

Now properly detects:
- No SNI extension → 'i' flag
- SNI with IP address → 'i' flag
- SNI with domain → 'd' flag

This matches the JA4 specification.
2025-07-10 14:03:27 +02:00
Luca Deri
f8e1c6f346 Results update 2025-07-08 17:51:09 +02:00
kalinda
9efd3cfb33
Add Blacknut ,Boosteroid and Rumble protocol(SNI detection WIP) (#2907)
Co-authored-by: Ivan Nardi <nardi.ivan@gmail.com>
2025-07-03 21:41:17 +02:00
Toni
a913e914e5
Added EasyWeather protocol dissector (#2912)
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2025-07-03 12:28:48 +02:00
Ivan Nardi
81ca06b0c7 websocket: ndpi_set_detected_protocol() should be called only once
Fix: b07a910dc
2025-07-02 08:28:11 +02:00
Ivan Nardi
43b60e3d7a
Rework classification in ndpi_match_host_subprotocol()-like functions (#2910) 2025-07-01 17:01:59 +02:00
Ivan Nardi
e5dbe83ecf Jabber: proper subclassification of TruPhone 2025-07-01 12:35:35 +02:00
Ivan Nardi
eb50750a3b Remove some hack for Google traffic in ndpi_reconcile_protocols() 2025-07-01 12:35:35 +02:00
Ivan Nardi
898135b2f7 Fix ndpi_reconcile_protocols with classification by port/ip 2025-07-01 12:35:35 +02:00
Ivan Nardi
ed1e6e2a39 Fix classification with nBPF rules 2025-07-01 12:35:35 +02:00
Ivan Nardi
86c591af6a
Bittorrent: update default ports (#2902) 2025-06-23 19:38:31 +02:00
Ivan Nardi
e0b14cc3fb
STUN: don't check NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT flow risk (#2901) 2025-06-23 18:15:48 +02:00
Ivan Nardi
06a49b4086 ndpiReader: fix check on max number of packets per flow 2025-06-23 17:27:39 +02:00
Ivan Nardi
64ea82ce28 Viber: fix category 2025-06-23 17:15:24 +02:00
Ivan Nardi
5db40f7598
Classify Tracking/ADS/Analytics traffic only via category (#2900)
See 3a243bb40 for similar work about porn and LLM
2025-06-23 16:03:44 +02:00
Ivan Nardi
aa6dcad15e
ndpiReader: print categories summary (#2895) 2025-06-21 12:41:00 +02:00
Luca Deri
3a243bb40d Merged protocols (now free to use) into existing categories
- AdultContent -> Category Adult Content
- LLM          -> Category Artificial Intelligence
2025-06-17 23:57:15 +02:00
Vladimir Gavrilov
aba60ac354
Add GLBP dissector (#2879)
GLBP is a Cisco proprietary first-hop redundancy protocol similar to HSRP and VRRP, but with additional load balancing capabilities.
2025-06-10 15:26:10 +02:00
Ivan Nardi
30ebb91a3b
Simplify ndpi_internal_detection_process_packet() (#2877)
Simplify process of each packet
2025-06-10 13:41:27 +02:00
Vladimir Gavrilov
75395cb264
Add category and breed support for custom rules (#2872)
Close #2594
2025-06-08 17:34:21 +02:00
Luca Deri
38fe9859b3 Fixes invalid SSH client/server detection based on stage and not on packet direction 2025-06-08 16:12:41 +02:00
Ivan Nardi
5e895f91ea
Sync unit tests results and fix NDPI_HTTP_SUSPICIOUS_HEADER (#2874) 2025-06-08 14:01:10 +02:00
Ivan Nardi
cc99039e1f Sync unit tests results 2025-06-08 13:04:05 +02:00
Luca Deri
2a77c58ebe Improved HTTP risk report
PCRE2 is now enabled (if present) by default as necessary to report some HTTP risks
2025-06-08 07:33:19 +02:00
Vladimir Gavrilov
6d0a891d1e
Normalize breed/category names: use _ instead of spaces and slashes (#2873) 2025-06-07 12:38:14 +02:00
Luca Deri
38cc4ac22b Added IMO and Badoo files 2025-06-06 16:48:41 +02:00
Ivan Nardi
a8ad57bab2 Sync unit tests results 2025-06-05 14:37:53 +02:00
Ivan Nardi
a4b1a14149 Sync unit tests results 2025-06-05 13:42:43 +02:00
Luca Deri
ed6f257f1d Improved HTTP risk message report 2025-06-05 13:19:13 +02:00
Vladimir Gavrilov
40fe26b2f1
Add Hamachi protocol detection support (#2860) 2025-06-02 14:00:31 +02:00
Luca Deri
c36e4bd5de Updated bots and scanners list
Improved lists file parsing
2025-05-29 10:38:24 +02:00