felipedc
(usa Debian)
Enviado em 03/11/2011 - 10:31h
squid.conf
http_port 3128
visible_hostname PROXY
cache_mem 512 MB
maximum_object_size_in_memory 128 KB
maximum_object_size 900 MB
minimum_object_size 0 KB
memory_replacement_policy lru
cache_replacement_policy lru
cache_swap_low 90
cache_swap_high 95
cache_dir ufs /var/spool/squid3 5048 16 256
cache_access_log /var/log/squid3/access.log
refresh_pattern ^ftp: 15 20% 2280
refresh_pattern ^gopher: 15 0% 2280
refresh_pattern . 15 20% 2280
error_directory /usr/share/squid3/errors/Portuguese/
acl manager proto cache_object
acl localhost src 127.0.0.1
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 25
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 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 Safe_ports port 1025-65535 # portas altas
acl purge method PURGE
acl CONNECT method CONNECT
acl redelocal src 192.168.0.0/24
#-
#definições de horarios
acl seg_sex time MTWHF 08:00-18:00
acl sabado time A 08:00-12:00
#-
acl sitesproblematicos url_regex -i "/etc/squid3/sitesproblematicos" # sites não trabalha com o proxy
acl sites_blo url_regex -i "/etc/squid3/sites_blo" # bloqueados
acl down_blo url_regex -i "/etc/squid3/down_blo" # bloqueados
acl palavras_blo dstdom_regex -i "/etc/squid3/palavras_blo" # bloqueadas
acl sites_porno url_regex -i "/etc/squid3/sites_porno" # pornográficos, bloqueados a toda rede
acl ip_blo src "/etc/squid3/ip_blo"
acl blacklist url_regex -i "/etc/squid3/blacklist"
#-
acl sites_lib url_regex -i "/etc/squid3/sites_lib" # liberados
acl down_lib url_regex -i "/etc/squid3/down_lib" # liberados
acl palavras_lib dstdom_regex -i "/etc/squid3/palavras_lib" # liberadas
#-
#endereços de atualizacoes de anti-virus (avast)
acl end_antivirus url_regex -i "/etc/squid3/end_antivirus" # de atualizações do anti-virus avast
#-
#enderecos msn
acl msn url_regex -i "/etc/squid3/msn" # para liberar o acesso ao msn na rede
http_access allow end_antivirus
http_access allow msn
#----------------------------------------------------------------
#AUTENTICACAO SQUID/PROXY
auth_param basic realm .:TELESCRIT:.
auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/squid_passwd
acl autenticados proxy_auth REQUIRED
#----------------------------------------------------------------
acl nivel1 proxy_auth "/etc/squid3/nivel1" # 1 (Acesso total, sem restrições)
acl nivel2 proxy_auth "/etc/squid3/nivel2" # 2 (Acesso total, com restrições de download e monitoramento pelo Sarg)
acl nivel3 proxy_auth "/etc/squid3/nivel3" # 3 (Acesso total, sem restrições e monitoramento pelo Sarg)
acl nivel4 proxy_auth "/etc/squid3/nivel4" # 4 (Acesso com restrições de sites, download, palavras e monitoramento pelo Sarg)
acl nivel5 proxy_auth "/etc/squid3/nivel5" # 5 (Acesso com permissões somente a sites pre-definidos, restrições de download e monitoramento pelo Sarg)
#-----------------------------------------------------------------
#ATIVANDO ACLS
http_access allow manager
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 nivel1
#http_access allow msn !ip_blo
http_access deny !autenticados
http_access allow sites_lib
http_access deny sites_blo
http_access deny sites_porno
#http_access deny blacklist
http_access deny ip_blo !sites_lib
http_access allow nivel3
http_access allow down_lib
http_access allow palavras_lib
http_access deny down_blo !sites_lib
http_access allow nivel2
http_access deny sites_blo seg_sex
http_access deny sites_blo sabado
http_access deny palavras_blo
http_access allow nivel4
http_access allow nivel5
http_access allow localhost
http_access allow redelocal
http_access deny all
refresh_pattern avast.com/.*\.(cab|exe|dll|msi|gz) 10080 100% 43200 reload-into-ims
refresh_pattern download973.avast.com/.*\.(cab|exe|dll|msi|gz) 10080 100% 43200 reload-into-ims
refresh_pattern download969.avast.com/.*\.(cab|exe|dll|msi|gz) 10080 100% 43200 reload-into-ims
refresh_pattern 85.14.149.239/.*\.(cab|exe|dll|msi|gz) 10080 100% 43200 reload-into-ims
refresh_pattern 74.86.232.46/.*\.(cab|exe|dll|msi|gz) 10080 100% 43200 reload-into-ims
firewall.sh
# Identifica qual é o interpretador que será usado na execução do script:
#!/bin/bash
# Declaração de variáveis
PATH=/sbin:/bin:/usr/sbin:/usr/bin
IPTABLES="/sbin/iptables"
IPSLIBERADOS="/etc/firewall/IPSLIBERADOS"
REDILIST="/etc/firewall/REDILIST"
PROGRAMA="/etc/firewall/firewall"
# Portas liberadas e bloqueadas
PORTSLIB="/etc/firewall/PORTSLIB"
PORTSBLO="/etc/firewall/PORTSBLO"
# Interfaces de Rede
WAN=eth0
LAN=eth1
REDE="192.168.0.0/24"
IP_EXTERNO="XXX.XXX.XXX.XXX"
# Servidores
SERVIDORINTERNET="192.168.0.1"
SERVIDORDADOS="192.168.0.2"
#Carregando Módulos Necessários
modprobe ip_tables
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_state
modprobe ipt_multiport
modprobe iptable_mangle
modprobe ipt_tos
modprobe ipt_limit
modprobe ipt_mark
modprobe ipt_MARK
case "$1" in
start)
# Mensagem de inicialização
echo #| Créditos a Marcelo Magno ® Comunidade Viva O Linux! \e[m'
echo #| Uso: firewall start|stop|restart \e[m'
echo "|====================================|"
echo "|INICIANDO A CONFIGURAÇÃO DO FIREWALL|"
echo "| NETFILTER ATRAVÉS DO IPTABLES |"
echo "|====================================|"
echo -n "Zerando Regras..................." ; sleep 1s ;
$IPTABLES -F
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
$IPTABLES -t mangle -F
$IPTABLES -t nat -F
$IPTABLES -X
echo "[OK]"
# Ativar o redirecionamento no arquivo ip_forward
echo "1" > /proc/sys/net/ipv4/ip_forward
# Habilitando o fluxo interno entre os processos
$IPTABLES -I INPUT -i lo -j ACCEPT
$IPTABLES -I OUTPUT -o lo -j ACCEPT
echo "Liberando Portas" ; sleep 1s ;
for i in `cat $PORTSLIB`; do
PORTA=`echo $i | cut -d ';' -f 1`
NOME=`echo $i | cut -d ';' -f 2`
echo -n "Liberando Servico $NOME($PORTA)......................." ; sleep 1 ;
$IPTABLES -A INPUT -p tcp --dport $PORTA -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport $PORTA -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --sport $PORTA -j ACCEPT
echo "[OK]"
done
$IPTABLES -A INPUT -m state --state NEW -j ACCEPT ;
$IPTABLES -A INPUT -m state --state ESTABLISHED -j ACCEPT ;
$IPTABLES -A INPUT -m state --state RELATED -j ACCEPT ;
$IPTABLES -A OUTPUT -p icmp -o $WAN -j ACCEPT ;
$IPTABLES -A INPUT -p icmp -j ACCEPT ;
echo "Portas Liberadas!"
echo "Redirecionamento de Portas" ; sleep 1s ;
for i in `cat $REDILIST`; do
REDIPROTO=`echo $i | cut -d ';' -f 1`
REDISERVICO=`echo $i | cut -d ';' -f 2`
REDIP=`echo $i | cut -d ';' -f 3`
PPUBLICA=`echo $i | cut -d ';' -f 4`
PPRIVADA=`echo $i | cut -d ';' -f 5`
echo "PROTOCOLO: $REDIPROTO"
echo "SERVICO: $REDISERVICO"
echo "IP DE DESTINO: $REDIP"
echo "PORTA PUBLICA: $PPUBLICA"
echo "PORTA PRIVADA: $PPRIVADA"
echo -n "SERVICO $REDISERVICO........................" ; sleep 1s ;
$IPTABLES -t nat -A PREROUTING -p $REDIPROTO -i $WAN --dport $PPUBLICA -j DNAT --to $REDIP:$PPRIVADA
$IPTABLES -t nat -A PREROUTING -p $REDIPROTO -d $IP_EXTERNO --dport $PPUBLICA -j DNAT --to-destination $REDIP:$PPRIVADA
$IPTABLES -t nat -A POSTROUTING -p $REDIPROTO -s $REDE -d $REDIP --dport $PPUBLICA -j SNAT --to-source $IP_EXTERNO
$IPTABLES -t filter -p $REDIPROTO -A FORWARD -s $REDE -d $REDIP --dport $PPUBLICA -j ACCEPT
echo "[OK]"
done
echo "Redirecionamento OK!"
echo "Liberando Conexão a USUARIOS sem intermédio do Proxy" ; sleep 1s ;
for i in `cat $IPSLIBERADOS `; do
IPLIBERADO=`echo $i | cut -d ';' -f 1`
NOME=`echo $i | cut -d ';' -f 2`
echo -n "Conexão Liberada a $NOME " ; sleep 1 ;
$IPTABLES -A FORWARD -s $IPLIBERADO -j ACCEPT
$IPTABLES -t nat -A PREROUTING -p tcp --dport 80 -s $IPLIBERADO -j RETURN
echo "[OK]"
done
echo "Conexões Liberadas!"
echo -n "Bloquear Ping da Morte..................." ; sleep 1s ;
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
$IPTABLES -N PING-MORTE
$IPTABLES -A INPUT -p icmp --icmp-type echo-request -j PING-MORTE
$IPTABLES -A PING-MORTE -m limit --limit 1/s --limit-burst 4 -j RETURN
$IPTABLES -A PING-MORTE -j DROP
echo "[OK]"
echo -n "Bloquear ataque do tipo SYN-FLOOD..................." ; sleep 1s ;
echo "0" > /proc/sys/net/ipv4/tcp_syncookies
$IPTABLES -N syn-flood
$IPTABLES -A INPUT -i $WAN -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 "[OK]"
echo -n "Bloqueio de Ataque SSH de Força Bruta..................." ; sleep 1s ;
$IPTABLES -N SSH-BRUT-FORCE
$IPTABLES -A INPUT -i $WAN -p tcp --dport 22 -j SSH-BRUT-FORCE
$IPTABLES -A SSH-BRUT-FORCE -m limit --limit 1/s --limit-burst 4 -j RETURN
$IPTABLES -A SSH-BRUT-FORCE -j DROP
echo "[OK]"
echo "Bloqueando Portas" ; sleep 1s ;
for i in `cat $PORTSBLO`; do
PORTA=`echo $i | cut -d ';' -f 1`
NOME=`echo $i | cut -d ';' -f 2`
echo -n "Bloqueando Porta $NOME($PORTA)......................." ; sleep 1 ;
$IPTABLES -A INPUT -p tcp -i $WAN --dport $PORTA -j DROP
$IPTABLES -A INPUT -p udp -i $WAN --dport $PORTA -j DROP
$IPTABLES -A FORWARD -p tcp --dport $PORTA -j DROP
$IPTABLES -A FORWARD -p udp --dport $PORTA -j DROP
$IPTABLES -A OUTPUT -p tcp --dport $PORTA -j DROP
$IPTABLES -A OUTPUT -p udp --dport $PORTA -j DROP
echo "[OK]"
done
echo "Portas Bloqueadas!"
echo -n "Bloqueio Anti-Spoofings..................." ; sleep 1s ;
$IPTABLES -A INPUT -s 10.0.0.0/8 -i $WAN -j DROP
$IPTABLES -A INPUT -s 127.0.0.0/8 -i $WAN -j DROP
$IPTABLES -A INPUT -s 172.16.0.0/12 -i $WAN -j DROP
$IPTABLES -A INPUT -s 192.168.0.0/16 -i $WAN -j DROP
echo "[OK]"
echo -n "Bloqueio de scanners ocultos (Sheal Scan) ..................." ; sleep 1s ;
$IPTABLES -A FORWARD -p tcp --tcp-flags SYN,ACK, FIN, -m limit --limit 1/s -j ACCEPT
echo "[OK]"
echo -n "Ativando Proxy Transparente..................." ; sleep 1s ;
#$IPTABLES -t nat -A PREROUTING -s $REDE -p tcp --dport 80 -j REDIRECT --to-port 3128
echo "[OK]"
echo -n "Mascarando Interface..................." ; sleep 1s ;
$IPTABLES -t nat -A POSTROUTING -o $WAN -j MASQUERADE
echo "[OK]"
echo -n "Políticas Padrão..................." ; sleep 1s ;
# Bloqueia conexões de entrada e redirecionamento
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
echo "[OK]"
echo
echo "|=====================================|"
echo "| TERMINADA A CONFIGURAÇÃO DO FIREWALL|"
echo "| NETFILTER ATRAVÉS DO IPTABLES |"
echo "|=====================================|"
echo "FIREWALL ATIVADO - SISTEMA PREPARADO"
echo "SCRIPT DE FIREWALL CONFIGURADO POR :-) VICTOR FELIPE :-)" ;
echo -e '\e[31;5m Free of necessity ... Linux by choice. \e[m' ; sleep 3 ;
;;
stop)
$IPTABLES -F
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F FORWARD
$IPTABLES -t mangle -F
$IPTABLES -t nat -F
$IPTABLES -X
$IPTABLES -Z
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
echo "FIREWALL DESCARREGADO - SISTEMA LIBERADO"
echo
;;
restart)
$PROGRAMA stop
$PROGRAMA start
;;
*)
SEG='8'
while [ $SEG != 0 ] ; do
clear ;
echo "Use: $N {start|stop|restart}" >&2
echo -e "\e[31;5m ATENÇÃO \e[m"
echo "Argumento não informado ou inválido, restartando firewall em $SEG segundos" ;
sleep 1 ;
let SEG-- ;
done
$PROGRAMA restart
exit 1
esac
exit 0
meu dhcpd.conf
option wpad code 252 = text;
option wpad "http://192.168.0.1/wpad.dat\n";
ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
authoritative;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.105;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1,200.221.11.100;
option broadcast-address 192.168.0.255;
}
#SERVIDOR DADOS (Windows Server 2003 S)
host servidordados {
hardware ethernet 20:cf:30:bc:df:d8;
fixed-address 192.168.0.2;
}