// A flow changed its service
#define FLOW_SERVICE_CHANGE_EVENT "flow.service_change_event"
+// A flow has found the service inspector
+#define SERVICE_INSPECTOR_CHANGE_EVENT "flow.service_inspector.changed"
// A flow has entered the setup state
#define FLOW_STATE_SETUP_EVENT "flow.state_setup"
#include <iomanip>
#include <sstream>
+#include "detection/detection_engine.h"
#include "flow/flow.h"
#include "flow/flow_key.h"
#include "framework/data_bus.h"
if ( flow->ssn_state.snort_protocol_id == UNKNOWN_PROTOCOL_ID )
flow->ssn_state.snort_protocol_id = gadget->get_service();
+
+ DataBus::publish(SERVICE_INSPECTOR_CHANGE_EVENT, DetectionEngine::get_current_packet());
}
else if ( wizard )
{
flow->set_gadget(ins);
flow->ssn_state.snort_protocol_id = ins->get_service();
+ DataBus::publish(SERVICE_INSPECTOR_CHANGE_EVENT, DetectionEngine::get_current_packet());
}
else
flow->ssn_state.snort_protocol_id = UNKNOWN_PROTOCOL_ID;
hello = (const SSL_handshake_hello_t*)handshake;
retval |= SSL_decode_version_v3(hello->major, hello->minor);
- /* Compare version of record with version of handshake */
- if ((cur_flags & SSL_VERFLAGS) != (retval & SSL_VERFLAGS))
- retval |= SSL_BAD_VER_FLAG;
-
break;
case SSL_HS_SHELLO:
expect_events.h
finalize_packet_event.h
http_events.h
+ opportunistic_tls_event.h
sip_events.h
)
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+// opportunistic_tls_event.h author Steven Baigal <sbaigal@cisco.com>
+
+#ifndef OPPORTUNISTIC_TLS_EVENT_H
+#define OPPORTUNISTIC_TLS_EVENT_H
+
+#include "framework/data_bus.h"
+
+// An opportunistic SSL/TLS session will start from next packet
+#define OPPORTUNISTIC_TLS_EVENT "service_inspector.opportunistic.tls"
+
+namespace snort
+{
+
+class SO_PUBLIC OpportunisticTlsEvent : public snort::DataEvent
+{
+public:
+ OpportunisticTlsEvent(const snort::Packet* p, const char* service) :
+ pkt(p), next_service(service) { }
+
+ const snort::Packet* get_packet() override
+ { return pkt; }
+
+ const char* get_next_service()
+ { return next_service; }
+
+private:
+ const snort::Packet* pkt;
+ const char* next_service = nullptr;
+};
+
+}
+
+#endif
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/ssl.h"
+#include "pub_sub/opportunistic_tls_event.h"
#include "stream/stream.h"
#include "utils/safec.h"
#include "utils/util.h"
/* This is either an initial server response or a STARTTLS response */
if (smtp_ssn->state == STATE_CONNECT)
smtp_ssn->state = STATE_COMMAND;
+
+ if (smtp_ssn->state == STATE_TLS_CLIENT_PEND)
+ {
+ OpportunisticTlsEvent event(p, p->flow->service);
+ DataBus::publish(OPPORTUNISTIC_TLS_EVENT, event, p->flow);
+ }
+
break;
case RESP_250:
#include "profiler/profiler.h"
#include "protocols/packet.h"
#include "protocols/ssl.h"
+#include "pub_sub/finalize_packet_event.h"
+#include "pub_sub/opportunistic_tls_event.h"
#include "stream/stream.h"
#include "stream/stream_splitter.h"
//-------------------------------------------------------------------------
// class stuff
//-------------------------------------------------------------------------
+static const char* s_name = "ssl";
class Ssl : public Inspector
{
void show(const SnortConfig*) const override;
void eval(Packet*) override;
+ bool configure(SnortConfig*) override;
StreamSplitter* get_splitter(bool c2s) override
{ return new SslSplitter(c2s); }
SSL_PROTO_CONF* config;
};
+class SslStartTlsEventtHandler : public DataHandler
+{
+public:
+ SslStartTlsEventtHandler() : DataHandler(s_name) { }
+
+ void handle(DataEvent&, Flow* flow) override
+ {
+ flow->flags.trigger_finalize_event = true;
+ }
+};
+
+class SslFinalizePacketHandler : public DataHandler
+{
+public:
+ SslFinalizePacketHandler() : DataHandler(s_name) {}
+
+ void handle(DataEvent& e, Flow*) override
+ {
+ FinalizePacketEvent* fp_event = (FinalizePacketEvent*)&e;
+ const Packet* pkt = fp_event->get_packet();
+
+ pkt->flow->flags.trigger_finalize_event = false;
+ pkt->flow->set_proxied();
+ pkt->flow->set_service(const_cast<Packet*>(pkt), s_name);
+ }
+};
+
Ssl::Ssl(SSL_PROTO_CONF* pc)
{
config = pc;
snort_ssl(config, p);
}
+bool Ssl::configure(SnortConfig*)
+{
+ DataBus::subscribe(FINALIZE_PACKET_EVENT, new SslFinalizePacketHandler());
+ DataBus::subscribe(OPPORTUNISTIC_TLS_EVENT, new SslStartTlsEventtHandler());
+ return true;
+}
+
//-------------------------------------------------------------------------
// api stuff
//-------------------------------------------------------------------------
IT_SERVICE,
PROTO_BIT__PDU,
nullptr, // buffers
- "ssl",
+ s_name,
ssl_init,
nullptr, // pterm
nullptr, // tinit