henriquebh
(usa Debian)
Enviado em 08/07/2010 - 16:50h
Boa tarde galera!
Seguinte, eu sou novato em Linux.
Então la vai. Ja andei estudando bastante a respeito ser servidores Linux.
Proxy, Firewall, DHCP, DNS dentre outras funcoes desse novo mundo.
Estou com dificuldade em colocar uma faixa de IP pra navegar fora o proxy.
Segue os conf do squid e do firewall
Desde ja agradeço a força.
############################################################################
####### ************************ Squid.conf ************************ #######
####### ******************** Henrique Rodrigues ******************** #######
####### *************************** 2010 *************************** #######
############################################################################
###### ***************** >> Proxy Transparente << ***************** ########
############################################################################
###
##
#
http_port 3128 transparent
#http_port 3128
visible_hostname Dhalsim.empresa.local
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
cache_mem 64 MB
maximum_object_size_in_memory 20 KB
maximum_object_size 16384 KB
minimum_object_size 0 KB
cache_swap_low 95
cache_swap_high 98
# ********** >> TAG -> logformat << ********** #
logformat custom %>A %Ss %Hs %tl %ru %mt
# ********** >> TAG -> access_log << ********** #
access_log /etc/squid/var/log/access.log custom
# ********** >> TAG -> cache_log << ********** #
cache_log /etc/squid/var/log/cache.log custom
# ********** >> TAG -> cache_store_log << ********** #
cache_store_log /etc/squid/var/log/store.log custom
# ********** >> TAG -> Diretorio do cache << ********** #
cache_dir ufs /etc/squid/var/cache 100 16 256
# ********** >> TAG -> Padrão de atualização do cache << ********** #
refresh_pattern ^ftp: 15 20% 2280
refresh_pattern ^gopher: 15 0% 2280
refresh_pattern . 15 20% 2280
# ********** >> TAG -> broken_vary_encoding << ********** #
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
# ********** >> TAG -> Usuarios sem restricoes de sites << ********** #
acl liberdade src "/etc/squid/var/db/liberdade"
http_access allow liberdade
# ********** >> TAG -> Controle de acesso << ********** #
acl all src 0.0.0.0/0.0.0.0
#acl net_int_1 src 192.168.0.0/255.255.255.0
acl net_int_2 src 192.168.1.0/255.255.255.0
#acl net_int_3 src 192.168.2.0/255.255.255.0
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl manager proto cache_object
acl Safe_ports port 443 563 # HTTPS, SNEWS
acl Safe_ports port 80 # HTTP
acl Safe_ports port 21 # FTP
acl Safe_ports port 25 # SMTP
acl Safe_ports port 110 # POP3
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 901 # SWAT
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 allow localhost
http_access deny to_localhost
# ********** >> TAG -> Bloqueio do MSN & Orkut << ********** #
acl msn url_regex -i /gateway/gateway.dll
acl msn_orkut dstdomain "/etc/squid/var/db/msn_orkut"
http_access deny msn_orkut
http_access deny msn
# ********** >> TAG -> Bloqueio com base em menssagem instantanea << ********** #
acl instant_messaging dstdom_regex "/etc/squid/var/db/instant_messaging"
http_access deny instant_messaging
# ********** >> TAG -> Bloqueio com base em palavras << ********** #
acl palavras dstdom_regex "/etc/squid/var/db/palavras"
http_access deny palavras
# ********** >> TAG -> Bloqueio com base em expressao << ********** #
# acl expressions url_regex -i "/etc/squid/var/db/expressions"
# http_access deny expressions
# ********** >> TAG -> Bloqueio com base em expressao pornografica << ********** #
acl expressions_porn url_regex -i "/etc/squid/var/db/expressions_porn"
http_access deny expressions_porn
# ********** >> TAG -> Bloqueio com base em sites infectado << ********** #
acl infectado url_regex -i "/etc/squid/var/db/infectado"
http_access deny infectado
# ********** >> TAG -> Bloqueio baseado em Dominios Específicos << ********** #z
acl dominios dstdomain "/etc/squid/var/db/dominios"
http_access deny dominios
# ********** >> TAG -> Bloqueio baseado em spyware << ********** #
acl spyware dstdomain "/etc/squid/var/db/spyware"
http_access deny spyware
# ********** >> TAG -> Bloqueio baseado em antispyware << ********** #
acl antispyware dstdomain "/etc/squid/var/db/antispyware"
http_access deny antispyware
# ********** >> TAG -> Bloqueio com base em extensões << ********** #
acl downloads urlpath_regex -i "/etc/squid/var/db/downloads"
http_access deny downloads
# ********** >> TAG -> Bloqueio com base em proxy externo << ********** #
acl proxy dstdom_regex "/etc/squid/var/db/proxy"
http_access deny proxy
# ********** >> TAG -> Bloqueio com base em hacker << ********** #
acl hacker dstdom_regex "/etc/squid/var/db/hacker"
http_access deny hacker
# ********** >> TAG -> Bloqueio com base em violação direitos autorais << ********** #
acl ilegal dstdom_regex "/etc/squid/var/db/ilegal"
http_access deny ilegal
# ********** >> TAG -> Bloqueio com base em jogos << ********** #
acl jogos dstdom_regex "/etc/squid/var/db/jogos"
http_access deny jogos
# ********** >> TAG -> Bloqueio com base em jogos online << ********** #
acl jogos_online dstdom_regex "/etc/squid/var/db/jogos_online"
http_access deny jogos_online
# ********** >> TAG -> Bloqueio com base no horário << ********** #
acl net_local src 192.168.1.0/255.255.255.0
acl web_mail url_regex "/etc/squid/var/db/web_mail"
acl h_manha time MTWHF 06:00-10:59
acl h_tarde time MTWHF 13:00-17:30
acl permit_webmail url_regex -i \webmail.exe$
http_access deny net_local permit_webmail h_manha
http_access deny net_local permit_webmail h_tarde
http_access deny net_local web_mail h_manha
http_access deny net_local web_mail h_tarde
# ********** >> TAG -> Acesso Google & Google_talk << ********** #
acl deny_googletalk url_regex -i google.com
acl deny_webgoogletalk url_regex -i mail.google.com/mail/channel/bind
acl allow_wwwgooglebr url_regex -i
www.google.com.br">
www.google.com.br
acl allow_wwwgoogle url_regex -i
www.google.com
acl allow_wwwgoogleimg url_regex -i images.google.com
acl allow_wwwgooglegroups url_regex -i groups.google.com
acl allow_wwwgooglenews url_regex -i news.google.com
acl allow_wwwgooglemail url_regex -i mail.google.com
acl allow_wwwgoogletranslate url_regex -i
www.translate.google.com
http_access deny deny_googletalk
http_access deny deny_webgoogletalk
http_access allow allow_wwwgooglebr
http_access allow allow_wwwgoogle
http_access allow allow_wwwgoogleimg
http_access allow allow_wwwgooglegroups
http_access allow allow_wwwgooglenews
http_access allow allow_wwwgooglemail
http_access allow allow_wwwgoogletranslate
# ********** >> TAG -> Libera rede local para usuarios << ********** #
#http_access allow net_int_1
http_access allow net_int_2
#http_access allow net_int_3
# ********** >> TAG -> Nega cache local, para não haver duplicação << ********** #
acl localcache dstdomain 192.168.1.5
cache deny localcache
# ********** >> TAG -> Bloqueio de tudo que não foi exposto anteriormente << ********** #
http_access deny all
##
##################################################################################
#!/bin/bash
# Interface da rede
rede="eth0";
# Interface da internet
internet="eth1";
# Definição da rede interna
visitantes="192.168.0.0/255.255.255.0";
rederestrita="192.168.1.0/255.255.255.218";
redeadm="192.168.2.0/255.255.255.240";
iniciar(){
# Compartilha a conexão:
modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $rede -j MASQUERADE
echo "Compartilhamento ativado"
# Liberar Rede Interna
iptables -A INPUT -p tcp --syn -s $visitantes -j ACCEPT
iptables -A OUTPUT -p tcp --syn -s $visitantes -j ACCEPT
iptables -A FORWARD -p tcp --syn -s $visitantes -j ACCEPT
iptables -A INPUT -p tcp --syn -s $rederestrita -j ACCEPT
iptables -A OUTPUT -p tcp --syn -s $rederestrita -j ACCEPT
iptables -A FORWARD -p tcp --syn -s $rederestrita -j ACCEPT
iptables -A INPUT -p tcp --syn -s $redeadm -j ACCEPT
iptables -A OUTPUT -p tcp --syn -s $redeadm -j ACCEPT
iptables -A FORWARD -p tcp --syn -s $redeadm -j ACCEPT
# iptables -A INPUT -s $visitantes -j ACCEPT
# iptables -A INPUT -s $rederestrita -j ACCEPT
# iptables -A INPUT -s $redeadm -j ACCEPT
# Liberar IP passar fora do SQUID "excluir estacoes do proxy, passa direto pelo NAT"
iptables -t nat -A PREROUTING -i $rede -s $visitantes -p tcp -m multiport --dport 80,443 -j ACCEPT
iptables -t nat -A PREROUTING -i $rede -s $redeadm -p tcp -m multiport --dport 80,443 -j ACCEPT
iptables -t nat -A PREROUTING -s $visitantes -d 0/0 -p tcp --dport 80 -j ACCEPT
iptables -t nat -A PREROUTING -s $redeadm -d 0/0 -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -s $visitantes -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -s $redeadm -p tcp --dport 80 -j ACCEPT
# Redirecionamento transparente:
iptables -t nat -A PREROUTING -i $internet -p tcp --dport 80 -j REDIRECT --to-port 3128
echo "Redirecionamento ativado"
# Liberando acesso ao Windows Update
iptables -A FORWARD -s $visitantes -d 207.46.209.122 -p tcp --dport 80 -j REJECT
iptables -A FORWARD -s $visitantes -d 64.4.21.91 -p tcp --dport 80 -j REJECT
iptables -A FORWARD -s $visitantes -d 200.171.222.93 -p tcp --dport 86 -j REJECT
iptables -A FORWARD -s $rederestrita -d 207.46.209.122 -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -s $rederestrita -d 64.4.21.91 -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -s $rederestrita -d 200.171.222.93 -p tcp --dport 86 -j ACCEPT
iptables -A FORWARD -s $redeadm -d 207.46.209.122 -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -s $redeadm -d 64.4.21.91 -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -s $redeadm -d 200.171.222.93 -p tcp --dport 86 -j ACCEPT
# Liberar VNC para rede redeadm
iptables -A FORWARD -s $rederestrita -p tcp -m multiport --dport 5800,5900,6000 -j ACCEPT
# libera ping para rede redeadm
iptables -A INPUT -s $rederestrita -p icmp --icmp-type 8 -j ACCEPT
# Liberando LoopBack
iptables -A INPUT -d 127.0.0.1 -j ACCEPT
# Liberando Porta 2222 (SSH)
iptables -A FORWARD -s $redeadm -p tcp --dport 2222 -j ACCEPT
iptables -A FORWARD -s 0/0 -p tcp --dport 2222 -j DROP
# Liberando Porta 22 (SSH)
iptables -A FORWARD -s $redeadm -p tcp --dport 22 -j ACCEPT
iptables -A FORWARD -s 0/0 -p tcp --dport 22 -j DROP
# Bloqueio de MSN
iptables -A FORWARD -s $rederestrita -p tcp --dport 1863 -j DROP
iptables -A FORWARD -s $rederestrita -d loginnet.passport.com -j DROP
iptables -A FORWARD -s $rederestrita -p tcp --dport 1863 -j DROP
iptables -A FORWARD -s $rederestrita -d loginnet.passport.com -j DROP
iptables -A FORWARD -s $rederestrita -d messenger.hotmail.com -j DROP
iptables -A FORWARD -s $rederestrita -d webmessenger.msn.com -j DROP
iptables -A FORWARD -p tcp --dport 1080 -j DROP
iptables -A FORWARD -s $rederestrita -p tcp --dport 1080 -j DROP
iptables -A FORWARD -p tcp --dport 1863 -j DROP
iptables -A FORWARD -d 64.4.13.0/24 -j DROP
# Registro de logs
iptables -A INPUT -p tcp --dport 333 --syn -j LOG --log-prefix="[TENTATIVA ACESSO FWLOGWATCH]"
iptables -A INPUT -p tcp --dport 23 --syn -j LOG --log-prefix="[TENTATIVA ACESSO TELNET]"
iptables -A INPUT -p tcp --dport 10000 --syn -j LOG --log-prefix="[TENTATIVA ACESSO WEBMIN]"
iptables -A FORWARD -m multiport -p tcp --dport 5800,5900,6000 -j LOG --log-prefix="[ACESSO VNC]"
iptables -A INPUT -p tcp --dport 22 --syn -j LOG --log-prefix="[TENTATIVA ACESSO SSH]"
iptables -A INPUT -p tcp --dport 2222 --syn -j LOG --log-prefix="[TENTATIVA ACESSO SSH]"
iptables -A INPUT -p tcp --dport 21 --syn -j LOG --log-prefix="[TENTATIVA ACESSO FTP]"
# Protege contra port scanners
iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 5/s -j ACCEPT
# proteção contra traceroute
iptables -A INPUT -p udp -s 0/0 -i $rede --dport 33435:33525 -j REJECT
# Contra DoS:
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
# Protecoes contra pacotes invalidos
iptables -A INPUT -m state --state INVALID -j REJECT
# Regras básicas de firewall:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
iptables -A INPUT -p tcp --syn -j DROP
# Bloqueia as portas UDP de 0 a 1023:
iptables -A INPUT -p udp --dport 0:1023 -j DROP
echo "Regras de firewall e compartilhamento ativados"
}
parar(){
iptables -F
iptables -t nat -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
echo 0 > /proc/sys/net/ipv4/ip_forward
echo "Regras de firewall e compartilhamento desativados"
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar ;;
*) echo "Use os parâmetros start | stop | restart"
esac
Aguardo
Aceito qualquer tipo de sugestao