Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust nginx log level according to modsecurity severity level #243

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/ngx_http_modsecurity_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
intervention.log = NULL;
intervention.disruptive = 0;
ngx_http_modsecurity_ctx_t *ctx = NULL;
const char *severity;
ngx_uint_t ngxloglevel = NGX_LOG_ERR;

dd("processing intervention");

Expand All @@ -158,7 +160,52 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
log = "(no log message was specified)";
}

ngx_log_error(NGX_LOG_ERR, (ngx_log_t *)r->connection->log, 0, "%s", log);
// extract modsecurity severity level from message
severity = strstr(log, "[severity \"");

if(severity != NULL)
{
int loglevel;

loglevel = atoi(severity + strlen("[severity \""));

switch(loglevel)
{
case 0: //EMERGENCY: is generated from correlation of anomaly scoring data where there is an inbound attack and an outbound leakage.
ngxloglevel = NGX_LOG_EMERG; //Emergency error level
break;

case 1: //ALERT: is generated from correlation where there is an inbound attack and an outbound application level error.
ngxloglevel = NGX_LOG_ALERT; // Alert error level
break;

case 2: //CRITICAL: Anomaly Score of 5. Is the highest severity level possible without correlation. It is normally generated by the web attack rules (40 level files).
ngxloglevel = NGX_LOG_CRIT; // Critical error level
break;

case 3: //ERROR: Error - Anomaly Score of 4. Is generated mostly from outbound leakage rules (50 level files).
ngxloglevel = NGX_LOG_ERR; // Error level
break;

case 4: //WARNING: Anomaly Score of 3. Is generated by malicious client rules (35 level files).
ngxloglevel = NGX_LOG_WARN; // Warning level
break;

case 5: //NOTICE: Anomaly Score of 2. Is generated by the Protocol policy and anomaly files.
ngxloglevel = NGX_LOG_NOTICE; // Notice level
break;

case 6: //INFO
ngxloglevel = NGX_LOG_INFO; // Information level
break;

case 7: //DEBUG
ngxloglevel = NGX_LOG_DEBUG; // Debug level
break;
}
}

ngx_log_error(ngxloglevel, (ngx_log_t *)r->connection->log, 0, "%s", log);

if (intervention.log != NULL) {
free(intervention.log);
Expand Down