Created
September 10, 2017 16:39
-
-
Save woohooyeah/28f2f400cacc4c53339c8e233d258b65 to your computer and use it in GitHub Desktop.
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
| ## insert-spammers-into-iptables.sh v0.1 | |
| ## Dorian Harmans <[email protected]> | |
| ## | |
| #!/bin/bash | |
| if [ -e /root/spammers.txt ]; then | |
| /sbin/iptables-save > /root/iptables.rules && cp /root/iptables.rules /root/iptables.rules-old | |
| else | |
| echo -e "Failed!\nReason: /root/spammers.txt not found" | |
| exit 1 | |
| fi | |
| if [ -e /root/iptables.rules ]; then | |
| grep -E "(-A INPUT -s | -j DROP)" /root/iptables.rules | awk '{ print $4 }' > /root/ip-blocklist-old.txt | |
| grep -vE "(-A INPUT -s | -j DROP)" /root/iptables.rules > /root/iptables.rules-clean | |
| else | |
| echo -e "Failed!\nReason: /root/iptables.rules not found" | |
| exit 1 | |
| fi | |
| if [ -e /root/iptables.rules-clean ]; then | |
| /sbin/iptables-restore < /root/iptables.rules-clean | |
| else | |
| echo -e "Failed!\nReason: /root/iptables.rules-clean not found" | |
| exit 1 | |
| fi | |
| if [ -e /root/spammers.txt ]; then | |
| for line in $(cat /root/spammers.txt); do /sbin/iptables -A INPUT -s $line/32 -j DROP; done | |
| else | |
| echo -e "Failed!\nReason: /root/spammers.txt not found" | |
| exit 1 | |
| fi | |
| if [ -e /root/iptables.rules ]; then | |
| /sbin/iptables-save > /etc/iptables.rules && /sbin/iptables-save > /root/iptables.rules-new | |
| grep -E "(-A INPUT -s | -j DROP)" /root/iptables.rules-new | awk '{ print $4 }' > /root/ip-blocklist-new.txt | |
| else | |
| echo -e "Failed!\nReason: /root/iptables.rules-new not found" | |
| exit 1 | |
| fi | |
| if [ -e /root/ip-blocklist-old.txt ] && [ -e /root/ip-blocklist-new.txt ]; then | |
| diff -Naur /root/ip-blocklist-old.txt /root/ip-blocklist-new.txt | |
| else | |
| echo -e "Failed!\nReason: /root/ip-blocklist-{old,new} not found" | |
| exit 1 | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment