一個簡單的防CC攻擊Shell腳本分享
更新時間:2014年06月13日 09:13:43 投稿:junjie
這篇文章主要介紹了一個簡單的防CC攻擊Shell腳本分享,主要原理是分析apache或者nginx的訪問日志,對大量訪問的IP加入iptables進(jìn)行禁止訪問,需要的朋友可以參考下
實現(xiàn)代碼:
復(fù)制代碼 代碼如下:
#!/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加入防火墻,并禁止訪問
相關(guān)文章
學(xué)習(xí)Linux網(wǎng)絡(luò)編程基本函數(shù)
這篇文章主要介紹了學(xué)習(xí)Linux網(wǎng)絡(luò)編程,網(wǎng)絡(luò)編程的一些基本函數(shù):也是實現(xiàn)tcp協(xié)議通訊的基本步驟,實現(xiàn)代碼在最后,IP需要修改為自己的IP,即可通信2021-08-08shell腳本殺死指定端口進(jìn)程的實現(xiàn)示例
隨著越來越廣泛的Linux系統(tǒng)使用,如何輕松殺死指定程序端口成為了很多系統(tǒng)管理員最迫切關(guān)心的問題,本文就詳細(xì)的介紹一下如何實現(xiàn),感興趣的可以了解一下2023-10-10