#!/bin/sh #################################################################### ## Netfilters Init-Script for workstations #################################################################### ## by Sebastian "blackwing" Werner (blackwing@blackwing.de) #################################################################### ## Current Version ## $Id: simple.workstation.NEW.txt,v 1.2 2003/12/22 21:20:15 blackwing Exp $ #################################################################### ## ChangeLog ## $Log: simple.workstation.NEW.txt,v $ ## Revision 1.2 2003/12/22 21:20:15 blackwing ## added rcs-tags. ## sw, 22/12/2003 ## #################################################################### ## ## Features: ## - Stateful filtering ## - Protection of common attacks ## ## Requires: ## - Kernel with netfilters (iptables support) i.e. 2.4.18 ## ## This script is released under the terms of the ## GNU General Public License ## ## If you have suggestions, please contact me! #################################################################### ## Variables #################################################################### ## Where is your IPTables binary? IPTABLES="/sbin/iptables" #################################################################### ## Start or Restart the script #################################################################### echo -n "Setting up netfilters: " ############################################################### ## Kernel security settings ############################################################### ## Activate IP-Forwarding in kernel echo 1 > /proc/sys/net/ipv4/ip_forward ## Activate Syncookie Support echo 1 > /proc/sys/net/ipv4/tcp_syncookies ## DynIP Patch echo 1 > /proc/sys/net/ipv4/ip_dynaddr ## Ignore Dead Error Messages echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses ## Ignore all Broadcasts pings echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts ## Enable route verification for f in /proc/sys/net/ipv4/conf/*/rp_filter; do echo 1 > $f done ## Deny source routed packages echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route ## Disable ICMP redirect acceptance echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects ## Enable bad error message protection echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses ## Don NOT Log impossible packets echo 0 >/proc/sys/net/ipv4/conf/all/log_martians ## Set local port range echo "50000 60999" >/proc/sys/net/ipv4/ip_local_port_range ## Decrease tcp timeouts to prevent DoS echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_time echo 1 > /proc/sys/net/ipv4/tcp_window_scaling echo 0 > /proc/sys/net/ipv4/tcp_sack #################################################################### ## Reset everything to the basics #################################################################### ## Delete all the rules already set $IPTABLES -F $IPTABLES -F -t mangle $IPTABLES -F -t nat ## Set the default policies $IPTABLES -P INPUT DROP $IPTABLES -P OUTPUT ACCEPT $IPTABLES -P FORWARD DROP ############################################################### ## Accepting specific incoming traffic ############################################################### ## Accept all traffic of existing connections $IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT ## Accept new incoming ssh connections (5 per second) $IPTABLES -A INPUT --protocol tcp --destination-port ssh -m state --state NEW -m limit --limit 5/s -j ACCEPT ## Accept five echo-replys per second $IPTABLES -A INPUT --protocol icmp --icmp-type echo-request -m limit --limit 10/s -j ACCEPT ## Add YOUR rules HERE! ############################################################### ## Default rules ############################################################### ## Reply to new tcp connections with tcp-reset $IPTABLES -A INPUT --protocol tcp -j REJECT --reject-with tcp-reset ## All other get regular icmp error $IPTABLES -A INPUT -j REJECT