#2013/06/13#
前天檢查http的log,發現怎麼有那麼多4images postcards.php的存取,
# cat /var/log/httpd/vhost.log* |grep postcards.php|wc -l
288948
@@",看來是被拿來亂寄廣告信了,於是把postcards.php改名。
以前幾乎都沒在看log的,偷懶的結果就是被拿來亂寄信,搞不好網站的IP已被許多公司列入黑名單了,所以現在要弄個檢查機制才行,於是就想以檢查Apache的Log,以IP的瀏灠次數中超過一萬次的就把它加入iptables中drop。
在Top20中找出大於10000次瀏灠量的IP後,用iptables把它drop掉:
#!/bin/bash
IPS=$(awk ‘{Log[$2]++}END{for (ip in Log) print Log[ip],ip}’ /var/log/httpd/vhost.log* | sort -n | tail -20 | awk ‘$1 > 10000 {print $2}’)
for ip in $IPS;do
istable=$(iptables -n -L INPUT | awk ‘{print $4}’ | grep ^${ip}$)
#echo $istable
if [ “$istable" = " ];then
iptables -A INPUT -s $ip -j DROP
echo “$ip dropped."
else
echo “$ip has in iptables."
fi
done
由於是小站的關係,訂這種數值應是沒什麼問題才是。
發表迴響