Adds support to the action `accuracy'

This commit is contained in:
Felipe Zimmerle 2016-02-10 13:34:41 -03:00
parent 5a2a81a568
commit 714df8db20
6 changed files with 100 additions and 3 deletions

View File

@ -80,6 +80,7 @@ class Rule {
std::string m_log_message;
std::string m_log_data;
int m_accuracy;
private:
bool m_unconditional;
@ -93,12 +94,12 @@ class RuleMessage {
m_ruleLine = rule->m_lineNumber;
m_ruleId = rule->rule_id;
m_rev = rule->m_rev;
m_accuracy = rule->m_accuracy;
m_message = std::string("");
m_data = std::string("");
m_severity = 0;
m_ver = rule->m_ver;
m_maturity = 0;
m_accuracy = 0;
m_rule = rule;
};
RuleMessage(Rule *rule, std::string message) {
@ -106,12 +107,12 @@ class RuleMessage {
m_ruleLine = rule->m_lineNumber;
m_ruleId = rule->rule_id;
m_rev = rule->m_rev;
m_accuracy = rule->m_accuracy;
m_message = message;
m_data = std::string("");
m_severity = 0;
m_ver = rule->m_ver;
m_maturity = 0;
m_accuracy = 0;
m_rule = rule;
};

View File

@ -62,6 +62,7 @@ VARIABLES = \
ACTIONS = \
actions/accuracy.cc \
actions/action.cc \
actions/audit_log.cc \
actions/block.cc \

47
src/actions/accuracy.cc Normal file
View File

@ -0,0 +1,47 @@
/*
* 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/accuracy.h"
#include <iostream>
#include <string>
#include "actions/action.h"
#include "modsecurity/transaction.h"
#include "src/utils.h"
#include "modsecurity/rule.h"
#include "src/macro_expansion.h"
namespace modsecurity {
namespace actions {
Accuracy::Accuracy(std::string action)
: Action(action, ConfigurationKind),
m_accuracy_str(action) {
if (m_accuracy_str.at(0) == '\'') {
m_accuracy_str.erase(0, 1);
m_accuracy_str.pop_back();
}
m_accuracy = std::stoi(m_accuracy_str);
}
bool Accuracy::evaluate(Rule *rule, Transaction *transaction) {
rule->m_accuracy = m_accuracy;
return true;
}
} // namespace actions
} // namespace modsecurity

45
src/actions/accuracy.h Normal file
View File

@ -0,0 +1,45 @@
/*
* 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_ACCURACY_H_
#define SRC_ACTIONS_ACCURACY_H_
class Transaction;
namespace modsecurity {
class Transaction;
namespace actions {
class Accuracy : public Action {
public:
explicit Accuracy(std::string action);
bool evaluate(Rule *rule, Transaction *transaction) override;
private:
std::string m_accuracy_str;
int m_accuracy;
};
} // namespace actions
} // namespace modsecurity
#endif // SRC_ACTIONS_ACCURACY_H_

View File

@ -19,6 +19,7 @@ class Driver;
#include "modsecurity/modsecurity.h"
#include "actions/accuracy.h"
#include "actions/action.h"
#include "actions/audit_log.h"
#include "actions/ctl_audit_log_parts.h"
@ -60,6 +61,7 @@ class Driver;
using modsecurity::ModSecurity;
using modsecurity::actions::Accuracy;
using modsecurity::actions::Action;
using modsecurity::actions::CtlAuditLogParts;
using modsecurity::actions::InitCol;
@ -837,7 +839,7 @@ act:
}
| ACTION_ACCURACY
{
$$ = Action::instantiate($1);
$$ = new Accuracy($1);
}
| ACTION_EXEC
{

View File

@ -79,6 +79,7 @@ Rule::Rule(std::string marker)
op(NULL),
rule_id(0),
phase(-1),
m_accuracy(0),
m_unconditional(false),
m_secmarker(true),
m_marker(marker),