]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Squashed commit of the following:
authorRuss Combs <rucombs@cisco.com>
Sat, 5 Aug 2017 15:56:54 +0000 (11:56 -0400)
committerRuss Combs <rucombs@cisco.com>
Sat, 5 Aug 2017 15:56:54 +0000 (11:56 -0400)
commit 3b226926b43af0665ba14c502c4a23cd8589811a
Author: Russ Combs <rucombs@cisco.com>
Date:   Sat Aug 5 10:55:06 2017 -0400

    rules: make table consistency checks debug only

commit 1f1901fecb88d2871fb4088d6f5f0955767ea5a3
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 4 14:01:13 2017 -0400

    doc: add stdlog usage example

commit f7f4dd5cef22a138582fe8ecad2d03f0b8a8e611
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 4 13:26:46 2017 -0400

    build: remove a4 from version string

commit 057220564faa84541f3882b2ea4e1d04df33557a
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 4 12:13:32 2017 -0400

    conf: convert string ranges to interval params

commit 2c997e0a969bea72bd641e519e48de4052753a16
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 4 11:03:29 2017 -0400

    conf: add explicit interval type

commit 756be7ac77ae96ef026aa92a4af268708ebf4748
Author: Russ Combs <rucombs@cisco.com>
Date:   Fri Aug 4 07:32:40 2017 -0400

    spell check: fix typo

commit fc7830bd27d6718a4bd439cde33bfc641d8363b7
Author: Russ Combs <rucombs@cisco.com>
Date:   Thu Aug 3 22:02:35 2017 -0400

    snort2lua: convert dsize:a<>b to dsize:a<=>b for consistency with other rule options

29 files changed:
CMakeLists.txt
configure.ac
doc/params.txt
doc/usage.txt
extra/src/ips_options/ips_pkt_num/ips_pkt_num.cc
extra/src/ips_options/ips_urg/ips_urg.cc
src/framework/parameter.cc
src/framework/parameter.h
src/ips_options/ips_ack.cc
src/ips_options/ips_bufferlen.cc
src/ips_options/ips_dsize.cc
src/ips_options/ips_fragoffset.cc
src/ips_options/ips_icmp_id.cc
src/ips_options/ips_icmp_seq.cc
src/ips_options/ips_icode.cc
src/ips_options/ips_id.cc
src/ips_options/ips_itype.cc
src/ips_options/ips_seq.cc
src/ips_options/ips_tos.cc
src/ips_options/ips_ttl.cc
src/ips_options/ips_window.cc
src/ports/port_table.cc
src/service_inspectors/dce_rpc/ips_dce_iface.cc
src/stream/tcp/ips_stream_size.cc
tools/snort2lua/output_states/out_sfunified2.cc
tools/snort2lua/rule_states/CMakeLists.txt
tools/snort2lua/rule_states/Makefile.am
tools/snort2lua/rule_states/rule_dsize.cc [new file with mode: 0644]
tools/snort2lua/rule_states/rule_unchanged.cc

index a1f71a71c2ad066e4aeeca84a4b2aa65daac84a2..3bf767d2b5e0f9e8c83eebbd3a865810c9ee90d5 100644 (file)
@@ -4,9 +4,8 @@ project (snort CXX C)
 set (VERSION_MAJOR 3)
 set (VERSION_MINOR 0)
 set (VERSION_BUILD 0)
-set (VERSION_RELEASE a4)
 set (VERSION
-    "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}-${VERSION_RELEASE}")
+    "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}")
 
 set (INCLUDE_SUFFIX "${CMAKE_PROJECT_NAME}")
 set (INCLUDE_INSTALL_PATH "include/${INCLUDE_SUFFIX}")
index e1bf4d4eec2f3c8b7a4624fa22d2cc6a49875d19..a3f7179bc71c94b6ce7c609a3fb0f0d7e895644c 100644 (file)
@@ -23,7 +23,7 @@
 # initialization
 #--------------------------------------------------------------------------
 
-AC_INIT([snort],[3.0.0-a4],[snort-team@cisco.com])
+AC_INIT([snort],[3.0.0],[snort-team@cisco.com])
 AC_PREREQ([2.69])
 
 AC_CONFIG_SRCDIR([src/main.h])
index a33a4e9b0041b6e7af110d704e87ad46c81c8c78..9fd4231c85a24b6be24decd75f2d8d07a1e36c4e 100644 (file)
@@ -13,6 +13,7 @@ The following types are used:
 * *enum*: a string selected from the given range
 * *implied*: an IPS rule option that takes no value but means true
 * *int*: a whole number in the given range
+* *interval*: a set of ints (see below)
 * *ip4*: an IP4 address or CIDR
 * *mac*: an ethernet address with the form 01:02:03:04:05:06
 * *multi*: one or more space separated strings from the given range
@@ -43,4 +44,7 @@ Some additional details to note:
   there is no hard limit.
 * bit_list is typically used to store a set of byte, port, or VLAN ID
   values.
+* interval takes the form [operator]i, j<>k, or j<=>k where i,j,k are
+  integers and operator is one of =, !, != (same as !), <, <=, >, >=.
+  j<>k means j < int < k and j<=>k means j <= int <= k.
 
index 0a036fca6280923535f088bbf6fc1d9f06aee125..b127e845b73a0b709f8559888abfccdeb30442b7 100644 (file)
@@ -98,6 +98,12 @@ Log any generated alerts to the console using the "-A" option:
 
     snort -c $my_path/etc/snort/snort.lua -r /path/to/my.pcap -A alert_full
 
+Capture separate stdout, stderr, and stdlog files (out has startup and
+shutdown output, err has warnings and errors, and log has alerts):
+
+    snort -c $my_path/etc/snort/snort.lua -r /path/to/my.pcap -A csv \
+        1>out 2>err 3>log
+
 Add or modify a configuration from the command line using the "--lua" option:
 
     snort -c $my_path/etc/snort/snort.lua -r /path/to/my.pcap -A cmg \
index 4b1a96da2466d58539872f894f8c1fa9ed29eaa5..1d51c8311af83fc9b3b1fbda8fa50ec525105af4 100644 (file)
@@ -87,9 +87,11 @@ int PktNumOption::eval(Cursor&, Packet*)
 // module
 //-------------------------------------------------------------------------
 
+#define RANGE "1:"
+
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
       "check if packet number is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
@@ -120,7 +122,7 @@ bool PktNumModule::set(const char*, Value& v, SnortConfig*)
     if ( !v.is("~range") )
         return false;
 
-    return data.validate(v.get_string(), "0:");
+    return data.validate(v.get_string(), RANGE);
 }
 
 //-------------------------------------------------------------------------
index f3818bb9506c2dc63b498a6c67676e132e6f5892..42c6e534f24fafd70be0d302aa85c9425362569d 100644 (file)
@@ -97,8 +97,8 @@ int TcpUrgOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if urgent offset is min<>max | <max | >min, range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if tcp urgent offset is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 99100c9ad8d5fd44888578e984d5658663234fa9..cac91045fbdd378653b42093fc30d72b39b0f32f 100644 (file)
@@ -78,6 +78,20 @@ static bool valid_int(Value& v, const char* r)
     return true;
 }
 
+// interval is a special case because we support a<>b and a<=>b for convenience.
+// if not for that, then dsize:1<>10; would be dsize:>1, <10; (2 parameters) but
+// that is the same as dsize:>1; dsize:<10; which is arguably easier to read and
+// not significantly worse performance and which we also, obviously, already
+// support.  and note that <> and <=> are non-standard Snort-isms.  so, we wind
+// up with a multivalued parameter which is best handled as a string.  validation
+// must be done by the user.  the advantage of using an interval instead of string
+// is that we can document the type in one place and the parameters can focus on
+// their actual, specific semantics instead of trying to explain the syntax.  this
+// also ensures that an int-type range is not applied to a string.
+
+static bool valid_interval(Value&, const char*)
+{ return true; }
+
 // FIXIT-L allow multiple , separated ranges
 static bool valid_real(Value& v, const char* r)
 {
@@ -362,6 +376,8 @@ bool Parameter::validate(Value& v) const
         // fall through
     case PT_INT:
         return valid_int(v, (const char*)range);
+    case PT_INTERVAL:
+        return valid_interval(v, (const char*)range);
     case PT_REAL:
         return valid_real(v, (const char*)range);
 
@@ -402,7 +418,7 @@ bool Parameter::validate(Value& v) const
 static const char* const pt2str[Parameter::PT_MAX] =
 {
     "table", "list", "dynamic",
-    "bool", "int", "real", "port",
+    "bool", "int", "interval", "real", "port",
     "string", "select", "multi", "enum",
     "mac", "ip4", "addr",
     "bit_list", "addr_list", "implied"
index eeab5a6172653da288920637b71e97ea5e3189d7..01387ca85ef671d692c5757ca03aab6277bf447c 100644 (file)
@@ -42,6 +42,7 @@ struct SO_PUBLIC Parameter
         PT_DYNAMIC,    // range is RangeQuery*
         PT_BOOL,       // if you are reading this, get more coffee
         PT_INT,        // signed 64 bits or less determined by range
+        PT_INTERVAL,   // string that defines an interval, bounds within range
         PT_REAL,       // double
         PT_PORT,       // 0 to 64K-1 unless specified otherwise
         PT_STRING,     // any string less than len chars
index 5e55ccaf2984d93b8a1b46a7f3cd444bb9c46508..7b7bdcedfabbcfbb07d195491a60901e0b2a5804 100644 (file)
@@ -94,9 +94,11 @@ int TcpAckOption::eval(Cursor&, Packet* p)
 // module
 //-------------------------------------------------------------------------
 
+#define RANGE "0:"
+
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
       "check if tcp ack value is 'value | min<>max | <max | >min'" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
@@ -127,7 +129,7 @@ bool AckModule::set(const char*, Value& v, SnortConfig*)
     if ( !v.is("~range") )
         return false;
 
-    return data.validate(v.get_string(), "0:");
+    return data.validate(v.get_string(), RANGE);
 }
 
 //-------------------------------------------------------------------------
index df072a0a6b7a2e802131ee4b72c0a999729fbeba..427b9f104a712028a21185d321e2046d2df1d831 100644 (file)
@@ -97,8 +97,8 @@ int LenOption::eval(Cursor& c, Packet*)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "len | min<>max | <max | >min, range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check that lenght of current buffer is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 540fa8a769867b3cd81218184e4d42ea9646927f..595068e6fe79cc8a2536ac459a35fa1c2ef7bd01 100644 (file)
@@ -103,8 +103,8 @@ int DsizeOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if packet payload size is 'size | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if packet payload size is in the given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index d377558e746bb861ad5e91ec275551edd12b7fb3..fb130b54972ffd5a437f298bf3eb2aed81c99ec9 100644 (file)
@@ -98,8 +98,8 @@ int FragOffsetOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if ip fragment offset value is 'value | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if ip fragment offset is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 60f42ca9e643c1b70932c8634df4733fdcaba88f..ad64a62776bebe4bc931212abe7064b1b6e00db5 100644 (file)
@@ -128,8 +128,8 @@ int IcmpIdOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if icmp id is 'id | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if icmp id is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 6f66bf110a17848334588539ac547994c5b3c15c..461b0005c01dfae7dd21d9d771212831f6cd502f 100644 (file)
@@ -129,8 +129,8 @@ int IcmpSeqOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if icmp sequence number is 'seq | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if icmp sequence number is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 9a0353b6c29dd8aaaa6652ddf6f1100f98198bce..5c07c5a290bd36372f6fe36cbc503865d10f6b37 100644 (file)
@@ -99,8 +99,8 @@ int IcodeOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if ICMP code is 'code | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if icmp code is in given range is" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index a76cf6740653fb794bef43f1a7745aa28eb1414d..838f5b30ac91be9a1d25a3bd87648352204c8571 100644 (file)
@@ -93,10 +93,12 @@ int IpIdOption::eval(Cursor&, Packet* p)
 // module
 //-------------------------------------------------------------------------
 
+#define RANGE "0:"
+
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if the IP ID is 'id | min<>max | <max | >min'" },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if the ip id is in the given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
@@ -129,7 +131,7 @@ bool IpIdModule::set(const char*, Value& v, SnortConfig*)
     if ( !v.is("~range") )
         return false;
 
-    return data.validate(v.get_string(), "0:");
+    return data.validate(v.get_string(), RANGE);
 }
 
 //-------------------------------------------------------------------------
index 9aeae999f5c411c30a911ba93853831b9c85a5eb..464476e73d8a096156afa2dc4a1ee6933d263726 100644 (file)
@@ -100,8 +100,8 @@ int IcmpTypeOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if icmp type is 'type | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if icmp type is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 9339f1a8982c475015f6dbd0a168070401d22626..b3672551e0e24793eea813a55d7e40a9889b532a 100644 (file)
@@ -93,10 +93,12 @@ int TcpSeqOption::eval(Cursor&, Packet* p)
 // module
 //-------------------------------------------------------------------------
 
+#define RANGE "0:"
+
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if tcp sequence number value is 'value | min<>max | <max | >min'" },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if tcp sequence number is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
@@ -129,7 +131,7 @@ bool SeqModule::set(const char*, Value& v, SnortConfig*)
     if ( !v.is("~range") )
         return false;
 
-    return data.validate(v.get_string(), "0:");
+    return data.validate(v.get_string(), RANGE);
 }
 
 //-------------------------------------------------------------------------
index 7954160caf3c44284b721e56d8f0d56473cc4452..cd32c99a7d70f16503501fc4b57e46734d3acf4b 100644 (file)
@@ -101,8 +101,8 @@ int IpTosOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if ip tos value is 'value | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if ip tos is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 80d5d868cc8659198b70f77d59cb2b08a748ab34..d5ad99641b5970e7c58cd7218f694e9eecbe27e7 100644 (file)
@@ -98,8 +98,8 @@ int TtlOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if ip ttl field value is 'value | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if ip ttl is in the given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index 02dc5b0b8ec6187724a73e69a3c9ad2461ceeb86..5cfc23f8fbb80931a38971381642f342144109ab 100644 (file)
@@ -98,8 +98,8 @@ int TcpWinOption::eval(Cursor&, Packet* p)
 
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "check if tcp window field size is 'size | min<>max | <max | >min', range is " RANGE },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if tcp window size is in given range" },
 
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
index b1229fbc96320696adfca1db48ce8fe6bb48d09c..25041b407cf1f2e1c707ff1593bddc40ad4aa48d 100644 (file)
@@ -513,33 +513,6 @@ static PortObject2* PortTableCompileMergePortObjectList2(
     return ponew;
 }
 
-/*
- *
- *  Verify all rules in 'po' list are in 'po2' hash
- *
- *  return  0 - OK
- *         !0 - a rule in po is not in po2
- */
-static int _po2_include_po_rules(PortObject2* po2, PortObject* po)
-{
-    SF_LNODE* rpos;
-
-    /* get each rule in po */
-    for ( int* pid = (int*)sflist_first(po->rule_list, &rpos);
-        pid;
-        pid = (int*)sflist_next(&rpos) )
-    {
-        /* find it in po2 */
-        int* id = (int*)sfghash_find(po2->rule_hash, pid);
-
-        /* make sure it's in po2 */
-        if ( !id )
-            return 1; /* error */
-    }
-
-    return 0;
-}
-
 static int PortTableCompileMergePortObjects(PortTable* p)
 {
     DebugMessage(DEBUG_PORTLISTS, "***\n***Merging PortObjects->PortObjects2\n***\n");
@@ -715,9 +688,9 @@ static int PortTableCompileMergePortObjects(PortTable* p)
     return 0;
 }
 
+#ifdef DEBUG
 // consistency check - part 1
 // make sure each port is only in one composite port object
-
 static bool PortTableConsistencyCheck(PortTable* p)
 {
     std::unique_ptr<char[]> upA(new char[SFPO_MAX_PORTS]);
@@ -757,6 +730,30 @@ static bool PortTableConsistencyCheck(PortTable* p)
     return true;
 }
 
+/*
+ * Verify all rules in 'po' list are in 'po2' hash
+ * return  0 - OK; !0 - a rule in po is not in po2
+ */
+static int _po2_include_po_rules(PortObject2* po2, PortObject* po)
+{
+    SF_LNODE* rpos;
+
+    /* get each rule in po */
+    for ( int* pid = (int*)sflist_first(po->rule_list, &rpos);
+        pid;
+        pid = (int*)sflist_next(&rpos) )
+    {
+        /* find it in po2 */
+        int* id = (int*)sfghash_find(po2->rule_hash, pid);
+
+        /* make sure it's in po2 */
+        if ( !id )
+            return 1; /* error */
+    }
+
+    return 0;
+}
+
 // consistency check - part 2
 /*
 * This phase checks the Input port object rules/ports against
@@ -809,6 +806,7 @@ static bool PortTableConsistencyCheck2(PortTable* p)
 
     return true;
 }
+#endif
 
 //-------------------------------------------------------------------------
 // PortTable - public
@@ -934,8 +932,10 @@ int PortTableCompile(PortTable* p)
 
     DEBUG_WRAP(DebugMessage(DEBUG_PORTLISTS, "Done\n"); fflush(stdout); );
 
+#ifdef DEBUG
     assert(PortTableConsistencyCheck(p));
     assert(PortTableConsistencyCheck2(p));
+#endif
 
     return 0;
 }
index b5d53c876b64c533a6fcc5638bb54fc9e6f39deb..35bcdb544efe3f635e1272849965d0d6613561ff 100644 (file)
@@ -421,11 +421,13 @@ int Dce2IfaceOption::eval(Cursor&, Packet* p)
 // dce2_iface module
 //-------------------------------------------------------------------------
 
+#define RANGE "0:"
+
 static const Parameter s_params[] =
 {
     { "uuid", Parameter::PT_STRING, nullptr, nullptr,
       "match given dcerpc uuid" },
-    { "version",Parameter::PT_STRING, nullptr, nullptr,
+    { "version",Parameter::PT_INTERVAL, RANGE, nullptr,
       "interface version" },
     { "any_frag", Parameter::PT_IMPLIED, nullptr, nullptr,
       "match on any fragment" },
@@ -456,7 +458,7 @@ bool Dce2IfaceModule::begin(const char*, int, SnortConfig*)
 bool Dce2IfaceModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("version") )
-        return version.validate(v.get_string(), "0:");
+        return version.validate(v.get_string(), RANGE);
     else if ( v.is("any_frag") )
         any_frag = true;
     else if ( v.is("uuid") )
index 26d18d2fb3f8290fe8455079b6bce544ba1296da..ef716bc8acc6c2117b16f09bab15ad30f77e583e 100644 (file)
@@ -162,10 +162,12 @@ int SizeOption::eval(Cursor&, Packet* pkt)
 // stream_size module
 //-------------------------------------------------------------------------
 
+#define RANGE "0:"
+
 static const Parameter s_params[] =
 {
-    { "~range", Parameter::PT_STRING, nullptr, nullptr,
-      "size for comparison" },
+    { "~range", Parameter::PT_INTERVAL, RANGE, nullptr,
+      "check if the stream size is in the given range" },
 
     { "~direction", Parameter::PT_ENUM, "either|to_server|to_client|both", nullptr,
       "compare applies to the given direction(s)" },
@@ -198,7 +200,7 @@ bool SizeModule::begin(const char*, int, SnortConfig*)
 bool SizeModule::set(const char*, Value& v, SnortConfig*)
 {
     if ( v.is("~range") )
-        return ssod.validate(v.get_string(), "0:");
+        return ssod.validate(v.get_string(), RANGE);
 
     else if ( v.is("~direction") )
         direction = v.get_long();
index 43439a2cfee833e745c480df0d5ed8867284d0a2..b83e88a136b1184919369ba6b48997cbbce2c426 100644 (file)
@@ -28,7 +28,7 @@ namespace output
 {
     namespace
     {
-        //FIXIT-L add when avaiable
+        //FIXIT-L add when available
         static std::string header = "output sf_unified2: ";
 
         template<std::string* header_text>
index e2f61d2db962b0932290c451f611eeb2e66908fa..f1f295322656d950e6b0c2da0412b4e04fff81cc 100644 (file)
@@ -5,6 +5,7 @@ add_library( rule_states
     rule_convert_comma_list.cc
     rule_dce_iface.cc
     rule_dnp3_obj.cc
+    rule_dsize.cc
     rule_file_data.cc
     rule_http_encode.cc
     rule_isdataat.cc
index 47c18e06172f7a5ba3ca881eaf34fd683a208529..bf6287d1d1792312a91834251cf0ab15c868916d 100644 (file)
@@ -7,6 +7,7 @@ rule_content.cc \
 rule_convert_comma_list.cc \
 rule_dce_iface.cc \
 rule_dnp3_obj.cc \
+rule_dsize.cc \
 rule_file_data.cc \
 rule_http_encode.cc \
 rule_isdataat.cc \
diff --git a/tools/snort2lua/rule_states/rule_dsize.cc b/tools/snort2lua/rule_states/rule_dsize.cc
new file mode 100644 (file)
index 0000000..5322768
--- /dev/null
@@ -0,0 +1,71 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2017-2017 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_dsize.cc author Russ Combs <rucombs@cisco.com>
+// (based on the amazing original work by Josh)
+
+#include <string>
+//#include <cstdlib>
+
+#include "conversion_state.h"
+#include "helpers/converter.h"
+#include "rule_states/rule_api.h"
+#include "helpers/s2l_util.h"
+
+namespace rules
+{
+namespace
+{
+class Dsize : public ConversionState
+{
+public:
+    Dsize(Converter& c) : ConversionState(c) { }
+    virtual ~Dsize() { }
+    virtual bool convert(std::istringstream& data);
+};
+} // namespace
+
+bool Dsize::convert(std::istringstream& data_stream)
+{
+    std::string args = util::get_rule_option_args(data_stream);
+    size_t ltgt = args.find("<>");
+
+    if ( ltgt != std::string::npos )
+    {
+        rule_api.add_comment("dsize: option change: '<>' --> '<=>'");
+        args.insert(ltgt+1, "=");
+    }
+    rule_api.add_option("dsize", args);
+    return set_next_rule_state(data_stream);
+}
+
+/**************************
+ *******  A P I ***********
+ **************************/
+
+static ConversionState* dsize_ctor(Converter& c)
+{ return new Dsize(c); }
+
+static const ConvertMap rule_dsize =
+{
+    "dsize",
+    dsize_ctor,
+};
+
+const ConvertMap* dsize_map = &rule_dsize;
+} // namespace rules
+
index 9af3fe69c80bd51a6191ab6a8b1691f4c4bd1943..160fc84082f1461e928d3798fbeb9ef027198db5 100644 (file)
@@ -172,20 +172,7 @@ static const ConvertMap rule_flowbits =
 const ConvertMap* flowbits_map = &rule_flowbits;
 
 /************************************
- *********  D S I Z E  **************
- ************************************/
-
-static const std::string dsize = "dsize";
-static const ConvertMap rule_dsize =
-{
-    dsize,
-    unchanged_rule_ctor<& dsize>,
-};
-
-const ConvertMap* dsize_map = &rule_dsize;
-
-/************************************
- *********  D S I Z E  **************
+ ************  FRABGITS  ************
  ************************************/
 
 static const std::string fragbits = "fragbits";