arasouza
(usa Debian)
Enviado em 02/09/2014 - 15:14h
Olá Pessoal, já fazem 2 semanas que estou tentando levantar este servidor proxy com o debian whezzy 7, vale salientar que estou com uma maquina similar de 64 bits rodando com o mesmo iptables e squid 2.7 stable + dansguardian funcionado legal, porém esta não funciona de jeito nenhum.... agradeço qualquer colaboração no script abaixo. (obs. se não levantar o script ele navega, faz os bloqueis sem problema):
----------------------- INICIO DO SCRIPT - IPTABLES ----------------------
#!/bin/sh
# Variaveis
# -------------------------------------------------------
iptables=/sbin/iptables
IF_EXTERNA=eth2
IF_INTERNA=eth1
# Ativa modulos
# -------------------------------------------------------
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
# Ativa roteamento no kernel
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
# Protecao 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 politica padrao
# -------------------------------------------------------
$iptables -P INPUT DROP
$iptables -P OUTPUT DROP
$iptables -P FORWARD DROP
#################################################
# Tabela FILTER
#################################################
# Dropa pacotes TCP indesejaveis
# -------------------------------------------------------
$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
# Desativa conexoes IPV6
# -------------------------------------------------------
#$ip6tables -p INPUT -j REJECT
#$ip6tables -p OUTPUT -j REJECT
#$ip6tables -p FORWARD -j REJECT
# 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
# Protecao 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
# Protecao 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
# Protecao contra worms
# -------------------------------------------------------
$iptables -A FORWARD -p tcp --dport 135 -i $IF_INTERNA -j REJECT
# Protecao contra syn-flood
# -------------------------------------------------------
$iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
# Protecao contra ping da morte
# -------------------------------------------------------
$iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# Protecao 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
####################
# Bloqueio Netbios #
####################
#iptables -t nat -A PREROUTING -p tcp --dport 445 -j DROP
#iptables -t nat -A PREROUTING -P tcp --dport 137 -j DROP
#iptables -t nat -A PREROUTING -P tcp --dport 138 -j DROP
#iptables -t nat -A PREROUTING -p tcp --dport 139 -j DROP
#iptables -t nat -A PREROUTING -p udp --dport 445 -j DROP
#iptables -t nat -A PREROUTING -p udp --dport 137 -j DROP
#iptables -t nat -A PREROUTING -p udp --dport 138 -j DROP
#iptables -t nat -A PREROUTING -p udp --dport 139 -j DROP
# Loga tentativa de acesso a determinadas portas
# -------------------------------------------------------
# -------------------------------------------------------
$iptables -A INPUT -p tcp --dport 21 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: ftp: "
$iptables -A INPUT -p tcp --dport 23 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: telnet: "
$iptables -A INPUT -p tcp --dport 25 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: smtp: "
$iptables -A INPUT -p tcp --dport 80 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: http: "
$iptables -A INPUT -p tcp --dport 110 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: pop3: "
$iptables -A INPUT -p udp --dport 111 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: rpc: "
$iptables -A INPUT -p tcp --dport 113 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: identd: "
$iptables -A INPUT -p tcp --dport 137:139 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: samba: "
$iptables -A INPUT -p udp --dport 137:139 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: samba: "
$iptables -A INPUT -p tcp --dport 161:162 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: snmp: "
$iptables -A INPUT -p tcp --dport 6667:6668 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: irc: "
$iptables -A INPUT -p tcp --dport 3128 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: squid: "
$iptables -A INPUT -p tcp --dport 3389 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIREWALL: RDP: "
#################################################
# Tabela NAT
#################################################
# Ativa mascaramento de saida
# -------------------------------------------------------
$iptables -t nat -A POSTROUTING -o $IF_EXTERNA -j MASQUERADE
# Proxy transparente
# -------------------------------------------------------
#
$iptables -t nat -A POSTROUTING -o $IF_INTERNA -j MASQUERADE
$iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 3128 -j REDIRECT --to-port 8081
$iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 80 -j REDIRECT --to-port 8081
$iptables -A INPUT -m tcp -p tcp -s !127.0.0.1/8 --dport 3128 -j DROP
# Redireciona portas para outros servidores
# -------------------------------------------------------
#$iptables -t nat -A PREROUTING -d 192.168.200.1 -p tcp --dport 22 -j DNAT --to-destination 10.0.0.1
# 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
#################################################
# FIM da Tabela NAT
#################################################
# Liberando porta 53 (DNS)
$iptables -A FORWARD -i $IF_INTERNA -p tcp --dport 53 -j ACCEPT
$iptables -A FORWARD -i $IF_INTERNA -p udp --dport 53 -j ACCEPT
#teste do cache full
# -------------------------------------------------------
$iptables -t mangle -A OUTPUT -p tcp -m connmark --mark 0 -m string --string "X-Cache: HIT" --algo kmp -j CONNMARK --set-mark 6
$iptables -t mangle -A OUTPUT -p tcp -j CONNMARK --restore-mark
$iptables -t mangle -A OUTPUT -p tcp -m mark --mark 6 -j CLASSIFY --set-class 1:10000000
# FECHA P2P
#$iptables -A FORWARD -p tcp -m ipp2p --ipp2p -j DROP
# Bittorrent - Funcionando
#$iptables -t nat -A PREROUTING -i eth9 -p tcp --dport 6881:6889 -j DNAT --to-des 10.0.0.1
#$iptables -A FORWARD -p tcp -i eth9 --dport 6881:6889 -d 10.0.0.1 -j DROP
# IMESH
$iptables -A FORWARD -d 216.35.208.0/24 -j DROP
# BEARSHARE
$iptables -A FORWARD -p TCP --dport 6346 -j REJECT
#TOADNODE
$iptables -A FORWARD -p TCP --dport 6346 -j REJECT
#WINMX
$iptables -A FORWARD -d 209.61.186.0/24
$iptables -A FORWARD -d 64.49.201.0/24
#Napigator
$iptables -A FORWARD -d 209.25.178.0/24 -j REJECT
# Morpheus - Funcionando
$iptables -A FORWARD -d 206.142.53.0/24 -j REJECT
# Kazaa lite
#$iptables -m string --string "X-Kazaa-Username:" -j REJECT
#$iptables -m string --string "X-Kazaa-Network:" -j REJECT
#$iptables -m string --string "X-Kazaa-IP:" -j REJECT
#$iptables -m string --string "X-Kazaa-SupernodeIP:" -j REJECT
# Limeware - Funcionando
$iptables -A FORWARD -p TCP --dport 6346 -j REJECT
# Audiogalaxy
$iptables -A FORWARD -d 64.245.58.0/23 -j REJECT
# Kazaa - Funcionando
$iptables -A FORWARD -d 213.248.112.0/24 -j REJECT
$iptables -A FORWARD -p TCP --dport 1214 -j REJECT
#Fim do arquivo
#--------------------------------------------------------