pauloorsida
(usa Debian)
Enviado em 04/02/2010 - 12:20h
internet=eth0
redelocal=eth2
mascara=192.168.10.0/24
Amigos alguém pode me ajudar com este firewall?
echo "####################ATIVANDO IPTABLES#######################"
### Passo 1: Limpando as regras ###
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F POSTROUTING -t nat
iptables -F PREROUTING -t nat
iptables -F -t nat
echo "Limpando as regras ..................................[ OK ]"
# Definindo a Politica Default das Cadeias
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
echo "Politica Default das Cadeias ........................[ OK ]"
### Passo 2: Desabilitar o trafego IP entre as placas de rede ###
echo "0" > /proc/sys/net/ipv4/ip_forward
echo "Desabilitar o trafego IP entre as placas ............[ OK ]"
# Configurando a Protecao anti-spoofing
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
# Impedimos que um atacante possa maliciosamente alterar alguma rota
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
echo "Impedimos alterar alguma rota .......................[ OK ]"
# Utilizado em diversos ataques, isso possibilita que o atacante determine o "caminho" que seu pacote vai percorrer (roteadores) ate seu destino. Junto com spoof, isso se torna muito perigoso.
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
echo "Impossibilita que o atacante determine o "caminho" ....[ OK ]"
# Protecao contra responses bogus
#echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "Protecao contra responses bogus .....................[ OK ]"
# Protecao contra ataques de syn flood (inicio da conexao TCP). Tenta conter ataques de DoS.
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo "Protecao contra ataques de syn ......................[ OK ]"
### Passo 3: Carregando os modulos do iptables ###
# Ativa modulos
# -------------------------------------------------------
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
echo "Carregando os modulos ...............................[ OK ]"
#################################################
# FIM DA Tabela FILTER
#################################################
# Protecao contra port scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 15/m -j LOG --log-prefix "FIREWALL: port scanner: "
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i $internet -j SCANNER
echo "Scaner de Portas ....................................[ OK ]"
# Libera acesso externo a determinadas portas
#Responde a PING
#iptables -A INPUT -p icmp --icmp-type 0 -i $internet -j ACCEPT
#iptables -A INPUT -p icmp --icmp-type 9 -i $internet -j ACCEPT
###Conectividade Social
iptables -t nat -A PREROUTING -p tcp -d 200.201.0.0/16 -j ACCEPT
iptables -A FORWARD -p tcp -d 200.201.0.0/16 -j ACCEPT
#DCTF
iptables -t nat -A PREOUTING -p tcp -d 200.230.57.43/16 -j ACCEPT
iptables -A FORWARD -p tcp -d 200.230.57.43/16 -j ACCEPT
##Algumas portas devem ser negadas.
iptables -A INPUT -p tcp --dport 1433 -j DROP
iptables -A INPUT -p tcp --dport 6670 -j DROP
iptables -A INPUT -p tcp --dport 6711 -j DROP
iptables -A INPUT -p tcp --dport 6712 -j DROP
iptables -A INPUT -p tcp --dport 6713 -j DROP
iptables -A INPUT -p tcp --dport 12345 -j DROP
iptables -A INPUT -p tcp --dport 12346 -j DROP
iptables -A INPUT -p tcp --dport 20034 -j DROP
iptables -A INPUT -p tcp --dport 31337 -j DROP
iptables -A INPUT -p tcp --dport 6000 -j DROP
iptables -A INPUT -p tcp --dport 5104 -j DROP
echo "Negando portas invalidas ............................[ OK ]"
#Traceroutes caindo
iptables -A INPUT -p udp --dport 33434:33523 -j DROP
iptables -A INPUT -p tcp --dport 113 -j REJECT
iptables -A INPUT -p igmp -j REJECT
iptables -A INPUT -p tcp --dport 80 -j DROP
iptables -A INPUT -p tcp --dport 443 -j REJECT
echo "Rejeitando lixo :....................................[ OK ]"
### Passo 4: Agora, vamos definir o que pode passar e o que nao ###
# Cadeia de Entrada
##ips que nao passam pelo proxy
#Presidencia
iptables -A FORWARD -p tcp -s 192.168.10.19 -j ACCEPT
#Marcio
iptables -A FORWARD -p tcp -s 192.168.10.146 -j ACCEPT
#Sandra
iptables -A FORWARD -p tcp -s 192.168.10.113 -j ACCEPT
#Elza
iptables -A FORWARD -p tcp -s 192.168.10.104 -j ACCEPT
#iptables -A FORWARD -p tcp -s 192.168.10.131 -j ACCEPT
#iptables -A FORWARD -p tcp -s 192.168.10.69 -j ACCEPT
#iptables -A FORWARD -p tcp -s 192.168.10.38 -j ACCEPT
#iptables -A FORWARD -p tcp -s 192.168.10.30 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.110 -j ACCEPT
#Luciane
iptables -A FORWARD -p tcp -s 192.168.10.107 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.146 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.112 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.170 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.86 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.200 -j ACCEPT
echo "Computadores que nao passam pelo proxy...............[ OK ]"
#Bloquear navegacao e liberar o outlook
#RONALDO
#iptables -A INPUT -m mac --mac-source 00:21:85:8f:fb:f4 -p tcp --dport 25 -j ACCEPT
#iptables -A INPUT -m mac --mac-source 00:21:85:8f:fb:f4 -p tcp --dport 110 -j ACCEPT
#iptables -A INPUT -m mac --mac-source 00:01:6c:18:10:00 -j DROP
#iptables -A FORWARD -m mac --mac-source 00:01:6c:18:10:00 -p tcp --dport 1863 -j DROP
#iptables -A FORWARD -m mac --mac-source 00:21:85:8f:fb:f4 -j DROP
#ips q podem acessar msn
#Dir Comercial
#iptables -A FORWARD -p tcp -s 192.168.10.38 --dport 1863 -j ACCEPT
#Presidencia
iptables -A FORWARD -p tcp -s 192.168.10.19 --dport 1863 -j ACCEPT
#Dir ADMINISTRAIVA
iptables -A FORWARD -p tcp -s 192.168.10.30 --dport 1863 -j ACCEPT
echo "Regras msn...........................................[ OK ]"
#Ch Gabinete
#iptables -A FORWARD -p tcp -s 192.168.10.45 --dport 1863 -j ACCEPT
#Paulo
iptables -A FORWARD -p tcp -s 192.168.10.86 --dport 1863 -j ACCEPT
#Porta Samba
iptables -A INPUT -p tcp --dport 445 -j ACCEPT
iptables -A INPUT -p tcp --dport 137 -j ACCEPT
iptables -A INPUT -p tcp --dport 138 -j ACCEPT
iptables -A INPUT -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -p udp --dport 137 -j ACCEPT
iptables -A INPUT -p udp --dport 138 -j ACCEPT
iptables -A INPUT -p udp --dport 139 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p udp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.10.0/24 -d 192.168.10.199/24 -destination-port mysql -syn -j ACCEPT
#PORTA DHCP
iptables -A INPUT -p udp --dport 67 -j ACCEPT
iptables -A INPUT -p udp --dport 68 -j ACCEPT
iptables -A FORWARD -p udp --dport 67 -j ACCEPT
iptables -A FORWARD -p udp --dport 68 -j ACCEPT
# porta para contabilidade
#DCTF
iptables -A FORWARD -p tcp --dport 3456 -j ACCEPT
#DPI
iptables -A FORWARD -p tcp --dport 24001 -j ACCEPT
#ted
iptables -A FORWARD -p tcp --dport 8017 -j ACCEPT
echo "Regras contabilidade.................................[ OK ]"
#portas para departamento pessoal
#sefip
iptables -A FORWARD -p tcp --dport 2004 -j ACCEPT
iptables -A FORWARD -p tcp --dport 2631 -j ACCEPT
iptables -A FORWARD -p tcp --dport 1494 -j ACCEPT
iptables -A FORWARD -p tcp --dport 5017 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.113 --dport 9090 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.10.69 --dport 9090 -j ACCEPT
echo "Regras DP ...........................................[ OK ]"
# PORTA 3128 - ACEITA PARA A REDE LOCAL
iptables -A FORWARD -i $redelocal -p tcp --dport 3128 -j ACCEPT
iptables -A FORWARD -i $redelocal -p tcp --dport 8080 -j ACCEPT
# Redireciona porta 80 para 3128 (squid)
iptables -t nat -A PREROUTING -i $redelocal -p tcp --dport 80 -j REDIRECT --to-port 3128
# Dra Nara
iptables -t nat -A PREROUTING -i $internet -s \! 192.168.10.38 -p tcp -m multiport --dport 80,443 -j REDIRECT --to-ports 3128
#MARCIO
iptables -t nat -A PREROUTING -i $internet -s \! 192.168.10.146 -p tcp -m multiport --dport 80,443 -j REDIRECT --to-ports 3128
#SANDRA DP
iptables -t nat -A PREROUTING -i $internet -s \! 192.168.10.113 -p tcp -m multiport --dport 80,443 -j REDIRECT --to-ports 3128
#ELZA CONTABILIDADE
iptables -t nat -A PREROUTING -i $internet -s \! 192.168.10.104 -p tcp -m multiport --dport 80,1723,25,110,500,4500,443 -j REDIRECT --to-ports 3128
iptables -t nat -A PREROUTING -i $internet -s \! 192.168.10.170 -p tcp -m multiport --dport 80,1723,25,110,500,3500,443 -j REDIRECT --to-ports 3128
# OUTLOOK
iptables -A FORWARD -p tcp --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp --dport 25 -j ACCEPT
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# identd
iptables -A INPUT -p tcp --dport 113 -j ACCEPT
iptables -A INPUT -p udp --dport 113 -j ACCEPT
# https
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p udp --dport 443 -j ACCEPT
iptables -A FORWARD -i $redelocal -p tcp --dport 443 -j ACCEPT
# PORTA 21 - ACEITA PARA A REDE LOCAL
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A FORWARD -p tcp --dport 21 -j ACCEPT
# PORTA 22 - ACEITA PARA A REDE INTERNET
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A FORWARD -p tcp --dport 22 -j ACCEPT
###vpn criar estas regras para todas vpns
iptables -A INPUT -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -p tcp --dport 50 -j ACCEPT
iptables -A INPUT -p tcp --dport 51 -j ACCEPT
iptables -A FORWARD -p tcp --dport 1723 -j ACCEPT
iptables -A INPUT -p tcp --dport 5001 -j ACCEPT
iptables -A FORWARD -p tcp --dport 5001 -j ACCEPT
iptables -A INPUT -p udp --dport 5001 -j ACCEPT
iptables -A FORWARD -p udp --dport 5001 -j ACCEPT
iptables -I FORWARD -i tun0 -j ACCEPT
iptables -I FORWARD -o tun0 -j ACCEPT
#bloqueia qualquer tentativa de nova conexao de fora para esta maquina
iptables -A INPUT -i $internet -m state --state ! ESTABLISHED,RELATED -j LOG --log-level 6 --log-prefix "FIREWALL entrada "
iptables -A INPUT -i $internet -m state --state ! ESTABLISHED,RELATED -j DROP
#no iptables, temos de dizer quais sockets sao validos em uma conexao
iptables -A INPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Cadeia de Entrada ...................................[ OK ]"
################################
# Cadeia de Reenvio (FORWARD).
# Primeiro, ativar o mascaramento (nat).
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o $internet -j MASQUERADE
echo "Ativando o mascaramento .............................[ OK ]"
# Agora dizemos quem e o que podem acessar externamente
# O controle do acesso a rede externa e feito na cadeia "FORWARD"
iptables -A FORWARD -i $internet -j ACCEPT
iptables -A FORWARD -o $internet -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Ativando o acesso ftp.. .............................[ OK ]"
###################
###BLOQUEANDO TODAS AS SAIDAS E PORTAS
#iptables -A INPUT -p all -j DROP
#iptables -A FORWARD -p all -j DROP
echo "Rejeitando saida e entrada ..........................[ OK ]"
########################
# No iptables, temos de dizer quais sockets sao validos em uma conexao
iptables -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Quais sockets sao validos ...........................[ OK ]"
#################################################
# Tabela FILTER
#################################################
# Protecao contra tronjans
# -------------------------------------------------------
iptables -A INPUT -p TCP -i $internet --dport 666 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 4000 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 6000 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 6006 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 16660 -j DROP
# Protecao contra trinoo
# -------------------------------------------------------
iptables -A INPUT -p TCP -i $internet --dport 27444 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 27665 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 31335 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 34555 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 35555 -j DROP
echo "Protecao contra trinoo ............................. [ OK ]"
# Protecao contra acesso externo squid
iptables -A INPUT -p TCP -i $internet --dport 3128 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 8080 -j DROP
echo "Protecao contra squid externo....................... [ OK ]"
# Protecao contra telnet
iptables -A INPUT -p TCP -i $internet --dport telnet -j DROP
echo "Protecao contra telnet ....................... [ OK ]"
# Dropa pacotes TCP indesejaveis
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
# Dropa pacotes mal formados
iptables -A INPUT -i $internet -m unclean -j DROP
# Protecao contra worms
iptables -A FORWARD -p tcp --dport 135 -i $internet -j REJECT
# Protecao contra syn-flood
iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
# Protecao contra ping da morte
#iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
#Allow ALL other forwarding going out
iptables -A FORWARD -o $internet -i $redelocal -j ACCEPT
echo "Caregado tabela filter ............................ [ OK ]"
# Finalmente: Habilitando o trafego IP, entre as Interfaces de rede
echo "1" > /proc/sys/net/ipv4/ip_forward
#echo "Habilitar o trafego IP entre as placas: .............[ OK ]"
iptables -t nat -A POSTROUTING -j MASQUERADE
O que esta de errado neste firewall, fica aparecendo erro(113) no route to host