Adds support to the TX collection and setvar action

This commit is contained in:
Felipe Zimmerle
2015-08-06 23:41:46 -03:00
parent a9e0fbb41e
commit e12d95b10d
11 changed files with 707 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ class Driver;
}
#include "actions/action.h"
#include "actions/set_var.h"
#include "actions/transformations/transformation.h"
#include "operators/operator.h"
#include "rule.h"
@@ -40,6 +41,7 @@ class Driver;
#include "variables/time_year.h"
using ModSecurity::actions::Action;
using ModSecurity::actions::SetVar;
using ModSecurity::actions::transformations::Transformation;
using ModSecurity::operators::Operator;
using ModSecurity::Rule;
@@ -62,6 +64,7 @@ using ModSecurity::Variables::TimeWDay;
using ModSecurity::Variables::TimeYear;
using ModSecurity::Variables::Variable;
#define CHECK_VARIATION_DECL \
Variable *var = NULL; \
bool t = false;
@@ -182,6 +185,7 @@ using ModSecurity::Variables::Variable;
%token <std::string> OPERATOR
%token <std::string> ACTION
%token <std::string> ACTION_SEVERITY
%token <std::string> ACTION_SETVAR
%token <std::string> TRANSFORMATION
%token <double> CONFIG_VALUE_NUMBER
@@ -596,6 +600,49 @@ actions:
actions->push_back(Action::instantiate($1));
$$ = actions;
}
| actions COMMA ACTION_SETVAR
{
std::vector<Action *> *a = $1;
std::string error;
SetVar *setVar = new SetVar($3);
if (setVar->init(&error) == false) {
driver.parserError << error;
YYERROR;
}
a->push_back(setVar);
$$ = $1;
}
| SPACE ACTION_SETVAR
{
std::vector<Action *> *actions = new std::vector<Action *>;
std::string error;
SetVar *setVar = new SetVar($2);
if (setVar->init(&error) == false) {
driver.parserError << error;
YYERROR;
}
actions->push_back(setVar);
$$ = actions;
}
| ACTION_SETVAR
{
std::vector<Action *> *actions = new std::vector<Action *>;
std::string error;
SetVar *setVar = new SetVar($1);
if (setVar->init(&error) == false) {
driver.parserError << error;
YYERROR;
}
actions->push_back(setVar);
$$ = actions;
}
%%

View File

@@ -23,8 +23,9 @@ using ModSecurity::split;
%}
%option noyywrap nounput batch debug noinput
ACTION (?i:accuracy|allow|append|auditlog|block|capture|chain|ctl|deny|deprecatevar|drop|exec|expirevar|id:[0-9]+|id:'[0-9]+'|initcol|log|logdata|maturity|msg|multiMatch|noauditlog|nolog|pass|pause|phase:[0-9]+|prepend|proxy|redirect:[A-Z0-9_\|\&\:\/\/\.]+|rev|sanitiseArg|sanitiseMatched|sanitiseMatchedBytes|sanitiseRequestHeader|sanitiseResponseHeader|setuid|setrsc|setsid|setenv|setvar|skip|skipAfter|status:[0-9]+|tag|ver|xmlns)
ACTION (?i:accuracy|allow|append|auditlog|block|capture|chain|ctl|deny|deprecatevar|drop|exec|expirevar|id:[0-9]+|id:'[0-9]+'|initcol|log|logdata|maturity|msg|multiMatch|noauditlog|nolog|pass|pause|phase:[0-9]+|prepend|proxy|redirect:[A-Z0-9_\|\&\:\/\/\.]+|rev|sanitiseArg|sanitiseMatched|sanitiseMatchedBytes|sanitiseRequestHeader|sanitiseResponseHeader|setuid|setrsc|setsid|setenv|skip|skipAfter|status:[0-9]+|tag|ver|xmlns)
ACTION_SEVERITY (?i:severity:[0-9]+|severity:'[0-9]+'|severity:(EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG)|severity:'(EMERGENCY|ALERT|CRITICAL|ERROR|WARNING|NOTICE|INFO|DEBUG)')
ACTION_SETVAR (?i:setvar)
DIRECTIVE SecRule
CONFIG_DIRECTIVE SecRequestBodyNoFilesLimit|SecRequestBodyInMemoryLimit|SecPcreMatchLimitRecursion|SecPcreMatchLimit|SecResponseBodyMimeType|SecTmpDir|SecDataDir|SecArgumentSeparator|SecCookieFormat|SecStatusEngine
@@ -188,6 +189,15 @@ FREE_TEXT_NEW_LINE [^\"|\n]+
["]{OPERATORNOARG}["] { return yy::seclang_parser::make_OPERATOR(yytext, *driver.loc.back()); }
{ACTION} { return yy::seclang_parser::make_ACTION(yytext, *driver.loc.back()); }
{ACTION_SEVERITY} { return yy::seclang_parser::make_ACTION_SEVERITY(yytext, *driver.loc.back()); }
{ACTION_SETVAR}:{FREE_TEXT}={FREE_TEXT} {
return yy::seclang_parser::make_ACTION_SETVAR(strchr(yytext, ':') + 1, *driver.loc.back());
}
{ACTION_SETVAR}:{FREE_TEXT}=+{FREE_TEXT} {
return yy::seclang_parser::make_ACTION_SETVAR(strchr(yytext, ':') + 1, *driver.loc.back());
}
{ACTION_SETVAR}:{FREE_TEXT} {
return yy::seclang_parser::make_ACTION_SETVAR(strchr(yytext, ':') + 1, *driver.loc.back());
}
["] { return yy::seclang_parser::make_QUOTATION_MARK(*driver.loc.back()); }
[,] { return yy::seclang_parser::make_COMMA(*driver.loc.back()); }
[|] { return yy::seclang_parser::make_PIPE(*driver.loc.back()); }