diff --git a/du_setup.sh b/du_setup.sh index ca5e978..24a647b 100644 --- a/du_setup.sh +++ b/du_setup.sh @@ -3,6 +3,7 @@ # Debian 12 and Ubuntu Server Hardening Interactive Script # Version: 0.57 | 2025-07-07 # Changelog: +# - v0.58: improved fail2ban to parse ufw logs # - v0.57: Fix for silent failure at test_backup() # Option to choose which directories to back up. # - v0.56: Make tailscale config optional @@ -111,7 +112,7 @@ print_header() { echo -e "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}" echo -e "${CYAN}║ ║${NC}" echo -e "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}" - echo -e "${CYAN}║ v0.57 | 2025-07-07 ║${NC}" + echo -e "${CYAN}║ v0.58 | 2025-07-07 ║${NC}" echo -e "${CYAN}║ ║${NC}" echo -e "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}" echo @@ -1036,45 +1037,58 @@ configure_firewall() { configure_fail2ban() { print_section "Fail2Ban Configuration" - # Set the SSH port for Fail2Ban to monitor. - local SSH_PORTS_TO_MONITOR="$SSH_PORT" - local NEW_FAIL2BAN_CONFIG + # --- Create UFW Probes Filter for Fail2ban --- + # This custom filter tells Fail2ban what to look for in UFW's log file. + print_info "Creating Fail2ban filter for UFW probes..." + mkdir -p /etc/fail2ban/filter.d + tee /etc/fail2ban/filter.d/ufw-probes.conf > /dev/null <<'EOF' +[Definition] +# This regex looks for the standard "[UFW BLOCK]" message in /var/log/ufw.log +failregex = \[UFW BLOCK\] IN=.* OUT=.* SRC= +ignoreregex = +EOF - NEW_FAIL2BAN_CONFIG=$(mktemp) - tee "$NEW_FAIL2BAN_CONFIG" > /dev/null < /dev/null <