From: Josh Date: Thu, 19 Jun 2014 17:30:49 +0000 (-0400) Subject: finishing stream_tcp conversion. Adding basic 'config' option support X-Git-Tag: 3.0.0-233~1476^2~1^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e2f96bbe803f33146431ab6f4df13684d0a5edbc;p=thirdparty%2Fsnort3.git finishing stream_tcp conversion. Adding basic 'config' option support --- diff --git a/tools/snort2lua/CMakeLists.txt b/tools/snort2lua/CMakeLists.txt index fe516ff23..f9d1d4969 100644 --- a/tools/snort2lua/CMakeLists.txt +++ b/tools/snort2lua/CMakeLists.txt @@ -6,6 +6,7 @@ add_subdirectory(data) add_subdirectory(keyword_states) add_subdirectory(preprocessor_states) add_subdirectory(output_states) +add_subdirectory(config_states) add_executable(snort2lua snort2lua.cc diff --git a/tools/snort2lua/config_states/CMakeLists.txt b/tools/snort2lua/config_states/CMakeLists.txt new file mode 100644 index 000000000..807603d6b --- /dev/null +++ b/tools/snort2lua/config_states/CMakeLists.txt @@ -0,0 +1,7 @@ + + +add_library( config_states + config_options.cc + config_api.h + config_api.cc +) diff --git a/tools/snort2lua/config_states/config_api.cc b/tools/snort2lua/config_states/config_api.cc new file mode 100644 index 000000000..c06eb65db --- /dev/null +++ b/tools/snort2lua/config_states/config_api.cc @@ -0,0 +1,33 @@ +/* +** 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. + */ +// config_api.cc author Josh Rosenbaum + +#include "config_states/config_api.h" + + +extern const ConvertMap *autogenerate_decode_rules_map; +extern const ConvertMap *paf_max_map; + + +const std::vector config_api = +{ + autogenerate_decode_rules_map, + paf_max_map, +}; diff --git a/tools/snort2lua/config_states/config_api.h b/tools/snort2lua/config_states/config_api.h new file mode 100644 index 000000000..6fd0c59e5 --- /dev/null +++ b/tools/snort2lua/config_states/config_api.h @@ -0,0 +1,30 @@ +/* +** 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. + */ +// config_api.h author Josh Rosenbaum + +#ifndef CONFIG_API_H +#define CONFIG_API_H + +#include +#include "../conversion_state.h" + +extern const std::vector config_api; + +#endif diff --git a/tools/snort2lua/config_states/config_options.cc b/tools/snort2lua/config_states/config_options.cc new file mode 100644 index 000000000..63a91457e --- /dev/null +++ b/tools/snort2lua/config_states/config_options.cc @@ -0,0 +1,100 @@ +/* +** 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. + */ +// config_options.cc author Josh Rosenbaum + +#include +#include + +#include "conversion_state.h" +#include "converter.h" +#include "snort2lua_util.h" + + + +static inline bool open_table_add_option(Converter* cv, + std::string table_name, + std::string opt_name, + bool val) +{ + bool tmpval = cv->open_table(table_name); + tmpval = cv->add_option_to_table(opt_name, val) && tmpval; + cv->close_table(); + return tmpval; +} + +/********************************************* + ************ config paf_max **************** + *********************************************/ + +namespace { + +class PafMax : public ConversionState +{ +public: + PafMax(Converter* cv) : ConversionState(cv) {}; + virtual ~PafMax() {}; + virtual bool convert(std::stringstream& data_stream); +}; + +} // namespace + + +bool PafMax::convert(std::stringstream& data_stream) +{ + converter->open_table("stream_tcp"); + bool retval = parse_int_option("paf_max", data_stream); + converter->close_table(); + return retval; +} + +/******* A P I ***********/ + +static ConversionState* paf_max_ctor(Converter* cv) +{ + return new PafMax(cv); +} + +static const ConvertMap config_paf_max = +{ + "paf_max", + paf_max_ctor, +}; + + +const ConvertMap* paf_max_map = &config_paf_max; + + +/********************************************* + ******* Autogenerate Decoder Rules ********* + *********************************************/ + +static ConversionState* autogenerate_preprocessor_decoder_rules_ctor(Converter* cv) +{ + open_table_add_option(cv, "ips", "enable_builtin_rules", true); + return nullptr; +} + +static const ConvertMap config_autogenerate_decode_rules = +{ + "autogenerate_preprocessor_decoder_rules", + autogenerate_preprocessor_decoder_rules_ctor, +}; + +const ConvertMap* autogenerate_decode_rules_map = &config_autogenerate_decode_rules; diff --git a/tools/snort2lua/conversion_state.h b/tools/snort2lua/conversion_state.h index ebff711f7..0d12de0fb 100644 --- a/tools/snort2lua/conversion_state.h +++ b/tools/snort2lua/conversion_state.h @@ -161,7 +161,7 @@ protected: return converter->add_option_to_table("--" + list_name, tmp ); } - inline bool pen_table_add_option(std::string table_name, std::string opt_name, std::string val) + inline bool open_table_add_option(std::string table_name, std::string opt_name, std::string val) { bool tmpval = converter->open_table(table_name); tmpval = converter->add_option_to_table(opt_name, val) && tmpval; diff --git a/tools/snort2lua/keyword_states/CMakeLists.txt b/tools/snort2lua/keyword_states/CMakeLists.txt index 7b32236a4..1347f9038 100644 --- a/tools/snort2lua/keyword_states/CMakeLists.txt +++ b/tools/snort2lua/keyword_states/CMakeLists.txt @@ -13,4 +13,5 @@ add_library( keyword_states target_link_libraries( keyword_states output_states preprocessor_states + config_states ) \ No newline at end of file diff --git a/tools/snort2lua/keyword_states/kws_config.cc b/tools/snort2lua/keyword_states/kws_config.cc index 4d95e6f43..a1e6fcbfd 100644 --- a/tools/snort2lua/keyword_states/kws_config.cc +++ b/tools/snort2lua/keyword_states/kws_config.cc @@ -17,13 +17,14 @@ * 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 +// kws_config.cc author Josh Rosenbaum #include #include #include "conversion_state.h" #include "converter.h" +#include "config_states/config_api.h" #include "snort2lua_util.h" @@ -42,12 +43,15 @@ public: bool Config::convert(std::stringstream& data_stream) { -#if 0 std::string keyword; - if(data >> keyword) + if(data_stream >> keyword) { - const ConvertMap* map = util::find_map(output_api, keyword); + + if(keyword.back() == ':') + keyword.pop_back(); + + const ConvertMap* map = util::find_map(config_api, keyword); if (map) { converter->set_state(map->ctor(converter)); @@ -55,9 +59,6 @@ bool Config::convert(std::stringstream& data_stream) } } - return false; -#endif - return false; } diff --git a/tools/snort2lua/keyword_states/kws_suppress.cc b/tools/snort2lua/keyword_states/kws_suppress.cc index eda365699..5608c00cd 100644 --- a/tools/snort2lua/keyword_states/kws_suppress.cc +++ b/tools/snort2lua/keyword_states/kws_suppress.cc @@ -46,6 +46,8 @@ bool Suppress::convert(std::stringstream& data_stream) std::string keyword; converter->open_table("suppress"); + converter->add_deprecated_comment("gen_id", "gid"); + converter->add_deprecated_comment("sig_id", "sid"); converter->open_table(); while(data_stream >> keyword) @@ -65,16 +67,13 @@ bool Suppress::convert(std::stringstream& data_stream) tmpval = parse_string_option("ip", data_stream); else if(!keyword.compare("gen_id")) - { - converter->add_deprecated_comment("gen_id", "gid"); tmpval = parse_int_option("gid", data_stream); - } else if (!keyword.compare("sig_id")) - { - converter->add_deprecated_comment("sig_id", "sid"); tmpval = parse_int_option("sid", data_stream); - } + + else + tmpval = false; if (retval) retval = tmpval; diff --git a/tools/snort2lua/preprocessor_states/pps_stream_tcp.cc b/tools/snort2lua/preprocessor_states/pps_stream_tcp.cc index c52861771..974b74155 100644 --- a/tools/snort2lua/preprocessor_states/pps_stream_tcp.cc +++ b/tools/snort2lua/preprocessor_states/pps_stream_tcp.cc @@ -185,6 +185,13 @@ bool StreamTcp::convert(std::stringstream& data_stream) else if(!keyword.compare("check_session_hijacking")) converter->add_deprecated_comment("check_session_hijacking"); + else if(!keyword.compare("bind_to")) + { + converter->add_deprecated_comment("bind_to", "bindings"); + if(!(data_stream >> keyword)) + tmpval = false; + } + else if(!keyword.compare("dont_reassemble_async")) { converter->add_deprecated_comment("dont_reassemble_async", "reassemble_async"); @@ -228,13 +235,6 @@ bool StreamTcp::convert(std::stringstream& data_stream) return retval; } -#if 0 - -# bind_to - IP address for this policy. The default is set - - ports [all|space separated port list] -] -#endif /************************** ******* A P I ***********