]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #3005 in SNORT/snort3 from ~SVLASIUK/snort3:wizard_options_move...
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 4 Aug 2021 16:49:03 +0000 (16:49 +0000)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Wed, 4 Aug 2021 16:49:03 +0000 (16:49 +0000)
Squashed commit of the following:

commit 4781785cec1ec20013758611cea6628db253d5c2
Author: russ <rucombs@cisco.com>
Date:   Thu May 6 09:54:51 2021 -0400

    wizard: add wizard max_pattern option and update HTTP/SIP aware methods patterns

commit a80b39187048cbab9bdcb70d59273aff773c7bff
Author: russ <rucombs@cisco.com>
Date:   Thu May 6 12:59:33 2021 -0400

    smtp: remove unused defines

commit 2bc14ed5ebee6aa818b60959432e0f22fb7651e3
Author: russ <rucombs@cisco.com>
Date:   Thu May 6 13:00:16 2021 -0400

    telnet: correct help for ayt_attack_thresh

commit c695c3092b7ef955e81de6090c6d6683e1946195
Author: russ <rucombs@cisco.com>
Date:   Thu May 6 13:00:57 2021 -0400

    ftp: remove unused defines and crufty comments

lua/snort_defaults.lua
src/service_inspectors/ftp_telnet/ftpp_si.cc
src/service_inspectors/ftp_telnet/ftpp_ui_config.h
src/service_inspectors/ftp_telnet/telnet_module.cc
src/service_inspectors/smtp/smtp.h
src/service_inspectors/wizard/hexes.cc
src/service_inspectors/wizard/magic.h
src/service_inspectors/wizard/spells.cc
src/service_inspectors/wizard/wiz_module.cc
src/service_inspectors/wizard/wiz_module.h
src/service_inspectors/wizard/wizard.cc

index c851594662faad026cfc7b1ac0744d555faf2216..36381eb1b48636792ed949c4f3c985917cdde252 100644 (file)
@@ -340,14 +340,15 @@ http_methods =  -- build from default_http_methods
     'UPDATEREDIRECTREF', 'PROPFIND', 'PROPPATCH', 'MKCOL', 'COPY',
     'MOVE', 'LOCK', 'UNLOCK', 'SEARCH', 'BCOPY', 'BDELETE', 'BMOVE',
     'BPROPFIND', 'BPROPPATCH', 'POLL', 'UNSUBSCRIBE', 'X_MS_ENUMATTS',
-    --'NOTIFY', 'OPTIONS', 'SUBSCRIBE', 'UPDATE'
+    'OPTIONS * HTTP/',
+    --'NOTIFY', 'SUBSCRIBE', 'UPDATE'
 }
 
-sip_methods =
+sip_requests =
 {
-    'INVITE', 'CANCEL', 'ACK', 'BYE', 'REGISTER', 'REFER', 'SUBSCRIBE',
-    'UPDATE', 'JOIN', 'INFO', 'MESSAGE', 'NOTIFY', 'PRACK'
-    --'OPTIONS',
+    'INVITE * SIP/', 'CANCEL * SIP/', 'ACK * SIP/', 'BYE * SIP/', 'REGISTER * SIP/',
+    'REFER * SIP/', 'SUBSCRIBE * SIP/', 'UPDATE * SIP/', 'INFO * SIP/', 'MESSAGE * SIP/',
+    'NOTIFY * SIP/', 'PRACK * SIP/', 'OPTIONS * SIP/'
 }
 
 telnet_commands =
@@ -381,7 +382,7 @@ default_wizard =
           to_client = { '+OK', '-ERR' } },
 
         { service = 'sip', client_first = true,
-          to_server = sip_methods, to_client = { 'SIP/' } },
+          to_server = sip_requests, to_client = { 'SIP/' } },
 
         { service = 'smtp', proto = 'tcp', client_first = true,
           to_server = { 'HELO', 'EHLO' },
@@ -1191,7 +1192,7 @@ default_low_port_scan =
 default_whitelist =
 [[
     ftp_command_specs default_ftp_server smtp_default_alt_max_command_lines
-    default_smtp http_methods sip_methods telnet_commands default_wizard
+    default_smtp http_methods sip_requests telnet_commands default_wizard
     default_references default_classifications gtp_v0_msg gtp_v1_msg gtp_v2_msg
     gtp_v0_info gtp_v1_info gtp_v2_info default_gtp tcp_low_ports
     tcp_low_decoy tcp_low_sweep tcp_low_dist tcp_med_ports
index d7fd395eabba492d32d200f6b027c6103fde846a..35bb88f8c7f6908c57ece8245dfa790b1d2f8221 100644 (file)
  * This file contains functions to select server configurations
  * and begin the FTPTelnet process.
  *
- * The session Inspection Module interfaces with the Stream Inspection
- * Module and the User Interface Module to select the appropriate
- * FTPTelnet configuration and in the case of stateful inspection the
- * session Inspection Module retrieves the user-data from the Stream
- * Module.  For stateless inspection, the session Inspection Module uses
- * the same structure for use by each packet.
- *
  * The main responsibility of this module is to supply the appropriate
  * data structures and configurations for the rest of the FTPTelnet
  * process.  The module also determines what type of data is being
@@ -135,14 +128,10 @@ static int TelnetStatefulsessionInspection(Packet* p,
  *          configuration for the session, and the type of inspection
  *          to be performed (client or server.)
  *
- *          When the session Inspection module is in stateful mode, it
- *          checks to see if there is a TELNET_SESSION pointer already
+ *          Checks to see if there is a TELNET_SESSION pointer already
  *          associated with the stream.  If there is, then it uses that
  *          session pointer, otherwise it calculates the server configuration
- *          using the FTP_SI_INPUT and returns a TELNET_SESSION pointer.  In
- *          stateful mode, this means that memory is allocated, but in
- *          stateless mode, the same session pointer is used for all packets
- *          to reduce the allocation overhead.
+ *          using the FTP_SI_INPUT and returns a TELNET_SESSION pointer.
  *
  *          The inspection mode can be either client or server.
  *
@@ -486,14 +475,11 @@ static int FTPStatefulsessionInspection(
  *          configuration for the session, and the type of inspection to
  *          be performed (client or server.)
  *
- *          When the session Inspection module is in stateful mode, it
- *          checks to see if there is a FTP_SESSION pointer already
+ *          Checks to see if there is a FTP_SESSION pointer already
  *          associated with the stream.  If there is, then it uses that
  *          session pointer, otherwise it calculates the server
  *          configuration using the FTP_SI_INPUT and returns a FTP_SESSION
- *          pointer.  In stateful mode, this means that memory is allocated,
- *          but in stateless mode, the same session pointer is used for all
- *          packets to reduce the allocation overhead.
+ *          pointer.
  *
  *          The inspection mode can be either client or server.
  */
index 217e8abd667a3a3c814eb41fb9c7774a78b7cf08..de505943b549c0a1ffdea3c02ca4ae0e8262d099 100644 (file)
@@ -44,8 +44,6 @@
 /*
  * Defines
  */
-#define FTPP_UI_CONFIG_STATELESS 0
-#define FTPP_UI_CONFIG_STATEFUL  1
 
 #define FTPP_UI_CONFIG_TELNET_DEF_AYT_THRESHOLD (-1)
 #define FTPP_UI_CONFIG_FTP_DEF_RESP_MSG_MAX (-1)
index dec8e6b4bf8bee234177390d386f2df3a743e682..4d130760b7865e207ca6b5474f788a6fc080daf1 100644 (file)
@@ -45,7 +45,7 @@ using namespace std;
 static const Parameter s_params[] =
 {
     { "ayt_attack_thresh", Parameter::PT_INT, "-1:max31", "-1",
-      "alert on this number of consecutive Telnet AYT commands" },
+      "alert beyond this number of consecutive Telnet AYT commands (-1 is disabled)" },
 
     { "check_encrypted", Parameter::PT_BOOL, nullptr, "false",
       "check for end of encryption" },
index 74e5ef995912b90fbd04f652a5e2233dc1aff43b..c032f34d9da517c8204e25ffb897177c1b420922 100644 (file)
 #define SMTP_PKT_FROM_CLIENT   1
 #define SMTP_PKT_FROM_SERVER   2
 
-// Inspection type
-#define SMTP_STATELESS  0
-#define SMTP_STATEFUL   1
-
 #define SEARCH_CMD       0
 #define SEARCH_RESP      1
 #define SEARCH_HDR       2
index 63845556dfc6bd4df6410d02f98876a2863ef055..a8344827813c4a6eb93b019ced07dc000141dd9b 100644 (file)
@@ -164,8 +164,11 @@ const MagicPage* HexBook::find_spell(
 }
 
 const char* HexBook::find_spell(
-    const uint8_t* data, unsigned len, const MagicPage*& p) const
+    const uint8_t* data, unsigned len, unsigned max, const MagicPage*& p) const
 {
+    if ( max and len > max )
+        len = max;
+
     p = find_spell(data, len, p, 0);
 
     if ( p and !p->value.empty() )
index 3c46c344f48b8587912b280bcc0d518509452953..8b7db0cc8c42e0984d343d6ef09e8da0eafd6e4d 100644 (file)
@@ -52,7 +52,8 @@ public:
     MagicBook& operator=(const MagicBook&) = delete;
 
     virtual bool add_spell(const char* key, const char*& val) = 0;
-    virtual const char* find_spell(const uint8_t*, unsigned len, const MagicPage*&) const = 0;
+    virtual const char* find_spell(const uint8_t*, unsigned len, unsigned max,
+        const MagicPage*&) const = 0;
 
     const MagicPage* page1()
     { return root; }
@@ -73,7 +74,8 @@ public:
     SpellBook();
 
     bool add_spell(const char*, const char*&) override;
-    const char* find_spell(const uint8_t*, unsigned len, const MagicPage*&) const override;
+    const char* find_spell(const uint8_t*, unsigned len, unsigned max,
+        const MagicPage*&) const override;
 
 private:
     bool translate(const char*, HexVector&);
@@ -92,7 +94,8 @@ public:
     HexBook() = default;
 
     bool add_spell(const char*, const char*&) override;
-    const char* find_spell(const uint8_t*, unsigned len, const MagicPage*&) const override;
+    const char* find_spell(const uint8_t*, unsigned len, unsigned,
+        const MagicPage*&) const override;
 
 private:
     bool translate(const char*, HexVector&);
index f0f6d531efee0baf0bb4bd3dc4c1d47e28259a65..51719f79ff133c34d6e76afc02b9433eab8a5f35 100644 (file)
@@ -163,13 +163,11 @@ const MagicPage* SpellBook::find_spell(
 }
 
 const char* SpellBook::find_spell(
-    const uint8_t* data, unsigned len, const MagicPage*& p) const
+    const uint8_t* data, unsigned len, unsigned max, const MagicPage*& p) const
 {
-    // FIXIT-L make configurable upper bound to limit globbing
-    unsigned max = 64;
     assert(p);
 
-    if ( len > max )
+    if ( max and len > max )
         len = max;
 
     p = find_spell(data, len, p, 0);
index 4b79175a188680cee2437fb49ced0d76008e6143..5e9cff76962e94f105967fddb63c323c38991cbf 100644 (file)
@@ -106,17 +106,13 @@ static const Parameter s_params[] =
     { "curses", Parameter::PT_MULTI, "dce_smb | dce_udp | dce_tcp | sslv2", nullptr,
       "enable service identification based on internal algorithm" },
 
+    { "max_pattern", Parameter::PT_INT, "0:65535", "64",
+      "maximum scan depth per segment (0 is unlimited)" },
+
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-WizardModule::WizardModule() : Module(WIZ_NAME, WIZ_HELP, s_params)
-{
-    c2s_hexes = nullptr;
-    s2c_hexes = nullptr;
-    c2s_spells = nullptr;
-    s2c_spells = nullptr;
-    curses = nullptr;
-}
+WizardModule::WizardModule() : Module(WIZ_NAME, WIZ_HELP, s_params) { }
 
 WizardModule::~WizardModule()
 {
@@ -163,6 +159,9 @@ bool WizardModule::set(const char*, Value& v, SnortConfig*)
     else if ( v.is("curses") )
         curses->add_curse(v.get_string());
 
+    else if ( v.is("max_pattern") )
+        max_pattern = v.get_uint16();
+
     return true;
 }
 
index fd085e20936a6d1e59f699e5e9c194e2a0f2e6bf..5d3dc4d0df921751647299885b58810b0991d589 100644 (file)
@@ -58,6 +58,9 @@ public:
     MagicBook* get_book(bool c2s, bool hex);
     CurseBook* get_curse_book();
 
+    uint16_t get_max_pattern()
+    { return max_pattern; }
+
     Usage get_usage() const override
     { return INSPECT; }
 
@@ -73,13 +76,14 @@ private:
     std::vector<std::string> s2c_patterns;
     bool c2s;
 
-    MagicBook* c2s_hexes;
-    MagicBook* s2c_hexes;
+    MagicBook* c2s_hexes = nullptr;
+    MagicBook* s2c_hexes = nullptr;
 
-    MagicBook* c2s_spells;
-    MagicBook* s2c_spells;
+    MagicBook* c2s_spells = nullptr;
+    MagicBook* s2c_spells = nullptr;
 
-    CurseBook* curses;
+    CurseBook* curses = nullptr;
+    uint16_t max_pattern = 0;
 };
 
 #endif
index ad1ed202d02537b628d3659648b67df798427482..273af7b50d1ea550867adc5e246bf974b8a449df 100644 (file)
@@ -150,6 +150,7 @@ public:
     MagicBook* s2c_spells;
 
     CurseBook* curses;
+    uint16_t max_pattern;
 };
 
 //-------------------------------------------------------------------------
@@ -215,6 +216,7 @@ Wizard::Wizard(WizardModule* m)
     s2c_spells = m->get_book(false, false);
 
     curses = m->get_curse_book();
+    max_pattern = m->get_max_pattern();
 }
 
 Wizard::~Wizard()
@@ -291,7 +293,7 @@ StreamSplitter* Wizard::get_splitter(bool c2s)
 bool Wizard::spellbind(
     const MagicPage*& m, Flow* f, const uint8_t* data, unsigned len)
 {
-    f->service = m->book.find_spell(data, len, m);
+    f->service = m->book.find_spell(data, len, max_pattern, m);
     return ( f->service != nullptr );
 }