AWS 太多请求,阻止 IP 地址

AWS too many requests, Block IP addresses

大家好,我在我的 AWS 服务器上 运行 wordpress。并且该服务器被来自某些 IP 地址的持续请求所淹没。我怎样才能阻止他们?

80.82.78.112 - - [16/Mar/2015:15:29:58 +0000] "POST /xmlrpc.php HTTP/1.0" 200 595 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)"

我每秒从同一个 IP 地址收到大约 30-40 个请求。这让我的服务器变慢了。

您可以使用 fail2ban 来阻止违规 IP。 WP 是一种广泛使用的 CMS,是攻击的目标,但互联网上也充满了与他们作斗争的人的资源。

在 Wordpress 中使用 fail2ban 阻止 xmlrpc 请求记录在此处:Countering WordPress XML-RPC Attacks with fail2ban

希望这些信息对未来的 Google 员工有所帮助,我想通过配置步骤扩展 Diego 的建议,使我在 EC2 服务器上进入使用 fail2ban 的工作状态。

环境:

  • 亚马逊 Linux AMI 版本 2017.09
  • 阿帕奇 2.4.27

1。为亚马逊安装和配置正确版本的 fail2ban Linux

按照Protecting your Amazon Linux WordPress server using fail2ban中的建议,安装亚马逊兼容版本:

yum --disablerepo epel install fail2ban 

2。配置jail.localwordpress.conf

此配置适用于 HTTPS 和 HTTP,并防止 wp-login 和 xml-rpc 攻击。

创建jail.local:

sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

编辑/etc/fail2ban/jail.local(在底部添加):

[wordpress]
enabled = true
port = http,https
action = iptables-multiport[name="wordpress", port="http,https", protocol="tcp"]
# Uncomment if you want emails when someone is banned:
#        sendmail-whois[name=fail2ban-wp-bruteforce, dest="your-email@yourdomain.com"]
filter = wordpress
logpath = /var/log/httpd/*access_log
maxretry = 5

创建和编辑/etc/fail2ban/filter.d/wordpress.conf:

[Definition]
failregex = ^<HOST> - - .* "POST .*(wp-login.php|xmlrpc.php) HTTP/.*" (200|401|403)
failregex = ^<HOST> - - .* "GET .*(wp-login.php|xmlrpc.php) HTTP/.*" (200|401|403)

ignoreregex =

注意:对于来自非白名单 IP 的任何 wp-admin/* 资源,我使用 .htaccess 规则 return 403(如 How to Lock WordPress Admin Login with .htaccess Rules 的第 7 步中所述)。如果你不喜欢,你可以安全地从正则表达式中删除 |403

相关说明:"scoreboard is full" 错误可能表示 DDoS 攻击

DDoS 攻击的另一个症状可能是 /var/log/httpd/error_log and/or var/log/httpd/ssl_error_log 中的大量错误,如下所示:

[Sun Apr 15 09:10:47.038565 2018] [mpm_worker:error] [pid 2847:tid 140053879679040] AH00288: scoreboard is full, not at MaxRequestWorkers

这让我陷入困境,直到我将上述错误与本问题中讨论的 access_log 错误相关联;认为值得一提。