linus black
(usa Debian)
Enviado em 11/08/2009 - 21:59h
#!/bin/sh
#
# rc.firewall .By Linus Black For slackware12.2
#
#
#
modprobe ip_tables
modprobe ip_conntrack
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
modprobe ipt_LOG
modprobe ipt_limit
modprobe ipt_state
modprobe ipt_REDIRECT
modprobe ipt_owner
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ip_gre
#
#Limpa as Regras
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
#
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 1 > /proc/sys/net/ipv4/conf/all/accept_source_route
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
echo 0 > /proc/sys/net/ipv4/conf/all/log_martians
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_intvl
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 1 > /proc/sys/net/ipv4/tcp_ecn
echo 1 > /proc/sys/net/ipv4/tcp_timestamps
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo "=========================================================|"
echo "|:INICIANDO A CONFIGURAÇÃO DO FIREWALL NETFILTER ATRAVÉS:|"
echo "|: DO IPTABLES :|"
echo "=========================================================|"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
#Politicas Padrao
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#
### Ativando Protecoes Contra Ataques ###
# 1 - Protecao contra Trinoo
iptables -N TRINOO
iptables -A TRINOO -m limit --limit 1/s -j LOG --log-level 6 --log-prefix "FIREWALL(Prot. 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 "ativado o bloqueio a tentativa de ataque do tipo Trinoo"
echo "ON .................................................[ OK ]"
# 2 - Protecao contra Trojans
iptables -N TROJAN
iptables -A TROJAN -m limit --limit 1/s -j LOG --log-level 6 --log-prefix "FIREWALL(Prot. 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 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 "ativado o bloqueio a tentativa de ataque do tipo Trojan"
echo "ON .................................................[ OK ]"
# 3 - Protecao contra Worms
iptables -A FORWARD -p tcp --dport 135 -i eth0 -j REJECT
echo "ativado o bloqueio a tentativa de ataque do tipo Worms"
echo "ON .................................................[ OK ]"
# 4 - Protecao contra Syn-Flood
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
echo "ativado o bloqueio a tentativa de ataque do tipo Syn-Flood"
echo "ON .................................................[ OK ]"
# 5 - Protecao contra Ping da Morte
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
echo "ativado o bloqueio a tentativa de ataque do tipo ping "
echo "ON .................................................[ OK ]"
# 6 - Protecao contra Port Scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 1/s -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
iptables -A INPUT -p udp -s 0/0 -i eth0 --dport 33435:33525 -j REJECT
iptables -A INPUT -m state --state INVALID -j REJECT
echo "ativado o bloqueio a tentativa de ataque do tipo Scanners"
echo "ON .................................................[ OK ]"
#
#Rotiamento e redirecionamento
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -j MASQUERADE
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "ativado o Rotiamento"
echo "ON .................................................[ OK ]"
#Liberando rrede interna
iptables -A OUTPUT -s 192.168.0.0/16 -j ACCEPT
iptables -A INPUT -s 192.168.0.0/16 -p udp --dport 53 -j ACCEPT
#iptables -A INPUT -s 192.168.0.0/16 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -s 192.168.0.15 -p tcp --dport 22 -j ACCEPT
#iptables -A INPUT -s 192.168.0.0/16 -p tcp --dport 443 -j ACCEPT
#Mantendo a coneo
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#
iptables -t filter -A INPUT -i lo -j ACCEPT
#
# BLOQUEA O QUE NAO SE ENCAIXA NAS REGRAS ACIMA
iptables -A INPUT -p tcp --syn -j DROP
iptables -P FORWARD DROP
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo "=========================================================|"
echo "|: CARREGAMENTO BEM SUSSEDIDO :|"
echo "|: DO IPTABLES :|"
echo "=========================================================|"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
testa ai.