Commit graph

1619 commits

Author SHA1 Message Date
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
17e1ed00c5 DNS: ndpi_match_host_subprotocol() should be called only once 2025-07-01 21:09:34 +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
6cbc8d1471
fuzz: fuzz loading of external protocols lists (#2897) 2025-06-22 20:43:16 +02:00
Ivan Nardi
aa6dcad15e
ndpiReader: print categories summary (#2895) 2025-06-21 12:41:00 +02:00
Ivan Nardi
a671226078
Rework default ports initialization (#2893)
Default ports trees are initialized during
`ndpi_finalize_initialization()`

Make `ndpi_init_detection_module()` less likely to fail, because there
are less memory allocations.
2025-06-20 17:54:12 +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
Ivan Nardi
57d529f74f
No limits on the number of (custom) protocols (#2875)
The hard limit of total number of protocols (internal and custom) is ~65535,
because protocol ids are `u_int16_t`...

API changes:
1. From `NDPI_MAX_SUPPORTED_PROTOCOLS + NDPI_MAX_NUM_CUSTOM_PROTOCOLS` to
`ndpi_get_num_protocols()` (after having called
`ndpi_finalize_initialization()`);

2. From `proto_id >= NDPI_MAX_SUPPORTED_PROTOCOLS` to
`ndpi_is_custom_protocol(proto_id)` (after having called
`ndpi_finalize_initialization()`);

Close #2136
Close #2545
2025-06-16 14:04:56 +02:00
Ivan Nardi
28ae2e14d8
Check ndpi_finalize_initialization() return value (#2884) 2025-06-14 11:31:23 +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
0e00318d7c
Dynamic allocation of ndpi_struct->proto_defaults[] (#2866)
Partial revert of 88bfe2cf0: in the trees we save the index and no more
a pointer to `ndpi_struct->proto_defaults[]`.

Remove same functions from public API

See #2136
2025-06-06 12:18:09 +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
Ivan Nardi
f287a6e7f8
Add a configuration to test a huge number of custom protocols (#2865)
File taken from #2136
2025-06-03 20:46:58 +02:00
Ivan Nardi
70a72f1638
New API to enable/disable protocols; remove ndpi_set_protocol_detection_bitmask2() (#2853)
The main goal is not to have the bitmask depending on the total number
of protocols anymore: `NDPI_INTERNAL_PROTOCOL_BITMASK` depends only on
internal protocols, i.e. on `NDPI_MAX_INTERNAL_PROTOCOLS`, i.e.
custom-defined protocols are not counted.
See #2136

Keep the old data structure `NDPI_PROTOCOL_BITMASK` with the old
semantic.

Since we need to change the API (and all the application code...)
anyway, simplify the API: by default all the protocols are enabled.
If you need otherwise, please use `ndpi_init_detection_module_ext()`
instead of `ndpi_init_detection_module()` (you can find an example in
the `ndpiReader` code).

To update the application code you likely only need to remove these 3
lines from your code:
```
- NDPI_PROTOCOL_BITMASK all;
- NDPI_BITMASK_SET_ALL(all);
- ndpi_set_protocol_detection_bitmask2(ndpi_str, &all);
```

Removed an unused field and struct definition.
2025-06-03 09:45:46 +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
Ivan Nardi
651daeb01a
Fix configuration of ip lists of flow risks (#2859)
Add some new tests about these configuration parameters.

Close #2858
2025-05-28 20:19:19 +02:00
Luca Deri
9e5a67f369 Improved detection of TCP scanners 2025-05-27 22:17:38 +02:00
Ivan Nardi
1f5378efb8
Allow to specify default ports also via range (#2856)
Ad a trivial example, update SIP configuration to use range
2025-05-27 19:11:35 +02:00
Ivan Nardi
1e3cc3938b Sync unit tests results 2025-05-27 10:26:10 +02:00
Ivan Nardi
8350cc68d4
BFCP: fix check on payload length and extract metadata (#2854)
We should be able to identified this protocol on the first packet,
without keeping any state

Close #2745
2025-05-26 15:08:53 +02:00
Ivan Nardi
03e1e593d1
Dofus: update detection to version 3.X (#2852)
See #2827
2025-05-25 20:06:12 +02:00
Ivan Nardi
78f4b60efe
A new interface for dissectors registration (#2843)
We use `registr_dissector()` instead of
`ndpi_set_bitmask_protocol_detection()`.

Every file in `src/lib/protocols/*.c` is a dissector.

Every dissector can handle multiple protocols.

The real goal is this small change:
```
 struct call_function_struct {
-  NDPI_PROTOCOL_BITMASK detection_bitmask;
```
i.e. getting rid of another protocol bitmask: this is mandatory to try
to fix #2136 (see also e845e8205b68752c997d05224d8b2fd45acde714)

As a nice side effect, we remove a bitmask comparison in the hot function
`check_ndpi_detection_func()`

TODO: change logging configuration from per-protocol to per-dissector
2025-05-24 13:17:46 +02:00
Luca Deri
c1d3728602 Added the support for multiple TCP fingerprint format
- default (0) is the native nDPI format
- MuonOF (1) has been added

The format can be changed using metadata.tcp_fingerprint_format

Added ability to identify mass scanners using TCP fingerprint
2025-05-24 10:30:33 +02:00
Vladimir Gavrilov
afc0da6468
Simplify ZeroMQ detection (#2847) 2025-05-23 16:09:16 +02:00
Vladimir Gavrilov
74cb03eb4c
Add MELSEC protocol support (#2846) 2025-05-23 11:13:52 +02:00