SSH ochrana před roboty
Z Wiki UnArt Slavičín
#!/bin/bash DIR="var/log" DAY=`date |awk '{print $1}'` FILE="auth_$DAY.log" EMAIL="muj@mail.cz" POKUS=10 # uklid na zacatek rm -f /$DIR/auth/$FILE touch /$DIR/auth/tmp # zaloha auth.log cat /$DIR/auth.log >> /$DIR/auth/$FILE #rm -f /$DIR/auth.log #touch /$DIR/auth.log # unikatni IP ze souboru + pridani do block_ip grep "Invalid user" /$DIR/auth/$FILE |awk '{print $10}' |uniq > /$DIR/auth/tmp; cat /$DIR/auth/tmp >> /$DIR/auth/block_ip # blokovani nalezenych IP SIZE=`wc -l /$DIR/auth/tmp |awk '{print $1}'`; SIZE=`expr $SIZE + 1`; I=1 while test $I -lt $SIZE do IP=`sed -n "$I"p /$DIR/auth/tmp`; I=`expr $I + 1`; POCET=`cat /$DIR/auth/$FILE |grep $IP |wc -l |awk '{print $1}'`; if [ $POCET -gt $POKUS ] ; then echo $POCET # iptables -A INPUT -s $IP -j DROP echo $IP fi done #mail cat /$DIR/auth/tmp |mail -s "Blokovane IP" $EMAIL