Adds support to MATCHED_VARS variable

This commit is contained in:
Felipe Zimmerle
2015-07-21 14:12:15 -03:00
parent 9d69501961
commit 09867791c7
5 changed files with 101 additions and 2 deletions

View File

@@ -1139,6 +1139,10 @@ bool Assay::update_variable_first(std::string var, const std::string &value) {
return false;
}
void Assay::delete_variable(std::string key) {
this->m_variables_strings.erase(key);
}
std::list<std::pair<std::string, std::string>>
Assay::resolve_variable(std::string var) {

View File

@@ -59,7 +59,7 @@ OPERATORNOARG (?i:@detectSQLi|@detectXSS|@geoLookup|@validateUrlEncoding|@valida
TRANSFORMATION t:(lowercase|urlDecodeUni|urlDecode|none|compressWhitespace|removeWhitespace|replaceNulls|removeNulls|htmlEntityDecode|jsDecode|cssDecode|trim)
VARIABLE (?i:MATCHED_VAR|INBOUND_DATA_ERROR|FULL_REQUEST|FILES|AUTH_TYPE|ARGS_NAMES|ARGS|QUERY_STRING|REMOTE_ADDR|REQUEST_BASENAME|REQUEST_BODY|REQUEST_COOKIES_NAMES|REQUEST_COOKIES|REQUEST_FILENAME|REQUEST_HEADERS_NAMES|REQUEST_HEADERS|REQUEST_METHOD|REQUEST_PROTOCOL|REQUEST_URI|RESPONSE_BODY|RESPONSE_CONTENT_LENGTH|RESPONSE_CONTENT_TYPE|RESPONSE_HEADERS_NAMES|RESPONSE_HEADERS|RESPONSE_PROTOCOL|RESPONSE_STATUS|TX|GEO)
VARIABLE (?i:MATCHED_VAR|MATCHED_VARS|INBOUND_DATA_ERROR|FULL_REQUEST|FILES|AUTH_TYPE|ARGS_NAMES|ARGS|QUERY_STRING|REMOTE_ADDR|REQUEST_BASENAME|REQUEST_BODY|REQUEST_COOKIES_NAMES|REQUEST_COOKIES|REQUEST_FILENAME|REQUEST_HEADERS_NAMES|REQUEST_HEADERS|REQUEST_METHOD|REQUEST_PROTOCOL|REQUEST_URI|RESPONSE_BODY|RESPONSE_CONTENT_LENGTH|RESPONSE_CONTENT_TYPE|RESPONSE_HEADERS_NAMES|RESPONSE_HEADERS|RESPONSE_PROTOCOL|RESPONSE_STATUS|TX|GEO)
RUN_TIME_VAR_DUR (?i:DURATION)
RUN_TIME_VAR_ENV (?i:ENV)
RUN_TIME_VAR_BLD (?i:MODSEC_BUILD)

View File

@@ -113,15 +113,19 @@ bool Rule::evaluate(Assay *assay) {
assay->debug(4, "Running action: " + a->action);
a->evaluate(assay);
}
if (this->chained && this->chainedRule == NULL) {
assay->debug(4, "Rule is marked as chained but there isn't a subsequent rule.");
}
if (this->chained && this->chainedRule != NULL) {
assay->debug(4, "Executing chained rule.");
if (assay->update_variable_first("MATCHED_VAR",
value) == false) {
assay->store_variable("MATCHED_VAR", value);
}
assay->store_variable("MATCHED_VARS:" + v.first, value);
this->chainedRule->evaluate(assay);
assay->update_variable_first("MATCHED_VAR", "");
assay->delete_variable("MATCHED_VARS:" + v.first);
}
} else {
assay->debug(4, "Rule returned 0.");