一個(gè)簡(jiǎn)單的防CC攻擊Shell腳本分享
更新時(shí)間:2014年06月13日 09:13:43 投稿:junjie
這篇文章主要介紹了一個(gè)簡(jiǎn)單的防CC攻擊Shell腳本分享,主要原理是分析apache或者nginx的訪問日志,對(duì)大量訪問的IP加入iptables進(jìn)行禁止訪問,需要的朋友可以參考下
實(shí)現(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
使用方法,運(yùn)行命令:sh limit.sh,這樣就會(huì)把訪問量過高的IP加入防火墻,并禁止訪問
相關(guān)文章
學(xué)習(xí)Linux網(wǎng)絡(luò)編程基本函數(shù)
這篇文章主要介紹了學(xué)習(xí)Linux網(wǎng)絡(luò)編程,網(wǎng)絡(luò)編程的一些基本函數(shù):也是實(shí)現(xiàn)tcp協(xié)議通訊的基本步驟,實(shí)現(xiàn)代碼在最后,IP需要修改為自己的IP,即可通信2021-08-08shell腳本殺死指定端口進(jìn)程的實(shí)現(xiàn)示例
隨著越來越廣泛的Linux系統(tǒng)使用,如何輕松殺死指定程序端口成為了很多系統(tǒng)管理員最迫切關(guān)心的問題,本文就詳細(xì)的介紹一下如何實(shí)現(xiàn),感興趣的可以了解一下2023-10-10Shell時(shí)間運(yùn)算及時(shí)間差計(jì)算方法
這篇文章主要介紹了Shell時(shí)間運(yùn)算及時(shí)間差計(jì)算方法,本文講解了時(shí)間時(shí)間加減運(yùn)算以及時(shí)間差計(jì)算方法,需要的朋友可以參考下2015-07-07設(shè)置Shell腳本開機(jī)自啟的方法和實(shí)例
這篇文章主要介紹了設(shè)置Shell腳本開機(jī)自啟的方法和實(shí)例,文中通過代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02Shell腳本實(shí)現(xiàn)ftok函數(shù)
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)ftok函數(shù),ftok函數(shù)是操作系統(tǒng)底層中很有名的一個(gè)函數(shù),本文講在Shell中如何實(shí)現(xiàn)同樣算法的函數(shù),需要的朋友可以參考下2015-01-01