Commit graph

4584 commits

Author SHA1 Message Date
Arne Welzel
f3470843d6 rule-parse: Remove [event_name] syntax, deprecate msg as identifier
As suggested by Robin. Thanks.
2023-12-14 10:16:35 +01:00
Vern Paxson
56cf3170c2 recent BTests that should be skipped when using -O gen-C++ 2023-12-12 09:45:19 +01:00
Tim Wojtulewicz
9e8a738a8a Merge remote-tracking branch 'origin/topic/vern/CSE-opt'
* origin/topic/vern/CSE-opt:
  incorporate latest version of gen-zam to correctly generate indirect calls
  added sub-directory for tracking ZAM maintenance issues
  BTest to stress-test AST optimizer's assessment of side effects
  reworked AST optimizers analysis of side effects during aggregate operations & calls
  script optimization support for tracking information associated with BiFs/functions
  fix for AST analysis of inlined functions
  improved AST optimizer's analysis of variable usage in inlined functions
  new method for Stmt nodes to report whether they could execute a "return"
  bug fixes for indirect function calls when using ZAM
  minor fixes for script optimization, exporting of attr_name, script layout tweak
2023-12-08 10:01:23 -07:00
Vern Paxson
6f0495b6ea BTest to stress-test AST optimizer's assessment of side effects 2023-12-06 12:26:46 -08:00
Arne Welzel
a7b077aa17 signatures: Support custom event via [event_name] syntax
This change allows to specify a per signature specific event, overriding
the default signature_match event. It further removes the message
parameter from such events if not provided in the signature.

This also tracks the message as StringValPtr directly to avoid
allocating the same StringVal for every DoAction() call.

Closes #3403
2023-12-05 15:28:21 +01:00
Arne Welzel
28eef9e4b2 Merge remote-tracking branch 'origin/topic/awelzel/log-write-delay-3'
* origin/topic/awelzel/log-write-delay-3:
  logging: ref() to record_ref() renaming
  logging: Fix typos from review
  logging/Manager: Make LogDelayExpiredTimer an implementation detail
  logging/WriteToFilters: Use range-based for loop
  testing/btest: Log::delay() from JavaScript
  NEWS: Entry for delayed log writes
  Bump doc submodule to branch
  logging: Do not keep delay state persistent
  logging: delay documentation polishing
  logging: Better error messages for invalid Log::delay() calls
  logging/Manager: Implement DelayTokenType as an actual opaque
  logging: Implement get_delay_queue_size()
  logging: Introduce Log::delay() and Log::delay_finish()
  logging/Manager: zeek::detail'ify
  logging/Manager: Split Write()
  Timer: Add LOG_DELAY_EXPIRE timer type
  Ascii: Remove extra include
2023-12-01 12:05:02 +01:00
Arne Welzel
a59578e018 Merge branch 'topic/awelzel/3473-register-telemetry-opaque-vals'
* topic/awelzel/3473-register-telemetry-opaque-vals:
  OpaqueVal: Register TelemetryVals, too
2023-11-30 10:19:44 +01:00
Arne Welzel
0a3d98973f testing/btest: Log::delay() from JavaScript 2023-11-29 12:52:19 +01:00
Arne Welzel
e3796894c6 logging: Do not keep delay state persistent
If Log::remove_stream() and Log::create_stream() is called for a stream,
do not restore the previously used max delay or max queue size.
2023-11-29 11:53:11 +01:00
Arne Welzel
fd096b1ce6 logging: delay documentation polishing
Based on PR feedback.
2023-11-29 11:53:11 +01:00
Arne Welzel
e2ce929fa4 logging: Better error messages for invalid Log::delay() calls
Add a test for Log::delay() usage within filter policy hooks, too.
2023-11-29 11:53:11 +01:00
Arne Welzel
5e046eee58 logging/Manager: Implement DelayTokenType as an actual opaque
With a bit of tweaking in the JavaScript plugin to support opaque types, this
will allow the delay functionality to work there, too.

Making the LogDelayToken an actual opaque seems reasonable, too. It's not
supposed to be user inspected.
2023-11-29 11:53:11 +01:00
Arne Welzel
2dbb467ba2 logging: Implement get_delay_queue_size()
Primarily for introspection given that re-delaying may exceed
queue sizes.
2023-11-29 11:53:11 +01:00
Arne Welzel
f0e67022fd logging: Introduce Log::delay() and Log::delay_finish()
This is a verbose, opinionated and fairly restrictive version of the log delay idea.
Main drivers are explicitly, foot-gun-avoidance and implementation simplicity.

Calling the new Log::delay() function is only allowed within the execution
of a Log::log_stream_policy() hook for the currently active log write.

Conceptually, the delay is placed between the execution of the global stream
policy hook and the individual filter policy hooks. A post delay callback
can be registered with every Log::delay() invocation. Post delay callbacks
can (1) modify a log record as they see fit, (2) veto the forwarding of the
log record to the log filters and (3) extend the delay duration by calling
Log::delay() again. The last point allows to delay a record by an indefinite
amount of time, rather than a fixed maximum amount. This should be rare and
is therefore explicit.

Log::delay() increases an internal reference count and returns an opaque
token value to be passed to Log::delay_finish() to release a delay reference.
Once all references are released, the record is forwarded to all filters
attached to a stream when the delay completes.

This functionality separates Log::log_stream_policy() and individual filter
policy hooks. One consequence is that a common use-case of filter policy hooks,
removing unproductive log records, may run after a record was delayed. Users
can lift their filtering logic to the stream level (or replicate the condition
before the delay decision). The main motivation here is that deciding on a
stream-level delay in per-filter hooks is too late. Attaching multiple filters
to a stream can additionally result in hard to understand behavior.

On the flip side, filter policy hooks are guaranteed to run after the delay
and can be used for further mangling or filtering of a delayed record.
2023-11-29 11:53:11 +01:00
Johanna Amann
424d1c00dd Merge remote-tracking branch 'origin/topic/johanna/fix-parsing-of-some-server-keyexchange-messages'
* origin/topic/johanna/fix-parsing-of-some-server-keyexchange-messages:
  TLS: Update cipher consts and keyexchange parsing
2023-11-28 15:12:28 +00:00
Arne Welzel
aa5d7f5a73 OpaqueVal: Register TelemetryVals, too
Even if they are not serializable, OpaqueMgr::TypeID() is called
during BuildJSON() for them and that previously just aborted.

Closes #3473
2023-11-28 09:21:31 +01:00
Arne Welzel
02d00a1984 OCSP: Open-code unknown revoke reason strings
OpenSSL 3.2.0 knows about more reasons. Add some backwards compatibility.

Reference: 1c8a7f5091
2023-11-27 20:53:00 +01:00
Johanna Amann
7c0f325d1b TLS: Update cipher consts and keyexchange parsing
Update cipher consts.

Furthermore some past updates have been applied to scriptland, but it
was not considered that some of these also have to be applied to binpac
code, to be able to correcly parse the ServerKeyExchange message.

(As a side-note - this was discovered due to a test discrepancy with the
Spicy parser)
2023-11-27 16:22:24 +00:00
Johanna Amann
9a4de4e9fc Spicy: allow providing file id in zeek::file_begin
Minor update of testcase
2023-11-23 17:17:48 +00:00
Johanna Amann
45c558af1e Spicy: allow providing file id in zeek::file_begin
Address feedback of GH-3470:
 minor changes of C++ code, unify test cases
2023-11-22 16:31:40 +00:00
Johanna Amann
ae0b328826 Spicy: allow providing file id in zeek::file_begin
Allow spicy parsers to generate their own file IDs and provide them to
Zeek. This duplicates functionality that is currently possible (and
used) by some binpac-based analyzers. One example for an analyzer
creating its own file IDs is the SSL analyzer.
2023-11-22 14:51:53 +00:00
Arne Welzel
c113b9b297 Expr/Val: Add support for in set[pattern] 2023-11-21 10:34:17 +01:00
Arne Welzel
e39f280e3d zeek.bif: Implement table_pattern_matcher_stats() bif for introspection
Provide a script accessible way to introspect the DFA stats that can be
leveraged to gather runtime statistics of the underlying DFA. This
re-uses the existing MatcherStats used by ``get_matcher_stats()``.
2023-11-21 10:34:17 +01:00
Arne Welzel
c72d4a4427 Expr: Implement string in table[pattern] of X
Not sure how useful this is (and the implementation isn't optimized in
any way), but seems reasonable for consistency.

Vern suggested that set[pattern] can already be achieved via
set_to_regex(), so left out any set[pattern] variants.
2023-11-21 10:34:17 +01:00
Arne Welzel
074f51fc96 btest: Add test for pattern tables and when 2023-11-21 10:34:16 +01:00
Vern Paxson
fd1094a184 BTests for indexing "table[pattern] of T" with strings 2023-11-21 10:34:15 +01:00
Arne Welzel
a5a79d3f3a Merge remote-tracking branch 'origin/topic/awelzel/3453-dnssec-ed448-ed25519'
* origin/topic/awelzel/3453-dnssec-ed448-ed25519:
  DNS: Add Ed25519 and Ed448 enum values to parser
2023-11-21 10:08:34 +01:00
Arne Welzel
c58f3149b3 Merge remote-tracking branch 'origin/topic/awelzel/3455-sub-gsub-anchors'
* origin/topic/awelzel/3455-sub-gsub-anchors:
  frameworks/software: Fix stale value used for stripping
  strings.bif/sub,gsub: Respect anchors in pattern
2023-11-21 10:04:49 +01:00
Arne Welzel
81aa6b14fd DNS: Add Ed25519 and Ed448 enum values to parser
We already had these declared in dns/const.zeek, so extend the parser
as well to avoid raising weirds and add some test pcaps:

   $ dig @8.8.8.8 DNSKEY ed448.no
   $ dig @8.8.8.8 ed448.no +dnssec

And the same for the ed25519.no domain.

Closes #3453
2023-11-17 19:56:47 +01:00
Arne Welzel
b0a200a5dc Merge remote-tracking branch 'origin/topic/vern/zam-EH-coalesce'
* origin/topic/vern/zam-EH-coalesce:
  BTest updates to accommodate event handler coalescence differences
  BTests for testing that event handler coalescence operates as expected
  coalescing of event handlers (ZAM optimization)

Minor fixups during merge as commented on the PR.
2023-11-17 18:05:32 +01:00
Arne Welzel
e339e93e69 strings.bif/sub,gsub: Respect anchors in pattern
Anchors within pattern passed to sub() or gsub() were previously ignored,
replacing any occurrence of '<text>' even when '^<text>' was used as a
pattern.

This is a pretty user-visible change (and we even have anchored patterns
within the base scripts), but seems "the right thing to do".

Relates to #3455
2023-11-17 14:37:25 +01:00
Vern Paxson
fc2796a5a4 BTest updates to accommodate event handler coalescence differences 2023-11-16 13:04:35 -08:00
Vern Paxson
39e1f71ebf BTests for testing that event handler coalescence operates as expected 2023-11-16 13:03:40 -08:00
Arne Welzel
98d9089a8f strings.bif/do_split_string: Pass bol and eol to MatchPrefix()
This allows better control of BOL and EOL. MatchPrefix() / LongestMatch()
always start with BOL.

Closes #3455
2023-11-16 08:36:08 +01:00
Vern Paxson
280acc51bf BTest updates for latest ZAM maintenance 2023-11-10 09:57:35 +01:00
Vern Paxson
23c08a05de descriptions of "for" statements now include their "value variable" if present 2023-11-10 09:56:51 +01:00
Robin Sommer
2498f7dbe9
Merge remote-tracking branch 'origin/topic/robin/gh-3443-skip'
* origin/topic/robin/gh-3443-skip:
  Spicy: Provide `zeek::skip_input()` to disable deliver to current analyzer.
2023-11-09 17:22:48 +01:00
Robin Sommer
f5aa5c3466
Spicy: Provide zeek::skip_input() to disable deliver to current analyzer.
```
## Tells Zeek to skip sending any further input data to the current analyzer.
## This is supported for protocol and file analyzers.
public function skip_input() : void;
```

Closes #3443.
2023-11-09 10:43:49 +01:00
Arne Welzel
3174999445 btest/opt: Update pure-inlining baseline
I suspect this as just stale due to not being executed regularly.
2023-11-08 16:23:22 +01:00
Arne Welzel
e7f010d14e btest/opt: Update basic baseline 2023-11-08 15:54:55 +01:00
Arne Welzel
60e997a3fd btest: Move zam/basic.test into opt/basic.test, update TestDirs
It seems "opt" can and should run unconditionally. The "misc" dir was
definitely an oversight.
2023-11-08 15:46:54 +01:00
Arne Welzel
398122206e EventRegistry: Deprecate UsedHandlers() and UnusedHandlers()
and check_for_unused_event_handlers: UsageAnalyzer is more thorough
and the previous ones weren't extended to work with &is_used and
should probably be considered superseded by the UsageAnalyzer even
if that currently does not provide a public API and just prints
out deprecation warnings.

I'm also tempted to deprecate SetUsed() and Used() of EventHandler
for the same reason.

Closes #3187.
2023-11-07 16:06:17 +01:00
Arne Welzel
384453346d policy/misc/load-balancing: Deprecate script 2023-11-07 16:06:16 +01:00
Arne Welzel
d88b147ac9 cluster: Deprecate the Cluster::Node$interface field
This field isn't required by a worker and it's certainly not used by a
worker to listen on that specific interface. It also isn't required to
be set consistently and its use in-tree limited to the old load-balancing
script.

There's a bif called packet_source() which on a worker will provide
information about the actually used packet source.

Relates to zeek/zeek#2877.
2023-11-07 16:06:16 +01:00
Arne Welzel
8a13155a41 Merge branch 'topic/xb-anssi/http_signature_body_end_match' of https://github.com/xb-anssi/zeek
* 'topic/xb-anssi/http_signature_body_end_match' of https://github.com/xb-anssi/zeek:
  Let signature framework match HTTP body end
  Test how the signature framework matches HTTP body
2023-11-07 09:58:59 +01:00
xb-anssi
c8103dd963
Test how the signature framework matches HTTP body
This adds a signatures/http-body-match btest to verify how the signature
framework matches HTTP body in requests and responses.

It currently fails because the 'http-request-body' and 'http-reply-body'
clauses never match anything when there is a '$' in their regular
expressions.

The other pattern clauses such as the 'payload' clause do not suffer
from that restriction and it is not documented as a limitation of HTTP
body pattern clauses either, so it is probably a bug.

The "http-body-match" btest shows that without a fix any signatures
which ends with a '$' in a http-request-body or http-reply-body rule
will never raise a signature_match() event, and that signatures which do
not end with a '$' cannot distinguish an HTTP body prefixed by the
matching pattern (ex: ABCD) from an HTTP body consisting entirely of the
matching pattern (ex: AB).

Test cases by source port:
- 13579:
  - GET without body, plain res body (CD, only)
- 13578:
  - GET without body, plain res body (CDEF, prefix)
- 24680:
  - POST plain req body (AB, only), plain res body (CD, only)
- 24681:
  - POST plain req body (ABCD, prefix), plain res body (CDEF, prefix)
- 24682:
  - POST gzipped req body (AB, only), gzipped res body (CD, only)
  - POST plain req body (CD, only), plain res body (EF, only)
- 33210:
  - POST multipart plain req body (AB;CD;EF, prefix)
  - plain res body (CD, only)
- 33211:
  - POST multipart plain req body (ABCD;EF, prefix)
  - plain res body (CDEF, prefix)
- 34527:
  - POST chunked gzipped req body (AB, only)
  - chunked gzipped res body (CD, only)
- 34528:
  - POST chunked gzipped req body (ABCD, prefix)
  - chunked gzipped res body (CDEF, prefix)

The tests with source ports 24680, 24682 and 34527 should
match the signature http_request_body_AB_only and the signature
http_request_body_AB_prefix, but they only match the latter.

The tests with source ports 13579, 24680, 24682, 33210 and 34527 should
match the signature http_response_body_CD_only and the signature
http_response_body_CD_prefix, but they only match the latter.

The tests with source ports 24680, 24681, 33210 and 33211 show how the
http_request_body_AB_then_CD signature with two http-request-body
conditions match either on one or multiple requests (documented
behaviour).

The test cases with other source ports show where the
http_request_body_AB_only and http_response_body_CD_only signatures
should not match because their bodies include more than the searched
patterns.
2023-11-03 15:28:15 +01:00
Dominik Charousset
cebb85b1e8 Fix unsafe and inefficient uses of copy_string
Add a new overload to `copy_string` that takes the input characters plus
size. The new overload avoids inefficient scanning of the input for the
null terminator in cases where we know the size beforehand. Furthermore,
this overload *must* be used when dealing with input character sequences
that may have no null terminator, e.g., when the input is from a
`std::string_view` object.
2023-11-03 15:25:38 +01:00
Johanna Amann
3257c0e216 Merge remote-tracking branch 'origin/topic/johanna/its-time-to-add-more-tls-extension-types'
* origin/topic/johanna/its-time-to-add-more-tls-extension-types:
  SSL: Add new extension types and ECH test
2023-10-31 16:19:57 +00:00
Tim Wojtulewicz
d7cb384545 Merge remote-tracking branch 'origin/topic/bbannier/use-spicy-formatting-style'
* origin/topic/bbannier/use-spicy-formatting-style:
  Update `.git-blame-ignore-revs`
  Format JSON with clang-format
  Bump pre-commit hooks
  Reformat Zeek in Spicy style
2023-10-30 12:48:37 -07:00
Johanna Amann
ff27eb5a69 SSL: Add new extension types and ECH test
This commit adds a multitude of new extension types that were added in
the last few years; it also adds grease values to extensions, curves,
and ciphersuites.

Furthermore, it adds a test that contains a encrypted-client-hello
key-exchange (which uses several extension types that we do not have in
our baseline so far).
2023-10-30 14:19:16 +00:00