shell结合iptables自动处理CC攻击(转载)
2012-01-31 13:31
190 查看
www.*****.com:80 118.251.244.183 - - [26/May/2010:20:22:16 +0800] "POST /syxcms/vote.php?act=submit HTTP/1.1" 200 56 "http://www.*****.com/news/201005/news-6213.shtml" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
www.*****.com:80 118.251.244.183 - - [26/May/2010:20:22:16 +0800] "POST /syxcms/vote.php?act=submit HTTP/1.1" 200 72 "http://www.*****.com/news/201005/news-6213.shtml" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
www.*****.com:80 118.251.244.183 - - [26/May/2010:20:22:16 +0800] "POST /syxcms/vote.php?act=submit HTTP/1.1" 200 56 "http://www.*****.com/news/201005/news-6213.shtml" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
大概原理就是对最新日志里面的客户端访问IP进行采样统计分析,然后对超出正常访问次数的IP进行屏蔽,如下面统计分析后的结果:
对最新1000条日志的客户端访问IP进行排序统计访问次数。比如第一个IP 219.128.20.68 1000条日志就有295条,访问肯定不正常
root@ubuntu134:# tail access.log -n 1000 |grep vote.php |awk {'print $2'} |sort |uniq -c |sort -nr
295 219.128.20.68
175 113.250.97.209
164 218.87.140.39
153 59.61.215.42
98 222.240.182.234
83 220.181.110.65
73 120.38.1.255
62 221.3.99.106
21 220.249.83.74
12 218.22.10.114
1 123.52.158.16
1 114.81.115.201
然后就是自动处理,如果1000条日志单IP超过50条就屏蔽掉
*/2 * * * * /usr/local/nginx/var/log/drop.sh
#!/bin/sh
cd /usr/local/nginx/var/log
tail access.log -n 1000 |grep vote.php |awk {'print $2'} |sort |uniq -c |sort -nr |awk '{if ($2!=null && $1>50) {print $2}}' > drop_ip.txt
for i in `cat drop_ip.txt`
do
/sbin/iptables -I INPUT -s $i -j DROP;
done
这shell 每几分钟执行一次,就可自动屏蔽那些不正常IP,相信大家都看的懂,下面是针对连接数屏蔽代码
#!/bin/sh
/bin/netstat -ant |grep 80 |awk '{print $5}' |awk -F : '{print $1}' |sort |uniq -c |sort -rn |grep -v -E '192.168|127.0' |awk '{if ($2!=null && $1>50) {print $2}}' > drop_ip.txt
for i in `cat drop_ip.txt`
do
/sbin/iptables -I INPUT -s $i -j DROP;
done
说下,grep -v -E '192.168|127.0' 也就是排除内网IP,免得把自己给屏蔽了,当然还可以加些自己的IP。
http://sookk8.blog.51cto.com/455855/448539
www.*****.com:80 118.251.244.183 - - [26/May/2010:20:22:16 +0800] "POST /syxcms/vote.php?act=submit HTTP/1.1" 200 72 "http://www.*****.com/news/201005/news-6213.shtml" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
www.*****.com:80 118.251.244.183 - - [26/May/2010:20:22:16 +0800] "POST /syxcms/vote.php?act=submit HTTP/1.1" 200 56 "http://www.*****.com/news/201005/news-6213.shtml" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
大概原理就是对最新日志里面的客户端访问IP进行采样统计分析,然后对超出正常访问次数的IP进行屏蔽,如下面统计分析后的结果:
对最新1000条日志的客户端访问IP进行排序统计访问次数。比如第一个IP 219.128.20.68 1000条日志就有295条,访问肯定不正常
root@ubuntu134:# tail access.log -n 1000 |grep vote.php |awk {'print $2'} |sort |uniq -c |sort -nr
295 219.128.20.68
175 113.250.97.209
164 218.87.140.39
153 59.61.215.42
98 222.240.182.234
83 220.181.110.65
73 120.38.1.255
62 221.3.99.106
21 220.249.83.74
12 218.22.10.114
1 123.52.158.16
1 114.81.115.201
然后就是自动处理,如果1000条日志单IP超过50条就屏蔽掉
*/2 * * * * /usr/local/nginx/var/log/drop.sh
#!/bin/sh
cd /usr/local/nginx/var/log
tail access.log -n 1000 |grep vote.php |awk {'print $2'} |sort |uniq -c |sort -nr |awk '{if ($2!=null && $1>50) {print $2}}' > drop_ip.txt
for i in `cat drop_ip.txt`
do
/sbin/iptables -I INPUT -s $i -j DROP;
done
这shell 每几分钟执行一次,就可自动屏蔽那些不正常IP,相信大家都看的懂,下面是针对连接数屏蔽代码
#!/bin/sh
/bin/netstat -ant |grep 80 |awk '{print $5}' |awk -F : '{print $1}' |sort |uniq -c |sort -rn |grep -v -E '192.168|127.0' |awk '{if ($2!=null && $1>50) {print $2}}' > drop_ip.txt
for i in `cat drop_ip.txt`
do
/sbin/iptables -I INPUT -s $i -j DROP;
done
说下,grep -v -E '192.168|127.0' 也就是排除内网IP,免得把自己给屏蔽了,当然还可以加些自己的IP。
http://sookk8.blog.51cto.com/455855/448539
相关文章推荐
- shell结合iptables自动处理CC攻击
- 利用shell结合iptables自动处理CC***
- shell结合iptables自动拒绝恶意连接ssh
- shell 结合iptables防止小型CC攻击
- shell for循环案例:自动批量添加iptables应用端口规则 推荐
- 利用shell自动将异常IP加入iptables黑名单
- shell脚本结合iptables防端口扫描的实现
- 批处理脚本结合Maven制作的自动打包工具
- zabbix结合shell实现自动发现占用内存最大top10进程并监控其资源
- Linux系统防CC攻击自动拉黑IP增强版Shell脚本
- shell基础——字符串处理(转载)
- Linux简单处理CC攻击shell脚本
- 用iptables自动封连接数较大的IP防止CC攻击的方法 zt
- 关于session不能自动去除的临时处理方法(转载)我一直没用SESSI
- 转载:shell 字符串处理汇总(查找,替换等等)
- zabbix自动发现结合shell实现自动发现占用内存最大top10进程并监控其资源 推荐
- crontab结合用PHP编写的shell完成自动更新数据的程序
- 如何处理xfce vnc 下 shell 自动完成需要 ctrl + tab的问题
- Linux系统防CC攻击自动拉黑IP增强版Shell脚本
- [转载]【Shell脚本】逐行处理文本文件