一個簡單的防CC攻擊Shell腳本分享
更新時間:2014年06月13日 09:13:43 投稿:junjie
這篇文章主要介紹了一個簡單的防CC攻擊Shell腳本分享,主要原理是分析apache或者nginx的訪問日志,對大量訪問的IP加入iptables進行禁止訪問,需要的朋友可以參考下
實現(xiàn)代碼:
復制代碼 代碼如下:
#!/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加入防火墻,并禁止訪問
相關文章
shell 通過makefile傳參給c語言的實現(xiàn)示例
本文主要介紹了shell 通過makefile傳參給c語言的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-03-03
Shell腳本函數(shù)傳遞參數(shù)的實現(xiàn)方法
本文主要介紹了Shell腳本函數(shù)傳遞參數(shù)的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-07-07
Linux 中可重入函數(shù)與不可重入函數(shù)詳解
這篇文章主要介紹了Linux 中可重入函數(shù)與不可重入函數(shù)詳解的相關資料,需要的朋友可以參考下2017-06-06

