From 5a2a81a56863234dda4e5d695ff36dd8895b5d1d Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 10 Feb 2016 12:53:22 -0300 Subject: [PATCH] Adds support to the action `ver' --- src/Makefile.am | 3 ++- src/actions/ver.cc | 46 ++++++++++++++++++++++++++++++++++++ src/actions/ver.h | 44 ++++++++++++++++++++++++++++++++++ src/parser/seclang-parser.yy | 4 +++- 4 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/actions/ver.cc create mode 100644 src/actions/ver.h diff --git a/src/Makefile.am b/src/Makefile.am index 53535bf3..717eea4f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -117,7 +117,8 @@ ACTIONS = \ actions/transformations/url_decode.cc \ actions/transformations/url_decode_uni.cc \ actions/transformations/url_encode.cc \ - actions/transformations/utf8_to_unicode.cc + actions/transformations/utf8_to_unicode.cc \ + actions/ver.cc OPERATORS = \ diff --git a/src/actions/ver.cc b/src/actions/ver.cc new file mode 100644 index 00000000..9e396eaf --- /dev/null +++ b/src/actions/ver.cc @@ -0,0 +1,46 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + +#include "actions/ver.h" + +#include +#include + +#include "actions/action.h" +#include "modsecurity/transaction.h" +#include "src/utils.h" +#include "modsecurity/rule.h" +#include "src/macro_expansion.h" + +namespace modsecurity { +namespace actions { + +Ver::Ver(std::string action) + : Action(action, ConfigurationKind), + m_ver(action) { + if (m_ver.at(0) == '\'') { + m_ver.erase(0, 1); + m_ver.pop_back(); + } +} + + +bool Ver::evaluate(Rule *rule, Transaction *transaction) { + rule->m_ver = m_ver; + return true; +} + +} // namespace actions +} // namespace modsecurity diff --git a/src/actions/ver.h b/src/actions/ver.h new file mode 100644 index 00000000..f79bc875 --- /dev/null +++ b/src/actions/ver.h @@ -0,0 +1,44 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + +#include + +#include "actions/action.h" + +#ifndef SRC_ACTIONS_VER_H_ +#define SRC_ACTIONS_VER_H_ + +class Transaction; + +namespace modsecurity { +class Transaction; +namespace actions { + + +class Ver : public Action { + public: + explicit Ver(std::string action); + + bool evaluate(Rule *rule, Transaction *transaction) override; + + private: + std::string m_ver; +}; + + +} // namespace actions +} // namespace modsecurity + +#endif // SRC_ACTIONS_VER_H_ diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index 508dbb1f..8349e843 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -31,6 +31,7 @@ class Driver; #include "actions/log_data.h" #include "actions/redirect.h" #include "actions/rev.h" +#include "actions/ver.h" #include "actions/tag.h" #include "actions/transformations/transformation.h" #include "actions/transformations/none.h" @@ -67,6 +68,7 @@ using modsecurity::actions::Severity; using modsecurity::actions::Tag; using modsecurity::actions::Redirect; using modsecurity::actions::Rev; +using modsecurity::actions::Ver; using modsecurity::actions::Msg; using modsecurity::actions::Phase; using modsecurity::actions::transformations::None; @@ -987,7 +989,7 @@ act: } | ACTION_VER { - $$ = Action::instantiate($1); + $$ = new Ver($1); } | ACTION_MATURITY {