#!/bin/bash # [Guarddog2] # DO NOT EDIT! # This firewall script was generated by "Guarddog" by Simon Edwards # http://www.simonzone.com/software/guarddog/ This script requires Linux # kernel version 2.2.x and ipchains OR Linux kernel 2.4.x and iptables. # # [Description] # # [Config] # LOCALPORTRANGESTART=1024 # LOCALPORTRANGEEND=59999 # DISABLED=0 # LOGREJECT=1 # LOGDROP=1 # LOGABORTEDTCP=1 # LOGIPOPTIONS=1 # LOGTCPOPTIONS=1 # LOGTCPSEQUENCE=1 # LOGLEVEL=4 # LOGRATELIMIT=1 # LOGRATE=1 # LOGRATEUNIT=0 # LOGRATEBURST=10 # LOGWARNLIMIT=1 # LOGWARNRATE=2 # LOGWARNRATEUNIT=1 # DHCPC=0 # DHCPCINTERFACENAME=eth0 # DHCPD=0 # DHCPDINTERFACENAME=eth0 # ALLOWTCPTIMESTAMPS=0 # [Zone] # NAME=vbox # COMMENT= # [ServerZone] Internet # [ClientZone] Local # CONNECTED=1 # PROTOCOL=svnserve # PROTOCOL=rsync # PROTOCOL=gnutella # PROTOCOL=ping # PROTOCOL=pop3 # PROTOCOL=vj-traceroute # PROTOCOL=domain # PROTOCOL=cvspserver # PROTOCOL=http # PROTOCOL=edonkey2000 # PROTOCOL=ftp # PROTOCOL=irc # PROTOCOL=nicname # PROTOCOL=pop3s # PROTOCOL=redirect # PROTOCOL=time # PROTOCOL=bt-peer # PROTOCOL=privoxy # PROTOCOL=msnmessenger # PROTOCOL=smtp # PROTOCOL=ymessenger # PROTOCOL=directconnect # PROTOCOL=netmeeting # PROTOCOL=ntp # PROTOCOL=https # PROTOCOL=fasttrack # PROTOCOL=smtps # PROTOCOL=jabber # PROTOCOL=icq # [ClientZone] vbox # CONNECTED=0 # [ServerZone] Local # [ClientZone] Internet # CONNECTED=1 # PROTOCOL=svnserve # PROTOCOL=pptp # PROTOCOL=rsync # PROTOCOL=gnutella # PROTOCOL=ping # PROTOCOL=pop3 # PROTOCOL=vj-traceroute # PROTOCOL=domain # PROTOCOL=cvspserver # PROTOCOL=http # PROTOCOL=edonkey2000 # PROTOCOL=ftp # PROTOCOL=irc # PROTOCOL=nicname # PROTOCOL=pop3s # PROTOCOL=redirect # PROTOCOL=bt-peer # PROTOCOL=time # PROTOCOL=privoxy # PROTOCOL=msnmessenger # PROTOCOL=smtp # PROTOCOL=directconnect # PROTOCOL=ymessenger # PROTOCOL=ssh # PROTOCOL=https # PROTOCOL=ntp # PROTOCOL=netmeeting # PROTOCOL=microsoft-ds # PROTOCOL=fasttrack # PROTOCOL=smtps # PROTOCOL=netbios # PROTOCOL=jabber # PROTOCOL=icq # [ClientZone] vbox # CONNECTED=0 # [ServerZone] vbox # [ClientZone] Internet # CONNECTED=0 # [ClientZone] Local # CONNECTED=0 # [End] # Real code starts here # If you change the line below then also change the # DISABLED line above. DISABLE_GUARDDOG=0 if test -z $GUARDDOG_VERBOSE; then GUARDDOG_VERBOSE=0 fi; if [ $DISABLE_GUARDDOG -eq 0 ]; then # Set the path PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin # Detect which filter command we should use. FILTERSYS=0 # 0 = unknown, 1 = ipchains, 2 = iptables # Check for ipchains. if [ -e /sbin/ipchains ]; then FILTERSYS=1 fi; if [ -e /usr/sbin/ipchains ]; then FILTERSYS=1 fi; if [ -e /usr/local/sbin/ipchains ]; then FILTERSYS=1 fi; # Check for iptables support. if [ -e /proc/sys/kernel/osrelease ]; then KERNEL_VERSION=`sed "s/^\([0-9][0-9]*\.[0-9][0-9]*\).*\$/\1/" < /proc/sys/kernel/osrelease` if [ $KERNEL_VERSION == "2.6" ]; then KERNEL_VERSION="2.4" fi; if [ $KERNEL_VERSION == "2.5" ]; then KERNEL_VERSION="2.4" fi; if [ $KERNEL_VERSION == "2.4" ]; then if [ -e /sbin/iptables ]; then FILTERSYS=2 fi; if [ -e /usr/sbin/iptables ]; then FILTERSYS=2 fi; if [ -e /usr/local/sbin/iptables ]; then FILTERSYS=2 fi; fi; fi; if [ $FILTERSYS -eq 0 ]; then logger -p auth.info -t guarddog "ERROR Can't determine the firewall command! (Is ipchains or iptables installed?)" [ $GUARDDOG_VERBOSE -eq 1 ] && echo "ERROR Can't determine the firewall command! (Is ipchains or iptables installed?)" false fi; if [ $FILTERSYS -eq 1 ]; then ############################### ###### ipchains ############### ############################### logger -p auth.info -t guarddog Configuring ipchains firewall now. [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Using ipchains." [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Resetting firewall rules." # Shut down all traffic ipchains -P forward DENY ipchains -P input DENY ipchains -P output DENY # Delete any existing chains ipchains -F ipchains -X [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Setting kernel parameters." # Turn on kernel IP spoof protection echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 2> /dev/null # Set the up TCP timestamps config echo 0 > /proc/sys/net/ipv4/tcp_timestamps 2> /dev/null # Enable TCP SYN Cookie Protection echo 1 > /proc/sys/net/ipv4/tcp_syncookies 2> /dev/null echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route 2> /dev/null # Log truly weird packets. echo 1 > /proc/sys/net/ipv4/conf/all/log_martians 2> /dev/null # Switch the current language for a moment GUARDDOG_BACKUP_LANG=$LANG GUARDDOG_BACKUP_LC_ALL=$LC_ALL LANG=US LC_ALL=US export LANG export LC_ALL # Set kernel rp_filter. NICs used for IPSEC should not have rp_fitler turned on. # Find the IPs of any ipsecX NICs IPSEC_IPS="`ifconfig | gawk '/^ipsec\w/ { grabip = 1} /inet addr:[[:digit:]\\.]+/ { if(grabip==1) printf \"%s \",gensub(/^.*inet addr:([[:digit:]\\.]+).*$/,\"\\\\1\",\"g\",$0) grabip = 0}'`" # Build a list of NIC names and metching IPs IP_NIC_PAIRS="`ifconfig | gawk '/^\w/ { nic = gensub(/^(.*):.*/,\"\\\\1\",\"g\",$1)} /inet addr:.*/ {match($0,/inet addr:[[:digit:]\.]+/) ip=substr($0,RSTART+10,RLENGTH-10) printf \"%s_%s\\n\",nic,ip }'`" # Restore the language setting LANG=$GUARDDOG_BACKUP_LANG LC_ALL=$GUARDDOG_BACKUP_LC_ALL export LANG export LC_ALL # Activate rp_filter for each NIC, except for NICs that are using # an IP that is involved with IPSEC. for X in $IP_NIC_PAIRS ; do NIC="`echo \"$X\" | cut -f 1 -d _`" IP="`echo \"$X\" | cut -f 2 -d _`" RPF="1" for SEC_IP in $IPSEC_IPS ; do if [[ $SEC_IP == $IP ]]; then RPF="0" fi done echo $RPF > /proc/sys/net/ipv4/conf/$NIC/rp_filter 2> /dev/null done echo "1024 59999" > /proc/sys/net/ipv4/ip_local_port_range 2> /dev/null [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Configuring firewall rules." # Allow loopback traffic. ipchains -A input -i lo -j ACCEPT ipchains -A output -i lo -j ACCEPT # Accept broadcasts from ourself. # Switch the current language for a moment GUARDDOG_BACKUP_LANG=$LANG GUARDDOG_BACKUP_LC_ALL=$LC_ALL LANG=US LC_ALL=US export LANG export LC_ALL IP_BCAST_PAIRS="`ifconfig | gawk '/^\w/ { nic = gensub(/^(.*):.*/,\"\\\\1\",\"g\",$1)} /inet addr:.*Bcast/ {match($0,/inet addr:[[:digit:]\\.]+/) ip=substr($0,RSTART+10,RLENGTH-10) match($0,/Bcast:[[:digit:]\\.]+/) bcast = substr($0,RSTART+6,RLENGTH-6) printf \"%s_%s_%s\\n\",nic,ip,bcast }'`" # Restore the language setting LANG=$GUARDDOG_BACKUP_LANG LC_ALL=$GUARDDOG_BACKUP_LC_ALL export LANG export LC_ALL for X in $IP_BCAST_PAIRS ; do NIC="`echo \"$X\" | cut -f 1 -d _`" IP="`echo \"$X\" | cut -f 2 -d _`" BCAST="`echo \"$X\" | cut -f 3 -d _`" ipchains -A input -i $NIC -s $IP -d $BCAST -j ACCEPT done # Allow certain critical ICMP types ipchains -A input -p icmp --sport 3 -j ACCEPT # Dest unreachable ipchains -A output -p icmp --sport 3 -j ACCEPT # Dest unreachable ipchains -A forward -p icmp --sport 3 -j ACCEPT &> /dev/null # Dest unreachable ipchains -A input -p icmp --sport 11 -j ACCEPT # Time exceeded ipchains -A output -p icmp --sport 11 -j ACCEPT # Time exceeded ipchains -A forward -p icmp --sport 11 -j ACCEPT &> /dev/null # Time exceeded ipchains -A input -p icmp --sport 12 -j ACCEPT # Parameter Problem ipchains -A output -p icmp --sport 12 -j ACCEPT # Parameter Problem ipchains -A forward -p icmp --sport 12 -j ACCEPT &> /dev/null # Parameter Problem # Work out our local IPs. # Switch the current language for a moment GUARDDOG_BACKUP_LANG=$LANG GUARDDOG_BACKUP_LC_ALL=$LC_ALL LANG=US LC_ALL=US export LANG export LC_ALL NIC_IP="`ifconfig | gawk '/^\w/ { nic = gensub(/^(.*):.*/,\"\\\\1\",\"g\",\$1)} /inet addr:/ { match(\$0,/inet addr:[[:digit:]\\.]+/) printf \"%s_%s\\n\",nic,substr(\$0,RSTART+10,RLENGTH-10) } /Bcast/ { match(\$0,/Bcast:[[:digit:]\\.]+/) printf \"%s_%s\\n\",nic,substr(\$0,RSTART+6,RLENGTH-6) }'`" # Restore the language setting LANG=$GUARDDOG_BACKUP_LANG LC_ALL=$GUARDDOG_BACKUP_LC_ALL export LANG export LC_ALL # Create the nicfilt chain ipchains -N nicfilt GOT_LO=0 NIC_COUNT=0 for X in $NIC_IP ; do NIC="`echo \"$X\" | cut -f 1 -d _`" IP="`echo \"$X\" | cut -f 2 -d _`" ipchains -A nicfilt -i $NIC -j RETURN # We also take this opportunity to see if we only have a lo interface. if [ $NIC == "lo" ]; then GOT_LO=1 fi let NIC_COUNT=$NIC_COUNT+1 done IPS="`echo \"$NIC_IP\" | cut -f 2 -d _`" # Do we have just a lo interface? if [ $GOT_LO -eq 1 ] && [ $NIC_COUNT -eq 1 ] ; then MIN_MODE=1 else MIN_MODE=0 fi # Are there *any* interfaces? if [ $NIC_COUNT -eq 0 ] ; then MIN_MODE=1 fi # If we only have a lo interface or no interfaces then we assume that DNS # is not going to work and just skip any iptables calls that need DNS. ipchains -A nicfilt -l -j DENY # Create the filter chains # Create chain to filter traffic going from 'Internet' to 'Local' ipchains -N f0to1 # Create chain to filter traffic going from 'Internet' to 'vbox' ipchains -N f0to2 # Create chain to filter traffic going from 'Local' to 'Internet' ipchains -N f1to0 # Create chain to filter traffic going from 'Local' to 'vbox' ipchains -N f1to2 # Create chain to filter traffic going from 'vbox' to 'Internet' ipchains -N f2to0 # Create chain to filter traffic going from 'vbox' to 'Local' ipchains -N f2to1 # Add rules to the filter chains # Traffic from 'Internet' to 'Local' # Allow 'svnserve' # Request connection. ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 3690:3690 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 3690:3690 --dport 1024:65535 -j ACCEPT # Allow 'pptp' # Control connection ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1723:1723 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1723:1723 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p 47 -j ACCEPT ipchains -A f1to0 -p 47 -j ACCEPT # Allow 'rsync' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 873:873 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 873:873 --dport 1024:65535 -j ACCEPT # Allow 'gnutella' ipchains -A f0to1 -p tcp --sport 0:65535 --dport 6346:6346 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 6346:6346 --dport 0:65535 -j ACCEPT # Allow 'ping' # Echo Request ipchains -A f0to1 -p icmp --sport 8 -j ACCEPT # Echo reply ipchains -A f1to0 -p icmp --sport 0 -j ACCEPT # Allow 'pop3' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 110:110 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 110:110 --dport 1024:65535 -j ACCEPT # Allow 'vj-traceroute' ipchains -A f0to1 -p udp --sport 0:65535 --dport 33434:33600 -j ACCEPT # Allow 'domain' ipchains -A f0to1 -p tcp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 53:53 --dport 0:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -A f1to0 -p udp --sport 53:53 --dport 0:65535 -j ACCEPT # Allow 'cvspserver' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 2401:2401 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 2401:2401 --dport 1024:65535 -j ACCEPT # Allow 'http' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 80:80 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 80:80 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 8080:8080 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 8080:8080 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 8008:8008 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 8008:8008 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 8000:8000 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 8000:8000 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 8888:8888 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 8888:8888 --dport 1024:65535 -j ACCEPT # Allow 'edonkey2000' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 4661:4661 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 4661:4661 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 4662:4662 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 4662:4662 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 4662:4662 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 4662:4662 --dport 1024:59999 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 4665:4665 -j ACCEPT ipchains -A f1to0 -p udp --sport 4665:4665 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 4666:4666 -j ACCEPT ipchains -A f1to0 -p udp --sport 4666:4666 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p udp --sport 1024:59999 --dport 4666:4666 -j ACCEPT ipchains -A f0to1 -p udp --sport 4666:4666 --dport 1024:59999 -j ACCEPT # Allow 'ftp' # Control connection ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 21:21 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 21:21 --dport 1024:65535 -j ACCEPT # Data connection ipchains -A f1to0 -p tcp --sport 20:20 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1024:65535 --dport 20:20 -j ACCEPT # Data connection passive mode ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT # Allow 'irc' # Server connection ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 6660:6669 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 6660:6669 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT # Allow 'nicname' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 43:43 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 43:43 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 0:65535 --dport 43:43 -j ACCEPT # Allow 'pop3s' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 995:995 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 995:995 --dport 1024:65535 -j ACCEPT # Allow 'redirect' ipchains -A f1to0 -p icmp --sport 5 -j ACCEPT # Allow 'bt-peer' # BitTorrent Peer ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 6881:6889 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 6881:6889 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 6881:6889 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 6881:6889 --dport 1024:59999 -j ACCEPT # Allow 'time' ipchains -A f0to1 -p udp --sport 1024:65535 --dport 37:37 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 37:37 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 37:37 --dport 1024:65535 -j ACCEPT # Allow 'privoxy' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 8118:8118 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 8118:8118 --dport 1024:65535 -j ACCEPT # Allow 'msnmessenger' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1863:1863 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1863:1863 --dport 1024:65535 -j ACCEPT # Allow 'smtp' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 25:25 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 25:25 --dport 1024:65535 -j ACCEPT # Allow 'directconnect' # This is used for connecting to hubs and other users ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 411:415 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 411:415 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1411:1415 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1411:1415 --dport 1024:65535 -j ACCEPT # This is used for connecting to hubs and other users ipchains -A f0to1 -p udp --sport 1024:65535 --dport 411:415 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 1411:1415 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f0to1 -p tcp --sport 1411:1415 --dport 0:65535 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 0:65535 --dport 1411:1415 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f0to1 -p udp --sport 1411:1415 --dport 0:65535 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f1to0 -p tcp --sport 0:65535 --dport 1411:1415 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1411:1415 --dport 0:65535 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f1to0 -p udp --sport 0:65535 --dport 1411:1415 -j ACCEPT # Allow 'ymessenger' # Login to network ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 5050:5050 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 5050:5050 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 23:23 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 23:23 --dport 1024:65535 -j ACCEPT # Conference ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 5000:5001 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 5000:5001 --dport 1024:65535 -j ACCEPT # Conference ipchains -A f0to1 -p udp --sport 1024:65535 --dport 5000:5000 -j ACCEPT # Allow 'ssh' # Normal connection ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 22:22 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 22:22 --dport 1024:65535 -j ACCEPT # privileged source port (rhosts compat.) ipchains -A f0to1 -p tcp --sport 0:1023 --dport 22:22 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 22:22 --dport 0:1023 -j ACCEPT # Allow 'https' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 443:443 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 443:443 --dport 1024:65535 -j ACCEPT # Allow 'ntp' ipchains -A f0to1 -p udp --sport 0:65535 --dport 123:123 -j ACCEPT ipchains -A f1to0 -p udp --sport 123:123 --dport 0:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 123:123 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 123:123 --dport 1024:65535 -j ACCEPT # Allow 'netmeeting' # Internet Locator Service (ILS) ipchains -A f0to1 -p tcp --sport 0:65535 --dport 389:389 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 389:389 --dport 0:65535 -j ACCEPT # User Location Service ipchains -A f0to1 -p tcp --sport 0:65535 --dport 522:522 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 522:522 --dport 0:65535 -j ACCEPT # T.120 ipchains -A f0to1 -p tcp --sport 0:65535 --dport 1503:1503 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1503:1503 --dport 0:65535 -j ACCEPT # H.323 call set-up ipchains -A f0to1 -p tcp --sport 0:65535 --dport 1720:1720 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1720:1720 --dport 0:65535 -j ACCEPT # Audio call control ipchains -A f0to1 -p tcp --sport 0:65535 --dport 1731:1731 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1731:1731 --dport 0:65535 -j ACCEPT # H.323 call control ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1024:59999 --dport 1024:65535 -j ACCEPT # H.323 streaming ipchains -A f0to1 -p udp --sport 1024:65535 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p udp --sport 1024:59999 --dport 1024:65535 -j ACCEPT # Allow 'microsoft-ds' # SMB over TCP ipchains -A f0to1 -p tcp --sport 0:65535 --dport 445:445 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 445:445 --dport 0:65535 -j ACCEPT # Allow 'fasttrack' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1214:1214 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1214:1214 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 1214:1214 -j ACCEPT # Allow 'smtps' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 465:465 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 465:465 --dport 1024:65535 -j ACCEPT # Allow 'netbios' # NETBIOS Name Service ipchains -A f0to1 -p tcp --sport 0:65535 --dport 137:137 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 137:137 --dport 0:65535 -j ACCEPT # NETBIOS Name Service ipchains -A f0to1 -p udp --sport 1024:65535 --dport 137:137 -j ACCEPT ipchains -A f1to0 -p udp --sport 137:137 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 137:137 --dport 137:137 -j ACCEPT ipchains -A f1to0 -p udp --sport 137:137 --dport 137:137 -j ACCEPT # NETBIOS Name Service, announcements, lookup replies. ipchains -A f1to0 -p udp --sport 137:137 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 137:137 -j ACCEPT ipchains -A f1to0 -p udp --sport 137:137 --dport 137:137 -j ACCEPT ipchains -A f0to1 -p udp --sport 137:137 --dport 137:137 -j ACCEPT # NETBIOS Datagram Service ipchains -A f0to1 -p udp --sport 1024:65535 --dport 138:138 -j ACCEPT ipchains -A f1to0 -p udp --sport 138:138 --dport 1024:65535 -j ACCEPT # NETBIOS Datagram Service (announcement) ipchains -A f1to0 -p udp --sport 138:138 --dport 138:138 -j ACCEPT ipchains -A f0to1 -p udp --sport 138:138 --dport 138:138 -j ACCEPT # NETBIOS Datagram Service (printer search) ipchains -A f0to1 -p udp --sport 138:138 --dport 138:138 -j ACCEPT ipchains -A f1to0 -p udp --sport 138:138 --dport 138:138 -j ACCEPT # NETBIOS Session Service ipchains -A f0to1 -p tcp --sport 0:65535 --dport 139:139 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 139:139 --dport 0:65535 -j ACCEPT # NETBIOS Session Service ipchains -A f0to1 -p udp --sport 1024:65535 --dport 139:139 -j ACCEPT # Allow 'jabber' ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 5222:5222 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 5222:5222 --dport 1024:65535 -j ACCEPT # Jabber over Secure Socket Layer ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 5223:5223 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 5223:5223 --dport 1024:65535 -j ACCEPT # Allow 'icq' ipchains -A f0to1 -p udp --sport 0:65535 --dport 5190:5190 -j ACCEPT ipchains -A f1to0 -p udp --sport 5190:5190 --dport 0:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:65535 --dport 3900:3999 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 3900:3999 --dport 1024:65535 -j ACCEPT # Rejected traffic from 'Internet' to 'Local' # Traffic from 'Internet' to 'vbox' # Rejected traffic from 'Internet' to 'vbox' # Traffic from 'Local' to 'Internet' # Allow 'svnserve' # Request connection. ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 3690:3690 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 3690:3690 --dport 1024:59999 -j ACCEPT # Allow 'rsync' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 873:873 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 873:873 --dport 1024:59999 -j ACCEPT # Allow 'gnutella' ipchains -A f1to0 -p tcp --sport 0:65535 --dport 6346:6346 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 6346:6346 --dport 0:65535 -j ACCEPT # Allow 'ping' # Echo Request ipchains -A f1to0 -p icmp --sport 8 -j ACCEPT # Echo reply ipchains -A f0to1 -p icmp --sport 0 -j ACCEPT # Allow 'pop3' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 110:110 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 110:110 --dport 1024:59999 -j ACCEPT # Allow 'vj-traceroute' ipchains -A f1to0 -p udp --sport 0:65535 --dport 33434:33600 -j ACCEPT # Allow 'domain' ipchains -A f1to0 -p tcp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 53:53 --dport 0:65535 -j ACCEPT ipchains -A f1to0 -p udp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -A f0to1 -p udp --sport 53:53 --dport 0:65535 -j ACCEPT # Allow 'cvspserver' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 2401:2401 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 2401:2401 --dport 1024:59999 -j ACCEPT # Allow 'http' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 80:80 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 80:80 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 8080:8080 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 8080:8080 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 8008:8008 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 8008:8008 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 8000:8000 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 8000:8000 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 8888:8888 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 8888:8888 --dport 1024:59999 -j ACCEPT # Allow 'edonkey2000' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 4661:4661 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 4661:4661 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 4662:4662 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 4662:4662 --dport 1024:59999 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 4662:4662 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 4662:4662 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p udp --sport 1024:59999 --dport 4665:4665 -j ACCEPT ipchains -A f0to1 -p udp --sport 4665:4665 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p udp --sport 1024:59999 --dport 4666:4666 -j ACCEPT ipchains -A f0to1 -p udp --sport 4666:4666 --dport 1024:59999 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 4666:4666 -j ACCEPT ipchains -A f1to0 -p udp --sport 4666:4666 --dport 1024:65535 -j ACCEPT # Allow 'ftp' # Control connection ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 21:21 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 21:21 --dport 1024:59999 -j ACCEPT # Data connection ipchains -A f0to1 -p tcp --sport 20:20 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1024:65535 --dport 20:20 -j ACCEPT # Data connection passive mode ipchains -A f1to0 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT # Allow 'irc' # Server connection ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 6660:6669 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 6660:6669 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT # Allow 'nicname' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 43:43 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 43:43 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p udp --sport 0:65535 --dport 43:43 -j ACCEPT # Allow 'pop3s' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 995:995 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 995:995 --dport 1024:59999 -j ACCEPT # Allow 'redirect' ipchains -A f0to1 -p icmp --sport 5 -j ACCEPT # Allow 'time' ipchains -A f1to0 -p udp --sport 1024:59999 --dport 37:37 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 37:37 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 37:37 --dport 1024:59999 -j ACCEPT # Allow 'bt-peer' # BitTorrent Peer ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 6881:6889 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 6881:6889 --dport 1024:59999 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 6881:6889 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 6881:6889 --dport 1024:65535 -j ACCEPT # Allow 'privoxy' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 8118:8118 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 8118:8118 --dport 1024:59999 -j ACCEPT # Allow 'msnmessenger' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 1863:1863 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1863:1863 --dport 1024:59999 -j ACCEPT # Allow 'smtp' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 25:25 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 25:25 --dport 1024:59999 -j ACCEPT # Allow 'ymessenger' # Login to network ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 5050:5050 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 5050:5050 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 23:23 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 23:23 --dport 1024:59999 -j ACCEPT # Conference ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 5000:5001 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 5000:5001 --dport 1024:59999 -j ACCEPT # Conference ipchains -A f1to0 -p udp --sport 1024:59999 --dport 5000:5000 -j ACCEPT # Allow 'directconnect' # This is used for connecting to hubs and other users ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 411:415 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 411:415 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 1411:1415 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1411:1415 --dport 1024:59999 -j ACCEPT # This is used for connecting to hubs and other users ipchains -A f1to0 -p udp --sport 1024:59999 --dport 411:415 -j ACCEPT ipchains -A f1to0 -p udp --sport 1024:59999 --dport 1411:1415 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f1to0 -p tcp --sport 1411:1415 --dport 0:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 0:65535 --dport 1411:1415 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f1to0 -p udp --sport 1411:1415 --dport 0:65535 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f0to1 -p tcp --sport 0:65535 --dport 1411:1415 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 1411:1415 --dport 0:65535 -j ACCEPT # DC Active mode - usable by an unprivileged user ipchains -A f0to1 -p udp --sport 0:65535 --dport 1411:1415 -j ACCEPT # Allow 'netmeeting' # Internet Locator Service (ILS) ipchains -A f1to0 -p tcp --sport 0:65535 --dport 389:389 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 389:389 --dport 0:65535 -j ACCEPT # User Location Service ipchains -A f1to0 -p tcp --sport 0:65535 --dport 522:522 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 522:522 --dport 0:65535 -j ACCEPT # T.120 ipchains -A f1to0 -p tcp --sport 0:65535 --dport 1503:1503 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1503:1503 --dport 0:65535 -j ACCEPT # H.323 call set-up ipchains -A f1to0 -p tcp --sport 0:65535 --dport 1720:1720 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1720:1720 --dport 0:65535 -j ACCEPT # Audio call control ipchains -A f1to0 -p tcp --sport 0:65535 --dport 1731:1731 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1731:1731 --dport 0:65535 -j ACCEPT # H.323 call control ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1024:65535 --dport 1024:59999 -j ACCEPT # H.323 streaming ipchains -A f1to0 -p udp --sport 1024:59999 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p udp --sport 1024:65535 --dport 1024:59999 -j ACCEPT # Allow 'ntp' ipchains -A f1to0 -p udp --sport 0:65535 --dport 123:123 -j ACCEPT ipchains -A f0to1 -p udp --sport 123:123 --dport 0:65535 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 123:123 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 123:123 --dport 1024:59999 -j ACCEPT # Allow 'https' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 443:443 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 443:443 --dport 1024:59999 -j ACCEPT # Allow 'fasttrack' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 1214:1214 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1214:1214 --dport 1024:59999 -j ACCEPT ipchains -A f1to0 -p udp --sport 1024:59999 --dport 1214:1214 -j ACCEPT # Allow 'smtps' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 465:465 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 465:465 --dport 1024:59999 -j ACCEPT # Allow 'jabber' ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 5222:5222 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 5222:5222 --dport 1024:59999 -j ACCEPT # Jabber over Secure Socket Layer ipchains -A f1to0 -p tcp --sport 1024:59999 --dport 5223:5223 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 5223:5223 --dport 1024:59999 -j ACCEPT # Allow 'icq' ipchains -A f1to0 -p udp --sport 0:65535 --dport 5190:5190 -j ACCEPT ipchains -A f0to1 -p udp --sport 5190:5190 --dport 0:65535 -j ACCEPT ipchains -A f1to0 -p tcp --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp ! -y --sport 1024:65535 --dport 1024:65535 -j ACCEPT ipchains -A f0to1 -p tcp --sport 1024:65535 --dport 3900:3999 -j ACCEPT ipchains -A f1to0 -p tcp ! -y --sport 3900:3999 --dport 1024:65535 -j ACCEPT # Rejected traffic from 'Local' to 'Internet' # Traffic from 'Local' to 'vbox' # Rejected traffic from 'Local' to 'vbox' # Traffic from 'vbox' to 'Internet' # Rejected traffic from 'vbox' to 'Internet' # Traffic from 'vbox' to 'Local' # Rejected traffic from 'vbox' to 'Local' # Place DENY and log rules at the end of our filter chains. # Failing all the rules above, we DENY and maybe log the packet. ipchains -A f0to1 -l -j DENY # Failing all the rules above, we DENY and maybe log the packet. ipchains -A f0to2 -l -j DENY # Failing all the rules above, we DENY and maybe log the packet. ipchains -A f1to0 -l -j DENY # Failing all the rules above, we DENY and maybe log the packet. ipchains -A f1to2 -l -j DENY # Failing all the rules above, we DENY and maybe log the packet. ipchains -A f2to0 -l -j DENY # Failing all the rules above, we DENY and maybe log the packet. ipchains -A f2to1 -l -j DENY # Add some temp DNS accept rules to the input and output chains. # This is so that we can pass domain names to ipchains and have ipchains be # able to look it up without being blocked by the our half-complete firewall. if [ $MIN_MODE -eq 0 ] ; then ipchains -A output -p tcp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -A input -p tcp ! -y --sport 53:53 --dport 0:65535 -j ACCEPT ipchains -A output -p udp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -A input -p udp --sport 53:53 --dport 0:65535 -j ACCEPT fi # Chain to split traffic coming from zone 'Internet' by dest zone ipchains -N s0 for X in $IPS ; do ipchains -A s0 -d $X -j f0to1 done if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has a least something in it. fi ipchains -A s0 -l -j DENY # Chain to split traffic coming from zone 'Local' by dest zone ipchains -N s1 if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has a least something in it. fi ipchains -A s1 -j f1to0 # Chain to split traffic coming from zone 'vbox' by dest zone ipchains -N s2 for X in $IPS ; do ipchains -A s2 -d $X -j f2to1 done if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has a least something in it. fi ipchains -A s2 -j f2to0 # Create the srcfilt chain ipchains -N srcfilt if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has a least something in it. fi # Assume internet default rule ipchains -A srcfilt -j s0 # Remove the temp DNS accept rules if [ $MIN_MODE -eq 0 ] ; then ipchains -D output -p tcp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -D input -p tcp ! -y --sport 53:53 --dport 0:65535 -j ACCEPT ipchains -D output -p udp --sport 0:65535 --dport 53:53 -j ACCEPT ipchains -D input -p udp --sport 53:53 --dport 0:65535 -j ACCEPT fi # The output chain is quite simple. We diverge and filter any traffic from # the local machine and accept the rest. The rest should have come via the # forward chain, and hence is already filtered. ipchains -A output -j nicfilt for X in $IPS ; do ipchains -A output -s $X -j s1 done ipchains -A output -j ACCEPT ipchains -A input -j nicfilt # Direct local bound traffic on the input chain to the srcfilt chain for X in $IPS ; do ipchains -A input -d $X -j srcfilt done ipchains -A input -j ACCEPT # All traffic on the forward chains goes to the srcfilt chain. ipchains -A forward -j nicfilt &> /dev/null ipchains -A forward -j srcfilt &> /dev/null logger -p auth.info -t guarddog Finished configuring firewall [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Finished." fi; if [ $FILTERSYS -eq 2 ]; then ############################### ###### iptables firewall ###### ############################### logger -p auth.info -t guarddog Configuring iptables firewall now. [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Using iptables." [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Resetting firewall rules." # Shut down all traffic iptables -P FORWARD DROP iptables -P INPUT DROP iptables -P OUTPUT DROP # Delete any existing chains iptables -F iptables -X # Load any special kernel modules. [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Loading kernel modules." modprobe ip_conntrack_ftp modprobe ip_conntrack_irc [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Setting kernel parameters." # Turn on kernel IP spoof protection echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 2> /dev/null # Set the TCP timestamps config echo 0 > /proc/sys/net/ipv4/tcp_timestamps 2> /dev/null # Enable TCP SYN Cookie Protection if available test -e /proc/sys/net/ipv4/tcp_syncookies && echo 1 > /proc/sys/net/ipv4/tcp_syncookies 2> /dev/null echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route 2> /dev/null echo 0 > /proc/sys/net/ipv4/conf/default/accept_source_route 2> /dev/null # Log truly weird packets. echo 1 > /proc/sys/net/ipv4/conf/all/log_martians 2> /dev/null echo 1 > /proc/sys/net/ipv4/conf/default/log_martians 2> /dev/null # Switch the current language for a moment GUARDDOG_BACKUP_LANG=$LANG GUARDDOG_BACKUP_LC_ALL=$LC_ALL LANG=US LC_ALL=US export LANG export LC_ALL # Set kernel rp_filter. NICs used for IPSEC should not have rp_fitler turned on. # Find the IPs of any ipsecX NICs IPSEC_IPS="`ifconfig | gawk '/^ipsec\w/ { grabip = 1} /inet addr:[[:digit:]\\.]+/ { if(grabip==1) printf \"%s \",gensub(/^.*inet addr:([[:digit:]\\.]+).*$/,\"\\\\1\",\"g\",$0) grabip = 0}'`" # Build a list of NIC names and metching IPs IP_NIC_PAIRS="`ifconfig | gawk '/^\w/ { nic = gensub(/^(.*):.*/,\"\\\\1\",\"g\",$1)} /inet addr:.*/ {match($0,/inet addr:[[:digit:]\.]+/) ip=substr($0,RSTART+10,RLENGTH-10) printf \"%s_%s\\n\",nic,ip }'`" # Restore the language setting LANG=$GUARDDOG_BACKUP_LANG LC_ALL=$GUARDDOG_BACKUP_LC_ALL export LANG export LC_ALL # Activate rp_filter for each NIC, except for NICs that are using # an IP that is involved with IPSEC. for X in $IP_NIC_PAIRS ; do NIC="`echo \"$X\" | cut -f 1 -d _`" IP="`echo \"$X\" | cut -f 2 -d _`" RPF="1" for SEC_IP in $IPSEC_IPS ; do if [[ $SEC_IP == $IP ]]; then RPF="0" fi done echo $RPF > /proc/sys/net/ipv4/conf/$NIC/rp_filter 2> /dev/null done echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter 2> /dev/null echo "1024 59999" > /proc/sys/net/ipv4/ip_local_port_range 2> /dev/null [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Configuring firewall rules." # Set up our logging and packet 'executing' chains iptables -N logdrop2 iptables -A logdrop2 -j LOG --log-prefix "DROPPED " --log-level 4 --log-ip-options --log-tcp-options --log-tcp-sequence iptables -A logdrop2 -j DROP iptables -N logdrop iptables -A logdrop -m limit --limit 1/second --limit-burst 10 -j logdrop2 iptables -A logdrop -m limit --limit 2/minute --limit-burst 1 -j LOG --log-prefix "LIMITED " --log-level 4 iptables -A logdrop -j DROP iptables -N logreject2 iptables -A logreject2 -j LOG --log-prefix "REJECTED " --log-level 4 --log-ip-options --log-tcp-options --log-tcp-sequence iptables -A logreject2 -p tcp -j REJECT --reject-with tcp-reset iptables -A logreject2 -p udp -j REJECT --reject-with icmp-port-unreachable iptables -A logreject2 -j DROP iptables -N logreject iptables -A logreject -m limit --limit 1/second --limit-burst 10 -j logreject2 iptables -A logreject -m limit --limit 2/minute --limit-burst 1 -j LOG --log-prefix "LIMITED " --log-level 4 iptables -A logreject -p tcp -j REJECT --reject-with tcp-reset iptables -A logreject -p udp -j REJECT --reject-with icmp-port-unreachable iptables -A logreject -j DROP iptables -N logaborted2 iptables -A logaborted2 -j LOG --log-prefix "ABORTED " --log-level 4 --log-ip-options --log-tcp-options --log-tcp-sequence iptables -A logaborted2 -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -N logaborted iptables -A logaborted -m limit --limit 1/second --limit-burst 10 -j logaborted2 iptables -A logaborted -m limit --limit 2/minute --limit-burst 1 -j LOG --log-prefix "LIMITED " --log-level 4 # Allow loopback traffic. iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # Switch the current language for a moment GUARDDOG_BACKUP_LANG=$LANG GUARDDOG_BACKUP_LC_ALL=$LC_ALL LANG=US LC_ALL=US export LANG export LC_ALL # Accept broadcasts from ourself. IP_BCAST_PAIRS="`ifconfig | gawk '/^\w/ { nic = gensub(/^(.*):.*/,\"\\\\1\",\"g\",$1)} /inet addr:.*Bcast/ {match($0,/inet addr:[[:digit:]\\.]+/) ip=substr($0,RSTART+10,RLENGTH-10) match($0,/Bcast:[[:digit:]\\.]+/) bcast = substr($0,RSTART+6,RLENGTH-6) printf \"%s_%s_%s\\n\",nic,ip,bcast }'`" # Restore the language setting LANG=$GUARDDOG_BACKUP_LANG LC_ALL=$GUARDDOG_BACKUP_LC_ALL export LANG export LC_ALL for X in $IP_BCAST_PAIRS ; do NIC="`echo \"$X\" | cut -f 1 -d _`" IP="`echo \"$X\" | cut -f 2 -d _`" BCAST="`echo \"$X\" | cut -f 3 -d _`" iptables -A INPUT -i $NIC -s $IP -d $BCAST -j ACCEPT done # Detect aborted TCP connections. iptables -A INPUT -m state --state ESTABLISHED,RELATED -p tcp --tcp-flags RST RST -j logaborted # Quickly allow anything that belongs to an already established connection. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow certain critical ICMP types iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT # Dest unreachable iptables -A OUTPUT -p icmp --icmp-type destination-unreachable -j ACCEPT # Dest unreachable iptables -A FORWARD -p icmp --icmp-type destination-unreachable -j ACCEPT &> /dev/null # Dest unreachable iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT # Time exceeded iptables -A OUTPUT -p icmp --icmp-type time-exceeded -j ACCEPT # Time exceeded iptables -A FORWARD -p icmp --icmp-type time-exceeded -j ACCEPT &> /dev/null # Time exceeded iptables -A INPUT -p icmp --icmp-type parameter-problem -j ACCEPT # Parameter Problem iptables -A OUTPUT -p icmp --icmp-type parameter-problem -j ACCEPT # Parameter Problem iptables -A FORWARD -p icmp --icmp-type parameter-problem -j ACCEPT &> /dev/null # Parameter Problem # Switch the current language for a moment GUARDDOG_BACKUP_LANG=$LANG GUARDDOG_BACKUP_LC_ALL=$LC_ALL LANG=US LC_ALL=US export LANG export LC_ALL # Work out our local IPs. NIC_IP="`ifconfig | gawk '/^\w/ { nic = gensub(/^(.*):.*/,\"\\\\1\",\"g\",\$1)} /inet addr:/ { match(\$0,/inet addr:[[:digit:]\\.]+/) printf \"%s_%s\\n\",nic,substr(\$0,RSTART+10,RLENGTH-10) } /Bcast/ { match(\$0,/Bcast:[[:digit:]\\.]+/) printf \"%s_%s\\n\",nic,substr(\$0,RSTART+6,RLENGTH-6) }'`" # Restore the language setting LANG=$GUARDDOG_BACKUP_LANG LC_ALL=$GUARDDOG_BACKUP_LC_ALL export LANG export LC_ALL # Create the nicfilt chain iptables -N nicfilt GOT_LO=0 NIC_COUNT=0 for X in $NIC_IP ; do NIC="`echo \"$X\" | cut -f 1 -d _`" iptables -A nicfilt -i $NIC -j RETURN # We also take this opportunity to see if we only have a lo interface. if [ $NIC == "lo" ]; then GOT_LO=1 fi let NIC_COUNT=$NIC_COUNT+1 done IPS="`echo \"$NIC_IP\" | cut -f 2 -d _`" iptables -A nicfilt -j logdrop # Do we have just a lo interface? if [ $GOT_LO -eq 1 ] && [ $NIC_COUNT -eq 1 ] ; then MIN_MODE=1 else MIN_MODE=0 fi # Are there *any* interfaces? if [ $NIC_COUNT -eq 0 ] ; then MIN_MODE=1 fi # If we only have a lo interface or no interfaces then we assume that DNS # is not going to work and just skip any iptables calls that need DNS. # Create the filter chains # Create chain to filter traffic going from 'Internet' to 'Local' iptables -N f0to1 # Create chain to filter traffic going from 'Internet' to 'vbox' iptables -N f0to2 # Create chain to filter traffic going from 'Local' to 'Internet' iptables -N f1to0 # Create chain to filter traffic going from 'Local' to 'vbox' iptables -N f1to2 # Create chain to filter traffic going from 'vbox' to 'Internet' iptables -N f2to0 # Create chain to filter traffic going from 'vbox' to 'Local' iptables -N f2to1 # Add rules to the filter chains # Traffic from 'Internet' to 'Local' # Allow 'svnserve' # Request connection. iptables -A f0to1 -p tcp --sport 1024:65535 --dport 3690:3690 -m state --state NEW -j ACCEPT # Allow 'pptp' # Control connection iptables -A f0to1 -p tcp --sport 1024:65535 --dport 1723:1723 -m state --state NEW -j ACCEPT iptables -A f0to1 -p 47 -j ACCEPT # Allow 'rsync' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 873:873 -m state --state NEW -j ACCEPT # Allow 'gnutella' iptables -A f0to1 -p tcp --sport 0:65535 --dport 6346:6346 -m state --state NEW -j ACCEPT # Allow 'ping' # Echo Request iptables -A f0to1 -p icmp --icmp-type echo-request -j ACCEPT # Echo reply iptables -A f1to0 -p icmp --icmp-type echo-reply -j ACCEPT # Allow 'pop3' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 110:110 -m state --state NEW -j ACCEPT # Allow 'vj-traceroute' iptables -A f0to1 -p udp --sport 0:65535 --dport 33434:33600 -j ACCEPT # Allow 'domain' iptables -A f0to1 -p tcp --sport 0:65535 --dport 53:53 -m state --state NEW -j ACCEPT iptables -A f0to1 -p udp --sport 0:65535 --dport 53:53 -j ACCEPT # Allow 'cvspserver' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 2401:2401 -m state --state NEW -j ACCEPT # Allow 'http' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 80:80 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 8080:8080 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 8008:8008 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 8000:8000 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 8888:8888 -m state --state NEW -j ACCEPT # Allow 'edonkey2000' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 4661:4661 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 4662:4662 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 4662:4662 -m state --state NEW -j ACCEPT iptables -A f0to1 -p udp --sport 1024:65535 --dport 4665:4665 -j ACCEPT iptables -A f0to1 -p udp --sport 1024:65535 --dport 4666:4666 -j ACCEPT iptables -A f1to0 -p udp --sport 1024:59999 --dport 4666:4666 -j ACCEPT # Allow 'ftp' # Control connection iptables -A f0to1 -p tcp --sport 1024:65535 --dport 21:21 -m state --state NEW -j ACCEPT # Data connection # - Handled by netfilter state tracking # Data connection passive mode # - Handled by netfilter state tracking # Allow 'irc' # Server connection iptables -A f0to1 -p tcp --sport 1024:65535 --dport 6660:6669 -m state --state NEW -j ACCEPT # - Handled by netfilter state tracking # Allow 'nicname' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 43:43 -m state --state NEW -j ACCEPT iptables -A f0to1 -p udp --sport 0:65535 --dport 43:43 -j ACCEPT # Allow 'pop3s' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 995:995 -m state --state NEW -j ACCEPT # Allow 'redirect' iptables -A f1to0 -p icmp --icmp-type redirect -j ACCEPT # Allow 'bt-peer' # BitTorrent Peer iptables -A f0to1 -p tcp --sport 1024:65535 --dport 6881:6889 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 6881:6889 -m state --state NEW -j ACCEPT # Allow 'time' iptables -A f0to1 -p udp --sport 1024:65535 --dport 37:37 -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 37:37 -m state --state NEW -j ACCEPT # Allow 'privoxy' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 8118:8118 -m state --state NEW -j ACCEPT # Allow 'msnmessenger' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 1863:1863 -m state --state NEW -j ACCEPT # Allow 'smtp' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 25:25 -m state --state NEW -j ACCEPT # Allow 'directconnect' # This is used for connecting to hubs and other users iptables -A f0to1 -p tcp --sport 1024:65535 --dport 411:415 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 1411:1415 -m state --state NEW -j ACCEPT # This is used for connecting to hubs and other users iptables -A f0to1 -p udp --sport 1024:65535 --dport 411:415 -j ACCEPT iptables -A f0to1 -p udp --sport 1024:65535 --dport 1411:1415 -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f0to1 -p tcp --sport 1411:1415 --dport 0:65535 -m state --state NEW -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f0to1 -p udp --sport 1411:1415 --dport 0:65535 -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f1to0 -p tcp --sport 0:65535 --dport 1411:1415 -m state --state NEW -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f1to0 -p udp --sport 0:65535 --dport 1411:1415 -j ACCEPT # Allow 'ymessenger' # Login to network iptables -A f0to1 -p tcp --sport 1024:65535 --dport 5050:5050 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 23:23 -m state --state NEW -j ACCEPT # Conference iptables -A f0to1 -p tcp --sport 1024:65535 --dport 5000:5001 -m state --state NEW -j ACCEPT # Conference iptables -A f0to1 -p udp --sport 1024:65535 --dport 5000:5000 -j ACCEPT # Allow 'ssh' # Normal connection iptables -A f0to1 -p tcp --sport 1024:65535 --dport 22:22 -m state --state NEW -j ACCEPT # privileged source port (rhosts compat.) iptables -A f0to1 -p tcp --sport 0:1023 --dport 22:22 -m state --state NEW -j ACCEPT # Allow 'https' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 443:443 -m state --state NEW -j ACCEPT # Allow 'ntp' iptables -A f0to1 -p udp --sport 0:65535 --dport 123:123 -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 123:123 -m state --state NEW -j ACCEPT # Allow 'netmeeting' # Internet Locator Service (ILS) iptables -A f0to1 -p tcp --sport 0:65535 --dport 389:389 -m state --state NEW -j ACCEPT # User Location Service iptables -A f0to1 -p tcp --sport 0:65535 --dport 522:522 -m state --state NEW -j ACCEPT # T.120 iptables -A f0to1 -p tcp --sport 0:65535 --dport 1503:1503 -m state --state NEW -j ACCEPT # H.323 call set-up iptables -A f0to1 -p tcp --sport 0:65535 --dport 1720:1720 -m state --state NEW -j ACCEPT # Audio call control iptables -A f0to1 -p tcp --sport 0:65535 --dport 1731:1731 -m state --state NEW -j ACCEPT # H.323 call control iptables -A f0to1 -p tcp --sport 1024:65535 --dport 1024:59999 -m state --state NEW -j ACCEPT # H.323 streaming iptables -A f0to1 -p udp --sport 1024:65535 --dport 1024:59999 -j ACCEPT # Allow 'microsoft-ds' # SMB over TCP iptables -A f0to1 -p tcp --sport 0:65535 --dport 445:445 -m state --state NEW -j ACCEPT # Allow 'fasttrack' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 1214:1214 -m state --state NEW -j ACCEPT iptables -A f0to1 -p udp --sport 1024:65535 --dport 1214:1214 -j ACCEPT # Allow 'smtps' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 465:465 -m state --state NEW -j ACCEPT # Allow 'netbios' # NETBIOS Name Service iptables -A f0to1 -p tcp --sport 0:65535 --dport 137:137 -m state --state NEW -j ACCEPT # NETBIOS Name Service iptables -A f0to1 -p udp --sport 1024:65535 --dport 137:137 -j ACCEPT iptables -A f0to1 -p udp --sport 137:137 --dport 137:137 -j ACCEPT # NETBIOS Name Service, announcements, lookup replies. iptables -A f1to0 -p udp --sport 137:137 --dport 1024:65535 -j ACCEPT iptables -A f1to0 -p udp --sport 137:137 --dport 137:137 -j ACCEPT # NETBIOS Datagram Service iptables -A f0to1 -p udp --sport 1024:65535 --dport 138:138 -j ACCEPT # NETBIOS Datagram Service (announcement) iptables -A f1to0 -p udp --sport 138:138 --dport 138:138 -j ACCEPT # NETBIOS Datagram Service (printer search) iptables -A f0to1 -p udp --sport 138:138 --dport 138:138 -j ACCEPT # NETBIOS Session Service iptables -A f0to1 -p tcp --sport 0:65535 --dport 139:139 -m state --state NEW -j ACCEPT # NETBIOS Session Service iptables -A f0to1 -p udp --sport 1024:65535 --dport 139:139 -j ACCEPT # Allow 'jabber' iptables -A f0to1 -p tcp --sport 1024:65535 --dport 5222:5222 -m state --state NEW -j ACCEPT # Jabber over Secure Socket Layer iptables -A f0to1 -p tcp --sport 1024:65535 --dport 5223:5223 -m state --state NEW -j ACCEPT # Allow 'icq' iptables -A f0to1 -p udp --sport 0:65535 --dport 5190:5190 -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:65535 --dport 3900:3999 -m state --state NEW -j ACCEPT # Rejected traffic from 'Internet' to 'Local' # Traffic from 'Internet' to 'vbox' # Rejected traffic from 'Internet' to 'vbox' # Traffic from 'Local' to 'Internet' # Allow 'svnserve' # Request connection. iptables -A f1to0 -p tcp --sport 1024:59999 --dport 3690:3690 -m state --state NEW -j ACCEPT # Allow 'rsync' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 873:873 -m state --state NEW -j ACCEPT # Allow 'gnutella' iptables -A f1to0 -p tcp --sport 0:65535 --dport 6346:6346 -m state --state NEW -j ACCEPT # Allow 'ping' # Echo Request iptables -A f1to0 -p icmp --icmp-type echo-request -j ACCEPT # Echo reply iptables -A f0to1 -p icmp --icmp-type echo-reply -j ACCEPT # Allow 'pop3' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 110:110 -m state --state NEW -j ACCEPT # Allow 'vj-traceroute' iptables -A f1to0 -p udp --sport 0:65535 --dport 33434:33600 -j ACCEPT # Allow 'domain' iptables -A f1to0 -p tcp --sport 0:65535 --dport 53:53 -m state --state NEW -j ACCEPT iptables -A f1to0 -p udp --sport 0:65535 --dport 53:53 -j ACCEPT # Allow 'cvspserver' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 2401:2401 -m state --state NEW -j ACCEPT # Allow 'http' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 80:80 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 8080:8080 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 8008:8008 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 8000:8000 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 8888:8888 -m state --state NEW -j ACCEPT # Allow 'edonkey2000' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 4661:4661 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 4662:4662 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 4662:4662 -m state --state NEW -j ACCEPT iptables -A f1to0 -p udp --sport 1024:59999 --dport 4665:4665 -j ACCEPT iptables -A f1to0 -p udp --sport 1024:59999 --dport 4666:4666 -j ACCEPT iptables -A f0to1 -p udp --sport 1024:65535 --dport 4666:4666 -j ACCEPT # Allow 'ftp' # Control connection iptables -A f1to0 -p tcp --sport 1024:59999 --dport 21:21 -m state --state NEW -j ACCEPT # Data connection # - Handled by netfilter state tracking # Data connection passive mode # - Handled by netfilter state tracking # Allow 'irc' # Server connection iptables -A f1to0 -p tcp --sport 1024:59999 --dport 6660:6669 -m state --state NEW -j ACCEPT # - Handled by netfilter state tracking # Allow 'nicname' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 43:43 -m state --state NEW -j ACCEPT iptables -A f1to0 -p udp --sport 0:65535 --dport 43:43 -j ACCEPT # Allow 'pop3s' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 995:995 -m state --state NEW -j ACCEPT # Allow 'redirect' iptables -A f0to1 -p icmp --icmp-type redirect -j ACCEPT # Allow 'time' iptables -A f1to0 -p udp --sport 1024:59999 --dport 37:37 -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 37:37 -m state --state NEW -j ACCEPT # Allow 'bt-peer' # BitTorrent Peer iptables -A f1to0 -p tcp --sport 1024:59999 --dport 6881:6889 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 6881:6889 -m state --state NEW -j ACCEPT # Allow 'privoxy' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 8118:8118 -m state --state NEW -j ACCEPT # Allow 'msnmessenger' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 1863:1863 -m state --state NEW -j ACCEPT # Allow 'smtp' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 25:25 -m state --state NEW -j ACCEPT # Allow 'ymessenger' # Login to network iptables -A f1to0 -p tcp --sport 1024:59999 --dport 5050:5050 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 23:23 -m state --state NEW -j ACCEPT # Conference iptables -A f1to0 -p tcp --sport 1024:59999 --dport 5000:5001 -m state --state NEW -j ACCEPT # Conference iptables -A f1to0 -p udp --sport 1024:59999 --dport 5000:5000 -j ACCEPT # Allow 'directconnect' # This is used for connecting to hubs and other users iptables -A f1to0 -p tcp --sport 1024:59999 --dport 411:415 -m state --state NEW -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 1411:1415 -m state --state NEW -j ACCEPT # This is used for connecting to hubs and other users iptables -A f1to0 -p udp --sport 1024:59999 --dport 411:415 -j ACCEPT iptables -A f1to0 -p udp --sport 1024:59999 --dport 1411:1415 -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f1to0 -p tcp --sport 1411:1415 --dport 0:65535 -m state --state NEW -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f1to0 -p udp --sport 1411:1415 --dport 0:65535 -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f0to1 -p tcp --sport 0:65535 --dport 1411:1415 -m state --state NEW -j ACCEPT # DC Active mode - usable by an unprivileged user iptables -A f0to1 -p udp --sport 0:65535 --dport 1411:1415 -j ACCEPT # Allow 'netmeeting' # Internet Locator Service (ILS) iptables -A f1to0 -p tcp --sport 0:65535 --dport 389:389 -m state --state NEW -j ACCEPT # User Location Service iptables -A f1to0 -p tcp --sport 0:65535 --dport 522:522 -m state --state NEW -j ACCEPT # T.120 iptables -A f1to0 -p tcp --sport 0:65535 --dport 1503:1503 -m state --state NEW -j ACCEPT # H.323 call set-up iptables -A f1to0 -p tcp --sport 0:65535 --dport 1720:1720 -m state --state NEW -j ACCEPT # Audio call control iptables -A f1to0 -p tcp --sport 0:65535 --dport 1731:1731 -m state --state NEW -j ACCEPT # H.323 call control iptables -A f1to0 -p tcp --sport 1024:59999 --dport 1024:65535 -m state --state NEW -j ACCEPT # H.323 streaming iptables -A f1to0 -p udp --sport 1024:59999 --dport 1024:65535 -j ACCEPT # Allow 'ntp' iptables -A f1to0 -p udp --sport 0:65535 --dport 123:123 -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:59999 --dport 123:123 -m state --state NEW -j ACCEPT # Allow 'https' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 443:443 -m state --state NEW -j ACCEPT # Allow 'fasttrack' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 1214:1214 -m state --state NEW -j ACCEPT iptables -A f1to0 -p udp --sport 1024:59999 --dport 1214:1214 -j ACCEPT # Allow 'smtps' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 465:465 -m state --state NEW -j ACCEPT # Allow 'jabber' iptables -A f1to0 -p tcp --sport 1024:59999 --dport 5222:5222 -m state --state NEW -j ACCEPT # Jabber over Secure Socket Layer iptables -A f1to0 -p tcp --sport 1024:59999 --dport 5223:5223 -m state --state NEW -j ACCEPT # Allow 'icq' iptables -A f1to0 -p udp --sport 0:65535 --dport 5190:5190 -j ACCEPT iptables -A f1to0 -p tcp --sport 1024:65535 --dport 1024:65535 -m state --state NEW -j ACCEPT iptables -A f0to1 -p tcp --sport 1024:65535 --dport 3900:3999 -m state --state NEW -j ACCEPT # Rejected traffic from 'Local' to 'Internet' # Traffic from 'Local' to 'vbox' # Rejected traffic from 'Local' to 'vbox' # Traffic from 'vbox' to 'Internet' # Rejected traffic from 'vbox' to 'Internet' # Traffic from 'vbox' to 'Local' # Rejected traffic from 'vbox' to 'Local' # Place DROP and log rules at the end of our filter chains. # Failing all the rules above, we log and DROP the packet. iptables -A f0to1 -j logdrop # Failing all the rules above, we log and DROP the packet. iptables -A f0to2 -j logdrop # Failing all the rules above, we log and DROP the packet. iptables -A f1to0 -j logdrop # Failing all the rules above, we log and DROP the packet. iptables -A f1to2 -j logdrop # Failing all the rules above, we log and DROP the packet. iptables -A f2to0 -j logdrop # Failing all the rules above, we log and DROP the packet. iptables -A f2to1 -j logdrop # Add some temp DNS accept rules to the input and output chains. # This is so that we can pass domain names to ipchains and have iptables be # able to look it up without being blocked by the our half-complete firewall. if [ $MIN_MODE -eq 0 ] ; then iptables -A OUTPUT -p tcp --sport 0:65535 --dport 53:53 -j ACCEPT iptables -A INPUT -p tcp ! --syn --sport 53:53 --dport 0:65535 -j ACCEPT iptables -A OUTPUT -p udp --sport 0:65535 --dport 53:53 -j ACCEPT iptables -A INPUT -p udp --sport 53:53 --dport 0:65535 -j ACCEPT fi # Chain to split traffic coming from zone 'Internet' by dest zone iptables -N s0 for X in $IPS ; do iptables -A s0 -d $X -j f0to1 done if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has at least something in it. fi iptables -A s0 -j logdrop # Chain to split traffic coming from zone 'Local' by dest zone iptables -N s1 if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has at least something in it. fi iptables -A s1 -j f1to0 # Chain to split traffic coming from zone 'vbox' by dest zone iptables -N s2 for X in $IPS ; do iptables -A s2 -d $X -j f2to1 done if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has at least something in it. fi iptables -A s2 -j f2to0 # Create the srcfilt chain iptables -N srcfilt if [ $MIN_MODE -eq 0 ] ; then true # make sure this if [] has at least something in it. fi # Assume internet default rule iptables -A srcfilt -j s0 if [ $MIN_MODE -eq 0 ] ; then # Remove the temp DNS accept rules iptables -D OUTPUT -p tcp --sport 0:65535 --dport 53:53 -j ACCEPT iptables -D INPUT -p tcp ! --syn --sport 53:53 --dport 0:65535 -j ACCEPT iptables -D OUTPUT -p udp --sport 0:65535 --dport 53:53 -j ACCEPT iptables -D INPUT -p udp --sport 53:53 --dport 0:65535 -j ACCEPT fi # The output chain is very simple. We direct everything to the # 'source is local' split chain. iptables -A OUTPUT -j s1 iptables -A INPUT -j nicfilt iptables -A INPUT -j srcfilt # All traffic on the forward chains goes to the srcfilt chain. iptables -A FORWARD -j srcfilt &> /dev/null logger -p auth.info -t guarddog Finished configuring firewall [ $GUARDDOG_VERBOSE -eq 1 ] && echo "Finished." fi; fi; true