#!/bin/sh # ######################################################################## # DoppelGanger Firewall Initiation Script # # Version 1.2 Final # # Copyright (C) 2005 DoppelGanger # # Bugs & Comments to: www.amado.ws/contactus.html # # # #This program is free software; you can redistribute it and/or # #modify it under the terms of the GNU General Public License # #as published by the Free Software Foundation; either version 2 # #of the License, or (at your option) any later version. # # # #This program is distributed in the hope that it will be useful, # #but WITHOUT ANY WARRANTY; without even the implied warranty of # #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # #GNU General Public License for more details. # # # ######################################################################## # # # Environment variables ANY=0.0.0.0/0 IPTABLES=/sbin/iptables MODPROBE=/sbin/modprobe # # ######################################################################## # Load IPTABLES modules as appropriate. Remove if precompiled # # support in kernel as * and not M (module). # ######################################################################## # $MODPROBE ip_tables # $MODPROBE iptable_filter # $MODPROBE ip_conntrack # $MODPROBE ip_conntrack_ftp # ######################################################################## # Set proc values for TCP/IP # # # # Ignore Icmp Echo Pings # # Disable IP Spoofing Attacks # # Ignore broadcast pings # # Block source routing # # Kill redirects # # Disable secure redirects # # Stop bogus Error Messages # # Disable Ip Forwarding # # Set acceptable local port range # # Enable TCP SYN Cookie Protection from SYN floods # # Use A Reasonable Local Port Range # ######################################################################## echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all echo "2" > /proc/sys/net/ipv4/conf/all/rp_filter echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route echo "0" > /proc/sys/net/ipv4/conf/default/accept_source_route echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects echo "0" > /proc/sys/net/ipv4/conf/default/accept_redirects echo "0" > /proc/sys/net/ipv4/conf/all/secure_redirects echo "0" > /proc/sys/net/ipv4/conf/default/secure_redirects echo "1" > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses echo "0" > /proc/sys/net/ipv4/ip_forward echo "1" > /proc/sys/net/ipv4/tcp_syncookies echo "32768 61000" > /proc/sys/net/ipv4/ip_local_port_range # # ######################################################################## # Flush and Reset All Chains # ######################################################################## $IPTABLES -F #remove rules in all chains $IPTABLES -X #remove user defined chains $IPTABLES -F INPUT #remove existing rules currently running (INPUT) $IPTABLES -F OUTPUT #remove existing rules currently running (OUTPUT) $IPTABLES -F FORWARD #remove existing rules currently running (FORWARD) $IPTABLES -t filter -F #remove rules in filter table $IPTABLES -t filter -X #remove user defined chains in filter table $IPTABLES -t nat -F #remove rules in NAT Table $IPTABLES -t nat -X #remove user defined chains in nat table $IPTABLES -t mangle -F #remove rules in nat table # # ######################################################################## # Default Policy Drop All Packets # ######################################################################## $IPTABLES -P INPUT DROP $IPTABLES -P FORWARD DROP $IPTABLES -P OUTPUT ACCEPT # # ######################################################################## # Allow Internal Traffic aka loopback # ######################################################################## $IPTABLES -A INPUT -i lo -j ACCEPT # # ######################################################################## # Allow Established Connections Through Firewall # ######################################################################## $IPTABLES -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT # # ######################################################################## # Drop Invalid Packets aka Spoofed Packets # ######################################################################## $IPTABLES -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP $IPTABLES -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP $IPTABLES -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP $IPTABLES -A INPUT -i eth0 -s 169.254.0.0/16 -j DROP $IPTABLES -A INPUT -i eth0 -s 0.0.0.0/8 -j DROP $IPTABLES -A INPUT -i eth0 -s 255.255.255.255/32 -j DROP $IPTABLES -A INPUT -d 127.0.0.0/8 -j DROP # # ######################################################################## # Allow Incoming SSH Connections for Remote Administration # # Other Services for Example Apache Maybe Added Below for TCP or UDP # # Ports. See /etc/services for a list of service ports # ######################################################################## $IPTABLES -A INPUT -p tcp --dport 22 -j ACCEPT # # ######################################################################## # SYN Packet Limiting to Prevent DOS Attacks # ######################################################################## $IPTABLES -A INPUT -p tcp --syn -m limit --limit 5/second -j ACCEPT #Limit Logs of SYN Packets to One Entry Per Minute $IPTABLES -A FORWARD -p tcp --syn -m limit --limit 1/minute -j LOG --log-prefix "SYN flood: " --log-ip-options --log-tcp-options # # ######################################################################## # Banned or Blocked IP Addresses # ######################################################################## #Drop A Specific IP Address #$IPTABLES -I INPUT -s 55.55.55.1 -j DROP #Drop A Class C Range #$IPTABLES -I INPUT -s 55.55.55.0/24 -j DROP #Drop A Domain Using IP Address Range #$IPTABLES -I INPUT -s 55.55.55.1:55.55.55.100 -j DROP # # ######################################################################## # Don't log IGMP, WEB, SSL,ICMP, NETBIOS. Add any other things you # # don't want to see in the logs. # ######################################################################## $IPTABLES -A INPUT -p igmp -j DROP $IPTABLES -A INPUT -p icmp -j DROP $IPTABLES -A INPUT -m multiport -p tcp --dports 80,137,138,139,443,449 -j DROP $IPTABLES -A INPUT -m multiport -p udp --dports 80,137,138,139,443,449 -j DROP # # ######################################################################## # Log Everything Else That You Did Not Exclude # ######################################################################## $IPTABLES -A INPUT -i eth0 -j LOG --log-prefix "|iptables -- " # # # Done!