]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
adding arp and arpspoof. added a nameless tabled to api
authorJosh <jrosenba@cisco.com>
Thu, 12 Jun 2014 15:15:47 +0000 (11:15 -0400)
committerJosh <jrosenba@cisco.com>
Thu, 12 Jun 2014 15:15:47 +0000 (11:15 -0400)
15 files changed:
tools/snort2lua/converter.cc
tools/snort2lua/converter.h
tools/snort2lua/data/conv_data.cc
tools/snort2lua/data/conv_option.cc
tools/snort2lua/data/conv_table.cc
tools/snort2lua/data/conv_table.h
tools/snort2lua/keywords/include.cc
tools/snort2lua/keywords/preprocessor.cc
tools/snort2lua/keywords/var.cc
tools/snort2lua/preprocessor/CMakeLists.txt
tools/snort2lua/preprocessor/arpspoof.cc [new file with mode: 0644]
tools/snort2lua/preprocessor/http_inspect.cc
tools/snort2lua/preprocessor/normalizers.cc
tools/snort2lua/preprocessor/preprocessor_api.cc
tools/snort2lua/preprocessor/smtp.cc

index ad0f5d563b34bedb11bff7fdbfb6b689eff76a9b..6be89d64adccc763457a547cf58b53c8b0c08af7 100644 (file)
@@ -62,6 +62,22 @@ bool Converter::convert_line(std::stringstream& data)
     return false;
 }
 
+bool Converter::open_table()
+{
+    // if no open tables, create a top-level table
+    if (open_tables.size() > 0)
+    {
+        Table *t = open_tables.top()->open_table();
+        open_tables.push(t);
+        return true;
+    }
+    else
+    {
+        log_error("A nameless table must be nested!!");
+        return false;
+    }
+}
+
 bool Converter::open_table(std::string table_name)
 {
     Table *t;
index 2570ae78bb1a2333278e1d06a01cddecc7b6226a..1c6b04ccaf5213e5ad75664263d63d6f2c800e45 100644 (file)
@@ -45,11 +45,20 @@ public:
     bool inline add_variable(std::string name, std::string v){ return data.add_variable(name, v); };
     friend std::ostream &operator<<( std::ostream& out, const Converter &cv) { return out << cv.data; }
 
-    bool open_table(std::string);
+    // open a table that does not contain a name --> NOT 'name = {...}' ONLY {...})
+    bool open_table();
+    // open a  named tabled --> 'name = {...}')
+    bool open_table(std::string name);
+    // close the current table.  go to previous table level
     bool close_table();
+
+    // add a string option to the table --> table = { name = 'val', }
     bool add_option_to_table(std::string name, std::string val);
+    // add an int option to the table --> table = { name = val, }
     bool add_option_to_table(std::string name, int val);
+    // add a bool option to the table --> table = { name = true|false, }
     bool add_option_to_table(std::string name, bool val);
+    // add a commment to be printed in the table --> table = { -- comment \n }
     void add_comment_to_table(std::string comment);
 
     void add_comment_to_file(std::string comment);
index 788c42ae3d85c8a7718613055416dccbf19f22ce..56982031d10e296d03d74dfe761aac54ac9abe89 100644 (file)
@@ -31,6 +31,9 @@
 
 static inline Table* find_table(std::vector<Table*> vec, std::string name)
 {
+    if(name.empty())
+        return nullptr;
+    
     for( auto *t : vec)
         if(!name.compare(t->get_name()))
             return t;
index be5d7ad712a3a9a461aa0efed223d19d5fab7c6e..90cbb51606cf59836a91843e2a5bd43255510bf7 100644 (file)
@@ -62,12 +62,12 @@ std::ostream &operator<<( std::ostream& out, const Option &o)
     switch(o.type)
     {
         case Option::OptionType::STRING:
-            out << '\'' << o.value << "',";
+            out << '\'' << o.value << '\'';
             break;
 
         case Option::OptionType::BOOL:
         case Option::OptionType::INT:
-            out << o.value << ',';
+            out << o.value;
             break;
     }
     return out;
index d0e0017ee1b4955f9dbdd3869aaf1e747fd291a2..cdfb86181eab1be433373c3ecba510a3255f0822 100644 (file)
@@ -23,6 +23,9 @@
 
 static inline Table* find_table(std::vector<Table*> vec, std::string name)
 {
+    if(name.empty())
+        return nullptr;
+
     for( auto *t : vec)
         if(!name.compare(t->get_name()))
             return t;
@@ -30,10 +33,10 @@ static inline Table* find_table(std::vector<Table*> vec, std::string name)
     return nullptr;
 }
 
-Table::Table(std::string name)
+Table::Table(int depth)
 {
-    this->name = name;
-    depth = 0;
+    this->name = "";
+    this->depth = depth;
 }
 
 Table::Table(std::string name, int depth)
@@ -51,6 +54,13 @@ Table::~Table()
         delete o;
 }
 
+Table* Table::open_table()
+{
+    Table *t = new Table(depth + 1);
+    tables.push_back(t);
+    return t;
+}
+
 Table* Table::open_table(std::string name)
 {
     Table* t = find_table(tables, name);
@@ -133,23 +143,24 @@ std::ostream &operator<<( std::ostream& out, const Table &t)
     for(int i = 0; i < t.depth; i++)
         whitespace += "    ";
 
-    out << whitespace << t.name << " = " << std::endl;
+    if(!t.name.empty())
+        out << whitespace << t.name << " = " << std::endl;
     out << whitespace << '{' << std::endl;
 
     for(std::string s : t.comments)
         out << whitespace << "    --" << s << std::endl;
 
     for (Option* o : t.options)
-        out << (*o) << std::endl;
+        out << (*o) << ',' << std::endl;
 
     for (Table* t : t.tables)
-        out << (*t) << std::endl;
+        out << (*t) << ',' << std::endl;
 
     // don't add a comma if the depth is zero
     if(t.depth == 0)
         out << "}";
     else
-        out << whitespace << "},";
+        out << whitespace << "}";
     
     return out;
 }
index cd34654ea53c180768e12e1cd37b76498f27dc91..7318a2f9b5bffac8e3a54d087dbe7ce6fc65ef96 100644 (file)
 class Table
 {
 public:
-    Table(std::string name);
+    Table(int depth);
     Table(std::string name, int depth);
     virtual ~Table();
 
     inline std::string get_name(){ return name; };
+    Table* open_table();
     Table* open_table(std::string);
     bool add_option(std::string, int val);
     bool add_option(std::string, bool val);
index 19eb2e82f11d2089998c9f83907167a3d637b565..5ddaf799fe84f76469f47bf6b1ecd99a34a7d379 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// config.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// include.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
index beba4739611f55afd7cb6516b047379dc65708e7..36426defb76a1dbfb54e64ba1595985a89133429 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// config.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// preprocessor.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
index a797f9eed2507842f75ec0b8cba30e997b44749a..91f2941e9797ca83ea20dc70a6aeb89a95724659 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// output.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// var.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
index 8f27d4df2c7e7c00b8df330bc050c468c5af94bc..e7a10572535f6c322e7f3cfd560c766bc675850e 100644 (file)
@@ -1,5 +1,6 @@
 
 add_library(preprocessor
+    arpspoof.cc
     http_inspect.cc
     smtp.cc
     normalizers.cc
diff --git a/tools/snort2lua/preprocessor/arpspoof.cc b/tools/snort2lua/preprocessor/arpspoof.cc
new file mode 100644 (file)
index 0000000..b6d90a0
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2002-2013 Sourcefire, Inc.
+ *
+ * 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.
+ */
+// arp_spoof.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+
+#include "conversion_state.h"
+#include "converter.h"
+#include "snort2lua_util.h"
+
+namespace {
+
+class ArpSpoof : public ConversionState
+{
+public:
+    ArpSpoof(Converter* cv)  : ConversionState(cv) {};
+    virtual ~ArpSpoof() {};
+    virtual bool convert(std::stringstream& data_stream);
+};
+
+} // namespace
+
+
+bool ArpSpoof::convert(std::stringstream& data_stream)
+{
+    std::string keyword;
+    bool retval = true;
+    converter->open_table("arp_spoof");
+
+    while(data_stream >> keyword)
+    {
+
+        if(!keyword.compare("-unicast"))
+            retval = converter->add_option_to_table("unicast", true) && retval;
+
+        else 
+            retval = false;
+    }
+
+    return retval;    
+}
+
+/*******  A P I ***********/
+
+static ConversionState* arpspoof_ctor(Converter* cv)
+{
+    return new ArpSpoof(cv);
+}
+
+static const ConvertMap preprocessor_arpspoof = 
+{
+    "arpspoof",
+    arpspoof_ctor,
+};
+
+const ConvertMap* arpspoof_map = &preprocessor_arpspoof;
+
+
+
+/********************************
+ *******  ArpSpoof Host *********
+ ********************************/
+
+
+namespace {
+
+class ArpSpoofHost : public ConversionState
+{
+public:
+    ArpSpoofHost(Converter* cv)  : ConversionState(cv) {};
+    virtual ~ArpSpoofHost() {};
+    virtual bool convert(std::stringstream& data_stream);
+};
+
+} // namespace
+
+
+bool ArpSpoofHost::convert(std::stringstream& data_stream)
+{
+    std::string ip, mac;
+
+    bool retval = true;
+    converter->open_table("arp_spoof");
+    converter->open_table("hosts");
+
+    while(data_stream >> ip &&
+          data_stream >> mac)
+    {
+        converter->open_table();
+        converter->add_option_to_table("ip", ip);
+        converter->add_option_to_table("mac", mac);
+        converter->close_table();
+
+        ip.clear();
+        mac.clear();
+    }
+
+    if (!ip.empty())
+        return false;
+
+    return retval;    
+}
+
+/*******  A P I ***********/
+
+static ConversionState* arpspoof_host_ctor(Converter* cv)
+{
+    return new ArpSpoofHost(cv);
+}
+
+static const ConvertMap preprocessor_arpspoof_host = 
+{
+    "arpspoof_detect_host",
+    arpspoof_host_ctor,
+};
+
+const ConvertMap* arpspoof_host_map = &preprocessor_arpspoof_host;
index a02d584a50a99af18536679f7aa5409dd15491a6..a928eeb640c19f768e8087f4db2378b70540f83d 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// config.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// http_inspect.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
index 94a05b6f67138501d79b51b503143292cf592d8f..1e1a3ef8aa7de83d90f9022b6f0d5344617338b8 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// config.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// normalizers.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
index 0f9c47c813160e53308777a85989a5746499190a..7b44e924d3503687d47abf941b6752cd9860017a 100644 (file)
@@ -22,6 +22,8 @@
 #include "preprocessor/preprocessor_api.h"
 
 
+extern const ConvertMap *arpspoof_map;
+extern const ConvertMap *arpspoof_host_map;
 extern const ConvertMap *httpinspect_map;
 extern const ConvertMap *normalizer_icmp4_map;
 extern const ConvertMap *normalizer_icmp6_map;
@@ -32,6 +34,8 @@ extern const ConvertMap *smtp_map;
 
 const std::vector<const ConvertMap*> preprocessor_api = 
 {
+    arpspoof_map,
+    arpspoof_host_map,
     httpinspect_map,
     normalizer_icmp4_map,
     normalizer_icmp6_map,
index 03efd6825cdfdb5e6ee19d144d8a8a9e43c89a7a..1b5a141d814e2c3e29254db8d38b238d0e8b11cc 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// config.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// smtp.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>