]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
further refinements to session binding
authorRuss Combs <rucombs@cisco.com>
Wed, 21 May 2014 10:56:58 +0000 (06:56 -0400)
committerRuss Combs <rucombs@cisco.com>
Wed, 21 May 2014 10:56:58 +0000 (06:56 -0400)
lua/snort.lua
src/flow/flow.h
src/flow/flow_control.cc
src/main/binder.cc
src/main/binder.h
src/managers/inspector_manager.cc
src/stream/base/stream_base.cc
src/stream/tcp/stream_tcp.cc
src/stream/tcp/stream_tcp.h
src/stream/tcp/tcp_session.cc

index e945c79636e7cf8727a7b91abbf742fd8e60af14..513e1fe8417ad0d53b8a5c2520dc9669510ca783 100644 (file)
@@ -138,19 +138,6 @@ ignore_ports =
 }
 --]]
 
-tcp_client_ports = SSH_PORTS .. FTP_PORTS .. MAIL_PORTS .. RPC_PORTS ..
-[[
-    23 25 42 53 79 109 113 119 135 136 137 139 161 445 513 514 587 593 691
-    1433 1521 1741 3306 6070 6665 6666 6667 6668 6669 7000 8181 
-]]
-tcp_server_ports = ''
-tcp_both_ports = HTTP_PORTS ..
-[[
-    443 465 563 636 989 992 993 994 995 7907 7802 7801 7900 7901 7902 7903
-    7904 7905 7906 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918
-    7919 7920
-]]
-
 ---------------------------------------------------------------------------
 -- Step #2: configure builtin features
 ---------------------------------------------------------------------------
@@ -469,10 +456,10 @@ ftp_client =
 
 stream =
 {
-    tcp_cache = { max_sessions = 256 * K, idle_timeout = 60 },
-    udp_cache = { max_sessions = 128 * K, pruning_timeout = 30 },
-    ip_cache = { max_sessions = 64 * K },
-    icmp_cache = { max_sessions = 32 * K },
+    tcp_cache = { max_sessions = 256000, idle_timeout = 60 },
+    udp_cache = { max_sessions = 128000, pruning_timeout = 30 },
+    ip_cache = { max_sessions = 64000 },
+    icmp_cache = { max_sessions = 0 },
 }
 
 stream_tcp =
@@ -481,30 +468,14 @@ stream_tcp =
     paf_max = 16384,
 
     session_timeout = 180,
-    require_3whs = 180,
-    flush_factor = 0,
+    --require_3whs = -1,
 
+    flush_factor = 0,
     overlap_limit = 10,
 
-    queue_limit =
-    {
-        max_bytes = 3,
-        max_segments = 1300,
-    },
-    small_segments = 
-    {
-        count = 10,
-        maximum_size = 128,
-        ignore_ports = '1 2 3'
-    },
-
     footprint = 0,
-    reassemble_async = false,
+    reassemble_async = true,
     ignore_any_rules = false,
-
-    client_ports = tcp_client_ports,
-    server_ports = tcp_server_ports,
-    both_ports = tcp_both_ports,
 }
 
 stream_udp =
@@ -520,7 +491,7 @@ stream_icmp =
 
 stream_ip =
 {
-    session_timeout = 180,
+    session_timeout = 980,
     policy = 'windows', 
     max_overlaps = 10,
     max_frags = 8191,
@@ -603,8 +574,9 @@ default_rules =
 #include $PLUGIN_RULE_PATH/chat.rules
 #include $PLUGIN_RULE_PATH/dos.rules
 
-alert tcp any any -> any 80 ( sid:1; msg:"1"; content:"HTTP"; )
-alert tcp any 80 -> any any ( sid:2; msg:"2"; content:"HTTP"; )
+#alert tcp any any -> any 80 ( sid:1; msg:"1"; content:"HTTP"; )
+#alert tcp any 80 -> any any ( sid:2; msg:"2"; content:"HTTP"; )
+alert ( gid:129; sid:20; )
 ]]
 
 network =
@@ -615,9 +587,9 @@ network =
 -- put classic rules and includes in the include file and/or rules string
 ips =
 {
-    include = '../active.rules',
+    --include = '../active.rules',
     --rules = default_rules,
-    enable_builtin_rules = true
+    --enable_builtin_rules = true
 }
 
 -- prototype bindings:
@@ -627,28 +599,29 @@ ips =
 -- use: action | file | type,name | policy_id [,service]
 -- when: days, times are tbd
 
+targetX = { nets = HTTP_SERVERS, proto = 'tcp', ports = HTTP_PORTS } 
+
 bindings =
 {
-    -- define / load a policy only
+    -- product define / load a policy only to be selected by firewall
     {
         when = { policy_id = 'uuid' },
         use = { file = 'uuid.lua' }
     },
-    -- open source policy based on vlan
+    -- classic open source policy based on vlan
     {
         when = { vlans = '123' },
         use = { file = 'vlan.lua' }
     },
-    -- open source policy based on cidr
+    -- classic open source policy based on cidr
     {
-        when = { nets = '1.2.3.0/24' },
+        when = { nets = HOME_NET },
         use = { file = 'net.lua' }
     },
     -- targeted inspector config
-    {
-        when = { nets = '2.3.4.0/24', proto = 'tcp', ports = '80', role = 'any' },
-        use = { type = 'http_inspect', name = 'hi2' }
-    },
+    { when = targetX, use = { type = 'stream_tcp', name = 'tcpX' } },
+    { when = targetX, use = { type = 'http_inspect', name = 'hiX' } },
+
     -- auto service id override
     {
         when = { nets = '3.4.5.0/24', proto = 'tcp', ports = '80', role = 'any' },
index 718ad8173684494b225dba287f8cd2a6f6accb43..987ec10e864edba5d5d7258136d59b907fd00697 100644 (file)
@@ -81,7 +81,6 @@
 #define STREAM5_STATE_CLOSED            0x0800
 
 struct Packet;
-class Inspector;
 
 typedef void (*StreamAppDataFree)(void*);
 
index ebe22572d4ae7d8b615623fa4ddda7d03ad6949d..b44d1dda55edb1c88a240a62d7200701c17bc767 100644 (file)
@@ -307,7 +307,7 @@ void FlowControl::init_tcp(
 
 void FlowControl::process_tcp(Packet* p)
 {
-    if( !p->tcph || !tcp_cache )
+    if ( !tcp_cache )
         return;
 
     tcp_count += process(tcp_cache, p);
@@ -339,7 +339,7 @@ void FlowControl::init_udp(
 
 void FlowControl::process_udp(Packet* p)
 {
-    if( !p->udph || !udp_cache )
+    if ( !udp_cache )
         return;
 
     udp_count += process(udp_cache, p);
@@ -371,9 +371,6 @@ void FlowControl::init_icmp(
 
 void FlowControl::process_icmp(Packet* p)
 {
-    if ( !p->icmph )
-        return;
-
     if ( icmp_cache )
         icmp_count += process(icmp_cache, p);
 
@@ -407,7 +404,7 @@ void FlowControl::init_ip(
 
 void FlowControl::process_ip(Packet* p)
 {
-    if ( !p->iph || !ip_cache )
+    if ( !ip_cache )
         return;
 
     ip_count += process(ip_cache, p);
index 9ba01b5beca93c2661753d5ae85c239e083035e1..f56b2b3b1d3f176445597678953be091fe3ba9a6 100644 (file)
 #include "binder.h"
 
 #include "flow/flow.h"
+#include "framework/inspector.h"
 #include "managers/inspector_manager.h"
-
-class Inspector;
+#include "protocols/packet.h"
 
 // FIXIT these will move into bindings lookup structures
 // these are for defaults but lookups will support default
-// and non-defaults
-static Inspector* tcp_hand;
-static Inspector* udp_hand;
-static Inspector* icmp_hand;
-static Inspector* ip_hand;
+// and non-defaults (and client and server may differ)
+static Inspector* pin_tcp = nullptr;
+static Inspector* pin_udp = nullptr;
+static Inspector* pin_icmp = nullptr;
+static Inspector* pin_ip = nullptr;
 
-void Binder::init()
+void Binder::set(Inspector* pin, unsigned proto)
 {
-    // FIXIT this is backwards; InspectorManager must call
-    // binder to set the various default inspectors since
-    // binder doesn't know what inspectors are available
-    tcp_hand = InspectorManager::get_inspector("stream_tcp");
-    udp_hand = InspectorManager::get_inspector("stream_udp");
-    ip_hand = InspectorManager::get_inspector("stream_ip");
-    icmp_hand = InspectorManager::get_inspector("stream_icmp");
-
-    if ( !icmp_hand )
-        icmp_hand = ip_hand;
+    switch ( proto )
+    {
+    case PROTO_BIT__TCP: pin_tcp = pin; break;
+    case PROTO_BIT__UDP: pin_udp = pin; break;
+    case PROTO_BIT__ICMP: pin_icmp = pin; break;
+    case PROTO_BIT__IP: pin_ip = pin; break;
+    }
+}
 
-    // FIXIT need to instantiate if not set?
-    assert(tcp_hand);
-    assert(udp_hand);
-    assert(ip_hand);
-    assert(icmp_hand);
+void Binder::init()
+{
+    if ( !pin_icmp )
+        pin_icmp = pin_ip;
 }
 
 void Binder::init_flow(Flow* flow)
@@ -58,23 +55,23 @@ void Binder::init_flow(Flow* flow)
     switch ( flow->protocol )
     {
     case IPPROTO_TCP:
-        flow->set_client(tcp_hand);
-        flow->set_server(tcp_hand);
+        flow->set_client(pin_tcp);
+        flow->set_server(pin_tcp);
         break;
 
     case IPPROTO_UDP:
-        flow->set_client(udp_hand);
-        flow->set_server(udp_hand);
+        flow->set_client(pin_udp);
+        flow->set_server(pin_udp);
         break;
 
     case IPPROTO_ICMP:
-        flow->set_client(icmp_hand);
-        flow->set_server(icmp_hand);
+        flow->set_client(pin_icmp);
+        flow->set_server(pin_icmp);
         break;
 
     case IPPROTO_IP:
-        flow->set_client(ip_hand);
-        flow->set_server(ip_hand);
+        flow->set_client(pin_ip);
+        flow->set_server(pin_ip);
         break;
     }
 }
index 2d96fac238369fe618d0f4f7d63f86c74463e6bd..078106c2bce1382d9e8c30641c48e1f7716ec670 100644 (file)
@@ -74,6 +74,7 @@ class Binder
 {
 public:
     static void init();
+    static void set(class Inspector*, unsigned proto);
     static void init_flow(class Flow*);
 };
 
index e26b29e07b3d1ad9db351d6c149e776bbd9dbd1a..503eb00f1ef4e192a1223eb7901406f4d91500b1 100644 (file)
@@ -26,6 +26,7 @@
 #include <mutex>
 
 #include "module_manager.h"
+#include "main/binder.h"
 #include "framework/inspector.h"
 #include "detection/detection_util.h"
 #include "obfuscation.h"
@@ -139,13 +140,17 @@ struct FrameworkPolicy
         for ( auto* p : ph_list )
         {
             if ( p->pp_class.api.ssn )
-                continue;
+                Binder::set(p->handler, p->pp_class.api.proto_bits);
+
             else if ( p->pp_class.api.type == IT_STREAM )
                 session.add(p);
+
             else if ( p->pp_class.api.type < IT_STREAM )
                 network.add(p);
+
             else if ( p->pp_class.api.type < IT_SERVICE )
                 generic.add(p);
+
             else
                 service.add(p);
         }
index 03f743568b804bc3440fed146f05d43ee6363e7c..d9aba9a4a2e3f88e89a84cbd20aa9afb96fc701a 100644 (file)
@@ -199,22 +199,26 @@ void StreamBase::eval(Packet *p)
     switch ( GET_IPH_PROTO(p) )
     {
     case IPPROTO_TCP:
-        flow_con->process_tcp(p);
+        if ( p->tcph )
+            flow_con->process_tcp(p);
         break;
 
     case IPPROTO_UDP:
         if ( p->frag_flag )
             flow_con->process_ip(p);
 
-        flow_con->process_udp(p);
+        if ( p->udph )
+            flow_con->process_udp(p);
         break;
 
     case IPPROTO_ICMP:
-        flow_con->process_icmp(p);
+        if ( p->icmph )
+            flow_con->process_icmp(p);
         break;
 
     case IPPROTO_IP:
-        flow_con->process_ip(p);
+        if ( p->iph )
+            flow_con->process_ip(p);
         break;
     }
 
index 7a3aff8820be11e5a9ce1a7ca1e3611c5d66dcf5..3bea5396309408c9fdb996a95bd21ddb46c5825e 100644 (file)
@@ -110,18 +110,6 @@ static Module* mod_ctor()
 static void mod_dtor(Module* m)
 { delete m; }
 
-#if 0
-static void tcp_stats()
-{
-    // FIXIT add method to get exp cache?
-    LogMessage("            Expected Flows\n");
-    LogMessage("                  Expected: %lu\n", exp_cache->get_expects());
-    LogMessage("                  Realized: %lu\n", exp_cache->get_realized());
-    LogMessage("                    Pruned: %lu\n", exp_cache->get_prunes());
-    LogMessage("                 Overflows: %lu\n", exp_cache->get_overflows());
-}
-#endif
-
 static Inspector* tcp_ctor(Module* m)
 {
     StreamTcpModule* mod = (StreamTcpModule*)m;
index fbf215e64e05a8b7798d52b92e80149069a82742..b86813e9b1a8fb39145642c1ac2dcae3686f95df 100644 (file)
@@ -108,13 +108,12 @@ struct StreamTcpConfig
     void add_proto(const char* svc, bool c2s, bool s2c);
 };
 
+// misc stuff
 int Stream5VerifyTcpConfig(SnortConfig*, StreamTcpConfig *);
-void Stream5ResetTcp();
+void Stream5ResetTcpInstance(StreamTcpConfig*);
 
 Session* get_tcp_session(Flow*);
-
-// misc stuff
-void Stream5ResetTcpInstance(StreamTcpConfig*);
+StreamTcpConfig* get_tcp_cfg(Inspector*);
 
 void tcp_sinit();
 void tcp_sterm();
@@ -123,8 +122,6 @@ void tcp_stats();
 void tcp_reset_stats();
 void tcp_show(StreamTcpConfig*);
 
-StreamTcpConfig* get_tcp_cfg(Inspector*);
-
 // Stream support
 int Stream5FlushListener(Packet*, Flow*);
 int Stream5FlushTalker(Packet*, Flow*);
index 55a3ea49459b8cdf3cf75176d1a0826f8c73b587..2aa91da27e48c3ac97c79a3dedcdadac0cb1c379 100644 (file)
@@ -471,8 +471,6 @@ static void targetPolicyIterate(void (*callback)(int));
 #endif
 
 /*  G L O B A L S  **************************************************/
-// FIXIT eliminate these globals
-static THREAD_LOCAL Packet *s5_pkt = NULL;
 
 /* enum for policy names */
 static const char *reassembly_policy_names[] = {
@@ -525,8 +523,6 @@ static const char *flush_policy_names[] = {
     "Protocol-IPS"
 };
 
-static THREAD_LOCAL int s5_tcp_cleanup = 0;
-
 static const uint32_t g_static_points[RAND_FLUSH_POINTS] =
 {
     128, 217, 189, 130, 240, 221, 134, 129,
@@ -539,6 +535,8 @@ static const uint32_t g_static_points[RAND_FLUSH_POINTS] =
     201, 142, 153, 187, 173, 199, 143, 201
 };
 
+static THREAD_LOCAL Packet *s5_pkt = NULL;
+
 /*  F U N C T I O N S  **********************************************/
 static inline uint32_t GenerateFlushPoint(FlushPointList *flush_point_list)
 {
@@ -7964,15 +7962,6 @@ static void targetPolicyIterate(void (*callback)(int))
 }
 #endif
 
-//-------------------------------------------------------------------------
-
-void Stream5ResetTcp()
-{
-    s5_tcp_cleanup = 1;
-    flow_con->purge_flows(IPPROTO_TCP);
-    s5_tcp_cleanup = 0;
-}
-
 //-------------------------------------------------------------------------
 // TcpSession methods
 //-------------------------------------------------------------------------