Update blocklist.sh

This commit is contained in:
Alfonso 2023-02-06 11:58:31 +01:00 committed by GitHub
parent a000daa412
commit a48bd42238
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
if [ "$(whoami)" == "root" ]; then echo "root ok"; else echo "run as root!"; exit 1; fi; if [ "$(whoami)" == "root" ]; then echo "root ok"; else echo "run as root!"; exit 1; fi;
#IPTABLES_PATH=$(whereis iptables | awk '{print $2}') IPTABLES_PATH=$(whereis iptables | awk '{print $2}')
#IPSET_PATH=$(whereis ipset | awk '{print $2}') #IPSET_PATH=$(whereis ipset | awk '{print $2}')
#SORT_PATH=$(whereis sort | awk '{print $2}') #SORT_PATH=$(whereis sort | awk '{print $2}')
#GREP_PATH=$(whereis grep | awk '{print $2}') #GREP_PATH=$(whereis grep | awk '{print $2}')
@ -11,8 +11,8 @@ abuse_key="INSERT_YOUR_API_KEY_HERE" #https://www.abuseipdb.com/account/api
#if [ -f $IPTABLES_PATH ]; then echo "iptables OK"; else echo "Cannot find [ iptables ]. Is it installed? Exiting"; exit 1; fi; if [ -f $IPTABLES_PATH ]; then echo "iptables OK"; else "I require iptables but it's not installed."; apt install -y iptables; fi;
if ! command -v iptables >/dev/null; then echo "I require iptables but it's not installed."; apt install -y iptables; else echo "iptables OK"; fi; #if ! command -v iptables >/dev/null; then echo "I require iptables but it's not installed."; apt install -y iptables; else echo "iptables OK"; fi;
#if [ -f $IPSET_PATH ]; then echo "ipset OK"; else echo "Cannot find [ ipset ]. Is it installed? Exiting"; exit 1; fi; #if [ -f $IPSET_PATH ]; then echo "ipset OK"; else echo "Cannot find [ ipset ]. Is it installed? Exiting"; exit 1; fi;
if ! command -v ipset >/dev/null; then echo "I require ipset but it's not installed."; apt install -y ipset; else echo "ipset OK"; fi; if ! command -v ipset >/dev/null; then echo "I require ipset but it's not installed."; apt install -y ipset; else echo "ipset OK"; fi;
#if [ -f $SORT_PATH ]; then echo "sort OK"; else echo "Cannot find [ sort ]. Is it installed? Exiting"; exit 1; fi; #if [ -f $SORT_PATH ]; then echo "sort OK"; else echo "Cannot find [ sort ]. Is it installed? Exiting"; exit 1; fi;
@ -23,13 +23,13 @@ if ! command -v jq >/dev/null; then echo "I require jq but it's not installed."
if ! command -v grep >/dev/null; then echo "I require grep but it's not installed."; apt install -y grep; else echo "grep OK"; fi; if ! command -v grep >/dev/null; then echo "I require grep but it's not installed."; apt install -y grep; else echo "grep OK"; fi;
echo "Downloading the most recent IP list from $BLOCKLISTDE ... and adding them to ipset blocklistde" echo "Downloading the most recent IP list from $BLOCKLISTDE ... and adding them to ipset blocklistde"
ipset create blocklistde hash:ip $(whereis ipset | cut -d" " -f 2) create blocklistde hash:ip
curl -s https://lists.blocklist.de/lists/all.txt | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | xargs -L1 ipset add blocklistde 2>&1 curl -s https://lists.blocklist.de/lists/all.txt | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | xargs -L1 ipset add blocklistde 2>&1
echo "Downloading the most recent IP list from $CRWALERS ... and adding them to ipset crawler_bots" echo "Downloading the most recent IP list from $CRWALERS ... and adding them to ipset crawler_bots"
ipset create crawler_bots hash:ip $(whereis iptset | cut -d" " -f 2) create crawler_bots hash:ip
curl -s https://isc.sans.edu/api/threatcategory/research?json | jq '.[] | {ipv4}' | grep ':' | awk '{ print $2 }' | tr -d '"' | xargs -L1 ipset add crawler_bots 2>&1 curl -s https://isc.sans.edu/api/threatcategory/research?json | jq '.[] | {ipv4}' | grep ':' | awk '{ print $2 }' | tr -d '"' | xargs -L1 ipset add crawler_bots 2>&1
echo "Downloading the most recent IP list from $ABUSE and adding them to abuseipdb" echo "Downloading the most recent IP list from $ABUSE and adding them to abuseipdb"
ipset create abuseipdb hash:ip $(whereis iptset | cut -d" " -f 2) create abuseipdb hash:ip
curl -s -H "key: $abuse_key" https://api.abuseipdb.com/api/v2/blacklist | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | xargs -L1 ipset add abuseipdb 2>&1 curl -s -H "key: $abuse_key" https://api.abuseipdb.com/api/v2/blacklist | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | xargs -L1 ipset add abuseipdb 2>&1
echo "Adding the iptables rules..." echo "Adding the iptables rules..."
$(whereis iptables | cut -d" " -f 2) -I INPUT -m set --match-set crawler_bots src -j DROP $(whereis iptables | cut -d" " -f 2) -I INPUT -m set --match-set crawler_bots src -j DROP