Create jsinix_spamhaus_blacklist.py

root@M14XR2:~/scripts# ./jsinix_iptables.py

         _     _       _
        (_)   (_)     (_)
         _ ___ _ _ __  ___  __
        | / __| | '_ \| \ \/ /
        | \__ \ | | | | |>  <
        | |___/_|_| |_|_/_/\_\.
       _/ |
      |__/




Author: jsinix(jsinix.1337@gmail.com)

I wrote this script to setup basic iptable rules to secure the system.
In addition to that, this script queries spamhaus's blacklisted IP/Network
addresses. These IP's are then stored in a new chain called droplist. Finally
it is referenced in the default filter table chains(i.e INPUT, OUTPUT and FORWARD).
This script or its customized version can be useful for many type of public 
facing servers including mail servers to protect from spams etc.
Please use this at yur own risk and read carefully before using. You might 
need to change some parts according to your needs. 




(+) Flushing old rules in droplist

(+) Installing firewall
(+) Firewall is running
(+) Setting up firewall on startup

(+) Creating droplist chain
(+) Quering Spamhaus Blacklist
(+) Refreshing droplist chain
(+) Applying droplist to filter chain

(+) Firewall updated !

+++++++++++++++++++++++++++++++++++++++++

root@M14XR2:~/scripts# iptables -L -n | less

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
droplist   all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
REJECT     all  --  0.0.0.0/0            127.0.0.0/8          reject-with icmp-port-unreachable
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            state NEW tcp dpt:22
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
LOG        all  --  0.0.0.0/0            0.0.0.0/0            limit: avg 5/min burst 5 LOG flags 0 level 7 prefix "iptables denied: "
DROP       all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
droplist   all  --  0.0.0.0/0            0.0.0.0/0           
DROP       all  --  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
droplist   all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           

Chain droplist (3 references)
target     prot opt source               destination         
DROP       all  --  10.0.0.0             0.0.0.0/0           
DROP       all  --  11.0.0.0             0.0.0.0/0           
DROP       all  --  1.116.0.0/14         0.0.0.0/0           
DROP       all  --  5.34.242.0/23        0.0.0.0/0           
DROP       all  --  5.72.0.0/14          0.0.0.0/0