cinsarmy.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. echo "Downloading the cinsarmy bad guys list of IPs."
  7. wget -c https://cinsscore.com/list/ci-badguys.txt -O $BADGUYS_FILE
  8. echo "Making sure it downloaded..."
  9. # Check if the file exists
  10. if [[ ! -f "$BADGUYS_FILE" ]]; then
  11. echo "File not found: $BADGUYS_FILE"
  12. exit 1
  13. fi
  14. # Check if the chain exists, and creates it if it's not there
  15. if $FIREWALL -L $CHAIN_NAME -n &> /dev/null; then
  16. echo "Chain $CHAIN_NAME already exists."
  17. $FIREWALL -F $CHAIN_NAME
  18. else
  19. echo "Creating chain $CHAIN_NAME."
  20. $FIREWALL -N $CHAIN_NAME
  21. # Jump to our chain from the FORWARD chain
  22. $FIREWALL -A FORWARD -j $CHAIN_NAME
  23. fi
  24. echo "Processing the updated bad guys list..."
  25. # Read each line (IP address) from the file and block it
  26. while IFS= read -r ip; do
  27. # Check if the line is not empty
  28. if [[ -n "$ip" ]]; then
  29. # Block the IP address using $FIREWALL
  30. $FIREWALL -A $CHAIN_NAME -i $ETH -s "$ip" -j DROP
  31. # echo "Blocked IP: $ip"
  32. fi
  33. done < "$BADGUYS_FILE"
  34. # Delete the bad guys file
  35. rm $BADGUYS_FILE
  36. echo "Bad guys list has been processed, and deleted."