Commit graph

5997 commits

Author SHA1 Message Date
Ivan Nardi
30aae910ed Kerberos: export S4U (S4U2Self and S4U2Proxy) requests
With S4U (MS-SFU) a service requests a ticket on behalf of a user: the
client name of the reply is the user, but the client of the flow is the
service. Without knowing it, the users of the metadata bind the user to
the host of the service.

Export it in the new field "s4u", set for the first TGS-REQ with:
- PA-FOR-USER (129) or PA-S4U-X509-USER (130): S4U2Self
- the cname-in-addl-tkt KDC option: S4U2Proxy (constrained delegation);
  additional tickets without this option are user-to-user
2026-11-05 13:28:09 +01:00
Ivan Nardi
877a9a919d ndpiReader: print the name of the Kerberos name type
E.g. "[Name type: 10 (NT-ENTERPRISE)]" (RFC 4120, RFC 6111, MS-KILE).
2026-11-05 13:28:09 +01:00
Ivan Nardi
5e46f85b98 Kerberos: don't export service principals as usernames; export the name type
With a client name of two components, only "host/x" and "ldap/x" were
handled (the second component is the machine): for any other service
principal (e.g. "nfs/server.corp.local" or "HTTP/web.corp.local", used by
logins with a keytab) the service was exported as the username ("nfs",
"http"). Now neither the username nor the hostname are set.

Export also the name type of the client name (e.g. 1 principal, 2/3
service, 6 X.500, 10 enterprise, -128 MS principal), so that the users of
the metadata can tell what kind of name it is.
2026-11-05 13:28:09 +01:00
Ivan Nardi
78eab27911 Kerberos: export the client name and realm of the reply
Names and realm were taken from the first message carrying them, usually
the request, that is set by the client: e.g. the realm of an AS-REQ can be
the short name of the domain ("CORP" instead of "CORP.LOCAL") and the
client name an enterprise principal ("alice@corp.com" instead of "alice").

The crealm and cname of the first successful reply (AS-REP/TGS-REP), set
by the KDC, now replace the ones of the request; requests and KRB-ERROR
still keep the first values seen. When the name is replaced, both the
username and the hostname are reset, as only one of them is set.
2026-11-05 13:28:09 +01:00
Ivan Kapranov
4a2a7611ad
TLS: added decode of ML-DSA sig algs (#3308) 2026-11-05 13:02:55 +01:00
Ivan Nardi
6b38c1c258
serializer: reject over-length strings instead of truncating (GHSA-q2gg-6j82-vwj5) (#3310)
ndpi_serialize_string_string() computed the value length with strlen()
and passed it into the u_int16_t value_len parameter of
ndpi_serialize_string_string_len(), silently truncating any value longer
than 65535 bytes (mod 65536). Fail with -1 instead.

Add serializerCsvMaxLengthUnitTest() covering the longest representable
value, rejection of an over-length value, and that the serializer stays
usable afterwards.
2026-11-03 17:36:56 +01:00
Luca Deri
679f31085f Various JSON/CSV serialization/.deserialization fixes 2026-11-03 14:08:31 +01:00
Ivan Nardi
f6caffea17
serializer: fix 16-bit wrap in the string size of the deserializer (#3309) 2026-11-03 11:07:51 +01:00
mmanoj
7393261e88
dns: harden any-port UDP detection (#3246) 2026-11-02 20:03:42 +01:00
Ivan Nardi
0c81498aa1
L2TP: fix out-of-bounds read on short control messages (#3307)
```
==253==ERROR: AddressSanitizer: use-after-poison on address 0x7a0db66b5828 at pc 0x5893db2adbf9 bp 0x7ffed45d3fc0 sp 0x7ffed45d3fb8
READ of size 2 at 0x7a0db66b5828 thread T0
    #0 0x5893db2adbf8 in ndpi_get_u_int16_t ndpi/src/include/ndpi_define.h:145:3
    #1 0x5893db2adbf8 in ndpi_int_l2tp_dissect_attrs ndpi/src/lib/protocols/l2tp.c:53:36
    #2 0x5893db2adbf8 in ndpi_search_l2tp ndpi/src/lib/protocols/l2tp.c:107:5
    #3 0x5893db1d2c57 in check_ndpi_detection_func ndpi/src/lib/ndpi_main.c:9277:6
```
Found by oss-fuzz
See: https://issues.oss-fuzz.com/issues/580370355?pli=1

While at it, fix an off-by-one in the AVP loop bounds checks, which
skipped an attribute ending exactly at the end of the packet.
2026-11-02 09:27:31 +01:00
Ivan Nardi
0d0d926fad
ndpiReader: remove the info of a risk cleared after the detection (#3306)
ndpiReader clears the unidirectional traffic risk when a packet comes
back after the detection (as nDPI asks the applications to do), but the
info of the risk, copied as a string when the detection was completed,
was still printed.

The flow now keeps a copy of the infos of its risks, by risk, instead of
the string: clearing a risk removes also its info, and the text is built
when required.
2026-11-02 09:14:32 +01:00
Ivan Nardi
fbada8eac5 fuzz: add fuzz_alg_asn1_ber fuzzer for the ASN.1 BER helpers
Fuzz the public `ndpi_asn1_ber_decode_*()` functions, walking all the
(nested) TLVs and checking some basic invariants on the decoded values.

The initial corpus has real messages extracted from the test pcaps
(SNMP, Kerberos, LDAP), a X.509 certificate and some hand-crafted
edge cases (length/tag encodings, integers, deep nesting).

Update .gitignore with some missing fuzzing artifacts.
2026-11-02 09:10:29 +01:00
Ivan Nardi
7e36be6c09 fuzz: avoid real DNS queries in ndpi_add_host_ip_subprotocol()
While fuzzing, symbolic hostnames in protocol files triggered real
getaddrinfo() lookups. In the oss-fuzz sandbox these can block in the
resolver until the run is aborted, causing sporadic, non reproducible
ABRT reports (in sendmmsg/res_send). Use AI_NUMERICHOST in fuzzing builds.
2026-11-02 09:10:29 +01:00
Luca Deri
0b5f522d45 Win fixes 2026-11-01 18:27:26 +01:00
Ivan Nardi
bf4696f36c
SNMP, LDAP: use the ASN.1 BER TLV API (#3304)
SNMP: rewrite the dissector using `ndpi_asn1_ber_decode_*()`.
This fixes:
* community strings longer than 127 bytes (long-form length)
* 8-bit offsets wrapping on packets longer than 255 bytes
* unchecked length decoding errors in the GetResponse parsing

LDAP: properly decode the messageID TLV, instead of assuming a
single-byte (short form) length.
2026-10-30 20:26:22 +01:00
Ivan Nardi
ff44ed290e
DCERPC: fix endianness of fragment length in TCP reassembly (GHSA-4x7j-8w5q-5f7w) (#3303)
`dcerpc_tcp_get_fragment_len()` had the data representation check
inverted: little endian PDUs (i.e. basically all Windows traffic) got
their fragment length byte-swapped, so TCP reassembly never worked and
remote administration BINDs split across multiple segments were missed.

DHCP: don't advance options/fingerprint offsets past the buffer end when
`ndpi_snprintf` truncates its output. This is only hardening: the
overshot offsets were never used to access memory.

Credits to @ccsimplyspolit
2026-10-30 18:31:25 +01:00
Weiqi Wang
cd3c030316
Merge commit from fork
* stun: cap recursion depth in stun_search_again()

stun_search_again() recurses without a depth limit when dissecting
nested encapsulations: TURN ChannelData frames, MS-TURN messages,
STUN DATA attributes and the Telegram custom encapsulation all
re-enter it. A crafted ~64 KB UDP datagram (16376 nested ChannelData
frames) exhausts the dissection thread stack and crashes the process
(e.g. ndpiReader bus error on the default 512 KB macOS worker stack
already at ~6700 nested frames).

Bound the recursion with a counter stored in the 4 spare padding bits
of the stun flow metadata (no struct size change): every descent now
re-enters through a wrapper that increments recursion_depth and stops
recursing past NDPI_MAX_STUN_RECURSION_DEPTH (15). Legitimate traffic
nests at most 1-2 levels, so the cap is far above any real usage.

Verified: nested-TURN pcaps that crash the unpatched build (depth
6679+, bus error) now dissect cleanly, and shallow nested traffic is
still classified as STUN.

* tests: add nested TURN ChannelData pcaps for the stun recursion cap

Two synthetic flows (STUN Allocate + one datagram of N nested TURN
ChannelData frames):

- stun_turn_nested_d3.pcap: shallow legitimate-style nesting, must
  dissect as STUN.
- stun_turn_nested_d32.pcap: nesting past NDPI_MAX_STUN_RECURSION_DEPTH,
  exercises the depth-limit path; must still dissect cleanly.

All pre-existing stun/turn expected outputs are unchanged with the cap
in place.

* tests: add Send Indication carrying ChannelData (valid 3-level nesting)

A protocol-permitted multi-level encapsulation: STUN Send Indication
(RFC 5766, type 0x0016) whose DATA attribute (0x0013) carries a TURN
ChannelData frame wrapping RTP. Drives stun_search_again() to recursion
depth 3 through the legitimate path — the case a depth-1 limit would
break. Dissects as STUN with the cap in place.

* Address review: cap at 4, single stun_recursion.pcap test

- NDPI_MAX_STUN_RECURSION_DEPTH 15 -> 4, per maintainer review; real
  traffic nests at most 2-3 levels.
- Replace the three separate test pcaps with one stun_recursion.pcap
  containing four flows (STUN Allocate + one datagram each): 3 nested
  ChannelData frames (shallow valid), a Send Indication carrying
  ChannelData over RTP (valid 3-level path), 32 nested frames (past the
  cap), and the full-size 16376-frame datagram from the original report.
  All four flows dissect cleanly as STUN with the fix.
- All pre-existing stun/turn expected outputs re-verified unchanged with
  the lower cap.

* Address review: 3-bit recursion counter, keep 1 padding bit
2026-10-30 09:01:57 +01:00
Toni
b17e3ae776
Add L2TP protocol dissector (#3301)
* dissect L2TP hostname

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
2026-10-29 10:15:27 +01:00
Ivan Nardi
d886a5d698
ASN.1: make BER helpers public and fix some bugs (#3302)
Export the BER decoding helpers with the `ndpi_` prefix.

Fixes:
* 0x80 length octet (indefinite form) was decoded as a short length of 128
* long-form length rejected when the buffer ended right after the length octets
* `value_len` was written even on failure
* `ndpi_asn1_ber_decode_tlv()` return value could overflow with huge buffers
2026-10-28 14:20:46 +01:00
Ivan Nardi
1e360a78af
TLS: improve sub-classification for Obfuscated traffic (#3297)
Try to detect the specific VPN.

See: https://github.com/ntop/nDPI/pull/3277
2026-10-28 11:41:27 +01:00
Ivan Nardi
654637aa80 SMB: fix memory leak 2026-10-27 19:51:35 +01:00
Luca Deri
b22957735c Added Windows define 2026-10-27 18:43:43 +01:00
Luca Deri
3ccdd4f5bc Added #define 2026-10-27 18:15:03 +01:00
Luca Deri
cbc2a894ea Updated test results 2026-10-27 17:30:19 +01:00
Luca Deri
f3a562f0d0 SMB detects file name and returs it in metadata
Renamed ends_with with ndpi_ends_with
2026-10-27 17:24:04 +01:00
Ivan Nardi
d9aa834639
PowerShell: detect Active Directory Web Services and Task Scheduler traffic (#3300)
* Active Directory Web Services (ADWS, TCP/9389), used by the PowerShell
  ActiveDirectory module (Get-ADUser & co.): new dissector looking at the
  clear-text .NET Message Framing (MC-NMF) preamble sent by the client
* Task Scheduler (MS-TSCH, i.e. schtasks.exe, atexec): "atsvc" named pipe
  over SMB and ITaskSchedulerService/ATSvc/SASec interfaces in DCE/RPC BIND
  requests
2026-10-27 13:50:45 +01:00
Ivan Nardi
ca9d819151
softEther: fix out-of-bounds read (#3298)
Close: #3291

Reported by HaiND (Nguyen Dinh Hai), Post and Telecommunication
Institute of Technology, github.com/Haind03
2026-10-26 17:35:39 +01:00
Jasper
e968138d8e
Serializer: fully restore the initial state in ndpi_reset_serializer() (#3299)
* TLV: rewrite the version/format header bytes, which may have been
  overwritten after ndpi_serializer_set_buffer_len()
* discard any snapshot taken before the reset, so that
  ndpi_serializer_rollback_snapshot() can no longer bring back the
  pre-reset content
* preserve the ndpi_serializer_skip_header() hint across the reset (CSV)

Add a unit test covering the three cases.

Fixes #3282
2026-10-26 17:34:39 +01:00
Ivan Nardi
34f935d414 TLS: update list of suspicious TLS extensions 2026-10-26 17:24:39 +01:00
Asim Siddiqui
44c22f8b5e
Sort the JA Host Stats table so the dump is reproducible (#3296)
The table printed by ndpiReader at verbose level 2 ("JA Host Stats", the number of
JA4C fingerprints seen per host) was emitted by walking the hash table directly:

    for(jaByHost_element = jaByHostsHashT; jaByHost_element != NULL;
	jaByHost_element = jaByHost_element->hh.next) {

i.e. in the order in which hosts happened to be added. Nothing sorted it, which is
visible in the committed test expectations, where the counts come out as 1, 3, 1.
That order is not portable: it depends on how the flows were walked and on the hash
of the key, so on a big-endian host the entries came out in a different order and
the text dump no longer matched its expectation (seen on the s390x cross-compile
job with tests/cfgs/default/pcap/perplexity_paste_text.pcapng).

Sort the table before printing it: number of client fingerprints, decreasing, then
IP address. 281 expectation files contain this table and 16 of them were not in
that order, so the rest of this commit is the usual refresh of those 16 files. The
second table printed at verbose level 3 (JA4C/JA3S per host) walks the same hash
table and becomes deterministic with the same change.

Co-authored-by: RikshaDriver <5790757+RikshaDriver@users.noreply.github.com>
2026-10-25 20:15:22 +01:00
Luca Deri
a915c7bceb Updated header 2026-10-23 22:20:49 +02:00
Copilot
91c58be4ea
Include fuzz_deserialization corpus in dist tarball (#3295)
* Initial plan

* Apply remaining changes

Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>
2026-10-23 21:37:48 +02:00
Luca Deri
823185f975 Added fix for long file names in tar files 2026-10-23 21:12:48 +02:00
Luca Deri
78a1d16fb7 Fixed "make dist" 2026-10-23 19:22:16 +02:00
Alfredo Cardigliano
9a365ee211 Add compile instructions for RH 2026-10-23 15:05:23 +02:00
netcons
eda68ccc93
Ambiguous data in GitHub domain lists (#3293)
GitHub downloaded lists are converted by ipaddr2list.py, which strips leading "*."
If "*.domain" and "domain" exists in these lists.
It causes "domain" to exist in multiple converted lists.
2026-10-23 13:21:59 +02:00
Ivan Nardi
e9e09ce795
PowerShell: detect remote administration over SMB and DCE/RPC (#3292)
Classify as PowerShell the traffic used by Windows to execute remote
commands, i.e. the svcctl (MS-SCMR) and winreg (MS-RRP) interfaces:
* SMBv2/3: after the flow has been classified, look into SMB2 CREATE
  requests for the "svcctl"/"winreg" named pipes (and for PsExec
  binary/pipes). Flows without these pipes are reported with the
  FILE_SHARING category.
* DCE/RPC over TCP: check the interface UUID in the BIND request
* HTTP: don't report generic WS-Management traffic (Openwsman clients,
  Intel AMT) as PowerShell

Close #3289

Also fix a memory leak in the IPsec JSON serialization (the transforms
sub-serializer was never freed).
2026-10-23 13:21:31 +02:00
Luca Deri
2b8c2989f8 Extended IPSEC metadat extraction and serialization 2026-10-20 23:02:56 +02:00
Ivan Nardi
05941e21d7
serializer: fix heap out-of-bounds read and length underflow (GHSA-cjvm-pg5v-f378) (#3287)
Reported by @GeekQAQ in GHSA-cjvm-pg5v-f378
2026-10-20 17:35:38 +02:00
Vladimir G.
cf69744289
Add JanitorAI detection (#3286) 2026-10-20 11:43:53 +02:00
mardgez13
1576f3e9fc
TLS: check the Server Key Exchange length before parsing it (#3285)
The Server Key Exchange parser read the public key length at offset 7
without checking that the handshake block holds 8 bytes, so a short
block made it read past its end.

Bound every read by payload_packet_len and skip the 12-byte DTLS
handshake header (the DTLS fragment offset was read as the key length).
Only named_curve ECDHE parameters are parsed now: other key exchanges
(DHE, explicit curves) have a different layout and were misparsed
before, so they are skipped.
2026-10-20 10:34:38 +02:00
Raja Muhammad Awais
d015ae84de
ndpi: honor per-flow DPI packet limit (#3284)
Co-authored-by: RajaMuhammadAwais <1.19938988e+08+RajaMuhammadAwais@users.noreply.github.com>
2026-10-20 09:56:45 +02:00
Slava Olesik
f1570f38fc
tests/performance: download a live Top 1M list instead of the Alexa file (#3280) 2026-10-16 15:57:20 +02:00
Ivan Nardi
b6611bf9ba
build,CI: fix some minor issues (#3281)
- fuzz/Makefile.am: remove stray 'cpp' token from fuzz_alg_anomalymodel_SOURCES
- CI: install libpcre2-dev (not libpcre3-dev) when testing --with-pcre2
- CI: replace bare 'make -j' / 'make -j all' with 'make -j $(nproc)'
2026-10-16 12:27:25 +02:00
Ivan Nardi
86435da5b8
Serializer: zero the deserializer in ndpi_init_deserializer_buf() (#3279)
ndpi_private_deserializer shares its layout with ndpi_private_serializer, and
ndpi_init_deserializer_buf() set only buffer.data/size/fmt before calling
ndpi_reset_serializer(). When the (attacker-controlled) format byte selects a
non-TLV format, reset_serializer() takes its JSON/CSV path and reads
serializer-only fields (multiline_json_array, inner_json) that a deserializer
never initializes. On a caller-provided, uninitialized deserializer this is a
use-of-uninitialized-value.

Found by OSS-Fuzz (MemorySanitizer)
2026-10-16 11:59:53 +02:00
Ivan Nardi
da1995058f
Merge commit from fork
The TLV deserializer (`ndpi_serializer.c`) could be driven into out-of-bounds
reads, an adjacent-heap info leak, a NULL-pointer crash and an infinite loop
by a malformed/truncated byte stream. These paths are reachable whenever an
embedder deserializes untrusted input (e.g. a collector reading nDPI TLV
records off a socket); nDPI itself only serializes, so no in-tree packet path
is affected.

Reported issues (GHSA-mmp7-3vgp-v8mg):
  1. `ndpi_deserialize_get_single_size()`: return type widened u_int16_t -> int
     so the -2 truncation sentinel survives for string/block/list types.
  2. `ndpi_deserialize_get_single_size()`: bounds-check each fixed-width numeric
     field (uint8..double) against the bytes remaining before returning a size.
  3. `ndpi_deserialize_get_single_string_size()`: guard `offset > buffer.size`
     before computing buff_diff, so it can no longer underflow.
  4. 'expected' accumulators widened u_int16_t -> u_int32_t across the
     deserialize paths, so two field sizes can no longer wrap mod 2^16.
  5. `ndpi_deserialize_clone_item()`: re-check the source holds 'expected' bytes
     before the memcpy, closing the heap over-read / info leak.

Additional issues found while fuzzing the fixed code (new `fuzz_deserialization`
target, see below), all in `ndpi_deserialize_clone_all()` on untrusted input:
  6. Infinite-loop DoS: the return value of `ndpi_deserialize_next()` was
     ignored, so a record that cannot advance the cursor looped forever.
     `clone_all()` now validates the whole record is present before reading it
     and breaks when `next()` reports an error.
  7. NULL / out-of-bounds string reads: `ndpi_deserialize_single_string()` now
     bounds the on-wire length to the buffer (returns {NULL,0} otherwise), and
     `ndpi_deserialize_key_string()` verifies the key subtype is a string before
     reading it (the guard `ndpi_deserialize_value_string()` already had).
  8. `atoi(NULL)` crash: ndpi_is_number() now treats NULL/empty as "not a
     number", so a NULL key can no longer reach `atoi()`.
  9. `atoi()` over-read on a numeric key: the `ndpi_serialize_binary_*()` helpers
      called `atoi()` on a counted, non-NUL-terminated key, reading past its
      length when the buffer continued with more digits. A bounded `ndpi_atoi_n()`
      now converts exactly key_len digits.

A new libFuzzer harness (`fuzz/fuzz_deserialization.cpp`) feeds untrusted bytes
directly to ndpi_init_deserializer_buf() + the clone/iterate APIs, with a seed
corpus reproducing every issue above.

Original report by Mike Myers (Apple).
2026-10-16 10:59:50 +02:00
Ivan Nardi
68887506f8
Merge commit from fork
`ndpi_dissect_strict_hdr()` computed `sizeof(*strict_hdr) + method_length`
in size_t arithmetic. method_length is an attacker-controlled u32; on
32-bit (ILP32) builds the sum wraps for method_length in
[0xFFFFFFF8, 0xFFFFFFFF], bypassing the length check. The ~4 GiB
method_length then reached `ndpi_is_printable_buffer()`, which walked the
whole length off the end of the packet buffer and crashed. A single
8-byte TCP segment to any port triggers it (the dissector has no port
restriction); 64-bit builds are unaffected as the addition does not wrap.

Reported as GHSA-4p5w-xmgh-3wg5.

Fixes:
- `ndpi_dissect_strict_hdr()`: reject method_length before adding it, by
  comparing against the bytes remaining instead of a sum that can wrap.
- `ndpi_is_printable_buffer()`: return on the first non-printable byte
  (correctness, performance, and defense-in-depth so a bogus length can
  no longer scan past the buffer).

Only the strict/binary (0x80, TCP) path is affected; the compact path's
method_length is a u_int8_t and cannot wrap.

Original report by Mike Myers (Apple).
2026-10-16 10:54:06 +02:00
Ivan Nardi
46a788f47e
Merge commit from fork
A crafted DTLS datagram could spin `ndpi_search_dtls_internal()` at 100%
CPU forever. The record cursor `processed` was a u_int16_t and was
advanced by an unchecked `block_len + 13`, so it could wrap mod 65536.
`is_dtls()` was also validating block_len against the whole packet length
instead of the bytes remaining, so a record near the end of the buffer
was accepted even when its length ran past the end.

Reported by Mike Myers (Apple).
2026-10-16 09:02:17 +02:00
Raja Muhammad Awais
cdad1fce08
ndpiReader: export expired flows (#3274) 2026-10-15 19:24:28 +02:00
Luca Deri
352da4336d Updated test results 2026-10-15 17:55:01 +02:00