From ca0bdb1cfa5b72fd43dfa33653d3d9af6e5bf24e Mon Sep 17 00:00:00 2001 From: Jiongxuan Zhang Date: Thu, 10 Oct 2024 23:21:10 +0800 Subject: [PATCH] docs: add Fail2Ban configuration guide to README - Added a section in README.md explaining how to configure Fail2Ban for WebDAV security. - Included examples for filter and jail configuration. - Provided instructions on setting up and testing Fail2Ban to block IPs after failed login attempts. --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/README.md b/README.md index 4cf8590..1da110a 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,64 @@ Restart=on-failure WantedBy=multi-user.target ``` +## Fail2Ban Setup + +To add security against brute-force attacks in your WebDAV server, you can configure Fail2Ban to ban IP addresses after a set number of failed login attempts. + +### Filter Configuration + +Create a new filter rule under `filter.d/webdav.conf`: + +```ini +[INCLUDES] +before = common.conf + +[Definition] +# Failregex to match "invalid password" and extract remote_address only +failregex = ^.*invalid password\s*\{.*"remote_address":\s*""\s*\} + +# Failregex to match "invalid username" and extract remote_address only (if applicable) +failregex += ^.*invalid username\s*\{.*"remote_address":\s*""\s*\} + +ignoreregex = +``` + +This configuration will capture invalid login attempts and extract the IP address to ban. + +### Jail Configuration + +In `jail.d/webdav.conf`, define the jail that monitors your WebDAV log for failed login attempts: + +```ini +[webdav] + +enabled = true +port = [your_port] +filter = webdav +logpath = [your_log_path] +banaction = iptables-allports +ignoreself = false +``` + +- Replace `[your_port]` with the port your WebDAV server is running on. +- Replace `[your_log_path]` with the path to your WebDAV log file. + +### Final Steps + +1. Restart Fail2Ban to apply these configurations: + + ```bash + sudo systemctl restart fail2ban + ``` + +2. Verify that Fail2Ban is running and monitoring your WebDAV logs: + + ```bash + sudo fail2ban-client status webdav + ``` + +With this setup, Fail2Ban will automatically block IP addresses that exceed the allowed number of failed login attempts. + ## Contributing Feel free to open an issue or a pull request.