]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Snort2Lua: fixing ttl rule option. now converts 'threshold' keyword
authorJosh <jrosenba@cisco.com>
Tue, 18 Nov 2014 17:34:15 +0000 (11:34 -0600)
committerJosh <jrosenba@cisco.com>
Tue, 18 Nov 2014 17:34:15 +0000 (11:34 -0600)
tools/snort2lua/keyword_states/keywords_api.cc
tools/snort2lua/keyword_states/kws_event_filter.cc
tools/snort2lua/keyword_states/kws_suppress.cc
tools/snort2lua/rule_states/CMakeLists.txt
tools/snort2lua/rule_states/Makefile.am
tools/snort2lua/rule_states/rule_base64_decode.cc
tools/snort2lua/rule_states/rule_tag.cc
tools/snort2lua/rule_states/rule_threshold.cc
tools/snort2lua/rule_states/rule_ttl.cc [new file with mode: 0644]
tools/snort2lua/rule_states/rule_unchanged.cc
tools/snort2lua/tests/snort.conf.in

index e26773a2dc452e31fcb92830050b2b88e17172a0..5111342dc4116955e306dd895e31724bec585009 100644 (file)
@@ -49,7 +49,8 @@ extern const ConvertMap* reject_map;
 extern const ConvertMap* rule_state_map;
 extern const ConvertMap* sblock_map;
 extern const ConvertMap* sdrop_map;
-extern const ConvertMap* supress_map;
+extern const ConvertMap* suppress_map;
+extern const ConvertMap* threshold_map;
 extern const ConvertMap* var_map;
 
 
index 5166fb8fff060c99bc3f2ef9732fc81599408299..3bce59eeaa2679a690efa5fc0f9d32b22da380bb 100644 (file)
@@ -30,24 +30,35 @@ namespace keywords
 
 namespace {
 
-class EventFilter : public ConversionState
+class Filter : public ConversionState
 {
 public:
-    EventFilter(Converter& c) : ConversionState(c) {};
-    virtual ~EventFilter() {};
+    Filter(Converter& c, std::string s) : ConversionState(c), type(s) {};
+    virtual ~Filter() {};
     virtual bool convert(std::istringstream& data_stream);
+
+private:
+    std::string type;
 };
 
 } // namespace
 
-bool EventFilter::convert(std::istringstream& data_stream)
+bool Filter::convert(std::istringstream& data_stream)
 {
     std::string args;
     bool retval = true;
+    static bool warn = true;
 
     table_api.open_table("event_filter");
-    table_api.open_table();
 
+    if ( warn && !type.compare("threshold"))
+    {
+        table_api.add_diff_option_comment("threshold", "event_filter");
+        warn = false;
+    }
+
+
+    table_api.open_table();
     while (std::getline(data_stream, args, ','))
     {
         std::string keyword;
@@ -104,15 +115,26 @@ bool EventFilter::convert(std::istringstream& data_stream)
  *******  A P I ***********
  **************************/
 
-static ConversionState* ctor(Converter& c)
-{ return new EventFilter(c); }
+static ConversionState* threshold_ctor(Converter& c)
+{ return new Filter(c, "threshold"); }
+
+static ConversionState* event_filter_ctor(Converter& c)
+{ return new Filter(c, "event_filter"); }
+
 
 static const ConvertMap event_filter_api =
 {
     "event_filter",
-    ctor,
+    event_filter_ctor,
+};
+
+static const ConvertMap threshold_api =
+{
+    "threshold",
+    threshold_ctor,
 };
 
 const ConvertMap* event_filter_map = &event_filter_api;
+const ConvertMap* threshold_map = &threshold_api;
 
 } // namespace keywords
index 739953924f6737b04b529ded45197c881b7ac335..e128fc5168cc798ac20a01e57807983153a6fbc2 100644 (file)
@@ -134,12 +134,12 @@ bool Suppress::convert(std::istringstream& data_stream)
 static ConversionState* ctor(Converter& c)
 { return new Suppress(c); }
 
-static const ConvertMap keyword_supress =
+static const ConvertMap keyword_suppress =
 {
     "suppress",
     ctor,
 };
 
-const ConvertMap* supress_map = &keyword_supress;
+const ConvertMap* suppress_map = &keyword_suppress;
 
 } // namespace keywords
index 69f433c1ae8db1d9137dd87b6f48ac65ec4743a4..aab9bbd3aca52b3e3acd6b23d32d7283aab748fc 100644 (file)
@@ -11,6 +11,7 @@ add_library( rule_states
     rule_resp.cc
     rule_stream_reassemble.cc
     rule_tag.cc
+    rule_ttl.cc
     rule_threshold.cc
     rule_unchanged.cc
     rule_urilen.cc
index da30f5b1593dd96bcd8a36e490081a20068a359b..3391f3df8b9d526a36b2f85d44296ca072903854 100644 (file)
@@ -15,6 +15,7 @@ rule_react.cc \
 rule_resp.cc \
 rule_stream_reassemble.cc \
 rule_tag.cc \
+rule_ttl.cc \
 rule_threshold.cc \
 rule_unchanged.cc \
 rule_urilen.cc \
index a163365601d447d4932c86106d563cbc10ffcf7b..2e63330731ed5d07808cefe6a00fa720e3cb155a 100644 (file)
@@ -19,7 +19,6 @@
 // rule_base64_decode.cc author Josh Rosenbaum <jrosenba@cisco.com>
 
 #include <sstream>
-#include <vector>
 
 #include "conversion_state.h"
 #include "helpers/converter.h"
index 26d47de174afc96829676833c98d4484836aed57..5f06b6bb7bcc3ffcb8637958c477232bfd08df0b 100644 (file)
@@ -19,7 +19,6 @@
 // rule_tag.cc author Josh Rosenbaum <jrosenba@cisco.com>
 
 #include <sstream>
-#include <vector>
 
 #include "conversion_state.h"
 #include "helpers/converter.h"
index 231176e256e977c8dd907a65cdb52808554177d1..19c051b023530d59d791b7a90f30f8753dcdd4ba 100644 (file)
@@ -151,9 +151,7 @@ bool Threshold::convert(std::istringstream& data_stream)
 
 
 static ConversionState* ctor(Converter& c)
-{
-    return new Threshold(c);
-}
+{ return new Threshold(c); }
 
 static const ConvertMap rule_threshold =
 {
diff --git a/tools/snort2lua/rule_states/rule_ttl.cc b/tools/snort2lua/rule_states/rule_ttl.cc
new file mode 100644 (file)
index 0000000..e787e53
--- /dev/null
@@ -0,0 +1,113 @@
+
+/*
+** Copyright (C) 2014 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.
+*/
+// rule_base64_decode.cc author Josh Rosenbaum <jrosenba@cisco.com>
+
+#include <sstream>
+
+#include "conversion_state.h"
+#include "helpers/converter.h"
+#include "rule_states/rule_api.h"
+#include "helpers/s2l_util.h"
+
+namespace rules
+{
+
+namespace
+{
+
+
+class Ttl : public ConversionState
+{
+public:
+    Ttl(Converter& c) : ConversionState(c) {};
+    virtual ~Ttl() {};
+    virtual bool convert(std::istringstream&);
+};
+
+} // namespace
+
+bool Ttl::convert(std::istringstream& stream)
+{
+    std::string arg = util::get_rule_option_args(stream);
+
+
+    if ( arg.empty() )
+    {
+        rule_api.bad_rule(stream, "ttl <missing_arg>");
+    }
+    else
+    {
+        std::string new_val;
+
+        if ( arg.find('-') == std::string::npos )
+            new_val = arg;
+        else
+        {
+            if ( arg.find('-') != arg.rfind('-') )
+            {
+                new_val = arg;
+                rule_api.bad_rule(stream, "ttl '" + arg + "'' contains "
+                    "multiple dashes");
+            }
+            else
+            {
+                if ( arg.front() == '-' )
+                {
+                    arg.erase(0, 1);
+                    new_val = "<=" + arg;
+                }
+                else if ( arg.back() == '-' )
+                {
+                    arg.pop_back();
+                    new_val = ">=" + arg;
+                }
+                else
+                {
+                    std::istringstream arg_stream(arg);
+                    int low;
+                    int high;
+
+                    arg_stream >> low;
+                    arg_stream.ignore(1);
+                    arg_stream >> high;
+                    new_val = std::to_string(low) + "<=>" + std::to_string(high);
+                }
+            }
+        }
+
+        rule_api.add_option("ttl", new_val);
+    }
+
+    return set_next_rule_state(stream);
+}
+
+
+static ConversionState* ctor(Converter& c)
+{ return new Ttl(c); }
+
+static const ConvertMap rule_ttl =
+{
+    "ttl",
+    ctor,
+};
+
+const ConvertMap* ttl_map = &rule_ttl;
+
+} // namespace rules
index d650ada0cb291b50df56d7a7008fd76e83bcc045..04d2361e2799a5479b5cfeace8a5d4279d956659 100644 (file)
@@ -218,7 +218,6 @@ const ConvertMap* flags_map = &rule_flags;
  *********  FRAGOFFSET **************
  ************************************/
 
-
 static const std::string fragoffset = "fragoffset";
 static const ConvertMap rule_fragoffset =
 {
@@ -228,20 +227,6 @@ static const ConvertMap rule_fragoffset =
 
 const ConvertMap* fragoffset_map = &rule_fragoffset;
 
-/************************************
- ************* T T L ****************
- ************************************/
-
-
-static const std::string ttl = "ttl";
-static const ConvertMap rule_ttl =
-{
-    ttl,
-    unchanged_rule_ctor<&ttl>,
-};
-
-const ConvertMap* ttl_map = &rule_ttl;
-
 
 /************************************
  ************* T O S ****************
index 80487ee74aca9aceaec841f2172dc8d244dd0557..cd6b2ba9c89ebba16b3b87e0aa95267cda9e3392 100644 (file)
@@ -1327,3 +1327,9 @@ alert tcp $EXTERNAL_NET any -> $HOME_NET 135 ( msg:"DELETED NETBIOS DCERPC Remot
 alert tcp $EXTERNAL_NET any -> any $TEST_PORTS (msg:"MISC CVS non-relative path access attempt"; flow:to_server,established; content:"Argument"; pcre:!"m?^Argument\s+/?smi"; pcre:"m?^Argument\s+/?smi"; pcre:"/^Directory/smiR"; reference:bugtraq,9178; reference:cve,2003-0977; reference:nessus,11947; classtype:misc-attack; sid:2319; rev:4;)
 
 alert tcp any any -> any any ( msg:"First Cookie"; content:"OvCgi",http_uri; content:"AcceptLang=en-usaAAAA",http_cookie,nocase; sid:11111111; )
+
+
+threshold gen_id 1, sig_id 7037, type limit, track by_src, count 1, seconds 60
+alert ip any any -> any any (msg:"TTL RULE OPTION"; ttl:-4; sid:11111112;)
+alert ip any any -> any any (msg:"TTL RULE OPTION"; ttl:5-6; sid:11111113;)
+alert ip any any -> any any (msg:"TTL RULE OPTION"; ttl:7-; sid:11111114;)