# ------------------------------------------------------------------------
# OWASP ModSecurity Core Rule Set ver.3.3.9
# Copyright (c) 2006-2020 Trustwave and contributors. All rights reserved.
# Copyright (c) 2021-2026 Core Rule Set project. All rights reserved.
#
# The OWASP ModSecurity Core Rule Set is distributed under
# Apache Software License (ASL) version 2
# Please see the enclosed LICENSE file for full details.
# ------------------------------------------------------------------------

#
# This file is used in post processing after the response has been sent to
# the client (in the logging phase).  Its purpose is to provide inbound+outbound
# correlation of events to provide a more intelligent designation as to the outcome
# or result of the transaction - meaning, was this a successful attack?
#

#
# -= Paranoia Level 0 (empty) =- (apply unconditionally)
#

#
# -=[ Correlated Successful Attack ]=-
#
SecRule &TX:'/LEAKAGE\\\/ERRORS/' "@ge 1" \
    "id:980100,\
    phase:5,\
    pass,\
    t:none,\
    log,\
    msg:'Correlated Successful Attack Identified: (Total Score: %{tx.anomaly_score}) Inbound Attack (Inbound Anomaly Score: %{TX.INBOUND_ANOMALY_SCORE}) + Outbound Data Leakage (Outbound Anomaly Score: %{TX.OUTBOUND_ANOMALY_SCORE})',\
    tag:'event-correlation',\
    ver:'OWASP_CRS/3.3.9',\
    severity:'EMERGENCY',\
    chain,\
    skipAfter:END-CORRELATION"
    SecRule &TX:'/WEB_ATTACK/' "@ge 1" "t:none"

#
# -=[ Correlated Attack Attempt ]=-
#
SecRule &TX:'/AVAILABILITY\\\/APP_NOT_AVAIL/' "@ge 1" \
    "id:980110,\
    phase:5,\
    pass,\
    t:none,\
    log,\
    msg:'Correlated Attack Attempt Identified: (Total Score: %{tx.anomaly_score}) Inbound Attack (Inbound Anomaly Score: %{TX.INBOUND_ANOMALY_SCORE}) + Outbound Application Error (Outbound Anomaly Score: %{TX.OUTBOUND_ANOMALY_SCORE})',\
    tag:'event-correlation',\
    ver:'OWASP_CRS/3.3.9',\
    severity:'ALERT',\
    chain,\
    skipAfter:END-CORRELATION"
    SecRule &TX:'/WEB_ATTACK/' "@ge 1" "t:none"

# Creating a total sum of all triggered inbound rules, including the ones only being monitored
SecAction \
    "id:980115,\
    phase:5,\
    pass,\
    t:none,\
    nolog,\
    noauditlog,\
    ver:'OWASP_CRS/3.3.9',\
    setvar:'tx.executing_anomaly_score=%{tx.anomaly_score_pl1}',\
    setvar:'tx.executing_anomaly_score=+%{tx.anomaly_score_pl2}',\
    setvar:'tx.executing_anomaly_score=+%{tx.anomaly_score_pl3}',\
    setvar:'tx.executing_anomaly_score=+%{tx.anomaly_score_pl4}'"

SecRule TX:INBOUND_ANOMALY_SCORE "@lt %{tx.inbound_anomaly_score_threshold}" \
    "id:980120,\
    phase:5,\
    pass,\
    t:none,\
    log,\
    noauditlog,\
    msg:'Inbound Anomaly Score (Total Inbound Score: %{TX.INBOUND_ANOMALY_SCORE} - SQLI=%{tx.sql_injection_score},XSS=%{tx.xss_score},RFI=%{tx.rfi_score},LFI=%{tx.lfi_score},RCE=%{tx.rce_score},PHPI=%{tx.php_injection_score},HTTP=%{tx.http_violation_score},SESS=%{tx.session_fixation_score}): individual paranoia level scores: %{TX.ANOMALY_SCORE_PL1}, %{TX.ANOMALY_SCORE_PL2}, %{TX.ANOMALY_SCORE_PL3}, %{TX.ANOMALY_SCORE_PL4}',\
    tag:'event-correlation',\
    ver:'OWASP_CRS/3.3.9',\
    chain"
    SecRule TX:MONITOR_ANOMALY_SCORE "@gt 1"

SecRule TX:INBOUND_ANOMALY_SCORE "@ge %{tx.inbound_anomaly_score_threshold}" \
    "id:980130,\
    phase:5,\
    pass,\
    t:none,\
    log,\
    noauditlog,\
    msg:'Inbound Anomaly Score Exceeded (Total Inbound Score: %{TX.INBOUND_ANOMALY_SCORE} - SQLI=%{tx.sql_injection_score},XSS=%{tx.xss_score},RFI=%{tx.rfi_score},LFI=%{tx.lfi_score},RCE=%{tx.rce_score},PHPI=%{tx.php_injection_score},HTTP=%{tx.http_violation_score},SESS=%{tx.session_fixation_score}): individual paranoia level scores: %{TX.ANOMALY_SCORE_PL1}, %{TX.ANOMALY_SCORE_PL2}, %{TX.ANOMALY_SCORE_PL3}, %{TX.ANOMALY_SCORE_PL4}',\
    tag:'event-correlation',\
    ver:'OWASP_CRS/3.3.9'"

SecRule TX:OUTBOUND_ANOMALY_SCORE "@ge %{tx.outbound_anomaly_score_threshold}" \
    "id:980140,\
    phase:5,\
    pass,\
    t:none,\
    log,\
    noauditlog,\
    msg:'Outbound Anomaly Score Exceeded (score %{TX.OUTBOUND_ANOMALY_SCORE}): individual paranoia level scores: %{TX.OUTBOUND_ANOMALY_SCORE_PL1}, %{TX.OUTBOUND_ANOMALY_SCORE_PL2}, %{TX.OUTBOUND_ANOMALY_SCORE_PL3}, %{TX.OUTBOUND_ANOMALY_SCORE_PL4}',\
    tag:'event-correlation',\
    ver:'OWASP_CRS/3.3.9'"

# Creating a total sum of all triggered outbound rules, including the ones only being monitored
SecAction \
    "id:980145,\
    phase:5,\
    pass,\
    t:none,\
    nolog,\
    noauditlog,\
    ver:'OWASP_CRS/3.3.9',\
    setvar:'tx.executing_anomaly_score=%{tx.outbound_anomaly_score_pl1}',\
    setvar:'tx.executing_anomaly_score=+%{tx.outbound_anomaly_score_pl2}',\
    setvar:'tx.executing_anomaly_score=+%{tx.outbound_anomaly_score_pl3}',\
    setvar:'tx.executing_anomaly_score=+%{tx.outbound_anomaly_score_pl4}'"

SecRule TX:OUTBOUND_ANOMALY_SCORE "@lt %{tx.outbound_anomaly_score_threshold}" \
    "id:980150,\
    phase:5,\
    pass,\
    t:none,\
    log,\
    noauditlog,\
    msg:'Outbound Anomaly Score (Total Outbound Score: %{TX.OUTBOUND_ANOMALY_SCORE}): individual paranoia level scores: %{TX.OUTBOUND_ANOMALY_SCORE_PL1}, %{TX.OUTBOUND_ANOMALY_SCORE_PL2}, %{TX.OUTBOUND_ANOMALY_SCORE_PL3}, %{TX.OUTBOUND_ANOMALY_SCORE_PL4}',\
    tag:'event-correlation',\
    ver:'OWASP_CRS/3.3.9',\
    chain"
    SecRule TX:MONITOR_ANOMALY_SCORE "@gt 1"

SecMarker "END-CORRELATION"


SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 1" "id:980011,phase:1,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 1" "id:980012,phase:2,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
#
# -= Paranoia Level 1 (default) =- (apply only when tx.executing_paranoia_level is sufficiently high: 1 or higher)
#



SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 2" "id:980013,phase:1,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 2" "id:980014,phase:2,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
#
# -= Paranoia Level 2 =- (apply only when tx.executing_paranoia_level is sufficiently high: 2 or higher)
#



SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 3" "id:980015,phase:1,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 3" "id:980016,phase:2,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
#
# -= Paranoia Level 3 =- (apply only when tx.executing_paranoia_level is sufficiently high: 3 or higher)
#



SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 4" "id:980017,phase:1,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
SecRule TX:EXECUTING_PARANOIA_LEVEL "@lt 4" "id:980018,phase:2,pass,nolog,skipAfter:END-RESPONSE-980-CORRELATION"
#
# -= Paranoia Level 4 =- (apply only when tx.executing_paranoia_level is sufficiently high: 4 or higher)
#



#
# -= Paranoia Levels Finished =-
#
SecMarker "END-RESPONSE-980-CORRELATION"
