From 8143f8ea894c1e58e4fc4cd9a5cf96acf079d96c Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 10 Feb 2016 13:55:12 -0300 Subject: [PATCH] Adds support to the action `maturity' --- headers/modsecurity/rule.h | 5 ++-- src/Makefile.am | 1 + src/actions/maturity.cc | 47 ++++++++++++++++++++++++++++++++++++ src/actions/maturity.h | 45 ++++++++++++++++++++++++++++++++++ src/parser/seclang-parser.yy | 4 ++- src/rule.cc | 1 + 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 src/actions/maturity.cc create mode 100644 src/actions/maturity.h diff --git a/headers/modsecurity/rule.h b/headers/modsecurity/rule.h index 5af5d2e2..db5520e8 100644 --- a/headers/modsecurity/rule.h +++ b/headers/modsecurity/rule.h @@ -81,6 +81,7 @@ class Rule { std::string m_log_message; std::string m_log_data; int m_accuracy; + int m_maturity; private: bool m_unconditional; @@ -99,7 +100,7 @@ class RuleMessage { m_data = std::string(""); m_severity = 0; m_ver = rule->m_ver; - m_maturity = 0; + m_maturity = rule->m_maturity; m_rule = rule; }; RuleMessage(Rule *rule, std::string message) { @@ -112,7 +113,7 @@ class RuleMessage { m_data = std::string(""); m_severity = 0; m_ver = rule->m_ver; - m_maturity = 0; + m_maturity = rule->m_maturity; m_rule = rule; }; diff --git a/src/Makefile.am b/src/Makefile.am index 9150417f..e1fe878b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -72,6 +72,7 @@ ACTIONS = \ actions/init_col.cc \ actions/deny.cc \ actions/log_data.cc \ + actions/maturity.cc \ actions/msg.cc \ actions/no_audit_log.cc \ actions/pass.cc \ diff --git a/src/actions/maturity.cc b/src/actions/maturity.cc new file mode 100644 index 00000000..be5a43a5 --- /dev/null +++ b/src/actions/maturity.cc @@ -0,0 +1,47 @@ +/* + * 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/maturity.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 { + +Maturity::Maturity(std::string action) + : Action(action, ConfigurationKind), + m_maturity_str(action) { + if (m_maturity_str.at(0) == '\'') { + m_maturity_str.erase(0, 1); + m_maturity_str.pop_back(); + } + m_maturity = std::stoi(m_maturity_str); +} + + +bool Maturity::evaluate(Rule *rule, Transaction *transaction) { + rule->m_maturity = m_maturity; + return true; +} + +} // namespace actions +} // namespace modsecurity diff --git a/src/actions/maturity.h b/src/actions/maturity.h new file mode 100644 index 00000000..5fb1c266 --- /dev/null +++ b/src/actions/maturity.h @@ -0,0 +1,45 @@ +/* + * 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_MATURITY_H_ +#define SRC_ACTIONS_MATURITY_H_ + +class Transaction; + +namespace modsecurity { +class Transaction; +namespace actions { + + +class Maturity : public Action { + public: + explicit Maturity(std::string action); + + bool evaluate(Rule *rule, Transaction *transaction) override; + + private: + std::string m_maturity_str; + int m_maturity; +}; + + +} // namespace actions +} // namespace modsecurity + +#endif // SRC_ACTIONS_MATURITY_H_ diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index 57c1d505..9f4a4f06 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -30,6 +30,7 @@ class Driver; #include "actions/msg.h" #include "actions/phase.h" #include "actions/log_data.h" +#include "actions/maturity.h" #include "actions/redirect.h" #include "actions/rev.h" #include "actions/ver.h" @@ -75,6 +76,7 @@ using modsecurity::actions::Msg; using modsecurity::actions::Phase; using modsecurity::actions::transformations::None; using modsecurity::actions::LogData; +using modsecurity::actions::Maturity; using modsecurity::actions::transformations::Transformation; using modsecurity::operators::Operator; using modsecurity::Rule; @@ -995,7 +997,7 @@ act: } | ACTION_MATURITY { - $$ = Action::instantiate($1); + $$ = new Maturity($1); } | ACTION_CTL_BDY_XML { diff --git a/src/rule.cc b/src/rule.cc index 42fb4fa3..b914fe27 100644 --- a/src/rule.cc +++ b/src/rule.cc @@ -83,6 +83,7 @@ Rule::Rule(std::string marker) m_unconditional(false), m_secmarker(true), m_marker(marker), + m_maturity(0), m_referenceCount(0), m_fileName(""), m_lineNumber(0) { }