matheus.silva
(usa Debian)
Enviado em 27/01/2008 - 15:41h
Dá uma olhada no meu script...
echo "Firewall Flushing - Stage 1"
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -t nat -F PREROUTING
echo "Loading Modules - Stage 2"
modprobe ip_tables
modprobe iptable_filter
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_conntrack_tftp
modprobe ip_conntrack_irc
modprobe iptable_mangle
modprobe iptable_nat
modprobe ip_nat_ftp
modprobe ip_nat_tftp
modprobe ip_nat_irc
modprobe ipt_MASQUERADE
echo "Standard Policies - Stage 3"
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
echo "Local Protection - Stage 4"
echo "Anti-spoofing Protection"
for spoofing in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $spoofing
done
echo "Protection against ping"
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
echo "Syn-flood protection"
#iptables -t filter -A INPUT -p tcp --syn -m limit --limit 6/s -j ACCEPT
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo
echo
echo "Initial Rules - Stage 5"
echo "Allowing localhost traffic"
iptables -A INPUT -i lo -j ACCEPT
echo "Keeping established connections"
iptables -A INPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Activating masquerading"
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth1 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Denying MSN"
#iptables -A FORWARD -s 10.0.0.0/8 -d 0/0 -p tcp --dport 1863 -j REJECT
#iptables -A FORWARD -i eth1 -p tcp --dport 1863 -j REJECT
#iptables -A OUTPUT -i eth1 -p tcp --dport 1863 -j DROP
#iptables -A FORWARD -i eth1 -d loginnet.passport.com -j REJECT
#iptables -A FORWARD -i eth1 -d messenger.hotmail.com -j REJECT
#iptables -A FORWARD -i eth1 -d webmessenger.msn.com -j REJECT
#iptables -A FORWARD -p tcp --dport 1080 -j DROP
#iptables -A FORWARD -i eth1 -p tcp --dport 1080 -j REJECT
#iptables -A FORWARD -p tcp --dport 1863 -j DROP
#iptables -A FORWARD -i eth1 -d loginnet.passport.com -j DROP
#iptables -A FORWARD -i eth1 -p tcp --dport 5190 -j DROP
#regra pra redirecionar servicos pra rede interna
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to 192.168.90.2:8080
echo "Redirecting Squid Traffic"
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j DROP
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 3128 -j DROP
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 1863 -j REDIRECT --to-port 80
echo "Dropping mal-formed packets"
iptables -A INPUT -i eth0 -m unclean -j LOG --log-level 6 --log-prefix "Firewall Bad PKT:"
iptables -A INPUT -i eth0 -m unclean -j DROP
echo "Controlling what's going away"
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Protections - Stage 6"
echo "Protection against Trinoo"
iptables -N TRINOO
iptables -A TRINOO -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "Firewall - Trinoo: "
iptables -A TRINOO -j DROP
iptables -A INPUT -p tcp -i eth0 --dport 27444 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 27665 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 31335 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 34555 -j TRINOO
iptables -A INPUT -p tcp -i eth0 --dport 35555 -j TRINOO
echo "Protection against Trojan"
iptables -N TROJAN
iptables -A TROJAN -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "Firewall - Trojan: "
iptables -A TROJAN -j DROP
iptables -A INPUT -p tcp -i eth0 --dport 666 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 4000 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 6000 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 6006 -j TROJAN
iptables -A INPUT -p tcp -i eth0 --dport 16660 -j TROJAN
echo "Protection against Worms"
iptables -A FORWARD -p tcp --dport 135 -i eth1 -j DROP
echo "Protection against Scanners"
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "Firewall: port scanner: "
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i eth0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i eth0 -j SCANNER
echo "Filtering Auth service"
iptables -A INPUT -p tcp --dport 113 -j DROP
iptables -A INPUT -p udp --dport 113 -j DROP
echo "Filtering Location service"
iptables -A INPUT -p tcp --dport 135 -j DROP
iptables -A INPUT -p udp --dport 135 -j DROP
echo "Filtering Profile Naming System"
iptables -A INPUT -p tcp --dport 136 -j DROP
iptables -A INPUT -p udp --dport 136 -j DROP
echo "Filtering SSH"
iptables -A INPUT -p tcp --dport 22 -j DROP
iptables -A INPUT -p tcp --dport 65000 -j ACCEPT
iptables -A FORWARD -p tcp -i eth1 --dport 65000 -j ACCEPT
echo "Filtering NetBIOS Naming Service"
iptables -A INPUT -p tcp --dport 137 -j DROP
iptables -A INPUT -p udp --dport 137 -j DROP
iptables -A OUTPUT -p tcp --sport 137 -j DROP
iptables -A OUTPUT -p udp --sport 137 -j DROP
iptables -A FORWARD -p tcp --dport 137 -j DROP
iptables -A FORWARD -p udp --dport 137 -j DROP
iptables -A FORWARD -p tcp --sport 137 -j DROP
iptables -A FORWARD -p udp --sport 137 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 137 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 137 -j DROP
iptables -t nat -A PREROUTING -p tcp --sport 137 -j DROP
iptables -t nat -A PREROUTING -p udp --sport 137 -j DROP
iptables -A INPUT -p tcp --dport 138 -j DROP
iptables -A INPUT -p udp --dport 138 -j DROP
iptables -A OUTPUT -p tcp --sport 138 -j DROP
iptables -A OUTPUT -p udp --sport 138 -j DROP
iptables -A FORWARD -p tcp --dport 138 -j DROP
iptables -A FORWARD -p udp --dport 138 -j DROP
iptables -A OUTPUT -p tcp --sport 138 -j DROP
iptables -A OUTPUT -p udp --sport 138 -j DROP
iptables -A FORWARD -p tcp --dport 138 -j DROP
iptables -A FORWARD -p udp --dport 138 -j DROP
iptables -A FORWARD -p tcp --sport 138 -j DROP
iptables -A FORWARD -p udp --sport 138 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 138 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 138 -j DROP
iptables -t nat -A PREROUTING -p tcp --sport 138 -j DROP
iptables -t nat -A PREROUTING -p udp --sport 138 -j DROP
iptables -A INPUT -p tcp --dport 139 -j DROP
iptables -A INPUT -p udp --dport 139 -j DROP
iptables -A OUTPUT -p tcp --sport 139 -j DROP
iptables -A OUTPUT -p udp --sport 139 -j DROP
iptables -A FORWARD -p tcp --dport 139 -j DROP
iptables -A FORWARD -p udp --dport 139 -j DROP
iptables -A FORWARD -p tcp --sport 139 -j DROP
iptables -A FORWARD -p udp --sport 139 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 139 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 139 -j DROP
iptables -t nat -A PREROUTING -p tcp --sport 139 -j DROP
iptables -t nat -A PREROUTING -p udp --sport 139 -j DROP
iptables -A INPUT -p tcp --dport 445 -j DROP
iptables -A INPUT -p udp --dport 445 -j DROP
iptables -A OUTPUT -p tcp --sport 445 -j DROP
iptables -A OUTPUT -p udp --sport 445 -j DROP
iptables -A FORWARD -p tcp --dport 445 -j DROP
iptables -A FORWARD -p udp --dport 445 -j DROP
iptables -A FORWARD -p tcp --sport 445 -j DROP
iptables -A FORWARD -p udp --sport 445 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 445 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 445 -j DROP
iptables -t nat -A PREROUTING -p tcp --sport 445 -j DROP
iptables -t nat -A PREROUTING -p udp --sport 445 -j DROP
echo "Last Configs - Stage 7"
echo "Denying everything else..."
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
iptables -A FORWARD -j DROP
#iptables -t nat -A PREROUTING -j DROP
echo "Enabling ip packet forwarding"
echo "1" > /proc/sys/net/ipv4/ip_forward