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

Diff for scripts/shell/firewall/fw-universal.sh between version 2.15 and 2.23

version 2.15, 2005/01/16 12:13:32 version 2.23, 2005/04/15 22:07:18
Line 9 
Line 9 
 # 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.14 2005/01/16 11:06:46 rajo Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.22 2005/03/16 13:53:36 rajo Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
Line 48  AWK="${AWK:=/usr/bin/awk}"
Line 48  AWK="${AWK:=/usr/bin/awk}"
 LO_IFACE="${LO_IFACE:=lo}"  LO_IFACE="${LO_IFACE:=lo}"
 LO_IP="IP_$LO_IFACE"  LO_IP="IP_$LO_IFACE"
   
   #
   # CONSTANTS - Do not edit
   #
   ANYWHERE="0.0.0.0/0"                            # Match any IP address
   BROADCAST_SRC="0.0.0.0"                         # Broadcast Source Address
   BROADCAST_DEST="255.255.255.255"        # Broadcast Destination Address
   CLASS_A="10.0.0.0/8"                            # Class-A Private (RFC-1918) Networks
   CLASS_B="172.16.0.0/12"                         # Class-B Private (RFC-1918) Networks
   CLASS_C="192.168.0.0/16"                        # Class-C Private (RFC-1918) Networks
   CLASS_D_MULTICAST="224.0.0.0/4"         # Class-D Multicast Addresses
   CLASS_E_RESERVED_NET="240.0.0.0/5"      # Class-E Reserved Addresses
   PRIVPORTS="0:1023"                                      # Well-Known, Privileged Port Range
   UNPRIVPORTS="1024:65535"                        # Unprivileged Port Range
   TRACEROUTE_SRC_PORTS="32769:65535"      # Traceroute Source Ports
   TRACEROUTE_DEST_PORTS="33434:33523"     # Traceroute Destination Ports
   
   
 # allow some ICMP packets - needed for ping etc.  # allow some ICMP packets - needed for ping etc.
 ACCEPT_ICMP_PACKETS="${ACCEPT_ICMP_PACKETS:=echo-reply destination-unreachable echo-request time-exceeded}"  ACCEPT_ICMP_PACKETS="${ACCEPT_ICMP_PACKETS:=echo-reply destination-unreachable echo-request time-exceeded}"
   
   
 # load necessary modules from $MODULES variable  # load necessary modules from $MODULES variable
 load_modules()  load_modules()
 { # {{{  { # {{{
Line 77  unload_modules()
Line 95  unload_modules()
 print_iface_status()  print_iface_status()
 { # {{{  { # {{{
         # Print interfaces:          # Print interfaces:
         echo "# iface   | IP addr       | broadcast     | netmask       | HW addr"          echo "# iface   | IP addr       | Gateway       | broadcast     | netmask       | HW addr"
         for iface in $interfaces; do          for iface in $interfaces; do
                 IP="IP_$iface"; Bcast="Bcast_$iface"; Mask="Mask_$iface"; HWaddr="HWaddr_$iface";                  IP="IP_$iface"; Gateway="Gateway_$iface"; Bcast="Bcast_$iface"; Mask="Mask_$iface"; HWaddr="HWaddr_$iface";
                 echo "$iface    | ${!IP}        | ${!Bcast}     | ${!Mask}      | ${!HWaddr}"                  echo "$iface    | ${!IP}        | ${!Gateway}   | ${!Bcast}     | ${!Mask}      | ${!HWaddr}"
         done          done
 } # }}}  } # }}}
   
Line 107  remove_chains()
Line 125  remove_chains()
         for table in filter nat mangle; do          for table in filter nat mangle; do
                 $IPTABLES -t $table -F # clear all chains                  $IPTABLES -t $table -F # clear all chains
                 $IPTABLES -t $table -X # remove all chains                  $IPTABLES -t $table -X # remove all chains
                   $IPTABLES -t $table -Z # zero counts
         done          done
   
 } # }}}  } # }}}
Line 256  mangle_output()
Line 275  mangle_output()
 masquerade()  masquerade()
 { # {{{  { # {{{
         if [ ! -z "$NAT_LAN_IFACE" ]; then          if [ ! -z "$NAT_LAN_IFACE" ]; then
           echo -en "NAT: Enabling packet forwarding..."
           echo 1 > /proc/sys/net/ipv4/ip_forward
           echo " done."
                 echo -en "NAT: 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";
Line 266  masquerade()
Line 288  masquerade()
   
                 # 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
                   for client_ip in $NAT_CLIENT_DROP; do
                           echo -en " !$client_ip";
                           $IPTABLES -A FORWARD -s $client_ip -i $NAT_SUBNET_IFACE -j DROP
                   done
   
                 for redirect in $NAT_TCP_PORT_REDIRECT; do                  for redirect in $NAT_TCP_PORT_REDIRECT; do
                         eval `echo $redirect | awk -v FS=: '{ printf "remote_port=%s; local_port=%s;", $1, $2; }'`                          eval `echo $redirect | awk -v FS=: '{ printf "remote_port=%s; local_port=%s;", $1, $2; }'`
Line 318  masquerade()
Line 344  masquerade()
                 #$IPTABLES -A FORWARD -p ICMP -j LOG --log-prefix "FWD ICMP: "                  #$IPTABLES -A FORWARD -p ICMP -j LOG --log-prefix "FWD ICMP: "
                 echo " done."                  echo " done."
   
                   # Port forwarding to local machines
                   if [ ! -z "$NAT_TCP_PORT_FORWARD" ]; then
                           echo -en "\tForwarding ports to local machines:"
                           for redirect in $NAT_TCP_PORT_FORWARD; do
                                   eval `echo $redirect | awk -v FS=: '{ printf "src_port=%s; local_machine=%s; dest_port=%s;", $1, $2, $3; }'`
                                   echo -en " $src_port -> $local_machine:$dest_port"
                                   $IPTABLES -t nat -A PREROUTING -p TCP -i $NAT_LAN_IFACE -d ${!lan_ip} \
                                   --dport $src_port -j DNAT --to $local_machine:$dest_port
                                   $IPTABLES -A FORWARD -p TCP -i eth0 -d $local_machine --dport $dest_port -j ACCEPT
                           done
                           echo " done."
                   fi
   
                 # Keep state of connections from private subnets                  # Keep state of connections from private subnets
                 $IPTABLES -A OUTPUT  -m state --state NEW -o $NAT_LAN_IFACE -j ACCEPT                  $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 NEW -o $NAT_LAN_IFACE -j ACCEPT
Line 372  drop_output()
Line 411  drop_output()
   
 } # }}}  } # }}}
   
   bann_ip_adresses()
   { # {{{
           #
           # This feature has been developed for following reason:
           # UbiCrawler spam our website with many requests (they are duplicit requests of the same page!)
           # And this web robot doesn't accept HTTP META tags (http://www.robotstxt.org/wc/faq.html#extension)
           #
           # Bann them too!
           #
           #IP address is: 146.48.97.11 146.48.97.13
           # User Agent: "UbiCrawler/v0.4beta (http://ubi.iit.cnr.it/projects/ubicrawler/)"
           #
           if [ ! -z "$BANNED_IP" ]; then
                   echo -en "Dropping ALL packets from IP:"
                   for banned_ip in $BANNED_IP; do
                           echo -en " $banned_ip"
                           $IPTABLES -A INPUT              -s $banned_ip -j DROP
                           $IPTABLES -A FORWARD    -s $banned_ip -j DROP
                   done
                   echo " done."
           fi
   } # }}}
   
 allow_accept_all()  allow_accept_all()
 { # {{{  { # {{{
         if [ ! -z "$IFACE_ACCEPT_ALL" ]; then          if [ ! -z "$IFACE_ACCEPT_ALL" ]; then
Line 440  allow_input()
Line 502  allow_input()
                 fi                  fi
         done          done
   
           # Enable outgoing TRACEROUTE requests (required e.g. by Skype, http://www.skype.com)
           if [ ! -z "$TRACEROUTE_IFACE" ]; then
                   ip="IP_$ANTISPOOF_IFACE";
                   echo -en "Accepting traceroute:"
   
                   $IPTABLES -A OUTPUT -o $ANTISPOOF_IFACE -p UDP \
                           --sport $TRACEROUTE_SRC_PORTS --dport $TRACEROUTE_DEST_PORTS \
                           -s ${!ip} -d $ANYWHERE -j ACCEPT
   
                   for iface in $TRACEROUTE_IFACE; do
                           $IPTABLES -A FORWARD -p UDP -i $iface --sport $TRACEROUTE_SRC_PORTS \
                                   --dport $TRACEROUTE_DEST_PORTS -j ACCEPT
                   done
                   echo " done."
           fi
   
 } # }}}  } # }}}
   
 # ACCEPT all packets from our IP address  # ACCEPT all packets from our IP address
Line 525  accept_loopback()
Line 603  accept_loopback()
   
         # Loopback není radno omezovat          # Loopback není radno omezovat
         echo -en "Accepting loopback:"          echo -en "Accepting loopback:"
         $IPTABLES -A INPUT -i $LO_IFACE -j ACCEPT          $IPTABLES -A INPUT  -i $LO_IFACE -j ACCEPT
           $IPTABLES -A OUTPUT -o $LO_IFACE -j ACCEPT
         echo " done."          echo " done."
   
 } # }}}  } # }}}
Line 566  parse_ifconfig()
Line 645  parse_ifconfig()
                         END { printf "\ninterfaces=\"%s\";      export interfaces;\n", interfaces; }                          END { printf "\ninterfaces=\"%s\";      export interfaces;\n", interfaces; }
         '`          '`
   
           eval `perl -e '
           $\ = "\n";
           open(FILE, "/proc/net/route") or die "Can not open /proc/net/route: $!";
           my @columns = split(/\s+/, <FILE>);
           while (my $line = <FILE>) {
                   my $iface;
                   my @vals = split(/\s+/, $line);
                   foreach my $key (@columns) {
                           $iface->{$key} = shift @vals;
                   }
   
                   foreach my $key (qw( Gateway Destination )) {
                           print "${key}_$iface->{Iface}=",
                                   qw("), hex2ip($iface->{$key}), qw("),
                                   "; export ${key}_$iface->{Iface};";
                   }
                   foreach my $key (qw( Flags MTU Metric Window IRTT )) {
                           print "${key}_$iface->{Iface}=",
                                   qw("), $iface->{$key}, qw("),
                                   "; export ${key}_$iface->{Iface};";
                   }
           }
           close(FILE);
   
   
           sub hex2ip
           { # {{{
                   my ($str) = @_;
                   my @block;
   
                   my $hex = uc($str);
   
                   while (length($hex)) {
                           my $x = ord(substr($hex, 0, 1));
                           my $y = ord(substr($hex, 1, 1));
   
                           $x = $x > 64 ? $x - 55 : $x - 48;
                           $y = $y > 64 ? $y - 55 : $y - 48;
   
                           push @block, 16 * $x + $y;
                           $hex = substr($hex, 2);
                   }
   
                   return join(".", reverse @block);
   
           } # }}}
           '`
         # Now we have defined variables like this:          # Now we have defined variables like this:
         # IFACE_eth0 HWaddr_eth0 IP_eth0 Bcast_eth0 Mask_eth0          # IFACE_eth0 HWaddr_eth0 IP_eth0 Bcast_eth0 Mask_eth0
         # IFACE_lo   HWaddr_lo   IP_lo   Bcast_lo   Mask_lo          # IFACE_lo   HWaddr_lo   IP_lo   Bcast_lo   Mask_lo
Line 599  for iface in $interfaces; do
Line 725  for iface in $interfaces; do
                 INTERFACES="$INTERFACES $iface";                  INTERFACES="$INTERFACES $iface";
         fi          fi
 done  done
   INTERFACES_ACCEPT_ALL="$IFACE_ACCEPT_ALL"
   
   
 case "$1" in  case "$1" in
Line 612  case "$1" in
Line 739  case "$1" in
                 #                  #
                 # (un)commnet next lines as needed                  # (un)commnet next lines as needed
                 #                  #
                   bann_ip_adresses
                 allow_accept_all                  allow_accept_all
                 nmap_scan_filter                  nmap_scan_filter
                 invalid_packet_filter                  invalid_packet_filter

Legend:
Removed from v.2.15  
changed lines
  Added in v.2.23

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