abelfrancia
(usa Debian)
Enviado em 15/01/2013 - 15:49h
Esqueçam o script acima, achei outro, e reduzi ele, pois era de servidor, porém está dando alguns problemas, queria ver com vocês o que pode ser...
#!/bin/sh
#
#
#
#
internet="wlan0" "eth0"
Primeira observaçao, pode ser feito isso? Quero que os filtros sejam aplicados nos dois dipositivos.....???
echo "####################ATIVANDO IPTABLES#######################"
### Passo 1: Limpando as regras ###
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F POSTROUTING -t nat
iptables -F PREROUTING -t nat
iptables -F -t nat
echo "Limpando as regras ..................................[ OK ]"
# Definindo a Politica Default das Cadeias
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
echo "Politica Default das Cadeias ........................[ OK ]"
# Configurando a Protecao anti-spoofing
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
#for spoofing in /proc/sys/net/ipv4/conf/*/rp_filter; do
# echo "1" > $spoofing
#done
echo "Protecao anti-spoofing ..............................[ OK ]"
# Impedimos que um atacante possa maliciosamente alterar alguma rota
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
echo "Impedimos alterar alguma rota .......................[ OK ]"
# Utilizado em diversos ataques, isso possibilita que o atacante determine o "caminho" que seu
# pacote vai percorrer (roteadores) ate seu destino. Junto com spoof, isso se torna muito perigoso.
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
echo "Impossibilita que o atacante determine o "caminho" ....[ OK ]"
# Protecao contra responses bogus
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "Protecao contra responses bogus .....................[ OK ]"
# Protecao contra ataques de syn flood (inicio da conexao TCP). Tenta conter ataques de DoS.
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo "Protecao contra ataques de syn ......................[ OK ]"
### Passo 3: Carregando os modulos do iptables ###
# 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
echo "Carregando os modulos ...............................[ OK ]"
#################################################
# FIM DA Tabela FILTER
#################################################
# Proteção contra port scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 15/m -j LOG --log-prefix "FIREWALL: port scanner: "
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i $internet -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i $internet -j SCANNER
echo "Scaner de Portas ....................................[ OK ]"
# Libera acesso externo a determinadas portas
##Algumas portas devem ser negadas.
iptables -A INPUT -p tcp --dport 1433 -j DROP
iptables -A INPUT -p tcp --dport 6670 -j DROP
iptables -A INPUT -p tcp --dport 6711 -j DROP
iptables -A INPUT -p tcp --dport 6712 -j DROP
iptables -A INPUT -p tcp --dport 6713 -j DROP
iptables -A INPUT -p tcp --dport 12345 -j DROP
iptables -A INPUT -p tcp --dport 12346 -j DROP
iptables -A INPUT -p tcp --dport 20034 -j DROP
iptables -A INPUT -p tcp --dport 31337 -j DROP
iptables -A INPUT -p tcp --dport 6000 -j DROP
echo "Negando portas invalidas ............................[ OK ]"
#Traceroutes caindo
iptables -A INPUT -p udp --dport 33434:33523 -j DROP
iptables -A INPUT -p tcp --dport 113 -j REJECT
iptables -A INPUT -p igmp -j REJECT
iptables -A INPUT -p tcp --dport 80 -j DROP
iptables -A INPUT -p tcp --dport 443 -j REJECT
echo "Rejeitando lixo :....................................[ OK ]"
#bloqueia qualquer tentativa de nova conexao de fora para esta maquina
#iptables -A INPUT -i $internet -m state --state ! ESTABLISHED,RELATED -j LOG --log-level 6 --log-prefix "FIREWALL entrada "
iptables -A INPUT -i $internet -m state --state ! ESTABLISHED,RELATED -j DROP
#no iptables, temos de dizer quais sockets sao validos em uma conexao
iptables -A INPUT -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Cadeia de Entrada ...................................[ OK ]"
################################
# Cadeia de Reenvio (FORWARD).
# Primeiro, ativar o mascaramento (nat).
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o $internet -j MASQUERADE
echo "Ativando o mascaramento .............................[ OK ]"
# Agora dizemos quem e o que podem acessar externamente
# O controle do acesso a rede externa e feito na cadeia "FORWARD"
iptables -A FORWARD -i $internet -j ACCEPT
iptables -A FORWARD -o $internet -m state --state ESTABLISHED,RELATED -j ACCEPT
echo "Ativando o acesso ftp.. .............................[ OK ]"
###################
###BLOQUEANDO TODAS AS SAIDAS E PORTAS
iptables -A INPUT -p all -j DROP
iptables -A FORWARD -p all -j DROP
echo "Rejeitando saida e entrada ..........................[ OK ]"
########################
# No iptables, temos de dizer quais sockets sao validos em uma conexao
iptables -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "Quais sockets sao validos ...........................[ OK ]"
#################################################
# Tabela FILTER
#################################################
# Proteção contra tronjans
# -------------------------------------------------------
iptables -A INPUT -p TCP -i $internet --dport 666 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 4000 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 6000 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 6006 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 16660 -j DROP
# Proteção contra trinoo
# -------------------------------------------------------
iptables -A INPUT -p TCP -i $internet --dport 27444 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 27665 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 31335 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 34555 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 35555 -j DROP
echo "Proteção contra trinoo ............................. [ OK ]"
# Protecao contra acesso externo squid
iptables -A INPUT -p TCP -i $internet --dport 3128 -j DROP
iptables -A INPUT -p TCP -i $internet --dport 8080 -j DROP
echo "Proteção contra squid externo....................... [ OK ]"
# Protecao contra telnet
iptables -A INPUT -p TCP -i $internet --dport telnet -j DROP
echo "Proteção contra telnet ....................... [ OK ]"
# Dropa pacotes TCP indesejaveis
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
# Dropa pacotes mal formados
iptables -A INPUT -i $internet -m unclean -j DROP
# Protecao contra worms
iptables -A FORWARD -p tcp --dport 135 -i $internet -j REJECT
# Protecaocontra 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
#Allow ALL other forwarding going out
iptables -A FORWARD -o -i $internet -j ACCEPT
echo "Carregado tabela filter ............................ [ OK ]"
echo "##################FIM DE REGRAS IPTABLES####################"
exit 0
Está dando erro ao executar o script,
[code]
$sudo ./firewall2.sh
./firewall2.sh: 6: ./firewall2.sh: eth0: not found
####################ATIVANDO IPTABLES#######################
Limpando as regras ..................................[ OK ]
Politica Default das Cadeias ........................[ OK ]
Protecao anti-spoofing ..............................[ OK ]
Impedimos alterar alguma rota .......................[ OK ]
Impossibilita que o atacante determine o caminho ....[ OK ]
Protecao contra responses bogus .....................[ OK ]
Protecao contra ataques de syn ......................[ OK ]
Carregando os modulos ...............................[ OK ]
iptables: Chain already exists.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `SCANNER'
Try `iptables -h' or 'iptables --help' for more information.
Scaner de Portas ....................................[ OK ]
Negando portas invalidas ............................[ OK ]
Rejeitando lixo :....................................[ OK ]
Bad argument `state'
Try `iptables -h' or 'iptables --help' for more information.
Cadeia de Entrada ...................................[ OK ]
Bad argument `MASQUERADE'
Try `iptables -h' or 'iptables --help' for more information.
Ativando o mascaramento .............................[ OK ]
Bad argument `ACCEPT'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `state'
Try `iptables -h' or 'iptables --help' for more information.
Ativando o acesso ftp.. .............................[ OK ]
Rejeitando saida e entrada ..........................[ OK ]
Quais sockets sao validos ...........................[ OK ]
Bad argument `666'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `4000'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `6000'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `6006'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `16660'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `27444'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `27665'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `31335'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `34555'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `35555'
Try `iptables -h' or 'iptables --help' for more information.
Proteção contra trinoo ............................. [ OK ]
Bad argument `3128'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `8080'
Try `iptables -h' or 'iptables --help' for more information.
Proteção contra squid externo....................... [ OK ]
Bad argument `telnet'
Try `iptables -h' or 'iptables --help' for more information.
Proteção contra telnet ....................... [ OK ]
Bad argument `unclean'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `REJECT'
Try `iptables -h' or 'iptables --help' for more information.
Carregado tabela filter ............................ [ OK ]
##################FIM DE REGRAS IPTABLES####################