mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Adds macro expansion for all operators
This commit is contained in:
parent
320bcde89e
commit
9d60dc6df8
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
@ -26,9 +27,11 @@ namespace operators {
|
||||
bool BeginsWith::evaluate(Assay *assay, const std::string &str) {
|
||||
bool ret = false;
|
||||
|
||||
if (str.size() < param.size()) {
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
|
||||
if (str.size() < p.size()) {
|
||||
ret = false;
|
||||
} else if (!str.compare(0, param.size(), param)) {
|
||||
} else if (!str.compare(0, p.size(), p)) {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,17 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool Contains::evaluate(Assay *assay, const std::string &input) {
|
||||
bool contains = input.find(param) != std::string::npos;
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
bool contains = input.find(p) != std::string::npos;
|
||||
|
||||
if (contains) {
|
||||
matched.push_back(param);
|
||||
matched.push_back(p);
|
||||
}
|
||||
|
||||
if (negation) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "others/libinjection/src/libinjection.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
@ -25,9 +26,11 @@ namespace operators {
|
||||
|
||||
bool EndsWith::evaluate(Assay *assay, const std::string &input) {
|
||||
bool ret = false;
|
||||
if (input.length() >= param.length()) {
|
||||
ret = (0 == input.compare(input.length() - param.length(),
|
||||
param.length(), param));
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
|
||||
if (input.length() >= p.length()) {
|
||||
ret = (0 == input.compare(input.length() - p.length(),
|
||||
p.length(), p));
|
||||
}
|
||||
|
||||
if (negation) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
@ -27,9 +28,10 @@ bool Eq::evaluate(Assay *assay, const std::string &input) {
|
||||
int p = 0;
|
||||
int i = 0;
|
||||
bool eq = false;
|
||||
std::string pt = MacroExpansion::expand(param, assay);
|
||||
|
||||
try {
|
||||
p = std::stoi(param);
|
||||
p = std::stoi(pt);
|
||||
} catch (...) {
|
||||
p = 0;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
@ -18,12 +18,15 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool Ge::evaluate(Assay *assay, const std::string &input) {
|
||||
bool ge = atoll(input.c_str()) >= atoll(param.c_str());
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
|
||||
bool ge = atoll(p.c_str()) >= atoll(p.c_str());
|
||||
|
||||
if (negation) {
|
||||
return !ge;
|
||||
|
@ -18,12 +18,15 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool Gt::evaluate(Assay *assay, const std::string &input) {
|
||||
bool gt = atoll(input.c_str()) > atoll(param.c_str());
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
|
||||
bool gt = atoll(input.c_str()) > atoll(p.c_str());
|
||||
|
||||
if (negation) {
|
||||
return !gt;
|
||||
|
@ -18,12 +18,15 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool Le::evaluate(Assay *assay, const std::string &input) {
|
||||
bool le = atoll(input.c_str()) <= atoll(param.c_str());
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
|
||||
bool le = atoll(input.c_str()) <= atoll(p.c_str());
|
||||
|
||||
if (negation) {
|
||||
return !le;
|
||||
|
@ -18,12 +18,15 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool Lt::evaluate(Assay *assay, const std::string &input) {
|
||||
bool lt = atoll(input.c_str()) < atoll(param.c_str());
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
|
||||
bool lt = atoll(input.c_str()) < atoll(p.c_str());
|
||||
|
||||
if (negation) {
|
||||
return !lt;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <list>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
@ -28,8 +29,8 @@ namespace operators {
|
||||
bool Rx::evaluate(Assay *assay, const std::string& input) {
|
||||
SMatch match;
|
||||
|
||||
std::string i = input;
|
||||
if (regex_search(i, &match, m_re) && match.size() >= 1) {
|
||||
Regex re(MacroExpansion::expand(param, assay));
|
||||
if (regex_search(input, &match, re) && match.size() >= 1) {
|
||||
this->matched.push_back(match.match);
|
||||
return true;
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ class Rx : public Operator {
|
||||
/** @ingroup ModSecurity_Operator */
|
||||
Rx(std::string op, std::string param, bool negation)
|
||||
: Operator(op, param, negation),
|
||||
m_re(param) { }
|
||||
m_param(param) { }
|
||||
|
||||
bool evaluate(Assay *assay, const std::string &input);
|
||||
|
||||
std::list<std::string> matched;
|
||||
private:
|
||||
Regex m_re;
|
||||
std::string m_param;
|
||||
};
|
||||
|
||||
|
||||
|
@ -16,12 +16,14 @@
|
||||
#include "operators/str_eq.h"
|
||||
|
||||
#include <string>
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
bool StrEq::evaluate(Assay *assay, const std::string &str) {
|
||||
bool eq = !this->param.compare(str);
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
bool eq = !p.compare(str);
|
||||
|
||||
if (negation) {
|
||||
return !eq;
|
||||
|
@ -18,13 +18,15 @@
|
||||
#include <string>
|
||||
|
||||
#include "operators/operator.h"
|
||||
#include "src/macro_expansion.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace operators {
|
||||
|
||||
|
||||
bool StrMatch::evaluate(Assay *assay, const std::string &input) {
|
||||
bool ret = input.find(param) != std::string::npos;
|
||||
std::string p = MacroExpansion::expand(param, assay);
|
||||
bool ret = input.find(p) != std::string::npos;
|
||||
|
||||
if (negation) {
|
||||
return !ret;
|
||||
|
@ -357,7 +357,7 @@ expression:
|
||||
| DIRECTIVE SPACE variables SPACE FREE_TEXT SPACE QUOTATION_MARK actions SPACE QUOTATION_MARK
|
||||
| DIRECTIVE SPACE variables SPACE FREE_TEXT SPACE QUOTATION_MARK actions QUOTATION_MARK
|
||||
{
|
||||
Operator *op = Operator::instantiate("@rx " + $5);
|
||||
Operator *op = Operator::instantiate("\"@rx " + $5 + "\"");
|
||||
const char *error = NULL;
|
||||
if (op->init(&error) == false) {
|
||||
driver.parserError << error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user