Commit graph

1441 commits

Author SHA1 Message Date
Tim Wojtulewicz
84e3f414a7 Use the same rules as cmake submodule to reformat Zeek 2023-05-09 08:31:43 -07:00
Arne Welzel
2c8b97c522 NTP: Detect out-of-order packets
The NTP mode provides us with the identity of the endpoints. For the
simple CLIENT / SERVER modes, flip the connection if we detect
orig/resp disagreeing with what the message says. This mainly
results in the history getting a ^ and the ntp.log / conn.log
showing the corrected endpoints.

Closes #2998.
2023-05-04 19:44:02 +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
1b69b4d26f Merge branch 'topic/amazingpp/irc-fuid-missing' of github.com:AmazingPP/zeek
* 'topic/amazingpp/irc-fuid-missing' of github.com:AmazingPP/zeek:
  Add irc_dcc_send_ack event and fix missing fields

I've moved IRC_Data back into the zeek::analyzer::file namespace, but
we did move the declaration from protocol/file/File.h to protocol/irc/IRC.h.
But, if someone actually customized IRC_Data and didn't include protocol/irc/IRC.h
for other reasons, I'll be surprised (and also just suggest to update the include).
2023-04-24 18:22:50 +02:00
Fupeng Zhao
161ffb4192 Add irc_dcc_send_ack event and fix missing fields 2023-04-24 07:29:51 +00:00
Dominik Charousset
9aeed5284d Redesign subdir-libs and plugin scaffolding 2023-04-13 22:23:46 +02:00
Tim Wojtulewicz
d8c1a1babf Merge remote-tracking branch 'security/topic/awelzel/155-reassem-validate-seq-upper-overflow'
* security/topic/awelzel/155-reassem-validate-seq-upper-overflow:
  file_analysis/File: Report overflowing chunks as weird and discard/truncate
  Reassem: Reject blocks overflowing 64bit upper
  zeek-setup: Load scrips before running unit tests
2023-04-11 15:30:58 -07:00
Tim Wojtulewicz
f812ce53cf Merge remote-tracking branch 'security/topic/timw/154-rdp-timeout'
* security/topic/timw/154-rdp-timeout:
  RDP: Instantiate SSL analyzer instead of PIA
  RDP: add some enforcement to required values based on MS-RDPBCGR docs
2023-04-11 15:23:52 -07:00
Arne Welzel
ea80f21e1d Reassem: Reject blocks overflowing 64bit upper
The reassembler logic isn't wrap around safe, so just truncate or
reject such blocks. For files specifically, a byte offset in the
2**64 bytes represents 16EiB which is the maximum size supported
by BTRFS or NTFS (and probably nothing we'd ever see in practice).
2023-04-03 16:45:03 +02:00
Vern Paxson
9560e38784 fixed type mismatch for ssl_certificate_request event 2023-04-01 12:56:54 -07:00
Tim Wojtulewicz
943b8b0b42 RDP: Instantiate SSL analyzer instead of PIA 2023-03-24 11:05:33 -07:00
Tim Wojtulewicz
a9d3245e80 RDP: add some enforcement to required values based on MS-RDPBCGR docs 2023-03-24 10:33:21 -07:00
Johanna Amann
dcbc809189 Merge remote-tracking branch 'origin/topic/johanna/certificate-req'
* origin/topic/johanna/certificate-req:
  SSL/TLS CertificateRequest message: Address review feedback
  SSL/TLS: Parse CertificateRequest message
2023-03-15 10:03:25 +01:00
Johanna Amann
b8d658ac77 SSL/TLS CertificateRequest message: Address review feedback
Minor stylistic changes; see https://github.com/zeek/zeek/pull/2855 for
details
2023-03-15 09:19:26 +01:00
Michael R. Torres
fe8390c646 Parse DNSSEC AD and CD bits
Parse authentic data (AD) and checking disabled (CD) bits according to
RFC 2535. Leaves the Z field as-is, in case users are already handling
this elsewhere and depend on the value being the integer for all 3 bits.

https://www.rfc-editor.org/rfc/rfc2535#section-6.1

Fixes #2672
2023-03-13 14:35:06 -07:00
Arne Welzel
c29b98b224 Merge remote-tracking branch 'origin/topic/awelzel/http-content-range-parsing-robustness'
* origin/topic/awelzel/http-content-range-parsing-robustness:
  HTTP: Make Content-Range parsing more robust
2023-03-13 18:41:16 +01:00
Arne Welzel
b21e6f72da HTTP: Make Content-Range parsing more robust
This was exposed by OSS-Fuzz after the HTTP/0.9 changes in zeek/zeek#2851:
We do not check the result of parsing the from and last bytes of a
Content-Range header and would reference uninitialized values on the stack
if these were not valid.

This doesn't seem as bad as it sounds outside of yielding non-sensible values:
If the result was negative, we weird/bailed. If the result was positive, we
already had to treat it with suspicion anyway and the SetPlainDelivery()
logic accounts for that.
2023-03-13 18:00:39 +01:00
Arne Welzel
fbf9d53c44 HTTP: Reset reply_message for HTTP/0.9
OSS-Fuzz tickled an assert when sending a HTTP response before a HTTP/0.9
request. Avoid this by resetting reply_message upon seeing a HTTP/0.9 request.

PCAP was generated artificially: Server sending a reply providing a
Content-Length. Because HTTP/0.9 processing would remove the ContentLine
support analyzer, more data was delivered to the HTTP_Message than
expected, triggering an assert.

This is a follow-up for zeek/zeek#2851.
2023-03-13 14:13:50 +01:00
Tim Wojtulewicz
9cb6de7447 Add weird for unknown HTTP/0.9 request method 2023-03-10 15:45:11 -07:00
Tim Wojtulewicz
0003495a9b Special case HTTP 0.9 early on
Mostly, treat HTTP0.9 completely separate. Because we're doing raw
delivery of a body directly, fake enough (connection_close=1, and finish
headers manually) so that the MIME infrastructure thinks it is seeing a
body.

This deals better with the body due to accounting for the first line. Also
it avoids the content line analyzer to strip CRLF/LF and the analyzer
then adding CRLF unconditionally by fully bypassing the content line
analyzer.

Concretely, the vlan-mpls test case contains a HTTP response with LF only,
but the previous implementation would use CRLF, accounting for two many bytes.
Same for the http.no-version test which would previously report a body
length of 280 and now is at 323 (which agrees with wireshark).

Further, the mime_type detection for the http-09 test case works because
it's now seeing the full body.

Drawback: We don't extract headers when a server actually replies with
a HTTP/1.1 message, but grrr, something needs to give I guess.
2023-03-10 09:52:34 -07:00
Tim Wojtulewicz
220d8a2795 Remove a couple unnecessary break statements 2023-03-10 09:52:34 -07:00
Johanna Amann
b56b856da9 SSL/TLS: Parse CertificateRequest message
This commit introduces parsing of the CertificateRequest message in the
TLS handshake. It introduces a new event ssl_certificate_request, as
well as a new function parse_distinguished_name, which can be used to
parse part of the ssl_certificate_request event parameters.

This commit also introduces a new policy script, which appends
information about the CAs a TLS server requests in the
CertificateRequest message, if it sends it.
2023-03-09 09:12:29 +01:00
Tim Wojtulewicz
f92ca9e537 SMB: clarify a confusing line in one of the pac files 2023-02-22 16:39:54 -07:00
Tim Wojtulewicz
184baf118d NTLM analyzer: Don't bother checking boolean values for > 0 2023-02-22 16:39:54 -07:00
Tim Wojtulewicz
d239f355fd FTP analyzer: Remove unnecessary lines from constructor 2023-02-22 16:39:54 -07: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
Arne Welzel
71bcd15d2e analyzer/http: Do not assume char is signed
On aarch64, char is unsigned, so is_HTTP_token_char() allowed
non-ASCII stuff with the high-bit set.

Fixes part of #2742
2023-02-02 14:57:57 +01: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
Tim Wojtulewicz
4cdd68f019 Fix some member-variable shadowing issues 2023-01-27 13:03:19 -07:00
Tim Wojtulewicz
5bfd84a903 Fix/simplify some if statement comparisons 2023-01-27 13:03:19 -07:00
Tim Wojtulewicz
3b0e8ee6f1 Fix a bunch of missing class member initializations 2023-01-27 13:03:18 -07:00
Tim Wojtulewicz
7374688d0d Remove unnecessary virtual specifiers from final classes 2023-01-27 13:03:18 -07: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
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
3af6b97c63 analyzers/http: Update request_version on subsequent SetVersion() calls
The #124 PR introduced special treatment when HTTP version 0.9
was set. With #127, a reproducer that set HTTP/1.0 in the first
request was created and subsequent requests wouldn't reset to
HTTP version 0.9.

This is subtle, but doesn't seem like things fall apart.

Improves runtime from 20 seconds to 2 seconds for the given
reproducer.

Fixes #127.
2023-01-26 19:59:02 +01:00
Arne Welzel
cf375cf362 ftp: Harden reply handing a bit and don't raise bad replies to script-land
This improves runtime of the oss-fuzz generated traffic in #125.
Specifically, that reproducers included a 064- reply code that was
interpreted as needing to be continued.

Also, return after AnalyzerViolations() for server replies rather than
propagating bad replies them to script-land. This trusts server's to
generally behave according to specification.
2023-01-26 19:56:20 +01:00
Arne Welzel
8f96ac3b77 ftp: ignore invalid commands
Do not propagate wrong FTP commands to script land.
2023-01-26 19:56:20 +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
7bbdce61e8 Merge remote-tracking branch 'origin/topic/awelzel/2547-fix-supress-weird-spelling'
* origin/topic/awelzel/2547-fix-supress-weird-spelling:
  ContentLine: Fix spelling of "suppress", deprecate SupressWeirds()
2022-12-06 12:18:36 +01:00
Arne Welzel
d9b7da334d Merge branch 'topic/fox-ds/ssh-key-init-events' of github.com:fox-ds/zeek
* 'topic/fox-ds/ssh-key-init-events' of github.com:fox-ds/zeek:
  Added several events for detailed info on the SSH2 key init directions

* Straightened out the zeek:see lines in events.bif to be the same across all events.
2022-12-06 10:04:53 +01:00
Joost Jansen
bcdbca4bb9 Added several events for detailed info on the SSH2 key init directions 2022-12-05 12:35:05 +01:00
nadavkluger
433b535e10 Expose PA_ENC_TIMESTAMP to script land 2022-12-02 15:43:19 +02:00
Arne Welzel
76ba9d4698 ContentLine: Fix spelling of "suppress", deprecate SupressWeirds()
Closes #2547
2022-12-02 12:40:47 +01:00
Tim Wojtulewicz
9e8833e2d5 Merge remote-tracking branch 'security/topic/awelzel/121-ftp-timeout-again'
* security/topic/awelzel/121-ftp-timeout-again:
  ftp: Introduce FTP::max_command_length
2022-11-22 12:27:37 -07:00
Tim Wojtulewicz
eb3fb68fcc Merge remote-tracking branch 'security/topic/awelzel/119-http-timeout-tspacerr'
* security/topic/awelzel/119-http-timeout-tspacerr:
  http: Heuristic around rejecting malformed HTTP/0.9 traffic
2022-11-22 12:27:10 -07:00
Tim Wojtulewicz
26030f4a57 Merge remote-tracking branch 'nadav/topic/nadavk/ntlm'
* nadav/topic/nadavk/ntlm:
  Added NTLM challenge and response
2022-11-21 09:09:18 -07:00
Arne Welzel
3f5cb75a2a ftp: Introduce FTP::max_command_length
oss-fuzz produced FTP traffic with a ~550KB long FTP command. Cap FTP command
length at 100 bytes, log a weird if a command is larger than that and move
on to the next. Likely it's not actual FTP traffic, but raising an
analyzer violation would allow clients an easy way to disable the analyzer
by sending an overly long command.

The added test PCAP was generated using a fake Python socket server/client.
2022-11-21 09:36:29 +01:00