tiago2001
(usa Debian)
Enviado em 18/09/2013 - 16:58h
Bom pessoal, minha internet fica bem lenta ao eu bloquear a porta 80, quando eu libero tudo para passar pela 80 funciona muito bem.
----------------------------------------------------------------
SQUID BÁSICO
----------------------------------------------------------------
http_port 192.168.1.1 3128
http_port 192.168.4.1 3128
cache_mem 5000 MB
cache_swap_low 90
cache_swap_high 95
cache_dir ufs /cache/squid/ 10000 16 256
maximum_object_size 300000 KB
maximum_object_size_in_memory 8000 KB
access_log /var/log/squid3/access.log squid
cache_log /var/log/squid3/cache.log
cache_store_log /var/log/squid3/store.log
pid_filename /var/log/squid3/squid3.pid
mime_table /usr/share/squid3/mime.conf
cache_mgr chj-informatica@saude.sp.gov.br
memory_pools off
diskd_program /usr/lib/squid3/diskd
unlinkd_program /usr/lib/squid3/unlinkd
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
quick_abort_max 16 KB
quick_abort_pct 95
quick_abort_min 16 KB
request_header_max_size 20 KB
reply_header_max_size 20 KB
request_body_max_size 0 KB
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl rede1 src 192.168.1.0/24
acl rede4 src 192.168.4.0/24
acl rede10 src 10.8.23.0/27
acl SSL_ports port 443 563 5500 8443 240
acl Safe_ports port 80 240 5500 # http
acl Safe_ports port 2082 # hospedagem washington
acl Safe_ports port 809 #sptrans
acl Safe_ports port 21 22 # ftp
acl Safe_ports port 23 # siafisico
acl Safe_ports port 53 88 # nao sei o que écl Safe_ports port 443 563 # https, snews
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
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 8443 # Siafem
acl Safe_ports port 8080
acl Safe_ports port 901 # swat
acl Safe_ports port 1025-65535 # portas altas
acl purge method PURGE
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
#acl streaming rep_mime_type -i "/etc/squid3/blockmime"
#acl sitesbloqueados url_regex -i "/etc/squid3/regras/sitesbloqueados"
#http_access deny sitesbloqueados
http_access allow rede1
http_access allow rede4
http_access allow rede10
cache_mgr webmaster
mail_program mail
cache_effective_user proxy
cache_effective_group proxy
httpd_suppress_version_string off
visible_hostname CHJ
error_directory /usr/share/squid3/errors/Portuguese/
------------------------------------------------------------
-----------------------------------------------------------
FIREWALL
-----------------------------------------------------------
----------------------------------------------------------
#!/bin/sh
# Variáveis
# -------------------------------------------------------
iptables=/sbin/iptables
IF_EXTERNA=eth0
IF_INTERNA_1=eth1
IF_INTERNA_4=eth2
IF_VPN=tun0
IF_DNS1=192.168.1.3
IF_DNS2=192.168.4.3
IF_REDE_1=192.168.1.0/24
IF_REDE_4=192.168.4.0/24
# Ativa módulos
# -------------------------------------------------------
modprobe iptable_nat
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
# Ativa roteamento no kernel
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
# Proteção contra IP spoofing
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
# Zera regras
# -------------------------------------------------------
iptables -F
iptables -X
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
# Determina a política padrão
# -------------------------------------------------------
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -I INPUT -p tcp --destination-port 631 -j ACCEPT
#iptables -t nat -A PREROUTING -i $IF_INTERNA_1 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A PREROUTING -i $IF_INTERNA_4 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -I FORWARD -p tcp -s 192.168.1.0/24 --dport 80 -j DROP
#iptables -I FORWARD -p tcp -s 192.168.4.0/24 --dport 80 -j DROP
#Liberando o INPUT para a interface de loopback
iptables -A INPUT -p ALL -s 127.0.0.1 -i lo -j ACCEPT
iptables -A INPUT -p ALL -s $IF_EXTERNA -i lo -j ACCEPT
# nao ir por fora o juquery.no-ip.org
iptables -t nat -A PREROUTING -p TCP -d juquery.no-ip.org --dport 80 -j DNAT --to 192.168.1.251
# FTP para Kazuo
iptables -t nat -A PREROUTING -d 10.8.23.6 -j DNAT --to 192.168.1.6
iptables -t nat -A POSTROUTING -d 192.168.1.6 -j SNAT --to 10.8.23.6
#Aqui eu libero as respostas do DNS
iptables -A INPUT -p udp -s $IF_DNS1 --sport 53 -j ACCEPT
iptables -A INPUT -p udp -s $IF_DNS2 --sport 53 -j ACCEPT
#Libera Squid para REDE INTERNA
iptables -A INPUT -p tcp -i $IF_INTERNA_1 -s $IF_REDE_1 --dport 3128 -j ACCEPT
iptables -A INPUT -p tcp -i $IF_INTERNA_4 -s $IF_REDE_4 --dport 3128 -j ACCEPT
iptables -A INPUT -p tcp -i $IF_INTERNA_1 -s $IF_REDE_1 --dport 631 -j ACCEPT
iptables -A INPUT -p tcp -i $IF_INTERNA_4 -s $IF_REDE_4 --dport 631 -j ACCEPT
#Vamos liberar as respostas www para o squid
iptables -A INPUT -p tcp -i $IF_EXTERNA --sport 80 -j ACCEPT
iptables -A INPUT -p tcp -i $IF_EXTERNA --sport 443 -j ACCEPT
# 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
# Dropa pacotes mal formados
# -------------------------------------------------------
iptables -A INPUT -i $IF_EXTERNA -m unclean -j LOG --log-level 6 --log-prefix "FIREWALL: pacote mal formado: "
iptables -A INPUT -i $IF_EXTERNA -m unclean -j DROP
# 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
# 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
# Proteção contra tronjans
# -------------------------------------------------------
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
# Proteção contra worms precisa para o AD
# -------------------------------------------------------
#iptables -A FORWARD -p tcp --dport 135 -i $IF_INTERNA_1 -j REJECT
#iptables -A FORWARD -p tcp --dport 135 -i $IF_INTERNA_4 -j REJECT
# Proteção contra syn-flood
# -------------------------------------------------------
iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
# Proteção contra ping da morte
# -------------------------------------------------------
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
#Liberar DNS para SMTP/POP
iptables -A FORWARD -p udp -s $IF_REDE_1 -d $IF_DNS1 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_REDE_1 -d $IF_DNS2 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_DNS1 -d $IF_REDE_1 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_DNS2 -d $IF_REDE_1 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_REDE_4 -d $IF_DNS1 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_REDE_4 -d $IF_DNS2 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_DNS1 -d $IF_REDE_4 --dport 53 -j ACCEPT
iptables -A FORWARD -p udp -s $IF_DNS2 -d $IF_REDE_4 --dport 53 -j ACCEPT
#Liberar portas SMTP/POP
iptables -A FORWARD -p tcp -s $IF_REDE_1 --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp -s $IF_REDE_1 --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp -s $IF_REDE_4 --dport 25 -j ACCEPT
iptables -A FORWARD -p tcp -s $IF_REDE_4 --dport 110 -j ACCEPT
iptables -A FORWARD -p tcp --sport 110 -j ACCEPT
iptables -A FORWARD -p tcp --sport 25 -j ACCEPT
# 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
# Libera acesso externo a determinadas portas
# -------------------------------------------------------
iptables -A INPUT -p tcp --dport 22 -i $IF_EXTERNA -j ACCEPT
# Ativa mascaramento de saída
# -------------------------------------------------------
iptables -A POSTROUTING -t nat -o $IF_EXTERNA -j MASQUERADE
iptables -A POSTROUTING -t nat -o $IF_INTERNA_1 -j MASQUERADE
iptables -A POSTROUTING -t nat -o $IF_INTERNA_4 -j MASQUERADE
iptables -A POSTROUTING -t nat -o $IF_VPN -j MASQUERADE
# Redireciona portas na própria máquina
# -------------------------------------------------------
#$iptables -A PREROUTING -t nat -d 192.168.200.1 -p tcp --dport 5922 -j REDIRECT --to-ports 22
#Fecha o resto
iptables -A INPUT -p tcp --dport 3128 -j REJECT --reject-with tcp-reset
iptables -A INPUT -j LOG --log-prefix "Pacote INPUT descartado: "
#iptables -A INPUT -j DROP
#Fecha o resto
iptables -A FORWARD -j LOG --log-prefix "Pacote FORWARD descartado: "
#iptables -A FORWARD -j DROP
# Fechar porta 80 e liberar intranet + servidores de impressao
iptables -I FORWARD -p tcp -s $IF_REDE_1 --dport 80 -j DROP
iptables -I FORWARD -p tcp -s $IF_REDE_4 --dport 80 -j DROP
iptables -I FORWARD -d 192.168.1.1 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.4.1 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.4.4 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.1.11 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.1.20 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.1.251 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.4.20 -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -d 192.168.4.20 -p tcp --dpot 631 -j ACCEPT
iptables -I FORWARD -d 192.168.1.20 -p tcp --dpot 631 -j ACCEPT
# Sites para nao passar pelo proxy
iptables -I FORWARD -d 10.0.0.0/8 -p tcp --dport 80 -j ACCEPT
#Regra para todos navegarem sem passar pelo proxy
iptables -I FORWARD -d 0/0 -p tcp --dport 80 -j ACCEPT
-------------------------------------------------------------------------------------------
TIRANDO DA REGRA A ÚLTIMA LINHA DO FIREWALL, A INTERNET FICA EXTREMAMENTE LENTA.
ALGUÉM TEM ALGUMA SOLUÇÃO? TEM ALGO ERRADO?
OBRIGADO