diff --git a/.cirrus.yml b/.cirrus.yml index 446116bb5b..d4a99824b1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -14,6 +14,7 @@ config: &CONFIG --build-type=release --disable-broker-tests --prefix=$CIRRUS_WOR no_spicy_config: &NO_SPICY_CONFIG --build-type=release --disable-broker-tests --disable-spicy --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror static_config: &STATIC_CONFIG --build-type=release --disable-broker-tests --enable-static-broker --enable-static-binpac --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror binary_config: &BINARY_CONFIG --prefix=$CIRRUS_WORKING_DIR/install --libdir=$CIRRUS_WORKING_DIR/install/lib --binary-package --enable-static-broker --enable-static-binpac --disable-broker-tests --build-type=Release --ccache --enable-werror +spicy_ssl_config: &SPICY_SSL_CONFIG --build-type=release --disable-broker-tests --enable-spicy-ssl --prefix=$CIRRUS_WORKING_DIR/install --ccache --enable-werror asan_sanitizer_config: &ASAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=address --enable-fuzzers --enable-coverage --ccache --enable-werror ubsan_sanitizer_config: &UBSAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=undefined --enable-fuzzers --ccache --enable-werror tsan_sanitizer_config: &TSAN_SANITIZER_CONFIG --build-type=debug --disable-broker-tests --sanitizers=thread --enable-fuzzers --ccache --enable-werror @@ -286,6 +287,7 @@ ubuntu22_task: $CIRRUS_BRANCH =~ 'release/.*' || $CIRRUS_CRON == 'benchmark-nightly' ) +# Also enable Spicy SSL for this ubuntu22_spicy_task: container: # Ubuntu 22.04 EOL: April 2027 @@ -294,7 +296,7 @@ ubuntu22_spicy_task: << : *CI_TEMPLATE env: ZEEK_CI_CREATE_ARTIFACT: 1 - test_script: true # Don't run tests, these are redundant. + ZEEK_CI_CONFIGURE_FLAGS: *SPICY_SSL_CONFIG spicy_install_analyzers_script: ./ci/spicy-install-analyzers.sh upload_binary_artifacts: path: build.tgz diff --git a/CHANGES b/CHANGES index d66cd9d44d..c3ba7a5a8d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,18 @@ +7.1.0-dev.305 | 2024-09-11 16:55:55 +0200 + + * Spicy SSL analyzer: + + This commit adds an alternative Spicy-based SSL analyzer. It supports + nearly the entire functionality of the current binpac analyzer, with + the exception of DTLS and decryption. + + This currently is mostly for internal tests, or for Spicy testing purposes. + There is no functional advantage to use the Spicy based analyzer - it does + not have any additional features. + + It is currently gated behind a configure-time flag that needs to be provided + to enable it (--enable-spicy-ssl). + 7.1.0-dev.259 | 2024-09-09 13:24:45 +0200 * script_opt/ZAM/IterInfo.h: Add missing Dict.h dependency (Arne Welzel, Corelight) diff --git a/VERSION b/VERSION index 2abe9bc7dc..15a1f8311f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -7.1.0-dev.259 +7.1.0-dev.305 diff --git a/cmake_templates/zeek-config.h.in b/cmake_templates/zeek-config.h.in index 67ab0a5b8e..9130ecc66e 100644 --- a/cmake_templates/zeek-config.h.in +++ b/cmake_templates/zeek-config.h.in @@ -244,6 +244,9 @@ /* Enable/disable ZAM profiling capability */ #cmakedefine ENABLE_ZAM_PROFILE +/* Enable/disable the Spicy SSL analyzer */ +#cmakedefine ENABLE_SPICY_SSL + /* String with host architecture (e.g., "linux-x86_64") */ #define HOST_ARCHITECTURE "@HOST_ARCHITECTURE@" diff --git a/configure b/configure index b365b7dd2a..c38acf5980 100755 --- a/configure +++ b/configure @@ -69,6 +69,7 @@ Usage: $0 [OPTION]... [VAR=VALUE]... --enable-static-broker build Broker statically (ignored if --with-broker is specified) --enable-werror build with -Werror --enable-ZAM-profiling build with ZAM profiling enabled (--enable-debug implies this) + --enable-spicy-ssl build with spicy SSL/TLS analyzer (conflicts with --disable-spicy) --disable-af-packet don't include native AF_PACKET support (Linux only) --disable-auxtools don't build or install auxiliary tools --disable-broker-tests don't try to build Broker unit tests @@ -310,6 +311,9 @@ while [ $# -ne 0 ]; do --enable-ZAM-profiling) append_cache_entry ENABLE_ZAM_PROFILE BOOL true ;; + --enable-spicy-ssl) + append_cache_entry ENABLE_SPICY_SSL BOOL true + ;; --disable-af-packet) append_cache_entry DISABLE_AF_PACKET BOOL true ;; diff --git a/src/analyzer/protocol/rdp/RDP.cc b/src/analyzer/protocol/rdp/RDP.cc index 7ad998567c..f11bf88377 100644 --- a/src/analyzer/protocol/rdp/RDP.cc +++ b/src/analyzer/protocol/rdp/RDP.cc @@ -1,6 +1,7 @@ #include "zeek/analyzer/protocol/rdp/RDP.h" #include "zeek/Reporter.h" +#include "zeek/analyzer/Manager.h" #include "zeek/analyzer/protocol/rdp/events.bif.h" #include "zeek/analyzer/protocol/rdp/types.bif.h" #include "zeek/analyzer/protocol/tcp/TCP_Reassembler.h" @@ -11,7 +12,7 @@ RDP_Analyzer::RDP_Analyzer(Connection* c) : analyzer::tcp::TCP_ApplicationAnalyz interp = new binpac::RDP::RDP_Conn(this); had_gap = false; - ssl = nullptr; + tls_active = false; } RDP_Analyzer::~RDP_Analyzer() { delete interp; } @@ -44,12 +45,13 @@ void RDP_Analyzer::DeliverStream(int len, const u_char* data, bool orig) { // 0x01 is SSL/TLS // 0x03-0x04 is CredSSP which is effectively SSL/TLS if ( interp->encryption_method() > 0x00 ) { - if ( ! ssl ) { - ssl = new analyzer::ssl::SSL_Analyzer(Conn()); + if ( ! tls_active ) { + tls_active = true; + Analyzer* ssl = analyzer_mgr->InstantiateAnalyzer("SSL", Conn()); if ( ! AddChildAnalyzer(ssl) ) { reporter->AnalyzerError(this, "failed to add TCP child analyzer " - "to RDP analyzer: already exists"); + "to RDP analyzer"); return; } } diff --git a/src/analyzer/protocol/rdp/RDP.h b/src/analyzer/protocol/rdp/RDP.h index 306f8a0e5b..c09b4d521d 100644 --- a/src/analyzer/protocol/rdp/RDP.h +++ b/src/analyzer/protocol/rdp/RDP.h @@ -1,9 +1,7 @@ #pragma once -#include "zeek/analyzer/protocol/pia/PIA.h" #include "zeek/analyzer/protocol/rdp/events.bif.h" #include "zeek/analyzer/protocol/rdp/rdp_pac.h" -#include "zeek/analyzer/protocol/ssl/SSL.h" #include "zeek/analyzer/protocol/tcp/TCP.h" namespace zeek::analyzer::rdp { @@ -25,7 +23,7 @@ protected: binpac::RDP::RDP_Conn* interp; bool had_gap; - analyzer::ssl::SSL_Analyzer* ssl; + bool tls_active; }; } // namespace zeek::analyzer::rdp diff --git a/src/analyzer/protocol/ssl/CMakeLists.txt b/src/analyzer/protocol/ssl/CMakeLists.txt index 5c686b16cf..9783784569 100644 --- a/src/analyzer/protocol/ssl/CMakeLists.txt +++ b/src/analyzer/protocol/ssl/CMakeLists.txt @@ -1,34 +1,39 @@ -zeek_add_plugin( - Zeek - SSL - SOURCES - SSL.cc - DTLS.cc - Plugin.cc - BIFS - types.bif - events.bif - functions.bif - consts.bif - PAC - tls-handshake.pac - tls-handshake-protocol.pac - tls-handshake-analyzer.pac - ssl-defs.pac - proc-certificate.pac - tls-handshake-signed_certificate_timestamp.pac - PAC - ssl.pac - ssl-dtls-analyzer.pac - ssl-analyzer.pac - ssl-dtls-protocol.pac - ssl-protocol.pac - ssl-defs.pac - proc-certificate.pac - PAC - dtls.pac - ssl-dtls-analyzer.pac - dtls-analyzer.pac - ssl-dtls-protocol.pac - dtls-protocol.pac - ssl-defs.pac) +if (NOT ENABLE_SPICY_SSL) + zeek_add_plugin( + Zeek + SSL + SOURCES + SSL.cc + DTLS.cc + Plugin.cc + BIFS + types.bif + events.bif + functions.bif + consts.bif + PAC + tls-handshake.pac + tls-handshake-protocol.pac + tls-handshake-analyzer.pac + ssl-defs.pac + proc-certificate.pac + tls-handshake-signed_certificate_timestamp.pac + PAC + ssl.pac + ssl-dtls-analyzer.pac + ssl-analyzer.pac + ssl-dtls-protocol.pac + ssl-protocol.pac + ssl-defs.pac + proc-certificate.pac + PAC + dtls.pac + ssl-dtls-analyzer.pac + dtls-analyzer.pac + ssl-dtls-protocol.pac + dtls-protocol.pac + ssl-defs.pac) +else () + add_subdirectory(spicy) + zeek_add_plugin(Zeek SSL SOURCES Plugin.cc BIFS functions.bif) +endif () diff --git a/src/analyzer/protocol/ssl/Plugin.cc b/src/analyzer/protocol/ssl/Plugin.cc index d91302cbc3..a807089e3c 100644 --- a/src/analyzer/protocol/ssl/Plugin.cc +++ b/src/analyzer/protocol/ssl/Plugin.cc @@ -2,17 +2,23 @@ #include "zeek/plugin/Plugin.h" +#include "zeek/zeek-config.h" + +#ifndef ENABLE_SPICY_SSL #include "zeek/analyzer/Component.h" #include "zeek/analyzer/protocol/ssl/DTLS.h" #include "zeek/analyzer/protocol/ssl/SSL.h" +#endif namespace zeek::plugin::detail::Zeek_SSL { class Plugin : public zeek::plugin::Plugin { public: zeek::plugin::Configuration Configure() override { +#ifndef ENABLE_SPICY_SSL AddComponent(new zeek::analyzer::Component("SSL", zeek::analyzer::ssl::SSL_Analyzer::Instantiate)); AddComponent(new zeek::analyzer::Component("DTLS", zeek::analyzer::dtls::DTLS_Analyzer::Instantiate)); +#endif zeek::plugin::Configuration config; config.name = "Zeek::SSL"; diff --git a/src/analyzer/protocol/ssl/functions.bif b/src/analyzer/protocol/ssl/functions.bif index 2e91190b73..d520cab6d1 100644 --- a/src/analyzer/protocol/ssl/functions.bif +++ b/src/analyzer/protocol/ssl/functions.bif @@ -1,8 +1,12 @@ %%{ #include -#include "zeek/analyzer/protocol/ssl/SSL.h" #include "zeek/Reporter.h" +#include "zeek/zeek-config.h" + +#ifndef ENABLE_SPICY_SSL +#include "zeek/analyzer/protocol/ssl/SSL.h" +#endif %%} ## Sets if the SSL analyzer should consider the connection established (handshake @@ -13,6 +17,8 @@ ## Returns: T on success, F on failure. function set_ssl_established%(c: connection%): bool %{ +#ifndef ENABLE_SPICY_SSL +/* not implemented for Spicy ssl */ zeek::analyzer::Analyzer* sa = c->FindAnalyzer("SSL"); if ( sa ) @@ -20,6 +26,7 @@ function set_ssl_established%(c: connection%): bool static_cast(sa)->StartEncryption(); return zeek::val_mgr->True(); } +#endif return zeek::val_mgr->False(); %} @@ -34,6 +41,8 @@ function set_ssl_established%(c: connection%): bool ## Returns: T on success, F on failure. function set_secret%(c: connection, secret: string%): bool %{ +#ifndef ENABLE_SPICY_SSL +/* not implemented for Spicy ssl */ analyzer::Analyzer* sa = c->FindAnalyzer("SSL"); if ( sa ) @@ -41,6 +50,7 @@ function set_secret%(c: connection, secret: string%): bool static_cast(sa)->SetSecret(*secret); return zeek::val_mgr->True(); } +#endif return zeek::val_mgr->False(); %} @@ -55,6 +65,8 @@ function set_secret%(c: connection, secret: string%): bool ## Returns: T on success, F on failure. function set_keys%(c: connection, keys: string%): bool %{ +#ifndef ENABLE_SPICY_SSL +/* not implemented for Spicy ssl */ analyzer::Analyzer* sa = c->FindAnalyzer("SSL"); if ( sa ) @@ -62,6 +74,7 @@ function set_keys%(c: connection, keys: string%): bool static_cast(sa)->SetKeys(*keys); return zeek::val_mgr->True(); } +#endif return zeek::val_mgr->False(); %} diff --git a/src/analyzer/protocol/ssl/spicy/CMakeLists.txt b/src/analyzer/protocol/ssl/spicy/CMakeLists.txt new file mode 100644 index 0000000000..c607dc64a4 --- /dev/null +++ b/src/analyzer/protocol/ssl/spicy/CMakeLists.txt @@ -0,0 +1 @@ +spicy_add_analyzer(NAME SSL SOURCES SSL.spicy SSL.evt support.cc) diff --git a/src/analyzer/protocol/ssl/spicy/SSL.evt b/src/analyzer/protocol/ssl/spicy/SSL.evt new file mode 100644 index 0000000000..7ea75c0748 --- /dev/null +++ b/src/analyzer/protocol/ssl/spicy/SSL.evt @@ -0,0 +1,89 @@ +# Copyright (c) 2024 by the Zeek Project. See LICENSE for details. + +protocol analyzer SSL over TCP: + parse with SSL::Message; + +protocol analyzer DTLS over UDP: + parse with SSL::DTLSMessage; + +import SSL; +import zeek; +import spicy; + +on SSL::ClientHello -> event ssl_client_hello($conn, self.client_version, msg.record_version, cast