Commit graph

3207 commits

Author SHA1 Message Date
Arne Welzel
b745556d36 ftp: Do not base seq on number of pending commands
Previously, seq was computed as the result of |pending_commands|+1. This
opened the possibility to override queued commands, as well as logging
the same pending ftp reply multiple times.

For example, when commands 1, 2, 3 are pending, command 1 may be dequeued,
but the incoming command then receives seq 3 and overrides the already
pending command 3. The second scenario happens when ftp_reply() selected
command 3 as pending for logging, but is then followed by many ftp_request()
events. This resulted in command 3's response being logged for every
following ftp_request() over and over again.

Avoid both scenarios by tracking the command sequence as an absolute counter.
2023-10-25 10:05:09 -07:00
Arne Welzel
f6615753f1 ssl: Prevent unbounded ssl_history growth
The previous fix also made it clear that the ssl_history field may grow
unbounded via the ssl_alert event. Prevent by capping using a configurable
limit (default 100) and raise a weird once reached.
2023-10-25 10:05:09 -07:00
Arne Welzel
da91cee022 ssl: Cap number of alerts parsed from SSL record
Limit the number of events raised from an SSL record with content_type
alert (21) to a configurable maximum number (default 10). For TLS 1.3,
the limit is set to 1 as specified in the RFC. Add a new weird for the
in cases where the limit is exceeded.

OSS-Fuzz managed to generate a reproducer that raised ~660k ssl_plaintext
and ssl_alert events together given ~810kb of input data. This prevents
it with hopefully no negative side-effect in the real-world.
2023-10-25 10:05:09 -07:00
Arne Welzel
65f8222b92 Merge remote-tracking branch 'origin/topic/awelzel/mmdb-fix-and-tests'
* origin/topic/awelzel/mmdb-fix-and-tests:
  base/frameworks/spicy: Do not load base/misc/version
  btest/core/mmdb: Basic lookup_autonomous_system / lookup_location tests
  btest/files: Add mmdb testing databases and generator code
  zeek.bif: Switch mmdb stale check to network_time
  Fix mmdb pointer destruction

(cherry picked from commit 44b67894ac)
2023-10-24 13:49:25 -07:00
Johanna Amann
3c3a3c92ea Add extract_limit_includes_missing option for file extraction
Setting this option to false does not count missing bytes in files towards the
extraction limits, and allows to extract data up to the desired limit,
even when partial files are written.

When missing bytes are encountered, files are now written as sparse
files.

Using this option requires the underlying storage and utilities to support
sparse files.

(cherry picked from commit afa6f3a0d3b8db1ec5b5e82d26225504c2891089)
2023-09-12 09:41:03 -07:00
Johanna Amann
9ab61fb626 File extraction: use fseek
In the past, we allocated a buffer with zeroes and wrote that with
fwrite. Now, instead we just fseek to the correct offset.

This changes the way in which the file extract limit is counted a bit;
skipped bytes do no longer count against the file size limit.

(cherry picked from commit 5071592e9b7105090a1d9de19689c499070749d4)
2023-09-12 09:40:56 -07:00
Arne Welzel
a96bcef839 ftp: Do not log non-pending commands
OSS Fuzz generated a CWD request and reply followed by very many EPRT
requests. This caused Zeek to re-log the CWD request and invoke `build_url_ftp()`
over and over again resulting in long processing times.

Avoid this scenario by not logging commands that aren't pending anymore.

(cherry picked from commit b05dd31667ff634ec7d017f09d122f05878fdf65)
2023-09-12 09:40:51 -07:00
Arne Welzel
3724c14ad2 http/smtp: Fix wrong character class usage
A call to `extract_filename_from_content_disposition()` is only
efficient if the string is guaranteed to contain the pattern that
is removed by `sub()`. Due to missing brackets around the `[:blank:]`
character class, an overly long string (756kb) ending in
"Type:dtanameaa=" matched the wrong pattern causing `sub()` to
exhibit quadratic runtime. Besides that, we may have potentially
extracted wrong information from a crafted header value.

(cherry picked from commit 6d385b1ca724a10444865e4ad38a58b31a2e2288)
2023-09-12 09:40:38 -07:00
Arne Welzel
fe9c7d4191 Merge remote-tracking branch 'origin/topic/jazoff/gh-3268t '
* origin/topic/jazoff/gh-3268:
  Fix check for emailed notices

Changes: Added a test-case printing email_delay_tokens to compare email vs
non-email notice types. Previously, both notice types would have email
delay tokens at that point in the flow.

(cherry picked from commit 7e11501d3c)
2023-09-08 11:09:56 -07:00
Johanna Amann
ab2b241c3f Merge remote-tracking branch 'origin/topic/johanna/gh-3242'
* origin/topic/johanna/gh-3242:
  Community-id: load main script in notice script, fix notice script

(cherry picked from commit 70c76977cf)
2023-08-23 10:16:45 -07:00
Tim Wojtulewicz
5811e58139 Merge remote-tracking branch 'origin/topic/awelzel/3145-dcerpc-state-clean'
* origin/topic/awelzel/3145-dcerpc-state-clean:
  dce-rpc: Test cases for unbounded state growth
  dce-rpc: Handle smb2_close_request() in scripts
  smb/dce-rpc: Cleanup DCE-RPC analyzers when fid is closed and limit them
  dce-rpc: Do not repeatedly register removal hooks

(cherry picked from commit f9904511ab)
2023-08-08 12:55:21 -07:00
Arne Welzel
4ae02b7973 Merge branch 'master' of https://github.com/progmboy/zeek
* 'master' of https://github.com/progmboy/zeek:
  fix http AUTHORIZATION base64 decode failed

Added a test during merge.

(cherry picked from commit b18122da08)
2023-08-08 12:51:51 -07:00
Tim Wojtulewicz
36fb655caa Merge remote-tracking branch 'origin/topic/awelzel/no-metrics-centralization'
* origin/topic/awelzel/no-metrics-centralization:
  telemetry: Disable metrics centralization by default

(cherry picked from commit 0fbfaeb996)
2023-06-21 15:42:10 -07:00
Arne Welzel
7e2d9aa7be Merge branch 'topic/awelzel/3112-log-suffix-left-over-log-rotation'
* topic/awelzel/3112-log-suffix-left-over-log-rotation:
  cluster/logger: Fix leftover-log-rotation in multi-logger setups
  cluster/logger: Fix global var reference

(cherry picked from commit f53aefdd5b)
2023-06-15 15:21:02 -07:00
Tim Wojtulewicz
d2b534e6b2 Merge remote-tracking branch 'origin/topic/awelzel/cluster-at-if-removal'
* origin/topic/awelzel/cluster-at-if-removal:
  test-all-policy: Do not load nodes-experimental/manager.zeek
  cluster/main: Remove extra @if ( Cluster::is_enabled() )

(cherry picked from commit 98e44ee14f)
2023-06-12 11:23:01 -07:00
Tim Wojtulewicz
b34e70e6cd Merge remote-tracking branch 'origin/topic/awelzel/3099-fix-and-extend-socks5-sig'
* origin/topic/awelzel/3099-fix-and-extend-socks5-sig:
  socks/dpd: Add newer auth methods
  socks/dpd: Fix socks5_server side signature

(cherry picked from commit c389d9804b)
2023-06-12 11:01:14 -07:00
Tim Wojtulewicz
1cfe0e3ee7 Merge remote-tracking branch 'origin/topic/bbannier/issue-3094'
* origin/topic/bbannier/issue-3094:
  Simplify code generated for Spicy analyzer port ranges.
2023-05-31 09:50:46 +02:00
Arne Welzel
737ac43942 catch-and-release: Mark cr_check_rule as is_used 2023-05-31 00:37:38 -07:00
Tim Wojtulewicz
5a3abbe364 Revert "Merge remote-tracking branch 'origin/topic/vern/at-if-analyze'"
This reverts commit 4e797ddbbc, reversing
changes made to 3ac28ba5a2.
2023-05-31 09:20:33 +02:00
Benjamin Bannier
dc735371be Simplify code generated for Spicy analyzer port ranges.
We previously would reprent port ranges from EVT files element-wise.
This can potentially generate a lot of code (all on a single line
though) which some versions of GCC seem to have trouble with, and which
also causes JIT overhead.

With this patch we switch to directly representing ranges. Single ports
are represented as ranges `[start, start]`.

Closes #3094.
2023-05-29 12:20:44 +02:00
Tim Wojtulewicz
4e797ddbbc Merge remote-tracking branch 'origin/topic/vern/at-if-analyze'
* origin/topic/vern/at-if-analyze:
  updates reflecting review comments
  change base scripts to use run-time if's or @if ... &analyze
  a number of BTests updated with @if ... &analyze
  update for scripting coverage BTest demonstrating utility of @if ... &analyze
  BTests for new @if ... &analyze functionality
  "if ( ... ) &analyze" language feature
  classes for tracking "@if (...) &analyze" notion of code being/not being "activated"
  RemoveGlobal() method for Scope class + simplifying interfaces
2023-05-26 14:56:01 -07:00
Vern Paxson
e441ba394a updates reflecting review comments 2023-05-25 18:00:13 -07:00
Arne Welzel
f396c2b16e stats: Add zeek-net-packet-lag-seconds metric
While writing documentation about troubleshooting and looking a bit
at the older stats.log, realized we don't have the packet lag metric
exposed as metric/telemetry. Add it.

This is a Zeek instance lagging behind in network time ~6second because
it's very overloaded:

    zeek_net_packet_lag_seconds{endpoint=""} 6.169406 1684848998092
2023-05-24 09:12:01 +02:00
Vern Paxson
890010915a change base scripts to use run-time if's or @if ... &analyze 2023-05-19 13:26:27 -07:00
Arne Welzel
d4c99e7c3f files: Warn once for missing get_file_handle()
Repeating the message for every new call to get_file_handle() is not
very useful. It's pretty much an analyzer configuration issue so logging
it once should be enough.
2023-05-19 09:37:51 -07:00
Arne Welzel
64f84aba34 ftp: No unbounded directory command re-use
OSS-Fuzz generated traffic containing a CWD command with a single very large
path argument (427kb) starting with ".___/` \x00\x00...", This is followed
by a large number of ftp replies with code 250. The directory logic in
ftp_reply() would match every incoming reply with the one pending CWD command,
triggering path buildup ending with something 120MB in size.

Protect from re-using a directory command by setting a flag in the
CmdArg record when it was consumed for the path traversal logic.

This doesn't prevent unbounded path build-up generally, but does prevent the
amplification of a single large command with very many small ftp_replies.
Re-using a pending path command seems like a bug as well.
2023-05-19 09:37:12 -07:00
Arne Welzel
c2a07476cc Merge remote-tracking branch 'jgras/topic/jgras/cluster-active-node-count-fix'
* jgras/topic/jgras/cluster-active-node-count-fix:
  Fix get_active_node_count for node types not present.

Changed over to explicit existence check instead to avoid the set()
creation upon missed lookups.
2023-05-17 10:37:00 +02:00
Jan Grashoefer
e4f654c14c Fix get_active_node_count for node types not present. 2023-05-16 17:47:50 +02:00
Robin Sommer
ecf00295c2
Move spicy/misc scripts to policy and clarify purpose. 2023-05-16 10:21:21 +02:00
Robin Sommer
a62e153dd3
Do not load Spicy scripts if Spicy is not available. 2023-05-16 10:21:21 +02:00
Robin Sommer
0040111955
Integrate the Spicy plugin into Zeek proper.
This reflects the `spicy-plugin` code as of `d8c296b81cc2a11`.

In addition to moving the code into Zeek's source tree, this comes
with a couple small functional changes:

- `spicyz` no longer tries to infer if it's running from the build
  directory. Instead `ZEEK_SPICY_LIBRARY` can be set to a custom
  location. `zeek-set-path.sh` does that now.

- ZEEK_CONFIG can be set to change what `spicyz -z` print out. This is
  primarily for backwards compatibility.

Some further notes on specifics:

- We raise the minimum Spicy version to 1.8 (i.e., current `main`
  branch).

- Renamed the `compiler/` subdirectory to `spicyz` to avoid
  include-path conflicts with the Spicy headers.

- In `cmake/`, the corresponding PR brings a new/extended version of
  `FindZeek`, which Spicy analyzer packages need. We also now install
  some of the files that the Spicy plugin used to bring for testing,
  so that existing packages keep working.

- For now, this all remains backwards compatible with the current
  `zkg` analyzer templates so that they work with both external and
  integrated Spicy support. Later, once we don't need to support any
  external Spicy plugin versions anymore, we can clean up the
  templates as well.

- All the plugin's tests have moved into the standard test suite. They
  are skipped if configure with `--disable-spicy`.

This holds off on adapting the new code further to Zeek's coding
conventions, so that it remains easier to maintain it in parallel to
the (now legacy) external plugin. We'll make a pass over the
formatting for (presumable) Zeek 6.1.
2023-05-16 10:17:45 +02:00
Johanna Amann
3d257e52e2 Merge branch 'topic/johanna/dtls13'
* topic/johanna/dtls13:
  DTLS1.3 - address review feedback
  DTLS 1.3: Update test baseline
  DTLS 1.3: finish implementation, add connection_id extension
  Add basic DTLSv1.3 support
  SSL: Fix logging of Hello Retry Requests
2023-05-11 15:04:26 +01:00
Arne Welzel
e82a7455d7 policy/community-id: Do not use new_connection()
Issue #3028 tracks how a flipped connections reset a connection's value
including any state set during new_connection(). For the time being,
update community-id functionality back to the original connection_state_remove()
approach to avoid missing community_ids on flipped connections.
2023-05-10 17:48:33 +02:00
Johanna Amann
527c0dc09f Merge remote-tracking branch 'origin/master' into topic/johanna/dtls13
* origin/master: (35 commits)
  Update doc submodule [nomail] [skip ci]
  Updating submodule(s) [nomail]
  zeek.bif: Add log2() and ceil()
  Use the same rules as cmake submodule to reformat Zeek
  Update cmake submodule after reformat
  Fixup Val.h/Val.cc: Actually move ValFromJSON into zeek::detail
  Implement from_json bif
  Revert "Skip version.h by default for Zeek sources"
  BTest baseline updates for -O gen-C++
  updates to C++ maintenance scripts to better handle uncompilable BTests
  added ZEEK_REPORT_UNCOMPILABLE environment variable for "-O report-uncompilable"
  Skip version.h by default for Zeek sources
  core.network_time.broker: Test reliability improvement
  cluster/supervisor: Multi-logger awareness
  Bump zeek-archiver submodule
  ci: Add public-ecr-vacuum.sh
  Update doc submodule [nomail] [skip ci]
  generate-docs: Only update submodule pointer during scheduled builds
  BTest baseline updates for ZAM
  NTP: Detect out-of-order packets
  ...
2023-05-10 13:02:08 +01:00
Tim Wojtulewicz
84e3f414a7 Use the same rules as cmake submodule to reformat Zeek 2023-05-09 08:31:43 -07:00
Arne Welzel
9330a74fe1 Merge remote-tracking branch 'origin/topic/awelzel/zeek-archiver-multiple-loggers'
* origin/topic/awelzel/zeek-archiver-multiple-loggers:
  cluster/supervisor: Multi-logger awareness
  Bump zeek-archiver submodule
2023-05-09 15:20:53 +02:00
Arne Welzel
264284150b Merge remote-tracking branch 'amazing-pp/topic/fupeng/from_json_bif'
* amazing-pp/topic/fupeng/from_json_bif:
  Implement from_json bif

Minor updates during merge: Moved ValFromJSON into zeek::detail for the
time being, removed gotos, normalized some error messages to lower case,
minimal test extension and added a raw reader input framework test reading
"json lines" as a demo, adding notes about the implicit type
conversions.
2023-05-09 10:36:58 +02:00
Fupeng Zhao
584e68434d Implement from_json bif 2023-05-06 00:42:46 +00:00
Arne Welzel
c813872915 cluster/supervisor: Multi-logger awareness
When multiple loggers are configured in a Supervisor controlled cluster
configuration, encode extra information into the rotated filename to
identify which logger produced the log.

This is similar to the approach taken for ZeekControl, re-using the
log_suffix terminology, but as there's only a single zeek-archiver
process and no postprocessors and no other side-channel for additional
information, we encode extra metadata into the filename. zeek-archiver
is extended to recognize the special metadata part of the filename.

This also solves the issue that multiple loggers in a supervisor setup
overwrite each others log files within a single log-queue directory.
2023-05-05 12:27:25 +02:00
Arne Welzel
12252743b1 Merge remote-tracking branch 'origin/topic/awelzel/smb2-state-handling'
* origin/topic/awelzel/smb2-state-handling:
  NEWS: Add entry about SMB::max_pending_messages and state discarding
  scripts/smb2-main: Reset script-level state upon smb2_discarded_messages_state()
  smb2: Limit per-connection read/ioctl/tree state
2023-05-04 09:40:19 +02:00
Tim Wojtulewicz
8eed46dfa1 Merge remote-tracking branch 'origin/topic/johanna/update-ssl-databases'
* origin/topic/johanna/update-ssl-databases:
  Update Mozilla CA and Google CT lists
2023-05-03 11:13:23 -07:00
Johanna Amann
d6c4c510ea Add basic DTLSv1.3 support
DTLSv1.3 changes the DTLS record format, introducing a completely new
header - which is a first for DTLS.

We don't currently completely parse this header, as this requires a bit
more statekeeping. This will be added in a future revision. This also
also has little practical implications.
2023-05-03 16:17:31 +01:00
Johanna Amann
9742d9a76e Merge branch 'topic/johanna/no-error-message-durning-tls-or-dtls-protocol-violations'
* topic/johanna/no-error-message-durning-tls-or-dtls-protocol-violations:
  SSL: failing analyzer handling - address review feedback
  SSL: do not try to disable failed analyzer

Also folds in minor feedback from GH-3012
2023-05-03 14:20:44 +01:00
Johanna Amann
9a47e201f8 SSL: failing analyzer handling - address review feedback
Fold the two analyzer_violation_info events into one. See GH-3012
2023-05-03 13:41:36 +01:00
Johanna Amann
e7c9fa1f6e SSL: Fix logging of Hello Retry Requests
It turns out that we never logged hello retry requests correctly in the
ssl_history field.

Hello retry requests are (in their final version) signaled by a specific
random value in the server random.

This commit fixes this oversight, and hello retry requests are now
correctly logged as such.
2023-05-03 13:34:48 +01:00
Johanna Amann
21888a145a SSL: do not try to disable failed analyzer
Currently, if a TLS/DTLS analyzer fails with a protocol violation, we
will still try to remove the analyzer later, which results in the
following error message:

error: connection does not have analyzer specified to disable

Now, instead we don't try removing the analyzer anymore, after a
violation occurred.
2023-05-03 11:16:14 +01:00
Johanna Amann
40a4da94b6 Update Mozilla CA and Google CT lists 2023-05-03 10:46:41 +01:00
Arne Welzel
3ac877e20d scripts/smb2-main: Reset script-level state upon smb2_discarded_messages_state()
This is similar to what the external corelight/zeek-smb-clear-state script
does, but leverages the smb2_discarded_messages_state() event instead of
regularly checking on the state of SMB connections.

The pcap was created using the dperson/samba container image and mounting
a share with Linux's CIFS filesystem, then copying the content of a
directory with 100 files. The test uses a BPF filter to imitate mostly
"half-duplex" traffic.
2023-05-03 11:22:01 +02:00
Arne Welzel
5caab1a667 smb2: Limit per-connection read/ioctl/tree state
Users on Slack observed memory growth in an environment with a lot of
SMB traffic. jeprof memory profiling pointed at the offset and fid maps
kept per-connection for smb2 read requests.

These maps can grow unbounded if responses are seen before requests, there's
packet drops, just one side of the connection is visible, or we fail to parse
responses properly.

Forcefully wipe out these maps when they grow too large and raise
smb2_discarded_messages_state() to notify script land about this.
2023-05-03 10:58:59 +02:00
Arne Welzel
df4f90b65c ip4_hdr: Add DF, MF, offset and sum fields
For low-level packet analysis use-cases, these fields are currently
not script-land accessible via raw_packet() or so. They are accessible
on the icmp_context record, but not on the actual ip4_hdr record, so
add them.
2023-04-29 17:09:43 +02:00