Adds support to setenv action

Issue #1044
This commit is contained in:
Felipe Zimmerle
2018-09-25 10:18:43 -03:00
parent 4dd2812757
commit bc3d3f1915
12 changed files with 5137 additions and 5434 deletions

View File

@@ -136,6 +136,7 @@ ACTIONS = \
actions/rev.cc \
actions/rule_id.cc \
actions/severity.cc \
actions/set_env.cc \
actions/set_rsc.cc \
actions/set_sid.cc \
actions/set_uid.cc \

48
src/actions/set_env.cc Normal file
View File

@@ -0,0 +1,48 @@
/*
* 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 "src/actions/set_env.h"
#include <iostream>
#include <string>
#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
#include "src/utils/string.h"
namespace modsecurity {
namespace actions {
bool SetENV::init(std::string *error) {
return true;
}
bool SetENV::evaluate(Rule *rule, Transaction *t) {
std::string colNameExpanded(m_string->evaluate(t));
#ifndef NO_LOGS
t->debug(8, "Setting envoriment variable: "
+ colNameExpanded + ".");
#endif
putenv((char *)colNameExpanded.c_str());
return true;
}
} // namespace actions
} // namespace modsecurity

53
src/actions/set_env.h Normal file
View File

@@ -0,0 +1,53 @@
/*
* 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 <string>
#include <utility>
#include <memory>
#include "modsecurity/actions/action.h"
#include "src/run_time_string.h"
#ifndef SRC_ACTIONS_SET_ENV_H_
#define SRC_ACTIONS_SET_ENV_H_
class Transaction;
namespace modsecurity {
class Transaction;
namespace actions {
class SetENV : public Action {
public:
explicit SetENV(std::string _action)
: Action(_action) { }
explicit SetENV(std::unique_ptr<RunTimeString> z)
: Action("setenv", RunTimeOnlyIfMatchKind),
m_string(std::move(z)) { }
bool evaluate(Rule *rule, Transaction *transaction) override;
bool init(std::string *error) override;
private:
std::unique_ptr<RunTimeString> m_string;
};
} // namespace actions
} // namespace modsecurity
#endif // SRC_ACTIONS_SET_ENV_H_

File diff suppressed because it is too large Load Diff

View File

@@ -85,6 +85,7 @@ class Driver;
#include "src/actions/phase.h"
#include "src/actions/rev.h"
#include "src/actions/rule_id.h"
#include "src/actions/set_env.h"
#include "src/actions/set_rsc.h"
#include "src/actions/set_sid.h"
#include "src/actions/set_uid.h"
@@ -380,7 +381,7 @@ using modsecurity::operators::Operator;
#line 384 "seclang-parser.hh" // lalr1.cc:379
#line 385 "seclang-parser.hh" // lalr1.cc:379
# include <cassert>
# include <cstdlib> // std::abort
@@ -457,7 +458,7 @@ using modsecurity::operators::Operator;
namespace yy {
#line 461 "seclang-parser.hh" // lalr1.cc:379
#line 462 "seclang-parser.hh" // lalr1.cc:379
@@ -2875,7 +2876,7 @@ namespace yy {
enum
{
yyeof_ = 0,
yylast_ = 3320, ///< Last index in yytable_.
yylast_ = 3321, ///< Last index in yytable_.
yynnts_ = 16, ///< Number of nonterminal symbols.
yyfinal_ = 336, ///< Termination state number.
yyterror_ = 1,
@@ -6139,7 +6140,7 @@ namespace yy {
} // yy
#line 6143 "seclang-parser.hh" // lalr1.cc:379
#line 6144 "seclang-parser.hh" // lalr1.cc:379

View File

@@ -51,6 +51,7 @@ class Driver;
#include "src/actions/phase.h"
#include "src/actions/rev.h"
#include "src/actions/rule_id.h"
#include "src/actions/set_env.h"
#include "src/actions/set_rsc.h"
#include "src/actions/set_sid.h"
#include "src/actions/set_uid.h"
@@ -2749,9 +2750,9 @@ act:
{
ACTION_NOT_SUPPORTED("SanitiseResponseHeader", @0);
}
| ACTION_SETENV
| ACTION_SETENV run_time_string
{
ACTION_NOT_SUPPORTED("SetEnv", @0);
ACTION_CONTAINER($$, new actions::SetENV(std::move($2)));
}
| ACTION_SETRSC run_time_string
{

File diff suppressed because it is too large Load Diff

View File

@@ -552,10 +552,7 @@ EQUALS_MINUS (?i:=\-)
{ACTION_REDIRECT}: { BEGIN(EXPECTING_ACTION_PREDICATE); return p::make_ACTION_REDIRECT(yytext, *driver.loc.back()); }
{ACTION_REV}:'{FREE_TEXT_QUOTE_COMMA}' { return p::make_ACTION_REV(yytext, *driver.loc.back()); }
{ACTION_REV}:{FREE_TEXT_QUOTE_COMMA} { return p::make_ACTION_REV(yytext, *driver.loc.back()); }
{ACTION_SETENV}:'{VAR_FREE_TEXT_QUOTE}={VAR_FREE_TEXT_QUOTE}' { return p::make_ACTION_SETENV(yytext, *driver.loc.back()); }
{ACTION_SETENV}:'{VAR_FREE_TEXT_QUOTE}' { return p::make_ACTION_SETENV(yytext, *driver.loc.back()); }
{ACTION_SETENV}:{VAR_FREE_TEXT_SPACE_COMMA} { return p::make_ACTION_SETENV(yytext, *driver.loc.back()); }
{ACTION_SETENV}:{VAR_FREE_TEXT_SPACE}={VAR_FREE_TEXT_SPACE_COMMA} { return p::make_ACTION_SETENV(yytext, *driver.loc.back()); }
{ACTION_SETENV}: { BEGIN(EXPECTING_ACTION_PREDICATE); return p::make_ACTION_SETENV(yytext, *driver.loc.back()); }
{ACTION_SETSID}: { BEGIN(EXPECTING_ACTION_PREDICATE); return p::make_ACTION_SETSID(yytext, *driver.loc.back()); }
{ACTION_SETUID}: { BEGIN(EXPECTING_ACTION_PREDICATE); return p::make_ACTION_SETUID(yytext, *driver.loc.back()); }

View File

@@ -30,7 +30,8 @@ class Transaction;
namespace Variables {
DEFINE_VARIABLE(InboundDataError, INBOUND_DATA_ERROR, m_variableInboundDataError)
DEFINE_VARIABLE(InboundDataError, INBOUND_DATA_ERROR,
m_variableInboundDataError)
} // namespace Variables