mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Expands log_cb to share ruleMessage structure instead text
Text version still available and it is the default options
This commit is contained in:
parent
9ea5b475b2
commit
e2af60e765
@ -323,6 +323,7 @@ AM_COND_IF([EXAMPLES],
|
|||||||
examples/simple_example_using_c/Makefile \
|
examples/simple_example_using_c/Makefile \
|
||||||
examples/multiprocess_c/Makefile \
|
examples/multiprocess_c/Makefile \
|
||||||
examples/reading_logs_with_offset/Makefile \
|
examples/reading_logs_with_offset/Makefile \
|
||||||
|
examples/reading_logs_via_rule_message/Makefile \
|
||||||
])])
|
])])
|
||||||
|
|
||||||
AM_COND_IF([AFL_FUZZER],
|
AM_COND_IF([AFL_FUZZER],
|
||||||
|
@ -5,7 +5,8 @@ ACLOCAL_AMFLAGS = -I build
|
|||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
simple_example_using_c \
|
simple_example_using_c \
|
||||||
multiprocess_c \
|
multiprocess_c \
|
||||||
reading_logs_with_offset
|
reading_logs_with_offset \
|
||||||
|
reading_logs_via_rule_message
|
||||||
|
|
||||||
# make clean
|
# make clean
|
||||||
CLEANFILES =
|
CLEANFILES =
|
||||||
|
40
examples/reading_logs_via_rule_message/Makefile.am
Normal file
40
examples/reading_logs_via_rule_message/Makefile.am
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
|
||||||
|
|
||||||
|
noinst_PROGRAMS = simple_request
|
||||||
|
|
||||||
|
simple_request_SOURCES = \
|
||||||
|
simple_request.cc
|
||||||
|
|
||||||
|
simple_request_LDADD = \
|
||||||
|
$(top_builddir)/src/.libs/libmodsecurity.a \
|
||||||
|
$(CURL_LDADD) \
|
||||||
|
$(GEOIP_LDFLAGS) $(GEOIP_LDADD) \
|
||||||
|
$(PCRE_LDADD) \
|
||||||
|
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
|
||||||
|
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
|
||||||
|
$(LIBXML2_LDADD) \
|
||||||
|
$(GLOBAL_LDADD)
|
||||||
|
|
||||||
|
|
||||||
|
simple_request_CPPFLAGS = \
|
||||||
|
$(GLOBAL_CFLAGS) \
|
||||||
|
-std=c++11 \
|
||||||
|
-I$(top_builddir)/headers \
|
||||||
|
-I$(top_builddir) \
|
||||||
|
-g \
|
||||||
|
-I../others \
|
||||||
|
-fPIC \
|
||||||
|
-O3 \
|
||||||
|
$(GEOIP_CFLAGS) \
|
||||||
|
$(GLOBAL_CPPFLAGS) \
|
||||||
|
$(MODSEC_NO_LOGS) \
|
||||||
|
$(YAJL_CFLAGS) \
|
||||||
|
$(LMDB_CFLAGS) \
|
||||||
|
$(PCRE_CFLAGS) \
|
||||||
|
$(LIBXML2_CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
MAINTAINERCLEANFILES = \
|
||||||
|
Makefile.in
|
||||||
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
|||||||
|
SecRule ARGS:param1 "test" "id:1,deny,phase:2,chain,msg:'test'"
|
||||||
|
SecRule ARGS:param1 "test" "log"
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
SecRuleEngine On
|
||||||
|
SecRule ARGS:param1 "test" "id:1,deny"
|
1
examples/reading_logs_via_rule_message/match.conf
Normal file
1
examples/reading_logs_via_rule_message/match.conf
Normal file
@ -0,0 +1 @@
|
|||||||
|
SecRule ARGS:param1 "test" "id:1,deny,msg:'this',msg:'is',msg:'a',msg:'test'"
|
1
examples/reading_logs_via_rule_message/no_match.conf
Normal file
1
examples/reading_logs_via_rule_message/no_match.conf
Normal file
@ -0,0 +1 @@
|
|||||||
|
SecRule ARGS:param1 "WHEEE" "id:1,phase:2,deny,msg:'this',msg:'is',msg:'a',msg:'test'"
|
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* 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 <memory>
|
||||||
|
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
|
|
||||||
|
#ifndef EXAMPLES_READING_LOGS_VIA_RULE_MESSAGE_READING_LOGS_VIA_RULE_MESSAGE_H_
|
||||||
|
#define EXAMPLES_READING_LOGS_VIA_RULE_MESSAGE_READING_LOGS_VIA_RULE_MESSAGE_H_
|
||||||
|
|
||||||
|
|
||||||
|
class ReadingLogsViaRuleMessage {
|
||||||
|
public:
|
||||||
|
ReadingLogsViaRuleMessage(char *request_header,
|
||||||
|
char *request_uri,
|
||||||
|
char *request_body,
|
||||||
|
char *response_headers,
|
||||||
|
char *response_body,
|
||||||
|
char *ip,
|
||||||
|
std::string rules) :
|
||||||
|
m_request_header(request_header),
|
||||||
|
m_request_uri(request_uri),
|
||||||
|
m_request_body(request_body),
|
||||||
|
m_response_headers(response_headers),
|
||||||
|
m_response_body(response_body),
|
||||||
|
m_ip(ip),
|
||||||
|
m_rules(rules)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
int process() {
|
||||||
|
modsecurity::ModSecurity *modsec;
|
||||||
|
modsecurity::Rules *rules;
|
||||||
|
modsecurity::ModSecurityIntervention it;
|
||||||
|
|
||||||
|
modsec = new modsecurity::ModSecurity();
|
||||||
|
modsec->setConnectorInformation("ModSecurity-test v0.0.1-alpha" \
|
||||||
|
" (ModSecurity test)");
|
||||||
|
modsec->setServerLogCb(logCb, modsecurity::RuleMessageLogProperty
|
||||||
|
| modsecurity::IncludeFullHighlightLogProperty);
|
||||||
|
|
||||||
|
rules = new modsecurity::Rules();
|
||||||
|
if (rules->loadFromUri(m_rules.c_str()) < 0) {
|
||||||
|
std::cout << "Problems loading the rules..." << std::endl;
|
||||||
|
std::cout << rules->m_parserError.str() << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
modsecurity::Transaction *modsecTransaction = \
|
||||||
|
new modsecurity::Transaction(modsec, rules, NULL);
|
||||||
|
modsecTransaction->processConnection(m_ip, 12345, "127.0.0.1", 80);
|
||||||
|
modsecTransaction->processURI(m_request_uri, "GET", "1.1");
|
||||||
|
|
||||||
|
modsecTransaction->addRequestHeader("Host",
|
||||||
|
"net.tutsplus.com");
|
||||||
|
modsecTransaction->processRequestHeaders();
|
||||||
|
modsecTransaction->processRequestBody();
|
||||||
|
modsecTransaction->addResponseHeader("HTTP/1.1",
|
||||||
|
"200 OK");
|
||||||
|
modsecTransaction->processResponseHeaders(200, "HTTP 1.2");
|
||||||
|
modsecTransaction->appendResponseBody(
|
||||||
|
(const unsigned char*)m_response_body,
|
||||||
|
strlen((const char*)m_response_body));
|
||||||
|
modsecTransaction->processResponseBody();
|
||||||
|
modsecTransaction->processLogging();
|
||||||
|
|
||||||
|
delete modsecTransaction;
|
||||||
|
delete rules;
|
||||||
|
delete modsec;
|
||||||
|
return 0;
|
||||||
|
end:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void logCb(void *data, const void *ruleMessagev) {
|
||||||
|
if (ruleMessagev == NULL) {
|
||||||
|
std::cout << "I've got a call but the message was null ;(";
|
||||||
|
std::cout << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modsecurity::RuleMessage *ruleMessage = \
|
||||||
|
reinterpret_cast<const modsecurity::RuleMessage *>(ruleMessagev);
|
||||||
|
|
||||||
|
std::cout << "Rule Id: " << std::to_string(ruleMessage->m_ruleId);
|
||||||
|
std::cout << " phase: " << std::to_string(ruleMessage->m_phase);
|
||||||
|
std::cout << std::endl;
|
||||||
|
if (ruleMessage->m_isDisruptive) {
|
||||||
|
std::cout << " * Disruptive action: ";
|
||||||
|
std::cout << modsecurity::RuleMessage::log(ruleMessage);
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::cout << " ** %d is meant to be informed by the webserver.";
|
||||||
|
std::cout << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << " * Match, but no disruptive action: ";
|
||||||
|
std::cout << modsecurity::RuleMessage::log(ruleMessage);
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
char *m_request_header;
|
||||||
|
char *m_request_uri;
|
||||||
|
char *m_request_body;
|
||||||
|
char *m_response_headers;
|
||||||
|
char *m_response_body;
|
||||||
|
char *m_ip;
|
||||||
|
std::string m_rules;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EXAMPLES_READING_LOGS_VIA_RULE_MESSAGE_READING_LOGS_VIA_RULE_MESSAGE_H_
|
77
examples/reading_logs_via_rule_message/simple_request.cc
Normal file
77
examples/reading_logs_via_rule_message/simple_request.cc
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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 <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <modsecurity/modsecurity.h>
|
||||||
|
#include <modsecurity/rules.h>
|
||||||
|
|
||||||
|
#include "examples/reading_logs_via_rule_message/reading_logs_via_rule_message.h"
|
||||||
|
|
||||||
|
char request_header[] = "" \
|
||||||
|
"GET /tutorials/other/top-20-mysql-best-practices/ HTTP/1.1\n\r" \
|
||||||
|
"Host: net.tutsplus.com\n\r" \
|
||||||
|
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5)" \
|
||||||
|
" Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)\n\r" \
|
||||||
|
"Accept: text/html,application/xhtml+xml,application/xml; " \
|
||||||
|
"q=0.9,*/*;q=0.8\n\r" \
|
||||||
|
"Accept-Language: en-us,en;q=0.5\n\r" \
|
||||||
|
"Accept-Encoding: gzip,deflate\n\r" \
|
||||||
|
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n\r" \
|
||||||
|
"Keep-Alive: 300\n\r" \
|
||||||
|
"Connection: keep-alive\n\r" \
|
||||||
|
"Cookie: PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120\n\r" \
|
||||||
|
"Pragma: no-cache\n\r" \
|
||||||
|
"Cache-Control: no-cache\n\r";
|
||||||
|
|
||||||
|
char request_uri[] = "/test.pl?param1=test¶2=test2";
|
||||||
|
|
||||||
|
char request_body[] = "";
|
||||||
|
|
||||||
|
char response_headers[] = "" \
|
||||||
|
"HTTP/1.1 200 OK\n\r" \
|
||||||
|
"Content-Type: text/xml; charset=utf-8\n\r" \
|
||||||
|
"Content-Length: length\n\r";
|
||||||
|
|
||||||
|
char response_body[] = "" \
|
||||||
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\r" \
|
||||||
|
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " \
|
||||||
|
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " \
|
||||||
|
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n\r" \
|
||||||
|
" <soap:Body>\n\r" \
|
||||||
|
" <EnlightenResponse xmlns=\"http://clearforest.com/\">\n\r" \
|
||||||
|
" <EnlightenResult>string</EnlightenResult>\n\r" \
|
||||||
|
" </EnlightenResponse>\n\r" \
|
||||||
|
" </soap:Body>\n\r" \
|
||||||
|
"</soap:Envelope>\n\r";
|
||||||
|
|
||||||
|
char ip[] = "200.249.12.31";
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
(*argv)++;
|
||||||
|
if (*argv == NULL) {
|
||||||
|
(*argv)--;
|
||||||
|
std::cout << "Use " << *argv << " test-case-file.conf";
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::string rules(*argv);
|
||||||
|
ReadingLogsViaRuleMessage rlvrm(request_header, request_uri, request_body,
|
||||||
|
response_headers, response_body, ip, rules);
|
||||||
|
rlvrm.process();
|
||||||
|
return 0;
|
||||||
|
}
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -62,7 +63,7 @@ class Action {
|
|||||||
Transaction *transaction);
|
Transaction *transaction);
|
||||||
virtual bool evaluate(Rule *rule, Transaction *transaction);
|
virtual bool evaluate(Rule *rule, Transaction *transaction);
|
||||||
virtual bool evaluate(Rule *rule, Transaction *transaction,
|
virtual bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *ruleMessage) {
|
std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
return evaluate(rule, transaction);
|
return evaluate(rule, transaction);
|
||||||
}
|
}
|
||||||
virtual bool init(std::string *error) { return true; }
|
virtual bool init(std::string *error) { return true; }
|
||||||
|
@ -77,6 +77,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -163,6 +164,8 @@ namespace modsecurity {
|
|||||||
*/
|
*/
|
||||||
NUMBER_OF_PHASES,
|
NUMBER_OF_PHASES,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace modsecurity
|
} // namespace modsecurity
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -198,17 +201,77 @@ namespace modsecurity {
|
|||||||
#define MODSECURITY_VERSION_NUM MODSECURITY_MAJOR \
|
#define MODSECURITY_VERSION_NUM MODSECURITY_MAJOR \
|
||||||
MODSECURITY_MINOR MODSECURITY_PATCHLEVEL MODSECURITY_TAG_NUM
|
MODSECURITY_MINOR MODSECURITY_PATCHLEVEL MODSECURITY_TAG_NUM
|
||||||
|
|
||||||
typedef void (*LogCb) (void *, const char *);
|
|
||||||
|
/*
|
||||||
|
* @name ModSecLogCb
|
||||||
|
* @brief Callback to be function on every log generation
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The callback is going to be called on every log request.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* void * Internal reference to be used by the API consumer. Whatever
|
||||||
|
* is set here will be passed on every call.
|
||||||
|
* void * Pointer to a const char * or RuleMessage class. The returned
|
||||||
|
* data is selected on the log register property.
|
||||||
|
*
|
||||||
|
* @note Vide LogProperty enum to learn more about Log Properties.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
typedef void (*ModSecLogCb) (void *, const void *);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
|
|
||||||
|
|
||||||
/* few forwarded declarations */
|
/* few forwarded declarations */
|
||||||
namespace actions {
|
namespace actions {
|
||||||
class Action;
|
class Action;
|
||||||
}
|
}
|
||||||
class Rule;
|
class Rule;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Properties used to configure the general log callback.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
enum LogProperty {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Original ModSecurity text log entry. The same entry that can be found
|
||||||
|
* within the Apache error_log (in the 2.x family)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
TextLogProperty = 1,
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Instead of return the text log entry an instance of the class
|
||||||
|
* RuleMessages is returned.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
RuleMessageLogProperty = 2,
|
||||||
|
/**
|
||||||
|
* This property only makes sense with the utilization of the
|
||||||
|
* RuleMessageLogProperty. Without this property set the RuleMessage
|
||||||
|
* structure will not be filled with the information of the hightlight.
|
||||||
|
*
|
||||||
|
* Notice that the highlight can be calculate post-analisys. Calculate it
|
||||||
|
* during the analisys may delay the analisys process.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
IncludeFullHighlightLogProperty = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** @ingroup ModSecurity_CPP_API */
|
/** @ingroup ModSecurity_CPP_API */
|
||||||
class ModSecurity {
|
class ModSecurity {
|
||||||
public:
|
public:
|
||||||
@ -217,8 +280,17 @@ class ModSecurity {
|
|||||||
|
|
||||||
static const std::string whoAmI();
|
static const std::string whoAmI();
|
||||||
void setConnectorInformation(std::string connector);
|
void setConnectorInformation(std::string connector);
|
||||||
void setServerLogCb(LogCb cb);
|
void setServerLogCb(ModSecLogCb cb);
|
||||||
void serverLog(void *data, const std::string& msg);
|
/**
|
||||||
|
*
|
||||||
|
* properties Properties to inform ModSecurity what kind of infornation
|
||||||
|
* is expected be returned.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void setServerLogCb(ModSecLogCb cb, int properties);
|
||||||
|
|
||||||
|
void serverLog(void *data, std::shared_ptr<RuleMessage> rm);
|
||||||
|
|
||||||
const std::string& getConnectorInformation();
|
const std::string& getConnectorInformation();
|
||||||
|
|
||||||
int processContentOffset(const char *content, size_t len,
|
int processContentOffset(const char *content, size_t len,
|
||||||
@ -232,7 +304,8 @@ class ModSecurity {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_connector;
|
std::string m_connector;
|
||||||
LogCb m_logCb;
|
ModSecLogCb m_logCb;
|
||||||
|
int m_logProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -249,7 +322,7 @@ const char *msc_who_am_i(ModSecurity *msc);
|
|||||||
/** @ingroup ModSecurity_C_API */
|
/** @ingroup ModSecurity_C_API */
|
||||||
void msc_set_connector_info(ModSecurity *msc, const char *connector);
|
void msc_set_connector_info(ModSecurity *msc, const char *connector);
|
||||||
/** @ingroup ModSecurity_C_API */
|
/** @ingroup ModSecurity_C_API */
|
||||||
void msc_set_log_cb(ModSecurity *msc, LogCb cb);
|
void msc_set_log_cb(ModSecurity *msc, ModSecLogCb cb);
|
||||||
/** @ingroup ModSecurity_C_API */
|
/** @ingroup ModSecurity_C_API */
|
||||||
void msc_cleanup(ModSecurity *msc);
|
void msc_cleanup(ModSecurity *msc);
|
||||||
|
|
||||||
|
@ -52,21 +52,21 @@ class Rule {
|
|||||||
explicit Rule(std::string marker);
|
explicit Rule(std::string marker);
|
||||||
~Rule();
|
~Rule();
|
||||||
|
|
||||||
bool evaluate(Transaction *transaction);
|
bool evaluate(Transaction *transaction, std::shared_ptr<RuleMessage> rm);
|
||||||
bool evaluateActions(Transaction *transaction);
|
bool evaluateActions(Transaction *transaction);
|
||||||
std::vector<std::unique_ptr<collection::Variable>>
|
std::vector<std::unique_ptr<collection::Variable>>
|
||||||
getFinalVars(Transaction *trasn);
|
getFinalVars(Transaction *trasn);
|
||||||
void executeActionsAfterFullMatch(Transaction *trasn,
|
void executeActionsAfterFullMatch(Transaction *trasn,
|
||||||
bool containsDisruptive, RuleMessage *ruleMessage);
|
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
|
||||||
|
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
std::list<std::pair<std::shared_ptr<std::string>,
|
||||||
std::shared_ptr<std::string>>> executeDefaultTransformations(
|
std::shared_ptr<std::string>>> executeDefaultTransformations(
|
||||||
Transaction *trasn, const std::string &value, bool multiMatch);
|
Transaction *trasn, const std::string &value, bool multiMatch);
|
||||||
|
|
||||||
bool executeOperatorAt(Transaction *trasn, std::string key,
|
bool executeOperatorAt(Transaction *trasn, std::string key,
|
||||||
std::string value, RuleMessage *rm);
|
std::string value, std::shared_ptr<RuleMessage> rm);
|
||||||
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
||||||
bool *b, RuleMessage *ruleMessage);
|
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
|
||||||
std::string resolveMatchMessage(std::string key, std::string value);
|
std::string resolveMatchMessage(std::string key, std::string value);
|
||||||
void updateMatchedVars(Transaction *trasn, std::string key,
|
void updateMatchedVars(Transaction *trasn, std::string key,
|
||||||
std::string value);
|
std::string value);
|
||||||
|
@ -34,47 +34,76 @@ namespace modsecurity {
|
|||||||
|
|
||||||
class RuleMessage {
|
class RuleMessage {
|
||||||
public:
|
public:
|
||||||
explicit RuleMessage(Rule *rule) :
|
explicit RuleMessage(Rule *rule, Transaction *trans) :
|
||||||
m_ruleFile(rule->m_fileName),
|
|
||||||
m_ruleLine(rule->m_lineNumber),
|
|
||||||
m_ruleId(rule->m_ruleId),
|
|
||||||
m_rev(rule->m_rev),
|
|
||||||
m_accuracy(rule->m_accuracy),
|
m_accuracy(rule->m_accuracy),
|
||||||
m_message(std::string("")),
|
m_clientIpAddress(trans->m_clientIpAddress),
|
||||||
m_data(std::string("")),
|
m_data(""),
|
||||||
m_severity(0),
|
m_disruptiveMessage(""),
|
||||||
m_ver(rule->m_ver),
|
m_id(trans->m_id),
|
||||||
|
m_isDisruptive(false),
|
||||||
|
m_match(""),
|
||||||
m_maturity(rule->m_maturity),
|
m_maturity(rule->m_maturity),
|
||||||
m_rule(rule),
|
m_message(""),
|
||||||
m_saveMessage(false),
|
|
||||||
m_noAuditLog(false),
|
m_noAuditLog(false),
|
||||||
m_match(std::string(""))
|
m_phase(rule->m_phase - 1),
|
||||||
|
m_reference(""),
|
||||||
|
m_rev(rule->m_rev),
|
||||||
|
m_rule(rule),
|
||||||
|
m_ruleFile(rule->m_fileName),
|
||||||
|
m_ruleId(rule->m_ruleId),
|
||||||
|
m_ruleLine(rule->m_lineNumber),
|
||||||
|
m_saveMessage(false),
|
||||||
|
m_serverIpAddress(trans->m_serverIpAddress),
|
||||||
|
m_severity(0),
|
||||||
|
m_uriNoQueryStringDecoded(trans->m_uri_no_query_string_decoded),
|
||||||
|
m_ver(rule->m_ver)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
std::string errorLog(Transaction *trans);
|
std::string errorLog() {
|
||||||
std::string disruptiveErrorLog(Transaction *trans, std::string log2);
|
return RuleMessage::errorLog(this);
|
||||||
std::string noClientErrorLog(Transaction *trans);
|
}
|
||||||
std::string errorLogTail(Transaction *trans);
|
std::string disruptiveErrorLog() {
|
||||||
|
return RuleMessage::disruptiveErrorLog(this);
|
||||||
|
}
|
||||||
|
std::string noClientErrorLog() {
|
||||||
|
return RuleMessage::noClientErrorLog(this);
|
||||||
|
}
|
||||||
|
std::string errorLogTail() {
|
||||||
|
return RuleMessage::errorLogTail(this);
|
||||||
|
}
|
||||||
|
std::string log() {
|
||||||
|
return RuleMessage::log(this);
|
||||||
|
}
|
||||||
|
static std::string disruptiveErrorLog(const RuleMessage *rm);
|
||||||
|
static std::string noClientErrorLog(const RuleMessage *rm);
|
||||||
|
static std::string errorLogTail(const RuleMessage *rm);
|
||||||
|
static std::string errorLog(const RuleMessage *rm);
|
||||||
|
static std::string log(const RuleMessage *rm);
|
||||||
|
|
||||||
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;
|
int m_accuracy;
|
||||||
|
std::string m_clientIpAddress;
|
||||||
|
std::string m_data;
|
||||||
|
std::string m_disruptiveMessage;
|
||||||
|
std::string m_id;
|
||||||
|
bool m_isDisruptive;
|
||||||
|
std::string m_match;
|
||||||
|
int m_maturity;
|
||||||
|
std::string m_message;
|
||||||
|
bool m_noAuditLog;
|
||||||
|
int m_phase;
|
||||||
std::string m_reference;
|
std::string m_reference;
|
||||||
|
std::string m_rev;
|
||||||
|
Rule *m_rule;
|
||||||
|
std::string m_ruleFile;
|
||||||
|
int m_ruleId;
|
||||||
|
int m_ruleLine;
|
||||||
|
bool m_saveMessage;
|
||||||
|
std::string m_serverIpAddress;
|
||||||
|
int m_severity;
|
||||||
|
std::string m_uriNoQueryStringDecoded;
|
||||||
|
std::string m_ver;
|
||||||
|
|
||||||
std::list<std::string> m_tags;
|
std::list<std::string> m_tags;
|
||||||
std::list<std::string> m_server_logs;
|
|
||||||
|
|
||||||
bool m_noAuditLog;
|
|
||||||
Rule *m_rule;
|
|
||||||
bool m_saveMessage;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ class Transaction : public TransactionAnchoredVariables {
|
|||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
void debug(int, std::string);
|
void debug(int, std::string);
|
||||||
#endif
|
#endif
|
||||||
void serverLog(const std::string& msg);
|
void serverLog(std::shared_ptr<RuleMessage> rm);
|
||||||
|
|
||||||
std::string toJSON(int parts);
|
std::string toJSON(int parts);
|
||||||
std::string toOldAuditLogFormat(int parts, const std::string &trailer);
|
std::string toOldAuditLogFormat(int parts, const std::string &trailer);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -26,7 +27,7 @@ namespace actions {
|
|||||||
|
|
||||||
|
|
||||||
bool AuditLog::evaluate(Rule *rule, Transaction *transaction,
|
bool AuditLog::evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) {
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
rm->m_noAuditLog = false;
|
rm->m_noAuditLog = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class AuditLog : public Action {
|
|||||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
|
|
||||||
@ -37,7 +38,8 @@ bool Status::init(std::string *error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Status::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Status::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
transaction->m_it.status = m_status;
|
transaction->m_it.status = m_status;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -36,8 +37,8 @@ class Status : public Action {
|
|||||||
m_status(0) { }
|
m_status(0) { }
|
||||||
|
|
||||||
bool init(std::string *error) override;
|
bool init(std::string *error) override;
|
||||||
bool evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm)
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
|
|
||||||
int m_status;
|
int m_status;
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
@ -29,7 +30,8 @@ namespace actions {
|
|||||||
namespace disruptive {
|
namespace disruptive {
|
||||||
|
|
||||||
|
|
||||||
bool Block::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Block::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
transaction->debug(8, "Marking request as disruptive.");
|
transaction->debug(8, "Marking request as disruptive.");
|
||||||
|
|
||||||
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
|
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -36,7 +37,7 @@ class Block : public Action {
|
|||||||
explicit Block(std::string action) : Action(action) { }
|
explicit Block(std::string action) : Action(action) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
bool isDisruptive() override { return true; }
|
bool isDisruptive() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
|
|
||||||
@ -27,7 +28,8 @@ namespace actions {
|
|||||||
namespace disruptive {
|
namespace disruptive {
|
||||||
|
|
||||||
|
|
||||||
bool Deny::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Deny::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
transaction->debug(8, "Running action deny");
|
transaction->debug(8, "Running action deny");
|
||||||
#endif
|
#endif
|
||||||
@ -41,11 +43,13 @@ bool Deny::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
|||||||
log.append(" (phase ");
|
log.append(" (phase ");
|
||||||
log.append(std::to_string(rm->m_rule->m_phase - 1) + "). ");
|
log.append(std::to_string(rm->m_rule->m_phase - 1) + "). ");
|
||||||
|
|
||||||
|
rm->m_disruptiveMessage.assign(log);
|
||||||
transaction->m_it.disruptive = true;
|
transaction->m_it.disruptive = true;
|
||||||
intervention::freeLog(&transaction->m_it);
|
intervention::freeLog(&transaction->m_it);
|
||||||
transaction->m_it.log = strdup(
|
transaction->m_it.log = strdup(
|
||||||
rm->disruptiveErrorLog(transaction, log).c_str());
|
rm->disruptiveErrorLog().c_str());
|
||||||
|
|
||||||
|
rm->m_isDisruptive = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -32,7 +33,7 @@ class Deny : public Action {
|
|||||||
explicit Deny(std::string action) : Action(action) { }
|
explicit Deny(std::string action) : Action(action) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
bool isDisruptive() override { return true; }
|
bool isDisruptive() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
@ -27,7 +28,8 @@ namespace actions {
|
|||||||
namespace disruptive {
|
namespace disruptive {
|
||||||
|
|
||||||
|
|
||||||
bool Pass::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Pass::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
intervention::free(&transaction->m_it);
|
intervention::free(&transaction->m_it);
|
||||||
intervention::reset(&transaction->m_it);
|
intervention::reset(&transaction->m_it);
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -30,8 +31,8 @@ class Pass : public Action {
|
|||||||
public:
|
public:
|
||||||
explicit Pass(std::string action) : Action(action) { }
|
explicit Pass(std::string action) : Action(action) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm)
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
bool isDisruptive() override { return true; }
|
bool isDisruptive() override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "src/macro_expansion.h"
|
#include "src/macro_expansion.h"
|
||||||
@ -36,7 +36,7 @@ bool Redirect::init(std::string *error) {
|
|||||||
|
|
||||||
|
|
||||||
bool Redirect::evaluate(Rule *rule, Transaction *transaction,
|
bool Redirect::evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) {
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
m_urlExpanded = MacroExpansion::expand(m_url, transaction);
|
m_urlExpanded = MacroExpansion::expand(m_url, transaction);
|
||||||
std::string log;
|
std::string log;
|
||||||
|
|
||||||
@ -48,13 +48,15 @@ bool Redirect::evaluate(Rule *rule, Transaction *transaction,
|
|||||||
log.append(" (phase ");
|
log.append(" (phase ");
|
||||||
log.append(std::to_string(rm->m_rule->m_phase - 1) + "). ");
|
log.append(std::to_string(rm->m_rule->m_phase - 1) + "). ");
|
||||||
|
|
||||||
|
rm->m_disruptiveMessage.assign(log);
|
||||||
intervention::freeUrl(&transaction->m_it);
|
intervention::freeUrl(&transaction->m_it);
|
||||||
transaction->m_it.url = strdup(m_urlExpanded.c_str());
|
transaction->m_it.url = strdup(m_urlExpanded.c_str());
|
||||||
transaction->m_it.disruptive = true;
|
transaction->m_it.disruptive = true;
|
||||||
intervention::freeLog(&transaction->m_it);
|
intervention::freeLog(&transaction->m_it);
|
||||||
transaction->m_it.log = strdup(
|
transaction->m_it.log = strdup(
|
||||||
rm->disruptiveErrorLog(transaction, log).c_str());
|
rm->disruptiveErrorLog().c_str());
|
||||||
|
|
||||||
|
rm->m_isDisruptive = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -39,8 +40,8 @@ class Redirect : public Action {
|
|||||||
m_urlExpanded(""),
|
m_urlExpanded(""),
|
||||||
m_url("") { }
|
m_url("") { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm)
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
bool init(std::string *error) override;
|
bool init(std::string *error) override;
|
||||||
bool isDisruptive() override { return true; }
|
bool isDisruptive() override { return true; }
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -27,7 +28,8 @@ namespace modsecurity {
|
|||||||
namespace actions {
|
namespace actions {
|
||||||
|
|
||||||
|
|
||||||
bool Log::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Log::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
transaction->debug(9, "Saving transaction to logs");
|
transaction->debug(9, "Saving transaction to logs");
|
||||||
rm->m_saveMessage = true;
|
rm->m_saveMessage = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -32,8 +33,8 @@ class Log : public Action {
|
|||||||
explicit Log(std::string action)
|
explicit Log(std::string action)
|
||||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm)
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace actions
|
} // namespace actions
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -29,7 +30,8 @@ namespace modsecurity {
|
|||||||
namespace actions {
|
namespace actions {
|
||||||
|
|
||||||
|
|
||||||
bool LogData::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool LogData::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
rm->m_data = data(transaction);
|
rm->m_data = data(transaction);
|
||||||
|
|
||||||
transaction->m_collections.storeOrUpdateFirst("RULE:logdata", rm->m_data);
|
transaction->m_collections.storeOrUpdateFirst("RULE:logdata", rm->m_data);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ class LogData : public Action {
|
|||||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
|
|
||||||
std::string data(Transaction *Transaction);
|
std::string data(Transaction *Transaction);
|
||||||
};
|
};
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -46,14 +47,14 @@ namespace modsecurity {
|
|||||||
namespace actions {
|
namespace actions {
|
||||||
|
|
||||||
|
|
||||||
bool Msg::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Msg::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
std::string msg = data(transaction);
|
std::string msg = data(transaction);
|
||||||
rm->m_message = msg;
|
rm->m_message = msg;
|
||||||
transaction->debug(9, "Saving msg: " + msg);
|
transaction->debug(9, "Saving msg: " + msg);
|
||||||
|
|
||||||
transaction->m_collections.storeOrUpdateFirst("RULE:msg", msg);
|
transaction->m_collections.storeOrUpdateFirst("RULE:msg", msg);
|
||||||
|
|
||||||
rm->m_server_logs.push_back(rm->errorLog(transaction));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -33,8 +34,8 @@ class Msg : public Action {
|
|||||||
explicit Msg(std::string action)
|
explicit Msg(std::string action)
|
||||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm)
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
|
|
||||||
std::string data(Transaction *Transaction);
|
std::string data(Transaction *Transaction);
|
||||||
};
|
};
|
||||||
|
@ -27,7 +27,7 @@ namespace actions {
|
|||||||
|
|
||||||
|
|
||||||
bool NoAuditLog::evaluate(Rule *rule, Transaction *transaction,
|
bool NoAuditLog::evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) {
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
rm->m_noAuditLog = true;
|
rm->m_noAuditLog = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class NoAuditLog : public Action {
|
|||||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace actions
|
} // namespace actions
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -28,7 +29,8 @@ namespace modsecurity {
|
|||||||
namespace actions {
|
namespace actions {
|
||||||
|
|
||||||
|
|
||||||
bool NoLog::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool NoLog::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
rm->m_saveMessage = false;
|
rm->m_saveMessage = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -32,8 +33,8 @@ class NoLog : public Action {
|
|||||||
explicit NoLog(std::string action)
|
explicit NoLog(std::string action)
|
||||||
: Action(action, RunTimeOnlyIfMatchKind) { }
|
: Action(action, RunTimeOnlyIfMatchKind) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm)
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace actions
|
} // namespace actions
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -70,7 +71,7 @@ bool Severity::init(std::string *error) {
|
|||||||
|
|
||||||
|
|
||||||
bool Severity::evaluate(Rule *rule, Transaction *transaction,
|
bool Severity::evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) {
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
transaction->debug(9, "This rule severity is: " + \
|
transaction->debug(9, "This rule severity is: " + \
|
||||||
std::to_string(this->m_severity) + " current transaction is: " + \
|
std::to_string(this->m_severity) + " current transaction is: " + \
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class Severity : public Action {
|
|||||||
m_severity(0) { }
|
m_severity(0) { }
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
bool init(std::string *error) override;
|
bool init(std::string *error) override;
|
||||||
|
|
||||||
int m_severity;
|
int m_severity;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -56,7 +57,8 @@ std::string Tag::getName(Transaction *transaction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Tag::evaluate(Rule *rule, Transaction *transaction, RuleMessage *rm) {
|
bool Tag::evaluate(Rule *rule, Transaction *transaction,
|
||||||
|
std::shared_ptr<RuleMessage> rm) {
|
||||||
std::string tag = getName(transaction);
|
std::string tag = getName(transaction);
|
||||||
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/actions/action.h"
|
#include "modsecurity/actions/action.h"
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class Tag : public Action {
|
|||||||
std::string getName(Transaction *transaction);
|
std::string getName(Transaction *transaction);
|
||||||
|
|
||||||
bool evaluate(Rule *rule, Transaction *transaction,
|
bool evaluate(Rule *rule, Transaction *transaction,
|
||||||
RuleMessage *rm) override;
|
std::shared_ptr<RuleMessage> rm) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ class Transformation : public Action {
|
|||||||
Transaction *transaction) override;
|
Transaction *transaction) override;
|
||||||
|
|
||||||
static Transformation* instantiate(std::string a);
|
static Transformation* instantiate(std::string a);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace transformations
|
} // namespace transformations
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "modsecurity/modsecurity.h"
|
#include "modsecurity/modsecurity.h"
|
||||||
#include "modsecurity/rule.h"
|
#include "modsecurity/rule.h"
|
||||||
|
#include "modsecurity/rule_message.h"
|
||||||
#include "src/collection/backend/in_memory-per_process.h"
|
#include "src/collection/backend/in_memory-per_process.h"
|
||||||
#include "src/collection/backend/lmdb.h"
|
#include "src/collection/backend/lmdb.h"
|
||||||
#include "src/config.h"
|
#include "src/config.h"
|
||||||
@ -166,12 +167,33 @@ const std::string& ModSecurity::getConnectorInformation() {
|
|||||||
return m_connector;
|
return m_connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModSecurity::serverLog(void *data, std::shared_ptr<RuleMessage> rm) {
|
||||||
void ModSecurity::serverLog(void *data, const std::string& msg) {
|
|
||||||
if (m_logCb == NULL) {
|
if (m_logCb == NULL) {
|
||||||
std::cout << "Server log callback is not set -- " << msg << std::endl;
|
std::cerr << "Server log callback is not set -- " << rm->errorLog();
|
||||||
} else {
|
std::cerr << std::endl;
|
||||||
m_logCb(data, msg.c_str());
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rm == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_logProperties & TextLogProperty) {
|
||||||
|
char *d = strdup(rm->log().c_str());
|
||||||
|
const void *a = static_cast<const void *>(d);
|
||||||
|
m_logCb(data, a);
|
||||||
|
free(d);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_logProperties & RuleMessageLogProperty) {
|
||||||
|
const void *a = static_cast<const void *>(rm.get());
|
||||||
|
if (m_logProperties & IncludeFullHighlightLogProperty) {
|
||||||
|
m_logCb(data, a);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_logCb(data, a);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,8 +377,14 @@ int ModSecurity::processContentOffset(const char *content, size_t len,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ModSecurity::setServerLogCb(LogCb cb) {
|
void ModSecurity::setServerLogCb(ModSecLogCb cb) {
|
||||||
m_logCb = (LogCb) cb;
|
setServerLogCb(cb, TextLogProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ModSecurity::setServerLogCb(ModSecLogCb cb, int properties) {
|
||||||
|
m_logCb = (ModSecLogCb) cb;
|
||||||
|
m_logProperties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -367,11 +395,11 @@ void ModSecurity::setServerLogCb(LogCb cb) {
|
|||||||
* connector should be called when logging is required.
|
* connector should be called when logging is required.
|
||||||
*
|
*
|
||||||
* @oarm msc The current ModSecurity instance
|
* @oarm msc The current ModSecurity instance
|
||||||
* @param LogCB The callback function to which a reference to the log msgs
|
* @param ModSecLogCb The callback function to which a reference to the log msgs
|
||||||
* will be passed.
|
* will be passed.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
extern "C" void msc_set_log_cb(ModSecurity *msc, LogCb cb) {
|
extern "C" void msc_set_log_cb(ModSecurity *msc, ModSecLogCb cb) {
|
||||||
msc->setServerLogCb(cb);
|
msc->setServerLogCb(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace operators {
|
|||||||
|
|
||||||
|
|
||||||
bool BeginsWith::evaluate(Transaction *transaction, Rule *rule,
|
bool BeginsWith::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) {
|
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
std::string p = MacroExpansion::expand(m_param, transaction);
|
std::string p = MacroExpansion::expand(m_param, transaction);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_BEGINS_WITH_H_
|
#define SRC_OPERATORS_BEGINS_WITH_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ class BeginsWith : public Operator {
|
|||||||
: Operator("BeginsWith", param) { }
|
: Operator("BeginsWith", param) { }
|
||||||
|
|
||||||
bool evaluate(Transaction *transaction, Rule *rule, const std::string &str,
|
bool evaluate(Transaction *transaction, Rule *rule, const std::string &str,
|
||||||
RuleMessage *ruleMessage) override;
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace operators
|
} // namespace operators
|
||||||
|
@ -23,7 +23,7 @@ namespace modsecurity {
|
|||||||
namespace operators {
|
namespace operators {
|
||||||
|
|
||||||
bool Contains::evaluate(Transaction *transaction, Rule *rule,
|
bool Contains::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) {
|
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
std::string p = MacroExpansion::expand(m_param, transaction);
|
std::string p = MacroExpansion::expand(m_param, transaction);
|
||||||
size_t offset = input.find(p);
|
size_t offset = input.find(p);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -35,7 +36,8 @@ class Contains : public Operator {
|
|||||||
explicit Contains(std::string param)
|
explicit Contains(std::string param)
|
||||||
: Operator("Contains", param) { }
|
: Operator("Contains", param) { }
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) override;
|
const std::string &str,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace operators
|
} // namespace operators
|
||||||
|
@ -38,7 +38,7 @@ bool ContainsWord::acceptableChar(const std::string& a, size_t pos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ContainsWord::evaluate(Transaction *transaction, Rule *rule,
|
bool ContainsWord::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) {
|
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
std::string paramTarget = MacroExpansion::expand(m_param, transaction);
|
std::string paramTarget = MacroExpansion::expand(m_param, transaction);
|
||||||
|
|
||||||
if (paramTarget.empty()) {
|
if (paramTarget.empty()) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_CONTAINS_WORD_H_
|
#define SRC_OPERATORS_CONTAINS_WORD_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
#include "modsecurity/rule_message.h"
|
#include "modsecurity/rule_message.h"
|
||||||
@ -32,7 +33,8 @@ class ContainsWord : public Operator {
|
|||||||
explicit ContainsWord(std::string param)
|
explicit ContainsWord(std::string param)
|
||||||
: Operator("ContainsWord", param) { }
|
: Operator("ContainsWord", param) { }
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) override;
|
const std::string &str,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
|
|
||||||
bool acceptableChar(const std::string& a, size_t pos);
|
bool acceptableChar(const std::string& a, size_t pos);
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ namespace operators {
|
|||||||
|
|
||||||
|
|
||||||
bool EndsWith::evaluate(Transaction *transaction, Rule *rule,
|
bool EndsWith::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) {
|
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
std::string p = MacroExpansion::expand(m_param, transaction);
|
std::string p = MacroExpansion::expand(m_param, transaction);
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_ENDS_WITH_H_
|
#define SRC_OPERATORS_ENDS_WITH_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -32,7 +33,8 @@ class EndsWith : public Operator {
|
|||||||
explicit EndsWith(std::string param)
|
explicit EndsWith(std::string param)
|
||||||
: Operator("EndsWith", param) { }
|
: Operator("EndsWith", param) { }
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) override;
|
const std::string &str,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "modsecurity/transaction.h"
|
#include "modsecurity/transaction.h"
|
||||||
@ -76,7 +76,7 @@ bool Operator::debug(Transaction *transaction, int x, std::string a) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Operator::evaluateInternal(Transaction *transaction,
|
bool Operator::evaluateInternal(Transaction *transaction,
|
||||||
Rule *rule, const std::string& a, RuleMessage *rm) {
|
Rule *rule, const std::string& a, std::shared_ptr<RuleMessage> rm) {
|
||||||
bool res = evaluate(transaction, rule, a, rm);
|
bool res = evaluate(transaction, rule, a, rm);
|
||||||
|
|
||||||
if (m_negation) {
|
if (m_negation) {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#ifndef SRC_OPERATORS_OPERATOR_H__
|
#ifndef SRC_OPERATORS_OPERATOR_H__
|
||||||
#define SRC_OPERATORS_OPERATOR_H__
|
#define SRC_OPERATORS_OPERATOR_H__
|
||||||
@ -63,7 +64,7 @@ class Operator {
|
|||||||
bool evaluateInternal(Transaction *t, Rule *rule,
|
bool evaluateInternal(Transaction *t, Rule *rule,
|
||||||
const std::string& a);
|
const std::string& a);
|
||||||
bool evaluateInternal(Transaction *t, Rule *rule,
|
bool evaluateInternal(Transaction *t, Rule *rule,
|
||||||
const std::string& a, RuleMessage *ruleMessage);
|
const std::string& a, std::shared_ptr<RuleMessage> ruleMessage);
|
||||||
|
|
||||||
|
|
||||||
virtual bool evaluate(Transaction *transaction, const std::string &str);
|
virtual bool evaluate(Transaction *transaction, const std::string &str);
|
||||||
@ -72,11 +73,12 @@ class Operator {
|
|||||||
return evaluate(transaction, str);
|
return evaluate(transaction, str);
|
||||||
}
|
}
|
||||||
virtual bool evaluate(Transaction *transaction, Rule *rule,
|
virtual bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) {
|
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
return evaluate(transaction, str);
|
return evaluate(transaction, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void logOffset(RuleMessage *ruleMessage, int offset, int len) {
|
static void logOffset(std::shared_ptr<RuleMessage> ruleMessage,
|
||||||
|
int offset, int len) {
|
||||||
if (ruleMessage) {
|
if (ruleMessage) {
|
||||||
ruleMessage->m_reference.append("o"
|
ruleMessage->m_reference.append("o"
|
||||||
+ std::to_string(offset) + ","
|
+ std::to_string(offset) + ","
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
#include "src/utils/acmp.h"
|
#include "src/utils/acmp.h"
|
||||||
@ -79,7 +80,7 @@ void Pm::postOrderTraversal(acmp_btree_node_t *node) {
|
|||||||
|
|
||||||
|
|
||||||
bool Pm::evaluate(Transaction *transaction, Rule *rule,
|
bool Pm::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) {
|
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
ACMPT pt;
|
ACMPT pt;
|
||||||
pt.parser = m_p;
|
pt.parser = m_p;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
#include "src/utils/acmp.h"
|
#include "src/utils/acmp.h"
|
||||||
@ -44,7 +45,8 @@ class Pm : public Operator {
|
|||||||
}
|
}
|
||||||
~Pm();
|
~Pm();
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) override;
|
const std::string &str,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
|
|
||||||
|
|
||||||
bool init(const std::string &file, std::string *error) override;
|
bool init(const std::string &file, std::string *error) override;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
#include "src/macro_expansion.h"
|
#include "src/macro_expansion.h"
|
||||||
@ -29,7 +30,7 @@ namespace operators {
|
|||||||
|
|
||||||
|
|
||||||
bool Rx::evaluate(Transaction *transaction, Rule *rule,
|
bool Rx::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string& input, RuleMessage *ruleMessage) {
|
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
SMatch match;
|
SMatch match;
|
||||||
std::list<SMatch> matches;
|
std::list<SMatch> matches;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
#include "src/utils/regex.h"
|
#include "src/utils/regex.h"
|
||||||
@ -59,7 +60,8 @@ class Rx : public Operator {
|
|||||||
return evaluate(transaction, NULL, input);
|
return evaluate(transaction, NULL, input);
|
||||||
}
|
}
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string& input, RuleMessage *ruleMessage) override;
|
const std::string& input,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Regex *m_re;
|
Regex *m_re;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "src/operators/validate_byte_range.h"
|
#include "src/operators/validate_byte_range.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ bool ValidateByteRange::init(const std::string &file,
|
|||||||
|
|
||||||
|
|
||||||
bool ValidateByteRange::evaluate(Transaction *transaction, Rule *rule,
|
bool ValidateByteRange::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) {
|
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -40,7 +41,8 @@ class ValidateByteRange : public Operator {
|
|||||||
~ValidateByteRange() override { }
|
~ValidateByteRange() override { }
|
||||||
|
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) override;
|
const std::string &input,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
bool getRange(const std::string &rangeRepresentation, std::string *error);
|
bool getRange(const std::string &rangeRepresentation, std::string *error);
|
||||||
bool init(const std::string& file, std::string *error) override;
|
bool init(const std::string& file, std::string *error) override;
|
||||||
private:
|
private:
|
||||||
|
@ -69,7 +69,7 @@ int ValidateUrlEncoding::validate_url_encoding(const char *input,
|
|||||||
|
|
||||||
|
|
||||||
bool ValidateUrlEncoding::evaluate(Transaction *transaction, Rule *rule,
|
bool ValidateUrlEncoding::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) {
|
const std::string &input, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
bool res = false;
|
bool res = false;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_VALIDATE_URL_ENCODING_H_
|
#define SRC_OPERATORS_VALIDATE_URL_ENCODING_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -33,7 +34,8 @@ class ValidateUrlEncoding : public Operator {
|
|||||||
: Operator("ValidateUrlEncoding") { }
|
: Operator("ValidateUrlEncoding") { }
|
||||||
|
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &input, RuleMessage *ruleMessage) override;
|
const std::string &input,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
int validate_url_encoding(const char *input, uint64_t input_length,
|
int validate_url_encoding(const char *input, uint64_t input_length,
|
||||||
size_t *offset);
|
size_t *offset);
|
||||||
};
|
};
|
||||||
|
@ -114,7 +114,7 @@ int ValidateUtf8Encoding::detect_utf8_character(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ValidateUtf8Encoding::evaluate(Transaction *transaction, Rule *rule,
|
bool ValidateUtf8Encoding::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) {
|
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
unsigned int i, bytes_left;
|
unsigned int i, bytes_left;
|
||||||
|
|
||||||
const char *str_c = str.c_str();
|
const char *str_c = str.c_str();
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_VALIDATE_UTF8_ENCODING_H_
|
#define SRC_OPERATORS_VALIDATE_UTF8_ENCODING_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -40,7 +41,8 @@ class ValidateUtf8Encoding : public Operator {
|
|||||||
: Operator("ValidateUtf8Encoding") { }
|
: Operator("ValidateUtf8Encoding") { }
|
||||||
|
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) override;
|
const std::string &str,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) override;
|
||||||
|
|
||||||
int detect_utf8_character(const unsigned char *p_read,
|
int detect_utf8_character(const unsigned char *p_read,
|
||||||
unsigned int length);
|
unsigned int length);
|
||||||
|
@ -25,7 +25,7 @@ namespace operators {
|
|||||||
|
|
||||||
|
|
||||||
bool Within::evaluate(Transaction *transaction, Rule *rule,
|
bool Within::evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage) {
|
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
bool res = false;
|
bool res = false;
|
||||||
std::string paramTarget = MacroExpansion::expand(m_param, transaction);
|
std::string paramTarget = MacroExpansion::expand(m_param, transaction);
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define SRC_OPERATORS_WITHIN_H_
|
#define SRC_OPERATORS_WITHIN_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ class Within : public Operator {
|
|||||||
explicit Within(std::string param)
|
explicit Within(std::string param)
|
||||||
: Operator("Within", param) { }
|
: Operator("Within", param) { }
|
||||||
bool evaluate(Transaction *transaction, Rule *rule,
|
bool evaluate(Transaction *transaction, Rule *rule,
|
||||||
const std::string &str, RuleMessage *ruleMessage);
|
const std::string &str, std::shared_ptr<RuleMessage> ruleMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace operators
|
} // namespace operators
|
||||||
|
42
src/rule.cc
42
src/rule.cc
@ -242,7 +242,7 @@ std::string Rule::resolveMatchMessage(std::string key, std::string value) {
|
|||||||
utils::string::limitTo(200, this->m_op->m_param) +
|
utils::string::limitTo(200, this->m_op->m_param) +
|
||||||
"' against variable `" + key + "' (Value: `" +
|
"' against variable `" + key + "' (Value: `" +
|
||||||
utils::string::limitTo(100, utils::string::toHexIfNeeded(value)) +
|
utils::string::limitTo(100, utils::string::toHexIfNeeded(value)) +
|
||||||
"' ) \" at " + key;
|
"' )";
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -250,7 +250,7 @@ std::string Rule::resolveMatchMessage(std::string key, std::string value) {
|
|||||||
|
|
||||||
|
|
||||||
void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
|
void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
|
||||||
bool *containsDisruptive, RuleMessage *ruleMessage) {
|
bool *containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
for (Action *a : this->m_actionsRuntimePos) {
|
for (Action *a : this->m_actionsRuntimePos) {
|
||||||
if (a->isDisruptive() == true) {
|
if (a->isDisruptive() == true) {
|
||||||
if (a->m_name == "pass") {
|
if (a->m_name == "pass") {
|
||||||
@ -272,7 +272,7 @@ void Rule::executeActionsIndependentOfChainedRuleResult(Transaction *trans,
|
|||||||
|
|
||||||
|
|
||||||
bool Rule::executeOperatorAt(Transaction *trans, std::string key,
|
bool Rule::executeOperatorAt(Transaction *trans, std::string key,
|
||||||
std::string value, RuleMessage *ruleMessage) {
|
std::string value, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
#if MSC_EXEC_CLOCK_ENABLED
|
#if MSC_EXEC_CLOCK_ENABLED
|
||||||
clock_t begin = clock();
|
clock_t begin = clock();
|
||||||
clock_t end;
|
clock_t end;
|
||||||
@ -524,7 +524,7 @@ std::vector<std::unique_ptr<collection::Variable>> Rule::getFinalVars(
|
|||||||
|
|
||||||
|
|
||||||
void Rule::executeActionsAfterFullMatch(Transaction *trans,
|
void Rule::executeActionsAfterFullMatch(Transaction *trans,
|
||||||
bool containsDisruptive, RuleMessage *ruleMessage) {
|
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
|
|
||||||
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
|
for (Action *a : trans->m_rules->m_defaultActions[this->m_phase]) {
|
||||||
if (a->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
|
if (a->action_kind != actions::Action::RunTimeOnlyIfMatchKind) {
|
||||||
@ -581,15 +581,20 @@ void Rule::executeActionsAfterFullMatch(Transaction *trans,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Rule::evaluate(Transaction *trans) {
|
bool Rule::evaluate(Transaction *trans,
|
||||||
|
std::shared_ptr<RuleMessage> ruleMessage) {
|
||||||
bool globalRet = false;
|
bool globalRet = false;
|
||||||
std::vector<Variable *> *variables = this->m_variables;
|
std::vector<Variable *> *variables = this->m_variables;
|
||||||
bool recursiveGlobalRet;
|
bool recursiveGlobalRet;
|
||||||
bool containsDisruptive = false;
|
bool containsDisruptive = false;
|
||||||
RuleMessage ruleMessage(this);
|
|
||||||
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
std::vector<std::unique_ptr<collection::Variable>> finalVars;
|
||||||
std::string eparam;
|
std::string eparam;
|
||||||
|
|
||||||
|
if (ruleMessage == NULL) {
|
||||||
|
ruleMessage = std::shared_ptr<RuleMessage>(
|
||||||
|
new RuleMessage(this, trans));
|
||||||
|
}
|
||||||
|
|
||||||
trans->m_matched.clear();
|
trans->m_matched.clear();
|
||||||
|
|
||||||
if (m_secMarker == true) {
|
if (m_secMarker == true) {
|
||||||
@ -599,7 +604,7 @@ bool Rule::evaluate(Transaction *trans) {
|
|||||||
trans->debug(4, "(Rule: " + std::to_string(m_ruleId) \
|
trans->debug(4, "(Rule: " + std::to_string(m_ruleId) \
|
||||||
+ ") Executing unconditional rule...");
|
+ ") Executing unconditional rule...");
|
||||||
executeActionsIndependentOfChainedRuleResult(trans,
|
executeActionsIndependentOfChainedRuleResult(trans,
|
||||||
&containsDisruptive, &ruleMessage);
|
&containsDisruptive, ruleMessage);
|
||||||
goto end_exec;
|
goto end_exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -646,17 +651,17 @@ bool Rule::evaluate(Transaction *trans) {
|
|||||||
bool ret;
|
bool ret;
|
||||||
std::string valueAfterTrans = std::move(*valueTemp.first);
|
std::string valueAfterTrans = std::move(*valueTemp.first);
|
||||||
|
|
||||||
ret = executeOperatorAt(trans, key, valueAfterTrans, &ruleMessage);
|
ret = executeOperatorAt(trans, key, valueAfterTrans, ruleMessage);
|
||||||
|
|
||||||
if (ret == true) {
|
if (ret == true) {
|
||||||
ruleMessage.m_match = resolveMatchMessage(key, value);
|
ruleMessage->m_match = resolveMatchMessage(key, value);
|
||||||
for (auto &i : v->m_orign) {
|
for (auto &i : v->m_orign) {
|
||||||
ruleMessage.m_reference.append(i->toText());
|
ruleMessage->m_reference.append(i->toText());
|
||||||
}
|
}
|
||||||
ruleMessage.m_reference.append(*valueTemp.second);
|
ruleMessage->m_reference.append(*valueTemp.second);
|
||||||
updateMatchedVars(trans, key, value);
|
updateMatchedVars(trans, key, value);
|
||||||
executeActionsIndependentOfChainedRuleResult(trans,
|
executeActionsIndependentOfChainedRuleResult(trans,
|
||||||
&containsDisruptive, &ruleMessage);
|
&containsDisruptive, ruleMessage);
|
||||||
globalRet = true;
|
globalRet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -681,7 +686,7 @@ bool Rule::evaluate(Transaction *trans) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trans->debug(4, "Executing chained rule.");
|
trans->debug(4, "Executing chained rule.");
|
||||||
recursiveGlobalRet = this->m_chainedRule->evaluate(trans);
|
recursiveGlobalRet = this->m_chainedRule->evaluate(trans, ruleMessage);
|
||||||
|
|
||||||
if (recursiveGlobalRet == true) {
|
if (recursiveGlobalRet == true) {
|
||||||
goto end_exec;
|
goto end_exec;
|
||||||
@ -691,13 +696,10 @@ end_clean:
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
end_exec:
|
end_exec:
|
||||||
executeActionsAfterFullMatch(trans, containsDisruptive, &ruleMessage);
|
executeActionsAfterFullMatch(trans, containsDisruptive, ruleMessage);
|
||||||
for (const auto &u : ruleMessage.m_server_logs) {
|
if (this->m_chained == false) {
|
||||||
trans->serverLog(u);
|
trans->serverLog(ruleMessage);
|
||||||
}
|
trans->m_rulesMessages.push_back(*ruleMessage);
|
||||||
|
|
||||||
if (ruleMessage.m_server_logs.size() > 0) {
|
|
||||||
trans->m_rulesMessages.push_back(ruleMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -23,79 +23,90 @@
|
|||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
|
|
||||||
std::string RuleMessage::disruptiveErrorLog(Transaction *trans,
|
std::string RuleMessage::disruptiveErrorLog(const RuleMessage *rm) {
|
||||||
std::string msg2) {
|
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
msg.append("[client " + std::string(trans->m_clientIpAddress) + "]");
|
msg.append("[client " + std::string(rm->m_clientIpAddress) + "]");
|
||||||
msg.append(" ModSecurity: ");
|
msg.append(" ModSecurity: ");
|
||||||
msg.append(msg2);
|
msg.append(rm->m_disruptiveMessage);
|
||||||
msg.append(m_match);
|
msg.append(rm->m_match);
|
||||||
msg.append(" [file \"" + std::string(m_ruleFile) + "\"]");
|
msg.append(" [file \"" + std::string(rm->m_ruleFile) + "\"]");
|
||||||
msg.append(" [line \"" + std::to_string(m_ruleLine) + "\"]");
|
msg.append(" [line \"" + std::to_string(rm->m_ruleLine) + "\"]");
|
||||||
msg.append(" [id \"" + std::to_string(m_ruleId) + "\"]");
|
msg.append(" [id \"" + std::to_string(rm->m_ruleId) + "\"]");
|
||||||
msg.append(" [rev \"" + m_rev + "\"]");
|
msg.append(" [rev \"" + rm->m_rev + "\"]");
|
||||||
msg.append(" [msg \"" + m_message + "\"]");
|
msg.append(" [msg \"" + rm->m_message + "\"]");
|
||||||
msg.append(" [data \"" + m_data + "\"]");
|
msg.append(" [data \"" + rm->m_data + "\"]");
|
||||||
msg.append(" [severity \"" +
|
msg.append(" [severity \"" +
|
||||||
std::to_string(m_severity) + "\"]");
|
std::to_string(rm->m_severity) + "\"]");
|
||||||
msg.append(" [ver \"" + m_ver + "\"]");
|
msg.append(" [ver \"" + rm->m_ver + "\"]");
|
||||||
msg.append(" [maturity \"" + std::to_string(m_maturity) + "\"]");
|
msg.append(" [maturity \"" + std::to_string(rm->m_maturity) + "\"]");
|
||||||
msg.append(" [accuracy \"" + std::to_string(m_accuracy) + "\"]");
|
msg.append(" [accuracy \"" + std::to_string(rm->m_accuracy) + "\"]");
|
||||||
for (auto &a : m_tags) {
|
for (auto &a : rm->m_tags) {
|
||||||
msg.append(" [tag \"" + a + "\"]");
|
msg.append(" [tag \"" + a + "\"]");
|
||||||
}
|
}
|
||||||
msg.append(" [hostname \"" + std::string(trans->m_serverIpAddress) \
|
msg.append(" [hostname \"" + std::string(rm->m_serverIpAddress) \
|
||||||
+ "\"]");
|
+ "\"]");
|
||||||
msg.append(" [uri \"" + trans->m_uri_no_query_string_decoded + "\"]");
|
msg.append(" [uri \"" + rm->m_uriNoQueryStringDecoded + "\"]");
|
||||||
msg.append(" [unique_id \"" + trans->m_id + "\"]");
|
msg.append(" [unique_id \"" + rm->m_id + "\"]");
|
||||||
msg.append(" [ref \"" + m_reference + "\"]");
|
msg.append(" [ref \"" + rm->m_reference + "\"]");
|
||||||
|
|
||||||
return modsecurity::utils::string::toHexIfNeeded(msg);
|
return modsecurity::utils::string::toHexIfNeeded(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string RuleMessage::noClientErrorLog(Transaction *trans) {
|
std::string RuleMessage::noClientErrorLog(const RuleMessage *rm) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
msg.append("ModSecurity: Warning. ");
|
msg.append("ModSecurity: Warning. ");
|
||||||
msg.append(m_match);
|
msg.append(rm->m_match);
|
||||||
msg.append(" [file \"" + std::string(m_ruleFile) + "\"]");
|
msg.append(" [file \"" + std::string(rm->m_ruleFile) + "\"]");
|
||||||
msg.append(" [line \"" + std::to_string(m_ruleLine) + "\"]");
|
msg.append(" [line \"" + std::to_string(rm->m_ruleLine) + "\"]");
|
||||||
msg.append(" [id \"" + std::to_string(m_ruleId) + "\"]");
|
msg.append(" [id \"" + std::to_string(rm->m_ruleId) + "\"]");
|
||||||
msg.append(" [rev \"" + m_rev + "\"]");
|
msg.append(" [rev \"" + rm->m_rev + "\"]");
|
||||||
msg.append(" [msg \"" + m_message + "\"]");
|
msg.append(" [msg \"" + rm->m_message + "\"]");
|
||||||
msg.append(" [data \"" + m_data + "\"]");
|
msg.append(" [data \"" + rm->m_data + "\"]");
|
||||||
msg.append(" [severity \"" +
|
msg.append(" [severity \"" +
|
||||||
std::to_string(m_severity) + "\"]");
|
std::to_string(rm->m_severity) + "\"]");
|
||||||
msg.append(" [ver \"" + m_ver + "\"]");
|
msg.append(" [ver \"" + rm->m_ver + "\"]");
|
||||||
msg.append(" [maturity \"" + std::to_string(m_maturity) + "\"]");
|
msg.append(" [maturity \"" + std::to_string(rm->m_maturity) + "\"]");
|
||||||
msg.append(" [accuracy \"" + std::to_string(m_accuracy) + "\"]");
|
msg.append(" [accuracy \"" + std::to_string(rm->m_accuracy) + "\"]");
|
||||||
for (auto &a : m_tags) {
|
for (auto &a : rm->m_tags) {
|
||||||
msg.append(" [tag \"" + a + "\"]");
|
msg.append(" [tag \"" + a + "\"]");
|
||||||
}
|
}
|
||||||
msg.append(" [ref \"" + m_reference + "\"]");
|
msg.append(" [ref \"" + rm->m_reference + "\"]");
|
||||||
|
|
||||||
return modsecurity::utils::string::toHexIfNeeded(msg);
|
return modsecurity::utils::string::toHexIfNeeded(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RuleMessage::errorLogTail(Transaction *trans) {
|
std::string RuleMessage::errorLogTail(const RuleMessage *rm) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
msg.append("[hostname \"" + std::string(trans->m_serverIpAddress) \
|
msg.append("[hostname \"" + std::string(rm->m_serverIpAddress) \
|
||||||
+ "\"]");
|
+ "\"]");
|
||||||
msg.append(" [uri \"" + trans->m_uri_no_query_string_decoded + "\"]");
|
msg.append(" [uri \"" + rm->m_uriNoQueryStringDecoded + "\"]");
|
||||||
msg.append(" [unique_id \"" + trans->m_id + "\"]");
|
msg.append(" [unique_id \"" + rm->m_id + "\"]");
|
||||||
|
|
||||||
return modsecurity::utils::string::toHexIfNeeded(msg);
|
return modsecurity::utils::string::toHexIfNeeded(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RuleMessage::errorLog(Transaction *trans) {
|
std::string RuleMessage::errorLog(const RuleMessage *rm) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
msg.append("[client " + std::string(trans->m_clientIpAddress) + "] ");
|
msg.append("[client " + std::string(rm->m_clientIpAddress) + "] ");
|
||||||
msg.append(noClientErrorLog(trans));
|
msg.append(noClientErrorLog(rm));
|
||||||
msg.append(" " + errorLogTail(trans));
|
msg.append(" " + errorLogTail(rm));
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RuleMessage::log(const RuleMessage *rm) {
|
||||||
|
std::string msg;
|
||||||
|
|
||||||
|
if (rm->m_isDisruptive) {
|
||||||
|
msg.append(disruptiveErrorLog(rm));
|
||||||
|
} else {
|
||||||
|
msg.append(errorLog(rm));
|
||||||
|
}
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ int Rules::evaluate(int phase, Transaction *transaction) {
|
|||||||
debug(9, "Skipped rule id '" + std::to_string(rule->m_ruleId) \
|
debug(9, "Skipped rule id '" + std::to_string(rule->m_ruleId) \
|
||||||
+ "'. Removed by an SecRuleRemove directive.");
|
+ "'. Removed by an SecRuleRemove directive.");
|
||||||
} else {
|
} else {
|
||||||
rule->evaluate(transaction);
|
rule->evaluate(transaction, NULL);
|
||||||
if (transaction->m_it.disruptive == true) {
|
if (transaction->m_it.disruptive == true) {
|
||||||
debug(8, "Skipping this phase as this " \
|
debug(8, "Skipping this phase as this " \
|
||||||
"request was already intercepted.");
|
"request was already intercepted.");
|
||||||
|
@ -1441,7 +1441,7 @@ std::string Transaction::toOldAuditLogFormat(int parts,
|
|||||||
if (parts & audit_log::AuditLog::HAuditLogPart) {
|
if (parts & audit_log::AuditLog::HAuditLogPart) {
|
||||||
audit_log << "--" << trailer << "-" << "H--" << std::endl;
|
audit_log << "--" << trailer << "-" << "H--" << std::endl;
|
||||||
for (auto a : m_rulesMessages) {
|
for (auto a : m_rulesMessages) {
|
||||||
audit_log << a.noClientErrorLog(this) << std::endl;
|
audit_log << a.noClientErrorLog() << std::endl;
|
||||||
}
|
}
|
||||||
audit_log << std::endl;
|
audit_log << std::endl;
|
||||||
/** TODO: write audit_log H part. */
|
/** TODO: write audit_log H part. */
|
||||||
@ -1658,8 +1658,8 @@ std::string Transaction::toJSON(int parts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Transaction::serverLog(const std::string& msg) {
|
void Transaction::serverLog(std::shared_ptr<RuleMessage> rm) {
|
||||||
m_ms->serverLog(m_logCbData, msg);
|
m_ms->serverLog(m_logCbData, rm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ char rules_file[] = "basic_rules.conf";
|
|||||||
|
|
||||||
#define NUM_REQUESTS 10000
|
#define NUM_REQUESTS 10000
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
modsecurity::ModSecurity *modsec;
|
modsecurity::ModSecurity *modsec;
|
||||||
|
@ -80,7 +80,8 @@ void actions(ModSecurityTestResults<RegressionTest> *r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void logCb(void *data, const char *msg) {
|
void logCb(void *data, const void *msgv) {
|
||||||
|
const char *msg = reinterpret_cast<const char*>(msgv);
|
||||||
std::stringstream *ss = (std::stringstream *) data;
|
std::stringstream *ss = (std::stringstream *) data;
|
||||||
*ss << msg << std::endl;
|
*ss << msg << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user