Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, March 29, 2024

Diff for scripts/shell/firewall/fw-universal.sh between version 2.3 and 2.13

version 2.3, 2004/12/30 23:16:20 version 2.13, 2005/01/16 11:06:10
Line 5 
Line 5 
 # Can be started by init or by hand.  # Can be started by init or by hand.
 #  #
 # Developed by Lubomir Host 'rajo' <rajo AT platon.sk>  # Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
 # Copyright (c) 2003-2004 Platon SDG, http://platon.sk/  # Copyright (c) 2003-2005 Platon SDG, http://platon.sk/
 # Licensed under terms of GNU General Public License.  # Licensed under terms of GNU General Public License.
 # All rights reserved.  # All rights reserved.
 #  #
 # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.2 2004/12/12 18:00:11 rajo Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.12 2005/01/16 10:55:39 rajo Exp $
 #  #
 # Changelog:  # Changelog:
 # 2004-11-14 - created  # 2003-10-24 - created
 #  #
   
 DESC="firewall"  DESC="firewall"
Line 33  DEFAULT_POLICY="${DEFAULT_POLICY:=DROP}"
Line 33  DEFAULT_POLICY="${DEFAULT_POLICY:=DROP}"
 # which modules to load  # which modules to load
 MODULES="${MODULES:=}"  MODULES="${MODULES:=}"
   
 LOG_LIMIT="${LOG_LIMIT:=-m limit --limit 12/h --limit-burst 10}"  LOG_LIMIT="${LOG_LIMIT:=-m limit --limit 12/h --limit-burst 10 -j LOG --log-level notice --log-prefix}"
   
 # Paths:  # Paths:
 #IPTABLES=":" # for testing only - does nothing  #IPTABLES=":" # for testing only - does nothing
 IPTABLES="${IPTABLES:=/sbin/iptables}"  IPTABLES="${IPTABLES:=$DEBUG/sbin/iptables}"
 IFCONFIG="${IFCONFIG:=/sbin/ifconfig}"  IFCONFIG="${IFCONFIG:=/sbin/ifconfig}"
 DEPMOD="${DEPMOD:=/sbin/depmod}"  DEPMOD="${DEPMOD:=/sbin/depmod}"
 MODPROBE="${MODPROBE:=/sbin/modprobe}"  MODPROBE="${MODPROBE:=/sbin/modprobe}"
Line 116  antispoof_on()
Line 116  antispoof_on()
 # clear status of iptable chains  # clear status of iptable chains
 remove_chains()  remove_chains()
 { # {{{  { # {{{
         $IPTABLES -F # clear all chains  
         $IPTABLES -X # remove all chains          for table in filter nat mangle; do
                   $IPTABLES -t $table -F # clear all chains
                   $IPTABLES -t $table -X # remove all chains
           done
   
 } # }}}  } # }}}
   
 # all packets on loopback are accpted  # all packets on loopback are accpted
Line 135  nmap_scan_filter()
Line 139  nmap_scan_filter()
   
         for chain in INPUT FORWARD; do          for chain in INPUT FORWARD; do
                 #  Nie je nastaveny ziaden bit                  #  Nie je nastaveny ziaden bit
                 $IPTABLES -A $chain   -p TCP --tcp-flags ALL NONE  $LOG_LIMIT -j LOG --log-prefix "nmap scan $chain ALL NONE: "                  $IPTABLES -A $chain   -p TCP --tcp-flags ALL NONE  $LOG_LIMIT "nmap scan $chain ALL NONE: "
                 echo -en "."                  echo -en "."
                 $IPTABLES -A $chain   -p TCP --tcp-flags ALL NONE -j DROP                  $IPTABLES -A $chain   -p TCP --tcp-flags ALL NONE -j DROP
                 echo -en "."                  echo -en "."
   
                 # dva odporujuuce si flagy su nastavene:                  # dva odporujuuce si flagy su nastavene:
                 for flags in   SYN,FIN   SYN,RST   FIN,RST   ; do                  for flags in   SYN,FIN   SYN,RST   FIN,RST   ; do
                         $IPTABLES -A $chain   -p TCP --tcp-flags $flags $flags $LOG_LIMIT -j LOG --log-prefix "nmap scan $chain $flags: "                          $IPTABLES -A $chain   -p TCP --tcp-flags $flags $flags $LOG_LIMIT "nmap scan $chain $flags: "
                         echo -en "."                          echo -en "."
                         $IPTABLES -A $chain   -p TCP --tcp-flags $flags $flags -j DROP                          $IPTABLES -A $chain   -p TCP --tcp-flags $flags $flags -j DROP
                         echo -en "."                          echo -en "."
Line 150  nmap_scan_filter()
Line 154  nmap_scan_filter()
   
                 # je nastavene len $flags bez predpokladaneho ACK                  # je nastavene len $flags bez predpokladaneho ACK
                 for flags in   FIN   PSH   URG   ; do                  for flags in   FIN   PSH   URG   ; do
                         $IPTABLES -A $chain   -p TCP --tcp-flags ACK,$flags $flags $LOG_LIMIT -j LOG --log-prefix "nmap scan $chain ACK,$flags: "                          $IPTABLES -A $chain   -p TCP --tcp-flags ACK,$flags $flags $LOG_LIMIT "nmap scan $chain ACK,$flags: "
                         echo -en "."                          echo -en "."
                         $IPTABLES -A $chain   -p TCP --tcp-flags ACK,$flags $flags -j DROP                          $IPTABLES -A $chain   -p TCP --tcp-flags ACK,$flags $flags -j DROP
                         echo -en "."                          echo -en "."
Line 167  invalid_packet_filter()
Line 171  invalid_packet_filter()
   
         echo -en "Turning on INVALID packet filter "          echo -en "Turning on INVALID packet filter "
         for chain in INPUT OUTPUT FORWARD; do          for chain in INPUT OUTPUT FORWARD; do
                 $IPTABLES -A $chain -m state --state INVALID $LOG_LIMIT  -j LOG --log-prefix "INVALID $chain: "                  $IPTABLES -A $chain -m state --state INVALID $LOG_LIMIT "INVALID $chain: "
                 echo -en "."                  echo -en "."
                 $IPTABLES -A $chain -m state --state INVALID -j DROP                  $IPTABLES -A $chain -m state --state INVALID -j DROP
                 echo -en "."                  echo -en "."
Line 204  anti_spoof_filter()
Line 208  anti_spoof_filter()
                 $IPTABLES -N spoof                  $IPTABLES -N spoof
   
                 # Ochrana proti Spoogingu zo spatnej slucky                  # Ochrana proti Spoogingu zo spatnej slucky
                 $IPTABLES -A spoof -s 127.0.0.0/8 $LOG_LIMIT -j LOG --log-prefix "RESERVED:127.0.0.0/8 src"                  $IPTABLES -A spoof -s 127.0.0.0/8 $LOG_LIMIT "RESERVED:127.0.0.0/8 src"
                 $IPTABLES -A spoof -s 127.0.0.0/8 -j DROP                  $IPTABLES -A spoof -s 127.0.0.0/8 -j DROP
                 $IPTABLES -A spoof -d 127.0.0.0/8 $LOG_LIMIT -j LOG --log-prefix "RESERVED:127.0.0.0/8 dest"                  $IPTABLES -A spoof -d 127.0.0.0/8 $LOG_LIMIT "RESERVED:127.0.0.0/8 dest"
                 $IPTABLES -A spoof -d 127.0.0.0/8 -j DROP                  $IPTABLES -A spoof -d 127.0.0.0/8 -j DROP
                 # Ochrana proti Spoofingu Internetu z adries urcenych pre lokalne siete                  # Ochrana proti Spoofingu Internetu z adries urcenych pre lokalne siete
                 $IPTABLES -A spoof -s 192.168.0.0/16 $LOG_LIMIT -j LOG --log-prefix "RESERVED:192.168.0.0/16 src"                  $IPTABLES -A spoof -s 192.168.0.0/16 $LOG_LIMIT "RESERVED:192.168.0.0/16 src"
                 $IPTABLES -A spoof -s 192.168.0.0/16 -j DROP            # RFC1918                  $IPTABLES -A spoof -s 192.168.0.0/16 -j DROP            # RFC1918
                 $IPTABLES -A spoof -s 172.16.0.0/12 $LOG_LIMIT -j LOG --log-prefix "RESERVED:172.16.0.0/12 src"                  $IPTABLES -A spoof -s 172.16.0.0/12 $LOG_LIMIT "RESERVED:172.16.0.0/12 src"
                 $IPTABLES -A spoof -s 172.16.0.0/12 -j DROP             # RFC1918                  $IPTABLES -A spoof -s 172.16.0.0/12 -j DROP             # RFC1918
                 $IPTABLES -A spoof -s 10.0.0.0/8  $LOG_LIMIT -j LOG --log-prefix "RESERVED:10.0.0.0/8 src"                  $IPTABLES -A spoof -s 10.0.0.0/8  $LOG_LIMIT "RESERVED:10.0.0.0/8 src"
                 $IPTABLES -A spoof -s 10.0.0.0/8 -j DROP  # RFC1918 len pre sietovy interface do Internetu, kedze 10.0.0.0 je adresa LAN                  $IPTABLES -A spoof -s 10.0.0.0/8 -j DROP  # RFC1918 len pre sietovy interface do Internetu, kedze 10.0.0.0 je adresa LAN
                 $IPTABLES -A spoof -s 96.0.0.0/4 $LOG_LIMIT -j LOG --log-prefix "RESERVED:96.0.0.0/4 src"                  $IPTABLES -A spoof -s 96.0.0.0/4 $LOG_LIMIT "RESERVED:96.0.0.0/4 src"
                 $IPTABLES -A spoof -s 96.0.0.0/4 -j DROP                        # IANA                  $IPTABLES -A spoof -s 96.0.0.0/4 -j DROP                        # IANA
   
                 for iface in $ANTISPOOF_IFACE; do                  for iface in $ANTISPOOF_IFACE; do
Line 272  mangle_output()
Line 276  mangle_output()
 masquerade()  masquerade()
 { # {{{  { # {{{
         if [ ! -z "$NAT_LAN_IFACE" ]; then          if [ ! -z "$NAT_LAN_IFACE" ]; then
                 echo -en "Masquerading local subnet: $NAT_SUBNET_IFACE --> $NAT_LAN_IFACE"                  echo -en "NAT: Masquerading local subnet: $NAT_SUBNET_IFACE --> $NAT_LAN_IFACE"
   
                 ip="IP_$NAT_SUBNET_IFACE";                  ip="IP_$NAT_SUBNET_IFACE";
                 netmask="Mask_$NAT_SUBNET_IFACE"                  netmask="Mask_$NAT_SUBNET_IFACE"
                 localnet="${!ip}/${!netmask}"                  localnet="${!ip}/${!netmask}"
   
                   lan_ip="IP_$NAT_LAN_IFACE"
   
                 # alow packets from private subnet                  # alow packets from private subnet
                 $IPTABLES -A FORWARD -s ! $localnet -i $NAT_SUBNET_IFACE -j DROP                  $IPTABLES -A FORWARD -s ! $localnet -i $NAT_SUBNET_IFACE -j DROP
                 $IPTABLES -A INPUT   -i $NAT_SUBNET_IFACE -j ACCEPT  
                 $IPTABLES -A FORWARD -i $NAT_SUBNET_IFACE -j ACCEPT  
   
                 $IPTABLES -t nat -A POSTROUTING -s $localnet -o $NAT_LAN_IFACE -j MASQUERADE                  for redirect in $NAT_TCP_PORT_REDIRECT; do
                           eval `echo $redirect | awk -v FS=: '{ printf "remote_port=%s; local_port=%s;", $1, $2; }'`
                           echo -en " $remote_port:$local_port"
                           $IPTABLES -t nat -A PREROUTING -p TCP \
                                   -i ! $NAT_LAN_IFACE -d ! ${!lan_ip} \
                                   --dport $remote_port -j REDIRECT --to-port $local_port
                   done
   
                   #$IPTABLES -t nat -A POSTROUTING -s $localnet -o $NAT_LAN_IFACE -j MASQUERADE
                   $IPTABLES -t nat -A POSTROUTING -o $NAT_LAN_IFACE -j MASQUERADE
   
                   echo " done."
   
                 # Keep state of connections from private subnets                  # don't forward Miscrosoft protocols - NOT RFC compliant packets
                 iptables -A OUTPUT  -m state --state NEW -o $NAT_LAN_IFACE -j ACCEPT                  if [ ! -z "$NAT_FORWARD_MICROSOFT" ]; then
                 iptables -A FORWARD -m state --state NEW -o $NAT_LAN_IFACE -j ACCEPT                          if [ "x$NAT_FORWARD_MICROSOFT" = "xno" ]; then
                 iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT                                  $IPTABLES -A FORWARD -p TCP ! --syn -m state --state NEW -j DROP
   
                                   for port in 69 135 445 1434 6667; do
                                           $IPTABLES -A FORWARD -p TCP --dport $port -j DROP
                                           $IPTABLES -A FORWARD -p UDP --dport $port -j DROP
                                   done
                           fi
                   fi
   
                   if [ ! -z "$NAT_FORWARD_TCP_PORTS" ]; then
                           echo -en "\tAccepting FORWARD TCP ports:"
                           for port in $NAT_FORWARD_TCP_PORTS; do
                                   echo -en " $port"
                                   $IPTABLES -A FORWARD -p TCP --dport $port -m state --state NEW -j ACCEPT
                           done
                           echo " done."
                   fi
   
                   if [ ! -z "$NAT_FORWARD_UDP_PORTS" ]; then
                           echo -en "\tAccepting FORWARD UDP ports:"
                           for port in $NAT_FORWARD_UDP_PORTS; do
                                   echo -en " $port"
                                   $IPTABLES -A FORWARD -p UDP --dport $port -m state --state NEW -j ACCEPT
                           done
                           echo " done."
                   fi
   
                   echo -en "\tAccepting ICMP packets:"
                   for type in $ACCEPT_ICMP_PACKETS; do
                           echo -en " $type"
                           $IPTABLES -A FORWARD -p ICMP --icmp-type $type -j ACCEPT
                   done
                   #$IPTABLES -A FORWARD -p ICMP -j LOG --log-prefix "FWD ICMP: "
                 echo " done."                  echo " done."
   
                   # Keep state of connections from private subnets
                   $IPTABLES -A OUTPUT  -m state --state NEW -o $NAT_LAN_IFACE -j ACCEPT
                   #$IPTABLES -A FORWARD -m state --state NEW -o $NAT_LAN_IFACE -j ACCEPT
                   $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
   
           fi
   } # }}}
   
   log_new_connections()
   { # {{{
           if [ ! -z "$NAT_LOG_NEW_CONNECTIONS" ]; then
                   if [ "x$NAT_LOG_NEW_CONNECTIONS" = "xyes" ]; then
                           echo -en "Logging new connections:"
                           $IPTABLES -A INPUT   -m state --state NEW -j LOG --log-prefix "IN  connection: "
                           $IPTABLES -A OUTPUT  -m state --state NEW -j LOG --log-prefix "OUT connection: "
                           $IPTABLES -A FORWARD -m state --state NEW -j LOG --log-prefix "FWD connection: "
                           echo " done."
                   fi
         fi          fi
 } # }}}  } # }}}
   
Line 336  allow_input()
Line 401  allow_input()
                         echo -en " $iface"                          echo -en " $iface"
                         $IPTABLES -A INPUT   -i $iface -j ACCEPT                          $IPTABLES -A INPUT   -i $iface -j ACCEPT
                         $IPTABLES -A FORWARD -i $iface -j ACCEPT                          $IPTABLES -A FORWARD -i $iface -j ACCEPT
                           $IPTABLES -A OUTPUT  -o $iface -j ACCEPT
                 done                  done
                 echo " done."                  echo " done."
         fi          fi
Line 351  allow_input()
Line 417  allow_input()
                 done                  done
                 echo " done."                  echo " done."
         fi          fi
           if [ ! -z "$ALL_ACCEPT_INPUT_UDP" ]; then
                   echo -en "Accepting ALL INPUT UDP connections on ports:"
                   for port in $ALL_ACCEPT_INPUT_UDP; do
                           for iface in $INTERFACES; do
                                   ip="IP_$iface";
                                   echo -en " $port($iface)"
                                   $IPTABLES -A INPUT -i $iface -p UDP --dport $port -j ACCEPT
                           done
                   done
                   echo " done."
           fi
   
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                 ip="IP_$iface";                  ip="IP_$iface";
Line 407  allow_icmp()
Line 484  allow_icmp()
         $IPTABLES -A INPUT -p TCP --dport 113 -j REJECT --reject-with tcp-reset #AUTH server          $IPTABLES -A INPUT -p TCP --dport 113 -j REJECT --reject-with tcp-reset #AUTH server
   
         # accept only allowed ICMP packets          # accept only allowed ICMP packets
         for type in echo-reply destination-unreachable echo-request time-exceeded; do          for type in $ACCEPT_ICMP_PACKETS; do
                 echo -en " $type"                  echo -en " $type"
                 for iface in $INTERFACES; do                  for iface in $INTERFACES; do
                         ip="IP_$iface";                          ip="IP_$iface";
                         $IPTABLES -A INPUT -i $iface -d ${!ip} -p ICMP --icmp-type $type -j ACCEPT                          $IPTABLES -A INPUT -i $iface -d ${!ip} -p ICMP --icmp-type $type -j ACCEPT
                 done                  done
         done          done
           #$IPTABLES -A INPUT  -p ICMP -j LOG --log-prefix "IN  ICMP: "
           #$IPTABLES -A OUTPUT -p ICMP -j LOG --log-prefix "OUT ICMP: "
         echo " done."          echo " done."
   
 } # }}}  } # }}}
Line 423  log_input_drop()
Line 502  log_input_drop()
   
         prefix="input drop: "          prefix="input drop: "
         echo "Input drop is logged with prefix '$prefix'"          echo "Input drop is logged with prefix '$prefix'"
         $IPTABLES -A INPUT $LOG_LIMIT -j LOG --log-prefix "$prefix"          $IPTABLES -A INPUT $LOG_LIMIT "$prefix"
   
 } # }}}  } # }}}
   
Line 432  log_output_drop()
Line 511  log_output_drop()
   
         prefix="output drop: "          prefix="output drop: "
         echo "Output drop is logged with prefix '$prefix'"          echo "Output drop is logged with prefix '$prefix'"
         $IPTABLES -A OUTPUT $LOG_LIMIT -j LOG --log-prefix "$prefix"          $IPTABLES -A OUTPUT $LOG_LIMIT "$prefix"
   
 } # }}}  } # }}}
   
Line 441  log_forward_drop()
Line 520  log_forward_drop()
   
         prefix="forward drop: "          prefix="forward drop: "
         echo "Forward drop is logged with prefix '$prefix'"          echo "Forward drop is logged with prefix '$prefix'"
         $IPTABLES -A FORWARD $LOG_LIMIT -j LOG --log-prefix "$prefix"          $IPTABLES -A FORWARD $LOG_LIMIT "$prefix"
   
 } # }}}  } # }}}
   
Line 542  case "$1" in
Line 621  case "$1" in
                 syn_flood                  syn_flood
                 mangle_prerouting                  mangle_prerouting
                 mangle_output                  mangle_output
                   log_new_connections
                 drop_output                  drop_output
                 allow_input                  allow_input
                 allow_output                  allow_output

Legend:
Removed from v.2.3  
changed lines
  Added in v.2.13

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top