Last active
December 14, 2015 16:39
-
-
Save cyjake/5116985 to your computer and use it in GitHub Desktop.
A simple vsftpd guard script for preventing bad guys from brute guessing your ftp account. The original version is created by @hugozhu for blocking ssh account guessing. http://hugozhu.myalert.info/2013/03/08/block_failed_ssh_attempts_with_iptable.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
last_ip="" | |
tail -f /var/log/vsftpd.log | while read LINE; do | |
{ | |
if [[ "${LINE}" =~ "FAIL LOGIN" ]]; then | |
ip="$(echo ${LINE} | awk '{ip=$NF;gsub(/\"/,"",ip);print ip}')" | |
if [[ "$last_ip" == "$ip" ]]; then | |
echo "block $ip" | |
iptables -A INPUT -s "$ip" -j DROP | |
fi | |
last_ip=$ip | |
echo $LINE | |
fi | |
} | |
done | |
# nohup /root/bin/guard.sh > /var/log/guard.log 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment