您现在的位置是:网站首页> 编程资料编程资料
一个简单的防CC攻击Shell脚本分享_linux shell_
2023-05-26
395人已围观
简介 一个简单的防CC攻击Shell脚本分享_linux shell_
实现代码:
复制代码 代码如下:
#!/bin/sh
cd /var/log/httpd/
cat access_log|awk '{print $1}'|sort|uniq -c|sort -n -r|head -n 20 > a
cp /dev/null access_log
cp /dev/null error_log
cp /dev/null limit.sh
cp /dev/null c
#awk '{print $2}' a|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b
cat a|while read num ip
do
if [ "$num" -gt "20" ]
then
echo $ip >> c
fi
done
cat c|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b
#cat c|sort|uniq > b
for i in `cat b`
#cat b|sed 's/\./ /g'|while read i1 i2 i3 i4
do
if `cat ourip |grep $i > /dev/null 2>&1`
then
echo "`date` $i" >> test
else
echo "iptables -I INPUT -p tcp -dport 80 -s $i.0/24 -j DROP" >> limit.sh
fi
done
cd /var/log/httpd/
cat access_log|awk '{print $1}'|sort|uniq -c|sort -n -r|head -n 20 > a
cp /dev/null access_log
cp /dev/null error_log
cp /dev/null limit.sh
cp /dev/null c
#awk '{print $2}' a|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b
cat a|while read num ip
do
if [ "$num" -gt "20" ]
then
echo $ip >> c
fi
done
cat c|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b
#cat c|sort|uniq > b
for i in `cat b`
#cat b|sed 's/\./ /g'|while read i1 i2 i3 i4
do
if `cat ourip |grep $i > /dev/null 2>&1`
then
echo "`date` $i" >> test
else
echo "iptables -I INPUT -p tcp -dport 80 -s $i.0/24 -j DROP" >> limit.sh
fi
done
使用方法,运行命令:sh limit.sh,这样就会把访问量过高的IP加入防火墙,并禁止访问
相关内容
- 简单的Linux查找后门思路和shell脚本分享_linux shell_
- 一个Linux系统安全设置的Shell脚本的分享(适用CentOS)_linux shell_
- 在Shell中分割字符串的例子_linux shell_
- Linux中获取某个进程的系统调用以及参数(故障排查案例)_linux shell_
- 自动杀掉占用较多CPU资源的Shell脚本_linux shell_
- Shell脚本获取进程的运行时间_linux shell_
- Shell中的循环语句for、while、until实例讲解_linux shell_
- Shell脚本处理浮点数的运算和比较实例_linux shell_
- Linux中删除文件内空行的4种方法_linux shell_
- Shell处理带空格的文件名的方法_linux shell_
