The OWASP Core Rule Set (CRS) is a set of generic ModSecurity rules designed to protect web applications from a wide range of common attack vectors. It includes pre-defined rules for detecting and blocking threats such as SQL injection, cross-site scripting (XSS), local file inclusion (LFI), and more.
The OWASP CRS organizes its rules into several files, each targeting specific types of attacks or tasks. Below is a list of the primary rule files and their purposes:
- Purpose: Configuration file, not a set of rules.
- Use: Provides global configurations for enabling/disabling specific protections, setting thresholds, and other tuning options.
- Example:
- Define application-specific parameters.
- Control the severity level for logging.
- Purpose: Ensures proper initialization of CRS.
- Use: Prepares ModSecurity for the rest of the rules by defining essential variables.
- Example:
- Sets up collections (e.g.,
txfor transaction-specific data).
- Sets up collections (e.g.,
- Purpose: Contains rules to exclude certain requests from being inspected.
- Use: Prevents false positives by ignoring trusted sources or paths.
- Example:
- Allows health checks (
/health-check).
- Allows health checks (
- Purpose: Protects against requests from known malicious IP addresses.
- Use: Integrates with third-party IP reputation services.
- Example:
- Block requests from blacklisted IP ranges.
- Purpose: Enforces restrictions on HTTP methods.
- Example:
- Block unsupported methods like
TRACEorTRACK.
- Block unsupported methods like
- Purpose: Detects automated scanners and bots.
- Example:
- Matches known patterns of scanning tools.
- Purpose: Validates the HTTP protocol to prevent malformed or malicious requests.
- Example:
- Enforces proper header structure.
- Purpose: Protects against protocol-based attacks.
- Example:
- Detects header injection or HTTP smuggling attempts.
- Purpose: Detects Local File Inclusion (LFI) attacks.
- Example:
- Blocks requests trying to access files like
/etc/passwd.
- Blocks requests trying to access files like
- Purpose: Protects against Remote File Inclusion (RFI) attacks.
- Example:
- Blocks requests with malicious external URLs.
- Purpose: Detects Remote Code Execution (RCE) attempts.
- Example:
- Blocks requests containing code execution patterns like
eval()orsystem().
- Blocks requests containing code execution patterns like
- Purpose: Protects against attacks targeting PHP applications.
- Example:
- Blocks malicious PHP-specific patterns.
- Purpose: Detects Cross-Site Scripting (XSS) attacks.
- Example:
- Blocks requests containing
<script>tags or JavaScript code.
- Blocks requests containing
- Purpose: Protects against SQL Injection (SQLi) attacks.
- Example:
- Blocks requests containing SQL keywords like
SELECT,UNION, orDROP.
- Blocks requests containing SQL keywords like
- Purpose: Detects session fixation and hijacking attempts.
- Example:
- Blocks attempts to set cookies via malicious requests.
- Purpose: Detects attacks targeting Java applications.
- Example:
- Blocks requests containing Java serialization vulnerabilities.
- Purpose: Evaluates whether to block a request based on previous rules.
- Example:
- Applies thresholds and scores from earlier rules to decide if the request should be blocked.
- Purpose: Detects data leakage in server responses.
- Example:
- Blocks responses containing sensitive data like credit card numbers or SSNs.
- Purpose: Detects SQL error messages in server responses.
- Example:
- Blocks responses revealing database errors.
- Purpose: Allows for correlation between rules and transactions.
- Example:
- Logs detailed information for analyzing multiple rules triggering simultaneously.
-
Include the CRS in
modsecurity.conf:Include /usr/local/modsecurity-crs/crs-setup.conf Include /usr/local/modsecurity-crs/rules/*.conf -
Customize the
crs-setup.conf:- Configure thresholds, exclusions, and parameters based on your application.
-
Test with Traffic:
- Monitor logs to identify false positives or necessary adjustments.
- Use tools like curl or penetration testing tools (e.g., OWASP ZAP).