mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Moves RuleMessage to its own file
This commit is contained in:
parent
ac4cb53d09
commit
768cc74f0e
@ -97,87 +97,6 @@ class Rule {
|
|||||||
int m_referenceCount;
|
int m_referenceCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RuleMessage {
|
|
||||||
public:
|
|
||||||
explicit RuleMessage(Rule *rule) :
|
|
||||||
m_ruleFile(rule->m_fileName),
|
|
||||||
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(rule->m_maturity),
|
|
||||||
m_rule(rule),
|
|
||||||
m_saveMessage(false),
|
|
||||||
m_match(std::string(""))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
RuleMessage(Rule *rule, std::string message) :
|
|
||||||
m_ruleFile(rule->m_fileName),
|
|
||||||
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(rule->m_maturity),
|
|
||||||
m_rule(rule),
|
|
||||||
m_saveMessage(false),
|
|
||||||
m_match(std::string(""))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
std::string errorLog(Transaction *trans) {
|
|
||||||
std::string msg;
|
|
||||||
|
|
||||||
msg.append("[client " + std::string(trans->m_clientIpAddress) + "]");
|
|
||||||
msg.append(" ModSecurity: Warning. ");
|
|
||||||
msg.append(m_match);
|
|
||||||
msg.append(" [file \"" + std::string(m_ruleFile) + "\"]");
|
|
||||||
msg.append(" [line \"" + std::to_string(m_ruleLine) + "\"]");
|
|
||||||
msg.append(" [id \"" + std::to_string(m_ruleId) + "\"]");
|
|
||||||
msg.append(" [rev \"" + m_rev + "\"]");
|
|
||||||
msg.append(" [msg \"" + m_message + "\"]");
|
|
||||||
msg.append(" [data \"" + m_data + "\"]");
|
|
||||||
msg.append(" [severity \"" +
|
|
||||||
std::to_string(m_severity) + "\"]");
|
|
||||||
msg.append(" [ver \"" + m_ver + "\"]");
|
|
||||||
msg.append(" [maturity \"" + std::to_string(m_maturity) + "\"]");
|
|
||||||
msg.append(" [accuracy \"" + std::to_string(m_accuracy) + "\"]");
|
|
||||||
for (auto &a : m_tags) {
|
|
||||||
msg.append(" [tag \"" + a + "\"]");
|
|
||||||
}
|
|
||||||
msg.append(" [hostname \"" + std::string(trans->m_serverIpAddress) \
|
|
||||||
+ "\"]");
|
|
||||||
msg.append(" [uri \"" + std::string(trans->m_uri) + "\"]");
|
|
||||||
msg.append(" [unique_id \"" + trans->m_id + "\"]");
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string m_match;
|
|
||||||
std::string m_ruleFile;
|
|
||||||
int m_ruleLine;
|
|
||||||
int m_ruleId;
|
|
||||||
std::string m_message;
|
|
||||||
std::string m_data;
|
|
||||||
int m_severity;
|
|
||||||
std::string m_ver;
|
|
||||||
std::string m_rev;
|
|
||||||
int m_maturity;
|
|
||||||
int m_accuracy;
|
|
||||||
|
|
||||||
std::list<std::string> m_tags;
|
|
||||||
|
|
||||||
Rule *m_rule;
|
|
||||||
bool m_saveMessage;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace modsecurity
|
} // namespace modsecurity
|
||||||
#endif
|
#endif
|
||||||
|
94
headers/modsecurity/rule_message.h
Normal file
94
headers/modsecurity/rule_message.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <stack>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HEADERS_MODSECURITY_RULE_MESSAGE_H_
|
||||||
|
#define HEADERS_MODSECURITY_RULE_MESSAGE_H_
|
||||||
|
|
||||||
|
#include "modsecurity/transaction.h"
|
||||||
|
#include "modsecurity/rule.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
namespace modsecurity {
|
||||||
|
|
||||||
|
class RuleMessage {
|
||||||
|
public:
|
||||||
|
explicit RuleMessage(Rule *rule) :
|
||||||
|
m_ruleFile(rule->m_fileName),
|
||||||
|
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(rule->m_maturity),
|
||||||
|
m_rule(rule),
|
||||||
|
m_saveMessage(false),
|
||||||
|
m_match(std::string(""))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
RuleMessage(Rule *rule, std::string message) :
|
||||||
|
m_ruleFile(rule->m_fileName),
|
||||||
|
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(rule->m_maturity),
|
||||||
|
m_rule(rule),
|
||||||
|
m_saveMessage(false),
|
||||||
|
m_match(std::string(""))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
std::string errorLog(Transaction *trans);
|
||||||
|
|
||||||
|
|
||||||
|
std::string m_match;
|
||||||
|
std::string m_ruleFile;
|
||||||
|
int m_ruleLine;
|
||||||
|
int m_ruleId;
|
||||||
|
std::string m_message;
|
||||||
|
std::string m_data;
|
||||||
|
int m_severity;
|
||||||
|
std::string m_ver;
|
||||||
|
std::string m_rev;
|
||||||
|
int m_maturity;
|
||||||
|
int m_accuracy;
|
||||||
|
|
||||||
|
std::list<std::string> m_tags;
|
||||||
|
|
||||||
|
Rule *m_rule;
|
||||||
|
bool m_saveMessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace modsecurity
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // HEADERS_MODSECURITY_RULE_MESSAGE_H_
|
@ -253,6 +253,7 @@ libmodsecurity_la_SOURCES = \
|
|||||||
debug_log_writer.cc \
|
debug_log_writer.cc \
|
||||||
macro_expansion.cc \
|
macro_expansion.cc \
|
||||||
rule.cc \
|
rule.cc \
|
||||||
|
rule_message.cc \
|
||||||
unique_id.cc \
|
unique_id.cc \
|
||||||
rules_exceptions.cc \
|
rules_exceptions.cc \
|
||||||
${BODY_PROCESSORS} \
|
${BODY_PROCESSORS} \
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include "actions/action.h"
|
#include "actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "operators/operator.h"
|
#include "operators/operator.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
namespace actions {
|
namespace actions {
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "src/macro_expansion.h"
|
#include "src/macro_expansion.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
namespace actions {
|
namespace actions {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "actions/action.h"
|
#include "actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "operators/operator.h"
|
#include "operators/operator.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
#include "utils/msc_string.h"
|
#include "utils/msc_string.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
|
|
||||||
using modsecurity::utils::String;
|
using modsecurity::utils::String;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "src/macro_expansion.h"
|
#include "src/macro_expansion.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description: Assigns a tag (category) to a rule or a chain.
|
* Description: Assigns a tag (category) to a rule or a chain.
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "variables/variations/exclusion.h"
|
#include "variables/variations/exclusion.h"
|
||||||
#include "utils/msc_string.h"
|
#include "utils/msc_string.h"
|
||||||
#include "modsecurity/rules.h"
|
#include "modsecurity/rules.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
#include "src/macro_expansion.h"
|
#include "src/macro_expansion.h"
|
||||||
|
|
||||||
|
|
||||||
|
54
src/rule_message.cc
Normal file
54
src/rule_message.cc
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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 "modsecurity/rules.h"
|
||||||
|
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
|
#include "modsecurity/modsecurity.h"
|
||||||
|
#include "modsecurity/transaction.h"
|
||||||
|
#include "src/utils/msc_string.h"
|
||||||
|
|
||||||
|
namespace modsecurity {
|
||||||
|
|
||||||
|
std::string RuleMessage::errorLog(Transaction *trans) {
|
||||||
|
std::string msg;
|
||||||
|
|
||||||
|
msg.append("[client " + std::string(trans->m_clientIpAddress) + "]");
|
||||||
|
msg.append(" ModSecurity: Warning. ");
|
||||||
|
msg.append(m_match);
|
||||||
|
msg.append(" [file \"" + std::string(m_ruleFile) + "\"]");
|
||||||
|
msg.append(" [line \"" + std::to_string(m_ruleLine) + "\"]");
|
||||||
|
msg.append(" [id \"" + std::to_string(m_ruleId) + "\"]");
|
||||||
|
msg.append(" [rev \"" + m_rev + "\"]");
|
||||||
|
msg.append(" [msg \"" + m_message + "\"]");
|
||||||
|
msg.append(" [data \"" + m_data + "\"]");
|
||||||
|
msg.append(" [severity \"" +
|
||||||
|
std::to_string(m_severity) + "\"]");
|
||||||
|
msg.append(" [ver \"" + m_ver + "\"]");
|
||||||
|
msg.append(" [maturity \"" + std::to_string(m_maturity) + "\"]");
|
||||||
|
msg.append(" [accuracy \"" + std::to_string(m_accuracy) + "\"]");
|
||||||
|
for (auto &a : m_tags) {
|
||||||
|
msg.append(" [tag \"" + a + "\"]");
|
||||||
|
}
|
||||||
|
msg.append(" [hostname \"" + std::string(trans->m_serverIpAddress) \
|
||||||
|
+ "\"]");
|
||||||
|
msg.append(" [uri \"" + std::string(trans->m_uri) + "\"]");
|
||||||
|
msg.append(" [unique_id \"" + trans->m_id + "\"]");
|
||||||
|
|
||||||
|
return modsecurity::utils::String::toHexIfNeeded(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace modsecurity
|
@ -46,6 +46,7 @@
|
|||||||
#include "utils/decode.h"
|
#include "utils/decode.h"
|
||||||
#include "utils/random.h"
|
#include "utils/random.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
#include "modsecurity/rules_properties.h"
|
#include "modsecurity/rules_properties.h"
|
||||||
#include "src/actions/allow.h"
|
#include "src/actions/allow.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user