Commit graph

4220 commits

Author SHA1 Message Date
Arne Welzel
4ac65ce8ca btest/decode_base_errors: Avoid binary output in baseline
Zeek prints the input string verbatim to the terminal and that's
upsetting btest just on Alpine.
2023-02-02 18:49:00 +01:00
Arne Welzel
b6df7773a9 Merge remote-tracking branch 'origin/topic/awelzel/arm64-container-follow-ups-2'
* origin/topic/awelzel/arm64-container-follow-ups-2:
  Bump private testsuite for char handling fixes
  Base64: report byte as positive integer
  netbios_decode: use unsigned char for result
  analyzer/http: Do not assume char is signed
  cirrus: Run tests in a Debian 11 container, too
2023-02-02 18:35:02 +01:00
Arne Welzel
bbe0a86d4a Bump private testsuite for char handling fixes 2023-02-02 16:24:41 +01:00
Arne Welzel
5dc54fb40e Base64: report byte as positive integer
A baseline difference between arm64 and x86 showed up. We would
print a wrong character as negative value on x86 due to chars
being signed by default. Force an unsigned interpretation which
is also more reasonable because we'd have never indexed the
base64 table with -112

    -XXXXXXXXXX.XXXXXX      XXXXXXXXXXX     131.243.99.154  3288 193.159.183.138 80      base64_illegal_encoding character -112 ignored by Base64 decoding       F       zeek    -
    +XXXXXXXXXX.XXXXXX      XXXXXXXXXXX     131.243.99.154  3288 193.159.183.138 80      base64_illegal_encoding character 144 ignored by Base64 decoding        F       zeek    -

Fixes more of #2742
2023-02-02 15:49:22 +01:00
Arne Welzel
c998cf697a netbios_decode: use unsigned char for result
The buf[i] < 3 condition in use previously allowed all chars (signed on x86)
through that had the 0x80 high-bit set after reconstructing from the two
bytes of the netbios name, resulting in escaped non-ascii content in
the logs.

Fixes more of #2742
2023-02-02 15:48:58 +01:00
Christian Kreibich
542a1d8f4e Bump cluster testsuite to pull in fix for test baseline race condition 2023-02-01 16:38:19 -08:00
Christian Kreibich
f8dbf70e3b Tighten the scripts.base.frameworks.logging.hooks test
This avoids interference from other log streams in the policy hook test cases,
which could cause deviations in output vs baselines depending on build
configuration.
2023-02-01 15:12:20 -08:00
Christian Kreibich
b5c8421ac2 Fix two btest-diff checks that couldn't fail
:-)
2023-02-01 15:12:20 -08:00
Tim Wojtulewicz
0fd335f7f0 Merge remote-tracking branch 'security/topic/timw/131-smb-fscontrol-overflow'
* security/topic/timw/131-smb-fscontrol-overflow:
  Restore/rename field in SMB2::Fscontrol record type
2023-02-01 10:48:16 -07:00
Tim Wojtulewicz
f33c697d6c Merge remote-tracking branch 'security/topic/awelzel/127-http-timeout-again'
* security/topic/awelzel/127-http-timeout-again:
  testing/http: http-11-request-then-cruft
  testing/http: Add pcap extracted from m5-long external test-suite
  testing/external: m57-long baseline update
  analyzers/http: Update request_version on subsequent SetVersion() calls
2023-02-01 10:47:54 -07:00
Tim Wojtulewicz
9a0dc30e35 Merge remote-tracking branch 'security/topic/awelzel/125-ftp-timeout-three'
* security/topic/awelzel/125-ftp-timeout-three:
  testing/ftp: Add tests and pcaps with invalid reply lines
  ftp: Harden reply handing a bit and don't raise bad replies to script-land
  ftp: ignore invalid commands
2023-02-01 10:47:32 -07:00
Robin Sommer
04a1ead978
Provide infrastructure to migrate legacy analyzers to Spicy.
As initial examples, this branch ports the Syslog and Finger analyzers
over. We leave the old analyzers in place for now and activate them
iff we compile without any Spicy.

Needs `zeek-spicy-infra` branches in `spicy/`, `spicy-plugin/`,
`CMake/`, and `zeek/zeek-testing-private`.

Note that the analyzer events remain associated with the Spicy plugin
for now: that's where they will show up with `-NN`, and also inside
the Zeekygen documentation.

We switch CMake over to linking the runtime library into the plugin,
vs. at the top-level through object libraries.
2023-02-01 11:33:48 +01:00
Arne Welzel
87d6efafb0 Merge branch 'topic/awelzel/mysql-start-tls'
* topic/awelzel/mysql-start-tls:
  mysql: Recognize when client/server negotiate SSL
2023-01-31 14:49:56 +01:00
Arne Welzel
be44c642e1 Merge remote-tracking branch 'origin/topic/awelzel/move-disabling-analyzer-out-of-global'
* origin/topic/awelzel/move-disabling-analyzer-out-of-global:
  analyzer: Move disabling_analyzer() hook into Analyzer module
2023-01-31 14:48:56 +01:00
Arne Welzel
023daf4ba8 Merge remote-tracking branch 'origin/topic/awelzel/topic/awelzel/argument-mismatch-with-error'
* origin/topic/awelzel/topic/awelzel/argument-mismatch-with-error:
  Skip somer error reporting when the record type has errors
2023-01-31 14:47:19 +01:00
Arne Welzel
f35cf228dc broker/store: Extend SQLiteOptions around data safety and performance
Add configurability of synchronous and journal_mode for SQLite backed
Broker data stores. Setting these to synchronous=normal and journal_mode=wal
can significantly improve throughput at the cost of some durability in
the presence of power loss or OS crash. In the context of Zeek, this is
likely more than acceptable.

Additionally, add integrity_check and failure_mode options to support deleting
and re-opening a corrupted SQLite database at store creation.

Closes #2698
2023-01-30 10:25:37 +01:00
Tim Wojtulewicz
48a7a6a0fb Update smb1-OSS-fuzz-54883.pcap to have correct snaplen 2023-01-28 08:19:05 -07:00
Tim Wojtulewicz
84ac362c67 Restore/rename field in SMB2::Fscontrol record type
b41a4bf06d removed a field from this record
because it had a duplicate name as another field. The field does need to
exist, but it needs the correct name.
2023-01-27 17:39:10 -07:00
Arne Welzel
adf56ef4d8 Skip somer error reporting when the record type has errors
The added test cases around function/event invocations report the
following flurry of errors when only the first one is relevant and
actionable. There's little use in reporting a mismatch with "error".
Squelch them.

    error in <...>/function-invoke-mismatch-error.zeek, line 8: identifier not defined: MyEnumTypo
    error in <...>/function-invoke-mismatch-error.zeek, line 12 and error: type mismatch (M::MY_ENUM_A and error)
    error in <...>/function-invoke-mismatch-error.zeek, line 12: argument type mismatch in function call (M::to_string(M::MY_ENUM_A))
    error in <...>/function-invoke-mismatch-error.zeek, line 16 and error: type mismatch (M::MY_ENUM_B and error)
    error in <...>/function-invoke-mismatch-error.zeek, line 16: argument type mismatch in function call (M::to_string(M::MY_ENUM_B))
    error in <...>/function-invoke-mismatch-error.zeek, line 20 and error: type mismatch (M::e and error)
    error in <...>/function-invoke-mismatch-error.zeek, line 20: argument type mismatch in function call (M::to_string(M::e))

Record coercion also reports noisy errors when coercing to a type that
has errors for individual fields, type clashing with "error":

    $ zeek language/record-field-error.zeek
    error in ./language/record-coerce-error.zeek, line 8: identifier not defined: MyEnumTypo
    error in ./language/record-coerce-error.zeek, line 19 and ./language/record-coerce-error.zeek, line 5: type clash for field "e" ((coerce [$e=MY_ENUM_B, $s=test] to MyRecord) and MyEnum)
2023-01-27 20:49:22 +01:00
Arne Welzel
8be8c22b3e smb1: Prevent accessing uninitialized referenced_tree
The added pcap was created from an OSS Fuzz test case and is borderline
valid SMB traffic, but it triggered a scripting error.

Closes #2726
2023-01-27 19:22:13 +01:00
Arne Welzel
fa48c88533 mysql: Recognize when client/server negotiate SSL
This instantiates the SSL analyzer when the client requests SSL
so that Zeek now has a bit more visibility into encrypted MySQL
connections.

The pattern used is the same as in the IMAP, POP or XMPP analyzer.
2023-01-27 12:42:19 +01:00
Arne Welzel
03dc21a861 testing/mysql: Add traces recorded with a free-tier MySQL instance
Not sure this adds much more coverage then there was, but minimally
more recent software versions.

The instances/passwords were ephemeral, so hostname and password hashes
etc aren't useful to anyone.
2023-01-27 10:59:23 +01:00
Arne Welzel
672602dae7 MySQL: Fix endianness, introduce mysql_eof() event
We were parsing MySQL using bigendian even though the protocol is
specified as with "least significant byte first" [1]. This is most
problematic when parsing length encoded strings with 2 byte length
fields...

Further, I think, the EOF_Packet parsing was borked, either due to
testing the CLIENT_DEPRECATE_EOF with the wrong endianness, or due to
the workaround in Resultset processing raising mysql_ok(). Introduce a
new mysql_eof() that triggers for EOF_Packet's and remove the fake
mysql_ok() Resultset invocation to fix. Adapt the mysql script and tests
to account for the new event.

This is a quite backwards incompatible change on the event level, but
due to being quite buggy in general, doubt this matters to many.

I think there is more buried, but this fixes the violation of the simple
"SHOW ENGINE INNODB STATUS" and the existing tests continue to
succeed...

[1] https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_dt_integers.html
2023-01-27 10:59:23 +01:00
Arne Welzel
25ee288a76 Tame error reporting and abort() for undefined types
The script added as a test case reports the following messages *and*
dumps a core file. Printing the first error and a normal failure exit
seems sufficient. IMO triggering an abort() due to user scripting issues
is not something that Zeek should do

    $ zeek ./identifier-not-defined-error.zeek
    error in ./identifier-not-defined-error.zeek, line 10: identifier not defined: MyEnu
    error in ./identifier-not-defined-error.zeek, line 10 and error: &default value has inconsistent type (M::MY_ENUM_A and error)
    internal error in ./identifier-not-defined-error.zeek, line 11: type inconsistency in ZVal constructor
    Aborted (core dumped)

Change is to skip certain checks when an error type is propagated.
2023-01-26 20:05:02 +01:00
Arne Welzel
c4302ec280 testing/http: http-11-request-then-cruft
A client sends a "proper" HTTP/1.1 request and afterwards a few T /\n\n sequences.
The latter ones aren't logged.
2023-01-26 19:59:39 +01:00
Arne Welzel
0b26866ecf testing/http: Add pcap extracted from m5-long external test-suite
This tests that the HTTP version is now updated if it changes in the
course of a connection.
2023-01-26 19:59:39 +01:00
Arne Welzel
dab551aaa3 testing/external: m57-long baseline update
There's a HTTP server that first replies with HTTP/1.1, then HTTP/1.0.
Seems actually nicer to have the real value within the log/event.
2023-01-26 19:59:28 +01:00
Arne Welzel
942f829825 testing/ftp: Add tests and pcaps with invalid reply lines
These have been created artificially. The tests show that for an
invalid reply line without a numeric code, with a numeric code < 100
or a numeric code not followed by a space we now raise an analyzer
violation and disable the analyzer.
2023-01-26 19:56:20 +01:00
Tim Wojtulewicz
f842a86e80 Update external testing repo commit hashes for Teredo changes 2023-01-26 09:23:22 -07:00
Tim Wojtulewicz
6ebfa02199 Update scripts.base.frameworks.analyzer.logging btest to use a different trace file 2023-01-26 09:14:00 -07:00
Tim Wojtulewicz
3d5918e6b3 Update btest baselines due to reduced calls to UID::Set
UID::Set is called by AnalyzerViolation, and since Teredo isn't calling nearly
as many of those anymore the UIDs used by other calls changed as well.
2023-01-26 09:14:00 -07:00
Tim Wojtulewicz
5e68880470 GH-2669: Give script location for type clash in for-loop construction 2023-01-26 09:11:10 -07:00
Tim Wojtulewicz
e61c3a95ad GH-2684: Stop violating VXLAN for forwarding failures 2023-01-25 10:50:07 -07:00
Tim Wojtulewicz
89675fc7de Add test for new handling of unknown RDP keyboards 2023-01-23 13:01:48 -07:00
Arne Welzel
26b1558cd1 analyzer: Move disabling_analyzer() hook into Analyzer module
When disabling_analyzer() was introduced, it was added to the GLOBAL
module. The awkward side-effect is that implementing a hook handler
in another module requires to prefix it with GLOBAL. Alternatively, one
can re-open the GLOBAL module and implement the handler in that scope.

Both are not great, and prefixing with GLOBAL is ugly, so move the
identifier to the Analyzer module and ask users to prefix with Analyzer.
2023-01-23 12:22:05 +01:00
Tim Wojtulewicz
d6ce5894a7 Fix diff-remove-abspath to ignore Windows drive letters 2023-01-19 09:13:33 -07:00
Tim Wojtulewicz
7623e9f290 Use pathsep btest value in btest.cfg 2023-01-19 09:13:33 -07:00
Tim Wojtulewicz
b3498da983 Use build_dir btest value in btest.cfg 2023-01-19 09:13:33 -07:00
Arne Welzel
b4cb5e753a Merge branch 'topic/awelzel/fix-zam-memory-leak'
* topic/awelzel/fix-zam-memory-leak:
  testing/btest: Add ZAM basic test
  Fix ZAM memory leak as reported in #2634
2023-01-18 17:14:56 +01:00
Arne Welzel
eb09662d48 bifs/parse_eftp: Prevent reporter warnings/errors on invalid input
When passing invalid IPs or an out-of range port to parse_eftp()
a warning or error was generated on stderr (in addition to setting
the $valid field to F). Prevent the output by adding safe-guarding
and using IPAddr::ConvertString() instead.
2023-01-16 15:20:02 +01:00
Arne Welzel
d4a84e7442 Merge remote-tracking branch 'origin/topic/vern/dup-rec-fields2'
* origin/topic/vern/dup-rec-fields2:
  fix for crashes when record definitions repeat a field name

Removed dead if !init code during merge.
2023-01-12 09:42:50 +01:00
Vern Paxson
a172617250 fix for crashes when record definitions repeat a field name 2023-01-10 13:56:47 -08:00
Arne Welzel
2d852209b0 Merge remote-tracking branch 'origin/topic/awelzel/analyzer-log'
* origin/topic/awelzel/analyzer-log:
  btest/net-control: Use different expiration times for rules
  analyzer: Add analyzer.log for logging violations/confirmations
2023-01-10 10:22:58 +01:00
Arne Welzel
a004bdf5d9 Merge remote-tracking branch 'origin/topic/awelzel/2647-intel-seen-file-names'
* origin/topic/awelzel/2647-intel-seen-file-names:
  intel/seen/file-names: Use file_over_new_connection()
2023-01-10 10:12:04 +01:00
Arne Welzel
ebf1a199c2 Merge branch 'topic/awelzel/analyzer-requested-analyzers'
* topic/awelzel/analyzer-requested-analyzers:
  scripts/analyzer: Introduce Analyzer::requested_analyzers
2023-01-10 10:11:37 +01:00
Arne Welzel
6d19c49efe intel/seen/file-names: Use file_over_new_connection()
The seen/file-names script relies on f$info$filename to be populated.
For HTTP and other network protocols, however, this field is only
populated during file_over_new_connection() that's running after
file_new().

Use the file_new() event only for files without connections and
file_over_new_connection() implies that f$conns is populated, anyway.

Special case SMB to avoid finding files twice, because there's a
custom implementation in seen/smb-filenames.zeek.

Fixes #2647
2023-01-10 10:10:28 +01:00
Arne Welzel
56833fcfd9 btest/net-control: Use different expiration times for rules
There's some non-determinism here: Force the expiration of the
shunt_flow rules first.
2023-01-09 18:11:55 +01:00
Arne Welzel
17d0ade26a analyzer: Add analyzer.log for logging violations/confirmations
By default this only logs all the violations, regardless of the
confirmation state (for which there's still dpd.log). It includes
packet, protocol and file analyzers.

This uses options, change handlers and event groups for toggling
the functionality at runtime.

Closes #2031
2023-01-09 18:11:49 +01:00
Arne Welzel
51376191f7 testing/btest: Add ZAM basic test
While there's a btest environment for ZAM, it's currently not run by
default. Add a single zam/basic.test so that we catch memory leaks or
dead-on-arrival cases with the current CI setup.
2023-01-09 12:30:26 +01:00
Arne Welzel
21cc5f9132 EventRegistry/Func: Disable events when all bodies are disabled
This is just a small optimization on top of what is there.

Add state to Func for tracking if any enabled bodies exist which
allows us to propagate it up to the EventHandler::bool() operator.
In turn, when all bodies of an event's Func have been runtime disabled,
the event itself will not be invoked anymore.

Experiments have shown that this allows runtime toggling of new_event()
without performance impact when disabled. This could enable use-cases
where new_packet() handlers are enabled for a split second once in a
while to either dump or sample raw packet data at runtime.
2023-01-05 12:03:58 +01:00