Skip to content

Instantly share code, notes, and snippets.

@csrutil
Created May 14, 2017 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csrutil/f52a3851caf15f0d83f2eac3c9395432 to your computer and use it in GitHub Desktop.
Save csrutil/f52a3851caf15f0d83f2eac3c9395432 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Fetch NEU SSH Black list to /etc/hosts.deny
#
# http://antivirus.neu.edu.cn/scan/ssh.php
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
URL=http://antivirus.neu.edu.cn/ssh/lists/neu_sshbl_hosts.deny.gz
HOSTSDENY=/etc/hosts.deny
TMP_DIR=/dev/shm
FILE=hosts.deny
[ -d $TMP_DIR ] || TMP_DIR=/tmp
cd $TMP_DIR
curl --connect-timeout 60 $URL 2> /dev/null | gzip -dc > $FILE 2> /dev/null
LINES=`grep "^sshd:" $FILE | wc -l`
if [ $LINES -gt 10 ]
then
sed -i '/^####SSH BlackList START####/,/^####SSH BlackList END####/d' $HOSTSDENY
echo "####SSH BlackList START####" >> $HOSTSDENY
cat $FILE >> $HOSTSDENY
echo "####SSH BlackList END####" >> $HOSTSDENY
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment