* 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().
* 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
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.
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.
* 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
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.
- 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.
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.
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").
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.
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.
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)
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
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.
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.
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.
`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
* 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
* 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
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>
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).
`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).
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).
Replace the per-message heuristics with a single ASN.1 walk covering
AS-REQ, AS-REP, TGS-REQ, TGS-REP and KRB-ERROR, over both TCP and UDP.
AS-REP was never parsed and nothing was extracted from KRB-ERROR.
New metadata: request type, response type and (for KRB-ERROR) the error
code. They are printed by ndpiReader and exported via JSON as
"request_type", "response_type", "response_ok" (true for AS-REP and
TGS-REP) and "error_code". Only the first request and the first reply
of a flow are exported.
Client name and realm keep the existing conventions, so they are not
the literal Wireshark `kerberos.CNameString/kerberos.realm` values:
- the trailing '$' of machine accounts is stripped on purpose: a cname
ending with '$' (e.g. "jersey-shore-2c$") is exported in "hostname"
without the '$'; any other cname is exported in "username" unchanged
- names and realm are lowercased
The generic BER helpers (asn1_ber_decode_header/tlv/single_tlv/int) are
in ndpi_utils.c, next to asn1_ber_decode_length().
Close#3275Close#2117