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.
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.
```
==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.
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.
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.
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.
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.
`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
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
* 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
* 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
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>
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.
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).
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.
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)
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).
`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).