mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 11:44:32 +03:00
Adds support to severity action and HIGHEST_SEVERITY variable
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "actions/status.h"
|
||||
#include "actions/rule_id.h"
|
||||
#include "actions/phase.h"
|
||||
#include "actions/severity.h"
|
||||
|
||||
|
||||
#define IF_MATCH(a) \
|
||||
@@ -58,6 +59,7 @@ Action *Action::instantiate(std::string name) {
|
||||
std::string block("block");
|
||||
std::string phase("phase:");
|
||||
std::string rule_id("id:");
|
||||
std::string severity("severity:");
|
||||
|
||||
if (name.compare(0, status.length(), status) == 0) {
|
||||
return new Status(name);
|
||||
@@ -74,6 +76,9 @@ Action *Action::instantiate(std::string name) {
|
||||
if (name.compare(0, rule_id.length(), rule_id) == 0) {
|
||||
return new RuleId(name);
|
||||
}
|
||||
if (name.compare(0, severity.length(), severity) == 0) {
|
||||
return new Severity(name);
|
||||
}
|
||||
|
||||
return new Action(name);
|
||||
}
|
||||
|
66
src/actions/severity.cc
Normal file
66
src/actions/severity.cc
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "actions/severity.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
#include "modsecurity/assay.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
namespace actions {
|
||||
|
||||
Severity::Severity(std::string action)
|
||||
: Action(action, RunTimeOnlyIfMatchKind) {
|
||||
std::string a = action;
|
||||
a.erase(0, 9);
|
||||
if (tolower(a) == "emergency") {
|
||||
this->m_severity = 0;
|
||||
} else if (tolower(a) == "alert") {
|
||||
this->m_severity = 1;
|
||||
} else if (tolower(a) == "critical") {
|
||||
this->m_severity = 2;
|
||||
} else if (tolower(a) == "error") {
|
||||
this->m_severity = 3;
|
||||
} else if (tolower(a) == "warning") {
|
||||
this->m_severity = 4;
|
||||
} else if (tolower(a) == "notice") {
|
||||
this->m_severity = 5;
|
||||
} else if (tolower(a) == "info") {
|
||||
this->m_severity = 6;
|
||||
} else if (tolower(a) == "debug") {
|
||||
this->m_severity = 7;
|
||||
} else {
|
||||
this->m_severity = std::stod(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Severity::evaluate(Assay *assay) {
|
||||
assay->debug(9, "This rule severity is: " + \
|
||||
std::to_string(this->m_severity) + " current assay is: " + \
|
||||
std::to_string(assay->highest_severity));
|
||||
|
||||
if (assay->highest_severity > this->m_severity) {
|
||||
assay->highest_severity = this->m_severity;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
46
src/actions/severity.h
Normal file
46
src/actions/severity.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "actions/action.h"
|
||||
|
||||
#ifndef SRC_ACTIONS_SEVERITY_H_
|
||||
#define SRC_ACTIONS_SEVERITY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
class Assay;
|
||||
|
||||
namespace ModSecurity {
|
||||
class Assay;
|
||||
|
||||
namespace actions {
|
||||
|
||||
|
||||
class Severity : public Action {
|
||||
public:
|
||||
explicit Severity(std::string action);
|
||||
|
||||
bool evaluate(Assay *assay) override;
|
||||
|
||||
private:
|
||||
int m_severity;
|
||||
};
|
||||
|
||||
} // namespace actions
|
||||
} // namespace ModSecurity
|
||||
#endif
|
||||
|
||||
#endif // SRC_ACTIONS_SEVERITY_H_
|
Reference in New Issue
Block a user