Commit graph

244 commits

Author SHA1 Message Date
Tim Wojtulewicz
2c46d3139c Merge remote-tracking branch 'origin/topic/timw/3417-packet-analysis-detail'
* origin/topic/timw/3417-packet-analysis-detail:
  Move packet_analysis::Dispatcher to detail namespace
2024-05-08 09:55:16 -07:00
Robin Sommer
ccfeffaf2b
Fix packet analyzer replacement.
Also reworking the existing test, which was pretty odd/broken.
2024-05-06 09:45:11 +02:00
Robin Sommer
5d0c61e68b
Add component API to transparently remap one component to another one.
When a specific component is requested through its tag or name, one
can now have the component manager transparently return a different
one that has been registered to replace the original one. We limit
this to disabled components to avoid unnecessary confusion. That also
means that remappings are currently only supported for analyzers
(because other types of components cannot be disabled for now, per the
previous change).
2024-05-06 09:45:11 +02:00
Robin Sommer
ac1a7508ee
Move enabled/disabled functionality from analyzers into Component base class API.
The different analyzers types all had their own methods for
enabling/disabling their availability. This change abstracts that into
a new API inside their base class (`plugin::Component`) so that they
can be toggled in a unified way.

In principle, other types of components could/should use this as well
now, so that, e.g., an input reader's availability could be toggled at
runtime. The code doesn't make that broader change for now because it
would requires a series of changes wherever these other component
types are being used. However, that means that one now could try
toggling some other component through the new API without that having
any effect. To catch that, there's a runtime check in place that turns
any such attempt into an internal error.
2024-05-06 09:45:11 +02:00
Tim Wojtulewicz
6900f3301e Move packet_analysis::Dispatcher to detail namespace 2024-04-26 13:11:45 -07:00
Christian Kreibich
581971e160 Factor in caplens in ICMPAnalyzer::DeliverPacket length calculations
Relying only on the IP-header-provided length could violate buffer boundaries in
the endpoints' rule matching. This change mirrors what we do in UDP and TCP.

Resolves #3671
2024-04-25 16:22:52 -07:00
Tim Wojtulewicz
8977f49665 Remove setting non-existent session history for IPTunnel 2024-01-23 12:39:58 -07:00
Arne Welzel
7325bc945f tunnels: Add 'X' to history when reaching Tunnel::max_depth 2024-01-11 10:22:44 +01:00
Arne Welzel
ad9446d799 Session/TCP/UDP: Reserve HIST_UNKNOWN_PKT mask
This is meant to be used for a new 'X' code in the history in scenarios when
packets are knowingly not processed or an unexpected unknown situation
is recognized.

Usually, these situations are currently reported via weirds or analyzer violations,
but being able to include it in the history field allows them to be more visible.

Will be used for exceeding tunnel depths first.
2024-01-11 10:22:44 +01:00
Arne Welzel
3f7881a57b segment_profiling: Remove SegmentProfiler and load_sample event
While it seems interesting functionality, this hasn't been documented,
maintained or knowingly leveraged for many years.

There are various other approaches today, too:

* We track the number of event handler invocations regardless of
  profiling. It's possible to approximate a load_sample event by
  comparing the result of two get_event_stats() calls. Or, visualize
  the corresponding counters in a Prometheus setup to get an idea of
  event/s broken down by event names.

* HookCallFunction() allows to intercept script execution, including
  measuring the time execution takes.

* The global call_stack and g_frame_stack can be used from plugins
  (and even external processes) to walk the Zeek script stack at certain
  points to implement a sampling profiler.

* USDT probes or more plugin hooks will likely be preferred over Zeek
  builtin functionality in the future.

Relates to #3458
2024-01-03 11:55:54 +01:00
Arne Welzel
01e305edd8 UpdateConnVal: Avoid FieldOffset() calls
These can be significant if a lot of new connections and or events
are created for which an existing conn val needs updating and otherwise
things are very fast.
2023-12-04 20:03:27 +01:00
Tim Wojtulewicz
ef5b169acd Add some uses of std::move in constructors and simple functions for pass-by-value arguments 2023-11-28 13:40:28 -07:00
Tim Wojtulewicz
3295c8f1c1 Change function return types to more concise types where possible
This helps avoid needing to call std::move on return values when we know the
type of value is fixed.
2023-11-28 13:40:28 -07:00
Arne Welzel
0c19e6fc54 build_inner_connection: Use the outer packet's timestamp
Don't construct the timeval based on run_state, just use the timestamp
of the outer packet to avoid the extra int/double conversions required.
2023-11-01 12:03:55 +01:00
Arne Welzel
d08e347e5e build_inner_connection: Avoid one extra Init()
Packet::Init() is not so cheap as one might think: It computes a
timestamp from { 0, 0 } using double division. Just avoid this
by not initializing an empty Packet.
2023-11-01 12:03:55 +01:00
Arne Welzel
ec4ad2e80d packet_analysis: Do not run DetectProtocol() on disabled analyzers
This came up when disabling the TEREDO analyzer but still seeing its
DetectProtocol() method prominently in flame graphs.
2023-11-01 12:03:55 +01:00
Arne Welzel
9bebd93c06 packet_analysis/Dispatcher: Do not index table twice
It's okay to return the nullptr that's in the table, no need to check
for != nullptr before dereferencing again.
2023-11-01 12:03:55 +01:00
Arne Welzel
e56ef0fd9b packet_analysis: Avoid shared_ptr copying for analyzer lookups
For deeply encapsulated connections (think AWS traffic mirroring format
like IP,UDP,GENEVE,IP,UDP,VXLAN,ETH,IP,TCP), the Dispatcher::Lookup()
method is fairly visible in profiles when running in bare mode.

This changes the Analyzer::Lookup() and Dispatcher::Lookup() return value
breaking the API in favor of the performance improvement.

Relates to zeek/zeek#3379.
2023-11-01 12:03:02 +01:00
Benjamin Bannier
f5a76c1aed Reformat Zeek in Spicy style
This largely copies over Spicy's `.clang-format` configuration file. The
one place where we deviate is header include order since Zeek depends on
headers being included in a certain order.
2023-10-30 09:40:55 +01:00
Arne Welzel
bccf1a9253 IEEE802_11: Fix buffer-overflow due to not accounting for the amsdu header
The fuzzer generated input where data length left was 14 and the amsdu_len
field set to 14. That caused buffer overread due not taking into account
the amsdu header length of 14.
2023-10-18 10:53:06 +02:00
Tim Wojtulewicz
9af7d830e7 VLAN: Fix length checking for non-Ethernet type 2 frames
(cherry picked from commit c579eb7b7cf3ca1d9008e74d7934155866c7e4f7)
2023-09-12 12:00:36 -07:00
Arne Welzel
ba04f4c31d IPBasedAnalyzer: Don't flip connections when destination is broadcast
Closes #3235
2023-08-28 12:15:55 +02:00
Arne Welzel
ee12a7a6e7 PPP: Add PPP analyzer to handle LINKTYPE_PPP (0x9)
Using pcaps from https://interop.seemann.io/ as samples for QUIC protocol
data didn't produce a conn.log for the contained data. `tcpdump -r`
and Wireshark do show the contained IP/UDP packets. Teach Zeek how
to handle link type DLT_PPP 0x09 using a new PPP analyzer based on the
PPPSerial analyzer code.

Usual update to files/x509 baseline after adding new analyzer due
to enum values changing.
2023-08-23 16:41:19 +02:00
Johanna Amann
940e3afab4 Do not forward padding to downstream TCP packet analyzer
This is similar to GH-3206. There do not seem to be practical
consequences - but we should still fix it.

This also includes the udp-testcase that was forgotten in GH-3206.
2023-08-02 17:17:01 +01:00
Johanna Amann
a391367c36 Do not forward more than the remaining data to downstream UDP analyzer
This fixes a bug introduced in 2b9de839b0
/ GH-3080, which causes UDP padding to be sent to UDP based analyzers.

Fixes GH-3205.
2023-07-27 13:35:41 +01:00
Tim Wojtulewicz
0d78eb1933 packet_analysis: Define all plugin type as final 2023-07-07 09:17:05 -07:00
Tim Wojtulewicz
cd7ebdb2ed A handful of int-to-bool conversions 2023-07-07 09:17:05 -07:00
Tim Wojtulewicz
9a79b98a1e Remove analyzer_confirmation/analyzer_violation events (6.1 deprecation) 2023-06-14 10:07:22 -07:00
Tim Wojtulewicz
4229af6820 Remove deprecations tagged for v6.1 2023-06-14 10:07:22 -07:00
Arne Welzel
7a043e5e8f all: Fix typos identified by typos pre-commit hook 2023-06-13 17:57:32 +02:00
Arne Welzel
c4d159d1ff Address wire/capture length feedback 2023-05-25 09:48:14 +02:00
Arne Welzel
6941e44aba packet_analysis/TCP: Do not use untrusted len for DeliverPacket()
We should not be passing the untrusted TCP header length into
DeliverPacket(). Also, DeliverPacket() cap len parameter should
be the capture length of the packet, not remaining data.
2023-05-24 16:41:52 +02:00
Arne Welzel
568946ec18 IP: Update packet->len with accumulated fragment size
With packet->len representing the wire length and other places
relying on it, ensure it's updated for fragments as well. This
assumes non-truncated fragments right now. Otherwise we'd need
to teach the FragmentReassembler to somehow track this independently
but it would be a mess.
2023-05-24 16:34:22 +02:00
Arne Welzel
2b9de839b0 UDP: Forward any remaining data (also empty) to session-analysis
The protocol analyzers are prepared to receive truncated data and
this way we give analyzers a chance to look at data. We previously
allowed empty data being passed: When len ended up 0 and remaining
was 0 too.
2023-05-24 16:31:11 +02:00
Arne Welzel
5654f81dee IPTunnel: Compute inner wire length based on cap_len differences. 2023-05-24 16:31:08 +02:00
Tim Wojtulewicz
18a30a7a53 IP: fix weird name to not be ipv6 specific 2023-05-24 16:29:29 +02:00
Tim Wojtulewicz
47ff5a4f61 UDP: don't validate checksum if caplen < len
This may happen with truncated packets and will cause asan builds to bail out
before the packet can be forwarded along. The TCP analyzer already has this
check, but it's missing for UDP.
2023-05-24 16:01:08 +02:00
Tim Wojtulewicz
84e3f414a7 Use the same rules as cmake submodule to reformat Zeek 2023-05-09 08:31:43 -07:00
Tim Wojtulewicz
7782f73251 Add additional length check to IEEE 802.11 analyzer 2023-05-02 16:12:43 -07:00
Tim Wojtulewicz
eb9d851a07 Fix a few warnings from recent changes 2023-04-27 15:38:02 -07:00
Tim Wojtulewicz
7facd94e6f Fix length checks in VLAN/Ethernet analyzers for non-ethertype protocols 2023-04-25 12:29:55 -07:00
Tim Wojtulewicz
7aa7909c94 Add forwarding from VLAN analyzer into LLC, SNAP, and Novell 802.3 analyzers 2023-04-25 12:29:55 -07:00
Tim Wojtulewicz
c5b8603218 Remove non-standard way of forwarding out of the Ethernet analyzer 2023-04-25 12:29:55 -07:00
Tim Wojtulewicz
7e88a2b3fb Add basic LLC, SNAP, and Novell 802.3 packet analyzers 2023-04-25 12:29:54 -07:00
Tim Wojtulewicz
31afe082ac ARP: add support for IEEE802 hardware type 2023-04-25 12:12:49 -07:00
Tim Wojtulewicz
f62f8e5cc9 Remove workaround for tunnels from IEEE 802.11 analyzer 2023-04-25 09:28:20 -07:00
Tim Wojtulewicz
934207c05b PPP in the GRE analyzer is actually PP*T*P 2023-04-25 09:28:20 -07:00
Tim Wojtulewicz
2d05beac06 Add support for 802.11 A-MSDU aggregates 2023-04-25 09:28:20 -07:00
Tim Wojtulewicz
5b1c6216bd Fix IEEE 802.11 analyzer to properly forward tunneled packets
This mostly happens with Aruba, but could possibly happen with other tunnels too.
2023-04-25 09:28:20 -07:00
Tim Wojtulewicz
e4a1c30828 Fix IEEE 802.11 analyzer to skip packets with the Protected bit enabled 2023-04-25 09:28:20 -07:00