topz
(usa Ubuntu)
Enviado em 29/10/2010 - 11:15h
Caros Colegas,
Estou tendo que implementar segurança em minha empresa e estou com algumas dificuldades, copiei este script na internet, adequei a configuração de meu servidor e implementei, antes apenas fazia o compartilhamento da conexão do iptables para o squid transparente e funcionava, com este novo script os clientes pingam para fora da rede para IP´s e resolvem nomes também, porém não navegam de jeito nenhum:
Segue o dito abaixo, desde ja agradeço pela ajuda.
#!bin/bash
#firewall
### VARIAVEIS GLOBAIS
ipt="/sbin/iptables"
mod="/sbin/modprobe"
#start_fw()
#{
### VARIAVEIS DO SISTEMA
LO_IP="127.0.0.1"
LAN_IF="eth1"
LAN_IP="172.16.16.1"
LAN_NET="172.16.16.0/24"
WAN_IF="eth0"
### PORTAS DE SAIDA
FW_TCPOUT="443,1049,1364,2500,3007,3456,5017,5024,7080,8017"
### HABILITA ROTEAMENTO DE PACOTES
echo 1 > /proc/sys/net/ipv4/ip_forward
### DESABILITA RESPOSTA DE PING DE BROADCAST
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
### DESABILITA TCP SYNCOOKIES
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
## PROTECAO CONTRA IP SPOOFING
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
## IMPEDIR QUE ATAQUES REDIRECIONEM ROTAS
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
## IMPEDIRE QUE ATAQUES DETERMINEM O CAMINHO DA ROTA
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
## PROTECAO CONTRA RESPONSES BOGUS
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
### CARREGANDO MODULOS
$mod ip_tables
$mod ip_conntrack
$mod iptable_filter
$mod iptable_mangle
$mod ipt_LOG
$mod ipt_limit
$mod ipt_state
$mod ipt_MASQUERADE
$mod ip_nat_ftp
$mod ip_conntrack_ftp
### APAGANDO AS REGRAS
$ipt -F
$ipt -X
$ipt -t nat -F
$ipt -t nat -X
$ipt -t mangle -F
$ipt -t mangle -X
### SETANDO AS POLITICAS
$ipt -P INPUT DROP
$ipt -P FORWARD DROP
$ipt -P OUTPUT ACCEPT
$ipt -t nat -P OUTPUT ACCEPT
$ipt -t nat -P PREROUTING ACCEPT
$ipt -t nat -P POSTROUTING ACCEPT
$ipt -t mangle -P PREROUTING ACCEPT
$ipt -t mangle -P POSTROUTING ACCEPT
### TABELAS ADICIONAIS
# $ipt -N SYN_FLOOD
# $ipt -N UNCLEAN
# $ipt -N PING_DEATH
$ipt -N PORT_SCANNER
$ipt -N INVALID_SOURCE
$ipt -N INVALID_CONNECTION
$ipt -N TRANS_PROXY -t nat
$ipt -N SSH
### CONFIGURA AS TABELAS
$ipt -A PORT_SCANNER -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j RETURN
$ipt -A PORT_SCANNER -j LOG --log-prefix "[IPTables PortScan] : " --log-level info
$ipt -A PORT_SCANNER -j DROP
$ipt -A INVALID_SOURCE -j LOG --log-prefix "[IPTables Drop_Source] : " --log-level info
$ipt -A INVALID_SOURCE -j DROP
$ipt -A INVALID_CONNECTION -j LOG --log-prefix "[IPTables Drop_Port] : " --log-level info
$ipt -A INVALID_CONNECTION -j DROP
$ipt -A SSH -j LOG --log-prefix "[IPTables SSH] : " --log-level info
$ipt -A SSH -j DROP
$ipt -A TRANS_PROXY -t nat -d $LAN_IP -j RETURN
$ipt -A TRANS_PROXY -t nat -p tcp -j REDIRECT --to-port 3128 # REDIRECIONA PARA O SQUID
#########################################################################################
#################### TABELA NAT
#########################################################################################
## SQUID3 / PROXY TRANSPARENTE
$ipt -t nat -A PREROUTING -s $LAN_NET -p tcp --dport 80 -j TRANS_PROXY
#$ipt -t nat -A PREROUTING -s $LAN_NET -p tcp --dport 8080 -j TRANS_PROXY
## ROTEAMENTO PARA TS
$ipt -t nat -A PREROUTING -i $WAN_IF -p tcp --dport 3389 -j DNAT --to-destination 172.16.16.220:3389
## MASCARANDO CONEXAO DO COMPARTILHAMENTO DE INTERNET
$ipt -A POSTROUTING -t nat -s $LAN_NET -o $WAN_IF -j MASQUERADE
#########################################################################################
##################### TABELA OUTPUT
#########################################################################################
## DESTINOS CONFIAVEIS
$ipt -A OUTPUT -d $LAN_NET -j ACCEPT
$ipt -A OUTPUT -d $LO_IP -j ACCEPT
## ORIGENS / DESTINOS NAO CONFIAVEIS
$ipt -A OUTPUT -s 10.0.0.0/8 -j DROP
$ipt -A OUTPUT -s 192.168.0.0/16 -j DROP
$ipt -A OUTPUT -s 224.0.0.0/4 -j DROP
$ipt -A OUTPUT -s 240.0.0.0/5 -j DROP
$ipt -A OUTPUT -s 127.0.0.0/8 -j DROP
$ipt -A OUTPUT -s 0.0.0.0/8 -j DROP
$ipt -A OUTPUT -d 255.255.255.255 -j DROP
$ipt -A OUTPUT -d 224.0.0.0/4 -j DROP
#########################################################################################
###################### TABELA INPUT
#########################################################################################
## SSH - LIBERA CONEXOES DA REDE INTERNA
$ipt -A INPUT -s $LAN_NET -p tcp --dport 22 -j ACCEPT
$ipt -A FORWARD -d $LAN_NET -p tcp --dport 22 -j ACCEPT
$ipt -A OUTPUT -d $LAN_NET -p tcp --dport 22 -j ACCEPT
## SSH - LOGA QUANQUER OUTRA TENTATIVA
$ipt -A INPUT -p tcp --dport 22 -j SSH
$ipt -A FORWARD -p tcp --dport 22 -j SSH
$ipt -A OUTPUT -p tcp --dport 22 -j SSH
## ORIGENS CONFIAVEIS
$ipt -A INPUT -i $LO_IP -j ACCEPT
$ipt -A INPUT -i $LAN_NET -j ACCEPT
## ORIGENS NAO CONFIAVEIS
$ipt -A INPUT -s 10.0.0.0/8 -j DROP
$ipt -A INPUT -s 192.168.0.0/16 -j INVALID_SOURCE
$ipt -A INPUT -s 224.0.0.0/4 -j INVALID_SOURCE
$ipt -A INPUT -s 240.0.0.0/4 -j INVALID_SOURCE
$ipt -A INPUT -s 127.0.0.0/8 -j INVALID_SOURCE
$ipt -A INPUT -s 0.0.0.0/8 -j INVALID_SOURCE
$ipt -A INPUT -d 255.255.255.255 -j INVALID_SOURCE
$ipt -A INPUT -d 224.0.0.0/4 -j INVALID_SOURCE
## PERMITE TRAFEGOS JA ESTABELECIDOS
$ipt -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
## LIBERANDO MENSAGENS ICMP
$ipt -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
$ipt -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
## TERMINAL SERVICE
$ipt -A INPUT -i $WAN_IF -p tcp --dport 3389 -j ACCEPT
## COMPUTADORES LIBERADOS E SEM PROXY
for i in $(cat /etc/fw_net_free)
do
$ipt -A INPUT -i $WAN_IF -s $i -p tcp --sport 0:65535 --dport 0:65535 -j ACCEPT
$ipt -A INPUT -i $WAN_IF -s $i -p udp --sport 0:65535 --dport 0:65535 -j ACCEPT
done
## SERVIDOR WEB
$ipt -A INPUT -i $WAN_IF -p tcp --dport 80 -j ACCEPT
$ipt -A INPUT -i $LAN_IF -p tcp --dport 80 -j ACCEPT
## DNS
$ipt -A INPUT -p tcp --dport 53 -j ACCEPT
$ipt -A INPUT -p udp --dport 53 -j ACCEPT
$ipt -A INPUT -p tcp --dport 953 -j ACCEPT
$ipt -A INPUT -p udp --dport 953 -j ACCEPT
#######################################################$ipt -A INPUT -p tcp --destination-port 80 -j ACCEPT
$ipt -A INPUT -m multiport -p tcp --dport 22,80 -j ACCEPT
#############################################################################################
######################### TABELA FORWARD
#############################################################################################
## PORTA 3128 ACEITA PELA REDE INTERNA
$ipt -A FORWARD -i $LAN_NET -p tcp --dport 3128 -j ACCEPT
## PERMITE TRAFEGO JA ESTABELECIDO
$ipt -A FORWARD -i $WAN_IF -o $LAN_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
$ipt -A FORWARD -i $LAN_IF -o $WAN_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
## BLOQUEIA ORKUT
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 64.233.171.0/24 -p tcp --dport 443 -j DROP
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 72.14.209.0/24 -p tcp --dport 443 -j DROP
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 216.239.51.0/24 -p tcp --dport 443 -j DROP
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d orkut.com.br -j DROP
## LIBERA CONEXOES HTTPS
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -p tcp --dport 443 -j ACCEPT
## LIBERA MSN
for i in $(cat /etc/fw_msn_free)
do
$ipt -A FORWARD -i $LAN_IF -s $i -p tcp --dport 1863 -j ACCEPT
done
## BLOQUEIA MSN
$ipt -A FORWARD -s $LAN_NET -p tcp --dport 1863 -j REJECT
$ipt -A FORWARD -s $LAN_NET -p tcp --dport 1864 -j REJECT
$ipt -A FORWARD -s $LAN_NET -d loginnet.passport.com -j REJECT
$ipt -A FORWARD -s $LAN_NET -d login.live.com -j REJECT
## PERMITE TRAFEGO DEFINIDO
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 0/0 -p tcp -m multiport --dport $FW_TCPOUT -j ACCEPT
## PERMITIR PING PARTINDO DA REDE LOCAL
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d 0/0 -p icmp -j ACCEPT
## PERMITIR FTP
$ipt -A FORWARD -i $LAN_IF -p tcp --dport 21 -j ACCEPT
$ipt -A FORWARD -i $LAN_IF -p tcp --dport 20 -j ACCEPT
## PERMITIR CLIENTES POP
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d smtp.terra.com.br -p tcp --dport 25 -j ACCEPT
$ipt -A FORWARD -i $LAN_IF -s $LAN_NET -d pop.terra.com.br -p tcp --dport 110 -j ACCEPT
## LIBERA COMPLETO
for i in $(cat /etc/fw_net_free)
do
$ipt -A FORWARD -i $WAN_IF -d $i -j ACCEPT
$ipt -A FORWARD -i $LAN_IF -s $i -j ACCEPT
done
## LOG DO TRAFEGO NAO PERMITIDO
$ipt -A FORWARD -p tcp -j INVALID_CONNECTION
## RECONFIGURA SQUID3
#squid3 -k reconfigure
#}