码迷,mamicode.com
首页 > Web开发 > 详细

根据web日志解决DOS安全Linux服务器

时间:2019-08-23 10:33:47      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:while   monitor   fun   his   bin   lin   table   echo   put   

#!/bin/sh
#########################
#monitor 恶意IP地址
#by zkg
#日期:2019-08-23
#########################

. /etc/init.d/functions
WEBFILE=/data/nginx/logs/access.log-2019-08-19
while true
do
tail -n 200 $WEBFILE|awk ‘{print $1}‘|sort|uniq -c >/tmp/iptables.log
while read line
do
IP=echo $line|awk ‘{print $2}‘
COUNT=echo $line|awk ‘{print $1}‘
IPTABLESCOUNT=iptables -L -n|grep "$IP"|wc -l
if [ $COUNT -ge 50 -a $IPTABLESCOUNT -lt 1 ];then
iptables -I INPUT -s $IP -j DROP && \
/etc/init.d/iptables save
[ $? -eq 0 ]&&
echo "$IP may be a malicious attack on IP, successfully blocking this IP" /bin/true
fi
done </tmp/iptables.log
sleep 5
done

根据web日志解决DOS安全Linux服务器

标签:while   monitor   fun   his   bin   lin   table   echo   put   

原文地址:https://blog.51cto.com/1009516/2431864

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!