Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Blacklist's names & URLs arrays
- bl_name=([0]='spyware')
- bl_url=([0]='http://list.iblocklist.com/?list=bt_spyware&fileformat=p2p&archiveformat=gz')
- bl_name=(${bl_name[*]} [1]='webexploit')
- bl_url=(${bl_url[*]} [1]='http://list.iblocklist.com/?list=ghlzqtqxnzctvvajwwag&fileformat=p2p&archiveformat=gz')
- bl_name=(${bl_name[*]} [2]='spider')
- bl_url=(${bl_url[*]} [2]='http://list.iblocklist.com/?list=bt_spider&fileformat=p2p&archiveformat=gz')
- bl_name=(${bl_name[*]} [3]='hijacked')
- bl_url=(${bl_url[*]} [3]='http://list.iblocklist.com/?list=bt_hijacked&fileformat=p2p&archiveformat=gz')
- bl_name=(${bl_name[*]} [4]='dshield')
- bl_url=(${bl_url[*]} [4]='http://list.iblocklist.com/?list=bt_dshield&fileformat=p2p&archiveformat=gz')
- bl_name=(${bl_name[*]} [5]='bogon')
- bl_url=(${bl_url[*]} [5]='http://list.iblocklist.com/?list=bt_bogon&fileformat=p2p&archiveformat=gz')
- # For each blacklist set above
- for i in {0..5}; do
- # Download blacklist
- wget --output-document=/tmp/blacklist_${bl_name[$i]}.gz -w 3 ${bl_url[$i]} -q
- # Delete current iptables chain link
- iptables -D INPUT -j ${bl_name[$i]}
- # Flush current iptables chain
- iptables -F ${bl_name[$i]}
- # Delete current iptables chain
- iptables -X ${bl_name[$i]}
- # Create current iptables chain
- iptables -N ${bl_name[$i]}
- # Link current iptables chain to INPUT chain
- iptables -A INPUT -j ${bl_name[$i]}
- # Read blacklist
- while read line; do
- # Drop description, keep only IP range
- ip_range=`echo -n $line | sed -e 's/.*:\(.*\)-\(.*\)/\1-\2/'`;
- # Test if it's an IP range
- if [[ $ip_range =~ ^[0-9].*$ ]]; then
- # Add to the blacklist
- iptables -A ${bl_name[$i]} -m iprange --src-range $ip_range -j DROP
- fi
- done < <(zcat /tmp/blacklist_${bl_name[$i]}.gz | iconv -f latin1 -t utf-8 - | dos2unix)
- done
- # Delete files
- rm /tmp/blacklist*
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment