Abstract
Traditional Web Application Firewalls (WAFs) like ModSecurity rely on manual heuristic scoring to detect malicious traffic, often leading to suboptimal performance and high false-positive rates. This paper introduces ModSec-Learn, a framework that treats security rules as binary features for machine learning models. By training on a balanced dataset of legitimate traffic and SQL injection (SQLi) attacks, ModSec-Learn optimizes rule weights and identifies redundancies. Our evaluation demonstrates that ModSec-Learn improves detection rates by over 45% compared to vanilla configurations while maintaining near-perfect accuracy across various paranoia levels.
Introduction
Web Application Firewalls (WAFs) serve as a primary defense mechanism against common web-based threats. ModSecurity, coupled with the OWASP Core Rule Set (CRS), is the industry standard. However, its traditional scoring mechanism is fundamentally limited. Rules are assigned static "severity" weights (e.g., Critical = 5), and a request is blocked if its cumulative score exceeds a predefined threshold. This heuristic approach fails to account for the unique traffic patterns of specific applications, resulting in a "one-size-fits-all" solution that often triggers false positives or misses sophisticated attacks.
The ModSec-Learn Framework
ModSec-Learn addresses these limitations by replacing manual scoring with data-driven machine learning models. The core innovation lies in the transformation of rule triggers into input features.
Methodology
The framework follows a multi-step pipeline:
- Feature Extraction: Each CRS rule is treated as a binary feature. If a rule is triggered by an incoming HTTP request, its corresponding feature is set to 1; otherwise, it is 0.
- Model Training: The system employs both linear and non-linear models. Linear models like Support Vector Machines (SVM) and Logistic Regression (LR) are particularly advantageous because their learned weights can be directly integrated back into standard ModSecurity configurations. Non-linear models like Random Forests (RF) are used to capture complex interactions between different rules.
- Regularization: The use of $\ell_1$ (Lasso) regularization induces sparsity, effectively forcing the model to prioritize the most informative rules and discard redundant ones.
Experimental Evaluation
To evaluate the framework, the authors developed a novel, balanced dataset. Legitimate traffic was sourced from the open-appsec dataset (508,529 samples), while malicious traffic consisted of 30,543 SQLi payloads from various public repositories and custom-generated samples using SQLmap. A balanced evaluation set of 50,000 samples was used for testing.
Results and Discussion
The experimental results highlight several key advantages of the ModSec-Learn approach.
Overcoming the Paranoia Paradox
In standard ModSecurity usage, increasing the "Paranoia Level" (PL) typically enables more aggressive rules. While this should theoretically improve security, it often leads to a "Paranoia Paradox" where the surge in false positives degrades overall system performance. ModSec-Learn resolves this by learning to ignore "noisy" rules that frequently trigger on benign traffic.
Performance Gains
As shown in the table below, the performance gap between vanilla ModSecurity and ModSec-Learn is stark, especially at higher paranoia levels.
At a strict 1% False Positive Rate, ModSec-Learn achieved a True Positive Rate improvement of more than 45% over the default configuration. While vanilla ModSecurity's detection rate plummeted to approximately 68% at PL3 and PL4, the ML-enhanced models maintained detection rates between 99.0% and 99.4%.
Rule Efficiency and Negative Weights
The framework also identified significant redundancies; approximately 30% of SQLi rules were found to be unnecessary for maintaining high performance. Furthermore, the models assigned negative weights to certain rules, indicating that their presence actually correlates with legitimate traffic—a nuance that manual scoring cannot capture.
Conclusion
ModSec-Learn demonstrates that a data-driven approach to WAF configuration significantly outperforms traditional heuristic methods. By automating rule weighting and identifying redundancies, it provides a more robust and efficient security posture. Future work will focus on extending this methodology to other attack vectors, such as Cross-Site Scripting (XSS), and developing automated pipelines for real-time model updates.
Summary updated