]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #70 in SNORT/snort3 from crc/cleanup to master
authorRuss Combs (rucombs) <rucombs@cisco.com>
Fri, 9 Oct 2015 17:38:39 +0000 (13:38 -0400)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Fri, 9 Oct 2015 17:38:39 +0000 (13:38 -0400)
Squashed commit of the following:

commit 5b3501d68c43a3fcccd456986ff8a462dc18dec4
Author: russ <russ@localhost.localdomain>
Date:   Fri Oct 9 11:34:22 2015 -0400

    -- build 173
    -- update change log
    -- added pkt_num rule option to extras
    -- fix final -> finalize changes for extras
    -- moved alert_unixsock and log_null to extras
    -- removed duplicate pat_stats source from extras
    -- prevent tcp session restart on rebuilt packets
       thanks to rmkml for reporting the issue

    update change log

24 files changed:
ChangeLog
extra/src/ips_options/CMakeLists.txt
extra/src/ips_options/Makefile.am
extra/src/ips_options/ips_pkt_num.cc [new file with mode: 0644]
extra/src/ips_options/ips_urg.cc
extra/src/loggers/CMakeLists.txt
extra/src/loggers/Makefile.am
extra/src/loggers/alert_unixsock.cc [moved from src/loggers/alert_unixsock.cc with 94% similarity]
extra/src/loggers/log_null.cc [moved from src/loggers/log_null.cc with 94% similarity]
extra/src/search_engines/Makefile.am
src/framework/module.h
src/log/messages.h
src/loggers/CMakeLists.txt
src/loggers/Makefile.am
src/loggers/loggers.cc
src/main.cc
src/main/build.h
src/main/snort.cc
src/main/snort.h
src/managers/inspector_manager.cc
src/search_engines/pat_stats.h
src/service_inspectors/rpc_decode/rpc_module.h
src/service_inspectors/wizard/wizard.cc
src/stream/tcp/tcp_session.cc

index 496d2c3c4dd1fe1f2c3dff8c9dc1f00d4423a9f6..370101bae789c0213c3becb5f7728cfca3b4f4f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+15/10/09 - build 173
+
+-- added pkt_num rule option to extras
+-- fix final -> finalize changes for extras
+-- moved alert_unixsock and log_null to extras
+-- removed duplicate pat_stats source from extras
+-- prevent tcp session restart on rebuilt packets
+   thanks to rmkml for reporting the issue
+-- fixed profiler configuration
+-- fixed ppm event logging
+-- added filename to reload commands
+-- fixed -B switch
+-- reverted tcp syn only logic to match 2X
+-- ensure ip6 extension decoder state is reset for ip4 too since ip4
+   packets may have ip6 next proto
+-- update default manuals
+
 15/10/01 - build 172
 
 -- check for bool value before setting fastpath config option in PPM
index 859f7acdf055b47b32720c2a0f7d4f08add420e5..1fd7a2bf2c1d8199ba82e978f384bd5dea218d4a 100644 (file)
@@ -1,5 +1,6 @@
 
 add_example_library(ips_urg ips_options ips_urg.cc)
+add_example_library(ips_pkt_num ips_options ips_pkt_num.cc)
 
 install (
     FILES find.lua
index 68b12c412bcb9217f618c26224221d92997e87f4..081b6a1a553e8997c66cac4f8df62d907e5c3a62 100644 (file)
@@ -1,6 +1,12 @@
 
 optlibdir = $(pkglibdir)/ips_options
-optlib_LTLIBRARIES = libips_urg.la
+
+optlib_LTLIBRARIES = libips_pkt_num.la
+libips_pkt_num_la_CXXFLAGS = $(AM_CXXFLAGS)
+libips_pkt_num_la_LDFLAGS = -export-dynamic -shared
+libips_pkt_num_la_SOURCES = ips_pkt_num.cc
+
+optlib_LTLIBRARIES += libips_urg.la
 libips_urg_la_CXXFLAGS = $(AM_CXXFLAGS)
 libips_urg_la_LDFLAGS = -export-dynamic -shared
 libips_urg_la_SOURCES = ips_urg.cc
diff --git a/extra/src/ips_options/ips_pkt_num.cc b/extra/src/ips_options/ips_pkt_num.cc
new file mode 100644 (file)
index 0000000..d3d5faf
--- /dev/null
@@ -0,0 +1,202 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2014-2015 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.
+//--------------------------------------------------------------------------
+
+// ips_pkt_num.cc author Russ Combs <rucombs@cisco.com>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "main/snort_types.h"
+#include "main/thread.h"
+#include "detection/detection_defines.h"
+#include "detection/treenodes.h"
+#include "framework/ips_option.h"
+#include "framework/module.h"
+#include "framework/parameter.h"
+#include "framework/range.h"
+#include "hash/sfhashfcn.h"
+#include "protocols/packet.h"
+#include "protocols/tcp.h"
+#include "time/profiler.h"
+#include "utils/stats.h"
+
+static const char* s_name = "pkt_num";
+static const char* s_help = "alert on raw packet number";
+
+static THREAD_LOCAL ProfileStats pkt_num_perf_stats;
+
+//-------------------------------------------------------------------------
+// option
+//-------------------------------------------------------------------------
+
+class PktNumOption : public IpsOption
+{
+public:
+    PktNumOption(const RangeCheck& c) : IpsOption(s_name)
+    { config = c; }
+
+    uint32_t hash() const override;
+    bool operator==(const IpsOption&) const override;
+
+    int eval(Cursor&, Packet*) override;
+
+private:
+    RangeCheck config;
+};
+
+uint32_t PktNumOption::hash() const
+{
+    uint32_t a, b, c;
+
+    a = config.op;
+    b = config.min;
+    c = config.max;
+
+    mix_str(a,b,c,get_name());
+    finalize(a,b,c);
+
+    return c;
+}
+
+bool PktNumOption::operator==(const IpsOption& ips) const
+{
+    if ( strcmp(s_name, ips.get_name()) )
+        return false;
+
+    PktNumOption& rhs = (PktNumOption&)ips;
+    return ( config == rhs.config );
+}
+
+int PktNumOption::eval(Cursor&, Packet*)
+{
+    PROFILE_VARS;
+    MODULE_PROFILE_START(pkt_num_perf_stats);
+
+    int rval;
+
+    if ( config.eval(pc.total_from_daq) )
+        rval = DETECTION_OPTION_MATCH;
+
+    else
+        rval = DETECTION_OPTION_NO_MATCH;
+
+    MODULE_PROFILE_END(pkt_num_perf_stats);
+    return rval;
+}
+
+//-------------------------------------------------------------------------
+// module
+//-------------------------------------------------------------------------
+
+static const Parameter s_params[] =
+{
+    { "~range", Parameter::PT_STRING, nullptr, nullptr,
+      "check if packet number is in given range" },
+
+    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+};
+
+class PktNumModule : public Module
+{
+public:
+    PktNumModule() : Module(s_name, s_help, s_params) { }
+
+    bool begin(const char*, int, SnortConfig*) override;
+    bool set(const char*, Value&, SnortConfig*) override;
+
+    ProfileStats* get_profile() const override
+    { return &pkt_num_perf_stats; }
+
+    RangeCheck data;
+};
+
+bool PktNumModule::begin(const char*, int, SnortConfig*)
+{
+    data.init();
+    return true;
+}
+
+bool PktNumModule::set(const char*, Value& v, SnortConfig*)
+{
+    if ( !v.is("~range") )
+        return false;
+
+    return data.parse(v.get_string());
+}
+
+//-------------------------------------------------------------------------
+// api methods
+//-------------------------------------------------------------------------
+
+static Module* mod_ctor()
+{
+    return new PktNumModule;
+}
+
+static void mod_dtor(Module* m)
+{
+    delete m;
+}
+
+static IpsOption* pkt_num_ctor(Module* p, OptTreeNode*)
+{
+    PktNumModule* m = (PktNumModule*)p;
+    return new PktNumOption(m->data);
+}
+
+static void pkt_num_dtor(IpsOption* p)
+{
+    delete p;
+}
+
+static const IpsApi pkt_num_api =
+{
+    {
+        PT_IPS_OPTION,
+        sizeof(IpsApi),
+        IPSAPI_VERSION,
+        0,
+        API_RESERVED,
+        API_OPTIONS,
+        s_name,
+        s_help,
+        mod_ctor,
+        mod_dtor
+    },
+    OPT_TYPE_DETECTION,
+    1, PROTO_BIT__TCP,
+    nullptr, // pinit
+    nullptr, // pterm
+    nullptr, // tinit
+    nullptr, // tterm
+    pkt_num_ctor,
+    pkt_num_dtor,
+    nullptr
+};
+
+SO_PUBLIC const BaseApi* snort_plugins[] =
+{
+    &pkt_num_api.base,
+    nullptr
+};
+
index b414aa400373d5a2fdf2f62bab5a31b49acc4d61..f5fdb6c6ceba35cb480a1a5eb0d8685e263d3dc3 100644 (file)
@@ -72,7 +72,7 @@ uint32_t TcpUrgOption::hash() const
     c = config.max;
 
     mix_str(a,b,c,get_name());
-    final(a,b,c);
+    finalize(a,b,c);
 
     return c;
 }
index bbe03776585043b0ded9910b37297ae3757a489a..b05e6a2a6a4cf26a9b5b5510980bd90b90d80380 100644 (file)
@@ -1,5 +1,7 @@
 
 add_example_library(alert_ex loggers alert_ex.cc)
+add_example_library(alert_unixsock loggers alert_unixsock.cc)
+add_example_library(log_null loggers log_null.cc)
 
 install (
     FILES alert.lua
index 0f3e46f1e96e22a4685c75b3a75041bdfdc9a091..43ddafc461fad8d98eab15250653cb4572ad24e0 100644 (file)
@@ -6,6 +6,16 @@ libalert_ex_la_CXXFLAGS = $(AM_CXXFLAGS)
 libalert_ex_la_LDFLAGS = -export-dynamic -shared
 libalert_ex_la_SOURCES = alert_ex.cc
 
+loglib_LTLIBRARIES += libalert_unixsock.la
+libalert_unixsock_la_CXXFLAGS = $(AM_CXXFLAGS)
+libalert_unixsock_la_LDFLAGS = -export-dynamic -shared
+libalert_unixsock_la_SOURCES = alert_unixsock.cc
+
+loglib_LTLIBRARIES += liblog_null.la
+liblog_null_la_CXXFLAGS = $(AM_CXXFLAGS)
+liblog_null_la_LDFLAGS = -export-dynamic -shared
+liblog_null_la_SOURCES = log_null.cc
+
 dist_loglib_SCRIPTS = alert.lua
 
 AM_CXXFLAGS = @AM_CXXFLAGS@
similarity index 94%
rename from src/loggers/alert_unixsock.cc
rename to extra/src/loggers/alert_unixsock.cc
index 551527c81221d51dcba9fa936f44163aff217835..0def72553a7f790d01add01b41036b58fab6f796 100644 (file)
 #include "main/snort_debug.h"
 #include "framework/logger.h"
 #include "framework/module.h"
+#include "detection/signature.h"
 #include "events/event.h"
 #include "protocols/packet.h"
-#include "parser/parser.h"
 #include "utils/util.h"
-#include "packet_io/sfdaq.h"
 
 #define UNSOCK_FILE "snort_alert"
 
@@ -139,14 +138,11 @@ static void get_alert_pkt(
 
     if (p && p->pkt)
     {
-        uint32_t snaplen = DAQ_GetSnapLen();
-        memmove( (void*)&us.alert.pkth, (const void*)p->pkth,
-            sizeof(us.alert.pkth));
-        memmove(us.alert.pkt, (const void*)p->pkt,
-            us.alert.pkth.caplen > snaplen ? snaplen : us.alert.pkth.caplen);
+        memmove( (void*)&us.alert.pkth, (const void*)p->pkth, sizeof(us.alert.pkth));
+        memmove(us.alert.pkt, (const void*)p->pkt, us.alert.pkth.caplen);
     }
     else
-        us.alert.val|=NOPACKET_STRUCT;
+        us.alert.val |= NOPACKET_STRUCT;
 
     if (msg)
     {
@@ -298,13 +294,9 @@ static LogApi unix_sock_api
     unix_sock_dtor
 };
 
-#ifdef BUILDING_SO
 SO_PUBLIC const BaseApi* snort_plugins[] =
 {
     &unix_sock_api.base,
     nullptr
 };
-#else
-const BaseApi* alert_unix_sock = &unix_sock_api.base;
-#endif
 
similarity index 94%
rename from src/loggers/log_null.cc
rename to extra/src/loggers/log_null.cc
index 9932140cced099252b1eebd4f6415c91346104b4..65401759a216b80e62269768dc3c3fc126c7d548 100644 (file)
@@ -33,7 +33,7 @@
 #include "framework/module.h"
 
 #define s_name "log_null"
-#define s_help "support for null encapsulation"
+#define s_help "disable logging of packets"
 
 //-------------------------------------------------------------------------
 // log_null module
@@ -70,13 +70,9 @@ static LogApi null_api
     null_dtor
 };
 
-#ifdef BUILDING_SO
 SO_PUBLIC const BaseApi* snort_plugins[] =
 {
     &null_api.base,
     nullptr
 };
-#else
-const BaseApi* log_null = &null_api.base;
-#endif
 
index 7feaaa4d768e474380a103fa13fbf0e18b717076..c3d21923be141471e5559306e9c79c07021c6a00 100644 (file)
@@ -7,7 +7,6 @@ liblowmem_la_LDFLAGS = -export-dynamic -shared
 liblowmem_la_SOURCES = \
 lowmem.cc \
 lowmem_q.cc \
-pat_stats.cc \
 sfksearch.cc \
 sfksearch.h \
 trie_api.cc
index d66407187717cbc78c4dec3ff240ae82516dee90..fb1e5d4bb10f0e9a8037c90df2e91e322e3916c2 100644 (file)
@@ -82,7 +82,7 @@ public:
     { return true; }
 
     virtual bool set(const char*, Value&, SnortConfig*)
-    { return !get_parameters(); }
+    { return false; }
 
     // ips events:
     virtual unsigned get_gid() const
index acb4732047c2a45e3d3a4aa6144c765820c1a577..193cc1b58a97b34cbfe2ecbdd40c76c68bd29eae 100644 (file)
@@ -48,7 +48,7 @@ struct ThrottleInfo
 void ErrorMessageThrottled(ThrottleInfo*,const char*, ...) __attribute__((format (printf, 2, 3)));
 
 // FIXIT-M do not call FatalError() during runtime
-NORETURN void FatalError(const char*, ...) __attribute__((format (printf, 1, 2)));
+SO_PUBLIC NORETURN void FatalError(const char*, ...) __attribute__((format (printf, 1, 2)));
 
 SO_PUBLIC void PrintPacketData(const uint8_t*, const uint32_t);
 SO_PUBLIC char* ObfuscateIpToText(const sfip_t*);
index e26616769c0e6781238e1691dd049c7dfc7d68c0..c930e4c847bb1ac7181ef56c6bb95ea5fb310195 100644 (file)
@@ -11,9 +11,7 @@ set (PLUGIN_LIST
     alert_fast.cc
     alert_full.cc
     alert_syslog.cc
-    alert_unixsock.cc
     log_hext.cc
-    log_null.cc
     log_pcap.cc
     unified2.cc
     unified2_common.h
@@ -44,9 +42,7 @@ else (STATIC_LOGGERS)
     add_shared_library(alert_fast loggers alert_fast.cc)
     add_shared_library(alert_full loggers alert_full.cc)
     add_shared_library(alert_syslog loggers alert_syslog.cc)
-    add_shared_library(alert_unixsock loggers alert_unixsock.cc)
     add_shared_library(log_hext loggers log_hext.cc)
-    add_shared_library(log_null loggers log_null.cc)
     add_shared_library(log_pcap loggers log_pcap.cc)
     add_shared_library(unified2 loggers unified2.cc unified2_common.h)
 
index 2e4ac58b3b57ee1b60ff60620adedb7bfcbf15ca..7af92026a7f3f5fd33575e00cd15fd7a420d42dd 100644 (file)
@@ -11,9 +11,7 @@ alert_csv.cc \
 alert_fast.cc \
 alert_full.cc \
 alert_syslog.cc \
-alert_unixsock.cc \
 log_hext.cc \
-log_null.cc \
 log_pcap.cc \
 unified2.cc \
 unified2_common.h
@@ -48,21 +46,11 @@ libalert_syslog_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
 libalert_syslog_la_LDFLAGS = -export-dynamic -shared
 libalert_syslog_la_SOURCES = alert_syslog.cc
 
-ehlib_LTLIBRARIES += libalert_unixsock.la
-libalert_unixsock_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
-libalert_unixsock_la_LDFLAGS = -export-dynamic -shared
-libalert_unixsock_la_SOURCES = alert_unixsock.cc
-
 ehlib_LTLIBRARIES += liblog_hext.la
 liblog_hext_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
 liblog_hext_la_LDFLAGS = -export-dynamic -shared
 liblog_hext_la_SOURCES = log_hext.cc
 
-ehlib_LTLIBRARIES += liblog_null.la
-liblog_null_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
-liblog_null_la_LDFLAGS = -export-dynamic -shared
-liblog_null_la_SOURCES = log_null.cc
-
 ehlib_LTLIBRARIES += liblog_pcap.la
 liblog_pcap_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
 liblog_pcap_la_LDFLAGS = -export-dynamic -shared
index cf50d1d0c04061273e1d6e88efe28c710f3187ad..0eea95e870aff08345f4796ab3b348fe06cde13d 100644 (file)
@@ -37,15 +37,16 @@ extern const BaseApi* alert_csv;
 extern const BaseApi* alert_fast;
 extern const BaseApi* alert_full;
 extern const BaseApi* alert_syslog;
-extern const BaseApi* alert_unix_sock;
 extern const BaseApi* log_hext;
-extern const BaseApi* log_null;
 extern const BaseApi* log_pcap;
 extern const BaseApi* eh_unified2;
 #endif
 
 const BaseApi* loggers[] =
 {
+    // loggers
+    log_codecs,
+
 #ifdef LINUX
     alert_sf_socket,
 #endif
@@ -56,18 +57,15 @@ const BaseApi* loggers[] =
     alert_fast,
     alert_full,
     alert_syslog,
-    alert_unix_sock,
+
     // loggers
     log_hext,
-    log_null,
     log_pcap,
 
     // both
     eh_unified2,
 #endif
-    // loggers
-    log_codecs,
-    // both
+
     nullptr
 };
 
index d199dac6d2933bec9abc3b1e6016034646bd5d20..fe3daa0c0adc99e24beea737da9febc39b55233d 100644 (file)
@@ -58,6 +58,7 @@ using namespace std;
 #include "control/idle_processing.h"
 #include "target_based/sftarget_reader.h"
 #include "flow/flow_control.h"
+#include "lua/lua.h"
 #include "helpers/process.h"
 #include "helpers/swapper.h"
 #include "time/profiler.h"
index c86775825d1cc10cdc8befa2f90ee56562cf5b5c..da0bddd85fc4ab5b5951695c7654175bf9d049b9 100644 (file)
@@ -10,7 +10,7 @@
 //                                               //
 //-----------------------------------------------//
 
-#define BUILD "172"
+#define BUILD "173"
 
 #endif
 
index 270efe6a0f2962c0cfdaa98ab7088d8aca74ae00..f12ebe514061486fb8c4e2905e2fd57765fa2a5e 100644 (file)
@@ -687,21 +687,6 @@ void Snort::thread_term()
     Active::term();
 }
 
-void Snort::decode_rebuilt_packet(
-    Packet* p, const DAQ_PktHdr_t* pkthdr, const uint8_t* pkt,
-    Flow* lws)
-{
-    SnortEventqPush();
-    PacketManager::decode(p, pkthdr, pkt, true);
-
-    p->flow = lws;
-
-    set_policy(p);  // FIXIT-M rebuilt should reuse original bindings from flow
-
-    SnortEventqReset();
-    SnortEventqPop();
-}
-
 void Snort::detect_rebuilt_packet(Packet* p)
 {
     int tmp_do_detect = do_detect;
index e54e413096f310c2f77235eca80bf2ba693b2346..41180a309150a4ccc255c1459a8691be7560711f 100644 (file)
@@ -54,7 +54,6 @@ public:
     static void thread_rotate();
 
     static void capture_packet();
-    static void decode_rebuilt_packet(Packet*, const DAQ_PktHdr_t*, const uint8_t* pkt, Flow*);
     static void detect_rebuilt_packet(Packet*);
 
     static DAQ_Verdict process_packet(
index 36aaecdc5574b811e08f18b6df3664671006ae0d..eb8fccf1f49a0c288a17f49e943f2c75965e0095 100644 (file)
@@ -766,7 +766,7 @@ void InspectorManager::full_inspection(FrameworkPolicy* fp, Packet* p)
     if ( !flow->service )
         ::execute(p, fp->network.vec, fp->network.num);
 
-    else if ( flow->clouseau )
+    else if ( flow->clouseau and !p->is_cooked() )
         bumble(p);
 
     if ( !p->dsize )
index 97564cdd22dfda9209e3f349b2bb1133b44c6e84..5e41e3866950ecb739e7142213f48afad35784e9 100644 (file)
@@ -36,7 +36,7 @@ struct PatMatQStat
 
 extern THREAD_LOCAL PatMatQStat pmqs;
 
-void print_pat_stats(const char*, unsigned max);
+SO_PUBLIC void print_pat_stats(const char*, unsigned max);
 
 #endif
 
index 2a5ca79a510a28cb54bf75ed91840646bfc46bd4..5ba20c07a00ccf9424fb6598415fcbd4eb06c696 100644 (file)
@@ -42,9 +42,6 @@ class RpcDecodeModule : public Module
 public:
     RpcDecodeModule();
 
-    bool set(const char*, Value&, SnortConfig*) override
-    { return false; }
-
     unsigned get_gid() const override
     { return GID_RPC_DECODE; }
 
index 5651998e5e54c2ca7a119417906fc9ecfb99a17d..033400b4909047bdd239cc45b3f720db829215a0 100644 (file)
@@ -129,6 +129,7 @@ MagicSplitter::~MagicSplitter()
     wizard->rem_ref();
 }
 
+// FIXIT-M stop search on hit and failure (no possible match)
 StreamSplitter::Status MagicSplitter::scan(
     Flow* f, const uint8_t* data, uint32_t len,
     uint32_t, uint32_t*)
index f694feab840b5db5213dfc7d17fac8fdf71bd65d..dbfe3728cd0d682b2bbb6ae3388fc4ea58636364 100644 (file)
@@ -2559,6 +2559,9 @@ void TcpSession::clear()
 
 void TcpSession::restart(Packet* p)
 {
+    // sanity check since this is called externally
+    assert(p->ptrs.tcph);
+
     TcpTracker* talker, *listener;
 
     if (p->packet_flags & PKT_FROM_SERVER)