Created
August 9, 2018 21:27
-
-
Save Ekultek/b8cf855b4e1547d8d1f440f91aa87a91 to your computer and use it in GitHub Desktop.
A script to download bad IP addresses and deny them with UFW
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 | |
TMP_DIR="/tmp" | |
URL_LINKS=$"http://www.blocklist.de/lists/ssh.txt | |
http://www.blocklist.de/lists/apache.txt | |
http://www.blocklist.de/lists/asterisk.txt | |
http://www.blocklist.de/lists/bots.txt | |
http://www.blocklist.de/lists/courierimap.txt | |
http://www.blocklist.de/lists/courierpop3.txt | |
http://www.blocklist.de/lists/email.txt | |
http://www.blocklist.de/lists/ftp.txt | |
http://www.blocklist.de/lists/imap.txt | |
http://www.blocklist.de/lists/ircbot.txt | |
http://www.blocklist.de/lists/pop3.txt | |
http://www.blocklist.de/lists/postfix.txt | |
http://www.blocklist.de/lists/proftpd.txt | |
http://www.blocklist.de/lists/sip.txt | |
http://www.ciarmy.com/list/ci-badguys.txt | |
http://charles.the-haleys.org/ssh_dico_attack_hdeny_format.php/hostsdeny.txt | |
http://www.nothink.org/blacklist/blacklist_ssh_day.txt | |
http://malc0de.com/bl/IP_Blacklist.txt | |
http://www.nothink.org/blacklist/blacklist_malware_dns.txt | |
http://www.nothink.org/blacklist/blacklist_malware_http.txt | |
http://www.nothink.org/blacklist/blacklist_malware_irc.txt" | |
function denyHost() { | |
sudo ufw deny from $1; | |
} | |
function getLists() { | |
if [[ ! -d "${BACKUP_DIR}" ]]; then | |
mkdir -p "${BACKUP_DIR}"; | |
fi; | |
for line in echo ${URL_LINKS}; do | |
filename=$(python -c 'import string; import random; acc=string.ascii_letters; d=["".join([random.choice(acc) for _ in range(1)]) for _ in range(7)]; print("".join(d))') | |
writeTo="${TMP_DIR}/${filename}.deny"; | |
touch $writeTo; | |
curl -o "${writeTo}" $line; | |
while read item; do | |
denyHost $item; | |
done < "${writeTo}"; | |
done; | |
} | |
getLists; |
However you want to do it.
now i dont have much time, but maybe in the future i will fork something more efficient taking your code as a base ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's taking so much time to add one rule (one rule per second).
The way U do this must be more efficient.
Maybe editing user.rules and reloading the ufw?