1 # ---------------------------------------------------------------
2 # Core ModSecurity Rule Set ver.2.2.6
3 # Copyright (C) 2006-2012 Trustwave All rights reserved.
5 # The OWASP ModSecurity Core Rule Set is distributed under
6 # Apache Software License (ASL) version 2
7 # Please see the enclosed LICENCE file for full details.
8 # ---------------------------------------------------------------
12 # -- [[ Recommended Base Configuration ]] -------------------------------------------------
14 # The configuration directives/settings in this file are used to control
15 # the OWASP ModSecurity CRS. These settings do **NOT** configure the main
16 # ModSecurity settings such as:
19 # - SecRequestBodyAccess
23 # You should use the modsecurity.conf-recommended file that comes with the
24 # ModSecurity source code archive.
26 # Ref: http://mod-security.svn.sourceforge.net/viewvc/mod-security/m2/trunk/modsecurity.conf-recommended
31 # -- [[ Rule Version ]] -------------------------------------------------------------------
33 # Rule version data is added to the "Producer" line of Section H of the Audit log:
35 # - Producer: ModSecurity for Apache/2.7.0-rc1 (http://www.modsecurity.org/); OWASP_CRS/2.2.4.
37 # Ref: https://sourceforge.net/apps/mediawiki/mod-security/index.php?title=Reference_Manual#SecComponentSignature
39 SecComponentSignature "OWASP_CRS/2.2.6"
43 # -- [[ Modes of Operation: Self-Contained vs. Collaborative Detection ]] -----------------
45 # Each detection rule uses the "block" action which will inherit the SecDefaultAction
46 # specified below. Your settings here will determine which mode of operation you use.
48 # -- [[ Self-Contained Mode ]] --
49 # Rules inherit the "deny" disruptive action. The first rule that matches will block.
51 # -- [[ Collaborative Detection Mode ]] --
52 # This is a "delayed blocking" mode of operation where each matching rule will inherit
53 # the "pass" action and will only contribute to anomaly scores. Transactional blocking
56 # -- [[ Alert Logging Control ]] --
57 # You have three options -
59 # - To log to both the Apache error_log and ModSecurity audit_log file use: "log"
60 # - To log *only* to the ModSecurity audit_log file use: "nolog,auditlog"
61 # - To log *only* to the Apache error_log file use: "log,noauditlog"
63 # Ref: http://blog.spiderlabs.com/2010/11/advanced-topic-of-the-week-traditional-vs-anomaly-scoring-detection-modes.html
64 # Ref: https://sourceforge.net/apps/mediawiki/mod-security/index.php?title=Reference_Manual#SecDefaultAction
66 SecDefaultAction "phase:1,deny,log"
70 # -- [[ Collaborative Detection Severity Levels ]] ----------------------------------------
72 # These are the default scoring points for each severity level. You may
73 # adjust these to you liking. These settings will be used in macro expansion
74 # in the rules to increment the anomaly scores when rules match.
76 # These are the default Severity ratings (with anomaly scores) of the individual rules -
78 # - 2: Critical - Anomaly Score of 5.
79 # Is the highest severity level possible without correlation. It is
80 # normally generated by the web attack rules (40 level files).
81 # - 3: Error - Anomaly Score of 4.
82 # Is generated mostly from outbound leakage rules (50 level files).
83 # - 4: Warning - Anomaly Score of 3.
84 # Is generated by malicious client rules (35 level files).
85 # - 5: Notice - Anomaly Score of 2.
86 # Is generated by the Protocol policy and anomaly files.
92 setvar:tx.critical_anomaly_score=5, \
93 setvar:tx.error_anomaly_score=4, \
94 setvar:tx.warning_anomaly_score=3, \
95 setvar:tx.notice_anomaly_score=2, \
101 # -- [[ Collaborative Detection Scoring Threshold Levels ]] ------------------------------
103 # These variables are used in macro expansion in the 49 inbound blocking and 59
104 # outbound blocking files.
106 # **MUST HAVE** ModSecurity v2.5.12 or higher to use macro expansion in numeric
107 # operators. If you have an earlier version, edit the 49/59 files directly to
108 # set the appropriate anomaly score levels.
110 # You should set the score to the proper threshold you would prefer. If set to "5"
111 # it will work similarly to previous Mod CRS rules and will create an event in the error_log
112 # file if there are any rules that match. If you would like to lessen the number of events
113 # generated in the error_log file, you should increase the anomaly score threshold to
114 # something like "20". This would only generate an event in the error_log file if
115 # there are multiple lower severity rule matches or if any 1 higher severity item matches.
121 setvar:tx.inbound_anomaly_score_level=5, \
130 setvar:tx.outbound_anomaly_score_level=4, \
136 # -- [[ Collaborative Detection Blocking ]] -----------------------------------------------
138 # This is a collaborative detection mode where each rule will increment an overall
139 # anomaly score for the transaction. The scores are then evaluated in the following files:
141 # Inbound anomaly score - checked in the modsecurity_crs_49_inbound_blocking.conf file
142 # Outbound anomaly score - checked in the modsecurity_crs_59_outbound_blocking.conf file
144 # If you want to use anomaly scoring mode, then uncomment this line.
150 setvar:tx.anomaly_score_blocking=on, \
156 # -- [[ GeoIP Database ]] -----------------------------------------------------------------
158 # There are some rulesets that need to inspect the GEO data of the REMOTE_ADDR data.
160 # You must first download the MaxMind GeoIP Lite City DB -
162 # http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
164 # You then need to define the proper path for the SecGeoLookupDb directive
166 # Ref: http://blog.spiderlabs.com/2010/10/detecting-malice-with-modsecurity-geolocation-data.html
167 # Ref: http://blog.spiderlabs.com/2010/11/detecting-malice-with-modsecurity-ip-forensics.html
169 #SecGeoLookupDb /opt/modsecurity/lib/GeoLiteCity.dat
172 # -- [[ Regression Testing Mode ]] --------------------------------------------------------
174 # If you are going to run the regression testing mode, you should uncomment the
175 # following rule. It will enable DetectionOnly mode for the SecRuleEngine and
176 # will enable Response Header tagging so that the client testing script can see
177 # which rule IDs have matched.
179 # You must specify the your source IP address where you will be running the tests
182 #SecRule REMOTE_ADDR "@ipMatch 192.168.1.100" \
186 ctl:ruleEngine=DetectionOnly, \
187 setvar:tx.regression_testing=1, \
193 # -- [[ HTTP Policy Settings ]] ----------------------------------------------------------
195 # Set the following policy settings here and they will be propagated to the 23 rules
196 # file (modsecurity_common_23_request_limits.conf) by using macro expansion.
197 # If you run into false positives, you can adjust the settings here.
199 # Only the max number of args is uncommented by default as there are a high rate
200 # of false positives. Uncomment the items you wish to set.
203 # -- Maximum number of arguments in request limited
208 setvar:tx.max_num_args=255, \
213 # -- Limit argument name length
218 setvar:tx.arg_name_length=100, \
223 # -- Limit value name length
228 setvar:tx.arg_length=400, \
233 # -- Limit arguments total length
238 setvar:tx.total_arg_length=64000, \
243 # -- Individual file size is limited
248 setvar:tx.max_file_size=1048576, \
253 # -- Combined file size is limited
258 setvar:tx.combined_file_sizes=1048576, \
264 # Set the following policy settings here and they will be propagated to the 30 rules
265 # file (modsecurity_crs_30_http_policy.conf) by using macro expansion.
266 # If you run into false positves, you can adjust the settings here.
272 setvar:'tx.allowed_methods=<%= @allowed_methods -%>', \
273 setvar:'tx.allowed_request_content_type=<%= @content_types -%>', \
274 setvar:'tx.allowed_http_versions=HTTP/0.9 HTTP/1.0 HTTP/1.1', \
275 setvar:'tx.restricted_extensions=<%= @restricted_extensions -%>', \
276 setvar:'tx.restricted_headers=<%= @restricted_headers -%>', \
282 # -- [[ Content Security Policy (CSP) Settings ]] -----------------------------------------
284 # The purpose of these settings is to send CSP response headers to
285 # Mozilla FireFox users so that you can enforce how dynamic content
286 # is used. CSP usage helps to prevent XSS attacks against your users.
290 # https://developer.mozilla.org/en/Security/CSP
292 # Uncomment this SecAction line if you want use CSP enforcement.
293 # You need to set the appropriate directives and settings for your site/domain and
294 # and activate the CSP file in the experimental_rules directory.
296 # Ref: http://blog.spiderlabs.com/2011/04/modsecurity-advanced-topic-of-the-week-integrating-content-security-policy-csp.html
302 setvar:tx.csp_report_only=1, \
303 setvar:tx.csp_report_uri=/csp_violation_report, \
304 setenv:'csp_policy=allow \'self\'; img-src *.yoursite.com; media-src *.yoursite.com; style-src *.yoursite.com; frame-ancestors *.yoursite.com; script-src *.yoursite.com; report-uri %{tx.csp_report_uri}', \
310 # -- [[ Brute Force Protection ]] ---------------------------------------------------------
312 # If you are using the Brute Force Protection rule set, then uncomment the following
313 # lines and set the following variables:
314 # - Protected URLs: resources to protect (e.g. login pages) - set to your login page
315 # - Burst Time Slice Interval: time interval window to monitor for bursts
316 # - Request Threshold: request # threshold to trigger a burst
317 # - Block Period: temporary block timeout
323 setvar:'tx.brute_force_protected_urls=/login.jsp /partner_login.php', \
324 setvar:'tx.brute_force_burst_time_slice=60', \
325 setvar:'tx.brute_force_counter_threshold=10', \
326 setvar:'tx.brute_force_block_timeout=300', \
332 # -- [[ DoS Protection ]] ----------------------------------------------------------------
334 # If you are using the DoS Protection rule set, then uncomment the following
335 # lines and set the following variables:
336 # - Burst Time Slice Interval: time interval window to monitor for bursts
337 # - Request Threshold: request # threshold to trigger a burst
338 # - Block Period: temporary block timeout
344 setvar:'tx.dos_burst_time_slice=60', \
345 setvar:'tx.dos_counter_threshold=100', \
346 setvar:'tx.dos_block_timeout=600', \
352 # -- [[ Check UTF enconding ]] -----------------------------------------------------------
354 # We only want to apply this check if UTF-8 encoding is actually used by the site, otherwise
355 # it will result in false positives.
357 # Uncomment this line if your site uses UTF8 encoding
362 setvar:tx.crs_validate_utf8_encoding=1, \
368 # -- [[ Enable XML Body Parsing ]] -------------------------------------------------------
370 # The rules in this file will trigger the XML parser upon an XML request
372 # Initiate XML Processor in case of xml content-type
374 SecRule REQUEST_HEADERS:Content-Type "text/xml" \
377 t:none,t:lowercase, \
381 SecRule REQBODY_PROCESSOR "!@streq XML" \
382 "ctl:requestBodyProcessor=XML"
386 # -- [[ Global and IP Collections ]] -----------------------------------------------------
388 # Create both Global and IP collections for rules to use
389 # There are some CRS rules that assume that these two collections
390 # have already been initiated.
392 SecRule REQUEST_HEADERS:User-Agent "^(.*)$" \
395 t:none,t:sha1,t:hexEncode, \
396 setvar:tx.ua_hash=%{matched_var}, \
401 SecRule REQUEST_HEADERS:x-forwarded-for "^\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b" \
406 setvar:tx.real_ip=%{tx.1}, \
411 SecRule &TX:REAL_IP "!@eq 0" \
415 initcol:global=global, \
416 initcol:ip=%{tx.real_ip}_%{tx.ua_hash}, \
421 SecRule &TX:REAL_IP "@eq 0" \
425 initcol:global=global, \
426 initcol:ip=%{remote_addr}_%{tx.ua_hash}, \