gilbertoateu
(usa Ubuntu)
Enviado em 07/10/2012 - 18:55h
segue abaixo meu squid.conf e script de firewall
# Configuracoes gerais
http_port 3128 transparent
visible_hostname LINUX
hierarchy_stoplist cgi-bin?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
cache_mem 350 MB
maximum_object_size_in_memory 100 KB
maximum_object_size 15360 KB
minimum_object_size 0 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_replacement_policy lru
memory_replacement_policy lru
logformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
access_log /var/log/squid/access.log squid
cache_swap_low 90
cache_swap_high 95
cache_dir ufs /var/spool/squid 3000 16 256
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_swap_log /var/spool/squid/swap.log
cache_mgr vaini@itelefonica.com.br
error_directory /usr/share/squid/errors/Portuguese
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
# Definicao das ACLs
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563 # snews
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 563 # https, snews
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 407 # msn
acl Safe_ports port 25 # smtp
acl Safe_ports port 110 # pop
acl purge method PURGE
acl CONNECT method CONNECT
# Sites Bloqueados/Liberados
acl macs_liberados arp "/etc/squid/macs_liberados"
acl sites_liberados url_regex -i "/etc/squid/sites_liberados"
# Ativando as ACLs Padrao
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny to_localhost
# Ativando as ACLs Personalizadas
http_access allow macs_liberados
http_access allow sites_liberados
http_access deny all
scrip de firewall
############################################################
#!/bin/sh
#### carregar modulos
modprobe ip_tables
modprobe ipt_MASQUERADE
modprobe ipt_REDIRECT
modprobe ipt_tos
modprobe iptable_filter
modprobe iptable_mangle
modprobe ipt_REJECT
modprobe iptable_nat
modprobe ip_nat_ftp
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ipt_state
modprobe ipt_mark
#modprobe ipt_LOG
modprobe ipt_limit
modprobe ipt_owner
modprobe ipt_multiport
##### limpa todas as regras
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
echo "Limpando as regras.............................[OK]"
##### define a politica padrao do Firewall
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
echo "Politica padrao definida.......................[OK]"
##### libera entrada para servicos locais do firewall
iptables -A INPUT -i lo -j ACCEPT #libera trafego local no firewall
iptables -A INPUT -p tcp -i eth1 --dport 3128 -j ACCEPT #libera Squid
iptables -A INPUT -p tcp --dport 53 -j ACCEPT #libera DNS
iptables -A INPUT -p tcp -i eth1 --dport ssh -j ACCEPT #Libera SSH para rede interna
#####Libera o acesso via SSH para rede externa e Limita o numero de 4 tentativas de acesso a cada minuto
iptables -I INPUT -p tcp --dport ssh -i ppp0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
echo "Acesso SSH permitido...........................[OK]"
#####Liberando acesso interno da rede
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT
echo "Acesso interno da rede liberado................[OK]"
##### Libera Ping
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -j ACCEPT
echo "Ping liberado..................................[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 "Conectividade social liberada..................[OK]"
##### SERVIDORES
# Apache - Servidor Web
#$iptables -A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
# Apache TomCat - Servidor Web
#$iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
# ProFTP - Servidor FTP
iptables -I INPUT -p tcp --dport 2121 -j ACCEPT
iptables -I INPUT -p tcp --dport 20 -j ACCEPT
iptables -I INPUT -p udp --dport 2121 -j ACCEPT
iptables -I INPUT -p udp --dport 20 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dports 49152:49162 -j ACCEPT
iptables -I FORWARD -p tcp --dport 2121 -j ACCEPT
echo "Servidor PROFTPD ativado.......................[OK]"
# Postfix - Servidor de E-mail
#$iptables -A INPUT -i $INTERNA -p tcp -m multiport --dports 25,110 -j ACCEPT
#$iptables -A INPUT -i $INTERNA -p tcp -m multiport --dports 465,995 -j ACCEPT
#$iptables -A INPUT -i $INTERNA -p tcp --sport 25 -j ACCEPT
# PostgreSQL - Servidor Postgresql
#$iptables -A INPUT -i $INTERNA -p tcp --dport 5432 -j ACCEPT
echo "Acesso a servidores ativado....................[OK]"
##### PROTOCOLOS E SERVICOS
# AIM
#$iptables -A INPUT -i $EXTERNA -p tcp --sport 5190 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p tcp --sport 5190 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p tcp --dport 5190 -j ACCEPT
# WEBMIN
iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
# DNS - Servico de Nomes de Dominios
iptables -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A FORWARD -p tcp --dport 53 -j ACCEPT
iptables -A FORWARD -p udp --dport 53 -j ACCEPT
# 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]"
# Agora dizemos quem e o que podem acessar externamente
# O controle do acesso a rede externa e feito na cadeia "FORWARD"
iptables -A FORWARD -o ppp0 -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Ativando o acesso ftp..........................[OK]"
# FTP - Protocolo de Transferência de Arquivo
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A FORWARD -p tcp --dport 21 -j ACCEPT
# HTTP - Protocolo de Transferência de Hypertext
iptables -A INPUT -i ppp0 -p tcp -m multiport --sports 80,8080 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp -m multiport --sports 80,8080 -j ACCEPT
iptables -A FORWARD -o ppp0 -p tcp -m multiport --dports 80,8080 -j ACCEPT
# HTTPS - Protocolo de Transferência de Hypertext Seguro
iptables -A INPUT -i ppp0 -p tcp --sport 443 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp --sport 443 -j ACCEPT
iptables -A FORWARD -o ppp0 -p tcp --dport 443 -j ACCEPT
# IAPP - Protocolo de Ponto de Acesso
#$iptables -A INPUT -i $INTERNA -p udp --sport 2313 -j ACCEPT
# IPP - Protocolo de Impressão na Internet
iptables -A INPUT -i eth1 -p tcp --dport 631 -j ACCEPT
iptables -A INPUT -i eth1 -p udp -m multiport --dports 138,631 -j ACCEPT
# IRC - Internet Relay Chat
#iptables -A INPUT -i eth0 -p tcp --sport 6667 -j ACCEPT
#iptables -A FORWARD -i eth0 -p tcp --sport 6667 -j ACCEPT
#iptables -A FORWARD -o eth0 -p tcp --dport 6667 -j ACCEPT
# Microsoft-DS - Servicos de Diretório da Microsoft
#iptables -A INPUT -i eth1 -p tcp --dport 445 -j ACCEPT
#iptables -A INPUT -i eth1 -p tcp -m multiport --sports 139,445 -j ACCEPT
# MSN - Servico de Mensageiro de Rede da Microsoft
#$iptables -A INPUT -i $EXTERNA -p tcp -m multiport --sports 1863,1900 -j ACCEPT
#$iptables -A INPUT -i $EXTERNA -p udp --sport 1900 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p tcp -m multiport --sports 1863,7001 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p udp --sport 7001 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p tcp -m multiport --dports 1863,7001 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p udp --dport 7001 -j ACCEPT
# NETBIOS-SSN - Servico de Sessão NetBIOS
iptables -A INPUT -i eth1 -p udp -m multiport --dports 137,138 -j ACCEPT
iptables -A INPUT -i eth1 -p tcp --dport 139 -j ACCEPT
# NO-IP - Provedor de DNS Dinâmico
iptables -A INPUT -i ppp0 -p tcp --sport 8245 -j ACCEPT
# NTP - Protocolo para sincronizacão dos relógios
#$iptables -A INPUT -i $EXTERNA -p udp --sport 123 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p udp --sport 123 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p udp --dport 123 -j ACCEPT
# POP3S - Protocolo de Correio Seguro
iptables -A INPUT -i ppp0 -p tcp --sport 995 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp --sport 995 -j ACCEPT
iptables -A FORWARD -o ppp0 -p tcp --dport 995 -j ACCEPT
# SSDP - Protocolo para Descoberta de Servicos Simples
iptables -A INPUT -i eth1 -p udp --dport 1900 -j ACCEPT
# SSH - Para Rede Externa
iptables -A INPUT -p tcp --sport 22 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp --sport 22 -j ACCEPT
iptables -A FORWARD -o ppp0 -p tcp --dport 22 -j ACCEPT
# SSMTP - Protocolo Simples para Transferência de Correio Seguro
iptables -A INPUT -i ppp0 -p tcp -m multiport --sports 465,587 -j ACCEPT
iptables -A FORWARD -i ppp0 -p tcp --sport 465 -j ACCEPT
iptables -A FORWARD -o ppp0 -p tcp --dport 465 -j ACCEPT
# TELNET
#$iptables -A INPUT -p tcp --sport 23 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p tcp --sport 23 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p tcp --dport 23 -j ACCEPT
# VNC - Computacão em Rede Virtual
#$iptables -A INPUT -p tcp --sport 5900 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p tcp --sport 5900 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p tcp --dport 5900 -j ACCEPT
# XMPP - Protocolo de Presenca e Mensagens Extensiva
#$iptables -A INPUT -i $EXTERNA -p tcp --sport 5222 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -p tcp --sport 5222 -j ACCEPT
#$iptables -A FORWARD -o $EXTERNA -p tcp --dport 5222 -j ACCEPT
echo "Protocolo de servicos ativado..................[OK]"
#libera toda a saida
#iptables -A OUTPUT -j ACCEPT
##### Seguranca
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route # Impede falsear pacote
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects # Perigo de descobrimento de rotas de roteamento (desativar em roteador)
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts # Risco de DoS
echo 1 > /proc/sys/net/ipv4/tcp_syncookies # Inicia a conexão quando recebe a confirmacao, diminuindo a banda gasta
echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter # Faz o firewall responder apenas a placa de rede que recebeu o pacote
# Protege a regra de Forward na rede interna
iptables -A FORWARD -o eth0 -m state --state INVALID -j DROP
#Protecão contra IP Spoofing
iptables -A INPUT -s 10.0.0.0/8 -i ppp0 -j DROP
iptables -A INPUT -s 172.16.0.0/16 -i ppp0 -j DROP
iptables -A INPUT -s 192.168.0.0/24 -i ppp0 -j DROP
# Protecão contra Ping da Morte
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
### Protecão contra Syn-Floods
iptables -N syn-flood
iptables -A INPUT -i ppp0 -p tcp --syn -j syn-flood
iptables -A syn-flood -m limit --limit 12/s --limit-burst 24 -j RETURN
iptables -A syn-flood -j DROP
iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
iptables -A FORWARD -p tcp -m limit --limit 1/s -j ACCEPT
# Protecao contra acessos externos
#iptables -A INPUT -p TCP --syn -j DROP
#Protecao contra pacotes danificados OU suspeitos
#iptables -A INPUT -m unclean -j DROP
#iptables -A FORWARD -m unclean -j DROP
# Protecao contra pacotes TCP indesejaveis
#iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
# Protecão contra Ataques
iptables -A INPUT -m state --state INVALID -j DROP
# Protecão contra os "Ping of Death"
iptables -A INPUT -i ppp0 -p icmp --icmp-type 8 -m limit --limit 5/m -j DROP
iptables -A INPUT -i ppp0 -p icmp --icmp-type 0 -j ACCEPT
iptables -A INPUT -i eth1 -p icmp -j ACCEPT
# Protecão contra trinoo
iptables -N TRINOO
iptables -A TRINOO -j DROP
iptables -A INPUT -p TCP -i ppp0 --dport 27444 -j TRINOO
iptables -A INPUT -p TCP -i ppp0 --dport 27665 -j TRINOO
iptables -A INPUT -p TCP -i ppp0 --dport 31335 -j TRINOO
iptables -A INPUT -p TCP -i ppp0 --dport 34555 -j TRINOO
iptables -A INPUT -p TCP -i ppp0 --dport 35555 -j TRINOO
# Protecão contra tronjans
iptables -N TROJAN
iptables -A TROJAN -j DROP
iptables -A INPUT -p TCP -i ppp0 --dport 666 -j TROJAN
iptables -A INPUT -p TCP -i ppp0 --dport 666 -j TROJAN
iptables -A INPUT -p TCP -i ppp0 --dport 4000 -j TROJAN
iptables -A INPUT -p TCP -i ppp0 --dport 6000 -j TROJAN
iptables -A INPUT -p TCP -i ppp0 --dport 6006 -j TROJAN
iptables -A INPUT -p TCP -i ppp0 --dport 16660 -j TROJAN
# Protecão contra worms
iptables -A FORWARD -p tcp --dport 135 -i eth1 -j REJECT
# Protecão contra Port Scanners (nmap)
iptables -N PSCAN
iptables -A PSCAN -j DROP
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j PSCAN
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 5/m -j PSCAN
# Protege contra pacotes que podem procurar e obter informações da rede interna
iptables -A FORWARD --protocol tcp --tcp-flags ALL SYN,ACK -j DROP
# Regras para Bloquear ataques Brute Force no SSH
iptables -A INPUT -p tcp --syn --dport ssh -m recent --name sshattack --set
iptables -A INPUT -p tcp --dport ssh --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j REJECT --reject-with tcp-reset
iptables -A FORWARD -p tcp --syn --dport ssh -m recent --name sshattack --set
iptables -A FORWARD -p tcp --dport ssh --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j REJECT --reject-with tcp-reset
# negar port scanners
iptables -N SCANNER
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i ppp0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i ppp0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i ppp0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i ppp0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i ppp0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i ppp0 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i ppp0 -j SCANNER
##### Fechando as portas do samba o perigo mora aqui caso fique de cara para a internet.
iptables -A INPUT -p tcp -i ppp0 --syn --dport 137 -j DROP
iptables -A INPUT -p tcp -i ppp0 --syn --dport 138 -j DROP
iptables -A INPUT -p tcp -i ppp0 --syn --dport 139 -j DROP
# Fechar NFS (portmap) para o mundo
iptables -A INPUT -p tcp -i ppp0 --syn --dport 111 -j DROP
echo "Regras de seguranca ativadas...................[OK]"
##### excluir estacoes do proxy, passa direto pelo NAT
#iptables -t nat -A PREROUTING -i eth1 -s 192.168.1.37/32 -p tcp -m multiport --dport 80,443,8080 -j ACCEPT
#$iptables -t nat -A PREROUTING -i eth1 -s 192.168.1.53/32 -p tcp -m multiport --dport 80,443,8080 -j ACCEPT
##############################################################################################################################
##### VNC
# Redireciona portas na primeira maquina vnc troque o ip conforme a maquina que deseja acessar.
#$iptables -A FORWARD -i $EXTERNA -d 192.168.X.X -p tcp --dport 5800:5900 -j ACCEPT
#$iptables -A FORWARD -i $EXTERNA -d 192.168.X.X-p udp --dport 5800:5900 -j ACCEPT
#$iptables -t nat -A PREROUTING -i $EXTERNA -p tcp --dport 5800:5900 -j DNAT --to-destination 192.168.X.X:5800-5900
#$iptables -t nat -A PREROUTING -i $EXTERNA -p udp --dport 5800:5900 -j DNAT --to-destination 192.168.X.X:5800-5900
# Terminal Service
#$iptables -A FORWARD -i $EXTERNA -d 192.168.X.X -p tcp --dport 3389 -j ACCEPT
#$iptables -t nat -A PREROUTING -i $EXTERNA -p tcp --dport 3389 -j DNAT --to-dest 192.168.X.X:3389
#prioriza trafego na porta 80
iptables -t mangle -A INPUT -p tcp --dport 80 -j TOS --set-tos 16
# NAT para compartilhar internet
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "Compartilhamento ativado.......................[OK]"
# redireciona o trafego da prota 80 para 3128 (squid) Proxy Transparente
iptables -t nat -A PREROUTING -i eth1 -p tcp -m multiport --dport 80,8080 -j REDIRECT --to-ports 3128
echo "Proxy transperente ativado.....................[OK]"