Commit graph

8307 commits

Author SHA1 Message Date
Vern Paxson
9e5977f24e Fix for ZAM inlining of nested function calls with the same parameter names 2024-05-15 17:32:13 -07:00
Vern Paxson
ca62898a11 Fixed ZAM logic error in canonicalizing specialized min/max instructions 2024-05-15 17:31:30 -07:00
Vern Paxson
5ce5bbdbaa Fixed order-of-evaluation bug in ZAM Subnet-To-Addr instruction 2024-05-15 17:30:29 -07:00
Robin Sommer
e02f04c6be
Apply missing fix for https://github.com/zeek/spicy/pull/1723. 2024-05-13 15:29:14 +02:00
Robin Sommer
747e26297b
Spicy: Update for https://github.com/zeek/spicy/pull/1738. 2024-05-13 09:25:37 +02:00
Robin Sommer
82be6425e6
Merge remote-tracking branch 'origin/topic/robin/gh-3561-forward-to-udp'
* origin/topic/robin/gh-3561-forward-to-udp:
  Update docs.
  Add explicit children life-cycle management method to analyzers.
  Spicy: Support UDP in Spicy's `protocol_*` runtime functions.
  Add method to analyzer to retrieve direct child by name.
  Extend PIA's `FirstPacket` API.
  Spicy: Prepare for supporting forwarding to protocols other than TCP.
2024-05-10 11:15:20 +02:00
Robin Sommer
4a63495b1d
Merge remote-tracking branch 'origin/topic/robin/gh-3725-service'
* origin/topic/robin/gh-3725-service:
  Spicy: Fix service reporting for replaced analyzers.
  Fix include of private file in public header
2024-05-10 11:07:40 +02:00
Tim Wojtulewicz
b2e4fbe58d Merge remote-tracking branch 'origin/topic/vern/gen-zam-multi-files'
* origin/topic/vern/gen-zam-multi-files:
  enable ZAM operation specifications to reside in multiple files (not yet used)
2024-05-08 13:09:35 -07:00
Vern Paxson
1989dc5e5a enable ZAM operation specifications to reside in multiple files (not yet used) 2024-05-08 12:50:49 -07:00
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
93a424b28a
Spicy: Fix service reporting for replaced analyzers.
We accidentally applied analyzer mappings when looking up an
analyzer's name from scriptland.

Closes #3725.
2024-05-08 14:01:46 +02:00
Benjamin Bannier
4e6bbd9756
Fix include of private file in public header 2024-05-08 12:50:42 +02:00
Vern Paxson
a0888b7e36 make SSH analyzer robust to half-duplex connections 2024-05-07 11:40:47 -07:00
Tim Wojtulewicz
d463141ded Merge remote-tracking branch 'origin/topic/christian/fix-zeekygen-crash'
* origin/topic/christian/fix-zeekygen-crash:
  Avoid segfault when generating Zeekygen docs on Zeek-internal identifiers.
  Add btest for Zeekygen docs extraction on identifiers defined by the Zeek core.
2024-05-07 10:26:19 -07:00
Robin Sommer
b4f68a2681
Add explicit children life-cycle management method to analyzers. 2024-05-07 18:19:47 +02:00
Robin Sommer
a2ae9c4b02
Spicy: Support UDP in Spicy's protocol_* runtime functions.
This extends the ability to feed new payload back into Zeek's analyzer
pipeline from TCP to now also UDP.

Note: We don't extend this further to ICMP because the ICMP analyzer
cannot be dynamically instantiated (Zeek aborts when trying so). As
ICMP isn't very interesting from use-case perspective anyways, that
seems fine.

Closes #3561.
2024-05-07 18:19:46 +02:00
Robin Sommer
df3d50ea07
Add method to analyzer to retrieve direct child by name. 2024-05-07 18:19:46 +02:00
Robin Sommer
2ec44f098f
Extend PIA's FirstPacket API.
`FirstPacket()` so far supported only TCP. To extend this to UDP, we
move the method into the PIA base class; give it a protocol parameter
for the case that there's no actual packet is available; and add the
ability to create fake UDP packets as well, not just TCP.

This whole thing is pretty ugly to begin with, and this doesn't make
it nicer, but we need this extension that so we can feed UDP data into
the signature engine that's tunneled over other protocols. Without the
fake packets, DPD signatures in particular wouldn't have anything to
match on.
2024-05-07 18:19:46 +02:00
Robin Sommer
8dd3debeae
Spicy: Prepare for supporting forwarding to protocols other than TCP.
So far the Spicy runtime supported forwarding data into other
analyzers only for TCP analyzers. This puts branching logic in place
that let the relevant runtime functions dispatch differently based on
the target transport-layer protocol. We don't implement anything else
than TCP yet; that will come next.

Along with the internal changes, this also updates the user-visible
runtime function to pass protocol information in. For now, this
likewise remains limited to TCP. The function signatures are chosen so
that they stay backwards-compatible to previous Spicy version. In
particular, they default to TCP where not otherwise specified.
2024-05-07 14:44:52 +02:00
Robin Sommer
8ce3c877ff
Merge remote-tracking branch 'origin/topic/robin/gh-3573-replaces-cleanup'
* origin/topic/robin/gh-3573-replaces-cleanup:
  Fix packet analyzer replacement.
  Spicy: Wenn replacing an analyzer add a component mapping.
  Add component API to transparently remap one component to another one.
  Move enabled/disabled functionality from analyzers into `Component` base class API.
2024-05-07 09:45:25 +02:00
Robin Sommer
083c682878
Merge remote-tracking branch 'origin/topic/robin/gh-3440-file-handles'
* origin/topic/robin/gh-3440-file-handles:
  Spicy: Query Zeek scriptland for file handles.
2024-05-07 09:44:41 +02:00
Robin Sommer
383a77dab7
Merge remote-tracking branch 'origin/topic/robin/gh-3606-port-enum'
* origin/topic/robin/gh-3606-port-enum:
  Spicy: Cleanup some runtime code.
  Spicy: Map Spicy's `Protocol` enum to Zeek's `transport_proto`.
2024-05-07 09:42:04 +02: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
3a469b3619
Spicy: Wenn replacing an analyzer add a component mapping.
This uses the new API to replace components internally.

With these changes in place, replacing protocol analyzers now don't
need to register their ports anymore if they match what the original
analyzer was using (because the old one's registrations will map
over).

Packet analyzer replacement doesn't quite work yet but will be fixed
in next commit.

Closes #3573.
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
Robin Sommer
56b9a79a65
Spicy: Query Zeek scriptland for file handles.
Like traditional file analyzers, we now query Zeek's
`get_file_handle()` event for handles when a connection begins
analyzing an embedded file. That means that Spicy-side protocol
analyzers that are forwarding data into file analysis now need to call
Zeek's `Files::register_protocol()` and provide a callback for
computing file handles. If that's missing, Zeek will now issue a
warning. This aligns with the requirements Zeek's traditional protocol
analyzers. (If the EVT file defines a protocol analyzer to `replace`
an existing one, that one's `register_protocol()` will be consulted.)

Because Zeek's `get_file_handle()` event requires a current
connection, if a Spicy file analyzer isn't directly part of a
connection context (e.g., with nested files), we continue to use
hardcoded, built-in file handle. Scriptland won't be consulted in
that case, just like before.

Closes #3440.
2024-05-06 09:20:38 +02:00
Christian Kreibich
0bde62efec Avoid segfault when generating Zeekygen docs on Zeek-internal identifiers.
Identifiers that Zeek generates explicitly in-core for example during component management
("Analyzer::ANALYZER_FOO", "Input::READER_FOO", etc), aren't associated with any
scripts and would lead to nullpointer derefs when trying to identify
modification time.

This fix returns a zero timestamp in such cases, ensuring it never triggers docs
refreshes. We do the same e.g. in PackageInfo instances.
2024-05-03 12:23:49 -07:00
Tim Wojtulewicz
cdcd83c8cc Merge remote-tracking branch 'origin/topic/vern/val-footprint-strings'
* origin/topic/vern/val-footprint-strings:
  refine Val "footprint" to equate long strings with multiple objects
2024-05-02 19:01:06 -07:00
Tim Wojtulewicz
38dae684bd Constify classes in RuleMatcher, fixes c++20 build failure 2024-05-01 16:59:54 -07:00
Vern Paxson
1f9fa4304d refine Val "footprint" to equate long strings with multiple objects 2024-04-29 12:39:36 -07:00
Tim Wojtulewicz
522bce8d58 Merge remote-tracking branch 'origin/topic/vern/script-opt.May24'
* origin/topic/vern/script-opt.May24:
  factored BTest constants into globals to prevent premature ZAM optimization when testing
  addressed minor issues flagged by Coverity
2024-04-29 09:08:28 -07:00
Tim Wojtulewicz
19702b06e7 Merge remote-tracking branch 'origin/topic/timw/val-avoid-type-casting'
* origin/topic/timw/val-avoid-type-casting:
  Avoid calling typecasts in Val when we have direct access to the underlying value object
2024-04-29 09:06:39 -07:00
Robin Sommer
cee92cbf6b
Spicy: Cleanup some runtime code. 2024-04-29 08:38:53 +02:00
Robin Sommer
5a74db30ef
Spicy: Map Spicy's Protocol enum to Zeek's transport_proto.
We now hardcode this specific enum mapping to make Zeek-side usage
more convenient.

Closes #3606.
2024-04-29 08:38:53 +02:00
Vern Paxson
cf456f943f addressed minor issues flagged by Coverity 2024-04-27 19:40:03 -07:00
Tim Wojtulewicz
6900f3301e Move packet_analysis::Dispatcher to detail namespace 2024-04-26 13:11:45 -07:00
Tim Wojtulewicz
ad6d70d4e6 Merge remote-tracking branch 'pbcullen/topic/pbcullen/shadow-file-handling'
* pbcullen/topic/pbcullen/shadow-file-handling:
  reformat changes
  Gracefully handle empty/missing shadow file
2024-04-26 12:29:28 -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
d745fbbca2 Avoid calling typecasts in Val when we have direct access to the underlying value object 2024-04-25 10:33:41 -07:00
Vern Paxson
9cddf16800 rewrite of ZAM optimization of BiFs and script functions/idioms 2024-04-25 09:15:13 -07:00
Vern Paxson
ef4386ea13 ZAM optimization for constructing records w/ fields initialized to network_time 2024-04-25 09:15:13 -07:00
Vern Paxson
68aa8221e1 factor some functionality used by BiFs to make accessible to ZAM instructions 2024-04-25 09:15:13 -07:00
Vern Paxson
7c8c83efc4 factor script optimization Expr AST nodes out of main AST header 2024-04-25 09:15:13 -07:00
Vern Paxson
01fd30dda9 new internal AST node for expression idioms with corresponding ZAM built-ins 2024-04-25 09:15:13 -07:00
Vern Paxson
16b2946fef streamlining of expressions only used for script optimization 2024-04-25 09:15:13 -07:00
Vern Paxson
f557b40d14 reordering of expressions to match main usage vs. script-optimization extras 2024-04-25 09:15:13 -07:00
Vern Paxson
52f506b7ae support for conditional expressions transforming into interal has-elements expr 2024-04-25 09:15:12 -07:00
Vern Paxson
86d3c932b7 make same_expr() functionality accessible as a utility 2024-04-25 09:15:12 -07:00
Vern Paxson
d15d4a6e08 unify functionality across EqExpr and RelExpr classes 2024-04-25 09:15:12 -07:00