joelsontech
(usa Debian)
Enviado em 24/07/2008 - 13:20h
fiz tudo isso q vc me falou, mas ainda estah sem funcionar. Segue meu squid.conf:
cache_mem 16 MB
maximum_object_size_in_memory 64 KB
maximum_object_size 100 MB
minimum_object_size 0 KB
cache_swap_low 90
cache_swap_high 95
cache_dir ufs /var/spool/squid 100 16 256
cache_access_log /var/log/squid/access.log
refresh_pattern ^ftp: 15 20% 2280
refresh_pattern ^gopher: 15 20% 2280
refresh_pattern . 15 20% 2280
http_port 3128 transparent
visible_hostname servIX
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 SSL_ports port 443 563
acl Safe_ports port 80 #http
#acl Safe_ports 21 #ftp
acl Safe_ports port 443 563 #https, news
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-httpt
acl Safe_ports port 591 #filemager
acl Safe_ports port 777 #multlink http
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 allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl bloqueados url_regex -i "/etc/squid/bloqueados"
http_access deny bloqueados
acl redelocal src 192.168.2.0/24 #definicao da acl redelocal
http_access allow localhost
http_access allow redelocal
http_access deny all
e assim o as regras do iptables:
#!/bin/bash
echo "Ativando FIEREWALL..."
EXT=eth0
INT=eth1
#carrega modulos
modprobe iptable_nat
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe ipt_multiport
echo 1 > /proc/sys/net/ipv4/ip_forward
### Mensagem de inicialização do Firewall
echo "Ativando Regras do Firewall"
### Exclui todas as regras
iptables -t nat -F
iptables -t mangle -F
iptables -t filter -F
### Exclui cadeias customizadas
iptables -X
### Zera os contadores das cadeias
iptables -t nat -Z
iptables -t mangle -Z
iptables -t filter -Z
### Regras PREROUTING
#iptables -t nat -A PREROUTING -i $EXT -p tcp --dport 3389 -j DNAT --to 192.168.0.200
#iptables -t nat -A PREROUTING -i $EXT -p tcp --dport 5900 -j DNAT --to 192.168.0.201
#iptables -t nat -A PREROUTING -i $INT -p tcp --dport 80 -j REDIRECT --to-port 3128
#proxy transparente
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j MASQUERADE
#Proteção contra ataques
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
#fitros de IP
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth0/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/eth1/rp_filter
iptables -t filter -A FORWARD -j ACCEPT -m state --state ESTABLISHED,RELATED
iptables -t filter -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED
#proteção contra ataques
iptables -A INPUT -p tcp -i eth1 --dport 1524 -j DROP
iptables -A INPUT -p tcp -i eth1 --dport 27665 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 27444 -j DROP
iptables -A INPUT -p udp -i eth1 --dport 31335 -j DROP
iptables -A FORWARD -m unclean -j DROP
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 2/s -j ACCEPT
iptables -A FORWARD -p tcp -m limit --limit 5/s -j ACCEPT
iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j LOG --log-prefix "FTP"
iptables -A INPUT -p tcp --dport 23 -j LOG --log-prefix "TELNET"
#iptables -A INPUT -p tcp --dport 22 -j LOG --log-prefix "SSH "
iptables -A INPUT -p tcp --dport 137:139 -j LOG --log-prefix "NETBEUI"
iptables -A INPUT -p tcp --dport 5042 -j LOG --log-prefix "Wincrash"
iptables -A INPUT -p tcp --dport 12345 -j LOG --log-prefix "BackOrifice"
# Liberando acesso para sua rede interna
iptables -A INPUT -p tcp --syn -s 192.168.2.0/255.255.255.0 -j ACCEPT &&
iptables -A OUTPUT -p tcp --syn -s 192.168.2.0/255.255.255.0 -j ACCEPT &&
iptables -A FORWARD -p tcp --syn -s 192.168.2.0/255.255.255.0 -j ACCEPT &&
#conexoes de fora->dentro
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 563 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 86 -j ACCEPT
iptables -A INPUT -p tcp --dport 5190 -j ACCEPT
iptables -A INPUT -p tcp --dport 1863 -j ACCEPT
iptables -A INPUT -p tcp --dport 5800 -j ACCEPT
iptables -A INPUT -p tcp --dport 5900 -j ACCEPT
#conexoes dentro->fora
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 20 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 86 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5190 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 1863 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 110 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 563 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5800 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 5900 -j ACCEPT
#libera HTTPS
iptables -A FORWARD -p tcp --dport 443 -j ACCEPT
iptables -A FORWARD -p tcp --dport 563 -j ACCEPT
#VNC
iptables -A FORWARD -i eth1 -p tcp --dport 5800:5900 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -p udp --dport 5800:5900 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A PREROUTING -p tcp -i eth1 --dport 5800:5900 -j DNAT --to 192.168.2.1:5800-5900
iptables -t nat -A PREROUTING -p udp -i eth1 --dport 5800:5900 -j DNAT --to 192.168.2.1:5800-5900
#fecha o resto
iptables -A INPUT -j DROP
iptables -A FORWARD -j DROP
### Regras POSTROUTING
iptables -t nat -A POSTROUTING -o $EXT -j MASQUERADE
#permite todo trafego na interface de loopback
iptables -t filter -A INPUT -j ACCEPT -i lo
echo "FIREWALL inicializado"
termina aqui as regras.
OUTRA COISA QUE ACONTECE: uma vez que eu descomento as regras que redirecionam a porta 80 para o squid porta 3128, mas ele n funciona, então para de funcionar conexão geral. Mesmo que eu comente novamente essas regras e execute novamente o script do firewall, mesmo assim continua sem funcionar a conexão. Descobri que so volta se fizer:
iptables -F
iptables -X
iptables -Z
...ou seja, sem redirecionar para o squid como eu acho que estah senod feito com a regra a baixo:
#proxy transparente
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
o script de firewall não atrapalha em nada a conexão. Basta descomentar essas regras e tudo para.
obrigodo desde jah...