Commit graph

4025 commits

Author SHA1 Message Date
Luca
f267cef424 Improved DNS dissection 2026-11-15 07:20:07 +01:00
John Earle
614f59a932
Merge commit from fork
* Kerberos: clamp the reply prefix copy to the buffer size (GHSA-3pvq-vj37-hfqg)

The reply-buffering branch of krb_process_packet() allocated
ndpi_min(kerberos_len, KRB_MAX_BUF_LEN)+4 bytes for pktbuf but then copied
payload_len+4 bytes into it. When 12000 < payload_len < kerberos_len <
1048576 the copy exceeds the clamped buffer, overflowing the heap with
attacker-controlled data (reachable via a Kerberos-classified TCP flow and a
crafted >12KB single-segment reply). pktbuf_currlen is u_int16_t, so the
unclamped payload_len+4 was also truncated on store.

Clamp both the copy length and pktbuf_currlen to pktbuf_maxlen, keeping only
the prefix the buffer can hold -- which is sufficient for the incremental
KRB_PARSE_PREFIX parsing performed just above. Verified under AddressSanitizer:
the PoC that previously overflowed now runs clean, and normal Kerberos traffic
still classifies.

* Kerberos: add a test for the reply prefix overflow (GHSA-3pvq-vj37-hfqg)

A TGS-REP whose padata keeps the client name out of a single 15000-byte
segment: the reply is buffered in a 12004-byte buffer. Without the fix,
AddressSanitizer reports a heap-buffer-overflow (WRITE of size 15004) in
krb_process_packet().
2026-11-13 18:21:19 +01:00
Ivan Nardi
4421ae2cc9
Fix CI failures (#3327)
* Update WebattackRCE.pcap.out to the new "Known Proto on Non Std
  Port" risk description
* Windows: add missing MAX_NUM_TLS_MONITORED_BLOCKS define
* Mingw: avoid %zu in printf formats; with GCC 13 and mingw-w64 13
  headers (Ubuntu 26.04) it is rejected by -Wformat
* Python: switch from 3.9 (not available on Ubuntu 26.04) to 3.14
  and explicitly install setuptools
2026-11-13 17:38:19 +01:00
Alfredo Cardigliano
9f8e80ebf9
Extend Known Proto on Non Std Port description to include both ports (and proto) (#3326) 2026-11-13 16:27:27 +01:00
Ivan Nardi
15a686dbfa
HTTP: handle Byte Order Marks when checking for suspicious content (#3325)
Text bodies starting with a UTF-8 BOM (EF BB BF) were flagged as
NDPI_HTTP_SUSPICIOUS_CONTENT, since the check accepts only ASCII bytes.
Skip the UTF-8 BOM and check the text after it.

UTF-16 text can't be validated with an ASCII check: if the body starts
with a UTF-16 (LE/BE) BOM, consider it as acceptable.
2026-11-12 20:03:07 +01:00
Ivan Nardi
db103fd80c TLS: extend list of non-suspicious extensions 2026-11-12 18:34:41 +01:00
Luca Deri
5d9724ca04 HTTP subprotocols are not set only in case HTTP returns a positive response.
This is to avoid that probing attempts create invalid protocol detection
2026-11-12 12:47:04 +01:00
Ivan Nardi
51ca71649c
HTTP: skip chunk-size line when checking for suspicious content (#3323)
With "Transfer-Encoding: chunked", the body starts with the chunk-size
line, so the human-readable content check was inspecting "<hex>\r\n"
instead of the actual payload. This reported wrong bytes in the risk
info (e.g. "610D0A1F"), missed non-printable data when the chunk size
had 2+ digits, and flagged valid gzip-compressed chunked bodies.

For chunked responses, skip the chunk-size line (and any extension)
before running the check.
2026-11-12 12:35:10 +01:00
Ivan Nardi
64b1ad9e6c
utests: fix TLS blocks initializers, stale malware domain and TLS results (#3324)
TLS: remove leftover debug printf in handleTLSBlockStat().
2026-11-12 12:34:46 +01:00
Raja Muhammad Awais
0bff3aa1ae
SSH: fix obsolete cipher detection and KEX metadata reuse (#3319)
Co-authored-by: RajaMuhammadAwais <1.19938988e+08+RajaMuhammadAwais@users.noreply.github.com>
2026-11-12 09:13:33 +01:00
Luca Deri
2ed880c637 Implemented TLS block export in monitoring mode 2026-11-11 07:44:04 +01:00
Ivan Nardi
0bcc7e82e6
PROFINET/IO: improve detection over DCERPC (#3322)
* Move PROFINET/IO detection into the DCERPC dissector: match the
  PROFINET/IO interface UUIDs (Device, Controller, Supervisor,
  ParameterServer) and the full object UUID prefix, and recognize the
  Endpoint Mapper lookups for PROFINET/IO interfaces. Remove the
  standalone PROFINET/IO dissector,
* After a generic EPM classification, look for PROFINET/IO calls in the
  next packets of the flow
* Add UDP 34964 as PROFINET/IO default port and don't trigger the
  `NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT` flow risk for PROFINET/IO:
  responses and following calls use dynamic ports
* Fix the byte order check of the connectionless DCERPC fragment length
2026-11-10 17:07:30 +01:00
Alfredo Cardigliano
c8d10df833
Fix Discord detection with request retransmission (#3321) 2026-11-10 11:16:59 +01:00
Ivan Nardi
95fc30c2bf
Protobuf: fix false positive on payloads parsed only partially (#3320)
The "weak" detection path (>= 4 packets, >= 2 elements, no LEN fields
required) didn't check that the whole payload had been parsed: the
dissector stops after PROTOBUF_MAX_ELEMENTS elements and returns a
non-zero offset anyway.

Require the parsed bytes to cover the entire payload on that path.

Add the trace to false_positives.pcapng.
2026-11-09 21:40:29 +01:00
Alfredo Cardigliano
a2b54f8293 Reduce severity of TCP Issues to reduce noise (Probing Attempt is also set when it's about security) 2026-11-09 11:15:53 +01:00
Luca Deri
ed59c1fcda Enhanced FTP detection 2026-11-07 12:37:04 +01:00
Luca
b0a2310906 Implements detection of CVE-2026-98432 2026-11-06 19:04:28 +01:00
Alfredo Cardigliano
cfbf5fe45d
Do not trigger Known Proto on Non Std Port for mail protocols (e.g. STARTTLS flows on port 25, SMTP expected but protocol nogotiated to SMTPS) (#3318) 2026-11-06 17:30:32 +01:00
Raja Muhammad Awais
8a07936f2a
SSH: match negotiated algorithms by exact name (#3311) 2026-11-06 17:14:06 +01:00
Ivan Nardi
96a07277c0 TLS: better flow risk info 2026-11-06 16:54:48 +01:00
Ivan Nardi
2005d3af4f Bittorrent: avoid Known Proto on Non Std Port flow risk 2026-11-06 16:12:21 +01:00
Ivan Nardi
b6bddaf79b
Kerberos: add helpers to describe and serialize the metadata (#3317)
- ndpi_kerberos_msg_type2str(), ndpi_kerberos_name_type2str(),
  ndpi_kerberos_error2str() (RFC 4120, RFC 4556, RFC 6113 error codes),
  ndpi_kerberos_s4u2str()
- ndpi_kerberos_reply_ok(): the KDC issued the ticket (AS-REP/TGS-REP)
- ndpi_kerberos_reply_error(): name of the error of a KRB-ERROR reply
- ndpi_kerberos_client_name(): "user@realm", or "host$@realm" for a
  machine; an enterprise name ending with the realm is used as it is,
  otherwise its '@' are escaped ("user\@upn.suffix@realm")
- ndpi_kerberos2json(): used by ndpi_dpi2json() (same output)

ndpiReader uses them, and prints the name of the error code.
2026-11-05 19:46:37 +01:00
Ivan Nardi
4eec73db6e
Kerberos: commit metadata to the shared union only after classification (GHSA-hp25-h2r7-vw5r) (#3316)
The write-before-classify ordering was introduced by commit b20123478
("Kerberos: rework dissector and export request/response metadata");
before it the dissector classified first and wrote metadata afterwards.

Add tests/pcap/pocs.pcapng (the merged SMBv23 and SIP reproductions) as a
regression test.
2026-11-05 14:32:21 +01:00
Ivan Nardi
3805b93ca9 Kerberos: export the short name of the machine of host/ldap principals
The name of a machine was exported in two forms: "ws1" from its account
name ("WS1$") and "ws1.corp.local" from a "host/ws1.corp.local" principal.
Now only the short one, i.e. the first label of the name, unless it is an
IPv4 address (e.g. "host/10.1.2.3").
2026-11-05 13:28:09 +01:00
Ivan Nardi
e1973d0797 DNS: don't start the extra dissection with max_packets_extra_dissection 0
With dns,max_packets_extra_dissection set to 0 the extra dissection was
started anyway and it never ended (max_extra_packets_to_check 0 is never
reached), instead of being disabled.
2026-11-05 13:28:09 +01:00
Ivan Nardi
f02c482839 Kerberos: add the kerberos,max_packets_extra_dissection parameter
The number of packets to wait for the reply, after a request (default 16,
as before). With 0 the reply is not dissected: no extra dissection is
started at all (with max_extra_packets_to_check 0 it would never end).
2026-11-05 13:28:09 +01:00
Ivan Nardi
c1c245002e Kerberos: same buffer limit (12000 bytes) for requests and replies
A single limit to the bytes buffered per flow: requests longer than it are
not reassembled (as before), replies are buffered only up to it. The worst
case per flow is unchanged and a larger padata fits before the client name.
2026-11-05 13:28:09 +01:00
Ivan Nardi
fb1310a80b Kerberos: parse only the beginning of large TCP replies
The whole reply was reassembled, up to KRB_MAX_MSG_LEN (12000) bytes and
within 5 extra packets, counting also the ACKs of the client: replies
larger than about 6KB (e.g. with the PAC of a user in many groups) were
lost, i.e. no client name and no reply type for the flow.

The needed fields (crealm and cname) are at the beginning of the reply,
before the ticket: now the reply is parsed up to the first incomplete
field. Usually the first segment is enough (no buffer at all); otherwise
(large padata, as with PKINIT, small segments, the record marker in its
own segment) only the first KRB_MAX_PREFIX_LEN (8192) bytes are buffered,
waiting for up to KRB_MAX_EXTRA_PACKETS (16) packets.

The requests are unchanged (whole message, up to KRB_MAX_MSG_LEN).

New test: kerberos-large-reply.pcap (synthetic): replies up to 48000
bytes (Windows MaxTokenSize), with and without ACKs, record marker alone,
cname in the 4th segment, large padata, padata larger than the limit.
2026-11-05 13:28:09 +01:00
Ivan Nardi
21184d1a50 Kerberos: keep UTF-8 names and report truncated names
Names and realm were copied byte by byte: any non-ASCII byte was replaced
by '?' (e.g. "josé" became "jos??") and a name longer than the buffer was
silently truncated, i.e. exported as a different, wrong, name.

Now:
- valid UTF-8 is kept as is (only ASCII is lowercased); control characters
  and invalid bytes are still replaced by '?'
- a multi-byte character is never split
- the new flags hostname_truncated, domain_truncated and
  username_truncated report a truncated name
- the buffers are larger (hostname 64, domain 64, username 96), to fit long
  enterprise names and realms (still within the protos union)
2026-11-05 13:28:09 +01:00
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
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
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
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