Lucas Peregrino
(usa Debian)
Enviado em 07/10/2009 - 13:30h
bom gente tenho servdor um ubuntu 9.04 que esta literalmente funcionado perfeito trabalho com squid + dansguardian para fazer a sensura do sites agora e tenho minha regras que estao funcionando blz mais o problema so um programa da receita nao trasmite Dapi-SEF ou se eu salva declaração no computador e pedir pra transferir no TED-SEF nao nao vai configuro perfeitamente o proxy no programa mais ele nao enchega o servido vo posta aqui o meu firewall pois nao se se e nele q esta o erro muito obrigado se alguem poder me ajudar abraço Lucas Peregrino
echo " * Inciando Firewall [ OK ] "
echo " * Limpado Nat [ OK ] "
##Limpado Nat
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
echo " * Definindo a Polica Padrao [ OK ] "
## Define a politica padrao
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
echo " * Modulos [ OK ]"
##Modulos
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
echo " * Ativando o Roteamento Dinamico [ OK ] "
##ativa o roteamento dinamico
echo 1 > /proc/sys/net/ipv4/ip_forward
echo " * Libera Internet para toda Rede [ OK ] "
##Libera Internet para toda Rede
iptables -A FORWARD -i eth1 -j ACCEPT
echo " * Mascaramento de rede para acesso externo [ OK ] "
#Mascaramento de rede para acesso externo
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
echo " * Redirecionando Porta 80 e 443 para 3128 [ OK ] "
##Redirencionar portas 80 e 443 para 3128
iptables -t nat -A PREROUTING -p tcp -m multiport -s 192.168.2.0/24 --dport 80,443 -j REDIRECT --to-ports 3128
echo " * Liberando o Squid 3129 e Dansguardian 3128 [ OK ] "
##Liberando o Squid 3129 e Dansguardian 3128
iptables -A INPUT -p tcp -m multiport -s 192.168.2.0/24 --dport 3128,3129 -j ACCEPT
echo " * Fechando Localhost [ OK ] "
##Fechando LocalHost:
iptables -A INPUT -m tcp -p tcp -s ! 127.0.0.1 --dport 3129 -j DROP
echo " * Libera Rede Interna [ OK ] "
##Libera a conexao para a rede interna
iptables -t nat -A POSTROUTING -s 192.168.2.0/255.255.255.0 -j MASQUERADE
echo " * Regras de INPUT, FORWARD e OUTPUT [ OK ] "
##Regras de INPUT, FORWARD e OUTPUT
iptables -A INPUT -s 192.168.2.0/24 -j ACCEPT
iptables -A FORWARD -s 192.168.2.0/24 -j ACCEPT
iptables -A OUTPUT -s 192.168.2.0/24 -j ACCEPT
echo " * Liberando FORWARD para porta 3128 - proxy [ OK ] "
##Liberando FORWARD para porta 3128 - proxy
iptables -A FORWARD -s 192.168.2.0/24 -i eth1 -p tcp --dport 3128 -j ACCEPT
echo " * Liberando FORWARD para porta 80 - web [ OK ] "
##Liberando forward para porta 80 - web
iptables -A FORWARD -s 192.168.2.0/24 -i eht1 -p tcp --dport 80 -j ACCEPT
echo " * Liberando FORWARD para porta 443 - web [ OK ] "
##Liberando FORWARD para porta 443 - web
iptables -A FORWARD -s 192.168.2.0/24 -i eth1 -p tcp --dport 443 -j ACCEPT
echo " * Liberando Pacotes de Retorno da internet [ OK ] "
## ACCEPT (libera) pacotes de retorno da internet
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 " * DNS Liberando [ OK ] "
## DNS - Libera a resolucao de nomes
iptables -A INPUT -s 192.168.2.0/24 -p udp --sport 53 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 53 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.2.0/24 --dport 53 -j ACCEPT
echo " * Travando o msn e Liberando o acesso por Maquina [ OK ] "
## Libera as maquinas na rede que pode ter msn
iptables -N MSN
iptables -A FORWARD -p tcp --dport 1863 -j MSN
iptables -A MSN -s 192.168.2.0/24 -j ACCEPT
iptables -A FORWARD -s 192.168.2.0/24 -p tcp --dport 1863 -j ACCEPT
iptables -A FORWARD -s 192.168.2.0/24 -d 65.54.179.192 -j ACCEPT
iptables -A INPUT -s 192.168.2.0/24 -p tcp --dport 1863 -j ACCEPT
iptables -A INPUT -s 192.168.2.0/24 -p tcp --sport 1863 -j ACCEPT
iptables -A INPUT -s 192.168.2.0/24 -p udp --dport 1863 -j ACCEPT
iptables -A INPUT -s 192.168.2.0/24 -p udp --sport 1863 -j ACCEPT
echo " * Liberando Mysql [ OK ] "
## Libera o mysql
iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 3310 -j ACCEPT
echo " * Terminal Server [ OK ] "
## Terminal Server
iptables -t nat -A PREROUTING -p tcp --dport 3389 -i eth1 -j DNAT --to 192.168.2.253:3389
echo " * Liberando SSH [ OK ] "
## Liberando SSH (porta 6689 e 22 )
iptables -N SSH
iptables -A INPUT -p tcp --dport 6689 -j SSH
iptables -A SSH -s 192.168.2.0/24 -j ACCEPT
iptables -A SSH -m limit --limit 10/s -j LOG
iptables -A SSH -j DROP
iptables -A INPUT -p tcp --dport 6689 -s 192.168.2.0/24 -j ACCEPT
iptables -A INPUT -s 192.168.2.0/24 -p tcp --dport 6689 -j ACCEPT
echo " * Liberando SSH Externo [ OK ]"
## Liberando SSH Externo
iptables -A INPUT -p tcp --dport 6689 -i eth1 -j ACCEPT
echo " * Liberando SSH em Servidor Web [ OK ] "
## Liberando SSH em Servidor web
iptables -A INPUT -p tcp --dport 80 -i eth1 -j ACCEPT
echo " * Liberando Webmin [ OK ] "
## Liberando Webmin (porta 332)
iptables -A INPUT -s 192.168.2.0/24 -p tcp --dport 332 -j ACCEPT
echo " * Liberando Acesso ao Webmin Externo [ OK ] "
## Liberando acesso Webmin externo
iptables -A INPUT -i eth1 -p tcp --dport 332 -j ACCEPT
echo " * Liberando BRADESCO [ OK ] "
## BRADESCO
iptables -A FORWARD -s 192.168.2.0/24 -d 200.155.84.15 -p tcp -j ACCEPT
iptables -A FORWARD -s 192.168.2.0/24 -d 200.155.84.69 -p tcp -j ACCEPT
echo " * PHP [ OK ] "
##PHP
iptables -A INPUT -p tcp --dport 5432 -j DROP
echo " * Email [ OK ] "
##Email
iptables -t filter -A OUTPUT -p tcp --dport 110 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 25 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 0/0 -d 0/0 --dport 25 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 0/0 -d 0/0 --dport 110 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 995 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 465 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 0/0 -d 0/0 --dport 465 -j ACCEPT
iptables -t filter -A FORWARD -p tcp -s 0/0 -d 0/0 --dport 995 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.2.0/24 -d 201.7.95.96 --dport 53 -j ACCEPT
iptables -A FORWARD -p tcp -s 201.7.95.96 --sport 53 -d 192.168.2.0/24 -j ACCEPT
echo " * Liberando SQL e Mysql [ OK ] "
## Libera SQL e Mysql
iptables -N SQL
iptables -A FORWARD -p tcp --dport 1433 -j SQL
iptables -A INPUT -p tcp --dport 1433 -j SQL
iptables -A INPUT -p udp --dport 5432 -j SQL
iptables -A SQL -s 0/0 -j DROP
iptables -A INPUT -p tcp -i eth0 --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp -i eth0 --dport 3310 -j ACCEPT
echo " * DAPI-SEF [ OK ] "
##Dapi-sef
iptables -A FORWARD -p tcp --dport 3050 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.2.0/24 --dport 3050 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.2.0/24 --dport 3050 -j ACCEPT
echo " * TEDSEF [ OK ] "
##Liberando TEDSEF
iptables -t nat -A PREROUTING -s 192.168.2.0/24 -p tcp -d 200.199.34.41 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.199.34.41 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.1.0/24 -d 200.199.34.41 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.199.34.41 --dport 8017 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.199.34.41 --sport 8017 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.199.34.41 --dport 80 -j ACCEPT
echo " * Sintegra [ OK ] "
##Liberando Sintegra
iptables -t filter -A FORWARD -p tcp -s 192.168.2.0/24 --dport 8017 -j ACCEPT
echo " * ReceitaNet [ OK ] "
##ReceitaNET
iptables -t nat -A PREROUTING -s 192.168.2.0/24 -p tcp -d 161.148.185.130 -j ACCEPT
iptables -A FORWARD -s 192.168.2.0/24 -d 161.148.185.130 -j ACCEPT
iptables -A FORWARD -p tcp -s 192.168.2.0/24 -d 161.148.185.130 --dport 3456 -j ACCEPT
echo " * Liberando Acesso Nota Fiscal Eletronica [ OK ] "
## Liberando acesso a NFE (Nota fiscal Eletronica)
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.189.133.249/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.189.133.249 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.189.133.249 --dport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.189.133.249 --sport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.189.133.249 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.189.133.247/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.189.133.247 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.189.133.247 --dport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.189.133.247 --sport 4199:5656 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.189.133.247 --dport 80 -j ACCEPT
echo " * Sicoob [ OK ] "
##Programa Boleto sicoob
iptables -t nat -A PREROUTING -s 192.168.2.0/24 -p tcp -d 200.252.146.0/24 --dport 80 -j RETURN
echo " * Sefip / CNS [ OK ] "
##Sefip / CNS
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
echo " * Caixa Economica [ OK ] "
## Caixa Economica
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.174.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.174.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.0/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.173.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.173.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.173.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.173.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.173.0/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.166.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.166.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.166.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.166.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.166.0/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.162.0/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.162.0/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.162.0/24 --dport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.162.0/24 --sport 1024:65535 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.162.0/24 --dport 80 -j ACCEPT
echo " * Sefip [ OK ] "
##Sefip
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.173.68/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.173.68/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.173.68/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.173.68/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.166.200/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.166.200/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.166.200/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.166.200/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.174.204/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.174.204/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.204/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.204/24 --dport 80 -j ACCEPT
iptables -t nat -I PREROUTING -s 192.168.2.0/24 -p tcp -d 200.201.174.207/24 --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -d ! 200.201.174.207/24 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.207/24 -j ACCEPT
iptables -I FORWARD -p tcp -s 192.168.2.0/24 -d 200.201.174.207/24 --dport 80 -j ACCEPT
echo " * Liberando Conectividade Social [ OK ] "
## Liberar Conectividade Social para todos
# liberando acesso a toda a rede 200.201 e pode liberar sites alem da Caixa.
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
echo " * Conexao via rede interna com destino ao Web Server [ OK ] "
## Aceita conexoes vindas da rede interna com destino ao web server
iptables -A INPUT -p tcp -s 192.168.2.0/24 --syn --dport 80 -j ACCEPT
echo " * Separa ICMP, TCP E UDP [ OK ] "
##Create separate chains for ICMP, TCP and UDP to traverse
iptables -N allowed
iptables -N tcp_packets
iptables -N udp_packets
iptables -N icmp_packets
echo " * Abre a faixa de endereco da rede local [ OK ] "
## Abre para uma faixa de endereco da rede local
sudo iptables -A INPUT -p tcp --syn -s 192.168.2.0/255.255.255.0 -j ACCEPT
echo " * Abrindo Porta de Conexao a Internet [ OK ] "
## Abre uma porta (inclusive para a Internet)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT # http
iptables -A INPUT -p tcp --dport 443 -j ACCEPT # https
iptables -A INPUT -p tcp --dport 21 -j ACCEPT # Ftp
iptables -A INPUT -p tcp --dport 563 -j ACCEPT # snews
iptables -A INPUT -p tcp --dport 70 -j ACCEPT # gopher
iptables -A INPUT -p tcp --dport 210 -j ACCEPT # wais
iptables -A INPUT -p tcp --dport 280 -j ACCEPT # http-mgmt
iptables -A INPUT -p tcp --dport 488 -j ACCEPT # gss-http
iptables -A INPUT -p tcp --dport 591 -j ACCEPT # filemaker
iptables -A INPUT -p tcp --dport 777 -j ACCEPT # multiling http
iptables -A INPUT -p tcp --dport 631 -j ACCEPT # cups
iptables -A INPUT -p tcp --dport 873 -j ACCEPT # rsync
iptables -A INPUT -p tcp --dport 901 -j ACCEPT # swat
iptables -A INPUT -p tcp --dport 3129 -j ACCEPT # Squid
iptables -A INPUT -p tcp --dport 465 -j ACCEPT # Email
iptables -A INPUT -p tcp --dport 25 -j ACCEPT # Email
iptables -A INPUT -p tcp --dport 110 -j ACCEPT # Email
iptables -A INPUT -p tcp --dport 995 -j ACCEPT # Email
iptables -A INPUT -p tcp --dport 332 -j ACCEPT # Webmin
iptables -A INPUT -p tcp --dport 6689 -j ACCEPT # SSH
iptables -A INPUT -p tcp --dport 1863 -j ACCEPT # Msn
iptables -A INPUT -p tcp --dport 7001 -j ACCEPT # Msn
iptables -A INPUT -p tcp --dport 6901 -j ACCEPT # Msn
iptables -A INPUT -p tcp --dport 6891 -j ACCEPT # Msn
iptables -A INPUT -p udp --dport 1863 -j ACCEPT # Msn
iptables -A INPUT -p udp --dport 6901 -j ACCEPT # Msn
iptables -A INPUT -p udp --dport 7001 -j ACCEPT # Msn
iptables -A INPUT -p udp --dport 6901 -j ACCEPT # Msn
iptables -A INPUT -p udp --dport 6891 -j ACCEPT # Msn
iptables -A INPUT -p tcp --dport 1433 -j ACCEPT # SQL
iptables -A INPUT -p tcp --dport 4199 -j ACCEPT # NFe
iptables -A INPUT -p tcp --dport 5959 -j ACCEPT # NFe
iptables -A INPUT -p tcp --dport 3389 -j ACCEPT # Terminal Server
iptables -A INPUT -p tcp --dport 1080 -j ACCEPT # Socks
iptables -A INPUT -p tcp --dport 2006 -j ACCEPT # COBCaixa
iptables -A INPUT -p tcp --dport 1024 -j ACCEPT # Caixa
iptables -A INPUT -p tcp --dport 65535 -j ACCEPT # Caixa
iptables -A INPUT -p tcp --dport 3456 -j ACCEPT # Receitanet
iptables -A INPUT -p tcp --dport 5900 -j ACCEPT
iptables -A INPUT -p tcp --dport 5800 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT # Mysql
iptables -A INPUT -p tcp --dport 3310 -j ACCEPT # Mysql
iptables -A INPUT -p tcp --dport 3050 -j ACCEPT # Dafi-Sef
iptables -A INPUT -p tcp --dport 8017 -j ACCEPT # TED-Sef / DIEF
iptables -A INPUT -p tcp --dport 3456 -j ACCEPT # Dacon
iptables -A INPUT -p tcp --dport 3007 -j ACCEPT # Raisnet
echo " * Nat ao contrario [ OK ] "
## Desabilita o suporte a source routed packets
# Esta recurso funciona como um NAT ao contrario, que em certas circunstancias pode permitir que alguem de fora envie pacotes para micros dentro da rede localecho "0" >/proc/sys/net/ipv4/conf/eth0/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/eth0/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/eth1/accept_source_route
echo " * Fechando as Portas do Samba para internet [ OK ] "
## Fechando as portas do samba caso fique de cara para a internet.
iptables -A INPUT -p tcp -i eth1 --syn --dport 139 -j DROP
iptables -A INPUT -p tcp -i eth1 --syn --dport 138 -j DROP
echo " * Bloqueio de NetBios (Compartilhamento de Arquivos do Servidor) [ OK ] "
#Bloqueio de NetBios
iptables -t nat -A PREROUTING -p tcp --dport 445 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 135 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 137 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 138 -j DROP
iptables -t nat -A PREROUTING -p tcp --dport 139 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 445 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 135 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 137 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 138 -j DROP
iptables -t nat -A PREROUTING -p udp --dport 139 -j DROP
echo " * Bloqueio de Multicast [ OK ] "
##Bloqueio de Multicast
iptables -A INPUT -s 224.0.0.0/8 -d 0/0 -j DROP
iptables -A INPUT -s 0/0 -d 224.0.0.0/8 -j DROP
echo " * Bloqueio de Black Orifice [ OK ] "
##Bloqueio de Black Orifice
iptables -A INPUT -p tcp -i eth1 --dport 12345:12345 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 12345:12345 -j DROP
echo " * Bloqueio acesso X server [ OK ] "
##Bloqueio acesso X server
iptables -A INPUT -p tcp -i eth1 --dport 5999:6003 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 5999:6003 -j DROP
iptables -A INPUT -p tcp -i eth1 --dport 7100 -j DROP
echo " * Bloqueio de NetBus [ OK ] "
##Bloqueio de NetBus
iptables -A INPUT -p tcp -i eth1 --dport 31337 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 31337 -j DROP
echo " * Bloqueio U89 - Software burlador de proxy [ OK ] "
##Bloqueando U89 - software burlador de proxy
iptables -A FORWARD -p tcp --dport 9666 -j DROP
echo " * Bloqueio a IP Spoofing [ OK ] "
##Bloqueio a IP Spoofing
iptables -N syn-flood
iptables -A INPUT -i eth1 -p tcp --syn -j syn-flood
iptables -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN
iptables -A syn-flood -j DROP
echo " * Protecao Contra IP spoofing [ OK ] "
##Protecao Contra IP Spoofing
iptables -A INPUT -s 10.0.0.0/8 -i eth1 -j DROP
iptables -A INPUT -s 127.0.0.0/8 -i eth1 -j DROP
iptables -A INPUT -s 172.16.0.0/16 -i eth1 -j DROP
iptables -A INPUT -s 192.168.0.0/24 -i eth1 -j DROP
echo " * Protecao contra ICMP Broadcasting [ OK ] "
##Protecao contra ICMP Broadcasting
echo "0" > /proc/sys/net/ipv4/conf/eth1/accept_redirects
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
iptables -A INPUT -p icmp -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -j DROP
echo " * Protecao contra Synflood [ OK ] "
##Protege contra synflood
echo "2048" > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p tcp --syn -j DROP
echo " * Protecao contra Ping od death, ataques DoS, [ OK ] "
##Protecao diversas contra portscanners, ping of death, ataques DoS, etc.
#INPUT
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -m state --state RELATED -j ACCEPT
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A INPUT -m state --state INVALID -j REJECT
iptables -A INPUT -p tcp -i eth1 --dport 1023:65535 -j ACCEPT
iptables -A INPUT -p udp -i eth1 --dport 1023:65535 -j ACCEPT
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p udp -s 0/0 -i eth1 --dport 33435:33525 -j REJECT
iptables -A INPUT -p icmp -i eth1 -j DROP
iptables -A INPUT -p icmp --icmp-type echo-reply -s 0/0 -i eth1 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type destination-unreachable -s 0/0 -i eth1 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type time-exceeded -s 0/0 -i eth1 -j ACCEPT
iptables -A OUTPUT -p icmp -o eth1 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -s 0.0.0.0/0 -p icmp -j DROP
iptables -A INPUT -i eth1 -p tcp --syn -j DROP
#FORWARD
iptables -A FORWARD -p tcp -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp --dport 135 -i eth1 -j REJECT
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD --protocol tcp --tcp-flags ALL SYN,ACK -j DROP
#VALID
iptables -N VALID_CHECK
iptables -A VALID_CHECK -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL ALL -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL FIN -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
iptables -A VALID_CHECK -p tcp --tcp-flags ALL NONE -j DROP
echo " * Protecao contra port scanners [ OK ] "
##Protecao contra port scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 5/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 eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i eth1 -j SCANNER
echo " * Protecao contra tronjans [ OK ] "
##Protecao contra tronjans
iptables -N TROJAN
iptables -A TROJAN -m limit --limit 5/m -j LOG --log-level 6 --log-prefix "FIREWALL: trojan: "
iptables -A TROJAN -j DROP
iptables -A INPUT -p tcp -i eth1 --dport 666 -j TROJAN
iptables -A INPUT -p tcp -i eth1 --dport 666 -j TROJAN
iptables -A INPUT -p tcp -i eth1 --dport 4000 -j TROJAN
iptables -A INPUT -p tcp -i eth1 --dport 6000 -j TROJAN
iptables -A INPUT -p tcp -i eth1 --dport 6006 -j TROJAN
iptables -A INPUT -p tcp -i eth1 --dport 16660 -j TROJAN
echo " * Protecao contra trinoo [ OK ] "
##Protecao contra trinoo
iptables -N TRINOO
iptables -A TRINOO -m limit --limit 5/m -j LOG --log-level 6 --log-prefix "FIREWALL: trinoo: "
iptables -A TRINOO -j DROP
iptables -A INPUT -p tcp -i eth1 --dport 1524 -j TRINOO
iptables -A INPUT -p tcp -i eth1 --dport 27444 -j TRINOO
iptables -A INPUT -p tcp -i eth1 --dport 27665 -j TRINOO
iptables -A INPUT -p tcp -i eth1 --dport 31335 -j TRINOO
iptables -A INPUT -p tcp -i eth1 --dport 34555 -j TRINOO
iptables -A INPUT -p tcp -i eth1 --dport 35555 -j TRINOO
echo " * Loga tentativa de acesso a determinadas portas [ OK ] "
##Loga tentativa de acesso a determinadas portas
iptables -A INPUT -p tcp --dport 21 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: ftp: "
iptables -A INPUT -p tcp --dport 23 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: telnet: "
iptables -A INPUT -p tcp --dport 25 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: smtp: "
iptables -A INPUT -p tcp --dport 80 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: http: "
iptables -A INPUT -p tcp --dport 110 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: pop3: "
iptables -A INPUT -p udp --dport 111 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: rpc: "
iptables -A INPUT -p tcp --dport 113 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: identd: "
iptables -A INPUT -p tcp --dport 137:139 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: samba: "
iptables -A INPUT -p udp --dport 137:139 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: samba: "
iptables -A INPUT -p tcp --dport 161:162 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: snmp: "
iptables -A INPUT -p tcp --dport 6667:6668 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: irc: "
iptables -A INPUT -p tcp --dport 3128 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: squid: "
echo " * Rejectando Ident Requeridos [ OK ] "
##Rejectando Ident Requeridos
iptables -A INPUT -p tcp -i eth1 --dport 113 -j REJECT
iptables -A INPUT -p udp -i eth1 --dport 113 -j REJECT
echo " * Interface Loopback [ OK ] "
## Abre para a interface de loopback.
# Esta regra e essencial para o KDE e outros programas graficos funcionarem adequadamente.
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i ! lo -s 127.0.0.0/255.0.0.0 -j DROP
echo " * Ignora Pings [ OK ] "
## Ignora pings
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo " * Fechando Todas Portas TCP [ OK ] "
## Esta regra e coracao do firewall ,
iptables -A INPUT -p tcp ! --syn -j DROP
echo " * Firewall Ativo 100% [ OK ] "