discuss AT lists.opennicproject.org
Subject: Discuss mailing list
List archive
- From: Jeff Taylor <shdwdrgn AT sourpuss.net>
- To: discuss AT lists.opennicproject.org
- Subject: Re: [opennic-discuss] Killed an IP due to excessive usage
- Date: Wed, 29 Dec 2010 20:54:39 -0700
- List-archive: <http://lists.darkdna.net/pipermail/discuss>
- List-id: <discuss.lists.opennicproject.org>
On 12/29/2010 06:00 PM, Barnaby Astles wrote:
Would it be possible to have a look at you script ? It could have multiple uses.
Sure, no problem. This relies on you having a logging option for security in BIND. In my case, that info is logged in /var/log/named/filter. The BLOCK variable simply points to where the script can store a file containing the blocked IPs and what time their block expires. If you do not run this script as root, simply touch the file with the proper user rights.
I have made some refinements to the script this evening. It now looks only at the lines which have been added to the log since the last iteration of the script (and that is now running once every second). It also is more critical of what is being blocked -- a single IP has to be pushing this particular query at least 10 times per second before they are blocked. That should be sufficient to ensure there are no false-positives.
#!/bin/bash
BLOCK="/etc/ddos.block"
LOGFILE="/var/log/named/filter"
NAME="DNS_Filter"
LAST="-n100"
while true ; do
FILTER=`tail $LAST $LOGFILE | grep "query: isc.org IN ANY +ED" | awk "{ print $6 }" | cut -d\# -f1 | sort | uniq`
now=`date "+%s"`
for IP in $FILTER ; do
if [ "`grep $IP $BLOCK`" == "" ] ; then
COUNT=`tail $LAST $LOGFILE | grep 'query: isc.org IN ANY +ED' | grep $IP | wc -l`
if [ $COUNT -ge 10 ] ; then
iptables -A INPUT -s $IP -j DROP
END=$(($now + 600))
echo "$END $IP" >> $BLOCK
logger -t $NAME Blocked $IP
fi
fi
done
if [ -f "$BLOCK" ] ; then
while read timeout IP ; do
if [ $timeout -lt $now ] ; then
iptables -D INPUT -s $IP -j DROP 2>/dev/null
sed "/$IP/d" $BLOCK > /tmp/ddos.block
mv /tmp/ddos.block $BLOCK
logger -t $NAME Removed $IP
fi
done < $BLOCK
fi
LAST="-c+`stat -c%s $LOGFILE`"
sleep 1
done
- Re: [opennic-discuss] Killed an IP due to excessive usage, (continued)
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/28/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Larry Brower, 12/28/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/28/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Julian De Marchi, 12/28/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/28/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Dustin, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Barnaby Astles, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/30/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Dustin, 12/30/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/30/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Barnaby Astles, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Jeff Taylor, 12/29/2010
- Re: [opennic-discuss] Killed an IP due to excessive usage, Dustin, 12/29/2010
Archive powered by MHonArc 2.6.19.