我的服务器受到攻击,它充满了以下模式的请求:
数以千计的IP每个IP请求相同的页面“GET / HTTP / 1.1”每秒3-5次(相同的时间戳)。
所以我需要的是一个小的shell脚本,它接受来自“tail -f /var/www/log/access.log”的input并parsing相同时间戳的重复请求(例如,相同的引用者和相同的时间),并添加一个iptable规则来丢弃来自这个IP的所有数据包。
看一下Fail2Ban,并在这个Howto中查看Apache日志文件filter的例子。
这是一个应该完成你所要求的例子。 请参阅手册并根据您的需求进行调整:
/etc/fail2ban/filters.d/apache-attackers.conf
[Definition] failregex = <HOST> - - [[^]]+] "GET / HTTP/1.1" 200 .* "REFERER"
/etc/fail2ban/local.jail
[DEFAULT] ignoreip = 127.0.0.1 <an IP you access the system from> [apache-attackers] enabled = true port = http,https filter = apache-attackers bantime = 86400 logpath = /var/log/httpd/*access_log maxretry = 5
在启动时启用fail2ban (RHEL / CentOS)并启动它:
chkconfig fail2ban on service fail2ban start
注意:在RHEL / CentOS上testing,您的里程可能会有所不同。