mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Adds contains to the list of operators compatibles with the capture action
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "operators/operator.h"
|
||||
#include "operators/pm.h"
|
||||
#include "operators/rx.h"
|
||||
#include "operators/contains.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace actions {
|
||||
@@ -35,6 +36,7 @@ bool Capture::evaluate(Rule *rule, Assay *assay) {
|
||||
|
||||
operators::Pm *pm = dynamic_cast<operators::Pm *>(op);
|
||||
operators::Rx *rx = dynamic_cast<operators::Rx *>(op);
|
||||
operators::Contains *contains = dynamic_cast<operators::Contains *>(op);
|
||||
|
||||
if (pm != NULL) {
|
||||
match = pm->matched;
|
||||
@@ -44,20 +46,19 @@ bool Capture::evaluate(Rule *rule, Assay *assay) {
|
||||
match = rx->matched;
|
||||
}
|
||||
|
||||
if (contains != NULL) {
|
||||
match = contains->matched;
|
||||
}
|
||||
|
||||
if (match.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (match.empty() == false) {
|
||||
std::string varName = "TX:" + std::to_string(i);
|
||||
std::string *a = assay->resolve_variable_first(varName);
|
||||
if (a == NULL) {
|
||||
assay->store_variable(varName, match.back());
|
||||
} else {
|
||||
assay->update_variable_first(varName, match.back());
|
||||
}
|
||||
assay->setCollection("TX", std::to_string(i), match.back());
|
||||
match.pop_back();
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@@ -23,6 +23,10 @@ namespace operators {
|
||||
bool Contains::evaluate(Assay *assay, const std::string &input) {
|
||||
bool contains = input.find(param) != std::string::npos;
|
||||
|
||||
if (contains) {
|
||||
matched.push_back(param);
|
||||
}
|
||||
|
||||
if (negation) {
|
||||
return !contains;
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@ class Contains : public Operator {
|
||||
Contains(std::string op, std::string param, bool negation)
|
||||
: Operator(op, param, negation) { }
|
||||
bool evaluate(Assay *assay, const std::string &exp) override;
|
||||
|
||||
std::list<std::string> matched;
|
||||
};
|
||||
|
||||
} // namespace operators
|
||||
|
Reference in New Issue
Block a user