Commit graph

16194 commits

Author SHA1 Message Date
Christian Kreibich
c2e791287e Fix MMDB::Lookup() to check result status correctly
This function confused checking the return value of MMDB_lookup_sockaddr() with
testing the value of the returned result.found_entry bit when that call
succeeds. Both need to happen.
2024-01-25 23:54:22 -08:00
Christian Kreibich
1044f4db0d Add btest for succeeding/failing IPv4/IPv6 lookups
The existing tests happen to test only succeeding IP addresses.
2024-01-25 23:54:20 -08:00
Christian Kreibich
975a6ae981 Add an IPv6 range to the test MMDB DBs 2024-01-25 23:43:34 -08:00
zeek-bot
4d6ec9a533 Update doc submodule [nomail] [skip ci] 2024-01-26 00:23:47 +00:00
Arne Welzel
b586b59b69 Merge remote-tracking branch 'origin/topic/vern/zam-rec-constr-opt2'
* origin/topic/vern/zam-rec-constr-opt2:
  ZAM optimizations for record creation
2024-01-25 20:55:16 +01:00
Vern Paxson
91cab9931d ZAM optimizations for record creation
includes reworking of managing "auxiliary" information for ZAM instructions
2024-01-25 20:49:12 +01:00
Arne Welzel
9f94360cfc testing/external: Revert commit hash for zeek-testing 2024-01-25 12:38:47 +01:00
Arne Welzel
e318b82032 Merge remote-tracking branch 'origin/topic/awelzel/intel-seen-hook'
* origin/topic/awelzel/intel-seen-hook:
  Intel: Introduce Intel::seen_policy() hook
2024-01-25 12:27:34 +01:00
Arne Welzel
62e0dc94db Intel: Introduce Intel::seen_policy() hook
This introduces a new hook into the Intel::seen() function that allows
users to directly interact with the result of a find() call via external
scripts.

This should solve the use-case brought up by @chrisanag1985 in
discussion #3256: Recording and acting on "no intel match found".

@Canon88 was recently asking on Slack about enabling HTTP logging for a
given connection only when an Intel match occurred and found that the
Intel::match() event would only occur on the manager. The
Intel::match_remote() event might be a workaround, but possibly running a
bit too late and also it's just an internal "detail" event that might not
be stable.

Another internal use case revolved around enabling packet recording
based on Intel matches which necessarily needs to happen on the worker
where the match happened. The proposed workaround is similar to the above
using Intel::match_remote().

This hook also provides an opportunity to rate-limit heavy hitter intel
items locally on the worker nodes, or even replacing the event approach
currently used with a customized approach.
2024-01-25 12:22:47 +01:00
Arne Welzel
ba510f018c Merge remote-tracking branch 'origin/topic/awelzel/websocket-continuation-opcode-fix'
* origin/topic/awelzel/websocket-continuation-opcode-fix:
  websocket: Fix opcode for continuation frames
2024-01-25 12:21:37 +01:00
zeek-bot
e3717f5476 Update doc submodule [nomail] [skip ci] 2024-01-25 00:12:17 +00:00
Christian Kreibich
46eba4811e Merge branch 'topic/neverlord/broker-variant-prep'
* topic/neverlord/broker-variant-prep:
  Prepare Broker manager for broker::variant
2024-01-24 15:25:27 -08:00
Dominik Charousset
4e3acfe8fc Prepare Broker manager for broker::variant
- With `broker::data`, we always have actual `std::string` objects that
  we can pass to C functions expecting a null-terminated string.
  However, `broker::variant` will return a `std::string_view` where we
  have previously received a `std::string`. Hence, we add an extra level
  of indirection that ensures that views are converted to
  null-terminated strings and also use `c_str()` where we have
  previously used `data()`. The former is not present on a
  `std::string_view`. Using this member function instead acts as an
  extra level of insurance that we do not accidentally pass the bytes
  from a view to a C function.
- Switch from error and status views to actual error and status objects.
  The view types from Broker only work with `broker::data` and thus
  won't be available with `broker::variant`.
2024-01-24 15:13:56 -08:00
Arne Welzel
a16179eae7 Merge remote-tracking branch 'origin/topic/awelzel/sed-E-everywhere'
* origin/topic/awelzel/sed-E-everywhere:
  testing/scripts: Use sed -E everywhere
2024-01-24 23:05:01 +01:00
Arne Welzel
77ef7f4ad9 Merge remote-tracking branch 'origin/topic/awelzel/bdat-websocket-fixlets'
* origin/topic/awelzel/bdat-websocket-fixlets:
  HTTP: Coverity std::move suggestion
  WebSocket: Coverity std::move suggestion
  SMTP/BDAT: Fix SonarQube reported issues
2024-01-24 23:04:27 +01:00
Arne Welzel
fb7799bdf6 websocket: Fix opcode for continuation frames
A continuation frame has the same type as the first frame, but that
information wasn't used nor kept, resulting payload of continuation
frames not being forwarded. The pcap was created with a fake Python
server and a bit of message crafting.
2024-01-24 22:57:24 +01:00
Arne Welzel
73458927ba testing/scripts: Use sed -E everywhere
I'm always a bit worried to use sed -E anywhere, because the canonifiers
give the impression it won't work everywhere consistently. My manpage says
sed -E should be preferred for portability, so lets remove the
sed -r / sed -E differentiation assuming it's just a thing from the past.
2024-01-24 11:19:17 +01:00
Arne Welzel
11e0322f0f HTTP: Coverity std::move suggestion 2024-01-24 10:50:42 +01:00
Arne Welzel
96376fe487 WebSocket: Coverity std::move suggestion 2024-01-24 10:50:42 +01:00
Arne Welzel
b5b30eb58d SMTP/BDAT: Fix SonarQube reported issues 2024-01-24 10:50:04 +01:00
zeek-bot
45000e2ec8 Update doc submodule [nomail] [skip ci] 2024-01-24 00:12:51 +00:00
Arne Welzel
cbaf838f4d Merge remote-tracking branch 'origin/topic/awelzel/smtp-bdat-follow-up-3'
* origin/topic/awelzel/smtp-bdat-follow-up-3:
  btest/smtp/bdat: Move tests into proper directory
  BDAT: Harden parse_bdat_arg()
  SMTP: Reset ContentLineAnalyzer plain delivery on EndData()
  SMTP: Add SMTP_IN_BDAT state
2024-01-23 21:53:37 +01:00
Arne Welzel
7373549de4 btest/smtp/bdat: Move tests into proper directory 2024-01-23 21:49:50 +01:00
Arne Welzel
ce4647a507 BDAT: Harden parse_bdat_arg()
There implementation assumed that arg is null terminated. Due to
the ContentLineAnalyzer wrongly being in plain delivery mode, this
assumption was violated. It shouldn't happen anymore, but protect
from this anyhow.
2024-01-23 21:49:50 +01:00
Arne Welzel
bc357c6ca1 SMTP: Reset ContentLineAnalyzer plain delivery on EndData()
When resetting the BDAT state, we also need to switch the ContentLine
analyzer back into line mode, otherwise we're feeding plain delivery
data through ProcessLine(), possibly violating some assumptions about
null termination.

Do it for both ContentLineAnalyzers - only one of them will be in plain
delivery mode anyhow, but we don't keep state which one it was.
2024-01-23 21:49:50 +01:00
Arne Welzel
9a510b8035 SMTP: Add SMTP_IN_BDAT state
Initially this reused SMTP_IN_DATA, but separating into SMTP_IN_BDAT
to avoid spurious EndData() calls upon a server's reply. The client
should usually continue to send the full in-flight chunk still.
2024-01-23 21:46:30 +01:00
Tim Wojtulewicz
fbb1a57945 Merge remote-tracking branch 'origin/topic/timw/iptunnel-check-null-session'
* origin/topic/timw/iptunnel-check-null-session:
  Remove setting non-existent session history for IPTunnel
2024-01-23 12:41:01 -07:00
Tim Wojtulewicz
8977f49665 Remove setting non-existent session history for IPTunnel 2024-01-23 12:39:58 -07:00
Tim Wojtulewicz
a3af4a4b51 Merge branch 'topic/timw/more-string-view-usage'
* topic/timw/more-string-view-usage:
  Change to use ToStdStringView() in a few other BIFs
  Convert remove_prefix/suffix BIFs to use std::string_view
  Rework starts_with BIF similarly to ends_with changes in 1649e3e7cc
2024-01-23 10:41:37 -07:00
Tim Wojtulewicz
012acb17cc Change to use ToStdStringView() in a few other BIFs 2024-01-23 10:38:56 -07:00
Tim Wojtulewicz
c77f8cc898 Convert remove_prefix/suffix BIFs to use std::string_view 2024-01-23 10:38:56 -07:00
Tim Wojtulewicz
94ad676db0 Rework starts_with BIF similarly to ends_with changes in 1649e3e7cc 2024-01-23 10:38:56 -07:00
Arne Welzel
822ca99e80 Merge remote-tracking branch 'origin/topic/awelzel/3424-http-upgrade-websocket-v1'
* origin/topic/awelzel/3424-http-upgrade-websocket-v1:
  websocket: Handle breaking from WebSocket::configure_analyzer()
  websocket: Address review feedback for BinPac code
  fuzzers: Add WebSocket fuzzer
  websocket: Fix crash for fragmented messages
  websocket: Verify Sec-WebSocket-Key/Accept headers and review feedback
  btest/websocket: Test for coalesced reply-ping
  HTTP/CONNECT: Also weird on extra data in reply
  HTTP/Upgrade: Weird when more data is available
  ContentLine: Add GetDeliverStreamRemainingLength() accessor
  HTTP: Drain event queue after instantiating upgrade analyzer
  btest/http: Explain switching-protocols test change as comment
  WebSocket: Introduce new analyzer and log
  HTTP: Add mechanism to instantiate Upgrade analyzer
2024-01-23 18:17:50 +01:00
zeek-bot
dddb8052d2 Update doc submodule [nomail] [skip ci] 2024-01-23 00:20:55 +00:00
Arne Welzel
9654226075 websocket: Handle breaking from WebSocket::configure_analyzer()
...and various nits from the review.
2024-01-22 18:54:41 +01:00
Arne Welzel
015a7c5fbc websocket: Address review feedback for BinPac code
* Rename mask_ to masking_key_
* Fold FrameHeaderFixed into FrameHeader directly
* Drop WebSocket_FramePayloadUnmask type

Thanks a bunch @ckreibich!
2024-01-22 18:54:41 +01:00
Arne Welzel
1775b01b58 fuzzers: Add WebSocket fuzzer
It immediately found an issue with &transient, but fairly stable thereafter.

This is a separate fuzzer implementation as there's a custom Configure()
call for the analyzer as well as disabling all other analyzers so we
don't fuzz unrelated protocols.
2024-01-22 18:54:38 +01:00
Arne Welzel
5eb380d74a websocket: Fix crash for fragmented messages
The &transient attribute does not work well with $element as that won't
be available within &until anymore apparently.

Found after a few seconds building out the fuzzer.
2024-01-22 18:54:38 +01:00
Arne Welzel
e17655be61 websocket: Verify Sec-WebSocket-Key/Accept headers and review feedback
Don't log them, they are random and arbitrary in the normal case. Users
can do the following to log them if wanted.

    redef += WebSocket::Info$client_key += { &log };
    redef += WebSocket::Info$server_accept += { &log };
2024-01-22 18:54:38 +01:00
Arne Welzel
a6c1d12206 btest/websocket: Test for coalesced reply-ping
Add a constructed PCAP where the HTTP/websocket server send a WebSocket
ping message directly with the packet of the HTTP reply. Ensure this is
interpreted the same as if the WebSocket message is in a separate packet
following the HTTP reply.

For the server side this should work, for the client side we'd need to
synchronize suspend parsing the client side as we currently cannot quite
know whether it's a pipelined HTTP request following, or upgraded protocol
data and we don't have "suspend parsing" functionality here.
2024-01-22 18:54:38 +01:00
Arne Welzel
4d81389df0 HTTP/CONNECT: Also weird on extra data in reply 2024-01-22 18:54:38 +01:00
Arne Welzel
de836ab528 HTTP/Upgrade: Weird when more data is available
After an HTTP upgrade to another protocol, create a weird if the packet
that contains the HTTP reply *also* contains some additional data
belonging to the upgraded to protocol already.
2024-01-22 18:54:38 +01:00
Arne Welzel
2b9776adca ContentLine: Add GetDeliverStreamRemainingLength() accessor
Helper to get information from the ContentLine analyzer about
bytes still pending to be delivered. In certain cases this can
be a signal for weirdness.
2024-01-22 18:54:38 +01:00
Arne Welzel
7967ef993b HTTP: Drain event queue after instantiating upgrade analyzer
With configurability through script-land comes the draw back
that we actually need to execute event handlers in the middle
of the parsing process: This might not be the best model, but
the script-side configurability it enables is kind of nice.

This explicit call only matters here when the HTTP reply is
directly followed by some WebSocket message data within the
same network packet, otherwise the queue is drained once the
packet has been completely processed anyhow.
2024-01-22 18:54:38 +01:00
Arne Welzel
37521f58e5 btest/http: Explain switching-protocols test change as comment
DPD enables HTTP based on the content of the WebSocket frames. However,
it's not HTTP, the protocol is x-kaazing-handshake and the server sends
some form of status/acknowledge to the client first, so the HTTP and the
HTTP analyzer receives that as the first bytes of the response and
bails, oh well.
2024-01-22 18:54:38 +01:00
Arne Welzel
efc2681152 WebSocket: Introduce new analyzer and log
This adds a new WebSocket analyzer that is enabled with the HTTP upgrade
mechanism introduced previously. It is a first implementation in BinPac with
manual chunking of frame payload. Configuration of the analyzer is sketched
via the new websocket_handshake() event and a configuration BiF called
WebSocket::__configure_analyzer(). In short, script land collects WebSocket
related HTTP headers and can forward these to the analyzer to change its
parsing behavior at websocket_handshake() time. For now, however, there's
no actual logic that would change behavior based on agreed upon extensions
exchanged via HTTP headers (e.g. frame compression). WebSocket::Configure()
simply attaches a PIA_TCP analyzer to the WebSocket analyzer for dynamic
protocol detection (or a custom analyzer if set). The added pcaps show this
in action for tunneled ssh, http and https using wstunnel. One test pcap is
Broker's WebSocket traffic from our own test suite, the other is the
Jupyter websocket traffic from the ticket/discussion.

This commit further adds a basic websocket.log that aggregates the WebSocket
specific headers (Sec-WebSocket-*) headers into a single log.

Closes #3424
2024-01-22 18:54:38 +01:00
Arne Welzel
8ebd054abc HTTP: Add mechanism to instantiate Upgrade analyzer
When a HTTP upgrade request/reply is detected, lookup an analyzer tag
from HTTP::upgrade_analyzers, or if nothing is found, attach PIA_TCP.
2024-01-22 18:54:38 +01:00
Tim Wojtulewicz
b5f9e5a3b1 Merge remote-tracking branch 'origin/topic/timw/remove-bifreturnval'
* origin/topic/timw/remove-bifreturnval:
  Make BIFs just return ValPtr directly instead of BifReturnVal
2024-01-22 10:36:30 -07:00
Tim Wojtulewicz
2aaaab4dad Make BIFs just return ValPtr directly instead of BifReturnVal 2024-01-22 10:35:34 -07:00
Tim Wojtulewicz
5602546f2e Merge remote-tracking branch 'origin/topic/timw/stop-supporting-bro-topics'
* origin/topic/timw/stop-supporting-bro-topics:
  Drop support for subscribing to bro/ topics
2024-01-22 10:01:23 -07:00