WordPress 是目前最受歡迎的 CMS, 而針對 WordPress 的攻擊也很多, 本文會講述使用 Fail2ban 攔截對 WordPress 的暴力入侵。
如果未安裝 Fail2ban, 先安裝 Fail2ban, 可以參考本站另一篇文章:
安裝好 Fail2ban 後, 在 Fail2ban 的 filter 目錄建立 wordpress 的 filter, 以下會以 /etc/fail2ban/filter.d/wordpress.conf 作為例子:
# vi /etc/fail2ban/filter.d/wordpress.conf
加入以下內容:
1 2 3 4 5 6 7 8 |
# WordPress brute force auth filter: /etc/fail2ban/filter.d/wordpress.conf: # # Block IPs trying to auth wp wordpress # # [Definition] failregex = ^<HOST> .* "POST .*wp-login.php ignoreregex = |
然後開啟 Fail2ban 的設定檔 /etc/fail2ban/jail.conf, 加入以下內容:
1 2 3 4 5 6 7 8 9 |
[wordpress] enabled = true port = http,https action = iptables-multiport[name=wordpress, port="http,https", protocol=tcp] filter = wordpress logpath = /var/log/httpd/access.log findtime = 1800 bandtime = 1800 maxretry = 10 |
上面的設定需要根據主機的環境設定:
logpath: 這是 Apache 紀錄檔的位置.
bantime: 封鎖 IP 的時間, 單位是秒, 上面例子是封鎖 IP 半小時.
maxretry: 最多登入次數, 上面設定了在半小時內有 10 次登入便會被封鎖.
修改好 jail.conf 後, 重新啟動 Fail2ban 便會生效:
# systemctl restart fail2ban