Commit graph

1881 commits

Author SHA1 Message Date
Vitaly Lavrov
f84512cd2a Merge commit '6d2476c31b' into flow_info-4 2026-11-20 12:56:46 +03:00
Vitaly Lavrov
842798e990 Merge commit '6a85dd290a' into flow_info-4 2026-11-20 12:48:58 +03:00
Vitaly Lavrov
ad0f93c339 Merge commit 'b6bddaf79b' into flow_info-4 2026-11-20 12:44:45 +03:00
Vitaly Lavrov
a0b3a6fbee Merge commit '6b38c1c258' into flow_info-4 2026-11-20 12:42:41 +03:00
Vitaly Lavrov
4d3cb23dc8 Merge commit 'b17e3ae776' into flow_info-4 2026-11-20 12:36:39 +03:00
Vitaly Lavrov
a6f5031574 Merge commit 'ca9d819151' into flow_info-4 2026-11-20 12:35:21 +03:00
Vitaly Lavrov
c2b9a0f952 Merge commit 'd015ae84de' into flow_info-4 2026-11-20 12:33:01 +03:00
Vitaly Lavrov
20fb399023 Merge commit 'cdad1fce08' into flow_info-4 2026-11-20 12:31:37 +03:00
Vitaly Lavrov
b47b075978 Merge commit 'e5f8ec9541' into flow_info-4 2026-11-20 12:25:59 +03:00
Ivan Nardi
bb583c6dc9 HTTP: improve detection of Connectivity-Checks flows 2026-11-15 17:36:06 +01:00
Ivan Nardi
0d213cd3bc Fix fp_tcp_win11.pcapng: use a single link type 2026-11-13 19:40:10 +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
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
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
Ivan Nardi
6a85dd290a Sync unit tests results 2026-11-09 13:26:54 +01:00
Luca Deri
b0a8b13e27 Updated test results 2026-11-07 08:53:54 +01:00
Luca
6c805efdfe Traffic forged using the script below to mimic CVE-2026-98432
--

from scapy.all import IP, TCP, IPOption, wrpcap

def generate_test_pcaps(output_filename="cve_2026_98432_test.pcap"):
    packets = []

    # Target and Source placeholders for the test trace
        src_ip = "192.168.1.50"
	    dst_ip = "192.168.1.100"
	        dst_port = 80

    print(f"[*] Generating synthetic test packets for CVE-2026-98432...")

    # Vector 1: TCP SYN packet carrying IPv4 Options (Triggers Rule 1)
        # Using the standard 'Record Route' option (option number 7)
	    ip_option = IPOption(b'\x07\x07\x04\x00\x00\x00\x00')

    syn_with_ip_opts = (
            IP(src=src_ip, dst=dst_ip, options=[ip_option]) /
	            TCP(sport=54321, dport=dst_port, flags="S", seq=1000)
		        )
			    packets.append(syn_with_ip_opts)
			        print(" [+] Added: TCP SYN with IPv4 Options")

    # Vector 2: TCP SYN packet carrying Multipath TCP (MPTCP) Options (Triggers Rule 2)
        # MPTCP uses TCP Option Kind 30 (\x1e).
	    # Subtype 0 (\x00) represents the MP_CAPABLE handshake signature.
	        mptcp_option = (30, b'\x00\x01\x02\x03\x04\x05\x06\x07')

    syn_with_mptcp = (
            IP(src=src_ip, dst=dst_ip) /
	            TCP(sport=54322, dport=dst_port, flags="S", seq=2000, options=[mptcp_option])
		        )
			    packets.append(syn_with_mptcp)
			        print(" [+] Added: TCP SYN with MPTCP Options")

    # Write the constructed array of packets to a standard PCAP file
        wrpcap(output_filename, packets)
	    print(f"[*] Successfully wrote {len(packets)} packets to '{output_filename}'.")

if __name__ == "__main__":
    generate_test_pcaps()
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
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
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 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
mmanoj
7393261e88
dns: harden any-port UDP detection (#3246) 2026-11-02 20:03:42 +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
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
cbc2a894ea Updated test results 2026-10-27 17:30:19 +01:00