May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Shell script for apache dos protection

#!/bin/bash
cur=`date +%H%M%S`
becur=`date -d “1 minute ago” +%H%M%S`
badip=`tail -n 10000 /var/log/httpd/access_log | egrep -v “\.(gif|jpg|jpeg|png|css|js)” | awk -v a=”$becu
r” -v b=”$cur” -F [‘ ‘:] ‘{t=$5$6$7;if (t>=a && t<=b) print $1}' | sort | uniq -c | awk '{if ($1>=20) print $2}
‘`
if [ ! -z $badip ];then
for ip in $badip;
do
if test -z “`/sbin/iptables -nL | grep $ip`”;then
/sbin/iptables -I INPUT -s $ip -j DROP
fi
done
fi

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>