Commit graph

4103 commits

Author SHA1 Message Date
Robin Sommer
f8eb2d9241
Merge remote-tracking branch 'origin/topic/awelzel/2440-break-next-usage-validation'
* origin/topic/awelzel/2440-break-next-usage-validation:
  parse.y: Traverse AST post parsing to detect break/next usage issues
2022-11-02 10:59:29 +01:00
Tim Wojtulewicz
bc0284aefa Merge remote-tracking branch 'origin/topic/awelzel/2446-runtime-error-for-variadic-functions'
* origin/topic/awelzel/2446-runtime-error-for-variadic-functions:
  Func: Do not crash on va_args confusion for script funcs
2022-11-01 07:47:50 -07:00
Arne Welzel
4314467e44 Func: Do not crash on va_args confusion for script funcs
Script and BIF functions with a single any parameter are excluded from
type checking regarding arguments. This makes it possible to call a
ScriptFunc with more arguments than it actually has parameters and frame
space for, causing heap-buffer-overflows.

This change runtime checks expected parameters and provided arguments
and short-circuits execution as well as logging runtime expression errors.

Fixes #2446
2022-11-01 08:55:14 +01:00
Tim Wojtulewicz
6dec7d6027 Merge remote-tracking branch 'origin/topic/awelzel/record-fields-not-just-enum'
* origin/topic/awelzel/record-fields-not-just-enum:
  bifs/record_fields: Include actual enum name in type_name
2022-10-31 15:18:11 -07:00
Tim Wojtulewicz
352705d316 Merge remote-tracking branch 'origin/topic/awelzel/no-reassembly-for-known-ports'
* origin/topic/awelzel/no-reassembly-for-known-ports:
  IPBasedAnalyzer/TCPSessionAdapter: Fix TCP reassembly decision for known port analyzers
2022-10-31 14:57:39 -07:00
Christian Kreibich
95151e1da9 Merge remote-tracking branch 'origin/topic/awelzel/2425-cat-sep-fully-varargs'
* origin/topic/awelzel/2425-cat-sep-fully-varargs:
  cat_sep: Make fully vararg and do explicit runtime type checks
2022-10-28 16:55:29 -07:00
Arne Welzel
850aaaa5a8 parse.y: Traverse AST post parsing to detect break/next usage issues
Seemed easiest to do it via the traversal infrastructure as we do not
otherwise track enough context/scope when instantiating break or next
statements.

Might be worth moving this out of src/parse.y, but didn't exactly know
where. Or maybe we wait until there's more such trivial validations
popping up

Fixes #2440
2022-10-28 12:53:37 +02:00
Tim Wojtulewicz
d442ea1bb9 egrep reported as obsolete by opensuse-tumbleweed builds 2022-10-27 11:48:43 -07:00
Arne Welzel
a5f04b6270 cat_sep: Make fully vararg and do explicit runtime type checks
Using positional and vararg arguments for BIFs, it's not possible to do
proper runtime type checking on them as discussed in #2425. The bifcl produced
code unconditionally attempts to convert the positional arguments to StringVals,
but nothing ever type checks them. Instead of improving the vararg support in
Zeek script and bifcl, align cat_sep() with fmt() in making it fully vararg
and do implement type checks by hand.

With this change, passing wrong types for the separator and default argument
isn't a fatal error anymore and the error messages are also more descriptive.

It's a bit of a crutch working around varargs limitations.

Fixes #2425
2022-10-27 13:06:06 +02:00
Christian Kreibich
3237ad0ba2 Merge remote-tracking branch 'origin/topic/awelzel/builtin-af-packet'
* origin/topic/awelzel/builtin-af-packet:
  Include in Jan's AF_PACKET plugin as builtin plugin
2022-10-26 16:48:37 -07:00
Arne Welzel
699949cd40 bifs/record_fields: Include actual enum name in type_name
One more from @stevesmoot. The record_fields() BIF produced "enum" as
type_name for fields of type enum.

Extend container_type_name() to append the actual name of the enum.

This is changing the format and may break consumers, but those are
likely in a category that are happy to adapt. Not having the actual
enum name available wasn't very helpful.

We could alternatively render only the actual type_name without the
prefixed "enum", but that isn't how it's done for record types currently
and it would make it more difficult to decide which subsequent BIFs to
use for further introspection, like enum_names().
2022-10-26 20:21:20 +02:00
Arne Welzel
2ad609cbbb Reintroduce event groups
This started with reverting commit 52cd02173d
and then rewriting it to be per handler rather than handler identifier
and adding support for hooks as well as adding implicit module groups.
2022-10-25 18:03:26 +02:00
Arne Welzel
f3f593c523 IPBasedAnalyzer/TCPSessionAdapter: Fix TCP reassembly decision for known port analyzers
This seems to be an age-old bug. Reported by mchen on discourse [1].

The TCPSessionAdapter decides in AddExtraAnalyzers() whether to enable
reassembly or not. When dpd_reassemble_first_packets is F, this boils down to
! GetChildren().empty(). The intention being that if any analyzers have been
added to the connection based on known ports, reassembly is to be enabled.

However, GetChildren() does not take into account new_children and so
! GetChildren().empty() is always false here and reassembly solely
based on dpd_reassemble_first_packets=F (or the tcp_content... options).
Ouch.

Call AppendNewChildren() before AddExtraAnalyzers() as a fix. Without this,
the new test does not produce an http.log and service "http" isn't in conn.log.

[1] https://community.zeek.org/t/how-to-activate-an-application-layer-analyzer-when-signature-dpd-reassemble-first-packets-is-off/6763
2022-10-25 16:07:40 +02:00
Robin Sommer
5aa7d80e88
Merge remote-tracking branch 'origin/topic/awelzel/enum-names-with-strings'
* origin/topic/awelzel/enum-names-with-strings:
  enum_names: Support naming types with a string
2022-10-25 12:37:33 +02:00
Robin Sommer
9f3a234f40
Merge remote-tracking branch 'origin/topic/awelzel/blank-identifer'
* origin/topic/awelzel/blank-identifer:
  scripts: Migrate table iteration to blank identifiers
  Introduce special treatment for the blank identifier _
2022-10-25 12:36:23 +02:00
Christian Kreibich
92c758bd44 Management framework: bump zeek-client and cluster testsuite 2022-10-24 16:00:58 -07:00
Arne Welzel
8c5896a74d scripts: Migrate table iteration to blank identifiers
No obvious hot-cases. Maybe the describe_file() ones or the intel ones
if/when there are hot intel hits.
2022-10-24 10:36:09 +02:00
Arne Welzel
46334f8b59 Introduce special treatment for the blank identifier _
Mostly: Do not instantiate variables within for loops and allow
reusing differently typed blanks which previously wasn't possible.

This may be missing some corner-cases, but the added tests seem
to work as expected and nothing else fell apart it seems.
2022-10-24 10:36:01 +02:00
Arne Welzel
a00cef9920 enum_names: Support naming types with a string
In his ZeekWeek 2022 presentation, @stevesmoot mentioned that he had a
difficult time looking up enum names when all he had was a string
naming the type.

Add support to enum_names() to transparently lookup the type if a string
is provided. This is similar in how record_fields() behaves when being
passed a string.
2022-10-21 20:09:48 +02:00
Tim Wojtulewicz
6bb6fed49f Add btest that exercises the pcap filter warnings 2022-10-21 10:50:00 -07:00
Tim Wojtulewicz
5e4db6d0c4 Add column to packet_filter.log for failure reason 2022-10-21 10:50:00 -07:00
Tim Wojtulewicz
0143d0cb86 Merge remote-tracking branch 'origin/topic/vern/CPP-Oct22-maint'
* origin/topic/vern/CPP-Oct22-maint:
  -O C++ maintenance updates to test suite
  -O gen-C++ maintenance: fixes for attributes & initializing globals
2022-10-17 16:19:04 -07:00
Tim Wojtulewicz
3656699e2f Merge remote-tracking branch 'origin/topic/awelzel/2403-reject-conflicting-plugins'
* origin/topic/awelzel/2403-reject-conflicting-plugins:
  plugins: Reject dynamic plugins matching names of built-in ones
2022-10-16 17:49:32 -07:00
Tim Wojtulewicz
bd7df9e2bf Add &ordered attribute for tables/sets 2022-10-16 15:31:42 -07:00
Vern Paxson
f4c1309dfc -O C++ maintenance updates to test suite 2022-10-14 08:38:55 -05:00
Tim Wojtulewicz
16601eafa2 Merge remote-tracking branch 'origin/topic/vern/ZAM-Oct22-maint'
* origin/topic/vern/ZAM-Oct22-maint:
  ZAM maintenance for recent test suite changes (and fixups missed last time)
2022-10-13 08:57:59 -05:00
Arne Welzel
0bc7d0905e Include in Jan's AF_PACKET plugin as builtin plugin
This has come up a few times and the motivation is mainly better "first timer"
experience with Zeek. Concretely, if one wants to run a Zeek cluster with
multiple workers and reasonable load balancing on Linux, AF_PACKET is a decent
start. Without AF_PACKET support being built into Zeek, however, a new user's
next experience is that of setting up a development environment in order
to compile an external plugin (think compiler, kernel headers, zkg, ...).
Only to get what could be termed basic functionality.

This is using the ZEEK_INCLUDE_PLUGINS infrastructure. I've used the all
upper case spelling of AF_PACKET in the help output because it seems everyone
else references/writes it like that. I think we should also write it
like that in the docs.
2022-10-13 13:29:27 +02:00
Vern Paxson
64ec7d0728 ZAM maintenance for recent test suite changes (and fixups missed last time) 2022-10-12 11:29:52 -07:00
Arne Welzel
048f2201fb plugins: Reject dynamic plugins matching names of built-in ones
This goes the hard-exit on conflicts route as IMO it provides better
messaging that something is wrong, rather than defaulting to something
the user may not expect.

Fixes #2403
2022-10-12 18:45:17 +02:00
Robin Sommer
b114850283 Move API for disabling packet analyzers into component.
Before, that API was part of the analyzers themselves, which meant we
couldn't disable a packet analyzer before it had been instantiated.
That's different from protocol/file analyzers, where we disable them
through the corresponding component. The lack of the component-side
API prevented Spicy from replacing packet analyzers at startup.

The reason we had put this into analyzer originally was performance so
that we don't need a component lookup for every packet. This change
keeps that optimization by caching the on/off state in the analyzer
itself as well, but now with the component being the one controlling
it.
2022-10-10 08:26:26 +02:00
Johanna Amann
3d9a1157f9 Update CT log list.
This uses the v3 json as a source for the first time. The test needed
some updating because Google removed a couple more logs - in the future
this should hopefully not be neccessary anymore because I think v3
should retain all logs.

In theory this might be neat in 5.1.
2022-10-06 15:10:59 +01:00
Robin Sommer
6fcbb55ccd Merge remote-tracking branch 'origin/topic/awelzel/analyzer-module-enable-disable-file-analyzer'
* origin/topic/awelzel/analyzer-module-enable-disable-file-analyzer:
  analyzer: Add file_analyzer support to enable_analyzer()/disable_analyzer()
2022-10-05 13:27:23 +02:00
Tim Wojtulewicz
37d4a28816 Merge remote-tracking branch 'origin/topic/awelzel/http-no-current-entity'
* origin/topic/awelzel/http-no-current-entity:
  http: Prevent script errors when http$current_entity is not set
2022-10-03 09:44:46 -07:00
Arne Welzel
81fe46f123 analyzer: Add file_analyzer support to enable_analyzer()/disable_analyzer()
This allows to enable/disable file analyzers through the same interfaces
as packet and protocol analyzers, specifically Analyzer::disable_analyzer
could be interesting.
2022-09-30 11:47:56 +02:00
Arne Welzel
af5a0215c0 packet_analysis: Introduce PacketAnalyzer::__disable_analyzer()
This adds machinery to the packet_analysis manager for disabling
and enabling packet analyzers and implements two low-level bifs
to use it.

Extend Analyzer::enable_analyzer() and Analyzer::disable_analyzer()
to transparently work with packet analyzers, too. This also allows
to add packet analyzers to Analyzer::disabled_analyzers.
2022-09-30 09:27:22 +02:00
Arne Welzel
700a9a4f37 Introduce basic test triggering when zeek -r triggers script errors
I wonder if there's another one that covers errors during a basic zeek -r,
but didn't seem like.
2022-09-27 17:49:58 +02:00
Arne Welzel
d5cd023dff file_analysis: Implement AnalyzerViolation() for file_analysis/Analyzer
Add a test parsing a malformed PE file showing that analyzer_violation_info
is raised with the fa_file object set.

It could be interesting to pass through an optional connection if one
exists, but access is provided through f$conns, too.
2022-09-27 17:49:58 +02:00
Arne Welzel
bc8fd5a4c6 Introduce generic analyzer_confirmation_info and analyzer_violation_info
Introduce two new events for analyzer confirmation and analyzer violation
reporting. The current analyzer_confirmation and analyzer_violation
events assume connection objects and analyzer ids are available which
is not always the case. We're already passing aid=0 for packet analyzers
and there's not currently a way to report violations from file analyzers
using analyzer_violation, for example.

These new events use an extensible Info record approach so that additional
(optional) information can be added later without changing the signature.
It would allow for per analyzer extensions to the info records to pass
analyzer specific info to script land. It's not clear that this would be
a good idea, however.

The previous analyzer_confirmation and analyzer_violation events
continue to exist, but are deprecated and will be removed with Zeek 6.1.
2022-09-27 17:49:51 +02:00
Arne Welzel
3a320fc6b6 packet_analysis: Do not raise analyzer_confirmation per-packet for tunnels
There's a logic error in the packet analyzer's AnalyzerConfirmation()
method that causes analyzer_confirmation() events to be raised for every
packet rather than stopping after the first confirmation which appears to
have been the intention. This affects, for example, VXLAN and Geneve tunnels.

The optional arg_tag parameter was used for short-circuit'ing, but the return
value of GetAnalyzerTag() used for setting the session state causing the
disconnect.

In scenarios where Zeek receives purely tunneled monitoring traffic, this may
result in a non-negligible performance impact.

Somewhat related, ensure the session state is set to violated before
short-circuiting if no analyzer_violations are installed.

Suggesting this as a 5.0.3 candidate.
2022-09-27 12:49:56 +02:00
Arne Welzel
38e226bf75 http: Prevent script errors when http$current_entity is not set
The current_entity tracking in HTTP assumes that client/server never
send HTTP entities at the same time. The attached pcap (generated
artificially) violates this and triggers:

    1663698249.307259 expression error in <...>base/protocols/http/./entities.zeek, line 89: field value missing (HTTP::c$http$current_entity)

For the http-no-crlf test, include weird.log as baseline. Now that weird is
@load'ed from http, it is actually created and seems to make sense
to btest-diff it, too.
2022-09-26 10:18:24 +02:00
Arne Welzel
660172013b scripts/conn: Open-code determine_service()
...and avoid doing it as suggested by Justin to avoid the extra over-head
in scan scenarios where c$service is empty.
2022-09-20 23:07:26 +02:00
Arne Welzel
0e28a7faf5 strings: Implement join_string_set() as bif
Haven't measured speed, but this is probably faster than
the cat() and string invocations.
2022-09-20 23:07:26 +02:00
Arne Welzel
31aeb58e10 dpd: Replace negated service fmt() magic with dedicated field
...the only known cases where the `-` for `connection$service` was
handled is to skip/ignore these analyzers.

Slight suspicion that join_string_set() should maybe become a bif
now determine_service() runs once for each connection.

Closes #2388
2022-09-20 23:07:26 +02:00
Tim Wojtulewicz
2b60f63123 Start of 5.2.0 development 2022-09-20 09:23:50 -07:00
Tim Wojtulewicz
b3c2988c90 Update broker submodule 2022-09-20 09:02:50 -07:00
Christian Kreibich
d20ffb100c Merge branch 'topic/amazingpp/2384-record-deprecation' of github.com:/AmazingPP/zeek
* 'topic/amazingpp/2384-record-deprecation' of github.com:/AmazingPP/zeek:
  Replace all the Warning() calls after IsFieldDeprecated() over to Warn()
  Fix deprecation not flagged and incorrect line number in record
2022-09-19 18:15:39 -07:00
Tim Wojtulewicz
f04f070d9f Merge remote-tracking branch 'origin/topic/vern/cpp-maint-Sep22'
* origin/topic/vern/cpp-maint-Sep22:
  oof more manual fixups
  undo inadvertently committed tweak to test
  update for btest only run in some environments
  btest tweaks for recent changes
  updates to notes for compile-to-C++ maintenance
  newly-created btest files
  baseline updates for -a cpp alternative (compile-to-C++)
  tweak btest so it's recognized as a candidate for C++ compilation testing
  split basic "int" btests into main part versus now-separate overflow part
  fix deprecated "local" scoping in test scripts
  annotated scripts to skip when testing compilation-to-C++
  C++ script generation fix for lambdas that have identical bodies
  fix for C++ scripts that refer to "opaque" types
  C++ compilation support for 2-valued vector "for" loops
  C++ compilation support for RE /s operator
  run-time checking of vector operations for overflows and division-by-zero
  error propagation fix to avoid a crash
2022-09-19 13:51:41 -07:00
Vern Paxson
2dfaa00c61 oof more manual fixups 2022-09-16 18:45:46 -07:00
Vern Paxson
bf0a74264a undo inadvertently committed tweak to test 2022-09-16 18:44:09 -07:00
Vern Paxson
3c0b07d149 update for btest only run in some environments 2022-09-16 18:43:05 -07:00