November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

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>