cinsarmy.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/bash
  2. BADGUYS_FILE="" # The location (full path) where you want to download the list
  3. CHAIN_NAME="CINSARMY_IPS" # The firewall chain to hold the cinsarmy rules
  4. FIREWALL="/sbin/iptables" # The path to iptables
  5. ETH="" # The name of the ethernet port you'd like to apply these rules to. Example: eth1
  6. BLOCKMODE="" # If you want these rules to apply to just this machine, this should be "INPUT".
  7. # If you want these rules to apply to a network behind this machine, this should be "FORWARD".
  8. echo "Downloading the cinsarmy bad guys list of IPs."
  9. wget -c https://cinsscore.com/list/ci-badguys.txt -O $BADGUYS_FILE
  10. echo "Making sure it downloaded..."
  11. # Check if the file exists
  12. if [[ ! -f "$BADGUYS_FILE" ]]; then
  13. echo "File not found: $BADGUYS_FILE"
  14. exit 1
  15. fi
  16. # Check if the chain exists, and creates it if it's not there
  17. if $FIREWALL -L $CHAIN_NAME -n &> /dev/null; then
  18. echo "Chain $CHAIN_NAME already exists."
  19. $FIREWALL -F $CHAIN_NAME
  20. else
  21. echo "Creating chain $CHAIN_NAME."
  22. $FIREWALL -N $CHAIN_NAME
  23. # Jump to our chain from the FORWARD chain
  24. $FIREWALL -A $BLOCKMODE -j $CHAIN_NAME
  25. fi
  26. echo "Processing the updated bad guys list. This might take a while..."
  27. # Read each line (IP address) from the file and block it
  28. while IFS= read -r ip; do
  29. # Check if the line is not empty
  30. if [[ -n "$ip" ]]; then
  31. # Block the IP address using $FIREWALL
  32. $FIREWALL -A $CHAIN_NAME -i $ETH -s "$ip" -j DROP
  33. # echo "Blocked IP: $ip"
  34. fi
  35. done < "$BADGUYS_FILE"
  36. # Delete the bad guys file
  37. rm $BADGUYS_FILE
  38. echo "Bad guys list has been processed, and deleted."