mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Fix copy/paste typo
This commit is contained in:
parent
027d50b76b
commit
cc25390dc9
190
src/rule.cc
190
src/rule.cc
@ -179,56 +179,56 @@ std::vector<std::string> Rule::getActionNames() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Rule::evaluateActions(Transaction *trasn) {
|
bool Rule::evaluateActions(Transaction *trans) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rule::updateMatchedVars(Transaction *trasn, std::string key,
|
void Rule::updateMatchedVars(Transaction *trans, std::string key,
|
||||||
std::string value) {
|
std::string value) {
|
||||||
trasn->debug(4, "Matched vars updated.");
|
trans->debug(4, "Matched vars updated.");
|
||||||
trasn->m_variableMatchedVar.set(value, trasn->m_variableOffset);
|
trans->m_variableMatchedVar.set(value, trans->m_variableOffset);
|
||||||
trasn->m_variableMatchedVarName.set(key, trasn->m_variableOffset);
|
trans->m_variableMatchedVarName.set(key, trans->m_variableOffset);
|
||||||
|
|
||||||
trasn->m_variableMatchedVars.set(key, value, trasn->m_variableOffset);
|
trans->m_variableMatchedVars.set(key, value, trans->m_variableOffset);
|
||||||
trasn->m_variableMatchedVarsNames.set(key, key, trasn->m_variableOffset);
|
trans->m_variableMatchedVarsNames.set(key, key, trans->m_variableOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rule::cleanMatchedVars(Transaction *trasn) {
|
void Rule::cleanMatchedVars(Transaction *trans) {
|
||||||
trasn->debug(4, "Matched vars cleaned.");
|
trans->debug(4, "Matched vars cleaned.");
|
||||||
trasn->m_variableMatchedVar.unset();
|
trans->m_variableMatchedVar.unset();
|
||||||
trasn->m_variableMatchedVars.unset();
|
trans->m_variableMatchedVars.unset();
|
||||||
trasn->m_variableMatchedVarName.unset();
|
trans->m_variableMatchedVarName.unset();
|
||||||
trasn->m_variableMatchedVarsNames.unset();
|
trans->m_variableMatchedVarsNames.unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rule::updateRulesVariable(Transaction *trasn) {
|
void Rule::updateRulesVariable(Transaction *trans) {
|
||||||
if (m_ruleId != 0) {
|
if (m_ruleId != 0) {
|
||||||
trasn->m_variableRule.set("id",
|
trans->m_variableRule.set("id",
|
||||||
std::to_string(m_ruleId), 0);
|
std::to_string(m_ruleId), 0);
|
||||||
}
|
}
|
||||||
if (m_rev.empty() == false) {
|
if (m_rev.empty() == false) {
|
||||||
trasn->m_variableRule.set("rev",
|
trans->m_variableRule.set("rev",
|
||||||
m_rev, 0);
|
m_rev, 0);
|
||||||
}
|
}
|
||||||
if (getActionsByName("msg").size() > 0) {
|
if (getActionsByName("msg").size() > 0) {
|
||||||
actions::Msg *msg = dynamic_cast<actions::Msg*>(
|
actions::Msg *msg = dynamic_cast<actions::Msg*>(
|
||||||
getActionsByName("msg")[0]);
|
getActionsByName("msg")[0]);
|
||||||
trasn->m_variableRule.set("msg",
|
trans->m_variableRule.set("msg",
|
||||||
msg->data(trasn), 0);
|
msg->data(trans), 0);
|
||||||
}
|
}
|
||||||
if (getActionsByName("logdata").size() > 0) {
|
if (getActionsByName("logdata").size() > 0) {
|
||||||
actions::LogData *data = dynamic_cast<actions::LogData*>(
|
actions::LogData *data = dynamic_cast<actions::LogData*>(
|
||||||
getActionsByName("logdata")[0]);
|
getActionsByName("logdata")[0]);
|
||||||
trasn->m_variableRule.set("logdata",
|
trans->m_variableRule.set("logdata",
|
||||||
data->data(trasn), 0);
|
data->data(trans), 0);
|
||||||
}
|
}
|
||||||
if (getActionsByName("severity").size() > 0) {
|
if (getActionsByName("severity").size() > 0) {
|
||||||
actions::Severity *data = dynamic_cast<actions::Severity*>(
|
actions::Severity *data = dynamic_cast<actions::Severity*>(
|
||||||
getActionsByName("severity")[0]);
|
getActionsByName("severity")[0]);
|
||||||
trasn->m_variableRule.set("severity",
|
trans->m_variableRule.set("severity",
|
||||||
std::to_string(data->m_severity), 0);
|
std::to_string(data->m_severity), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,12 +249,12 @@ std::string Rule::resolveMatchMessage(std::string key, std::string value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
|
||||||
bool *containsDisruptive, RuleMessage *ruleMessage) {
|
bool *containsDisruptive, RuleMessage *ruleMessage) {
|
||||||
for (Action *a : this->m_actionsRuntimePos) {
|
for (Action *a : this->m_actionsRuntimePos) {
|
||||||
if (a->isDisruptive() == true) {
|
if (a->isDisruptive() == true) {
|
||||||
if (a->m_name == "pass") {
|
if (a->m_name == "pass") {
|
||||||
trasn->debug(4, "Rule contains a `pass' action");
|
trans->debug(4, "Rule contains a `pass' action");
|
||||||
} else {
|
} else {
|
||||||
*containsDisruptive = true;
|
*containsDisruptive = true;
|
||||||
}
|
}
|
||||||
@ -262,16 +262,16 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
|||||||
if (a->m_name == "setvar"
|
if (a->m_name == "setvar"
|
||||||
|| a->m_name == "msg"
|
|| a->m_name == "msg"
|
||||||
|| a->m_name == "log") {
|
|| a->m_name == "log") {
|
||||||
trasn->debug(4, "Running [I] (_non_ disruptive) " \
|
trans->debug(4, "Running [I] (_non_ disruptive) " \
|
||||||
"action: " + a->m_name);
|
"action: " + a->m_name);
|
||||||
a->evaluate(this, trasn, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Rule::executeOperatorAt(Transaction *trasn, std::string key,
|
bool Rule::executeOperatorAt(Transaction *trans, std::string key,
|
||||||
std::string value, RuleMessage *ruleMessage) {
|
std::string value, RuleMessage *ruleMessage) {
|
||||||
#if MSC_EXEC_CLOCK_ENABLED
|
#if MSC_EXEC_CLOCK_ENABLED
|
||||||
clock_t begin = clock();
|
clock_t begin = clock();
|
||||||
@ -280,11 +280,11 @@ bool Rule::executeOperatorAt(Transaction *trasn, std::string key,
|
|||||||
#endif
|
#endif
|
||||||
bool ret;
|
bool ret;
|
||||||
|
|
||||||
trasn->debug(9, "Target value: \"" + utils::string::limitTo(80,
|
trans->debug(9, "Target value: \"" + utils::string::limitTo(80,
|
||||||
utils::string::toHexIfNeeded(value)) \
|
utils::string::toHexIfNeeded(value)) \
|
||||||
+ "\" (Variable: " + key + ")");
|
+ "\" (Variable: " + key + ")");
|
||||||
|
|
||||||
ret = this->m_op->evaluateInternal(trasn, this, value, ruleMessage);
|
ret = this->m_op->evaluateInternal(trans, this, value, ruleMessage);
|
||||||
if (ret == false) {
|
if (ret == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ bool Rule::executeOperatorAt(Transaction *trasn, std::string key,
|
|||||||
end = clock();
|
end = clock();
|
||||||
elapsed_s = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
|
elapsed_s = static_cast<double>(end - begin) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
trasn->debug(4, "Operator completed in " + \
|
trans->debug(4, "Operator completed in " + \
|
||||||
std::to_string(elapsed_s) + " seconds");
|
std::to_string(elapsed_s) + " seconds");
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
@ -304,7 +304,7 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
std::shared_ptr<std::string>>>
|
std::shared_ptr<std::string>>>
|
||||||
Rule::executeDefaultTransformations(
|
Rule::executeDefaultTransformations(
|
||||||
|
|
||||||
Transaction *trasn, const std::string &in, bool multiMatch) {
|
Transaction *trans, const std::string &in, bool multiMatch) {
|
||||||
int none = 0;
|
int none = 0;
|
||||||
int transformations = 0;
|
int transformations = 0;
|
||||||
|
|
||||||
@ -316,16 +316,16 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
std::shared_ptr<std::string>(new std::string(in));
|
std::shared_ptr<std::string>(new std::string(in));
|
||||||
std::shared_ptr<std::string> newValue;
|
std::shared_ptr<std::string> newValue;
|
||||||
|
|
||||||
std::shared_ptr<std::string> trans =
|
std::shared_ptr<std::string> transStr =
|
||||||
std::shared_ptr<std::string>(new std::string());
|
std::shared_ptr<std::string>(new std::string());
|
||||||
|
|
||||||
if (multiMatch == true) {
|
if (multiMatch == true) {
|
||||||
ret.push_back(std::make_pair(
|
ret.push_back(std::make_pair(
|
||||||
std::shared_ptr<std::string>(value),
|
std::shared_ptr<std::string>(value),
|
||||||
std::shared_ptr<std::string>(trans)));
|
std::shared_ptr<std::string>(transStr)));
|
||||||
ret.push_back(std::make_pair(
|
ret.push_back(std::make_pair(
|
||||||
std::shared_ptr<std::string>(value),
|
std::shared_ptr<std::string>(value),
|
||||||
std::shared_ptr<std::string>(trans)));
|
std::shared_ptr<std::string>(transStr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Action *a : this->m_actionsRuntimePre) {
|
for (Action *a : this->m_actionsRuntimePre) {
|
||||||
@ -338,26 +338,26 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
// Notice that first we make sure that won't be a t:none
|
// Notice that first we make sure that won't be a t:none
|
||||||
// on the target rule.
|
// on the target rule.
|
||||||
if (none == 0) {
|
if (none == 0) {
|
||||||
for (Action *a : trasn->m_rules->m_defaultActions[this->m_phase]) {
|
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
|
||||||
if (a->action_kind \
|
if (a->action_kind \
|
||||||
== actions::Action::RunTimeBeforeMatchAttemptKind) {
|
== actions::Action::RunTimeBeforeMatchAttemptKind) {
|
||||||
newValue = std::unique_ptr<std::string>(
|
newValue = std::unique_ptr<std::string>(
|
||||||
new std::string(a->evaluate(*value, trasn)));
|
new std::string(a->evaluate(*value, trans)));
|
||||||
|
|
||||||
if (multiMatch == true) {
|
if (multiMatch == true) {
|
||||||
if (*newValue != *value) {
|
if (*newValue != *value) {
|
||||||
ret.push_back(std::make_pair(
|
ret.push_back(std::make_pair(
|
||||||
newValue,
|
newValue,
|
||||||
trans));
|
transStr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = std::shared_ptr<std::string>(newValue);
|
value = std::shared_ptr<std::string>(newValue);
|
||||||
if (trans->empty()) {
|
if (transStr->empty()) {
|
||||||
trans->append(a->m_name);
|
transStr->append(a->m_name);
|
||||||
} else {
|
} else {
|
||||||
trans->append("," + a->m_name);
|
transStr->append("," + a->m_name);
|
||||||
}
|
}
|
||||||
trasn->debug(9, "(SecDefaultAction) T (" + \
|
trans->debug(9, "(SecDefaultAction) T (" + \
|
||||||
std::to_string(transformations) + ") " + \
|
std::to_string(transformations) + ") " + \
|
||||||
a->m_name + ": \"" + \
|
a->m_name + ": \"" + \
|
||||||
utils::string::limitTo(80, *value) +"\"");
|
utils::string::limitTo(80, *value) +"\"");
|
||||||
@ -370,26 +370,26 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
for (Action *a : this->m_actionsRuntimePre) {
|
for (Action *a : this->m_actionsRuntimePre) {
|
||||||
if (none == 0) {
|
if (none == 0) {
|
||||||
newValue = std::shared_ptr<std::string>(
|
newValue = std::shared_ptr<std::string>(
|
||||||
new std::string(a->evaluate(*value, trasn)));
|
new std::string(a->evaluate(*value, trans)));
|
||||||
|
|
||||||
if (multiMatch == true) {
|
if (multiMatch == true) {
|
||||||
if (*value != *newValue) {
|
if (*value != *newValue) {
|
||||||
ret.push_back(std::make_pair(
|
ret.push_back(std::make_pair(
|
||||||
newValue,
|
newValue,
|
||||||
trans));
|
transStr));
|
||||||
value = newValue;
|
value = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value = newValue;
|
value = newValue;
|
||||||
trasn->debug(9, " T (" + \
|
trans->debug(9, " T (" + \
|
||||||
std::to_string(transformations) + ") " + \
|
std::to_string(transformations) + ") " + \
|
||||||
a->m_name + ": \"" + \
|
a->m_name + ": \"" + \
|
||||||
utils::string::limitTo(80, *value) + "\"");
|
utils::string::limitTo(80, *value) + "\"");
|
||||||
if (trans->empty()) {
|
if (transStr->empty()) {
|
||||||
trans->append(a->m_name);
|
transStr->append(a->m_name);
|
||||||
} else {
|
} else {
|
||||||
trans->append("," + a->m_name);
|
transStr->append("," + a->m_name);
|
||||||
}
|
}
|
||||||
transformations++;
|
transformations++;
|
||||||
}
|
}
|
||||||
@ -401,13 +401,13 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
// v2 checks the last entry twice. Don't know why.
|
// v2 checks the last entry twice. Don't know why.
|
||||||
ret.push_back(ret.back());
|
ret.push_back(ret.back());
|
||||||
|
|
||||||
trasn->debug(9, "multiMatch is enabled. " \
|
trans->debug(9, "multiMatch is enabled. " \
|
||||||
+ std::to_string(ret.size()) + \
|
+ std::to_string(ret.size()) + \
|
||||||
" values to be tested.");
|
" values to be tested.");
|
||||||
} else {
|
} else {
|
||||||
ret.push_back(std::make_pair(
|
ret.push_back(std::make_pair(
|
||||||
std::shared_ptr<std::string>(value),
|
std::shared_ptr<std::string>(value),
|
||||||
std::shared_ptr<std::string>(trans)));
|
std::shared_ptr<std::string>(transStr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -415,7 +415,7 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
||||||
Transaction *trasn) {
|
Transaction *trans) {
|
||||||
std::list<const std::string*> exclusions;
|
std::list<const std::string*> exclusions;
|
||||||
std::vector<Variable *> *variables = m_variables;
|
std::vector<Variable *> *variables = m_variables;
|
||||||
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
||||||
@ -424,7 +424,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
|||||||
Variable *variable = variables->at(i);
|
Variable *variable = variables->at(i);
|
||||||
if (variable->m_isExclusion) {
|
if (variable->m_isExclusion) {
|
||||||
std::vector<const collection::Variable *> z;
|
std::vector<const collection::Variable *> z;
|
||||||
variable->evaluateInternal(trasn, this, &z);
|
variable->evaluateInternal(trans, this, &z);
|
||||||
for (auto &y : z) {
|
for (auto &y : z) {
|
||||||
exclusions.push_back(y->m_key);
|
exclusions.push_back(y->m_key);
|
||||||
}
|
}
|
||||||
@ -441,14 +441,14 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
variable->evaluateInternal(trasn, this, &e);
|
variable->evaluateInternal(trans, this, &e);
|
||||||
for (const collection::Variable *v : e) {
|
for (const collection::Variable *v : e) {
|
||||||
const std::string *key = v->m_key;
|
const std::string *key = v->m_key;
|
||||||
if (std::find_if(exclusions.begin(), exclusions.end(),
|
if (std::find_if(exclusions.begin(), exclusions.end(),
|
||||||
[key](const std::string *m) -> bool { return *key == *m; })
|
[key](const std::string *m) -> bool { return *key == *m; })
|
||||||
!= exclusions.end()) {
|
!= exclusions.end()) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
trasn->debug(9, "Variable: " + *key +
|
trans->debug(9, "Variable: " + *key +
|
||||||
" is part of the exclusion list, skipping...");
|
" is part of the exclusion list, skipping...");
|
||||||
#endif
|
#endif
|
||||||
if (v->m_dynamic) {
|
if (v->m_dynamic) {
|
||||||
@ -458,14 +458,14 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &i : trasn->m_ruleRemoveTargetByTag) {
|
for (auto &i : trans->m_ruleRemoveTargetByTag) {
|
||||||
std::string tag = i.first;
|
std::string tag = i.first;
|
||||||
std::string args = i.second;
|
std::string args = i.second;
|
||||||
if (containsTag(tag, trasn) == false) {
|
if (containsTag(tag, trans) == false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (args == *key) {
|
if (args == *key) {
|
||||||
trasn->debug(9, "Variable: " + *key +
|
trans->debug(9, "Variable: " + *key +
|
||||||
" was excluded by ruleRemoteTargetByTag...");
|
" was excluded by ruleRemoteTargetByTag...");
|
||||||
ignoreVariable = true;
|
ignoreVariable = true;
|
||||||
break;
|
break;
|
||||||
@ -479,14 +479,14 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &i : trasn->m_ruleRemoveTargetById) {
|
for (auto &i : trans->m_ruleRemoveTargetById) {
|
||||||
int id = i.first;
|
int id = i.first;
|
||||||
std::string args = i.second;
|
std::string args = i.second;
|
||||||
if (m_ruleId != id) {
|
if (m_ruleId != id) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (args == *key) {
|
if (args == *key) {
|
||||||
trasn->debug(9, "Variable: " + *key +
|
trans->debug(9, "Variable: " + *key +
|
||||||
" was excluded by ruleRemoteTargetById...");
|
" was excluded by ruleRemoteTargetById...");
|
||||||
ignoreVariable = true;
|
ignoreVariable = true;
|
||||||
break;
|
break;
|
||||||
@ -523,38 +523,38 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Rule::executeActionsAfterFullMatch(Transaction *trasn,
|
void Rule::executeActionsAfterFullMatch(Transaction *trans,
|
||||||
bool containsDisruptive, RuleMessage *ruleMessage) {
|
bool containsDisruptive, RuleMessage *ruleMessage) {
|
||||||
|
|
||||||
for (Action *a : trasn->m_rules->m_defaultActions[this->m_phase]) {
|
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
|
||||||
if (a->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
|
if (a->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->isDisruptive() == false) {
|
if (a->isDisruptive() == false) {
|
||||||
trasn->debug(4, "(SecDefaultAction) Running " \
|
trans->debug(4, "(SecDefaultAction) Running " \
|
||||||
"action: " + a->m_name);
|
"action: " + a->m_name);
|
||||||
a->evaluate(this, trasn, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containsDisruptive) {
|
if (containsDisruptive) {
|
||||||
trasn->debug(4, "(SecDefaultAction) _ignoring_ " \
|
trans->debug(4, "(SecDefaultAction) _ignoring_ " \
|
||||||
"action: " + a->m_name + \
|
"action: " + a->m_name + \
|
||||||
" (rule contains a disruptive action)");
|
" (rule contains a disruptive action)");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trasn->m_rules->m_secRuleEngine == Rules::EnabledRuleEngine) {
|
if (trans->m_rules->m_secRuleEngine == Rules::EnabledRuleEngine) {
|
||||||
trasn->debug(4, "(SecDefaultAction) " \
|
trans->debug(4, "(SecDefaultAction) " \
|
||||||
"Running action: " + a->m_name + \
|
"Running action: " + a->m_name + \
|
||||||
" (rule _does not_ contains a " \
|
" (rule _does not_ contains a " \
|
||||||
"disruptive action)");
|
"disruptive action)");
|
||||||
a->evaluate(this, trasn, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
trasn->debug(4, "(SecDefaultAction) _Not_ running action: " \
|
trans->debug(4, "(SecDefaultAction) _Not_ running action: " \
|
||||||
+ a->m_name + ". Rule _does not_contains a disruptive action,"\
|
+ a->m_name + ". Rule _does not_contains a disruptive action,"\
|
||||||
+ " but SecRuleEngine is not On.");
|
+ " but SecRuleEngine is not On.");
|
||||||
}
|
}
|
||||||
@ -563,25 +563,25 @@ void Rule::executeActionsAfterFullMatch(Transaction *trasn,
|
|||||||
if (a->isDisruptive() == false) {
|
if (a->isDisruptive() == false) {
|
||||||
if (a->m_name != "setvar" && a->m_name != "log"
|
if (a->m_name != "setvar" && a->m_name != "log"
|
||||||
&& a->m_name != "msg") {
|
&& a->m_name != "msg") {
|
||||||
trasn->debug(4, "Running [I] (_non_ disruptive) " \
|
trans->debug(4, "Running [I] (_non_ disruptive) " \
|
||||||
"action: " + a->m_name);
|
"action: " + a->m_name);
|
||||||
a->evaluate(this, trasn, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (trasn->m_rules->m_secRuleEngine == Rules::EnabledRuleEngine) {
|
if (trans->m_rules->m_secRuleEngine == Rules::EnabledRuleEngine) {
|
||||||
trasn->debug(4, "Running (disruptive) action: " + a->m_name);
|
trans->debug(4, "Running (disruptive) action: " + a->m_name);
|
||||||
a->evaluate(this, trasn, ruleMessage);
|
a->evaluate(this, trans, ruleMessage);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
trasn->debug(4, "Not running disruptive action: " + \
|
trans->debug(4, "Not running disruptive action: " + \
|
||||||
a->m_name + ". SecRuleEngine is not On");
|
a->m_name + ". SecRuleEngine is not On");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Rule::evaluate(Transaction *trasn) {
|
bool Rule::evaluate(Transaction *trans) {
|
||||||
bool globalRet = false;
|
bool globalRet = false;
|
||||||
std::vector<Variable *> *variables = this->m_variables;
|
std::vector<Variable *> *variables = this->m_variables;
|
||||||
bool recursiveGlobalRet;
|
bool recursiveGlobalRet;
|
||||||
@ -590,29 +590,29 @@ bool Rule::evaluate(Transaction *trasn) {
|
|||||||
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
||||||
std::string eparam;
|
std::string eparam;
|
||||||
|
|
||||||
trasn->m_matched.clear();
|
trans->m_matched.clear();
|
||||||
|
|
||||||
if (m_secMarker == true) {
|
if (m_secMarker == true) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (m_unconditional == true) {
|
if (m_unconditional == true) {
|
||||||
trasn->debug(4, "(Rule: " + std::to_string(m_ruleId) \
|
trans->debug(4, "(Rule: " + std::to_string(m_ruleId) \
|
||||||
+ ") Executing unconditional rule...");
|
+ ") Executing unconditional rule...");
|
||||||
executeActionsIndependentOfChainedRuleResult(trasn,
|
executeActionsIndependentOfChainedRuleResult(trans,
|
||||||
&containsDisruptive, &ruleMessage);
|
&containsDisruptive, &ruleMessage);
|
||||||
goto end_exec;
|
goto end_exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &i : trasn->m_ruleRemoveById) {
|
for (auto &i : trans->m_ruleRemoveById) {
|
||||||
if (m_ruleId != i) {
|
if (m_ruleId != i) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
trasn->debug(9, "Rule id: " + std::to_string(m_ruleId) +
|
trans->debug(9, "Rule id: " + std::to_string(m_ruleId) +
|
||||||
" was skipped due to an ruleRemoveById action...");
|
" was skipped due to an ruleRemoveById action...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
eparam = MacroExpansion::expand(this->m_op->m_param, trasn);
|
eparam = MacroExpansion::expand(this->m_op->m_param, trans);
|
||||||
|
|
||||||
if (this->m_op->m_param != eparam) {
|
if (this->m_op->m_param != eparam) {
|
||||||
eparam = "\"" + eparam + "\" Was: \"" + this->m_op->m_param + "\"";
|
eparam = "\"" + eparam + "\" Was: \"" + this->m_op->m_param + "\"";
|
||||||
@ -620,16 +620,16 @@ bool Rule::evaluate(Transaction *trasn) {
|
|||||||
eparam = "\"" + eparam + "\"";
|
eparam = "\"" + eparam + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
trasn->debug(4, "(Rule: " + std::to_string(m_ruleId) \
|
trans->debug(4, "(Rule: " + std::to_string(m_ruleId) \
|
||||||
+ ") Executing operator \"" + this->m_op->m_op \
|
+ ") Executing operator \"" + this->m_op->m_op \
|
||||||
+ "\" with param " \
|
+ "\" with param " \
|
||||||
+ eparam \
|
+ eparam \
|
||||||
+ " against " \
|
+ " against " \
|
||||||
+ Variable::to_s(variables) + ".");
|
+ Variable::to_s(variables) + ".");
|
||||||
|
|
||||||
updateRulesVariable(trasn);
|
updateRulesVariable(trans);
|
||||||
|
|
||||||
finalVars = getFinalVars(trasn);
|
finalVars = getFinalVars(trans);
|
||||||
|
|
||||||
for (auto &v : finalVars) {
|
for (auto &v : finalVars) {
|
||||||
const std::string value = *(v->m_value);
|
const std::string value = *(v->m_value);
|
||||||
@ -640,13 +640,13 @@ bool Rule::evaluate(Transaction *trasn) {
|
|||||||
|
|
||||||
bool multiMatch = getActionsByName("multimatch").size() > 0;
|
bool multiMatch = getActionsByName("multimatch").size() > 0;
|
||||||
|
|
||||||
values = executeDefaultTransformations(trasn, value,
|
values = executeDefaultTransformations(trans, value,
|
||||||
multiMatch);
|
multiMatch);
|
||||||
for (const auto &valueTemp : values) {
|
for (const auto &valueTemp : values) {
|
||||||
bool ret;
|
bool ret;
|
||||||
std::string valueAfterTrans = std::move(*valueTemp.first);
|
std::string valueAfterTrans = std::move(*valueTemp.first);
|
||||||
|
|
||||||
ret = executeOperatorAt(trasn, key, valueAfterTrans, &ruleMessage);
|
ret = executeOperatorAt(trans, key, valueAfterTrans, &ruleMessage);
|
||||||
|
|
||||||
if (ret == true) {
|
if (ret == true) {
|
||||||
ruleMessage.m_match = resolveMatchMessage(key, value);
|
ruleMessage.m_match = resolveMatchMessage(key, value);
|
||||||
@ -654,8 +654,8 @@ bool Rule::evaluate(Transaction *trasn) {
|
|||||||
ruleMessage.m_reference.append(i->toText());
|
ruleMessage.m_reference.append(i->toText());
|
||||||
}
|
}
|
||||||
ruleMessage.m_reference.append(*valueTemp.second);
|
ruleMessage.m_reference.append(*valueTemp.second);
|
||||||
updateMatchedVars(trasn, key, value);
|
updateMatchedVars(trans, key, value);
|
||||||
executeActionsIndependentOfChainedRuleResult(trasn,
|
executeActionsIndependentOfChainedRuleResult(trans,
|
||||||
&containsDisruptive, &ruleMessage);
|
&containsDisruptive, &ruleMessage);
|
||||||
globalRet = true;
|
globalRet = true;
|
||||||
}
|
}
|
||||||
@ -663,25 +663,25 @@ bool Rule::evaluate(Transaction *trasn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (globalRet == false) {
|
if (globalRet == false) {
|
||||||
trasn->debug(4, "Rule returned 0.");
|
trans->debug(4, "Rule returned 0.");
|
||||||
cleanMatchedVars(trasn);
|
cleanMatchedVars(trans);
|
||||||
goto end_clean;
|
goto end_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
trasn->debug(4, "Rule returned 1.");
|
trans->debug(4, "Rule returned 1.");
|
||||||
|
|
||||||
if (this->m_chained == false) {
|
if (this->m_chained == false) {
|
||||||
goto end_exec;
|
goto end_exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->m_chainedRule == NULL) {
|
if (this->m_chainedRule == NULL) {
|
||||||
trasn->debug(4, "Rule is marked as chained but there " \
|
trans->debug(4, "Rule is marked as chained but there " \
|
||||||
"isn't a subsequent rule.");
|
"isn't a subsequent rule.");
|
||||||
goto end_clean;
|
goto end_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
trasn->debug(4, "Executing chained rule.");
|
trans->debug(4, "Executing chained rule.");
|
||||||
recursiveGlobalRet = this->m_chainedRule->evaluate(trasn);
|
recursiveGlobalRet = this->m_chainedRule->evaluate(trans);
|
||||||
|
|
||||||
if (recursiveGlobalRet == true) {
|
if (recursiveGlobalRet == true) {
|
||||||
goto end_exec;
|
goto end_exec;
|
||||||
@ -691,13 +691,13 @@ end_clean:
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
end_exec:
|
end_exec:
|
||||||
executeActionsAfterFullMatch(trasn, containsDisruptive, &ruleMessage);
|
executeActionsAfterFullMatch(trans, containsDisruptive, &ruleMessage);
|
||||||
for (const auto &u : ruleMessage.m_server_logs) {
|
for (const auto &u : ruleMessage.m_server_logs) {
|
||||||
trasn->serverLog(u);
|
trans->serverLog(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ruleMessage.m_server_logs.size() > 0) {
|
if (ruleMessage.m_server_logs.size() > 0) {
|
||||||
trasn->m_rulesMessages.push_back(ruleMessage);
|
trans->m_rulesMessages.push_back(ruleMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user