]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1382 in SNORT/snort3 from config_address_anomaly to master
authorMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 23 Oct 2018 20:16:36 +0000 (16:16 -0400)
committerMike Stepanek (mstepane) <mstepane@cisco.com>
Tue, 23 Oct 2018 20:16:36 +0000 (16:16 -0400)
Squashed commit of the following:

commit e3885a1d1e15a5b8d5749067f0f2201223c50ed1
Author: Pratik Shinde <pshinde2@cisco.com>
Date:   Fri Oct 5 15:44:51 2018 -0400

    snort2lua: Enable address_anomaly_detection during snort2lua and fixed missing string sanity checks

tools/snort2lua/data/data_types/dt_var.cc
tools/snort2lua/data/dt_rule_api.cc
tools/snort2lua/data/dt_rule_api.h
tools/snort2lua/helpers/converter.cc
tools/snort2lua/helpers/s2l_util.cc

index a8ad7e45aedc6cede7911db270e565b08b973203..7e9ab839c22960092f57798a85f491ed40dea5b2 100644 (file)
@@ -89,7 +89,7 @@ bool Variable::add_value(std::string elem)
         }
     }
 
-    if (s.front() == '$')
+    if (!s.empty() and s.front() == '$')
     {
         // add a space between strings
         if (!vars.empty())
index 67966f10ea7db9a534d8886adde3447cda6a1e94..8a06afba5d387abce2aa973228e68ee83344d58a 100644 (file)
 std::size_t RuleApi::error_count = 0;
 std::string RuleApi::remark;
 
+std::set<GidSid> RuleApi::address_anomaly_rules = {
+                                            {"116", "403"},
+                                            {"116", "411"},
+                                            {"116", "412"},
+                                            {"129", "9"},
+                                            {"129", "10"},
+                                        };
+
 RuleApi::RuleApi()
     :   curr_rule(nullptr),
     curr_data_bad(false)
@@ -95,6 +103,15 @@ void RuleApi::make_rule_a_comment()
     curr_rule->make_comment();
 }
 
+bool RuleApi::enable_addr_anomaly_detection()
+{
+    if (curr_rule != nullptr)
+        return address_anomaly_rules.count({curr_rule->get_option("gid"),
+                                          curr_rule->get_option("sid")}) != 0;
+
+    return false;
+}
+
 void RuleApi::bad_rule(std::istringstream& stream, const std::string& bad_option)
 {
     if (!curr_rule)
index 5206677cf7259b2e5376db2c8a6fbc8f99f4d380..c69e7ebfec3917d33d2020cb046209e47284b353 100644 (file)
 #ifndef DATA_DT_RULE_API_H
 #define DATA_DT_RULE_API_H
 
-#include <string>
 #include <iostream>
-#include <vector>
+#include <set>
 #include <stack>
+#include <string>
+#include <vector>
 
 class Rule;
 class RuleOption;
 class Comments;
 class RuleApi;
 
+using GidSid = std::pair<std::string, std::string>;
+
 // FIXIT-L simplify this API. Several options functions are no longer necessary
 
 class RuleApi
@@ -74,6 +77,7 @@ public:
 
     void add_comment(const std::string& comment);
     void make_rule_a_comment();
+    bool enable_addr_anomaly_detection();
     void bad_rule(std::istringstream& stream, const std::string& bad_option);
     void old_http_rule();
     bool is_old_http_rule();
@@ -86,6 +90,7 @@ private:
     Comments* bad_rules;
     Rule* curr_rule;
     bool curr_data_bad;
+    static std::set<GidSid> address_anomaly_rules;
 
     // Create a new rule object.
     void begin_rule();
index 98066667d2fa97ca89a57f120e7d066757611c82..cc4c0eee1769fcd15f0787e087668149f5c1a6dd 100644 (file)
 TableDelegation table_delegation = 
 {
     { "binder", true },
+    { "detection", true },
     { "ips", true },
     { "network", true },
-    { "normalizer", true},
+    { "normalizer", true },
     { "stream_tcp", true},
     { "suppress", true},
 };
@@ -283,6 +284,13 @@ int Converter::parse_file(
                     table_api.close_table();
                 }
 
+                if (rule_api.enable_addr_anomaly_detection())
+                {
+                    table_api.open_table("detection");
+                    table_api.add_option("enable_address_anomaly_checks", true);
+                    table_api.close_table();
+                }
+
                 if (commented_rule)
                     rule_api.make_rule_a_comment();
 
index 590f0d2519eb5ce835e1a0158a42481f181b968d..4d7e20cbb939ce9c438001c5bdb5c86578220505 100644 (file)
@@ -248,12 +248,18 @@ std::string get_rule_option_args(std::istringstream& stream)
     do
     {
         std::getline(stream, tmp, ';');
+
+        if (tmp.empty())
+            break;
+
         args += tmp + ";";
     }
     while (tmp.back() == '\\');
 
     // semicolon will be added when printing
-    args.pop_back();
+    if (!args.empty())
+        args.pop_back();
+
     trim(args);
     return args;
 }