
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# Blacklist selected hosts and/or networks from ALL services. Both input 
# AND output packets are affected.
#
# To install, copy this file to /etc/firewall-modules/public/services/
# 000-blacklist-hosts (it needs to be the first module run to over-ride
# all other services) and execute rc.firewall with the --update-config
# parameter. The proper options will be added to the configuration file.
#
#-----------------------------------------------------------------------
# CHANGES
#-----------------------------------------------------------------------
#
# 2000-10-14  Jean-Sebastien Morisset <jsmoriss@jsm-mv.dyndns.org>
#             Initial module written for v5.0.
#
#-----------------------------------------------------------------------
# MODULE CONFIGURATION
#-----------------------------------------------------------------------
#
#N# blacklist
#A# ignore deny
#T# hosts
#   |--------------------------------------------------------------------|
#D# The ignore-{int}-blacklist-hosts option will deny these hosts access 
#D# to all your public services. Rejected packets are NOT LOGGED. The 
#D# deny-{int}-blacklist-hosts option performs the same function, except
#D# that denied packets ARE LOGGED.
#D#
#D# These variable can be used after detecting an attack on your firewall.
#D# Other options (deny-{int}-smtp-clients, deny-{int}-http-clients, etc.)
#D# restrict access to specific services. The ignore option has precedence
#D# over the deny option.
#D#
#D# Input AND output packets will be denied from/to these hosts/networks
#D# (including outgoing traceroute and ping).
#   |--------------------------------------------------------------------|
#
#-----------------------------------------------------------------------
# START OF MODULE CODE
#-----------------------------------------------------------------------


#--------------------------------------------------------------------
# Blacklisted Hosts
#--------------------------------------------------------------------
# These rules are "inserted" instead of "appended" to over-ride the 
# default DNS access.
#--------------------------------------------------------------------

# Ignore-deny order must be inversed since we're "inserting" rules.
for ACTION in DENY IGNORE
do
	case $ACTION in
		IGNORE)	ACTION_LOG_MSG="$LOG_MSG"; ACTION_LOG="$LOG";;
		DENY)	ACTION_LOG_MSG="(logged)"; ACTION_LOG="-l"  ;;
	esac
	for HOST in `Option_Value $ACTION $INTERFACE BLACKLIST HOSTS`
	do
		# Since these rules are "inserted", read them from last to first.
		#
		echo "Deny/Reject [BLACKLIST] $INTERFACE $ANY <-> $HOST $ACTION_LOG_MSG"
		ipchains -I $OUTCHAIN -j REJECT -p all -s $ANY  -d $HOST $ACTION_LOG
		ipchains -I $INCHAIN  -j DENY   -p all -s $HOST -d $ANY  $ACTION_LOG
	done
done

