-
Notifications
You must be signed in to change notification settings - Fork 10
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
Improve DoS Protection with Lua Script for Efficient IP Blocking #27
base: main
Are you sure you want to change the base?
Conversation
This version utilizes a Lua Script to write IP addresses into the blockListIP.txt file, ensuring that IP blocking functions effectively across all ModSecurity threads when mitigating denial-of-service (DoS) attacks. This approach optimizes protection and minimizes delays in applying new IP blocking rules.
Thanks @ChanThien3101. We'll review your plugin. |
@ChanThien3101 First of all, you have put all rules into file |
Thanks for contributing a plugin. This is very welcome. Especially in this area where CRS has removed functionality for CRS4. Yet I have a few question marks around your implementation. Namely how it behaves under heavy load (-> DDoS). I do not see any write-lock functionality on the code level and I would be interested to see how thousands of threads behave when they want to write into your txt file at the same time. Also the read loop over the file implemented via 9514910 is likely to slow down non-attacking requests and bringing the server down in a DDoS situation. This will need some real world testing (or very good simulation of DDoS). |
Apologies for the delayed response. I had received your feedback earlier, but I have had the chance to reply until now because I've been tied up with some work at my university. To be honest, I am currently a final-year student and working on my graduation project, which is related to yours ModSecurity. |
Thank you for the update! |
Hello! Since ModSecurity operates in a multithreaded environment, it’s quite challenging to load all IPs into memory for optimal performance. While this approach may not be the most efficient for DDoS protection, my plugin can still contribute to DDoS mitigation if someone wishes to try it and combine it with ModSecurity for small-scale implementations. Additionally, if you prefer not to use the blocklist method for IP blocking, I have implemented a second approach that combines ModSecurity with iptables and utilizes ipset to block IPs at the network level. With this method, once ModSecurity detects an IP involved in a DDoS attack, it will immediately call add_ip_to_ipset.lua to add the IP to ipset (see rules 9514151 or 9514153). For more details on the implementation, please refer to the readme.md. |
This may be my final update for now. If you believe my plugin can be successfully implemented, please accept the pull request on GitHub, and I will continue developing it in the future. Thank you! |
README.md
Outdated
@@ -26,6 +26,7 @@ maps the regular CRS IDs from 900K for each rule to the range 9,900,000 - 9,999, | |||
| phpbb-rule-exclusions | 9,512,000 - 9,512,999 | [coreruleset/phpbb-rule-exclusions-plugin](https://github.com/coreruleset/phpbb-rule-exclusions-plugin) | official | ✅ tested | ![Integration tests](https://github.com/coreruleset/phpbb-rule-exclusions-plugin/actions/workflows/integration.yml/badge.svg) | | |||
| phpmyadmin-rule-exclusions | 9,513,000 - 9,513,999 | [coreruleset/phpmyadmin-rule-exclusions-plugin](https://github.com/coreruleset/phpmyadmin-rule-exclusions-plugin) | official | ✅ tested | ![Integration tests](https://github.com/coreruleset/phpmyadmin-rule-exclusions-plugin/actions/workflows/integration.yml/badge.svg) | | |||
| dos-protection-modsecurity | 9,514,000 - 9,514,999 | [coreruleset/dos-protection-plugin-modsecurity](https://github.com/coreruleset/dos-protection-plugin-modsecurity) | official | untested | | | |||
| dos-protection-modsecurity-vr2 | 9,514,000 - 9,514,999 | [ChanThien3101/plugin-dos-protection-modsecurity](https://github.com/ChanThien3101/plugin-dos-protection-modsecurity.git)| 3rd party | | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use an unused range. The next range would be 9,523,000 - 9523,999.
Hello @theseion |
@ChanThien3101 Sending my initial comments:
Also, consider using SQLite instead of a simple txt file - this will also resolve the locking problem. |
@azurit
|
@theseion What do you all think of my plugin? Please provide me with your feedback. |
Ping @azurit |
Co-authored-by: Max Leske <250711+theseion@users.noreply.github.com>
This version utilizes a Lua Script to write IP addresses into the blockListIP.txt file, ensuring that IP blocking functions effectively across all ModSecurity threads when mitigating denial-of-service (DoS) attacks. This approach optimizes protection and minimizes delays in applying new IP blocking rules.
I have modified this rule based on your original implementation. The addition of writing IP addresses to the blocklist was made because I noticed that the previous rule did not effectively block IPs when they changed their port. With my implementation, this issue has been fully resolved. However, as my work builds upon your original rule, feel free to contact me if there are any questions or further requirements.