Commit ad0f8f1d authored by Vitaly Lipatov's avatar Vitaly Lipatov

update ddos script

parent 2f779e48
#!/bin/sh
for id in $(vzlist | sed -e "s| *\([0-9]*\).*|\1|g") ; do
CONF=/etc/vz/conf/$id.conf
test -r $CONF || continue
eval `cat $CONF | grep ^HOSTNAME | sed -e "s|office.etersoft.ru||g"`
printf "%4s (%20s):" $id $HOSTNAME
vzctl exec $id uptime
done
echo "---"
uptime
#!/bin/bash #!/bin/bash
cd /root/bin cd /root/bin
IFDEV=breth0 # Сколько запросов анализируем за раз
# Сколко запоов анализием за аз
NUMP=10000 NUMP=10000
# Сколко поенов може занима один аде # Сколько процентов может занимать один адрес
MAXPERC=15 MAXPERC=15
# акимм вемени на tcpdmp # Максимум времени на tcpdmp
TIMEP=15 TIMEP=15
get_already_dropped() get_already_dropped()
{ {
/sbin/iptables -L -n | grep DROP | awk '{print $4;}' > ipt.dropped.list /sbin/iptables -L -n | grep DROP | awk '{print $4;}' > ipt.dropped.list
} }
do_drop() do_drop()
{ {
grep -q "$1" ipt.dropped.list white.list && return 1 grep -q "$1" ipt.dropped.list white.list && return 1
echo "$1 # $2 percent, $(date)" >> dropped.list echo "$1 # $2 percent, $(date)" >> dropped.list
/sbin/iptables -A INPUT -s $1 -j DROP /sbin/iptables -A INPUT -s $1 -j DROP
} }
get_already_dropped get_already_dropped
SECST=$(date "+%s") SECST=$(date "+%s")
timeout -s SIGQUIT $TIMEP /usr/sbin/tcpdump -n -c $NUMP -f -i $IFDEV dst 212.176.192.225 or dst 212.176.200.17 | \ timeout -s SIGQUIT $TIMEP /usr/sbin/tcpdump -n -c $NUMP -f -i inet dst 212.176.192.225 or dst 212.176.200.17 | \
awk '{print $3;}' | \ awk '{print $3;}' | \
sed 's/\([[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\)\..*/\1/g' > full.list sed 's/\([[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\)\..*/\1/g' > full.list
SECST=$(($(date "+%s")-$SECST)) SECST=$(($(date "+%s")-$SECST))
NUMP=$(cat full.list | wc -l) NUMP=$(cat full.list | wc -l)
...@@ -36,12 +34,12 @@ cat full.list | sort | uniq -c | sort -r -n > attack.list ...@@ -36,12 +34,12 @@ cat full.list | sort | uniq -c | sort -r -n > attack.list
TOTALATTACKED=0 TOTALATTACKED=0
while read c ip ; do while read c ip ; do
#echo $c = $ip #echo $c = $ip
perc=$((100*$c/$NUMP)) perc=$((100*$c/$NUMP))
if [ $perc -gt $MAXPERC ] ; then if [ $perc -gt $MAXPERC ] ; then
do_drop $ip $perc && echo "Drop IP $ip with $perc percent traffic" || echo "IP $ip already dropped" do_drop $ip $perc && echo "Drop IP $ip with $perc percent traffic" || echo "IP $ip already dropped"
TOTALATTACKED=$(($TOTALATTACKED+$perc)) TOTALATTACKED=$(($TOTALATTACKED+$perc))
fi fi
done < attack.list done < attack.list
echo "Checked packages: $NUMP ($SECST secs). Traffic: $(($NUMP/$SECST)) rps. Atacker percent: $TOTALATTACKED" | tee result.out echo "Checked packages: $NUMP ($SECST secs). Traffic: $(($NUMP/$SECST)) rps. Atacker percent: $TOTALATTACKED" | tee result.out
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment