berdam
(usa CentOS)
Enviado em 03/05/2010 - 13:00h
Galer,a montei um script de firewall aqui e gostaria de ver com vcs, oq estaria de errado nele, ou algumas coisas para ajudar.
Gostatia da opiniao de vcs.
Obrigado desde ja
#!/bin/sh
# Variáveis
# -------------------------------------------------------
IF_EXTERNA=eth0
IF_INTERNA=eth1
echo "Iniciando firewall ........................................[ OK ]"
modprobe iptable_nat
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
echo "Compartilhando internet"
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "Proteção contra IP spoofing"
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
#Coloque 1 servidor for roteador
echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
#Destiva Broadcast
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "Zera regras"
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#Bloqueio pacotes invalidos
echo "1" > /proc/sys/net/ipv4/conf/default/rp_filter
iptables -A INPUT -m state --state INVALID -j DROP
echo "Restringindo faixa de ips 192.168.0.0"
iptables -A INPUT -s 192.168.0.0/255.255.255.0 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
echo "Aceita os pacotes que realmente devem entrar"
iptables -A INPUT -i ! $IF_EXTERNA -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Dropa pacotes TCP indesejáveis"
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-level 6 --log-prefix "FIREWALL: NEW sem syn: "
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
echo "Direcionando WTS"
iptables -t nat -p tcp -I PREROUTING --dport 3389 -j DNAT --to 192.168.0.3
iptables -I FORWARD -p TCP --dport 3389 -j ACCEPT
echo "Proteção contra 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 $IF_EXTERNA --dport 27444 -j TRINOO
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 27665 -j TRINOO
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 31335 -j TRINOO
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 34555 -j TRINOO
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 35555 -j TRINOO
echo "Proteção contra trojans"
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 $IF_EXTERNA --dport 666 -j TROJAN
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 666 -j TROJAN
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 4000 -j TROJAN
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 6000 -j TROJAN
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 6006 -j TROJAN
iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 16660 -j TROJAN
echo "Proteção contra worms"
iptables -A FORWARD -p tcp --dport 135 -i $IF_INTERNA -j REJECT
echo "Proteção contra syn-flood"
iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
echo "Proteção contra ping da morte"
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 2/s -j ACCEPT
echo "Proteção contra port 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 $IF_EXTERNA -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i $IF_EXTERNA -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i $IF_EXTERNA -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $IF_EXTERNA -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i $IF_EXTERNA -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i $IF_EXTERNA -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i $IF_EXTERNA -j SCANNER
echo "Libera acesso externo a determinadas portas"
iptables -A INPUT -p tcp --dport 22 -s 192.168.1.0/255.255.255.0 -i $IF_EXTERNA -j ACCEPT
#iptables -A INPUT -p tcp --dport 3306 -s 192.168.1.0/255.255.255.0 -i $IF_EXTERNA -j DROP
#iptables -A INPUT -p tcp --dport 80 -s 192.168.1.0/255.255.255.0 -i $IF_EXTERNA -j ACCEPT
##echo "Libera acesso de smtp para fora apenas para o IP XXX.XXX.XXX.XXX"
##$iptables -A FORWARD -p tcp -d ! XXX.XXX.XXX.XXX --dport 25 -j LOG --log-level 6 --log-prefix "FIREWALL: SMTP proibido: "
##$iptables -A FORWARD -p tcp -d ! XXX.XXX.XXX.XXX --dport 25 -j REJECT
echo "Ativa o mascaramento de saida"
iptables -A POSTROUTING -t nat -o $IF_EXTERNA -j MASQUERADE
echo "Direcionando tráfego da porta 80 para 3128"
iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 80 -j REDIRECT --to-port 3128
echo "Bloquear Emule"
iptables -t mangle -I FORWARD -p tcp --dport 4661 -j DROP
iptables -t mangle -I FORWARD -p tcp --dport 4662 -j DROP
iptables -t mangle -I FORWARD -p tcp --sport 4661 -j DROP
iptables -t mangle -I FORWARD -p tcp --sport 4662 -j DROP
iptables -t mangle -I FORWARD -p udp --dport 4671 -j DROP
iptables -t mangle -I FORWARD -p udp --dport 4672 -j DROP
iptables -t mangle -I FORWARD -p udp --sport 4671 -j DROP
iptables -t mangle -I FORWARD -p udp --sport 4672 -j DROP
echo "Direcionando WTS"
iptables -t nat -p tcp -I PREROUTING --dport 3389 -j DNAT --to 192.168.0.3
iptables -I FORWARD -p TCP --dport 3389 -j ACCEPT
echo "Direcionando Pop e SMTP"
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -d 0/0 -m tcp --dport 25 -p tcp -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -d 0/0 -m tcp --dport 110 -p tcp -j MASQUERADE
#iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
#iptables -A INPUT -p tcp --syn -j DROP
#iptables -A INPUT -p udp --dport 0:1029 -j DROP
echo "Firewall montado por uberdamcavaletti@yahoo.com.br"
printf '\a'
sleep 0.5
printf '\a'
sleep 0.5
printf '\a'
sleep 2