]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1069 in SNORT/snort3 from nss_0 to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 20 Nov 2017 17:10:12 +0000 (12:10 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 20 Nov 2017 17:10:12 +0000 (12:10 -0500)
Squashed commit of the following:

commit 83cd94521652ab6349bcbce59f24e4137ff199eb
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sat Nov 18 08:30:40 2017 -0500

    soid: allow stub to contain any or all options
    --rule-to-*: use whole soid arg as suffix to rule and len identifiers; make static

commit 141d6fb80625a69cd7ab232e7d5a8ef2450b6eeb
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Nov 17 15:46:28 2017 -0500

    snort2lua: future proof --bind-wizard binding order

commit 0cab5c8f91bc553444c52375e18cf1ca6a8a280d
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Nov 17 13:49:34 2017 -0500

    snort: do not dlclose plugins at shutdown during REG_TEST to avoid borked backtraces from LeakSanitizer

commit ee4de247f8944df42539a4ee6bb2bcc210d86de5
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Mon Nov 13 09:00:58 2017 -0500

    snort2lua: no sticky buffer for relative pcre

commit e154eea548013235536b4dd160c915762925bdae
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sun Nov 12 21:37:45 2017 -0500

    memory: no stats output unless configured

commit 17d93dca22c4770d710cf74926da105dee586d23
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sun Nov 12 19:36:08 2017 -0500

    inspection: default policy mode depends on adaptor mode

commit 86c5792850916faa149d3ae2407331801e420df2
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sun Nov 12 08:20:07 2017 -0500

    stream_size: fix snort2lua to_client, to_server conversion and eval packet checks

commit d5cc4f29811b090a673a8fe51c3f165a468c645c
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sat Nov 11 19:37:31 2017 -0500

    snort2lua: urilen:<> --> bufferlen:<=>

commit 03525a245f6ad14da647ba7c8d2266391fb40524
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sat Nov 11 17:27:20 2017 -0500

    dce: use service names from rules (dce_smb = netbios-ssn; dce_tcp / dce_udp = dcerpc)

commit 3f65c4e31799bd288705dfc6c055a15e5c06871b
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Sat Nov 11 17:25:46 2017 -0500

    http_inspect: use configured max_pdu as base target reassembly size

commit 204f4e7b98e1cc10d0aeb8900efab0bacba43ed1
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Nov 10 22:25:26 2017 -0500

    wizard: abort if no match

commit 1e2a90d557d083ac973ae7327223b9b2dfc026eb
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Nov 10 22:24:40 2017 -0500

    stream_user: clear splitter properly

commit 66e7626080c53090f433bc8fd1ab291974623ae6
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Fri Nov 10 15:34:25 2017 -0500

    normalizer: fix enable checks

commit 4febd24b53d2cb4ce4806072618389ad71b75f63
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Nov 9 08:44:20 2017 -0500

    byte_test: fix string bounds check

commit f4c0bddbfb04a56551a3dd911aa8be3d0d23e849
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Nov 9 08:14:56 2017 -0500

    conf: remove OPTIONS from SIP and HTTP spells to avoid confusion with RTSP
    conf: remove client to server spells for FTP, IMAP, POP, and SMTP to avoid false pickups

commit f4cfb26f69b360743e728268c154a085a20e7980
Author: Russ Combs (rucombs) <rucombs@cisco.com>
Date:   Thu Nov 9 08:12:12 2017 -0500

    detection: fix option tree looping issue

39 files changed:
lua/snort.lua
lua/snort_defaults.lua
src/detection/detection_options.cc
src/framework/so_rule.h
src/ips_options/ips_byte_test.cc
src/ips_options/ips_so.cc
src/ips_options/ips_soid.cc
src/main/policy.h
src/main/snort_config.cc
src/managers/plugin_manager.cc
src/managers/so_manager.cc
src/memory/memory_cap.cc
src/memory/memory_module.cc
src/memory/memory_module.h
src/network_inspectors/normalize/norm_module.cc
src/network_inspectors/normalize/normalize.cc
src/network_inspectors/normalize/normalize.h
src/service_inspectors/dce_rpc/dce_http_proxy.cc
src/service_inspectors/dce_rpc/dce_http_server.cc
src/service_inspectors/dce_rpc/dce_smb.cc
src/service_inspectors/dce_rpc/dce_tcp.cc
src/service_inspectors/dce_rpc/dce_udp.cc
src/service_inspectors/http_inspect/http_enum.h
src/service_inspectors/http_inspect/http_msg_section.cc
src/service_inspectors/wizard/curses.cc
src/service_inspectors/wizard/curses.h
src/service_inspectors/wizard/spells.cc
src/service_inspectors/wizard/wizard.cc
src/stream/tcp/ips_stream_size.cc
src/stream/tcp/tcp_module.cc
src/stream/tcp/tcp_session.cc
src/stream/user/user_session.cc
tools/snort2lua/config_states/config_paf_max.cc
tools/snort2lua/helpers/converter.cc
tools/snort2lua/helpers/util_binder.h
tools/snort2lua/preprocessor_states/pps_stream5_tcp.cc
tools/snort2lua/rule_states/rule_pcre.cc
tools/snort2lua/rule_states/rule_stream_size.cc
tools/snort2lua/rule_states/rule_urilen.cc

index b2a00ab3f5020318dafbe265d6c0421911511664..2e245dffd512809bba3490b0cf47ca5212b52ffd 100644 (file)
@@ -133,17 +133,19 @@ wizard = default_wizard
 
 binder =
 {
-    -- these protocols do not yet have wizard support
+    -- port bindings required for protocols without wizard support
     { when = { proto = 'udp', ports = '53' },  use = { type = 'dns' } },
     { when = { proto = 'tcp', ports = '111' }, use = { type = 'rpc_decode' } },
     { when = { proto = 'tcp', ports = '502' }, use = { type = 'modbus' } },
     { when = { proto = 'tcp', ports = '2123 2152 3386' }, use = { type = 'gtp' } },
 
+    { when = { proto = 'tcp', service = 'dcerpc' }, use = { type = 'dce_tcp' } },
+    { when = { proto = 'udp', service = 'dcerpc' }, use = { type = 'dce_udp' } },
+
+    { when = { service = 'netbios-ssn' },      use = { type = 'dce_smb' } },
     { when = { service = 'dce_http_server' },  use = { type = 'dce_http_server' } },
     { when = { service = 'dce_http_proxy' },   use = { type = 'dce_http_proxy' } },
-    { when = { service = 'dce_smb' },          use = { type = 'dce_smb' } },
-    { when = { service = 'dce_udp' },          use = { type = 'dce_udp' } },
-    { when = { service = 'dce_tcp' },          use = { type = 'dce_tcp' } },
+
     { when = { service = 'dnp3' },             use = { type = 'dnp3' } },
     { when = { service = 'dns' },              use = { type = 'dns' } },
     { when = { service = 'ftp' },              use = { type = 'ftp_server' } },
index d3e85b00dd127a03306ec0973bc3a951ab1de59c..3115077e8801b813bbe05481580b396901ee4bc1 100644 (file)
@@ -266,7 +266,7 @@ default_smtp =
 
 http_methods =  -- build from default_http_methods
 {
-    'OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT',
+    'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT',
     'VERSION_CONTROL', 'REPORT', 'CHECKOUT', 'CHECKIN', 'UNCHECKOUT',
     'MKWORKSPACE', 'UPDATE', 'LABEL', 'MERGE', 'BASELINE_CONTROL',
     'MKACTIVITY', 'ORDERPATCH', 'ACL', 'PATCH', 'BIND', 'LINK',
@@ -275,25 +275,14 @@ http_methods =  -- build from default_http_methods
     'MOVE', 'LOCK', 'UNLOCK', 'SEARCH', 'BCOPY', 'BDELETE', 'BMOVE',
     'BPROPFIND', 'BPROPPATCH', 'NOTIFY', 'POLL', 'SUBSCRIBE',
     'UNSUBSCRIBE', 'X_MS_ENUMATTS',
-}
-
-ftp_commands =  -- build from ftp_default_cmds
-{
-    'ABOR', 'ACCT', 'ADAT', 'ALLO', 'APPE', 'AUTH', 'CCC', 'CDUP', 'CEL',
-    'CLNT', 'CMD', 'CONF', 'CWD', 'DELE', 'ENC', 'EPRT', 'EPSV', 'ESTA',
-    'ESTP', 'FEAT', 'HELP', 'LANG', 'LIST', 'LPRT', 'LPSV', 'MACB', 'MAIL',
-    'MDTM', 'MIC', 'MKD', 'MLSD', 'MLST', 'MODE', 'NLST', 'NOOP', 'OPTS',
-    'PASS', 'PASV', 'PBSZ', 'PORT', 'PROT', 'PWD', 'QUIT', 'REIN', 'REST',
-    'RETR', 'RMD', 'RNFR', 'RNTO', 'SDUP', 'SITE', 'SIZE', 'SMNT', 'STAT',
-    'STOR', 'STOU', 'STRU', 'SYST', 'TEST', 'TYPE', 'USER', 'XCUP', 'XCRC',
-    'XCWD', 'XMAS', 'XMD5', 'XMKD', 'XPWD', 'XRCP', 'XRMD', 'XRSQ', 'XSEM',
-    'XSEN', 'XSHA1', 'XSHA256'
+    --'OPTIONS',
 }
 
 sip_methods =
 {
-    'INVITE', 'CANCEL', 'ACK', 'BYE', 'REGISTER', 'OPTIONS', 'REFER', 'SUBSCRIBE',
+    'INVITE', 'CANCEL', 'ACK', 'BYE', 'REGISTER', 'REFER', 'SUBSCRIBE',
     'UPDATE', 'JOIN', 'INFO', 'MESSAGE', 'NOTIFY', 'PRACK'
+    --'OPTIONS',
 }
 
 telnet_commands =
@@ -309,23 +298,21 @@ default_wizard =
     spells =
     {
         { service = 'ftp', proto = 'tcp', client_first = false,
-          to_server = ftp_commands, to_client = { '220*FTP' } },
+          to_client = { '220*FTP' } },
 
         { service = 'http', proto = 'tcp', client_first = true,
           to_server = http_methods, to_client = { 'HTTP/' } },
 
         { service = 'imap', proto = 'tcp', client_first = false,
-          to_server = { 'LOGIN', 'AUTHENTICATE', 'STARTTLS' },
-          to_client = { '** OK', '** BYE' } },
+          to_client = { '** OK', '** BYE', '** PREAUTH' } },
 
         { service = 'pop3', proto = 'tcp', client_first = false,
-          to_server = { 'USER', 'APOP' },
           to_client = { '+OK', '-ERR' } },
 
-        { service = 'sip', proto = 'tcp', client_first = true,
+        { service = 'sip', client_first = true,
           to_server = sip_methods, to_client = { 'SIP/' } },
 
-        { service = 'smtp', proto = 'tcp', client_first = false,
+        { service = 'smtp', proto = 'tcp', client_first = true,
           to_server = { 'HELO', 'EHLO' },
           to_client = { '220*SMTP', '220*MAIL' } },
 
index 5b124548d6e82eaf7d0e65eadb039dff1ec2401d..49a444565dcba57b7d22c71332a5f49268985db7 100644 (file)
@@ -514,17 +514,14 @@ int detection_option_node_evaluate(
                         break;
                     }
                 }
-
                 rval = node->evaluate(node->option_data, cursor, p);
             }
-
             break;
 
         case RULE_OPTION_TYPE_FLOWBIT:
             if ( node->evaluate )
             {
-                flowbits_setoperation =
-                    FlowBits_SetOperation(node->option_data);
+                flowbits_setoperation = FlowBits_SetOperation(node->option_data);
 
                 if ( flowbits_setoperation )
                     // set to match so we don't bail early
@@ -533,13 +530,11 @@ int detection_option_node_evaluate(
                 else
                     rval = node->evaluate(node->option_data, cursor, eval_data->p);
             }
-
             break;
 
         default:
             if ( node->evaluate )
                 rval = node->evaluate(node->option_data, cursor, p);
-
             break;
         }
 
@@ -591,11 +586,8 @@ int detection_option_node_evaluate(
             {
                 for ( int i = 0; i < node->num_children; ++i )
                 {
-                    detection_option_tree_node_t* child_node =
-                        node->children[i];
-
-                    dot_node_state_t* child_state =
-                        child_node->state + get_instance_id();
+                    detection_option_tree_node_t* child_node = node->children[i];
+                    dot_node_state_t* child_state = child_node->state + get_instance_id();
 
                     for ( int j = 0; j < NUM_IPS_OPTIONS_VARS; ++j )
                         SetVarValueByIndex(tmp_byte_extract_vars[j], (int8_t)j);
@@ -604,9 +596,9 @@ int detection_option_node_evaluate(
                     {
                         if ( child_state->result == (int)IpsOption::NO_MATCH )
                         {
-                            if ( !child_node->is_relative )
+                            if ( child_node->option_type == RULE_OPTION_TYPE_CONTENT )
                             {
-                                if ( child_node->option_type == RULE_OPTION_TYPE_CONTENT )
+                                if ( !child_node->is_relative )
                                 {
                                     // If it's a non-relative content or pcre, no reason
                                     // to check again.  Only increment result once.
@@ -616,23 +608,23 @@ int detection_option_node_evaluate(
 
                                     continue;
                                 }
-                            }
-                            else if ( child_node->option_type == RULE_OPTION_TYPE_CONTENT )
-                            {
-                                // Check for an unbounded relative search.  If this
-                                // failed before, it's going to fail again so don't
-                                // go down this path again
-                                IpsOption* opt = (IpsOption*)node->option_data;
-                                PatternMatchData* pmd = opt->get_pattern(0, RULE_WO_DIR);
-
-                                if ( pmd->is_unbounded() )
+                                else
                                 {
-                                    // Only increment result once. Should hit this
-                                    // condition on first loop iteration
-                                    if (loop_count == 1)
-                                        ++result;
-
-                                    continue;
+                                    // Check for an unbounded relative search.  If this
+                                    // failed before, it's going to fail again so don't
+                                    // go down this path again
+                                    IpsOption* opt = (IpsOption*)child_node->option_data;
+                                    PatternMatchData* pmd = opt->get_pattern(0, RULE_WO_DIR);
+
+                                    if ( pmd and pmd->is_unbounded() )
+                                    {
+                                        // Only increment result once. Should hit this
+                                        // condition on first loop iteration
+                                        if (loop_count == 1)
+                                            ++result;
+
+                                        continue;
+                                    }
                                 }
                             }
                         }
index 860545620e78a256dbe435241be9d8c6156fadc8..7a9a297f174b465bc1f50878422458370247970d 100644 (file)
@@ -35,9 +35,8 @@ struct Packet;
 #define SOAPI_VERSION ((BASE_API_VERSION << 16) | 0)
 
 //-------------------------------------------------------------------------
-// rule format is:  header ( <stub opts>; soid:<tag>; <detect opts>; )
-// <stub opts> must include sid
-// <detect opts> may include so opts like so:<key>;
+// rule format is:  header ( [<stub opts>;] soid:<tag>; [<remaining opts>;] )
+// <remaining opts> may include so opts like so:<key>;
 // ctor(<key>) returns eval func and optional data
 // data is freed with dtor(data)
 
index e27ad6aec88f13fb69f91e0be18898ec1be6b5dc..30035735cc10a4c848093592f6c4b51369ba88ef 100644 (file)
@@ -343,9 +343,13 @@ IpsOption::EvalStatus ByteTestOption::eval(Cursor& c, Packet* p)
     }
     else
     {
+        unsigned len = btd->relative_flag ? c.length() : c.size();
+
+        if ( len > btd->bytes_to_compare )
+            len = btd->bytes_to_compare;
+
         payload_bytes_grabbed = string_extract(
-            btd->bytes_to_compare, btd->base,
-            start_ptr, c.buffer(), c.endo(), &value);
+            len, btd->base, start_ptr, c.buffer(), c.endo(), &value);
 
         if ( payload_bytes_grabbed < 0 )
         {
index 8d45419463a6847679d70579c572fb7a496d7d2a..9cb3347d478a8e64f6c42adf5df7ddf3421b3769 100644 (file)
@@ -168,6 +168,11 @@ static IpsOption* so_ctor(Module* p, OptTreeNode* otn)
     SoModule* m = (SoModule*)p;
     const char* name = m->name.c_str();
 
+    if ( !otn->soid )
+    {
+        ParseError("no soid before so:%s", name);
+        return nullptr;
+    }
     SoEvalFunc func = SoManager::get_so_eval(otn->soid, name, &data);
 
     if ( !func )
index 72357842c4597da0b3c06626540a728cc426e8fa..500885ecd57077a257b941961a35604be3b55f7f 100644 (file)
@@ -36,7 +36,7 @@
 static const Parameter s_params[] =
 {
     { "~", Parameter::PT_STRING, nullptr, nullptr,
-      "SO rule ID has <gid>|<sid> format, like 3|12345" },
+      "SO rule ID is unique key, eg <gid>_<sid>_<rev> like 3_45678_9" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index dca145cbe50ba6b1d26b0faa6a629e9e5b2ea6fe..48f6e3010b6e4956aefcc0922d79713c54bcf172 100644 (file)
@@ -109,7 +109,7 @@ public:
 
 public:
     PolicyId policy_id;
-    PolicyMode policy_mode = POLICY_MODE__INLINE_TEST;
+    PolicyMode policy_mode = POLICY_MODE__MAX;
     uint32_t user_policy_id = 0;
     uuid_t uuid{};
 
@@ -137,7 +137,7 @@ public:
     uint32_t user_policy_id = 0;
     uuid_t uuid{};
 
-    PolicyMode policy_mode;
+    PolicyMode policy_mode = POLICY_MODE__MAX;
     bool enable_builtin_rules;
 
     std::string include;
index 19d140b7c417ccc4c7a58de72c20cbf4b9e39a60..1a561ae9ecf63cc4ae23f0a5c5a0e878c934f376 100644 (file)
@@ -125,23 +125,23 @@ static void FreeReferences(ReferenceSystemNode* head)
     }
 }
 
-static void init_policy_mode(IpsPolicy* p)
+static PolicyMode init_policy_mode(PolicyMode mode)
 {
-    switch ( p->policy_mode )
+    switch ( mode )
     {
     case POLICY_MODE__PASSIVE:
         if ( SnortConfig::adaptor_inline_test_mode() )
-            p->policy_mode = POLICY_MODE__INLINE_TEST;
+            return POLICY_MODE__INLINE_TEST;
         break;
 
     case POLICY_MODE__INLINE:
         if ( SnortConfig::adaptor_inline_test_mode() )
-            p->policy_mode = POLICY_MODE__INLINE_TEST;
+            return POLICY_MODE__INLINE_TEST;
 
         else if (!SnortConfig::adaptor_inline_mode())
         {
             ParseWarning(WARN_DAQ, "adapter is in passive mode; switching policy mode to tap.");
-            p->policy_mode = POLICY_MODE__PASSIVE;
+            return POLICY_MODE__PASSIVE;
         }
         break;
 
@@ -150,17 +150,21 @@ static void init_policy_mode(IpsPolicy* p)
 
     case POLICY_MODE__MAX:
         if ( SnortConfig::adaptor_inline_mode() )
-            p->policy_mode = POLICY_MODE__INLINE;
+            return POLICY_MODE__INLINE;
         else
-            p->policy_mode = POLICY_MODE__PASSIVE;
+            return POLICY_MODE__PASSIVE;
         break;
     }
+    return mode;
 }
 
 static void init_policies(SnortConfig* sc)
 {
     for ( auto p : sc->policy_map->ips_policy )
-        init_policy_mode(p);
+        p->policy_mode = init_policy_mode(p->policy_mode);
+
+    for ( auto p : sc->policy_map->inspection_policy )
+        p->policy_mode = init_policy_mode(p->policy_mode);
 }
 
 //-------------------------------------------------------------------------
index 1160f7d9a16f042959707343735a88bfaf81f9bb..0004b7c79dd7b07500ae68977a80b2e5a9b71a1d 100644 (file)
@@ -368,10 +368,10 @@ static void unload_plugins()
         it->second.clear();
     }
 
+#ifndef REG_TEST
     for ( RefMap::iterator it = ref_map.begin(); it != ref_map.end(); ++it )
-    {
         dlclose(it->first);
-    }
+#endif
 }
 
 //-------------------------------------------------------------------------
index c02afd0844be3d08be2d71bdaffc04d0942a53ca..d09efad73f9bcad2fe4e67b22b9f08fe52e49bc2 100644 (file)
@@ -200,6 +200,9 @@ const char* SoManager::get_so_options(const char* soid)
     if ( !api )
         return nullptr;
 
+    if ( !api->length )
+        return ")";  // plain stub is full rule
+
     const char* rule = revert(api->rule, api->length);
 
     if ( !rule )
@@ -271,17 +274,14 @@ void SoManager::dump_rule_stubs(const char*)
 static void get_var(const string& s, string& v)
 {
     v.clear();
-    size_t pos = s.find("soid");
+    size_t pos = s.find("soid:");
 
     if ( pos == string::npos )
         return;
 
-    pos = s.find('|', pos+1);
-
-    if ( pos == string::npos )
-        return;
+    pos += 5;
 
-    size_t end = s.find(';', ++pos);
+    size_t end = s.find(';', pos);
 
     if ( end == string::npos )
         return;
@@ -304,7 +304,7 @@ void SoManager::rule_to_hex(const char*)
     string var;
     get_var(text, var);
 
-    cout << "const uint8_t rule_" << var;
+    cout << "static const uint8_t rule_" << var;
     cout << "[] =" << endl;
     cout << "{" << endl << "   ";
     cout << hex << uppercase;
@@ -322,7 +322,7 @@ void SoManager::rule_to_hex(const char*)
 
     cout << dec;
     cout << "};" << endl;
-    cout << "const unsigned rule_" << var << "_len = ";
+    cout << "static const unsigned rule_" << var << "_len = ";
     cout << data.size() << ";" << endl;
 }
 
@@ -338,7 +338,7 @@ void SoManager::rule_to_text(const char*)
     string var;
     get_var(text, var);
 
-    cout << "const uint8_t rule_" << var;
+    cout << "static const uint8_t rule_" << var;
     cout << "[] =" << endl;
     cout << "{" << endl << "   ";
     cout << hex << uppercase;
@@ -356,7 +356,7 @@ void SoManager::rule_to_text(const char*)
 
     cout << dec;
     cout << "};" << endl;
-    cout << "const unsigned rule_" << var;
+    cout << "static const unsigned rule_" << var;
     cout << "_len = 0;" << endl;
 }
 
index 12e3f3c709597618c56b7f35d6a92239faebcbea..45c3a4d9e08a4286efccdcadca0656080be36f40 100644 (file)
@@ -206,6 +206,9 @@ void MemoryCap::calculate(unsigned num_threads)
 
 void MemoryCap::print()
 {
+    if ( !MemoryModule::is_active() )
+        return;
+
     const MemoryConfig& config = *SnortConfig::get_conf()->memory;
 
     if ( SnortConfig::log_verbose() or s_tracker.allocations )
index a563dd519f206306312433b81331f43348577361..938845852bd0e49d433081deb5cda978722f8c18 100644 (file)
@@ -55,6 +55,8 @@ static const Parameter s_params[] =
 // memory module
 // -----------------------------------------------------------------------------
 
+bool MemoryModule::configured = false;
+
 MemoryModule::MemoryModule() :
     Module(s_name, s_help, s_params)
 { }
@@ -75,3 +77,13 @@ bool MemoryModule::set(const char*, Value& v, SnortConfig* sc)
 
     return true;
 }
+
+bool MemoryModule::end(const char*, int, SnortConfig*)
+{
+    configured = true;
+    return true;
+}
+
+bool MemoryModule::is_active()
+{ return configured; }
+
index d892ff170af0ee9f57054a5c34b5b632381a26be..9adcee8ccbb60813cf073812e297d5e71f284643 100644 (file)
@@ -29,9 +29,15 @@ public:
     MemoryModule();
 
     bool set(const char*, Value&, SnortConfig*) override;
+    bool end(const char*, int, SnortConfig*) override;
 
     Usage get_usage() const override
     { return GLOBAL; }
+
+    static bool is_active();
+
+private:
+    static bool configured;
 };
 
 #endif
index a0e889ace5eabef1002a47c61f579234b3a6adfb..910f0885206b632e4837f34b31351fe598e032e8 100644 (file)
@@ -409,8 +409,8 @@ const PegInfo* NormalizeModule::get_pegs() const
 
     while ( p->name )
     {
-        test_pegs.push_back(*p);
         add_test_peg(*p);
+        test_pegs.push_back(*p);
         p++;
     }
 
@@ -419,8 +419,8 @@ const PegInfo* NormalizeModule::get_pegs() const
 
     while ( p->name )
     {
-        test_pegs.push_back(*p);
         add_test_peg(*p);
+        test_pegs.push_back(*p);
         p++;
     }
 
index 33aeb5db4bd256b6012373a5132a5121c8348447..1c9b0c5b2f3d5f4211a3a0663df6355007a608b0 100644 (file)
@@ -209,11 +209,13 @@ bool Normalize_IsEnabled(NormFlags nf)
     if ( !(t_flags & nf) )
         return false;
 
+    if ( get_inspection_policy()->policy_mode != POLICY_MODE__INLINE )
+        return false;
+
     NetworkPolicy* nap = get_network_policy();
     return ( (nap->normal_mask & nf) != 0 );
 }
 
-// FIXIT-L should return OFF if flag isn't set. Stream will need to handle that condition
 NormMode Normalize_GetMode(NormFlags nf)
 {
     if (Normalize_IsEnabled(nf))
index 3330bb1ccb39aff1b1d2383675b1bce29816365d..7afe5fd67b505572fda4815433bb41316734e29a 100644 (file)
@@ -60,8 +60,8 @@ enum NormFlags
 
 enum NormMode : int8_t
 {
-    NORM_MODE_ON,
     NORM_MODE_TEST,
+    NORM_MODE_ON,
     NORM_MODE_MAX
 };
 
index 6b2179667a516fb20554782f5c2603acd037443a..16ecae57a5fe4e38947628924ea214ceedafec39 100644 (file)
@@ -66,7 +66,7 @@ void DceHttpProxy::clear(Packet* p)
             if ( c2s_splitter->cutover_inspector() && s2c_splitter->cutover_inspector() )
             {
                 dce_http_proxy_stats.http_proxy_sessions++;
-                dce_http_bind(flow, "dce_tcp");
+                dce_http_bind(flow, "dcerpc");
             }
             else
                 dce_http_proxy_stats.http_proxy_session_failures++;
index 7b64e3990a801cae558e5563fbfbfe5d49b85f32..f95f138e577d8c9e4ad8a2a358e73f8531bb2d94 100644 (file)
@@ -63,7 +63,7 @@ void DceHttpServer::clear(Packet* p)
             if ( splitter->cutover_inspector())
             {
                 dce_http_server_stats.http_server_sessions++;
-                dce_http_bind(flow, "dce_tcp");
+                dce_http_bind(flow, "dcerpc");
             }
             else
                 dce_http_server_stats.http_server_session_failures++;
index b7e3eb5bfd4964cdf37bb31a7816d2059be38493..651bb795aa472f0964ea9af2ccdbad6af03694fe 100644 (file)
@@ -462,7 +462,7 @@ const InspectApi dce2_smb_api =
     IT_SERVICE,
     (uint16_t)PktType::PDU,
     nullptr,  // buffers
-    "dce_smb",
+    "netbios-ssn",
     dce2_smb_init,
     nullptr, // pterm
     nullptr, // tinit
index fcaa0481ff8e8347a35a5f67ef41387b445666ed..605eb3b872024d2e1d7ee83754a2f3ae921ff6c3 100644 (file)
@@ -239,7 +239,7 @@ const InspectApi dce2_tcp_api =
     IT_SERVICE,
     (uint16_t)PktType::PDU,
     nullptr,  // buffers
-    "dce_tcp",
+    "dcerpc",
     dce2_tcp_init,
     nullptr, // pterm
     nullptr, // tinit
index f35edea30f0a5b9ef55cae5af14f31e1100c97b7..9348e4b2d60ff3b710f71097f03d838cad675eb2 100644 (file)
@@ -230,7 +230,7 @@ const InspectApi dce2_udp_api =
     IT_SERVICE,
     (uint16_t)PktType::UDP,
     nullptr,  // buffers
-    "dce_udp",
+    "dcerpc",
     dce2_udp_init,
     nullptr, // pterm
     nullptr, // tinit
index 3f31f3148f7f5f9c20e10bfe037672526fd85869..2256e6017882836c2122381f7588edcb88637191 100644 (file)
@@ -25,8 +25,6 @@
 namespace HttpEnums
 {
 static const int MAX_OCTETS = 63780;
-static const int DATA_BLOCK_SIZE = 16384;
-static const int FINAL_BLOCK_SIZE = 24576;
 static const int GZIP_BLOCK_SIZE = 2048;
 static const int FINAL_GZIP_BLOCK_SIZE = 2304; // compromise value, too big causes gzip overruns
                                                // too small leaves too many little end sections
index cd965d30b90d023e09bfbfadc26a8b92381acf26..89eb3bcad3842f419d654bb4038b543173fcadc7 100644 (file)
@@ -86,8 +86,9 @@ void HttpMsgSection::update_depth() const
     {
     case CMP_NONE:
       {
-        session_data->section_size_target[source_id] = DATA_BLOCK_SIZE + random_increment;
-        session_data->section_size_max[source_id] = FINAL_BLOCK_SIZE;
+        unsigned max_pdu = SnortConfig::get_conf()->max_pdu;
+        session_data->section_size_target[source_id] = max_pdu + random_increment;
+        session_data->section_size_max[source_id] = max_pdu + (max_pdu >> 1);
         break;
       }
     case CMP_GZIP:
index b43aca2bf5ce1b01b929776a9362489fd969897b..b1a88961459e383ec507dbba6c979ebfea9262df 100644 (file)
@@ -253,17 +253,17 @@ static bool dce_smb_curse(const uint8_t* data, unsigned len, CurseTracker* track
 // map between service and curse details
 static vector<CurseDetails> curse_map
 {
-    // service_name    alg        is_tcp
-    { "dce_udp", dce_udp_curse, false },
-    { "dce_tcp", dce_tcp_curse, true },
-    { "dce_smb", dce_smb_curse, true },
+    // name      service        alg            is_tcp
+    { "dce_udp", "dcerpc",      dce_udp_curse, false },
+    { "dce_tcp", "dcerpc",      dce_tcp_curse, true  },
+    { "dce_smb", "netbios-ssn", dce_smb_curse, true  },
 };
 
 bool CurseBook::add_curse(const char* key)
 {
     for (const CurseDetails& curse : curse_map)
     {
-        if (curse.service == key)
+        if (curse.name == key)
         {
             if (curse.is_tcp)
                 tcp_curses.push_back(&curse);
index 9df85d044faf96135ebf7010cb1bac8bd63c00e6..366471083800df5738e2671ba14c926b84334d2c 100644 (file)
@@ -52,6 +52,7 @@ typedef bool (* curse_alg)(const uint8_t* data, unsigned len, CurseTracker*);
 
 struct CurseDetails
 {
+    std::string name;
     std::string service;
     curse_alg alg;
     bool is_tcp;
index 85c3c5ab8d1d0c4e53041f1563b06c0ab783963e..b715bbbe1899a771781313ed836197be69cfe998 100644 (file)
@@ -21,6 +21,8 @@
 #include "config.h"
 #endif
 
+#include <cassert>
+
 #include "magic.h"
 
 using namespace std;
@@ -143,8 +145,9 @@ const MagicPage* SpellBook::find_spell(
                     return q;
                 ++i;
             }
+            return p->any;
         }
-        break;
+        return p->value.empty() ? nullptr : p;
     }
     return p;
 }
@@ -153,14 +156,15 @@ const char* SpellBook::find_spell(
     const uint8_t* data, unsigned len, const MagicPage*& p) const
 {
     // FIXIT-L make configurable upper bound to limit globbing
-    unsigned max = 16;
+    unsigned max = 64;
+    assert(p);
 
     if ( len > max )
         len = max;
 
     p = find_spell(data, len, p, 0);
 
-    if ( !p->value.empty() )
+    if ( p and !p->value.empty() )
         return p->value.c_str();
 
     return nullptr;
index b3dd1ce33a2e39eddb9d2f56a29105562c0aed0f..d3ad1b7e408448afcbf77e464b71882fbf974769 100644 (file)
@@ -108,6 +108,7 @@ public:
     StreamSplitter* get_splitter(bool) override;
 
     void reset(Wand&, bool tcp, bool c2s);
+    bool finished(Wand&);
     bool cast_spell(Wand&, Flow*, const uint8_t*, unsigned);
     bool spellbind(const MagicPage*&, Flow*, const uint8_t*, unsigned);
     bool cursebind(vector<CurseServiceTracker>&, Flow*, const uint8_t*, unsigned);
@@ -155,6 +156,10 @@ StreamSplitter::Status MagicSplitter::scan(
     if ( wizard->cast_spell(wand, f, data, len) )
         ++tstats.tcp_hits;
 
+    else if ( wizard->finished(wand) )
+        return ABORT;
+
+    // ostensibly continue but splitter will be swapped out upon hit
     return SEARCH;
 }
 
@@ -281,6 +286,18 @@ bool Wizard::cast_spell(
     return false;
 }
 
+bool Wizard::finished(Wand& w)
+{
+    if ( w.hex or w.spell )
+        return false;
+
+    // FIXTHIS-L how to know curses are done?
+    if ( !w.curse_tracker.empty() )
+        return false;
+
+    return true;
+}
+
 //-------------------------------------------------------------------------
 // api stuff
 //-------------------------------------------------------------------------
index c6ccfda32e10f9f5064e446f66f6e9a03a247eff..ce430a38914648971a078da0631cd9b42e8c4881 100644 (file)
@@ -95,11 +95,10 @@ IpsOption::EvalStatus SizeOption::eval(Cursor&, Packet* pkt)
 {
     Profile profile(streamSizePerfStats);
 
-    if (!pkt->flow || !pkt->ptrs.tcph)
+    if ( !pkt->flow || pkt->flow->pkt_type != PktType::TCP )
         return NO_MATCH;
 
-    Flow* lwssn = (Flow*)pkt->flow;
-    TcpSession* tcpssn = (TcpSession*)lwssn->session;
+    TcpSession* tcpssn = (TcpSession*)pkt->flow->session;
 
     uint32_t client_size;
     uint32_t server_size;
index 5f83c1a98ebc7563e8f9a1f432c97eb614c2c4f7..a306780052975bf43b6c8db3280a0a3d1aea14fa 100644 (file)
@@ -161,7 +161,7 @@ static const Parameter s_params[] =
     { "overlap_limit", Parameter::PT_INT, "0:255", "0",
       "maximum number of allowed overlapping segments per session" },
 
-    { "max_pdu", Parameter::PT_INT, "1460:65535", "16384",
+    { "max_pdu", Parameter::PT_INT, "1460:32768", "16384",
       "maximum reassembled PDU size" },
 
     { "policy", Parameter::PT_ENUM, TCP_POLICIES, "bsd",
index 15a677e3175515b889f2a7fc2e37eefaa4e60e83..32aa5f76f822df5a6ca074cd69093ddd0b29649a 100644 (file)
@@ -632,15 +632,10 @@ void TcpSession::handle_data_on_syn(TcpSegmentDescriptor& tsd)
     }
     else
     {
-        // remove data on SYN
         listener->normalizer->trim_syn_payload(tsd);
-
-        if (Normalize_GetMode(NORM_TCP_TRIM_SYN) != NORM_MODE_ON)
-        {
-            DebugMessage(DEBUG_STREAM_STATE, "Got data on SYN packet, not processing it\n");
-            tel.set_tcp_event(EVENT_DATA_ON_SYN);
-            pkt_action_mask |= ACTION_BAD_PKT;
-        }
+        DebugMessage(DEBUG_STREAM_STATE, "Got data on SYN packet, not processing it\n");
+        tel.set_tcp_event(EVENT_DATA_ON_SYN);
+        pkt_action_mask |= ACTION_BAD_PKT;
     }
 }
 
index 07ea5a843f3c26ef93076a19436949790e66de79..e992c9af419d702ae8e4077b876b584a62ddde01 100644 (file)
@@ -130,7 +130,10 @@ void UserTracker::init()
 void UserTracker::term()
 {
     if ( splitter )
+    {
         delete splitter;
+        splitter = nullptr;
+    }
 
     for ( auto* p : seg_list )
         snort_free(p);
index 2da3bf82020163dbcc27896f6f34c06142df5b2b..5b8c3fe1a1ef5937b5dd3fb8d3e9b990d43f117e 100644 (file)
@@ -60,9 +60,14 @@ bool PafMax::convert(std::istringstream& data_stream)
 
         if (val < 1460)
         {
-            data_api.add_comment("option change: 'paf_max [0:63780]' --> 'max_pdu [1460:63780]'");
+            data_api.add_comment("option change: 'paf_max [0:63780]' --> 'max_pdu [1460:32768]'");
             val = 1460;
         }
+        else if (val > 32768)
+        {
+            data_api.add_comment("option change: 'paf_max [0:63780]' --> 'max_pdu [1460:32768]'");
+            val = 32768;
+        }
         data_api.add_comment("stream_tcp.max_pdu = " + std::to_string(val));
 #endif
 
index a9f327a156bff20152c5389bd3abfb5bc137fca6..fd89184de132258aafcf4fb4fc4e81251cade19e 100644 (file)
@@ -34,6 +34,7 @@
 #include "data/data_types/dt_rule.h"
 #include "data/data_types/dt_table.h"
 #include "helpers/s2l_util.h"
+#include "helpers/util_binder.h"
 #include "init_state.h"
 
 TableDelegation table_delegation = 
@@ -51,13 +52,12 @@ bool Converter::convert_rules_mult_files = true;
 bool Converter::convert_conf_mult_files = true;
 bool Converter::bind_wizard = false;
 
-Converter::Converter()
-    :   table_api(&top_table_api, table_delegation),
+Converter::Converter() :
+    table_api(&top_table_api, table_delegation),
     state(nullptr),
     error(false),
     multiline_state(false)
-{
-}
+{ }
 
 Converter::~Converter()
 {
@@ -356,13 +356,13 @@ int Converter::convert(const std::string& input,
 
     if ( bind_wizard )
     {
-        // FIXIT-H this should create wizard = { } but need wizard = default_wizard
-        //table_api.open_top_level_table("wizard");
-        //table_api.close_table();
+        // add wizard = default_wizard before binder
         data_api.set_variable("wizard", "default_wizard", false);
 
+        // add binding for wizard at bottom of table
         auto& wiz = make_binder();
         wiz.set_use_type("wizard");
+        wiz.set_priority(Binder::MAX_PRIORITY);
     }
 
     add_bindings();
index 6859442fbb45121c2976a7f3a863f566a3f44deb..3ccb43647987a4042e4a6dc2c69eebabe268d040 100644 (file)
@@ -51,6 +51,8 @@ public:
     void print_binding(bool should_print)
     { printed = !should_print; }
 
+    static const unsigned MAX_PRIORITY = UINT_MAX;
+
     void set_priority(unsigned);
     unsigned get_priority();
 
@@ -137,7 +139,7 @@ private:
     bool printed = false; // ensures that the binding is added once,
                           // by either the destructor or user
 
-    unsigned priority = UINT_MAX;
+    unsigned priority = MAX_PRIORITY;
     
     int when_ips_policy_id = -1;
     std::string when_service;
index e08c5bdab3b11f0975614aacfced65c85e92eb2e..932e51c90696b2c45c87a39ad3bcb46fb11396c8 100644 (file)
@@ -502,12 +502,10 @@ bool StreamTcp::convert(std::istringstream& data_stream)
 
     if (!protos_set)
     {
-        const std::vector<std::string> default_protos = { "ftp", "telnet",
-                                                          "smtp", "nameserver", "dns", "http",
-                                                          "pop3", "sunrpc", "dcerpc",
-                                                          "netbios-ssn", "imap", "login", "shell",
-                                                          "mssql", "oracle", "cvs",
-                                                          "mysql" };
+        const std::vector<std::string> default_protos =
+        { "ftp", "telnet", "smtp", "nameserver", "dns", "http",
+          "pop3", "sunrpc", "dcerpc", "netbios-ssn", "imap",
+          "login", "shell", "mssql", "oracle", "cvs", "mysql" };
 
         for (const std::string& s : default_protos)
         {
index 0d6bde68bc8ca5f92789d31ce09094f94d8711a2..7d3b7521c359bcceab0378f36c4725cd0b4a1589 100644 (file)
@@ -83,6 +83,7 @@ bool Pcre::convert(std::istringstream& data_stream)
     pattern += pcre_str.substr(0, pattern_end + 1);
     options = pcre_str.substr(pattern_end + 1, std::string::npos);
     new_opts = "";
+    bool relative = false;
 
     for (char c : options )
     {
@@ -108,11 +109,14 @@ bool Pcre::convert(std::istringstream& data_stream)
         case 'A':
         case 'E':
         case 'G':
-        case 'R':
         case 'O':
         case '"':     // end of reg_ex
             new_opts += c;
             break;
+        case 'R':
+            relative = true;
+            new_opts += c;
+            break;
         default:
         {
             std::string dlt_opt = "unknown option - '";
@@ -136,7 +140,10 @@ bool Pcre::convert(std::istringstream& data_stream)
     }
 
     rule_api.add_option("pcre", pattern + new_opts);
-    rule_api.set_curr_options_buffer(buffer);
+
+    if ( !relative )
+        rule_api.set_curr_options_buffer(buffer);
+
     return set_next_rule_state(data_stream);
 }
 
index d275df6574a6c45fac4c5fcceed6784bafbd66d0..024a4499630338a4073ccc17f51e9bd5b99c55e0 100644 (file)
@@ -89,26 +89,24 @@ bool StreamSize::convert(std::istringstream& data_stream)
 
     else if (dir == "client")
     {
-        rule_api.add_suboption("to_client");
+        rule_api.add_suboption("to_server");
 
         static bool printed_client = false;
         if (!printed_client)
         {
             printed_client = true;
-            rule_api.add_comment("stream_size: option change: 'client'"
-                " --> 'to_client'");
+            rule_api.add_comment("stream_size: option change: 'client' --> 'to_server'");
         }
     }
     else if (dir == "server")
     {
-        rule_api.add_suboption("to_server");
+        rule_api.add_suboption("to_client");
 
         static bool printed_server = false;
         if (!printed_server)
         {
             printed_server = true;
-            rule_api.add_comment("stream_size: option change: 'server'"
-                " --> 'to_server'");
+            rule_api.add_comment("stream_size: option change: 'server' --> 'to_client'");
         }
     }
     else
index 6dd283e34338cf68855e09365d36656b60b562c9..d1520976346502a088ba4467a6256ee6d41b7732 100644 (file)
@@ -43,6 +43,14 @@ bool Urilen::convert(std::istringstream& data_stream)
     std::string value;
 
     args = util::get_rule_option_args(data_stream);
+
+    size_t ltgt = args.find("<>");
+
+    if ( ltgt != std::string::npos )
+    {
+        rule_api.add_comment("urilen: option change: '<>' --> '<=>'");
+        args.insert(ltgt+1, "=");
+    }
     std::istringstream arg_stream(args);
 
     // if there are no arguments, the option had a colon before a semicolon.