]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3302: appid: do not add odp mapping for a process name that already...
authorMasud Hasan (mashasan) <mashasan@cisco.com>
Tue, 8 Mar 2022 19:15:24 +0000 (19:15 +0000)
committerMasud Hasan (mashasan) <mashasan@cisco.com>
Tue, 8 Mar 2022 19:15:24 +0000 (19:15 +0000)
Merge in SNORT/snort3 from ~SATHIRKA/snort3:custom_process_mapping to master

Squashed commit of the following:

commit 41b88649edd815ed38aa25641a360bf18ebac711
Author: Sreeja Athirkandathil Narayanan <sathirka@cisco.com>
Date:   Thu Mar 3 16:29:30 2022 -0500

    appid: do not add duplicate process to client app mapping for the same process name

src/network_inspectors/appid/client_plugins/eve_ca_patterns.cc
src/network_inspectors/appid/client_plugins/eve_ca_patterns.h
src/network_inspectors/appid/client_plugins/test/eve_ca_patterns_test.cc

index f79e8e1260e9aeae5d2fe733a37c17e482f4c9aa..0a68935d37e8af81096d8485e7e9c57044bc59f9 100644 (file)
@@ -37,16 +37,19 @@ void EveCaPatternMatchers::add_eve_ca_pattern(AppId app_id, const string& patter
     uint8_t confidence, const string& detector)
 {
     auto match = find_if(eve_ca_load_list.begin(), eve_ca_load_list.end(),
-        [app_id, pattern_str] (EveCaPattern* eve_ca)
-        { return (eve_ca->pattern == pattern_str and eve_ca->app_id != app_id); });
-
+        [pattern_str] (EveCaPattern* eve_ca) { return eve_ca->pattern == pattern_str; });
     if (match != eve_ca_load_list.end())
-        WarningMessage("appid: detector %s - process name '%s' for client app %d is already "
-            "mapped to client app %d\n", detector.c_str(), (*match)->pattern.c_str(), app_id,
-            (*match)->app_id);
-
-    EveCaPattern* new_eve_ca_pattern = new EveCaPattern(app_id, pattern_str, confidence);
-    eve_ca_load_list.push_back(new_eve_ca_pattern);
+    {
+        if ((*match)->app_id != app_id)
+            WarningMessage("appid: detector %s - process name '%s' for client app %d is already "
+                "mapped to client app %d\n", detector.c_str(), (*match)->pattern.c_str(), app_id,
+                (*match)->app_id);
+    }
+    else
+    {
+        EveCaPattern* new_eve_ca_pattern = new EveCaPattern(app_id, pattern_str, confidence);
+        eve_ca_load_list.push_back(new_eve_ca_pattern);
+    }
 }
 
 static int eve_ca_pattern_match(void* id, void*, int, void* data, void*)
index 7c395f0f230bcccf575b861cd91d6ea842085d68..93690c7439352565601f016e24b6506aee733afa 100644 (file)
@@ -49,6 +49,8 @@ public:
     void finalize_patterns();
     void reload_patterns();
 
+    const EveCaPatternList& get_eve_ca_load_list() const { return eve_ca_load_list; }
+
 private:
     snort::SearchTool eve_ca_pattern_matcher = snort::SearchTool();
     EveCaPatternList eve_ca_load_list;
index 7333fb7629c2e24e514d513c969b89cf60c5db53..a47d9a8d36cb4e50557e832f154555efd533a32f 100644 (file)
@@ -90,6 +90,25 @@ TEST(eve_ca_patterns_tests, match_eve_ca_pattern)
     CHECK(eve_matcher->match_eve_ca_pattern("firefox", 92) == APPID_UT_ID);
 }
 
+TEST(eve_ca_patterns_tests, add_eve_ca_pattern)
+{
+    // same process name mapped to different app
+    eve_matcher->add_eve_ca_pattern(APPID_UT_ID + 1, "firefox", 40, "custom_detector.lua");
+    eve_matcher->add_eve_ca_pattern(APPID_UT_ID + 2, "firefox", 90, "odp_detector.lua");
+
+    CHECK(eve_matcher->get_eve_ca_load_list().size() == 1);
+    CHECK(eve_matcher->get_eve_ca_load_list()[0]->app_id == APPID_UT_ID + 1);
+    CHECK(eve_matcher->get_eve_ca_load_list()[0]->confidence == 40);
+
+    // same process name mapped to an existing app, but with different confidence
+    eve_matcher->add_eve_ca_pattern(APPID_UT_ID + 1, "chrome", 80, "custom_detector.lua");
+    eve_matcher->add_eve_ca_pattern(APPID_UT_ID + 1, "chrome", 90, "odp_detector.lua");
+
+    CHECK(eve_matcher->get_eve_ca_load_list().size() == 2);
+    CHECK(eve_matcher->get_eve_ca_load_list()[1]->app_id == APPID_UT_ID + 1);
+    CHECK(eve_matcher->get_eve_ca_load_list()[1]->confidence == 80);
+}
+
 int main(int argc, char** argv)
 {
     int return_value = CommandLineTestRunner::RunAllTests(argc, argv);