Last active
May 9, 2022 14:05
-
-
Save dewomser/7fc6ba3f3655ad30ae39a89a9ee692cc to your computer and use it in GitHub Desktop.
greensnow and ufw a bashscript
This file contains hidden or 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 | |
ufwpath="/home/foo/bin/greesnow-test" | |
rm "greensnow.txt" | |
wget https://blocklist.greensnow.co/greensnow.txt -O greensnow1.txt | |
tail -n 30 greensnow1.txt > greensnow.txt | |
head -n -16 $ufwpath"user.rules.gut" > "user.rules.gut1" | |
while read -r line; do | |
echo "### tuple ### deny any any 0.0.0.0/0 any $line in" >> user.rules.gut1 | |
echo "-A ufw-user-input -s $line -j DROP" >> user.rules.gut1 | |
echo " " >> user.rules.gut1 | |
done < greensnow.txt | |
echo '### END RULES ### | |
### LOGGING ### | |
-A ufw-after-logging-input -j LOG --log-prefix "[UFW BLOCK] " -m limit --limit 3/min --limit-burst 10 | |
-A ufw-after-logging-forward -j LOG --log-prefix "[UFW BLOCK] " -m limit --limit 3/min --limit-burst 10 | |
-I ufw-logging-deny -m conntrack --ctstate INVALID -j RETURN -m limit --limit 3/min --limit-burst 10 | |
-A ufw-logging-deny -j LOG --log-prefix "[UFW BLOCK] " -m limit --limit 3/min --limit-burst 10 | |
-A ufw-logging-allow -j LOG --log-prefix "[UFW ALLOW] " -m limit --limit 3/min --limit-burst 10 | |
### END LOGGING ### | |
### RATE LIMITING ### | |
-A ufw-user-limit -m limit --limit 3/minute -j LOG --log-prefix "[UFW LIMIT BLOCK] " | |
-A ufw-user-limit -j REJECT | |
-A ufw-user-limit-accept -j ACCEPT | |
### END RATE LIMITING ### | |
COMMIT' >> user.rules.gut1 | |
cp user.rules.gut1 $ufwpath"user.rules" | |
sleep 2 | |
# /usr/sbin/ufw reload | |
#-A ufw-user-input -s 46.38.145.253 -j DROP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Natürlich muss man Pfade und Zeugs anpassen, An der UFW spielt man nicht. Sei dir bewusst was du machst.
Hinter tail -n kann man die Anzahl der gesperrten IPs einstellen, falls der Server wegen der schieren Masse kotzt.