mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Cosmetics: Fix coding style
This commit is contained in:
parent
f6e0b447b3
commit
b497091017
@ -104,7 +104,6 @@ class ModSecurityStringVar {
|
|||||||
class ModSecurityStringVariables :
|
class ModSecurityStringVariables :
|
||||||
public std::unordered_multimap<std::string, std::string> {
|
public std::unordered_multimap<std::string, std::string> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ModSecurityStringVariables() {
|
ModSecurityStringVariables() {
|
||||||
this->reserve(1000);
|
this->reserve(1000);
|
||||||
}
|
}
|
||||||
@ -140,7 +139,6 @@ class ModSecurityStringVariables :
|
|||||||
std::list<ModSecurityStringVar *>
|
std::list<ModSecurityStringVar *>
|
||||||
resolveVariable(const std::string& key,
|
resolveVariable(const std::string& key,
|
||||||
std::list<ModSecurityStringVar *> *l) {
|
std::list<ModSecurityStringVar *> *l) {
|
||||||
|
|
||||||
auto range = this->equal_range(key);
|
auto range = this->equal_range(key);
|
||||||
|
|
||||||
for (auto it = range.first; it != range.second; ++it) {
|
for (auto it = range.first; it != range.second; ++it) {
|
||||||
@ -159,11 +157,11 @@ class ModSecurityStringVariables :
|
|||||||
if (x.first.compare(0, keySize, key + ":") != 0) {
|
if (x.first.compare(0, keySize, key + ":") != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//auto range = this->equal_range(x.first);
|
// auto range = this->equal_range(x.first);
|
||||||
|
|
||||||
//for (auto it = range.first; it != range.second; ++it) {
|
// for (auto it = range.first; it != range.second; ++it) {
|
||||||
l->push_back(new ModSecurityStringVar(x.first, x.second));
|
l->push_back(new ModSecurityStringVar(x.first, x.second));
|
||||||
//}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,6 +291,7 @@ class Assay {
|
|||||||
|
|
||||||
std::list<std::pair<int, std::string>> auditLogModifier;
|
std::list<std::pair<int, std::string>> auditLogModifier;
|
||||||
std::string m_marker;
|
std::string m_marker;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ofstream myfile;
|
std::ofstream myfile;
|
||||||
ModSecurity *m_ms;
|
ModSecurity *m_ms;
|
||||||
|
@ -74,8 +74,10 @@ class RulesProperties {
|
|||||||
delete m_debugLog;
|
delete m_debugLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Rule *> rules[7]; // ModSecurity::Phases::NUMBER_OF_PHASES
|
std::vector<Rule *> rules[7];
|
||||||
std::vector<actions::Action *> defaultActions[7]; // ModSecurity::Phases::NUMBER_OF_PHASES
|
// ModSecurity::Phases::NUMBER_OF_PHASES
|
||||||
|
std::vector<actions::Action *> defaultActions[7];
|
||||||
|
// ModSecurity::Phases::NUMBER_OF_PHASES
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -25,8 +25,7 @@ namespace actions {
|
|||||||
|
|
||||||
CtlAuditLogParts::CtlAuditLogParts(std::string action)
|
CtlAuditLogParts::CtlAuditLogParts(std::string action)
|
||||||
: Action(action, RunTimeOnlyIfMatchKind),
|
: Action(action, RunTimeOnlyIfMatchKind),
|
||||||
mPartsAction(0)
|
mPartsAction(0) {
|
||||||
{
|
|
||||||
std::string what(action, 18, 1);
|
std::string what(action, 18, 1);
|
||||||
mParts = std::string(action, 19, action.length()-19);
|
mParts = std::string(action, 19, action.length()-19);
|
||||||
if (what == "+") {
|
if (what == "+") {
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
#include "actions/action.h"
|
#include "actions/action.h"
|
||||||
#include "modsecurity/assay.h"
|
#include "modsecurity/assay.h"
|
||||||
|
|
||||||
#ifndef SRC_CLT_ACTIONS_AUDIT_LOG_PARTS_H_
|
#ifndef SRC_ACTIONS_CTL_AUDIT_LOG_PARTS_H_
|
||||||
#define SRC_CLT_ACTIONS_AUDIT_LOG_PARTS_H_
|
#define SRC_ACTIONS_CTL_AUDIT_LOG_PARTS_H_
|
||||||
|
|
||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace actions {
|
namespace actions {
|
||||||
@ -37,4 +37,4 @@ class CtlAuditLogParts : public Action {
|
|||||||
} // namespace actions
|
} // namespace actions
|
||||||
} // namespace ModSecurity
|
} // namespace ModSecurity
|
||||||
|
|
||||||
#endif // SRC_CLT_ACTIONS_AUDIT_LOG_PARTS_H_
|
#endif // SRC_ACTIONS_CTL_AUDIT_LOG_PARTS_H_
|
||||||
|
@ -36,9 +36,6 @@ bool Pass::evaluate(Rule *rule, Assay *assay) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pass::fill_intervention(ModSecurityIntervention *i) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace actions
|
} // namespace actions
|
||||||
} // namespace ModSecurity
|
} // namespace ModSecurity
|
||||||
|
@ -30,7 +30,6 @@ class Pass : public Action {
|
|||||||
explicit Pass(std::string action);
|
explicit Pass(std::string action);
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Assay *assay) override;
|
bool evaluate(Rule *rule, Assay *assay) override;
|
||||||
void fill_intervention(ModSecurityIntervention *i) override;
|
|
||||||
bool isDisruptive() override { return true; }
|
bool isDisruptive() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,8 @@ Phase::Phase(std::string action)
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
this->phase = 0;
|
this->phase = 0;
|
||||||
if (tolower(a) == "request") {
|
if (tolower(a) == "request") {
|
||||||
this->phase = this->phase + ModSecurity::Phases::RequestHeadersPhase;
|
this->phase = this->phase +
|
||||||
|
ModSecurity::Phases::RequestHeadersPhase;
|
||||||
m_secRulesPhase = 2;
|
m_secRulesPhase = 2;
|
||||||
}
|
}
|
||||||
if (tolower(a) == "response") {
|
if (tolower(a) == "response") {
|
||||||
|
@ -36,14 +36,16 @@ bool RuleId::init(std::string *error) {
|
|||||||
m_ruleId = std::stod(a);
|
m_ruleId = std::stod(a);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
m_ruleId = 0;
|
m_ruleId = 0;
|
||||||
error->assign("The input \"" + a + "\" does not seems to be a valid rule id.");
|
error->assign("The input \"" + a + "\" does not " \
|
||||||
|
"seems to be a valid rule id.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << std::setprecision(40) << m_ruleId;
|
oss << std::setprecision(40) << m_ruleId;
|
||||||
if (a != oss.str() || m_ruleId < 0) {
|
if (a != oss.str() || m_ruleId < 0) {
|
||||||
error->assign("The input \"" + a + "\" does not seems to be a valid rule id.");
|
error->assign("The input \"" + a + "\" does not seems " \
|
||||||
|
"to be a valid rule id.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -38,7 +38,7 @@ class RuleId : public Action {
|
|||||||
bool init(std::string *error) override;
|
bool init(std::string *error) override;
|
||||||
bool evaluate(Rule *rule, Assay *assay) override;
|
bool evaluate(Rule *rule, Assay *assay) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_ruleId;
|
double m_ruleId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
21
src/assay.cc
21
src/assay.cc
@ -1084,29 +1084,33 @@ int Assay::processLogging(int returned_code) {
|
|||||||
/* If relevant, save this assay information at the audit_logs */
|
/* If relevant, save this assay information at the audit_logs */
|
||||||
if (m_rules != NULL && m_rules->audit_log != NULL) {
|
if (m_rules != NULL && m_rules->audit_log != NULL) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
debug(8, "Checking if this request is suitable to be saved as an audit log.");
|
debug(8, "Checking if this request is suitable to be " \
|
||||||
|
"saved as an audit log.");
|
||||||
#endif
|
#endif
|
||||||
int parts = -1;
|
int parts = -1;
|
||||||
|
|
||||||
if (this->auditLogModifier.size() > 0)
|
if (this->auditLogModifier.size() > 0) {
|
||||||
{
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
debug(4, "There was an audit log modifier for this transaction.");
|
debug(4, "There was an audit log modifier for this transaction.");
|
||||||
#endif
|
#endif
|
||||||
std::list<std::pair<int, std::string>>::iterator it;
|
std::list<std::pair<int, std::string>>::iterator it;
|
||||||
parts = this->m_rules->audit_log->m_parts;
|
parts = this->m_rules->audit_log->m_parts;
|
||||||
for (it = auditLogModifier.begin(); it != auditLogModifier.end(); ++it) {
|
for (it = auditLogModifier.begin();
|
||||||
|
it != auditLogModifier.end(); ++it) {
|
||||||
std::pair <int, std::string> p = *it;
|
std::pair <int, std::string> p = *it;
|
||||||
if (p.first == 0) { // Add
|
if (p.first == 0) { // Add
|
||||||
parts = this->m_rules->audit_log->addParts(parts, p.second);
|
parts = this->m_rules->audit_log->addParts(parts,
|
||||||
|
p.second);
|
||||||
} else { // Remove
|
} else { // Remove
|
||||||
parts = this->m_rules->audit_log->removeParts(parts, p.second);
|
parts = this->m_rules->audit_log->removeParts(parts,
|
||||||
|
p.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
if (save_in_auditlog) {
|
if (save_in_auditlog) {
|
||||||
debug(8, "This request was marked to be saved via auditlog action.");
|
debug(8, "This request was marked to be " \
|
||||||
|
"saved via auditlog action.");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool saved = this->m_rules->audit_log->saveIfRelevant(this, parts);
|
bool saved = this->m_rules->audit_log->saveIfRelevant(this, parts);
|
||||||
@ -1489,7 +1493,8 @@ void Assay::resolve_variable(const std::string& var,
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Assay::resolve_variable(const std::string& var) {
|
Assay::resolve_variable(const std::string& var) {
|
||||||
std::list<ModSecurityStringVar *> *l = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *l =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
resolve_variable(var, l);
|
resolve_variable(var, l);
|
||||||
|
|
||||||
|
@ -239,8 +239,7 @@ bool AuditLog::saveIfRelevant(Assay *assay, int parts) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parts == -1)
|
if (parts == -1) {
|
||||||
{
|
|
||||||
parts = m_parts;
|
parts = m_parts;
|
||||||
}
|
}
|
||||||
m_writer->write(assay, parts);
|
m_writer->write(assay, parts);
|
||||||
|
@ -169,7 +169,7 @@ class AuditLog {
|
|||||||
|
|
||||||
int m_parts;
|
int m_parts;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AuditLogStatus m_status;
|
AuditLogStatus m_status;
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,8 @@ int DebugLog::getDebugLogLevel() {
|
|||||||
|
|
||||||
void DebugLog::write(int level, const std::string &msg) {
|
void DebugLog::write(int level, const std::string &msg) {
|
||||||
if (level <= m_debugLevel) {
|
if (level <= m_debugLevel) {
|
||||||
DebugLogWriter::getInstance().write(m_fileName, "[" + std::to_string(level) + "] " + msg);
|
DebugLogWriter::getInstance().write(m_fileName, "[" \
|
||||||
|
+ std::to_string(level) + "] " + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef SRC_DEBUG_LOG_WRITER_H_
|
#ifndef SRC_DEBUG_LOG_WRITER_H_
|
||||||
#define SRC_DEBUG_LOG_WRITER_H_
|
#define SRC_DEBUG_LOG_WRITER_H_
|
||||||
|
|
||||||
#include "debug_log_writer_agent.h"
|
#include "src/debug_log_writer_agent.h"
|
||||||
|
|
||||||
|
|
||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
@ -37,7 +37,7 @@ class DebugLogWriter {
|
|||||||
void close(const std::string& m_fileName);
|
void close(const std::string& m_fileName);
|
||||||
void open(const std::string& m_fileName);
|
void open(const std::string& m_fileName);
|
||||||
private:
|
private:
|
||||||
DebugLogWriter() {};
|
DebugLogWriter() {}
|
||||||
|
|
||||||
// C++ 03
|
// C++ 03
|
||||||
// ========
|
// ========
|
||||||
|
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "debug_log_writer.h"
|
#include "src/debug_log_writer.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
|
@ -25,7 +25,7 @@ namespace ModSecurity {
|
|||||||
/** @ingroup ModSecurity_CPP_API */
|
/** @ingroup ModSecurity_CPP_API */
|
||||||
class DebugLogWriterAgent : public std::ofstream {
|
class DebugLogWriterAgent : public std::ofstream {
|
||||||
public:
|
public:
|
||||||
DebugLogWriterAgent(const std::string& fileName);
|
explicit DebugLogWriterAgent(const std::string& fileName);
|
||||||
~DebugLogWriterAgent() {
|
~DebugLogWriterAgent() {
|
||||||
if (is_open()) {
|
if (is_open()) {
|
||||||
close();
|
close();
|
||||||
|
@ -32,7 +32,8 @@ class MacroExpansion {
|
|||||||
MacroExpansion();
|
MacroExpansion();
|
||||||
|
|
||||||
static std::string expand(const std::string& input, Assay *assay);
|
static std::string expand(const std::string& input, Assay *assay);
|
||||||
static std::string expandKeepOriginal(const std::string& input, Assay *assay);
|
static std::string expandKeepOriginal(const std::string& input,
|
||||||
|
Assay *assay);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_CONTAINS_H_
|
#define SRC_OPERATORS_CONTAINS_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include "modsecurity/assay.h"
|
#include "modsecurity/assay.h"
|
||||||
#include "operators/operator.h"
|
#include "operators/operator.h"
|
||||||
|
@ -59,9 +59,10 @@ void Pm::postOrderTraversal(acmp_btree_node_t *node) {
|
|||||||
node = NULL;
|
node = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pm::replaceAll(std::string& str, const std::string& from, const std::string& to) {
|
void Pm::replaceAll(std::string str, const std::string& from,
|
||||||
|
const std::string& to) {
|
||||||
size_t start_pos = 0;
|
size_t start_pos = 0;
|
||||||
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||||
size_t end_pos = start_pos + from.length();
|
size_t end_pos = start_pos + from.length();
|
||||||
str.replace(start_pos, end_pos, to);
|
str.replace(start_pos, end_pos, to);
|
||||||
start_pos += to.length();
|
start_pos += to.length();
|
||||||
|
@ -35,7 +35,8 @@ class Pm : public Operator {
|
|||||||
m_p = acmp_create(0);
|
m_p = acmp_create(0);
|
||||||
}
|
}
|
||||||
~Pm();
|
~Pm();
|
||||||
void replaceAll(std::string& str, const std::string& from, const std::string& to);
|
void replaceAll(std::string str, const std::string& from,
|
||||||
|
const std::string& to);
|
||||||
bool evaluate(Assay *assay, const std::string &input);
|
bool evaluate(Assay *assay, const std::string &input);
|
||||||
|
|
||||||
virtual bool init(const char **error);
|
virtual bool init(const char **error);
|
||||||
|
@ -30,7 +30,7 @@ bool Rx::evaluate(Assay *assay, const std::string& input) {
|
|||||||
SMatch match;
|
SMatch match;
|
||||||
|
|
||||||
if (regex_search(input, &match, *m_re) && match.size() >= 1) {
|
if (regex_search(input, &match, *m_re) && match.size() >= 1) {
|
||||||
//this->matched.push_back(match.match);
|
// this->matched.push_back(match.match);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,8 @@ int Driver::addSecRule(Rule *rule) {
|
|||||||
std::vector<Rule *> rules = this->rules[i];
|
std::vector<Rule *> rules = this->rules[i];
|
||||||
for (int j = 0; j < rules.size(); j++) {
|
for (int j = 0; j < rules.size(); j++) {
|
||||||
if (rules[j]->rule_id == rule->rule_id) {
|
if (rules[j]->rule_id == rule->rule_id) {
|
||||||
parserError << "Rule id: " << std::to_string(rule->rule_id) << " is duplicated" << std::endl;
|
parserError << "Rule id: " << std::to_string(rule->rule_id) \
|
||||||
|
<< " is duplicated" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,7 +127,8 @@ int Driver::parse(const std::string &f, const std::string &ref) {
|
|||||||
scan_end();
|
scan_end();
|
||||||
|
|
||||||
if (audit_log->init() == false) {
|
if (audit_log->init() == false) {
|
||||||
parserError << "Problems while initializing the audit logs" << std::endl;
|
parserError << "Problems while initializing the audit logs" \
|
||||||
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,9 +224,9 @@ bool Multipart::process(std::string data) {
|
|||||||
|
|
||||||
checkForCrlfLf(block);
|
checkForCrlfLf(block);
|
||||||
|
|
||||||
//if (this->crlf) {
|
// if (this->crlf) {
|
||||||
// block.erase(0, 1);
|
// block.erase(0, 1);
|
||||||
//}
|
// }
|
||||||
|
|
||||||
blobs.push_back(block);
|
blobs.push_back(block);
|
||||||
lastValidBoundary = end;
|
lastValidBoundary = end;
|
||||||
|
@ -50,6 +50,7 @@ class Multipart {
|
|||||||
m_assay->debug(a, str);
|
m_assay->debug(a, str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_boundary;
|
std::string m_boundary;
|
||||||
std::string m_header;
|
std::string m_header;
|
||||||
|
33
src/rule.cc
33
src/rule.cc
@ -82,7 +82,7 @@ Rule::Rule(std::string marker)
|
|||||||
m_unconditional(false),
|
m_unconditional(false),
|
||||||
m_secmarker(true),
|
m_secmarker(true),
|
||||||
m_marker(marker),
|
m_marker(marker),
|
||||||
m_referenceCount(0) { };
|
m_referenceCount(0) { }
|
||||||
|
|
||||||
Rule::Rule(Operator *_op,
|
Rule::Rule(Operator *_op,
|
||||||
std::vector<Variable *> *_variables,
|
std::vector<Variable *> *_variables,
|
||||||
@ -319,7 +319,8 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
// on the target rule.
|
// on the target rule.
|
||||||
if (none == 0) {
|
if (none == 0) {
|
||||||
for (Action *a : assay->m_rules->defaultActions[this->phase]) {
|
for (Action *a : assay->m_rules->defaultActions[this->phase]) {
|
||||||
if (a->action_kind == actions::Action::RunTimeBeforeMatchAttemptKind) {
|
if (a->action_kind ==
|
||||||
|
actions::Action::RunTimeBeforeMatchAttemptKind) {
|
||||||
value = a->evaluate(value, assay);
|
value = a->evaluate(value, assay);
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(9, "(SecDefaultAction) T (" + \
|
assay->debug(9, "(SecDefaultAction) T (" + \
|
||||||
@ -348,8 +349,8 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(9, "Target value: \"" + limitTo(80, toHexIfNeeded(value)) + \
|
assay->debug(9, "Target value: \"" + limitTo(80,
|
||||||
"\" (Variable: " + v->m_key + ")");
|
toHexIfNeeded(value)) + "\" (Variable: " + v->m_key + ")");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = this->op->evaluate(assay, value);
|
ret = this->op->evaluate(assay, value);
|
||||||
@ -374,7 +375,8 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
this->actions_runtime_pos) {
|
this->actions_runtime_pos) {
|
||||||
if (a->isDisruptive() == false) {
|
if (a->isDisruptive() == false) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(4, "Running (_non_ disruptive) action: " + a->action);
|
assay->debug(4, "Running (_non_ disruptive) action: " \
|
||||||
|
+ a->action);
|
||||||
#endif
|
#endif
|
||||||
a->evaluate(this, assay);
|
a->evaluate(this, assay);
|
||||||
} else {
|
} else {
|
||||||
@ -410,14 +412,17 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
assay->delete_variable("MATCHED_VARS_NAME");
|
assay->delete_variable("MATCHED_VARS_NAME");
|
||||||
}
|
}
|
||||||
if (this->chained && chainResult == true || !this->chained) {
|
if (this->chained && chainResult == true || !this->chained) {
|
||||||
for (Action *a : assay->m_rules->defaultActions[this->phase]) {
|
for (Action *a :
|
||||||
if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind) {
|
assay->m_rules->defaultActions[this->phase]) {
|
||||||
|
if (a->action_kind
|
||||||
|
== actions::Action::RunTimeOnlyIfMatchKind) {
|
||||||
if (a->isDisruptive()) {
|
if (a->isDisruptive()) {
|
||||||
if (containsDisruptive) {
|
if (containsDisruptive) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(4, "(SecDefaultAction) " \
|
assay->debug(4, "(SecDefaultAction) " \
|
||||||
"_ignoring_ action: " + a->action + \
|
"_ignoring_ action: " + a->action \
|
||||||
" (rule contains a disruptive action)");
|
+ " (rule contains " \
|
||||||
|
+ "a disruptive action)");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (assay->m_rules->secRuleEngine
|
if (assay->m_rules->secRuleEngine
|
||||||
@ -432,16 +437,18 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
} else {
|
} else {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(4, "(SecDefaultAction) " \
|
assay->debug(4, "(SecDefaultAction) " \
|
||||||
"_Not_ running action: " + a->action + \
|
"_Not_ running action: " \
|
||||||
". Rule _does not_ contains a " \
|
+ a->action + ". Rule _does not_" \
|
||||||
"disruptive action, but SecRuleEngine is not On.");
|
+ " contains a disruptive action,"\
|
||||||
|
+ " but SecRuleEngine is not On.");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(4, "(SecDefaultAction) Running " \
|
assay->debug(4, "(SecDefaultAction) Running " \
|
||||||
"action: " + a->action + "!!" + std::to_string(a->isDisruptive()));
|
"action: " + a->action + "!!" \
|
||||||
|
+ std::to_string(a->isDisruptive()));
|
||||||
#endif
|
#endif
|
||||||
a->evaluate(this, assay);
|
a->evaluate(this, assay);
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ class Rule {
|
|||||||
|
|
||||||
std::string m_marker;
|
std::string m_marker;
|
||||||
bool m_secmarker;
|
bool m_secmarker;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_unconditional;
|
bool m_unconditional;
|
||||||
int m_referenceCount;
|
int m_referenceCount;
|
||||||
|
@ -175,7 +175,8 @@ int Rules::evaluate(int phase, Assay *assay) {
|
|||||||
if (assay->m_marker.empty()) {
|
if (assay->m_marker.empty()) {
|
||||||
rule->evaluate(assay);
|
rule->evaluate(assay);
|
||||||
} else {
|
} else {
|
||||||
debug(9, "Skipped rule id '" + std::to_string(rule->rule_id) + "' due to a SecMarker: " + assay->m_marker);
|
debug(9, "Skipped rule id '" + std::to_string(rule->rule_id) \
|
||||||
|
+ "' due to a SecMarker: " + assay->m_marker);
|
||||||
m_secmarker_skipped++;
|
m_secmarker_skipped++;
|
||||||
debug(9, "Rule: " + rule->m_marker);
|
debug(9, "Rule: " + rule->m_marker);
|
||||||
if (rule->m_secmarker && rule->m_marker == assay->m_marker) {
|
if (rule->m_secmarker && rule->m_marker == assay->m_marker) {
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
|
|
||||||
std::string phase_name(int x) {
|
std::string phase_name(int x) {
|
||||||
switch(x) {
|
switch (x) {
|
||||||
case ModSecurity::Phases::ConnectionPhase:
|
case ModSecurity::Phases::ConnectionPhase:
|
||||||
return "Connection Phase";
|
return "Connection Phase";
|
||||||
break;
|
break;
|
||||||
|
@ -40,19 +40,22 @@ Regex::Regex(const std::string& pattern_)
|
|||||||
pattern.assign(".*");
|
pattern.assign(".*");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE, &errptr, &erroffset, NULL);
|
m_pc = pcre_compile(pattern.c_str(), PCRE_DOTALL|PCRE_MULTILINE,
|
||||||
|
&errptr, &erroffset, NULL);
|
||||||
m_pce = pcre_study(m_pc, PCRE_STUDY_JIT_COMPILE, &errptr);
|
m_pce = pcre_study(m_pc, PCRE_STUDY_JIT_COMPILE, &errptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int regex_search(const std::string& s, SMatch *match,
|
int regex_search(const std::string& s, SMatch *match,
|
||||||
const Regex& regex) {
|
const Regex& regex) {
|
||||||
int ovector[OVECCOUNT];
|
int ovector[OVECCOUNT];
|
||||||
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, OVECCOUNT) > 0;
|
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(),
|
||||||
|
s.size(), 0, 0, ovector, OVECCOUNT) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int regex_search(const std::string& s, const Regex& regex) {
|
int regex_search(const std::string& s, const Regex& regex) {
|
||||||
int ovector[OVECCOUNT];
|
int ovector[OVECCOUNT];
|
||||||
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, OVECCOUNT) > 0;
|
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(),
|
||||||
|
s.size(), 0, 0, ovector, OVECCOUNT) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@ -13,10 +13,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <pcre.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <pcre.h>
|
|
||||||
|
|
||||||
#ifndef SRC_UTILS_REGEX_H_
|
#ifndef SRC_UTILS_REGEX_H_
|
||||||
#define SRC_UTILS_REGEX_H_
|
#define SRC_UTILS_REGEX_H_
|
||||||
|
@ -29,7 +29,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Duration::evaluate(Assay *assay) {
|
Duration::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
std::string res;
|
std::string res;
|
||||||
|
|
||||||
double e = cpu_seconds() - assay->start;
|
double e = cpu_seconds() - assay->start;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Env::evaluate(Assay *assay) {
|
Env::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
std::map<std::string, std::string> envs;
|
std::map<std::string, std::string> envs;
|
||||||
for (char **current = environ; *current; current++) {
|
for (char **current = environ; *current; current++) {
|
||||||
|
@ -28,7 +28,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
HighestSeverity::evaluate(Assay *assay) {
|
HighestSeverity::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
resl->push_back(new ModSecurityStringVar("HIGHEST_SEVERITY",
|
resl->push_back(new ModSecurityStringVar("HIGHEST_SEVERITY",
|
||||||
std::to_string(assay->highest_severity)));
|
std::to_string(assay->highest_severity)));
|
||||||
|
@ -29,7 +29,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
ModsecBuild::evaluate(Assay *assay) {
|
ModsecBuild::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MAJOR;
|
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MAJOR;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Time::evaluate(Assay *assay) {
|
Time::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeDay::evaluate(Assay *assay) {
|
TimeDay::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,9 +35,11 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeEpoch::evaluate(Assay *assay) {
|
TimeEpoch::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
resl->push_back(new ModSecurityStringVar("TIME_EPOCH", std::to_string(std::time(nullptr))));
|
resl->push_back(new ModSecurityStringVar("TIME_EPOCH",
|
||||||
|
std::to_string(std::time(nullptr))));
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeHour::evaluate(Assay *assay) {
|
TimeHour::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeMin::evaluate(Assay *assay) {
|
TimeMin::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeMon::evaluate(Assay *assay) {
|
TimeMon::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeSec::evaluate(Assay *assay) {
|
TimeSec::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeWDay::evaluate(Assay *assay) {
|
TimeWDay::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeYear::evaluate(Assay *assay) {
|
TimeYear::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
|
@ -35,7 +35,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Tx::evaluate(Assay *assay) {
|
Tx::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *resl =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
resl->push_back(new ModSecurityStringVar("TX:0", "teste"));
|
resl->push_back(new ModSecurityStringVar("TX:0", "teste"));
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ namespace Variables {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Variable::evaluate(Assay *assay) {
|
Variable::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *l = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *l =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
assay->resolve_variable(this->name, l);
|
assay->resolve_variable(this->name, l);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,8 @@ namespace Variations {
|
|||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Count::evaluate(Assay *assay) {
|
Count::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *reslIn;
|
std::list<ModSecurityStringVar *> *reslIn;
|
||||||
std::list<ModSecurityStringVar *> *reslOut = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *reslOut =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
reslIn = var->evaluate(assay);
|
reslIn = var->evaluate(assay);
|
||||||
|
@ -31,7 +31,8 @@ namespace Variations {
|
|||||||
|
|
||||||
std::list<ModSecurityStringVar *> *
|
std::list<ModSecurityStringVar *> *
|
||||||
Exclusion::evaluate(Assay *assay) {
|
Exclusion::evaluate(Assay *assay) {
|
||||||
std::list<ModSecurityStringVar *> *l = new std::list<ModSecurityStringVar *>();
|
std::list<ModSecurityStringVar *> *l =
|
||||||
|
new std::list<ModSecurityStringVar *>();
|
||||||
assay->resolve_variable(this->name, l);
|
assay->resolve_variable(this->name, l);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,10 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
|
|||||||
|
|
||||||
if (modsec_rules->load(t->rules.c_str(), filename) < 0) {
|
if (modsec_rules->load(t->rules.c_str(), filename) < 0) {
|
||||||
if (t->parser_error.empty() == true) {
|
if (t->parser_error.empty() == true) {
|
||||||
testRes->reason << KRED << "parse failed." << RESET << std::endl;
|
testRes->reason << KRED << "parse failed." << RESET \
|
||||||
testRes->reason << modsec_rules->getParserError() << std::endl;
|
<< std::endl;
|
||||||
|
testRes->reason << modsec_rules->getParserError() \
|
||||||
|
<< std::endl;
|
||||||
testRes->passed = false;
|
testRes->passed = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -299,7 +301,8 @@ int main(int argc, char **argv) {
|
|||||||
} else {
|
} else {
|
||||||
std::cout << KRED << "Test failed." << RESET << KWHT << " From: " \
|
std::cout << KRED << "Test failed." << RESET << KWHT << " From: " \
|
||||||
<< RESET << r->test->filename << "." << std::endl;
|
<< RESET << r->test->filename << "." << std::endl;
|
||||||
std::cout << KWHT << "Test name: " << RESET << r->test->name << "." << std::endl;
|
std::cout << KWHT << "Test name: " << RESET << r->test->name \
|
||||||
|
<< "." << std::endl;
|
||||||
std::cout << KWHT << "Reason: " << RESET << std::endl;
|
std::cout << KWHT << "Reason: " << RESET << std::endl;
|
||||||
std::cout << r->reason.str() << std::endl;
|
std::cout << r->reason.str() << std::endl;
|
||||||
failed++;
|
failed++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user