]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
adding ftp_telnet converter
authorJosh <jrosenba@cisco.com>
Mon, 16 Jun 2014 17:23:59 +0000 (13:23 -0400)
committerJosh <jrosenba@cisco.com>
Mon, 16 Jun 2014 18:14:35 +0000 (14:14 -0400)
21 files changed:
tools/snort2lua/CMakeLists.txt
tools/snort2lua/conversion_state.h
tools/snort2lua/data/CMakeLists.txt
tools/snort2lua/data/cv_var.cc
tools/snort2lua/keyword_states/kws_config.cc
tools/snort2lua/keyword_states/kws_include.cc
tools/snort2lua/keyword_states/kws_preprocessor.cc
tools/snort2lua/keyword_states/kws_suppress.cc
tools/snort2lua/keyword_states/kws_var.cc
tools/snort2lua/preprocessor_states/CMakeLists.txt
tools/snort2lua/preprocessor_states/pps_bo.cc [new file with mode: 0644]
tools/snort2lua/preprocessor_states/pps_ftp_telnet.cc
tools/snort2lua/preprocessor_states/pps_ftp_telnet_protocol.cc [new file with mode: 0644]
tools/snort2lua/preprocessor_states/pps_http_inspect.cc
tools/snort2lua/preprocessor_states/pps_http_inspect_server.cc
tools/snort2lua/preprocessor_states/pps_sfportscan.cc
tools/snort2lua/preprocessor_states/preprocessor_api.cc
tools/snort2lua/snort2lua.cc
tools/snort2lua/snort2lua_util.cc
tools/snort2lua/snort2lua_util.h
tools/snort2lua/state_template.cc

index 6de08dc00a952fd67edf425bc75aaa228d46d909..2d0d72217eff266a41a6f6bfe41907a5a25f92f6 100644 (file)
@@ -18,7 +18,7 @@ add_executable(snort2lua
 )
 
 target_link_libraries( snort2lua
-    converrsion_data
+    conversion_data
     keyword_states
     output_states
     preprocessor_states
index 611805d6e1d35b713f502f8adc0584287d923a6e..87018489921c9645776d1ca51ab3de40872678ea 100644 (file)
@@ -39,17 +39,50 @@ public:
 protected:
     Converter* converter;
 
-    inline bool add_int_option(std::string keyword, std::stringstream& stream)
+    inline bool parse_int_option(std::string opt_name, std::stringstream& stream)
     {
         int val;
 
         if(stream >> val)
         {
-            converter->add_option_to_table(keyword, val);
+            converter->add_option_to_table(opt_name, val);
             return true;
         }
 
-        converter->add_comment_to_table("snort.conf missing argument for: " + keyword + " <int>");
+        converter->add_comment_to_table("snort.conf missing argument for: " + opt_name + " <int>");
+        return false;
+    }
+
+    // parse adn add a curly bracketed list to the table
+    inline bool parse_curly_bracket_list(std::string list_name, std::stringstream& stream)
+    {
+        std::string elem;
+        bool retval = true;
+
+        if(!(stream >> elem) || (elem != "{"))
+            return false;
+
+        while (stream >> elem && elem != "}")
+            retval = converter->add_list_to_table(list_name, elem) && retval;
+
+        return retval;
+    }
+
+    // parse and add a yes/no boolean option.
+    inline bool parse_yn_bool_option(std::string opt_name, std::stringstream& stream)
+    {
+        std::string val;
+
+        if(!(stream >> val))
+            return false;
+
+        else if(!val.compare("yes"))
+            return converter->add_option_to_table(opt_name, true);
+
+        else if (!val.compare("no"))
+            return converter->add_option_to_table(opt_name, false);
+
+        converter->add_comment_to_table("Unable to convert_option: " + opt_name + ' ' + val);
         return false;
     }
 
index 41137f19447f3ea47aa027b6539a7c5047e5134a..afc01b9d71383b06e10a9c060f582472f2b0b34d 100644 (file)
@@ -1,5 +1,5 @@
 
-add_library(converrsion_data
+add_library(conversion_data
     cv_data.h
     cv_data.cc
     cv_var.h
index 394da5defaa37ce954e831241cd6fa15829083f0..aa623602aafaa1fb7a4199d74f67f39b01239988 100644 (file)
@@ -20,7 +20,7 @@
 // cv_var.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include "data/cv_var.h"
-
+#include "snort2lua_util.h"
 
 #if 0
 static inline bool var_exists(std::vector<std::string> vec, std::string name)
@@ -84,45 +84,50 @@ std::ostream& operator<<( std::ostream& out, const Variable &var)
             out << std::endl << whitespace << "    ";
 
         length += v.size();
-        out << " " << v << " ..";
+        out << v << " .. ";
     }
 
     if (var.strs.size() == 0)
-        out << " ''";
+        out << "''";
+
+
 
     else if(var.count < var.max_line_length || var.strs.size() == 1)
     {
-        out << "'";
+        std::string tmp_str = "";
 
         for (auto s : var.strs)
         {
             if ( 0 < length && length + s.size() > var.max_line_length )
-                out << std::endl << whitespace << "    ";
+                tmp_str += "\n" + whitespace + "    ";
 
             length += s.size();
-            out << " " << s;
+            tmp_str += s + ' ';
         }
-        out << "'";
+        util::trim(tmp_str);
+        out << "'" << tmp_str << "'";
     }
     else
     {
-        out << std::endl <<  whitespace << "[[" << std::endl;
-        out << whitespace << "    ";
         length = 4 + whitespace.size();
+        std::string tmp_str = "";
 
         for (auto s : var.strs)
         {
             if ( 0 < length && length + s.size() > var.max_line_length )
             {
-                out << std::endl << whitespace << "    ";
+                tmp_str += "\n" + whitespace + "    ";
                 length = 4 + whitespace.size();
             }
 
             length += s.size();
-            out << " " << s;
+            tmp_str += s + " ";
         }
 
-        out << std::endl << whitespace << "]]";
+        util::trim(tmp_str);
+        out << std::endl <<  whitespace << "[[" << std::endl;
+        out << whitespace << "    " << tmp_str << std::endl;
+        out << whitespace << "]]";
     }
 
     return out;
index 7babe5ff0d71a0d35d9187bae82d476ca93a296e..9c1d5f6db927bfd1763ff67a5cad08fa5d2dffb6 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
index 5ddaf799fe84f76469f47bf6b1ecd99a34a7d379..8181eff03181442e77870853f522ba18eeb6728a 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
index 203bdf4755f1fb07c84a1f02f0d0c707bd516046..25d04a4af9075447522888dcf4c3f719d60e312b 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
index 043463fa0f87f9de022f0147ffeb0a2df7255d5f..420a51735118ae8929058a48d428ab25beabc133 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// suppress.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// kws_suppress.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
index 91f2941e9797ca83ea20dc70a6aeb89a95724659..17d9fdd2ad203f4bbf3e7bc7e108618bccd80cf0 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
index 0fa357db487ec7b35622efd165bbad1c2081b97e..5da40672310913bcdca1c89e178db14d9d6c0b60 100644 (file)
@@ -6,6 +6,9 @@ add_library(preprocessor_states
     pps_normalizers.cc
     pps_sfportscan.cc
     pps_ftp_telnet.cc
+    pps_ftp_telnet_protocol.cc
+    pps_bo.cc
     preprocessor_api.h
     preprocessor_api.cc
 )
+
diff --git a/tools/snort2lua/preprocessor_states/pps_bo.cc b/tools/snort2lua/preprocessor_states/pps_bo.cc
new file mode 100644 (file)
index 0000000..bbf5a77
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+** 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.
+ */
+// pps_bo.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+#include <iomanip>
+
+#include "conversion_state.h"
+#include "converter.h"
+#include "snort2lua_util.h"
+
+
+
+static ConversionState* bo_ctor(Converter* cv)
+{
+    cv->open_table("bo");
+    cv->close_table();
+    return nullptr;
+}
+
+static const ConvertMap preprocessor_bo = 
+{
+    "bo",
+    bo_ctor,
+};
+
+const ConvertMap* bo_map = &preprocessor_bo;
+
index f1c633522eb8f26f08a6a051f4cfc089f4b7338c..3ba1a98f9d9edc1865552bbb797d4af5a5f552bc 100644 (file)
  * 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>
+// pps_ftp_telnet.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
@@ -35,66 +34,81 @@ public:
     FtpTelnet(Converter* cv)  : ConversionState(cv) {};
     virtual ~FtpTelnet() {};
     virtual bool convert(std::stringstream& data_stream);
+private:
+    bool add_ftp_n_telnet_option(std::string opt_name, bool val);
+    void add_ftp_n_telnet_deprecated(std::string opt_name);
 };
 
 } // namespace
 
+bool FtpTelnet::add_ftp_n_telnet_option(std::string opt_name, bool val)
+{
+    bool retval;
+
+    converter->open_table("telnet");
+    retval = converter->add_option_to_table(opt_name, val);
+    converter->close_table();
+    converter->open_table("ftp_server");
+    retval = converter->add_option_to_table(opt_name, val) && retval;
+    converter->close_table();
+    return retval;
+}
+
+void FtpTelnet::add_ftp_n_telnet_deprecated(std::string opt_name)
+{
+    converter->open_table("telnet");
+    converter->add_deprecated_comment(opt_name);
+    converter->close_table();
+    converter->open_table("ftp_server");
+    converter->add_deprecated_comment(opt_name);
+    converter->close_table();
+}
 
 bool FtpTelnet::convert(std::stringstream& data_stream)
 {
-#if 0
-# FTP / Telnet normalization and anomaly detection.  For more information, see README.ftptelnet
-preprocessor ftp_telnet: global inspection_type stateful encrypted_traffic no check_encrypted
-preprocessor ftp_telnet_protocol: telnet \
-    ayt_attack_thresh 20 \
-    normalize ports { 23 } \
-    detect_anomalies
-preprocessor ftp_telnet_protocol: ftp server default \
-    def_max_param_len 100 \
-    ports { 21 2100 3535 } \
-    telnet_cmds yes \
-    ignore_telnet_erase_cmds yes \
-    ftp_cmds { ABOR ACCT ADAT ALLO APPE AUTH CCC CDUP } \
-    ftp_cmds { CEL CLNT CMD CONF CWD DELE ENC EPRT } \
-    ftp_cmds { EPSV ESTA ESTP FEAT HELP LANG LIST LPRT } \
-    ftp_cmds { LPSV MACB MAIL MDTM MIC MKD MLSD MLST } \
-    ftp_cmds { MODE NLST NOOP OPTS PASS PASV PBSZ PORT } \
-    ftp_cmds { PROT PWD QUIT REIN REST RETR RMD RNFR } \
-    ftp_cmds { RNTO SDUP SITE SIZE SMNT STAT STOR STOU } \
-    ftp_cmds { STRU SYST TEST TYPE USER XCUP XCRC XCWD } \
-    ftp_cmds { XMAS XMD5 XMKD XPWD XRCP XRMD XRSQ XSEM } \
-    ftp_cmds { XSEN XSHA1 XSHA256 } \
-    alt_max_param_len 0 { ABOR CCC CDUP ESTA FEAT LPSV NOOP PASV PWD QUIT REIN STOU SYST XCUP XPWD } \
-    alt_max_param_len 200 { ALLO APPE CMD HELP NLST RETR RNFR STOR STOU XMKD } \
-    alt_max_param_len 256 { CWD RNTO } \
-    alt_max_param_len 400 { PORT } \
-    alt_max_param_len 512 { SIZE } \
-    chk_str_fmt { ACCT ADAT ALLO APPE AUTH CEL CLNT CMD } \
-    chk_str_fmt { CONF CWD DELE ENC EPRT EPSV ESTP HELP } \
-    chk_str_fmt { LANG LIST LPRT MACB MAIL MDTM MIC MKD } \
-    chk_str_fmt { MLSD MLST MODE NLST OPTS PASS PBSZ PORT } \
-    chk_str_fmt { PROT REST RETR RMD RNFR RNTO SDUP SITE } \
-    chk_str_fmt { SIZE SMNT STAT STOR STRU TEST TYPE USER } \
-    chk_str_fmt { XCRC XCWD XMAS XMD5 XMKD XRCP XRMD XRSQ } \
-    chk_str_fmt { XSEM XSEN XSHA1 XSHA256 } \
-    cmd_validity ALLO < int [ char R int ] > \
-    cmd_validity EPSV < [ { char 12 | char A char L char L } ] > \
-    cmd_validity MACB < string > \
-    cmd_validity MDTM < [ date nnnnnnnnnnnnnn[.n[n[n]]] ] string > \
-    cmd_validity MODE < char ASBCZ > \
-    cmd_validity PORT < host_port > \
-    cmd_validity PROT < char CSEP > \
-    cmd_validity STRU < char FRPO [ string ] > \
-    cmd_validity TYPE < { char AE [ char NTC ] | char I | char L [ number ] } >
-preprocessor ftp_telnet_protocol: ftp client default \
-    max_resp_len 256 \
-    bounce yes \
-    ignore_telnet_erase_cmds yes \
-    telnet_cmds yes
-#endif
-
-    data_stream.setstate(std::basic_ios<char>::eofbit);
-    return true;    
+
+    std::string keyword;
+    std::string s_value;
+
+    // using this to keep track of any errors.  I want to convert as much 
+    // as possible while being aware something went wrong
+    bool retval = true;
+
+    if(data_stream >> keyword)
+    {
+        if(keyword.compare("global"))
+        {
+            converter->log_error("preprocessor ftp_telnet: requires the 'global' keyword");
+            return false;
+        }
+    }
+
+    while(data_stream >> keyword)
+    {
+        if(!keyword.compare("check_encrypted"))
+            retval = add_ftp_n_telnet_option("check_encrypted", true);
+
+        else if(!keyword.compare("inspection_type"))
+            add_ftp_n_telnet_deprecated("inspection_type");
+
+        else if(!keyword.compare("encrypted_traffic"))
+        {
+            data_stream >> s_value;
+
+            if(s_value.compare("yes"))
+                retval = add_ftp_n_telnet_option("encrypted_traffic", true) && retval;
+
+            else
+                retval = add_ftp_n_telnet_option("encrypted_traffic", false) && retval;
+            
+        }
+
+        else
+            retval = false;
+
+    }
+
+    return retval;    
 }
 
 /**************************
@@ -106,10 +120,10 @@ static ConversionState* ctor(Converter* cv)
     return new FtpTelnet(cv);
 }
 
-static const ConvertMap keyword_preprocessor = 
+static const ConvertMap preprocessor_ftptelnet = 
 {
     "ftp_telnet",
     ctor,
 };
 
-const ConvertMap* preprocessor_map = &keyword_preprocessor;
+const ConvertMap* ftptelnet_map = &preprocessor_ftptelnet;
diff --git a/tools/snort2lua/preprocessor_states/pps_ftp_telnet_protocol.cc b/tools/snort2lua/preprocessor_states/pps_ftp_telnet_protocol.cc
new file mode 100644 (file)
index 0000000..5ba4919
--- /dev/null
@@ -0,0 +1,372 @@
+/*
+** 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.
+ */
+// pps_ftp_telnet_protocol.cc author Josh Rosenbaum <jorosenba@cisco.com>
+
+#include <sstream>
+#include <vector>
+
+#include "conversion_state.h"
+#include "converter.h"
+#include "snort2lua_util.h"
+
+namespace {
+
+class FtpServer : public ConversionState
+{
+public:
+    FtpServer(Converter* cv);
+    virtual ~FtpServer() {};
+    virtual bool convert(std::stringstream& data_stream);
+private:
+    bool parse_alt_max_cmd(std::stringstream& data_stream);
+    bool parse_cmd_validity_cmd(std::stringstream& data_stream);
+    static int ftpsever_binding_id;
+};
+
+class FtpClient : public ConversionState
+{
+public:
+    FtpClient(Converter* cv) : ConversionState(cv) {};
+    virtual ~FtpClient() {};
+    virtual bool convert(std::stringstream& data_stream);
+private:
+    static int ftpclient_binding_id;
+};
+
+class Telnet : public ConversionState
+{
+public:
+    Telnet(Converter* cv)  : ConversionState(cv) {};
+    virtual ~Telnet() {};
+    virtual bool convert(std::stringstream& data_stream);
+};
+
+class FtpTelnetProtocol : public ConversionState
+{
+public:
+    FtpTelnetProtocol(Converter* cv)  : ConversionState(cv) {};
+    virtual ~FtpTelnetProtocol() {};
+    virtual bool convert(std::stringstream& data_stream);
+};
+
+} // namespace
+
+
+/****************************************
+ *******  FtpServer Protocol  ***********
+ ****************************************/
+
+int FtpServer::ftpsever_binding_id = 1;
+
+
+FtpServer::FtpServer(Converter* cv)  : ConversionState(cv)
+{}
+
+bool FtpServer::parse_alt_max_cmd(std::stringstream& data_stream)
+{
+    int i_val;
+    bool tmpval;
+
+    if(!(data_stream >> i_val))
+        return false;
+
+    converter->open_table("alt_max_param");
+    converter->open_table();
+    converter->add_option_to_table("length", i_val);
+    tmpval = parse_curly_bracket_list("commands", data_stream);
+    converter->close_table();
+    converter->close_table();
+    return tmpval;
+}
+
+bool FtpServer::parse_cmd_validity_cmd(std::stringstream& data_stream)
+{
+    std::string val;
+    std::string elem;
+    bool tmpval;
+
+    if(!(data_stream >> val))
+        return false;
+
+    if(!(data_stream >> elem) || (elem != "<"))
+        return false;
+
+
+    converter->open_table("cmd_validity");
+    converter->open_table();
+    tmpval = converter->add_option_to_table("command", val);
+    tmpval = converter->add_list_to_table("format", elem) && tmpval;
+
+    while((data_stream >> elem) && (elem != ">"))
+        tmpval = converter->add_list_to_table("format", elem) && tmpval;
+
+    converter->add_list_to_table("format", elem);
+    converter->close_table(); // anonymouse table
+    converter->close_table(); // "cmd_validity" table
+    return tmpval;
+}
+
+bool FtpServer::convert(std::stringstream& data_stream)
+{
+    std::string keyword;
+    bool retval = true;
+
+    if (data_stream >> keyword)
+    {
+        if(!keyword.compare("default"))
+            converter->open_table("ftp_server");
+        else
+        {
+            converter->open_table("ftp_server_target_" + std::to_string(ftpsever_binding_id));
+            ftpsever_binding_id++;
+            converter->add_comment_to_table("Unable to create target based ftp configuration at this time!!!");
+            retval = false;
+        }
+    }
+    else
+    {
+        return false;
+    }
+
+    while(data_stream >> keyword)
+    {
+        bool tmpval = true;
+
+
+        if(!keyword.compare("print_cmds"))
+            converter->add_option_to_table("print_cmds", true);
+
+        else if(!keyword.compare("def_max_param_len"))
+            tmpval = parse_int_option("def_max_param_len", data_stream);
+
+        else if(!keyword.compare("telnet_cmds"))
+            tmpval = parse_yn_bool_option("telnet_cmds", data_stream);
+        
+        else if(!keyword.compare("ignore_telnet_erase_cmds"))
+            tmpval = parse_yn_bool_option("ignore_telnet_erase_cmds", data_stream);
+
+        else if(!keyword.compare("ignore_data_chan"))
+            tmpval = parse_yn_bool_option("ignore_data_chan", data_stream);
+
+        else if(!keyword.compare("ftp_cmds"))
+            tmpval = parse_curly_bracket_list("ftp_cmds", data_stream);
+
+        else if(!keyword.compare("chk_str_fmt"))
+            tmpval = parse_curly_bracket_list("chk_str_fmt", data_stream);
+
+        else if(!keyword.compare("alt_max_param_len"))
+            tmpval = parse_alt_max_cmd(data_stream);
+
+        else if(!keyword.compare("cmd_validity"))
+            tmpval = parse_cmd_validity_cmd(data_stream);
+        
+        else if(!keyword.compare("data_chan"))
+        {
+            converter->add_deprecated_comment("data_chan", "ignore_data_chan");
+            tmpval = converter->add_option_to_table("ignore_data_chan", true);
+        }
+
+        else if (!keyword.compare("ports"))
+        {
+            converter->add_deprecated_comment("ports", "bindings");
+            converter->add_comment_to_table("check bindings table for port information");
+            // add commented list for now
+            std::string tmp = "";
+            while (data_stream >> keyword && keyword != "}")
+                tmp += " " + keyword;
+            tmpval = converter->add_option_to_table("--ports", tmp + "}");
+        }
+
+        else
+        {
+            tmpval = false;
+        }
+
+        retval = retval && tmpval;
+    }
+    return retval;
+}
+
+/****************************************
+ *******  FtpClient Protocol  ***********
+ ****************************************/
+
+int FtpClient::ftpclient_binding_id = 1;
+
+bool FtpClient::convert(std::stringstream& data_stream)
+{
+    std::string keyword;
+    bool retval = true;
+
+    if (data_stream >> keyword)
+    {
+        if(!keyword.compare("default"))
+            converter->open_table("ftp_client");
+        else
+        {
+            converter->open_table("ftp_client_target_" + std::to_string(ftpclient_binding_id));
+            ftpclient_binding_id++;
+            converter->add_comment_to_table("Unable to create target based ftp configuration at this time!!!");
+            retval = false;
+        }
+    }
+    else
+    {
+        return false;
+    }
+
+    while(data_stream >> keyword)
+    {
+        bool tmpval = true;
+
+
+        if(!keyword.compare("telnet_cmds"))
+            tmpval = parse_yn_bool_option("telnet_cmds", data_stream);
+
+        else if(!keyword.compare("ignore_telnet_erase_cmds"))
+            tmpval = parse_yn_bool_option("ignore_telnet_erase_cmds", data_stream);
+
+        else if(!keyword.compare("max_resp_len"))
+            tmpval = parse_int_option("max_resp_len", data_stream);
+
+        else if(!keyword.compare("bounce"))
+            tmpval = parse_yn_bool_option("bounce", data_stream);
+
+        // add bounce_to as a commented list
+        else if(!keyword.compare("bounce_to"))
+        {
+            std::string tmp = "";
+            while (data_stream >> keyword && keyword != "}")
+                tmp += " " + keyword;
+            tmpval = converter->add_option_to_table("--bounce_to", tmp + "}");
+        }
+
+        else
+        {
+            tmpval = false;
+        }
+
+        retval = retval && tmpval;
+    }
+
+
+    return retval;
+}
+
+/****************************************
+ *********  Telnet Protocol  ************
+ ****************************************/
+
+bool Telnet::convert(std::stringstream& data_stream)
+{
+    std::string keyword;
+    int i_val;
+    bool retval = true;
+
+    converter->open_table("telnet");
+
+    while(data_stream >> keyword)
+    {
+        bool tmpval;
+        if(!keyword.compare("ayt_attack_thresh"))
+        {
+            if(data_stream >> i_val)
+                tmpval = converter->add_option_to_table("ayt_attack_thresh", i_val);
+            else
+                tmpval = false;
+        }
+
+        else  if(!keyword.compare("normalize"))
+            tmpval = converter->add_option_to_table("normalize", true);
+
+        else  if(!keyword.compare("ports"))
+        {
+            converter->add_deprecated_comment("ports", "bindings");
+            converter->add_comment_to_table("check bindings table for port information");
+            // vvvv defined in ConversionState vvvv
+            parse_curly_bracket_list("--ports", data_stream); // create a commented list of the ports
+        }
+
+        else  if(!keyword.compare("detect_anomalies"))
+            tmpval = converter->add_option_to_table("detect_anomalies", true);
+
+        else
+            tmpval = false;
+
+        retval = tmpval && retval;
+    }
+
+
+    converter->close_table(); // not necessary but 
+    return retval;
+}
+
+/****************************************
+ *******  FtpTelnetProtocol  ************
+ ****************************************/
+
+
+bool FtpTelnetProtocol::convert(std::stringstream& data_stream)
+{
+    std::string protocol;
+
+    if(data_stream >> protocol)
+    {
+        if(!protocol.compare("telnet"))
+        {
+            converter->set_state(new Telnet(converter));
+        }
+        else if (!protocol.compare("ftp"))
+        {
+            if(data_stream >> protocol)
+            {
+                if(!protocol.compare("client"))
+                    converter->set_state(new FtpClient(converter));
+
+                else if (!protocol.compare("server"))
+                    converter->set_state(new FtpServer(converter));
+
+                else
+                    return false;
+            }
+        }
+        else
+            return false;
+
+        return true;
+    }
+
+    return false;
+}
+
+/*******  PUBLIC API ************/
+
+static ConversionState* ctor(Converter* cv)
+{
+    return new FtpTelnetProtocol(cv);
+}
+
+static const ConvertMap ftptelnet_protocol_preprocessor = 
+{
+    "ftp_telnet_protocol",
+    ctor,
+};
+
+const ConvertMap* ftptelnet_protocol_map = &ftptelnet_protocol_preprocessor;
index a928eeb640c19f768e8087f4db2378b70540f83d..5ab10bc0546fc78f8a3d693dc402b89386656a71 100644 (file)
@@ -78,10 +78,10 @@ bool HttpInspect::convert(std::stringstream& data_stream)
     while(data_stream >> keyword)
     {
         if(!keyword.compare("compress_depth"))
-            retval = add_int_option("compress_depth", data_stream) && retval;
+            retval = parse_int_option("compress_depth", data_stream) && retval;
 
         else if(!keyword.compare("decompress_depth")) 
-            retval = add_int_option("decompress_depth", data_stream) && retval;
+            retval = parse_int_option("decompress_depth", data_stream) && retval;
 
         else if(!keyword.compare("detect_anomalous_servers"))
             converter->add_option_to_table("detect_anomalous_servers", true);
@@ -90,10 +90,10 @@ bool HttpInspect::convert(std::stringstream& data_stream)
             converter->add_option_to_table("proxy_alert", true);
 
         else if(!keyword.compare("max_gzip_mem"))
-            retval = add_int_option("max_gzip_mem", data_stream) && retval;
+            retval = parse_int_option("max_gzip_mem", data_stream) && retval;
         
         else if(!keyword.compare("memcap"))
-            retval = add_int_option("memcap", data_stream) && retval;
+            retval = parse_int_option("memcap", data_stream) && retval;
         
         else if(!keyword.compare("disabled"))
             converter->add_comment_to_table("'disabled' is deprecated");
index b034406ab9bf8934da0b586e293b44ee8841f7cd..c2af23f56d074491a69d0a2e71f899b4adbb8b38 100644 (file)
  * 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>
+// pps_http_inspect_server.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
index 4ca07758c8283f2a59b514bf42215cb53a7decf8..a8cf3eaaabdad073b15f192c1156b9c37d4aa4c5 100644 (file)
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-// portscan.cc author Josh Rosenbaum <jorosenba@cisco.com>
+// pps_sfportscan.cc author Josh Rosenbaum <jorosenba@cisco.com>
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"
@@ -131,13 +130,15 @@ bool PortScan::convert(std::stringstream& data_stream)
         if(!keyword.compare("proto"))
         {
             converter->add_deprecated_comment("proto", "protos");
-            retval = parse_list("protos", data_stream) && retval;
+            // defined in ConversionState vvvv
+            retval = parse_curly_bracket_list("protos", data_stream) && retval;
         }
 
         if(!keyword.compare("scan_type"))
         {
             converter->add_deprecated_comment("scan_type", "scan_types");
-            retval = parse_list("scan_types", data_stream) && retval;
+            // defined in ConversionState vvvv
+            retval = parse_curly_bracket_list("scan_types", data_stream) && retval;
         }
         else if(!keyword.compare("sense_level"))
             retval = parse_option("sense_level", data_stream) && retval;
index 78ea8c46a15a330e6b4eba500fe8096a4763ec2e..9db516654d0a1f833ea952fd59323b0999af0035 100644 (file)
@@ -24,6 +24,9 @@
 
 extern const ConvertMap *arpspoof_map;
 extern const ConvertMap *arpspoof_host_map;
+extern const ConvertMap *bo_map;
+extern const ConvertMap *ftptelnet_map;
+extern const ConvertMap *ftptelnet_protocol_map;
 extern const ConvertMap *httpinspect_map;
 extern const ConvertMap *normalizer_icmp4_map;
 extern const ConvertMap *normalizer_icmp6_map;
@@ -37,7 +40,10 @@ const std::vector<const ConvertMap*> preprocessor_api =
 {
     arpspoof_map,
     arpspoof_host_map,
+    bo_map,
+    ftptelnet_map,
     httpinspect_map,
+    ftptelnet_protocol_map,
     normalizer_icmp4_map,
     normalizer_icmp6_map,
     normalizer_ip4_map,
index 5eb76b5776becebd760834c53db9913e9d093900..c7279c041be695c294a8f2f6c6b5ce1dd55d9b79 100644 (file)
@@ -82,7 +82,7 @@ static bool convert(std::ifstream& in, std::ofstream& out)
 
 static void show_usage()
 {
-    std::cout << "usage:  snort2lua <input_conf_file> <output_lua_file" << std::endl;
+    std::cout << "usage:  snort2lua <input_conf_file> <output_lua_file>" << std::endl;
 }
 
 int main (int argc, char* argv[])
index 80242344448d7e476d134bb09c0675de99514b22..b441c8483a690016c3fbbfaf1611fa748d974d12 100644 (file)
@@ -31,22 +31,6 @@ namespace util
 {
 
 
-// trim from start
-std::string &ltrim(std::string &s) {
-        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
-        return s;
-}
-
-// trim from end
-std::string &rtrim(std::string &s) {
-        s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
-        return s;
-}
-
-// trim from both ends
-std::string &trim(std::string &s) {
-        return ltrim(rtrim(s));
-}
 
 
 std::vector<std::string> &split(const std::string &s, 
index bcefae1cfecbb34e2e5f2a6582ff14bdd54601e7..85a199bf9ec4934bea44992544e979329c86a68d 100644 (file)
 
 #include <string>
 #include <vector>
+#include <algorithm> 
+#include <functional> 
+#include <cctype>
+#include <locale>
 
 struct ConvertMap;
 
@@ -40,6 +44,25 @@ std::string &ltrim(std::string &s);
 std::string &rtrim(std::string &s);
 // trim from both ends
 std::string &trim(std::string &s);
+
+
+// trim from start
+inline std::string &ltrim(std::string &s) {
+        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
+        return s;
+}
+
+// trim from end
+inline std::string &rtrim(std::string &s) {
+        s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
+        return s;
+}
+
+// trim from both ends
+inline std::string &trim(std::string &s) {
+        return ltrim(rtrim(s));
+}
+
 } // namespace util
 
 #endif
index 715f3b54d98464d213531d1015d4b589b084b437..a795624f8f075b694671506942c701bcaabd217d 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sstream>
 #include <vector>
-#include <iomanip>
 
 #include "conversion_state.h"
 #include "converter.h"